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>
15 #include <linux/platform_device.h>
16 #include <linux/usb/isp1760.h>
17 #include <linux/usb/hcd.h>
19 #include "isp1760-hcd.h"
21 #if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
22 #include <linux/slab.h>
24 #include <linux/of_platform.h>
25 #include <linux/of_address.h>
26 #include <linux/of_irq.h>
30 #include <linux/pci.h>
33 #if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
34 static int of_isp1760_probe(struct platform_device *dev)
37 struct device_node *dp = dev->dev.of_node;
39 struct resource memory;
41 resource_size_t res_len;
43 unsigned int devflags = 0;
46 ret = of_address_to_resource(dp, 0, &memory);
50 res_len = resource_size(&memory);
52 res = request_mem_region(memory.start, res_len, dev_name(&dev->dev));
56 virq = irq_of_parse_and_map(dp, 0);
62 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
63 devflags |= ISP1760_FLAG_ISP1761;
65 /* Some systems wire up only 16 of the 32 data lines */
66 of_property_read_u32(dp, "bus-width", &bus_width);
68 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
70 if (of_get_property(dp, "port1-otg", NULL) != NULL)
71 devflags |= ISP1760_FLAG_OTG_EN;
73 if (of_get_property(dp, "analog-oc", NULL) != NULL)
74 devflags |= ISP1760_FLAG_ANALOG_OC;
76 if (of_get_property(dp, "dack-polarity", NULL) != NULL)
77 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
79 if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
80 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
82 hcd = isp1760_register(memory.start, res_len, virq, IRQF_SHARED,
83 &dev->dev, dev_name(&dev->dev), devflags);
89 platform_set_drvdata(dev, hcd);
93 release_mem_region(memory.start, res_len);
97 static int of_isp1760_remove(struct platform_device *dev)
99 struct usb_hcd *hcd = platform_get_drvdata(dev);
103 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
109 static const struct of_device_id of_isp1760_match[] = {
111 .compatible = "nxp,usb-isp1760",
114 .compatible = "nxp,usb-isp1761",
118 MODULE_DEVICE_TABLE(of, of_isp1760_match);
120 static struct platform_driver isp1760_of_driver = {
122 .name = "nxp-isp1760",
123 .of_match_table = of_isp1760_match,
125 .probe = of_isp1760_probe,
126 .remove = of_isp1760_remove,
131 static int isp1761_pci_probe(struct pci_dev *dev,
132 const struct pci_device_id *id)
138 unsigned int devflags = 0;
141 resource_size_t pci_mem_phy0;
142 resource_size_t memlength;
144 u8 __iomem *chip_addr;
146 resource_size_t nxp_pci_io_base;
147 resource_size_t iolength;
152 if (pci_enable_device(dev) < 0)
158 /* Grab the PLX PCI mem maped port start address we need */
159 nxp_pci_io_base = pci_resource_start(dev, 0);
160 iolength = pci_resource_len(dev, 0);
162 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
163 printk(KERN_ERR "request region #1\n");
167 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
169 printk(KERN_ERR "ioremap #1\n");
170 ret_status = -ENOMEM;
173 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
174 pci_mem_phy0 = pci_resource_start(dev, 3);
175 memlength = pci_resource_len(dev, 3);
176 if (memlength < 0xffff) {
177 printk(KERN_ERR "memory length for this resource is wrong\n");
178 ret_status = -ENOMEM;
182 if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) {
183 printk(KERN_ERR "host controller already in use\n");
188 /* map available memory */
189 chip_addr = ioremap_nocache(pci_mem_phy0,memlength);
191 printk(KERN_ERR "Error ioremap failed\n");
192 ret_status = -ENOMEM;
196 /* bad pci latencies can contribute to overruns */
197 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
199 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
200 if (limit && limit < latency)
201 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
204 /* Try to check whether we can access Scratch Register of
205 * Host Controller or not. The initial PCI access is retried until
206 * local init for the PCI bridge is completed
210 while ((reg_data != 0xFACE) && retry_count) {
211 /*by default host is in 16bit mode, so
212 * io operations at this stage must be 16 bit
214 writel(0xface, chip_addr + HC_SCRATCH_REG);
216 reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff;
222 /* Host Controller presence is detected by writing to scratch register
223 * and reading back and checking the contents are same or not
225 if (reg_data != 0xFACE) {
226 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
227 ret_status = -ENOMEM;
233 /* configure PLX PCI chip to pass interrupts */
234 #define PLX_INT_CSR_REG 0x68
235 reg_data = readl(iobase + PLX_INT_CSR_REG);
237 writel(reg_data, iobase + PLX_INT_CSR_REG);
239 dev->dev.dma_mask = NULL;
240 hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq,
241 IRQF_SHARED, &dev->dev, dev_name(&dev->dev),
244 ret_status = -ENODEV;
248 /* done with PLX IO access */
250 release_mem_region(nxp_pci_io_base, iolength);
252 pci_set_drvdata(dev, hcd);
256 release_mem_region(pci_mem_phy0, memlength);
260 release_mem_region(nxp_pci_io_base, iolength);
264 static void isp1761_pci_remove(struct pci_dev *dev)
268 hcd = pci_get_drvdata(dev);
272 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
275 pci_disable_device(dev);
278 static void isp1761_pci_shutdown(struct pci_dev *dev)
280 printk(KERN_ERR "ips1761_pci_shutdown\n");
283 static const struct pci_device_id isp1760_plx [] = {
285 .class = PCI_CLASS_BRIDGE_OTHER << 8,
287 .vendor = PCI_VENDOR_ID_PLX,
289 .subvendor = PCI_VENDOR_ID_PLX,
294 MODULE_DEVICE_TABLE(pci, isp1760_plx);
296 static struct pci_driver isp1761_pci_driver = {
298 .id_table = isp1760_plx,
299 .probe = isp1761_pci_probe,
300 .remove = isp1761_pci_remove,
301 .shutdown = isp1761_pci_shutdown,
305 static int isp1760_plat_probe(struct platform_device *pdev)
309 struct resource *mem_res;
310 struct resource *irq_res;
311 resource_size_t mem_size;
312 struct isp1760_platform_data *priv = dev_get_platdata(&pdev->dev);
313 unsigned int devflags = 0;
314 unsigned long irqflags = IRQF_SHARED;
316 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
318 pr_warning("isp1760: Memory resource not available\n");
322 mem_size = resource_size(mem_res);
323 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) {
324 pr_warning("isp1760: Cannot reserve the memory resource\n");
329 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
331 pr_warning("isp1760: IRQ resource not available\n");
336 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
339 if (priv->is_isp1761)
340 devflags |= ISP1760_FLAG_ISP1761;
341 if (priv->bus_width_16)
342 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
344 devflags |= ISP1760_FLAG_OTG_EN;
346 devflags |= ISP1760_FLAG_ANALOG_OC;
347 if (priv->dack_polarity_high)
348 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
349 if (priv->dreq_polarity_high)
350 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
353 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
354 irqflags, &pdev->dev, dev_name(&pdev->dev),
357 platform_set_drvdata(pdev, hcd);
360 pr_warning("isp1760: Failed to register the HCD device\n");
365 pr_info("ISP1760 USB device initialised\n");
369 release_mem_region(mem_res->start, mem_size);
374 static int isp1760_plat_remove(struct platform_device *pdev)
376 struct resource *mem_res;
377 resource_size_t mem_size;
378 struct usb_hcd *hcd = platform_get_drvdata(pdev);
382 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383 mem_size = resource_size(mem_res);
384 release_mem_region(mem_res->start, mem_size);
391 static struct platform_driver isp1760_plat_driver = {
392 .probe = isp1760_plat_probe,
393 .remove = isp1760_plat_remove,
399 static int __init isp1760_init(void)
401 int ret, any_ret = -ENODEV;
405 ret = platform_driver_register(&isp1760_plat_driver);
408 #if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
409 ret = platform_driver_register(&isp1760_of_driver);
414 ret = pci_register_driver(&isp1761_pci_driver);
423 module_init(isp1760_init);
425 static void __exit isp1760_exit(void)
427 platform_driver_unregister(&isp1760_plat_driver);
428 #if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
429 platform_driver_unregister(&isp1760_of_driver);
432 pci_unregister_driver(&isp1761_pci_driver);
436 module_exit(isp1760_exit);