4 * Xilinx SPI controller driver (master mode only)
6 * Author: MontaVista Software, Inc.
9 * 2002-2007 (c) MontaVista Software, Inc. This file is licensed under the
10 * terms of the GNU General Public License version 2. This program is licensed
11 * "as is" without any warranty of any kind, whether express or implied.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
18 #include <linux/platform_device.h>
20 #include <linux/of_platform.h>
21 #include <linux/of_device.h>
22 #include <linux/of_spi.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/spi_bitbang.h>
27 #include "xilinx_spi.h"
30 static int __init
xilinx_spi_of_probe(struct of_device
*ofdev
,
31 const struct of_device_id
*match
)
33 struct resource r_irq_struct
;
34 struct resource r_mem_struct
;
35 struct spi_master
*master
;
37 struct resource
*r_irq
= &r_irq_struct
;
38 struct resource
*r_mem
= &r_mem_struct
;
43 rc
= of_address_to_resource(ofdev
->node
, 0, r_mem
);
45 dev_warn(&ofdev
->dev
, "invalid address\n");
49 rc
= of_irq_to_resource(ofdev
->node
, 0, r_irq
);
51 dev_warn(&ofdev
->dev
, "no IRQ found\n");
55 /* number of slave select bits is required */
56 prop
= of_get_property(ofdev
->node
, "xlnx,num-ss-bits", &len
);
57 if (!prop
|| len
< sizeof(*prop
)) {
58 dev_warn(&ofdev
->dev
, "no 'xlnx,num-ss-bits' property\n");
61 master
= xilinx_spi_init(&ofdev
->dev
, r_mem
, r_irq
->start
, -1, *prop
, 8,
64 return PTR_ERR(master
);
66 dev_set_drvdata(&ofdev
->dev
, master
);
68 /* Add any subnodes on the SPI bus */
69 of_register_spi_devices(master
, ofdev
->node
);
74 static int __devexit
xilinx_spi_remove(struct of_device
*ofdev
)
76 xilinx_spi_deinit(dev_get_drvdata(&ofdev
->dev
));
77 dev_set_drvdata(&ofdev
->dev
, 0);
81 static int __exit
xilinx_spi_of_remove(struct of_device
*op
)
83 return xilinx_spi_remove(op
);
86 static struct of_device_id xilinx_spi_of_match
[] = {
87 { .compatible
= "xlnx,xps-spi-2.00.a", },
88 { .compatible
= "xlnx,xps-spi-2.00.b", },
92 MODULE_DEVICE_TABLE(of
, xilinx_spi_of_match
);
94 static struct of_platform_driver xilinx_spi_of_driver
= {
96 .name
= "xilinx-xps-spi",
97 .match_table
= xilinx_spi_of_match
,
98 .probe
= xilinx_spi_of_probe
,
99 .remove
= __exit_p(xilinx_spi_of_remove
),
101 .name
= "xilinx-xps-spi",
102 .owner
= THIS_MODULE
,
106 static int __init
xilinx_spi_of_init(void)
108 return of_register_platform_driver(&xilinx_spi_of_driver
);
110 module_init(xilinx_spi_of_init
);
112 static void __exit
xilinx_spi_of_exit(void)
114 of_unregister_platform_driver(&xilinx_spi_of_driver
);
116 module_exit(xilinx_spi_of_exit
);
117 MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
118 MODULE_DESCRIPTION("Xilinx SPI driver");
119 MODULE_LICENSE("GPL");