9
0
Fork 0

spi: support dynamic bus ids

When probing spi bus masters from devicetree they got a bus_num
of -1. This works with a single bus master only since all bus masters
had the same bus_num. Detect this and dynamically assign a valid
bus_num.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2013-10-28 12:07:48 +01:00
parent fd5b82e640
commit fb40dd5157
1 changed files with 5 additions and 0 deletions

View File

@ -215,6 +215,7 @@ static LIST_HEAD(spi_master_list);
*/
int spi_register_master(struct spi_master *master)
{
static int dyn_bus_id = (1 << 15) - 1;
int status = -ENODEV;
debug("%s: %s:%d\n", __func__, master->dev->name, master->dev->id);
@ -225,6 +226,10 @@ int spi_register_master(struct spi_master *master)
if (master->num_chipselect == 0)
return -EINVAL;
/* convention: dynamically assigned bus IDs count down from the max */
if (master->bus_num < 0)
master->bus_num = dyn_bus_id--;
list_add_tail(&master->list, &spi_master_list);
spi_of_register_slaves(master);