]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/spi/spi-pxa2xx-pci.c
Merge commit 'tags/spi-pxa2xx-clk' into for-linus
[mirror_ubuntu-artful-kernel.git] / drivers / spi / spi-pxa2xx-pci.c
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 #include <linux/clk.h>
11 #include <linux/clk-provider.h>
12
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;
26 unsigned long max_clk_rate;
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,
38 .max_clk_rate = 3686400,
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,
48 .max_clk_rate = 50000000,
49 },
50 };
51
52 static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
53 const struct pci_device_id *ent)
54 {
55 struct platform_device_info pi;
56 int ret;
57 struct platform_device *pdev;
58 struct pxa2xx_spi_master spi_pdata;
59 struct ssp_device *ssp;
60 struct pxa_spi_info *c;
61 char buf[40];
62
63 ret = pcim_enable_device(dev);
64 if (ret)
65 return ret;
66
67 ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
68 if (ret)
69 return ret;
70
71 c = &spi_info_configs[ent->driver_data];
72
73 memset(&spi_pdata, 0, sizeof(spi_pdata));
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;
81
82 ssp = &spi_pdata.ssp;
83 ssp->phys_base = pci_resource_start(dev, 0);
84 ssp->mmio_base = pcim_iomap_table(dev)[0];
85 if (!ssp->mmio_base) {
86 dev_err(&dev->dev, "failed to ioremap() registers\n");
87 return -EIO;
88 }
89 ssp->irq = dev->irq;
90 ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
91 ssp->type = c->type;
92
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
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);
105
106 pdev = platform_device_register_full(&pi);
107 if (IS_ERR(pdev)) {
108 clk_unregister(ssp->clk);
109 return PTR_ERR(pdev);
110 }
111
112 pci_set_drvdata(dev, pdev);
113
114 return 0;
115 }
116
117 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
118 {
119 struct platform_device *pdev = pci_get_drvdata(dev);
120 struct pxa2xx_spi_master *spi_pdata;
121
122 spi_pdata = dev_get_platdata(&pdev->dev);
123
124 platform_device_unregister(pdev);
125 clk_unregister(spi_pdata->ssp.clk);
126 pci_set_drvdata(dev, NULL);
127 }
128
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 },
132 { },
133 };
134 MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
135
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,
141 };
142
143 module_pci_driver(pxa2xx_spi_pci_driver);
144
145 MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
146 MODULE_LICENSE("GPL v2");
147 MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");