Commit 12b15e83289bc7cf2ec9a342412e0c955beeb395
Committed by
Grant Likely
1 parent
559e2b7ee7
Exists in
master
and in
7 other branches
of/spi: call of_register_spi_devices() from spi core code
Move of_register_spi_devices() call from drivers to spi_register_master(). Also change the function to use the struct device_node pointer from master spi device instead of passing it as function argument. Signed-off-by: Anatolij Gustschin <agust@denx.de> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Showing 10 changed files with 27 additions and 24 deletions Side-by-side Diff
drivers/of/of_spi.c
... | ... | @@ -15,12 +15,11 @@ |
15 | 15 | /** |
16 | 16 | * of_register_spi_devices - Register child devices onto the SPI bus |
17 | 17 | * @master: Pointer to spi_master device |
18 | - * @np: parent node of SPI device nodes | |
19 | 18 | * |
20 | - * Registers an spi_device for each child node of 'np' which has a 'reg' | |
19 | + * Registers an spi_device for each child node of master node which has a 'reg' | |
21 | 20 | * property. |
22 | 21 | */ |
23 | -void of_register_spi_devices(struct spi_master *master, struct device_node *np) | |
22 | +void of_register_spi_devices(struct spi_master *master) | |
24 | 23 | { |
25 | 24 | struct spi_device *spi; |
26 | 25 | struct device_node *nc; |
... | ... | @@ -28,7 +27,10 @@ |
28 | 27 | int rc; |
29 | 28 | int len; |
30 | 29 | |
31 | - for_each_child_of_node(np, nc) { | |
30 | + if (!master->dev.of_node) | |
31 | + return; | |
32 | + | |
33 | + for_each_child_of_node(master->dev.of_node, nc) { | |
32 | 34 | /* Alloc an spi_device */ |
33 | 35 | spi = spi_alloc_device(master); |
34 | 36 | if (!spi) { |
drivers/spi/mpc512x_psc_spi.c
drivers/spi/mpc52xx_psc_spi.c
... | ... | @@ -17,7 +17,6 @@ |
17 | 17 | #include <linux/errno.h> |
18 | 18 | #include <linux/interrupt.h> |
19 | 19 | #include <linux/of_platform.h> |
20 | -#include <linux/of_spi.h> | |
21 | 20 | #include <linux/workqueue.h> |
22 | 21 | #include <linux/completion.h> |
23 | 22 | #include <linux/io.h> |
... | ... | @@ -398,6 +397,7 @@ |
398 | 397 | master->setup = mpc52xx_psc_spi_setup; |
399 | 398 | master->transfer = mpc52xx_psc_spi_transfer; |
400 | 399 | master->cleanup = mpc52xx_psc_spi_cleanup; |
400 | + master->dev.of_node = dev->of_node; | |
401 | 401 | |
402 | 402 | mps->psc = ioremap(regaddr, size); |
403 | 403 | if (!mps->psc) { |
... | ... | @@ -470,7 +470,6 @@ |
470 | 470 | const u32 *regaddr_p; |
471 | 471 | u64 regaddr64, size64; |
472 | 472 | s16 id = -1; |
473 | - int rc; | |
474 | 473 | |
475 | 474 | regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL); |
476 | 475 | if (!regaddr_p) { |
477 | 476 | |
... | ... | @@ -491,13 +490,8 @@ |
491 | 490 | id = *psc_nump + 1; |
492 | 491 | } |
493 | 492 | |
494 | - rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, | |
493 | + return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, | |
495 | 494 | irq_of_parse_and_map(op->dev.of_node, 0), id); |
496 | - if (rc == 0) | |
497 | - of_register_spi_devices(dev_get_drvdata(&op->dev), | |
498 | - op->dev.of_node); | |
499 | - | |
500 | - return rc; | |
501 | 495 | } |
502 | 496 | |
503 | 497 | static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op) |
drivers/spi/mpc52xx_spi.c
... | ... | @@ -18,7 +18,6 @@ |
18 | 18 | #include <linux/interrupt.h> |
19 | 19 | #include <linux/delay.h> |
20 | 20 | #include <linux/spi/spi.h> |
21 | -#include <linux/of_spi.h> | |
22 | 21 | #include <linux/io.h> |
23 | 22 | #include <linux/of_gpio.h> |
24 | 23 | #include <linux/slab.h> |
... | ... | @@ -439,6 +438,7 @@ |
439 | 438 | master->setup = mpc52xx_spi_setup; |
440 | 439 | master->transfer = mpc52xx_spi_transfer; |
441 | 440 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; |
441 | + master->dev.of_node = op->dev.of_node; | |
442 | 442 | |
443 | 443 | dev_set_drvdata(&op->dev, master); |
444 | 444 | |
... | ... | @@ -512,7 +512,6 @@ |
512 | 512 | if (rc) |
513 | 513 | goto err_register; |
514 | 514 | |
515 | - of_register_spi_devices(master, op->dev.of_node); | |
516 | 515 | dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n"); |
517 | 516 | |
518 | 517 | return rc; |
drivers/spi/spi.c
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 | #include <linux/slab.h> |
27 | 27 | #include <linux/mod_devicetable.h> |
28 | 28 | #include <linux/spi/spi.h> |
29 | +#include <linux/of_spi.h> | |
29 | 30 | |
30 | 31 | |
31 | 32 | /* SPI bustype and spi_master class are registered after board init code |
... | ... | @@ -540,6 +541,9 @@ |
540 | 541 | /* populate children from any spi device tables */ |
541 | 542 | scan_boardinfo(master); |
542 | 543 | status = 0; |
544 | + | |
545 | + /* Register devices from the device tree */ | |
546 | + of_register_spi_devices(master); | |
543 | 547 | done: |
544 | 548 | return status; |
545 | 549 | } |
drivers/spi/spi_mpc8xxx.c
... | ... | @@ -38,7 +38,6 @@ |
38 | 38 | #include <linux/of_platform.h> |
39 | 39 | #include <linux/gpio.h> |
40 | 40 | #include <linux/of_gpio.h> |
41 | -#include <linux/of_spi.h> | |
42 | 41 | #include <linux/slab.h> |
43 | 42 | |
44 | 43 | #include <sysdev/fsl_soc.h> |
... | ... | @@ -1009,6 +1008,7 @@ |
1009 | 1008 | master->setup = mpc8xxx_spi_setup; |
1010 | 1009 | master->transfer = mpc8xxx_spi_transfer; |
1011 | 1010 | master->cleanup = mpc8xxx_spi_cleanup; |
1011 | + master->dev.of_node = dev->of_node; | |
1012 | 1012 | |
1013 | 1013 | mpc8xxx_spi = spi_master_get_devdata(master); |
1014 | 1014 | mpc8xxx_spi->dev = dev; |
... | ... | @@ -1298,8 +1298,6 @@ |
1298 | 1298 | ret = PTR_ERR(master); |
1299 | 1299 | goto err; |
1300 | 1300 | } |
1301 | - | |
1302 | - of_register_spi_devices(master, np); | |
1303 | 1301 | |
1304 | 1302 | return 0; |
1305 | 1303 |
drivers/spi/spi_ppc4xx.c
... | ... | @@ -407,6 +407,7 @@ |
407 | 407 | master = spi_alloc_master(dev, sizeof *hw); |
408 | 408 | if (master == NULL) |
409 | 409 | return -ENOMEM; |
410 | + master->dev.of_node = np; | |
410 | 411 | dev_set_drvdata(dev, master); |
411 | 412 | hw = spi_master_get_devdata(master); |
412 | 413 | hw->master = spi_master_get(master); |
... | ... | @@ -545,7 +546,6 @@ |
545 | 546 | } |
546 | 547 | |
547 | 548 | dev_info(dev, "driver initialized\n"); |
548 | - of_register_spi_devices(master, np); | |
549 | 549 | |
550 | 550 | return 0; |
551 | 551 |
drivers/spi/xilinx_spi.c
drivers/spi/xilinx_spi_of.c
include/linux/of_spi.h
... | ... | @@ -9,11 +9,16 @@ |
9 | 9 | #ifndef __LINUX_OF_SPI_H |
10 | 10 | #define __LINUX_OF_SPI_H |
11 | 11 | |
12 | -#include <linux/of.h> | |
13 | 12 | #include <linux/spi/spi.h> |
14 | 13 | |
15 | -extern void of_register_spi_devices(struct spi_master *master, | |
16 | - struct device_node *np); | |
14 | +#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE) | |
15 | +extern void of_register_spi_devices(struct spi_master *master); | |
16 | +#else | |
17 | +static inline void of_register_spi_devices(struct spi_master *master) | |
18 | +{ | |
19 | + return; | |
20 | +} | |
21 | +#endif /* CONFIG_OF_SPI */ | |
17 | 22 | |
18 | 23 | #endif /* __LINUX_OF_SPI */ |