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)
9 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
13 #include <linux/usb.h>
15 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
19 #include <linux/usb/isp1760.h>
20 #include <linux/usb/hcd.h>
22 #include "isp1760-core.h"
23 #include "isp1760-regs.h"
26 #include <linux/pci.h>
30 static int isp1761_pci_init(struct pci_dev *dev)
32 resource_size_t mem_start;
33 resource_size_t mem_length;
39 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
40 mem_start = pci_resource_start(dev, 3);
41 mem_length = pci_resource_len(dev, 3);
42 if (mem_length < 0xffff) {
43 printk(KERN_ERR "memory length for this resource is wrong\n");
47 if (!request_mem_region(mem_start, mem_length, "ISP-PCI")) {
48 printk(KERN_ERR "host controller already in use\n");
52 /* map available memory */
53 iobase = ioremap_nocache(mem_start, mem_length);
55 printk(KERN_ERR "Error ioremap failed\n");
56 release_mem_region(mem_start, mem_length);
60 /* bad pci latencies can contribute to overruns */
61 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
63 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
64 if (limit && limit < latency)
65 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
68 /* Try to check whether we can access Scratch Register of
69 * Host Controller or not. The initial PCI access is retried until
70 * local init for the PCI bridge is completed
74 while ((reg_data != 0xFACE) && retry_count) {
75 /*by default host is in 16bit mode, so
76 * io operations at this stage must be 16 bit
78 writel(0xface, iobase + HC_SCRATCH_REG);
80 reg_data = readl(iobase + HC_SCRATCH_REG) & 0x0000ffff;
85 release_mem_region(mem_start, mem_length);
87 /* Host Controller presence is detected by writing to scratch register
88 * and reading back and checking the contents are same or not
90 if (reg_data != 0xFACE) {
91 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
95 /* Grab the PLX PCI mem maped port start address we need */
96 mem_start = pci_resource_start(dev, 0);
97 mem_length = pci_resource_len(dev, 0);
99 if (!request_mem_region(mem_start, mem_length, "ISP1761 IO MEM")) {
100 printk(KERN_ERR "request region #1\n");
104 iobase = ioremap_nocache(mem_start, mem_length);
106 printk(KERN_ERR "ioremap #1\n");
107 release_mem_region(mem_start, mem_length);
111 /* configure PLX PCI chip to pass interrupts */
112 #define PLX_INT_CSR_REG 0x68
113 reg_data = readl(iobase + PLX_INT_CSR_REG);
115 writel(reg_data, iobase + PLX_INT_CSR_REG);
117 /* done with PLX IO access */
119 release_mem_region(mem_start, mem_length);
124 static int isp1761_pci_probe(struct pci_dev *dev,
125 const struct pci_device_id *id)
127 unsigned int devflags = 0;
133 if (pci_enable_device(dev) < 0)
136 ret = isp1761_pci_init(dev);
142 dev->dev.dma_mask = NULL;
143 ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev,
151 pci_disable_device(dev);
155 static void isp1761_pci_remove(struct pci_dev *dev)
157 isp1760_unregister(&dev->dev);
159 pci_disable_device(dev);
162 static void isp1761_pci_shutdown(struct pci_dev *dev)
164 printk(KERN_ERR "ips1761_pci_shutdown\n");
167 static const struct pci_device_id isp1760_plx[] = {
169 .class = PCI_CLASS_BRIDGE_OTHER << 8,
171 .vendor = PCI_VENDOR_ID_PLX,
173 .subvendor = PCI_VENDOR_ID_PLX,
178 MODULE_DEVICE_TABLE(pci, isp1760_plx);
180 static struct pci_driver isp1761_pci_driver = {
182 .id_table = isp1760_plx,
183 .probe = isp1761_pci_probe,
184 .remove = isp1761_pci_remove,
185 .shutdown = isp1761_pci_shutdown,
189 static int isp1760_plat_probe(struct platform_device *pdev)
191 unsigned long irqflags;
192 unsigned int devflags = 0;
193 struct resource *mem_res;
194 struct resource *irq_res;
197 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
199 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
201 pr_warn("isp1760: IRQ resource not available\n");
204 irqflags = irq_res->flags & IRQF_TRIGGER_MASK;
206 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
207 struct device_node *dp = pdev->dev.of_node;
210 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
211 devflags |= ISP1760_FLAG_ISP1761;
213 /* Some systems wire up only 16 of the 32 data lines */
214 of_property_read_u32(dp, "bus-width", &bus_width);
216 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
218 if (of_property_read_bool(dp, "port1-otg"))
219 devflags |= ISP1760_FLAG_OTG_EN;
221 if (of_property_read_bool(dp, "analog-oc"))
222 devflags |= ISP1760_FLAG_ANALOG_OC;
224 if (of_property_read_bool(dp, "dack-polarity"))
225 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
227 if (of_property_read_bool(dp, "dreq-polarity"))
228 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
229 } else if (dev_get_platdata(&pdev->dev)) {
230 struct isp1760_platform_data *pdata =
231 dev_get_platdata(&pdev->dev);
233 if (pdata->is_isp1761)
234 devflags |= ISP1760_FLAG_ISP1761;
235 if (pdata->bus_width_16)
236 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
237 if (pdata->port1_otg)
238 devflags |= ISP1760_FLAG_OTG_EN;
239 if (pdata->analog_oc)
240 devflags |= ISP1760_FLAG_ANALOG_OC;
241 if (pdata->dack_polarity_high)
242 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
243 if (pdata->dreq_polarity_high)
244 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
247 ret = isp1760_register(mem_res, irq_res->start, irqflags, &pdev->dev,
252 pr_info("ISP1760 USB device initialised\n");
256 static int isp1760_plat_remove(struct platform_device *pdev)
258 isp1760_unregister(&pdev->dev);
264 static const struct of_device_id isp1760_of_match[] = {
265 { .compatible = "nxp,usb-isp1760", },
266 { .compatible = "nxp,usb-isp1761", },
269 MODULE_DEVICE_TABLE(of, isp1760_of_match);
272 static struct platform_driver isp1760_plat_driver = {
273 .probe = isp1760_plat_probe,
274 .remove = isp1760_plat_remove,
277 .of_match_table = of_match_ptr(isp1760_of_match),
281 static int __init isp1760_init(void)
283 int ret, any_ret = -ENODEV;
285 isp1760_init_kmem_once();
287 ret = platform_driver_register(&isp1760_plat_driver);
290 #ifdef CONFIG_USB_PCI
291 ret = pci_register_driver(&isp1761_pci_driver);
297 isp1760_deinit_kmem_cache();
300 module_init(isp1760_init);
302 static void __exit isp1760_exit(void)
304 platform_driver_unregister(&isp1760_plat_driver);
305 #ifdef CONFIG_USB_PCI
306 pci_unregister_driver(&isp1761_pci_driver);
308 isp1760_deinit_kmem_cache();
310 module_exit(isp1760_exit);