1 // SPDX-License-Identifier: GPL-2.0
3 * Glue code for the ISP1760 driver and bus
4 * Currently there is support for
7 * - PDEV (generic platform device centralized driver model)
14 #include <linux/usb.h>
16 #include <linux/irq.h>
17 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <linux/usb/hcd.h>
22 #include <linux/usb/otg.h>
24 #include "isp1760-core.h"
25 #include "isp1760-regs.h"
28 #include <linux/pci.h>
32 static int isp1761_pci_init(struct pci_dev *dev)
34 resource_size_t mem_start;
35 resource_size_t mem_length;
41 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
42 mem_start = pci_resource_start(dev, 3);
43 mem_length = pci_resource_len(dev, 3);
44 if (mem_length < 0xffff) {
45 printk(KERN_ERR "memory length for this resource is wrong\n");
49 if (!request_mem_region(mem_start, mem_length, "ISP-PCI")) {
50 printk(KERN_ERR "host controller already in use\n");
54 /* map available memory */
55 iobase = ioremap(mem_start, mem_length);
57 printk(KERN_ERR "Error ioremap failed\n");
58 release_mem_region(mem_start, mem_length);
62 /* bad pci latencies can contribute to overruns */
63 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
65 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
66 if (limit && limit < latency)
67 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
70 /* Try to check whether we can access Scratch Register of
71 * Host Controller or not. The initial PCI access is retried until
72 * local init for the PCI bridge is completed
76 while ((reg_data != 0xFACE) && retry_count) {
77 /*by default host is in 16bit mode, so
78 * io operations at this stage must be 16 bit
80 writel(0xface, iobase + ISP176x_HC_SCRATCH);
82 reg_data = readl(iobase + ISP176x_HC_SCRATCH) & 0x0000ffff;
87 release_mem_region(mem_start, mem_length);
89 /* Host Controller presence is detected by writing to scratch register
90 * and reading back and checking the contents are same or not
92 if (reg_data != 0xFACE) {
93 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
97 /* Grab the PLX PCI mem maped port start address we need */
98 mem_start = pci_resource_start(dev, 0);
99 mem_length = pci_resource_len(dev, 0);
101 if (!request_mem_region(mem_start, mem_length, "ISP1761 IO MEM")) {
102 printk(KERN_ERR "request region #1\n");
106 iobase = ioremap(mem_start, mem_length);
108 printk(KERN_ERR "ioremap #1\n");
109 release_mem_region(mem_start, mem_length);
113 /* configure PLX PCI chip to pass interrupts */
114 #define PLX_INT_CSR_REG 0x68
115 reg_data = readl(iobase + PLX_INT_CSR_REG);
117 writel(reg_data, iobase + PLX_INT_CSR_REG);
119 /* done with PLX IO access */
121 release_mem_region(mem_start, mem_length);
126 static int isp1761_pci_probe(struct pci_dev *dev,
127 const struct pci_device_id *id)
129 unsigned int devflags = 0;
135 if (pci_enable_device(dev) < 0)
138 ret = isp1761_pci_init(dev);
144 ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev,
152 pci_disable_device(dev);
156 static void isp1761_pci_remove(struct pci_dev *dev)
158 isp1760_unregister(&dev->dev);
160 pci_disable_device(dev);
163 static void isp1761_pci_shutdown(struct pci_dev *dev)
165 printk(KERN_ERR "ips1761_pci_shutdown\n");
168 static const struct pci_device_id isp1760_plx[] = {
170 .class = PCI_CLASS_BRIDGE_OTHER << 8,
172 .vendor = PCI_VENDOR_ID_PLX,
174 .subvendor = PCI_VENDOR_ID_PLX,
179 MODULE_DEVICE_TABLE(pci, isp1760_plx);
181 static struct pci_driver isp1761_pci_driver = {
183 .id_table = isp1760_plx,
184 .probe = isp1761_pci_probe,
185 .remove = isp1761_pci_remove,
186 .shutdown = isp1761_pci_shutdown,
190 static int isp1760_plat_probe(struct platform_device *pdev)
192 unsigned long irqflags;
193 unsigned int devflags = 0;
194 struct resource *mem_res;
198 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
200 irq = platform_get_irq(pdev, 0);
203 irqflags = irq_get_trigger_type(irq);
205 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
206 struct device_node *dp = pdev->dev.of_node;
209 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
210 devflags |= ISP1760_FLAG_ISP1761;
212 if (of_device_is_compatible(dp, "nxp,usb-isp1763"))
213 devflags |= ISP1760_FLAG_ISP1763;
216 * Some systems wire up only 8 of 16 data lines or
217 * 16 of the 32 data lines
219 of_property_read_u32(dp, "bus-width", &bus_width);
221 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
222 else if (bus_width == 8)
223 devflags |= ISP1760_FLAG_BUS_WIDTH_8;
225 if (usb_get_dr_mode(&pdev->dev) == USB_DR_MODE_PERIPHERAL)
226 devflags |= ISP1760_FLAG_PERIPHERAL_EN;
228 if (of_property_read_bool(dp, "analog-oc"))
229 devflags |= ISP1760_FLAG_ANALOG_OC;
231 if (of_property_read_bool(dp, "dack-polarity"))
232 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
234 if (of_property_read_bool(dp, "dreq-polarity"))
235 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
237 pr_err("isp1760: no platform data\n");
241 ret = isp1760_register(mem_res, irq, irqflags, &pdev->dev, devflags);
245 pr_info("ISP1760 USB device initialised\n");
249 static void isp1760_plat_remove(struct platform_device *pdev)
251 isp1760_unregister(&pdev->dev);
255 static const struct of_device_id isp1760_of_match[] = {
256 { .compatible = "nxp,usb-isp1760", },
257 { .compatible = "nxp,usb-isp1761", },
258 { .compatible = "nxp,usb-isp1763", },
261 MODULE_DEVICE_TABLE(of, isp1760_of_match);
264 static struct platform_driver isp1760_plat_driver = {
265 .probe = isp1760_plat_probe,
266 .remove = isp1760_plat_remove,
269 .of_match_table = of_match_ptr(isp1760_of_match),
273 static int __init isp1760_init(void)
275 int ret, any_ret = -ENODEV;
277 isp1760_init_kmem_once();
279 ret = platform_driver_register(&isp1760_plat_driver);
282 #ifdef CONFIG_USB_PCI
283 ret = pci_register_driver(&isp1761_pci_driver);
289 isp1760_deinit_kmem_cache();
292 module_init(isp1760_init);
294 static void __exit isp1760_exit(void)
296 platform_driver_unregister(&isp1760_plat_driver);
297 #ifdef CONFIG_USB_PCI
298 pci_unregister_driver(&isp1761_pci_driver);
300 isp1760_deinit_kmem_cache();
302 module_exit(isp1760_exit);