diff options
author | Richard Röjfors <richard.rojfors@mocean-labs.com> | 2009-11-13 06:28:39 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2009-12-08 20:48:14 -0500 |
commit | d5af91a1faca68e9a8cc493b85aa7b194b6128aa (patch) | |
tree | e5948bf1cb4e6e2b9d20392d9542da43559c1810 /drivers/spi/xilinx_spi_of.c | |
parent | b8d4e2ce60b63294e3408d1c5211b8a8dc4af095 (diff) |
xilinx_spi: Split into of driver and generic part.
This patch splits the xilinx_spi driver into a generic part and a
OF driver part.
The reason for this is to later add in a platform driver as well.
Tested-by: John Linn <John.Linn@xilinx.com>
Signed-off-by: Richard Röjfors <richard.rojfors@mocean-labs.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/spi/xilinx_spi_of.c')
-rw-r--r-- | drivers/spi/xilinx_spi_of.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c new file mode 100644 index 000000000000..151aa13494bd --- /dev/null +++ b/drivers/spi/xilinx_spi_of.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Xilinx SPI OF device driver | ||
3 | * | ||
4 | * Copyright (c) 2009 Intel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | */ | ||
19 | |||
20 | /* Supports: | ||
21 | * Xilinx SPI devices as OF devices | ||
22 | * | ||
23 | * Inspired by xilinx_spi.c, 2002-2007 (c) MontaVista Software, Inc. | ||
24 | */ | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include <linux/io.h> | ||
30 | |||
31 | #include <linux/of_platform.h> | ||
32 | #include <linux/of_device.h> | ||
33 | #include <linux/of_spi.h> | ||
34 | |||
35 | #include <linux/spi/xilinx_spi.h> | ||
36 | #include "xilinx_spi.h" | ||
37 | |||
38 | |||
39 | static int __devinit xilinx_spi_of_probe(struct of_device *ofdev, | ||
40 | const struct of_device_id *match) | ||
41 | { | ||
42 | struct spi_master *master; | ||
43 | struct xspi_platform_data *pdata; | ||
44 | struct resource r_mem; | ||
45 | struct resource r_irq; | ||
46 | int rc = 0; | ||
47 | const u32 *prop; | ||
48 | int len; | ||
49 | |||
50 | rc = of_address_to_resource(ofdev->node, 0, &r_mem); | ||
51 | if (rc) { | ||
52 | dev_warn(&ofdev->dev, "invalid address\n"); | ||
53 | return rc; | ||
54 | } | ||
55 | |||
56 | rc = of_irq_to_resource(ofdev->node, 0, &r_irq); | ||
57 | if (rc == NO_IRQ) { | ||
58 | dev_warn(&ofdev->dev, "no IRQ found\n"); | ||
59 | return -ENODEV; | ||
60 | } | ||
61 | |||
62 | ofdev->dev.platform_data = | ||
63 | kzalloc(sizeof(struct xspi_platform_data), GFP_KERNEL); | ||
64 | pdata = ofdev->dev.platform_data; | ||
65 | if (!pdata) | ||
66 | return -ENOMEM; | ||
67 | |||
68 | /* number of slave select bits is required */ | ||
69 | prop = of_get_property(ofdev->node, "xlnx,num-ss-bits", &len); | ||
70 | if (!prop || len < sizeof(*prop)) { | ||
71 | dev_warn(&ofdev->dev, "no 'xlnx,num-ss-bits' property\n"); | ||
72 | return -EINVAL; | ||
73 | } | ||
74 | pdata->num_chipselect = *prop; | ||
75 | master = xilinx_spi_init(&ofdev->dev, &r_mem, r_irq.start, -1); | ||
76 | if (!master) | ||
77 | return -ENODEV; | ||
78 | |||
79 | dev_set_drvdata(&ofdev->dev, master); | ||
80 | |||
81 | /* Add any subnodes on the SPI bus */ | ||
82 | of_register_spi_devices(master, ofdev->node); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static int __devexit xilinx_spi_remove(struct of_device *ofdev) | ||
88 | { | ||
89 | xilinx_spi_deinit(dev_get_drvdata(&ofdev->dev)); | ||
90 | dev_set_drvdata(&ofdev->dev, 0); | ||
91 | kfree(ofdev->dev.platform_data); | ||
92 | ofdev->dev.platform_data = NULL; | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static int __exit xilinx_spi_of_remove(struct of_device *op) | ||
97 | { | ||
98 | return xilinx_spi_remove(op); | ||
99 | } | ||
100 | |||
101 | static struct of_device_id xilinx_spi_of_match[] = { | ||
102 | { .compatible = "xlnx,xps-spi-2.00.a", }, | ||
103 | { .compatible = "xlnx,xps-spi-2.00.b", }, | ||
104 | {} | ||
105 | }; | ||
106 | |||
107 | MODULE_DEVICE_TABLE(of, xilinx_spi_of_match); | ||
108 | |||
109 | static struct of_platform_driver xilinx_spi_of_driver = { | ||
110 | .match_table = xilinx_spi_of_match, | ||
111 | .probe = xilinx_spi_of_probe, | ||
112 | .remove = __exit_p(xilinx_spi_of_remove), | ||
113 | .driver = { | ||
114 | .name = "xilinx-xps-spi", | ||
115 | .owner = THIS_MODULE, | ||
116 | }, | ||
117 | }; | ||
118 | |||
119 | static int __init xilinx_spi_of_init(void) | ||
120 | { | ||
121 | return of_register_platform_driver(&xilinx_spi_of_driver); | ||
122 | } | ||
123 | module_init(xilinx_spi_of_init); | ||
124 | |||
125 | static void __exit xilinx_spi_of_exit(void) | ||
126 | { | ||
127 | of_unregister_platform_driver(&xilinx_spi_of_driver); | ||
128 | } | ||
129 | module_exit(xilinx_spi_of_exit); | ||
130 | |||
131 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); | ||
132 | MODULE_DESCRIPTION("Xilinx SPI platform driver"); | ||
133 | MODULE_LICENSE("GPL v2"); | ||