]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
of/spi: call of_register_spi_devices() from spi core code
authorAnatolij Gustschin <agust@denx.de>
Tue, 27 Jul 2010 20:35:58 +0000 (22:35 +0200)
committerGrant Likely <grant.likely@secretlab.ca>
Fri, 30 Jul 2010 06:03:59 +0000 (00:03 -0600)
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>
drivers/of/of_spi.c
drivers/spi/mpc512x_psc_spi.c
drivers/spi/mpc52xx_psc_spi.c
drivers/spi/mpc52xx_spi.c
drivers/spi/spi.c
drivers/spi/spi_mpc8xxx.c
drivers/spi/spi_ppc4xx.c
drivers/spi/xilinx_spi.c
drivers/spi/xilinx_spi_of.c
include/linux/of_spi.h

index d504f1d1324bdb84b746afb81901d49594db19a7..1dbce58a58b01eecc8ebe48d7a9d802cfa90193f 100644 (file)
 /**
  * of_register_spi_devices - Register child devices onto the SPI bus
  * @master:    Pointer to spi_master device
- * @np:                parent node of SPI device nodes
  *
- * Registers an spi_device for each child node of 'np' which has a 'reg'
+ * Registers an spi_device for each child node of master node which has a 'reg'
  * property.
  */
-void of_register_spi_devices(struct spi_master *master, struct device_node *np)
+void of_register_spi_devices(struct spi_master *master)
 {
        struct spi_device *spi;
        struct device_node *nc;
@@ -28,7 +27,10 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
        int rc;
        int len;
 
-       for_each_child_of_node(np, nc) {
+       if (!master->dev.of_node)
+               return;
+
+       for_each_child_of_node(master->dev.of_node, nc) {
                /* Alloc an spi_device */
                spi = spi_alloc_device(master);
                if (!spi) {
index 2534b1ec3eddc5b39485c8fa71fff21dcbef07d3..1bb4315f5f84d2d0e2ba0ac6151040824a049f8f 100644 (file)
@@ -440,6 +440,7 @@ static int __init mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
        master->setup = mpc512x_psc_spi_setup;
        master->transfer = mpc512x_psc_spi_transfer;
        master->cleanup = mpc512x_psc_spi_cleanup;
+       master->dev.of_node = dev->of_node;
 
        tempp = ioremap(regaddr, size);
        if (!tempp) {
index 7104cb739da7eceab4af5a2bcf644c0aaa239d26..bd81ff90cfb3acc44a96c15e4e8e4f2930d568a7 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/of_platform.h>
-#include <linux/of_spi.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/io.h>
@@ -398,6 +397,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
        master->setup = mpc52xx_psc_spi_setup;
        master->transfer = mpc52xx_psc_spi_transfer;
        master->cleanup = mpc52xx_psc_spi_cleanup;
+       master->dev.of_node = dev->of_node;
 
        mps->psc = ioremap(regaddr, size);
        if (!mps->psc) {
@@ -470,7 +470,6 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
        const u32 *regaddr_p;
        u64 regaddr64, size64;
        s16 id = -1;
-       int rc;
 
        regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
        if (!regaddr_p) {
@@ -491,13 +490,8 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
                id = *psc_nump + 1;
        }
 
-       rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+       return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
                                irq_of_parse_and_map(op->dev.of_node, 0), id);
-       if (rc == 0)
-               of_register_spi_devices(dev_get_drvdata(&op->dev),
-                                       op->dev.of_node);
-
-       return rc;
 }
 
 static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
index b1a76bff775f8f2c11e0c1d35efc41039fa95acf..56136ff00e01643dbfe46754e0f3aefce01d11dc 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
-#include <linux/of_spi.h>
 #include <linux/io.h>
 #include <linux/of_gpio.h>
 #include <linux/slab.h>
@@ -439,6 +438,7 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
        master->setup = mpc52xx_spi_setup;
        master->transfer = mpc52xx_spi_transfer;
        master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
+       master->dev.of_node = op->dev.of_node;
 
        dev_set_drvdata(&op->dev, master);
 
@@ -512,7 +512,6 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
        if (rc)
                goto err_register;
 
-       of_register_spi_devices(master, op->dev.of_node);
        dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
 
        return rc;
index b3a1f9259b62539d6f2b3bd4c2a501f93c337cee..1bb1b88780cefc4cd69e88e15d4e1f5413c55d1e 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spi/spi.h>
+#include <linux/of_spi.h>
 
 
 /* SPI bustype and spi_master class are registered after board init code
@@ -540,6 +541,9 @@ int spi_register_master(struct spi_master *master)
        /* populate children from any spi device tables */
        scan_boardinfo(master);
        status = 0;
+
+       /* Register devices from the device tree */
+       of_register_spi_devices(master);
 done:
        return status;
 }
index 97ab0a81338adf036bea9e706dbcbe552b6d607c..aad9ae1b9c69093b829aa09c942b7a8a8b53dd78 100644 (file)
@@ -38,7 +38,6 @@
 #include <linux/of_platform.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/of_spi.h>
 #include <linux/slab.h>
 
 #include <sysdev/fsl_soc.h>
@@ -1009,6 +1008,7 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
        master->setup = mpc8xxx_spi_setup;
        master->transfer = mpc8xxx_spi_transfer;
        master->cleanup = mpc8xxx_spi_cleanup;
+       master->dev.of_node = dev->of_node;
 
        mpc8xxx_spi = spi_master_get_devdata(master);
        mpc8xxx_spi->dev = dev;
@@ -1299,8 +1299,6 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
                goto err;
        }
 
-       of_register_spi_devices(master, np);
-
        return 0;
 
 err:
index d53466a249d9700bb9108478a5b08ffcf1955b6a..0f5fa7e2a55041f6f4695bcd4f54f2f2167ff6d7 100644 (file)
@@ -407,6 +407,7 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
        master = spi_alloc_master(dev, sizeof *hw);
        if (master == NULL)
                return -ENOMEM;
+       master->dev.of_node = np;
        dev_set_drvdata(dev, master);
        hw = spi_master_get_devdata(master);
        hw->master = spi_master_get(master);
@@ -545,7 +546,6 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
        }
 
        dev_info(dev, "driver initialized\n");
-       of_register_spi_devices(master, np);
 
        return 0;
 
index 1b47363cb73f6d8c624b0af5bc44d2047e6ae8a7..80f2db5bcfd6e669bdd136c25f2d04ebb51d4595 100644 (file)
@@ -390,6 +390,9 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 
        master->bus_num = bus_num;
        master->num_chipselect = pdata->num_chipselect;
+#ifdef CONFIG_OF
+       master->dev.of_node = dev->of_node;
+#endif
 
        xspi->mem = *mem;
        xspi->irq = irq;
index 4654805b08d887f8b44460ef174941040effc0b6..87cda0956a83f5ccaea7ada8bff1cc2ac15c9cff 100644 (file)
@@ -80,9 +80,6 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
 
        dev_set_drvdata(&ofdev->dev, master);
 
-       /* Add any subnodes on the SPI bus */
-       of_register_spi_devices(master, ofdev->dev.of_node);
-
        return 0;
 }
 
index 5f71ee8c0868d6d549ded2ca2ffbbfa837160584..9e3e70f78ae64c4077917d330923d9868e290cfc 100644 (file)
@@ -9,10 +9,15 @@
 #ifndef __LINUX_OF_SPI_H
 #define __LINUX_OF_SPI_H
 
-#include <linux/of.h>
 #include <linux/spi/spi.h>
 
-extern void of_register_spi_devices(struct spi_master *master,
-                                   struct device_node *np);
+#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
+extern void of_register_spi_devices(struct spi_master *master);
+#else
+static inline void of_register_spi_devices(struct spi_master *master)
+{
+       return;
+}
+#endif /* CONFIG_OF_SPI */
 
 #endif /* __LINUX_OF_SPI */