summaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2012-12-21 19:32:09 +0000
committerGrant Likely <grant.likely@secretlab.ca>2013-02-05 12:26:59 +0000
commitbb29785e0d6d150181704be2efcc3141044625e2 (patch)
treee6814ea5c06407a8fe57ad154a797f15ed6a0403 /drivers/spi
parentcf9c86efecf9510e62388fd174cf607671c59fa3 (diff)
downloadlinux-stable-bb29785e0d6d150181704be2efcc3141044625e2.tar.gz
linux-stable-bb29785e0d6d150181704be2efcc3141044625e2.tar.bz2
linux-stable-bb29785e0d6d150181704be2efcc3141044625e2.zip
spi/of: Use DT aliases for assigning bus number
Linux assigns a number to each spi_master in the system, but when the platform used the device tree, the numbers are dynamically assigned and are not predictable. In general this shouldn't matter since the kernel doesn't use the bus number for anything other than matching a bus to spi_boardinfo (not used for DT). However, sometimes userspace needs to figure out which bus is which, so it makes sense to use the global /aliases namespace to choose a specific bus number. It is safe to derive the bus number from an alias because aliases will never cause two buses to try and use the same bus number. (At one time the cell-index property was used for this purpose, but cell-index has the risk of an id collision). Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Anatolij Gustschin <agust@denx.de> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 19ee901577da..08ff4acd5225 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1135,6 +1135,9 @@ int spi_register_master(struct spi_master *master)
if (master->num_chipselect == 0)
return -EINVAL;
+ if ((master->bus_num < 0) && master->dev.of_node)
+ master->bus_num = of_alias_get_id(master->dev.of_node, "spi");
+
/* convention: dynamically assigned bus IDs count down from the max */
if (master->bus_num < 0) {
/* FIXME switch to an IDR based scheme, something like