2 * CE4100's SPI device is more or less the same one as found on PXA
6 #include <linux/platform_device.h>
7 #include <linux/of_device.h>
8 #include <linux/spi/pxa2xx_spi.h>
10 struct awesome_struct {
11 struct ssp_device ssp;
12 struct platform_device spi_pdev;
13 struct pxa2xx_spi_master spi_pdata;
16 static DEFINE_MUTEX(ssp_lock);
17 static LIST_HEAD(ssp_list);
19 struct ssp_device *pxa_ssp_request(int port, const char *label)
21 struct ssp_device *ssp = NULL;
23 mutex_lock(&ssp_lock);
25 list_for_each_entry(ssp, &ssp_list, node) {
26 if (ssp->port_id == port && ssp->use_count == 0) {
33 mutex_unlock(&ssp_lock);
35 if (&ssp->node == &ssp_list)
40 EXPORT_SYMBOL_GPL(pxa_ssp_request);
42 void pxa_ssp_free(struct ssp_device *ssp)
44 mutex_lock(&ssp_lock);
49 dev_err(&ssp->pdev->dev, "device already free\n");
50 mutex_unlock(&ssp_lock);
52 EXPORT_SYMBOL_GPL(pxa_ssp_free);
54 static void plat_dev_release(struct device *dev)
56 struct awesome_struct *as = container_of(dev,
57 struct awesome_struct, spi_pdev.dev);
59 of_device_node_put(&as->spi_pdev.dev);
62 static int __devinit ce4100_spi_probe(struct pci_dev *dev,
63 const struct pci_device_id *ent)
66 resource_size_t phys_beg;
67 resource_size_t phys_len;
68 struct awesome_struct *spi_info;
69 struct platform_device *pdev;
70 struct pxa2xx_spi_master *spi_pdata;
71 struct ssp_device *ssp;
73 ret = pci_enable_device(dev);
77 phys_beg = pci_resource_start(dev, 0);
78 phys_len = pci_resource_len(dev, 0);
80 if (!request_mem_region(phys_beg, phys_len,
82 dev_err(&dev->dev, "Can't request register space.\n");
87 spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL);
93 pdev = &spi_info->spi_pdev;
94 spi_pdata = &spi_info->spi_pdata;
96 pdev->name = "pxa2xx-spi";
97 pdev->id = dev->devfn;
98 pdev->dev.parent = &dev->dev;
99 pdev->dev.platform_data = &spi_info->spi_pdata;
102 pdev->dev.of_node = dev->dev.of_node;
104 pdev->dev.release = plat_dev_release;
106 spi_pdata->num_chipselect = dev->devfn;
108 ssp->phys_base = pci_resource_start(dev, 0);
109 ssp->mmio_base = ioremap(phys_beg, phys_len);
110 if (!ssp->mmio_base) {
111 dev_err(&pdev->dev, "failed to ioremap() registers\n");
116 ssp->port_id = pdev->id;
117 ssp->type = PXA25x_SSP;
119 mutex_lock(&ssp_lock);
120 list_add(&ssp->node, &ssp_list);
121 mutex_unlock(&ssp_lock);
123 pci_set_drvdata(dev, spi_info);
125 ret = platform_device_register(pdev);
132 pci_set_drvdata(dev, NULL);
133 mutex_lock(&ssp_lock);
134 list_del(&ssp->node);
135 mutex_unlock(&ssp_lock);
136 iounmap(ssp->mmio_base);
142 release_mem_region(phys_beg, phys_len);
147 static void __devexit ce4100_spi_remove(struct pci_dev *dev)
149 struct awesome_struct *spi_info;
150 struct platform_device *pdev;
151 struct ssp_device *ssp;
153 spi_info = pci_get_drvdata(dev);
155 ssp = &spi_info->ssp;
156 pdev = &spi_info->spi_pdev;
158 platform_device_unregister(pdev);
160 iounmap(ssp->mmio_base);
161 release_mem_region(pci_resource_start(dev, 0),
162 pci_resource_len(dev, 0));
164 mutex_lock(&ssp_lock);
165 list_del(&ssp->node);
166 mutex_unlock(&ssp_lock);
168 pci_set_drvdata(dev, NULL);
169 pci_disable_device(dev);
173 static struct pci_device_id ce4100_spi_devices[] __devinitdata = {
175 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) },
178 MODULE_DEVICE_TABLE(pci, ce4100_spi_devices);
180 static struct pci_driver ce4100_spi_driver = {
181 .name = "ce4100_spi",
182 .id_table = ce4100_spi_devices,
183 .probe = ce4100_spi_probe,
184 .remove = __devexit_p(ce4100_spi_remove),
187 static int __init ce4100_spi_init(void)
189 return pci_register_driver(&ce4100_spi_driver);
191 module_init(ce4100_spi_init);
193 static void __exit ce4100_spi_exit(void)
195 pci_unregister_driver(&ce4100_spi_driver);
197 module_exit(ce4100_spi_exit);
199 MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
200 MODULE_LICENSE("GPL v2");
201 MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");