2 * Glue code for the ISP1760 driver and bus
3 * Currently there is support for
7 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
11 #include <linux/usb.h>
13 #include <linux/platform_device.h>
15 #include "../core/hcd.h"
16 #include "isp1760-hcd.h"
20 #include <linux/of_platform.h>
24 #include <linux/pci.h>
28 static int of_isp1760_probe(struct of_device *dev,
29 const struct of_device_id *match)
32 struct device_node *dp = dev->node;
34 struct resource memory;
39 const unsigned int *prop;
40 unsigned int devflags = 0;
42 ret = of_address_to_resource(dp, 0, &memory);
46 res = request_mem_region(memory.start, memory.end - memory.start + 1,
51 res_len = memory.end - memory.start + 1;
53 if (of_irq_map_one(dp, 0, &oirq)) {
58 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
61 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
62 devflags |= ISP1760_FLAG_ISP1761;
64 /* Some systems wire up only 16 of the 32 data lines */
65 prop = of_get_property(dp, "bus-width", NULL);
66 if (prop && *prop == 16)
67 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
69 if (of_get_property(dp, "port1-otg", NULL) != NULL)
70 devflags |= ISP1760_FLAG_OTG_EN;
72 if (of_get_property(dp, "analog-oc", NULL) != NULL)
73 devflags |= ISP1760_FLAG_ANALOG_OC;
75 if (of_get_property(dp, "dack-polarity", NULL) != NULL)
76 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
78 if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
79 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
81 hcd = isp1760_register(memory.start, res_len, virq,
82 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
89 dev_set_drvdata(&dev->dev, hcd);
93 release_mem_region(memory.start, memory.end - memory.start + 1);
97 static int of_isp1760_remove(struct of_device *dev)
99 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
101 dev_set_drvdata(&dev->dev, NULL);
105 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
110 static struct of_device_id of_isp1760_match[] = {
112 .compatible = "nxp,usb-isp1760",
115 .compatible = "nxp,usb-isp1761",
119 MODULE_DEVICE_TABLE(of, of_isp1760_match);
121 static struct of_platform_driver isp1760_of_driver = {
122 .name = "nxp-isp1760",
123 .match_table = of_isp1760_match,
124 .probe = of_isp1760_probe,
125 .remove = of_isp1760_remove,
130 static int __devinit isp1761_pci_probe(struct pci_dev *dev,
131 const struct pci_device_id *id)
137 unsigned int devflags = 0;
140 resource_size_t pci_mem_phy0;
141 resource_size_t memlength;
143 u8 __iomem *chip_addr;
145 resource_size_t nxp_pci_io_base;
146 resource_size_t iolength;
151 if (pci_enable_device(dev) < 0)
157 /* Grab the PLX PCI mem maped port start address we need */
158 nxp_pci_io_base = pci_resource_start(dev, 0);
159 iolength = pci_resource_len(dev, 0);
161 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
162 printk(KERN_ERR "request region #1\n");
166 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
168 printk(KERN_ERR "ioremap #1\n");
169 ret_status = -ENOMEM;
172 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
173 pci_mem_phy0 = pci_resource_start(dev, 3);
174 memlength = pci_resource_len(dev, 3);
175 if (memlength < 0xffff) {
176 printk(KERN_ERR "memory length for this resource is wrong\n");
177 ret_status = -ENOMEM;
181 if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) {
182 printk(KERN_ERR "host controller already in use\n");
187 /* map available memory */
188 chip_addr = ioremap_nocache(pci_mem_phy0,memlength);
190 printk(KERN_ERR "Error ioremap failed\n");
191 ret_status = -ENOMEM;
195 /* bad pci latencies can contribute to overruns */
196 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
198 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
199 if (limit && limit < latency)
200 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
203 /* Try to check whether we can access Scratch Register of
204 * Host Controller or not. The initial PCI access is retried until
205 * local init for the PCI bridge is completed
209 while ((reg_data != 0xFACE) && retry_count) {
210 /*by default host is in 16bit mode, so
211 * io operations at this stage must be 16 bit
213 writel(0xface, chip_addr + HC_SCRATCH_REG);
215 reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff;
221 /* Host Controller presence is detected by writing to scratch register
222 * and reading back and checking the contents are same or not
224 if (reg_data != 0xFACE) {
225 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
226 ret_status = -ENOMEM;
232 /* configure PLX PCI chip to pass interrupts */
233 #define PLX_INT_CSR_REG 0x68
234 reg_data = readl(iobase + PLX_INT_CSR_REG);
236 writel(reg_data, iobase + PLX_INT_CSR_REG);
238 dev->dev.dma_mask = NULL;
239 hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq,
240 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
243 ret_status = -ENODEV;
247 /* done with PLX IO access */
249 release_mem_region(nxp_pci_io_base, iolength);
251 pci_set_drvdata(dev, hcd);
255 release_mem_region(pci_mem_phy0, memlength);
259 release_mem_region(nxp_pci_io_base, iolength);
263 static void isp1761_pci_remove(struct pci_dev *dev)
267 hcd = pci_get_drvdata(dev);
271 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
274 pci_disable_device(dev);
277 static void isp1761_pci_shutdown(struct pci_dev *dev)
279 printk(KERN_ERR "ips1761_pci_shutdown\n");
282 static const struct pci_device_id isp1760_plx [] = {
284 .class = PCI_CLASS_BRIDGE_OTHER << 8,
286 .vendor = PCI_VENDOR_ID_PLX,
288 .subvendor = PCI_VENDOR_ID_PLX,
293 MODULE_DEVICE_TABLE(pci, isp1760_plx);
295 static struct pci_driver isp1761_pci_driver = {
297 .id_table = isp1760_plx,
298 .probe = isp1761_pci_probe,
299 .remove = isp1761_pci_remove,
300 .shutdown = isp1761_pci_shutdown,
304 static int __devinit isp1760_plat_probe(struct platform_device *pdev)
308 struct resource *mem_res;
309 struct resource *irq_res;
310 resource_size_t mem_size;
311 unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED;
313 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
315 pr_warning("isp1760: Memory resource not available\n");
319 mem_size = resource_size(mem_res);
320 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) {
321 pr_warning("isp1760: Cannot reserve the memory resource\n");
326 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
328 pr_warning("isp1760: IRQ resource not available\n");
331 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
333 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
334 irqflags, &pdev->dev, dev_name(&pdev->dev), 0);
336 pr_warning("isp1760: Failed to register the HCD device\n");
341 pr_info("ISP1760 USB device initialised\n");
345 release_mem_region(mem_res->start, mem_size);
350 static int __devexit isp1760_plat_remove(struct platform_device *pdev)
352 struct resource *mem_res;
353 resource_size_t mem_size;
355 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
356 mem_size = resource_size(mem_res);
357 release_mem_region(mem_res->start, mem_size);
362 static struct platform_driver isp1760_plat_driver = {
363 .probe = isp1760_plat_probe,
364 .remove = __devexit_p(isp1760_plat_remove),
370 static int __init isp1760_init(void)
372 int ret, any_ret = -ENODEV;
376 ret = platform_driver_register(&isp1760_plat_driver);
380 ret = of_register_platform_driver(&isp1760_of_driver);
385 ret = pci_register_driver(&isp1761_pci_driver);
394 module_init(isp1760_init);
396 static void __exit isp1760_exit(void)
398 platform_driver_unregister(&isp1760_plat_driver);
400 of_unregister_platform_driver(&isp1760_of_driver);
403 pci_unregister_driver(&isp1761_pci_driver);
407 module_exit(isp1760_exit);