Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Anatolij Gustschin and committed by
Grant Likely
12b15e83 559e2b7e

+27 -24
+6 -4
drivers/of/of_spi.c
··· 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; ··· 27 28 int rc; 28 29 int len; 29 30 30 - for_each_child_of_node(np, nc) { 31 + if (!master->dev.of_node) 32 + return; 33 + 34 + for_each_child_of_node(master->dev.of_node, nc) { 31 35 /* Alloc an spi_device */ 32 36 spi = spi_alloc_device(master); 33 37 if (!spi) {
+1
drivers/spi/mpc512x_psc_spi.c
··· 440 440 master->setup = mpc512x_psc_spi_setup; 441 441 master->transfer = mpc512x_psc_spi_transfer; 442 442 master->cleanup = mpc512x_psc_spi_cleanup; 443 + master->dev.of_node = dev->of_node; 443 444 444 445 tempp = ioremap(regaddr, size); 445 446 if (!tempp) {
+2 -8
drivers/spi/mpc52xx_psc_spi.c
··· 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> ··· 397 398 master->setup = mpc52xx_psc_spi_setup; 398 399 master->transfer = mpc52xx_psc_spi_transfer; 399 400 master->cleanup = mpc52xx_psc_spi_cleanup; 401 + master->dev.of_node = dev->of_node; 400 402 401 403 mps->psc = ioremap(regaddr, size); 402 404 if (!mps->psc) { ··· 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) { ··· 490 491 id = *psc_nump + 1; 491 492 } 492 493 493 - rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, 494 + return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, 494 495 irq_of_parse_and_map(op->dev.of_node, 0), id); 495 - if (rc == 0) 496 - of_register_spi_devices(dev_get_drvdata(&op->dev), 497 - op->dev.of_node); 498 - 499 - return rc; 500 496 } 501 497 502 498 static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
+1 -2
drivers/spi/mpc52xx_spi.c
··· 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> ··· 438 439 master->setup = mpc52xx_spi_setup; 439 440 master->transfer = mpc52xx_spi_transfer; 440 441 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; 442 + master->dev.of_node = op->dev.of_node; 441 443 442 444 dev_set_drvdata(&op->dev, master); 443 445 ··· 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;
+4
drivers/spi/spi.c
··· 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 ··· 541 540 /* populate children from any spi device tables */ 542 541 scan_boardinfo(master); 543 542 status = 0; 543 + 544 + /* Register devices from the device tree */ 545 + of_register_spi_devices(master); 544 546 done: 545 547 return status; 546 548 }
+1 -3
drivers/spi/spi_mpc8xxx.c
··· 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> ··· 1008 1009 master->setup = mpc8xxx_spi_setup; 1009 1010 master->transfer = mpc8xxx_spi_transfer; 1010 1011 master->cleanup = mpc8xxx_spi_cleanup; 1012 + master->dev.of_node = dev->of_node; 1011 1013 1012 1014 mpc8xxx_spi = spi_master_get_devdata(master); 1013 1015 mpc8xxx_spi->dev = dev; ··· 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
+1 -1
drivers/spi/spi_ppc4xx.c
··· 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); ··· 546 545 } 547 546 548 547 dev_info(dev, "driver initialized\n"); 549 - of_register_spi_devices(master, np); 550 548 551 549 return 0; 552 550
+3
drivers/spi/xilinx_spi.c
··· 390 390 391 391 master->bus_num = bus_num; 392 392 master->num_chipselect = pdata->num_chipselect; 393 + #ifdef CONFIG_OF 394 + master->dev.of_node = dev->of_node; 395 + #endif 393 396 394 397 xspi->mem = *mem; 395 398 xspi->irq = irq;
-3
drivers/spi/xilinx_spi_of.c
··· 80 80 81 81 dev_set_drvdata(&ofdev->dev, master); 82 82 83 - /* Add any subnodes on the SPI bus */ 84 - of_register_spi_devices(master, ofdev->dev.of_node); 85 - 86 83 return 0; 87 84 } 88 85
+8 -3
include/linux/of_spi.h
··· 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 */