Commit bb29785e0d6d150181704be2efcc3141044625e2

Authored by Grant Likely
1 parent cf9c86efec

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>

Showing 1 changed file with 3 additions and 0 deletions Side-by-side Diff

... ... @@ -1135,6 +1135,9 @@
1135 1135 if (master->num_chipselect == 0)
1136 1136 return -EINVAL;
1137 1137  
  1138 + if ((master->bus_num < 0) && master->dev.of_node)
  1139 + master->bus_num = of_alias_get_id(master->dev.of_node, "spi");
  1140 +
1138 1141 /* convention: dynamically assigned bus IDs count down from the max */
1139 1142 if (master->bus_num < 0) {
1140 1143 /* FIXME switch to an IDR based scheme, something like