02a2eca1798cc923e2026d6113f6ab19284c74ff
[openwrt/staging/yousong.git] / target / linux / generic / patches-3.8 / 033-backport-spi-of-Use-DT-aliases-for-assigning-bus-number.patch
1 From bb29785e0d6d150181704be2efcc3141044625e2 Mon Sep 17 00:00:00 2001
2 From: Grant Likely <grant.likely@secretlab.ca>
3 Date: Fri, 21 Dec 2012 19:32:09 +0000
4 Subject: [PATCH] spi/of: Use DT aliases for assigning bus number
5
6 Linux assigns a number to each spi_master in the system, but when the
7 platform used the device tree, the numbers are dynamically assigned and
8 are not predictable. In general this shouldn't matter since the kernel
9 doesn't use the bus number for anything other than matching a bus to
10 spi_boardinfo (not used for DT). However, sometimes userspace needs to
11 figure out which bus is which, so it makes sense to use the global
12 /aliases namespace to choose a specific bus number.
13
14 It is safe to derive the bus number from an alias because aliases will
15 never cause two buses to try and use the same bus number. (At one time
16 the cell-index property was used for this purpose, but cell-index has
17 the risk of an id collision).
18
19 Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
20 Cc: Anatolij Gustschin <agust@denx.de>
21 Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
22 ---
23 drivers/spi/spi.c | 3 +++
24 1 file changed, 3 insertions(+)
25
26 --- a/drivers/spi/spi.c
27 +++ b/drivers/spi/spi.c
28 @@ -1135,6 +1135,9 @@ int spi_register_master(struct spi_maste
29 if (master->num_chipselect == 0)
30 return -EINVAL;
31
32 + if ((master->bus_num < 0) && master->dev.of_node)
33 + master->bus_num = of_alias_get_id(master->dev.of_node, "spi");
34 +
35 /* convention: dynamically assigned bus IDs count down from the max */
36 if (master->bus_num < 0) {
37 /* FIXME switch to an IDR based scheme, something like