a16722acafea9da91628e77b52cb2b5e053bd4bc
[pandora-kernel.git] / drivers / spi / xilinx_spi_pltfm.c
1 /*
2  * Support for Xilinx SPI platform devices
3  * Copyright (c) 2009 Intel Corporation
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 /* Supports:
20  * Xilinx SPI devices as platform devices
21  *
22  * Inspired by xilinx_spi.c, 2002-2007 (c) MontaVista Software, Inc.
23  */
24
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/io.h>
29 #include <linux/platform_device.h>
30
31 #include <linux/spi/spi.h>
32 #include <linux/spi/spi_bitbang.h>
33 #include <linux/spi/xilinx_spi.h>
34
35 #include "xilinx_spi.h"
36
37 static int __devinit xilinx_spi_probe(struct platform_device *dev)
38 {
39         struct xspi_platform_data *pdata;
40         struct resource *r;
41         int irq;
42         struct spi_master *master;
43         u8 i;
44
45         pdata = dev->dev.platform_data;
46         if (!pdata)
47                 return -ENODEV;
48
49         r = platform_get_resource(dev, IORESOURCE_MEM, 0);
50         if (!r)
51                 return -ENODEV;
52
53         irq = platform_get_irq(dev, 0);
54         if (irq < 0)
55                 return -ENXIO;
56
57         master = xilinx_spi_init(&dev->dev, r, irq, dev->id,
58                                  pdata->num_chipselect, pdata->little_endian,
59                                  pdata->bits_per_word);
60         if (!master)
61                 return -ENODEV;
62
63         for (i = 0; i < pdata->num_devices; i++)
64                 spi_new_device(master, pdata->devices + i);
65
66         platform_set_drvdata(dev, master);
67         return 0;
68 }
69
70 static int __devexit xilinx_spi_remove(struct platform_device *dev)
71 {
72         xilinx_spi_deinit(platform_get_drvdata(dev));
73         platform_set_drvdata(dev, 0);
74
75         return 0;
76 }
77
78 /* work with hotplug and coldplug */
79 MODULE_ALIAS("platform:" XILINX_SPI_NAME);
80
81 static struct platform_driver xilinx_spi_driver = {
82         .probe  = xilinx_spi_probe,
83         .remove = __devexit_p(xilinx_spi_remove),
84         .driver = {
85                 .name = XILINX_SPI_NAME,
86                 .owner = THIS_MODULE,
87         },
88 };
89
90 static int __init xilinx_spi_pltfm_init(void)
91 {
92         return platform_driver_register(&xilinx_spi_driver);
93 }
94 module_init(xilinx_spi_pltfm_init);
95
96 static void __exit xilinx_spi_pltfm_exit(void)
97 {
98         platform_driver_unregister(&xilinx_spi_driver);
99 }
100 module_exit(xilinx_spi_pltfm_exit);
101
102 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
103 MODULE_DESCRIPTION("Xilinx SPI platform driver");
104 MODULE_LICENSE("GPL v2");