2 * Glue code for the ISP1760 driver and bus
3 * Currently there is support for
6 * - PDEV (generic platform device centralized driver model)
8 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
12 #include <linux/usb.h>
14 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/usb/isp1760.h>
19 #include <linux/usb/hcd.h>
21 #include "isp1760-hcd.h"
24 #include <linux/pci.h>
28 static int isp1761_pci_probe(struct pci_dev *dev,
29 const struct pci_device_id *id)
35 unsigned int devflags = 0;
38 resource_size_t pci_mem_phy0;
39 resource_size_t memlength;
41 u8 __iomem *chip_addr;
43 resource_size_t nxp_pci_io_base;
44 resource_size_t iolength;
49 if (pci_enable_device(dev) < 0)
55 /* Grab the PLX PCI mem maped port start address we need */
56 nxp_pci_io_base = pci_resource_start(dev, 0);
57 iolength = pci_resource_len(dev, 0);
59 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
60 printk(KERN_ERR "request region #1\n");
64 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
66 printk(KERN_ERR "ioremap #1\n");
70 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
71 pci_mem_phy0 = pci_resource_start(dev, 3);
72 memlength = pci_resource_len(dev, 3);
73 if (memlength < 0xffff) {
74 printk(KERN_ERR "memory length for this resource is wrong\n");
79 if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) {
80 printk(KERN_ERR "host controller already in use\n");
85 /* map available memory */
86 chip_addr = ioremap_nocache(pci_mem_phy0,memlength);
88 printk(KERN_ERR "Error ioremap failed\n");
93 /* bad pci latencies can contribute to overruns */
94 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
96 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
97 if (limit && limit < latency)
98 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
101 /* Try to check whether we can access Scratch Register of
102 * Host Controller or not. The initial PCI access is retried until
103 * local init for the PCI bridge is completed
107 while ((reg_data != 0xFACE) && retry_count) {
108 /*by default host is in 16bit mode, so
109 * io operations at this stage must be 16 bit
111 writel(0xface, chip_addr + HC_SCRATCH_REG);
113 reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff;
119 /* Host Controller presence is detected by writing to scratch register
120 * and reading back and checking the contents are same or not
122 if (reg_data != 0xFACE) {
123 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
124 ret_status = -ENOMEM;
130 /* configure PLX PCI chip to pass interrupts */
131 #define PLX_INT_CSR_REG 0x68
132 reg_data = readl(iobase + PLX_INT_CSR_REG);
134 writel(reg_data, iobase + PLX_INT_CSR_REG);
136 dev->dev.dma_mask = NULL;
137 hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq,
138 IRQF_SHARED, &dev->dev, dev_name(&dev->dev),
141 ret_status = -ENODEV;
145 /* done with PLX IO access */
147 release_mem_region(nxp_pci_io_base, iolength);
152 release_mem_region(pci_mem_phy0, memlength);
156 release_mem_region(nxp_pci_io_base, iolength);
160 static void isp1761_pci_remove(struct pci_dev *dev)
162 isp1760_unregister(&dev->dev);
164 pci_disable_device(dev);
167 static void isp1761_pci_shutdown(struct pci_dev *dev)
169 printk(KERN_ERR "ips1761_pci_shutdown\n");
172 static const struct pci_device_id isp1760_plx [] = {
174 .class = PCI_CLASS_BRIDGE_OTHER << 8,
176 .vendor = PCI_VENDOR_ID_PLX,
178 .subvendor = PCI_VENDOR_ID_PLX,
183 MODULE_DEVICE_TABLE(pci, isp1760_plx);
185 static struct pci_driver isp1761_pci_driver = {
187 .id_table = isp1760_plx,
188 .probe = isp1761_pci_probe,
189 .remove = isp1761_pci_remove,
190 .shutdown = isp1761_pci_shutdown,
194 static int isp1760_plat_probe(struct platform_device *pdev)
196 unsigned long irqflags = IRQF_SHARED;
197 unsigned int devflags = 0;
198 struct resource *mem_res;
199 struct resource *irq_res;
200 resource_size_t mem_size;
204 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
206 pr_warning("isp1760: Memory resource not available\n");
209 mem_size = resource_size(mem_res);
210 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) {
211 pr_warning("isp1760: Cannot reserve the memory resource\n");
215 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
217 pr_warning("isp1760: IRQ resource not available\n");
222 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
224 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
225 struct device_node *dp = pdev->dev.of_node;
228 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
229 devflags |= ISP1760_FLAG_ISP1761;
231 /* Some systems wire up only 16 of the 32 data lines */
232 of_property_read_u32(dp, "bus-width", &bus_width);
234 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
236 if (of_property_read_bool(dp, "port1-otg"))
237 devflags |= ISP1760_FLAG_OTG_EN;
239 if (of_property_read_bool(dp, "analog-oc"))
240 devflags |= ISP1760_FLAG_ANALOG_OC;
242 if (of_property_read_bool(dp, "dack-polarity"))
243 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
245 if (of_property_read_bool(dp, "dreq-polarity"))
246 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
247 } else if (dev_get_platdata(&pdev->dev)) {
248 struct isp1760_platform_data *pdata =
249 dev_get_platdata(&pdev->dev);
251 if (pdata->is_isp1761)
252 devflags |= ISP1760_FLAG_ISP1761;
253 if (pdata->bus_width_16)
254 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
255 if (pdata->port1_otg)
256 devflags |= ISP1760_FLAG_OTG_EN;
257 if (pdata->analog_oc)
258 devflags |= ISP1760_FLAG_ANALOG_OC;
259 if (pdata->dack_polarity_high)
260 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
261 if (pdata->dreq_polarity_high)
262 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
265 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
266 irqflags, &pdev->dev, dev_name(&pdev->dev),
269 pr_warning("isp1760: Failed to register the HCD device\n");
274 pr_info("ISP1760 USB device initialised\n");
278 release_mem_region(mem_res->start, mem_size);
282 static int isp1760_plat_remove(struct platform_device *pdev)
284 isp1760_unregister(&pdev->dev);
290 static const struct of_device_id isp1760_of_match[] = {
291 { .compatible = "nxp,usb-isp1760", },
292 { .compatible = "nxp,usb-isp1761", },
295 MODULE_DEVICE_TABLE(of, isp1760_of_match);
298 static struct platform_driver isp1760_plat_driver = {
299 .probe = isp1760_plat_probe,
300 .remove = isp1760_plat_remove,
303 .of_match_table = of_match_ptr(isp1760_of_match),
307 static int __init isp1760_init(void)
309 int ret, any_ret = -ENODEV;
313 ret = platform_driver_register(&isp1760_plat_driver);
317 ret = pci_register_driver(&isp1761_pci_driver);
326 module_init(isp1760_init);
328 static void __exit isp1760_exit(void)
330 platform_driver_unregister(&isp1760_plat_driver);
332 pci_unregister_driver(&isp1761_pci_driver);
336 module_exit(isp1760_exit);