Linux Audio

Check our new training course

Yocto distribution development and maintenance

Need a Yocto distribution for your embedded project?
Loading...
v3.5.6
  1/*
  2 * CE4100's SPI device is more or less the same one as found on PXA
  3 *
  4 */
  5#include <linux/pci.h>
  6#include <linux/platform_device.h>
  7#include <linux/of_device.h>
  8#include <linux/module.h>
  9#include <linux/spi/pxa2xx_spi.h>
 10
 11struct ce4100_info {
 12	struct ssp_device ssp;
 13	struct platform_device *spi_pdev;
 14};
 15
 16static DEFINE_MUTEX(ssp_lock);
 17static LIST_HEAD(ssp_list);
 18
 19struct ssp_device *pxa_ssp_request(int port, const char *label)
 20{
 21	struct ssp_device *ssp = NULL;
 22
 23	mutex_lock(&ssp_lock);
 24
 25	list_for_each_entry(ssp, &ssp_list, node) {
 26		if (ssp->port_id == port && ssp->use_count == 0) {
 27			ssp->use_count++;
 28			ssp->label = label;
 29			break;
 30		}
 31	}
 32
 33	mutex_unlock(&ssp_lock);
 34
 35	if (&ssp->node == &ssp_list)
 36		return NULL;
 37
 38	return ssp;
 39}
 40EXPORT_SYMBOL_GPL(pxa_ssp_request);
 41
 42void pxa_ssp_free(struct ssp_device *ssp)
 43{
 44	mutex_lock(&ssp_lock);
 45	if (ssp->use_count) {
 46		ssp->use_count--;
 47		ssp->label = NULL;
 48	} else
 49		dev_err(&ssp->pdev->dev, "device already free\n");
 50	mutex_unlock(&ssp_lock);
 51}
 52EXPORT_SYMBOL_GPL(pxa_ssp_free);
 53
 54static int __devinit ce4100_spi_probe(struct pci_dev *dev,
 55		const struct pci_device_id *ent)
 56{
 
 57	int ret;
 58	resource_size_t phys_beg;
 59	resource_size_t phys_len;
 60	struct ce4100_info *spi_info;
 61	struct platform_device *pdev;
 62	struct pxa2xx_spi_master spi_pdata;
 63	struct ssp_device *ssp;
 64
 65	ret = pci_enable_device(dev);
 66	if (ret)
 67		return ret;
 68
 69	phys_beg = pci_resource_start(dev, 0);
 70	phys_len = pci_resource_len(dev, 0);
 71
 72	if (!request_mem_region(phys_beg, phys_len,
 73				"CE4100 SPI")) {
 74		dev_err(&dev->dev, "Can't request register space.\n");
 75		ret = -EBUSY;
 76		return ret;
 77	}
 78
 79	pdev = platform_device_alloc("pxa2xx-spi", dev->devfn);
 80	spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL);
 81	if (!pdev || !spi_info ) {
 82		ret = -ENOMEM;
 83		goto err_nomem;
 84	}
 85	memset(&spi_pdata, 0, sizeof(spi_pdata));
 86	spi_pdata.num_chipselect = dev->devfn;
 87
 88	ret = platform_device_add_data(pdev, &spi_pdata, sizeof(spi_pdata));
 89	if (ret)
 90		goto err_nomem;
 91
 92	pdev->dev.parent = &dev->dev;
 93	pdev->dev.of_node = dev->dev.of_node;
 94	ssp = &spi_info->ssp;
 95	ssp->phys_base = pci_resource_start(dev, 0);
 96	ssp->mmio_base = ioremap(phys_beg, phys_len);
 97	if (!ssp->mmio_base) {
 98		dev_err(&pdev->dev, "failed to ioremap() registers\n");
 99		ret = -EIO;
100		goto err_nomem;
101	}
102	ssp->irq = dev->irq;
103	ssp->port_id = pdev->id;
104	ssp->type = PXA25x_SSP;
105
106	mutex_lock(&ssp_lock);
107	list_add(&ssp->node, &ssp_list);
108	mutex_unlock(&ssp_lock);
109
110	pci_set_drvdata(dev, spi_info);
 
 
 
 
 
