aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2012-04-07 16:16:53 -0400
committerGrant Likely <grant.likely@secretlab.ca>2012-04-13 12:21:39 -0400
commitd57a4282d04810417c4ed2a49cbbeda8b3569b18 (patch)
tree40fbd959e4a72c7c2635f8488bbd43d0ff353b80
parent8ebb35fd7ad07ab9a88a35eedd4f89a1e2a8fa55 (diff)
spi/devicetree: Move devicetree support code into spi directory
The SPI device tree support code isn't shared by any other subsystem. It can be moved into the core drivers/spi directory and the exported symbol can be removed. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Rob Herring <rob.herring@calxeda.com>
-rw-r--r--drivers/of/Kconfig6
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/of_spi.c99
-rw-r--r--drivers/spi/spi-fsl-espi.c1
-rw-r--r--drivers/spi/spi-fsl-lib.c2
-rw-r--r--drivers/spi/spi-ppc4xx.c1
-rw-r--r--drivers/spi/spi.c92
-rw-r--r--include/linux/of_spi.h23
8 files changed, 92 insertions, 133 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 8e84ce9765a9..f623f17a0b9f 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -67,12 +67,6 @@ config OF_NET
67 depends on NETDEVICES 67 depends on NETDEVICES
68 def_bool y 68 def_bool y
69 69
70config OF_SPI
71 def_tristate SPI
72 depends on SPI && !SPARC
73 help
74 OpenFirmware SPI accessors
75
76config OF_MDIO 70config OF_MDIO
77 def_tristate PHYLIB 71 def_tristate PHYLIB
78 depends on PHYLIB 72 depends on PHYLIB
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index aa90e602c8a7..0040d1858665 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -7,7 +7,6 @@ obj-$(CONFIG_OF_DEVICE) += device.o platform.o
7obj-$(CONFIG_OF_GPIO) += gpio.o 7obj-$(CONFIG_OF_GPIO) += gpio.o
8obj-$(CONFIG_OF_I2C) += of_i2c.o 8obj-$(CONFIG_OF_I2C) += of_i2c.o
9obj-$(CONFIG_OF_NET) += of_net.o 9obj-$(CONFIG_OF_NET) += of_net.o
10obj-$(CONFIG_OF_SPI) += of_spi.o
11obj-$(CONFIG_OF_SELFTEST) += selftest.o 10obj-$(CONFIG_OF_SELFTEST) += selftest.o
12obj-$(CONFIG_OF_MDIO) += of_mdio.o 11obj-$(CONFIG_OF_MDIO) += of_mdio.o
13obj-$(CONFIG_OF_PCI) += of_pci.o 12obj-$(CONFIG_OF_PCI) += of_pci.o
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
deleted file mode 100644
index 6dbc074e4876..000000000000
--- a/drivers/of/of_spi.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * SPI OF support routines
3 * Copyright (C) 2008 Secret Lab Technologies Ltd.
4 *
5 * Support routines for deriving SPI device attachments from the device
6 * tree.
7 */
8
9#include <linux/module.h>
10#include <linux/of.h>
11#include <linux/device.h>
12#include <linux/spi/spi.h>
13#include <linux/of_irq.h>
14#include <linux/of_spi.h>
15
16/**
17 * of_register_spi_devices - Register child devices onto the SPI bus
18 * @master: Pointer to spi_master device
19 *
20 * Registers an spi_device for each child node of master node which has a 'reg'
21 * property.
22 */
23void of_register_spi_devices(struct spi_master *master)
24{
25 struct spi_device *spi;
26 struct device_node *nc;
27 const __be32 *prop;
28 int rc;
29 int len;
30
31 if (!master->dev.of_node)
32 return;
33
34 for_each_child_of_node(master->dev.of_node, nc) {
35 /* Alloc an spi_device */
36 spi = spi_alloc_device(master);
37 if (!spi) {
38 dev_err(&master->dev, "spi_device alloc error for %s\n",
39 nc->full_name);
40 spi_dev_put(spi);
41 continue;
42 }
43
44 /* Select device driver */
45 if (of_modalias_node(nc, spi->modalias,
46 sizeof(spi->modalias)) < 0) {
47 dev_err(&master->dev, "cannot find modalias for %s\n",
48 nc->full_name);
49 spi_dev_put(spi);
50 continue;
51 }
52
53 /* Device address */
54 prop = of_get_property(nc, "reg", &len);
55 if (!prop || len < sizeof(*prop)) {
56 dev_err(&master->dev, "%s has no 'reg' property\n",
57 nc->full_name);
58 spi_dev_put(spi);
59 continue;
60 }
61 spi->chip_select = be32_to_cpup(prop);
62
63 /* Mode (clock phase/polarity/etc.) */
64 if (of_find_property(nc, "spi-cpha", NULL))
65 spi->mode |= SPI_CPHA;
66 if (of_find_property(nc, "spi-cpol", NULL))
67 spi->mode |= SPI_CPOL;
68 if (of_find_property(nc, "spi-cs-high", NULL))
69 spi->mode |= SPI_CS_HIGH;
70
71 /* Device speed */
72 prop = of_get_property(nc, "spi-max-frequency", &len);
73 if (!prop || len < sizeof(*prop)) {
74 dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n",
75 nc->full_name);
76 spi_dev_put(spi);
77 continue;
78 }
79 spi->max_speed_hz = be32_to_cpup(prop);
80
81 /* IRQ */
82 spi->irq = irq_of_parse_and_map(nc, 0);
83
84 /* Store a pointer to the node in the device structure */
85 of_node_get(nc);
86 spi->dev.of_node = nc;
87
88 /* Register the new device */
89 request_module(spi->modalias);
90 rc = spi_add_device(spi);
91 if (rc) {
92 dev_err(&master->dev, "spi_device register error %s\n",
93 nc->full_name);
94 spi_dev_put(spi);
95 }
96
97 }
98}
99EXPORT_SYMBOL(of_register_spi_devices);
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 7523a2429d09..27bdc47b5250 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -17,7 +17,6 @@
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_platform.h> 19#include <linux/of_platform.h>
20#include <linux/of_spi.h>
21#include <linux/interrupt.h> 20#include <linux/interrupt.h>
22#include <linux/err.h> 21#include <linux/err.h>
23#include <sysdev/fsl_soc.h> 22#include <sysdev/fsl_soc.h>
diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c
index 2674fad7f68a..1503574b215a 100644
--- a/drivers/spi/spi-fsl-lib.c
+++ b/drivers/spi/spi-fsl-lib.c
@@ -22,7 +22,7 @@
22#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/of_platform.h> 24#include <linux/of_platform.h>
25#include <linux/of_spi.h> 25#include <linux/spi/spi.h>
26#include <sysdev/fsl_soc.h> 26#include <sysdev/fsl_soc.h>
27 27
28#include "spi-fsl-lib.h" 28#include "spi-fsl-lib.h"
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 98ec53285fc7..d95d307a1100 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -30,7 +30,6 @@
30#include <linux/errno.h> 30#include <linux/errno.h>
31#include <linux/wait.h> 31#include <linux/wait.h>
32#include <linux/of_platform.h> 32#include <linux/of_platform.h>
33#include <linux/of_spi.h>
34#include <linux/of_gpio.h> 33#include <linux/of_gpio.h>
35#include <linux/interrupt.h> 34#include <linux/interrupt.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3d8f662e4fe9..37c555ec59ab 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2,6 +2,7 @@
2 * SPI init/core code 2 * SPI init/core code
3 * 3 *
4 * Copyright (C) 2005 David Brownell 4 * Copyright (C) 2005 David Brownell
5 * Copyright (C) 2008 Secret Lab Technologies Ltd.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -19,15 +20,16 @@
19 */ 20 */
20 21
21#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/kmod.h>
22#include <linux/device.h> 24#include <linux/device.h>
23#include <linux/init.h> 25#include <linux/init.h>
24#include <linux/cache.h> 26#include <linux/cache.h>
25#include <linux/mutex.h> 27#include <linux/mutex.h>
26#include <linux/of_device.h> 28#include <linux/of_device.h>
29#include <linux/of_irq.h>
27#include <linux/slab.h> 30#include <linux/slab.h>
28#include <linux/mod_devicetable.h> 31#include <linux/mod_devicetable.h>
29#include <linux/spi/spi.h> 32#include <linux/spi/spi.h>
30#include <linux/of_spi.h>
31#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
32#include <linux/export.h> 34#include <linux/export.h>
33#include <linux/sched.h> 35#include <linux/sched.h>
@@ -798,6 +800,94 @@ err_init_queue:
798 800
799/*-------------------------------------------------------------------------*/ 801/*-------------------------------------------------------------------------*/
800 802
803#if defined(CONFIG_OF) && !defined(CONFIG_SPARC)
804/**
805 * of_register_spi_devices() - Register child devices onto the SPI bus
806 * @master: Pointer to spi_master device
807 *
808 * Registers an spi_device for each child node of master node which has a 'reg'
809 * property.
810 */
811static void of_register_spi_devices(struct spi_master *master)
812{
813 struct spi_device *spi;
814 struct device_node *nc;
815 const __be32 *prop;
816 int rc;
817 int len;
818
819 if (!master->dev.of_node)
820 return;
821
822 for_each_child_of_node(master->dev.of_node, nc) {
823 /* Alloc an spi_device */
824 spi = spi_alloc_device(master);
825 if (!spi) {
826 dev_err(&master->dev, "spi_device alloc error for %s\n",
827 nc->full_name);
828 spi_dev_put(spi);
829 continue;
830 }
831
832 /* Select device driver */
833 if (of_modalias_node(nc, spi->modalias,
834 sizeof(spi->modalias)) < 0) {
835 dev_err(&master->dev, "cannot find modalias for %s\n",
836 nc->full_name);
837 spi_dev_put(spi);
838 continue;
839 }
840
841 /* Device address */
842 prop = of_get_property(nc, "reg", &len);
843 if (!prop || len < sizeof(*prop)) {
844 dev_err(&master->dev, "%s has no 'reg' property\n",
845 nc->full_name);
846 spi_dev_put(spi);
847 continue;
848 }
849 spi->chip_select = be32_to_cpup(prop);
850
851 /* Mode (clock phase/polarity/etc.) */
852 if (of_find_property(nc, "spi-cpha", NULL))
853 spi->mode |= SPI_CPHA;
854 if (of_find_property(nc, "spi-cpol", NULL))
855 spi->mode |= SPI_CPOL;
856 if (of_find_property(nc, "spi-cs-high", NULL))
857 spi->mode |= SPI_CS_HIGH;
858
859 /* Device speed */
860 prop = of_get_property(nc, "spi-max-frequency", &len);
861 if (!prop || len < sizeof(*prop)) {
862 dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n",
863 nc->full_name);
864 spi_dev_put(spi);
865 continue;
866 }
867 spi->max_speed_hz = be32_to_cpup(prop);
868
869 /* IRQ */
870 spi->irq = irq_of_parse_and_map(nc, 0);
871
872 /* Store a pointer to the node in the device structure */
873 of_node_get(nc);
874 spi->dev.of_node = nc;
875
876 /* Register the new device */
877 request_module(spi->modalias);
878 rc = spi_add_device(spi);
879 if (rc) {
880 dev_err(&master->dev, "spi_device register error %s\n",
881 nc->full_name);
882 spi_dev_put(spi);
883 }
884
885 }
886}
887#else
888static void of_register_spi_devices(struct spi_master *master) { }
889#endif
890
801static void spi_master_release(struct device *dev) 891static void spi_master_release(struct device *dev)
802{ 892{
803 struct spi_master *master; 893 struct spi_master *master;
diff --git a/include/linux/of_spi.h b/include/linux/of_spi.h
deleted file mode 100644
index 9e3e70f78ae6..000000000000
--- a/include/linux/of_spi.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 * OpenFirmware SPI support routines
3 * Copyright (C) 2008 Secret Lab Technologies Ltd.
4 *
5 * Support routines for deriving SPI device attachments from the device
6 * tree.
7 */
8
9#ifndef __LINUX_OF_SPI_H
10#define __LINUX_OF_SPI_H
11
12#include <linux/spi/spi.h>
13
14#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
15extern void of_register_spi_devices(struct spi_master *master);
16#else
17static inline void of_register_spi_devices(struct spi_master *master)
18{
19 return;
20}
21#endif /* CONFIG_OF_SPI */
22
23#endif /* __LINUX_OF_SPI */