]>
Commit | Line | Data |
---|---|---|
d6ea3df0 SAS |
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> | |
d7614de4 | 8 | #include <linux/module.h> |
d6ea3df0 | 9 | #include <linux/spi/pxa2xx_spi.h> |
afa93c90 CCE |
10 | #include <linux/clk.h> |
11 | #include <linux/clk-provider.h> | |
d6ea3df0 | 12 | |
d6ba32d5 CCE |
13 | enum { |
14 | PORT_CE4100, | |
15 | PORT_BYT, | |
16 | }; | |
17 | ||
18 | struct pxa_spi_info { | |
19 | enum pxa_ssp_type type; | |
20 | int port_id; | |
21 | int num_chipselect; | |
22 | int tx_slave_id; | |
23 | int tx_chan_id; | |
24 | int rx_slave_id; | |
25 | int rx_chan_id; | |
afa93c90 | 26 | unsigned long max_clk_rate; |
d6ba32d5 CCE |
27 | }; |
28 | ||
29 | static struct pxa_spi_info spi_info_configs[] = { | |
30 | [PORT_CE4100] = { | |
31 | .type = PXA25x_SSP, | |
32 | .port_id = -1, | |
33 | .num_chipselect = -1, | |
34 | .tx_slave_id = -1, | |
35 | .tx_chan_id = -1, | |
36 | .rx_slave_id = -1, | |
37 | .rx_chan_id = -1, | |
afa93c90 | 38 | .max_clk_rate = 3686400, |
d6ba32d5 CCE |
39 | }, |
40 | [PORT_BYT] = { | |
41 | .type = LPSS_SSP, | |
42 | .port_id = 0, | |
43 | .num_chipselect = 1, | |
44 | .tx_slave_id = 0, | |
45 | .tx_chan_id = 0, | |
46 | .rx_slave_id = 1, | |
47 | .rx_chan_id = 1, | |
afa93c90 | 48 | .max_clk_rate = 50000000, |
d6ba32d5 CCE |
49 | }, |
50 | }; | |
51 | ||
52 | static int pxa2xx_spi_pci_probe(struct pci_dev *dev, | |
d6ea3df0 SAS |
53 | const struct pci_device_id *ent) |
54 | { | |
0202775b | 55 | struct platform_device_info pi; |
d6ea3df0 | 56 | int ret; |
d6ea3df0 | 57 | struct platform_device *pdev; |
0f3e1d27 | 58 | struct pxa2xx_spi_master spi_pdata; |
d6ea3df0 | 59 | struct ssp_device *ssp; |
d6ba32d5 | 60 | struct pxa_spi_info *c; |
afa93c90 | 61 | char buf[40]; |
d6ea3df0 | 62 | |
0202775b | 63 | ret = pcim_enable_device(dev); |
d6ea3df0 SAS |
64 | if (ret) |
65 | return ret; | |
66 | ||
0202775b | 67 | ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI"); |
c1346340 | 68 | if (ret) |
d6ea3df0 | 69 | return ret; |
d6ea3df0 | 70 | |
d6ba32d5 CCE |
71 | c = &spi_info_configs[ent->driver_data]; |
72 | ||
0f3e1d27 | 73 | memset(&spi_pdata, 0, sizeof(spi_pdata)); |
d6ba32d5 CCE |
74 | spi_pdata.num_chipselect = (c->num_chipselect > 0) ? |
75 | c->num_chipselect : dev->devfn; | |
76 | spi_pdata.tx_slave_id = c->tx_slave_id; | |
77 | spi_pdata.tx_chan_id = c->tx_chan_id; | |
78 | spi_pdata.rx_slave_id = c->rx_slave_id; | |
79 | spi_pdata.rx_chan_id = c->rx_chan_id; | |
80 | spi_pdata.enable_dma = c->rx_slave_id >= 0 && c->tx_slave_id >= 0; | |
d6ea3df0 | 81 | |
851bacf5 | 82 | ssp = &spi_pdata.ssp; |
d6ea3df0 | 83 | ssp->phys_base = pci_resource_start(dev, 0); |
0202775b | 84 | ssp->mmio_base = pcim_iomap_table(dev)[0]; |
d6ea3df0 | 85 | if (!ssp->mmio_base) { |
0202775b MW |
86 | dev_err(&dev->dev, "failed to ioremap() registers\n"); |
87 | return -EIO; | |
d6ea3df0 SAS |
88 | } |
89 | ssp->irq = dev->irq; | |
d6ba32d5 CCE |
90 | ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn; |
91 | ssp->type = c->type; | |
d6ea3df0 | 92 | |
afa93c90 CCE |
93 | snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id); |
94 | ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, | |
95 | CLK_IS_ROOT, c->max_clk_rate); | |
96 | if (IS_ERR(ssp->clk)) | |
97 | return PTR_ERR(ssp->clk); | |
98 | ||
0202775b MW |
99 | memset(&pi, 0, sizeof(pi)); |
100 | pi.parent = &dev->dev; | |
101 | pi.name = "pxa2xx-spi"; | |
102 | pi.id = ssp->port_id; | |
103 | pi.data = &spi_pdata; | |
104 | pi.size_data = sizeof(spi_pdata); | |
d6ea3df0 | 105 | |
0202775b | 106 | pdev = platform_device_register_full(&pi); |
afa93c90 CCE |
107 | if (IS_ERR(pdev)) { |
108 | clk_unregister(ssp->clk); | |
d77b5382 | 109 | return PTR_ERR(pdev); |
afa93c90 | 110 | } |
d6ea3df0 | 111 | |
851bacf5 | 112 | pci_set_drvdata(dev, pdev); |
d6ea3df0 | 113 | |
0202775b | 114 | return 0; |
d6ea3df0 SAS |
115 | } |
116 | ||
d6ba32d5 | 117 | static void pxa2xx_spi_pci_remove(struct pci_dev *dev) |
d6ea3df0 | 118 | { |
851bacf5 | 119 | struct platform_device *pdev = pci_get_drvdata(dev); |
afa93c90 CCE |
120 | struct pxa2xx_spi_master *spi_pdata; |
121 | ||
122 | spi_pdata = dev_get_platdata(&pdev->dev); | |
d6ea3df0 | 123 | |
851bacf5 | 124 | platform_device_unregister(pdev); |
afa93c90 CCE |
125 | clk_unregister(spi_pdata->ssp.clk); |
126 | pci_set_drvdata(dev, NULL); | |
d6ea3df0 SAS |
127 | } |
128 | ||
d6ba32d5 CCE |
129 | static const struct pci_device_id pxa2xx_spi_pci_devices[] = { |
130 | { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 }, | |
131 | { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT }, | |
d6ea3df0 SAS |
132 | { }, |
133 | }; | |
d6ba32d5 | 134 | MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices); |
d6ea3df0 | 135 | |
d6ba32d5 CCE |
136 | static struct pci_driver pxa2xx_spi_pci_driver = { |
137 | .name = "pxa2xx_spi_pci", | |
138 | .id_table = pxa2xx_spi_pci_devices, | |
139 | .probe = pxa2xx_spi_pci_probe, | |
140 | .remove = pxa2xx_spi_pci_remove, | |
d6ea3df0 SAS |
141 | }; |
142 | ||
d6ba32d5 | 143 | module_pci_driver(pxa2xx_spi_pci_driver); |
d6ea3df0 | 144 | |
d6ba32d5 | 145 | MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver"); |
d6ea3df0 SAS |
146 | MODULE_LICENSE("GPL v2"); |
147 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); |