111
112	ret = platform_device_add(pdev);
113	if (ret)
114		goto err_dev_add;
115
116	return ret;
117
118err_dev_add:
119	pci_set_drvdata(dev, NULL);
120	mutex_lock(&ssp_lock);
121	list_del(&ssp->node);
122	mutex_unlock(&ssp_lock);
123	iounmap(ssp->mmio_base);
124
125err_nomem:
126	release_mem_region(phys_beg, phys_len);
127	platform_device_put(pdev);
128	kfree(spi_info);
129	return ret;
130}
131
132static void __devexit ce4100_spi_remove(struct pci_dev *dev)
133{
134	struct ce4100_info *spi_info;
135	struct ssp_device *ssp;
136
137	spi_info = pci_get_drvdata(dev);
138	ssp = &spi_info->ssp;
139	platform_device_unregister(spi_info->spi_pdev);
140
141	iounmap(ssp->mmio_base);
142	release_mem_region(pci_resource_start(dev, 0),
143			pci_resource_len(dev, 0));
144
145	mutex_lock(&ssp_lock);
146	list_del(&ssp->node);
147	mutex_unlock(&ssp_lock);
148
149	pci_set_drvdata(dev, NULL);
150	pci_disable_device(dev);
151	kfree(spi_info);
152}
153
154static DEFINE_PCI_DEVICE_TABLE(ce4100_spi_devices) = {
155	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) },
156	{ },
157};
158MODULE_DEVICE_TABLE(pci, ce4100_spi_devices);
159
160static struct pci_driver ce4100_spi_driver = {
161	.name           = "ce4100_spi",
162	.id_table       = ce4100_spi_devices,
163	.probe          = ce4100_spi_probe,
164	.remove         = __devexit_p(ce4100_spi_remove),
165};
166
167module_pci_driver(ce4100_spi_driver);
168
169MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
170MODULE_LICENSE("GPL v2");
171MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
v3.15
 1/*
 2 * CE4100's SPI device is more or less the same one as found on PXA
 3 *
 4 */
 5#include <linux/pci.h>
 6#include <linux/platform_device.h>
 7#include <linux/of_device.h>
 8#include <linux/module.h>
 9#include <linux/spi/pxa2xx_spi.h>
10
11static int ce4100_spi_probe(struct pci_dev *dev,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12		const struct pci_device_id *ent)
13{
14	struct platform_device_info pi;
15	int ret;
 
 
 
16	struct platform_device *pdev;
17	struct pxa2xx_spi_master spi_pdata;
18	struct ssp_device *ssp;
19
20	ret = pcim_enable_device(dev);
21	if (ret)
22		return ret;
23
24	ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
25	if (ret)
 
 
 
 
 
26		return ret;
 
27
 
 
 
 
 
 
28	memset(&spi_pdata, 0, sizeof(spi_pdata));
29	spi_pdata.num_chipselect = dev->devfn;
30
31	ssp = &spi_pdata.ssp;
 
 
 
 
 
 
32	ssp->phys_base = pci_resource_start(dev, 0);
33	ssp->mmio_base = pcim_iomap_table(dev)[0];
34	if (!ssp->mmio_base) {
35		dev_err(&dev->dev, "failed to ioremap() registers\n");
36		return -EIO;
 
37	}
38	ssp->irq = dev->irq;
39	ssp->port_id = dev->devfn;
40	ssp->type = PXA25x_SSP;
41
42	memset(&pi, 0, sizeof(pi));
43	pi.parent = &dev->dev;
44	pi.name = "pxa2xx-spi";
45	pi.id = ssp->port_id;
46	pi.data = &spi_pdata;
47	pi.size_data = sizeof(spi_pdata);
48
49	pdev = platform_device_register_full(&pi);
50	if (IS_ERR(pdev))
51		return PTR_ERR(pdev);
52
53	pci_set_drvdata(dev, pdev);
 
 
 
 
54
55	return 0;
 
 
 
 
 
 
 
 
 
 
 
56}
57
58static void ce4100_spi_remove(struct pci_dev *dev)
59{
60	struct platform_device *pdev = pci_get_drvdata(dev);
 
61
62	platform_device_unregister(pdev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63}
64
65static const struct pci_device_id ce4100_spi_devices[] = {
66	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) },
67	{ },
68};
69MODULE_DEVICE_TABLE(pci, ce4100_spi_devices);
70
71static struct pci_driver ce4100_spi_driver = {
72	.name           = "ce4100_spi",
73	.id_table       = ce4100_spi_devices,
74	.probe          = ce4100_spi_probe,
75	.remove         = ce4100_spi_remove,
76};
77
78module_pci_driver(ce4100_spi_driver);
79
80MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
81MODULE_LICENSE("GPL v2");
82MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");