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>
14 #include "../core/hcd.h"
15 #include "isp1760-hcd.h"
17 #ifdef CONFIG_USB_ISP1760_OF
19 #include <linux/of_platform.h>
22 #ifdef CONFIG_USB_ISP1760_PCI
23 #include <linux/pci.h>
26 #ifdef CONFIG_USB_ISP1760_OF
27 static int of_isp1760_probe(struct of_device *dev,
28 const struct of_device_id *match)
31 struct device_node *dp = dev->node;
33 struct resource memory;
39 ret = of_address_to_resource(dp, 0, &memory);
43 res = request_mem_region(memory.start, memory.end - memory.start + 1,
48 res_len = memory.end - memory.start + 1;
50 if (of_irq_map_one(dp, 0, &oirq)) {
55 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
58 hcd = isp1760_register(memory.start, res_len, virq,
59 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id);
65 dev_set_drvdata(&dev->dev, hcd);
69 release_mem_region(memory.start, memory.end - memory.start + 1);
73 static int of_isp1760_remove(struct of_device *dev)
75 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
77 dev_set_drvdata(&dev->dev, NULL);
81 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
86 static struct of_device_id of_isp1760_match[] = {
88 .compatible = "nxp,usb-isp1760",
92 MODULE_DEVICE_TABLE(of, of_isp1760_match);
94 static struct of_platform_driver isp1760_of_driver = {
95 .name = "nxp-isp1760",
96 .match_table = of_isp1760_match,
97 .probe = of_isp1760_probe,
98 .remove = of_isp1760_remove,
102 #ifdef CONFIG_USB_ISP1760_PCI
103 static u32 nxp_pci_io_base;
105 static u32 pci_mem_phy0;
107 static u8 *chip_addr;
110 static int __devinit isp1761_pci_probe(struct pci_dev *dev,
111 const struct pci_device_id *id)
123 if (pci_enable_device(dev) < 0)
129 /* Grab the PLX PCI mem maped port start address we need */
130 nxp_pci_io_base = pci_resource_start(dev, 0);
131 iolength = pci_resource_len(dev, 0);
133 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
134 printk(KERN_ERR "request region #1\n");
138 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
140 printk(KERN_ERR "ioremap #1\n");
141 release_mem_region(nxp_pci_io_base, iolength);
144 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
145 pci_mem_phy0 = pci_resource_start(dev, 3);
146 length = pci_resource_len(dev, 3);
148 if (length < 0xffff) {
149 printk(KERN_ERR "memory length for this resource is less than "
151 release_mem_region(nxp_pci_io_base, iolength);
156 if (!request_mem_region(pci_mem_phy0, length, "ISP-PCI")) {
157 printk(KERN_ERR "host controller already in use\n");
158 release_mem_region(nxp_pci_io_base, iolength);
163 /* bad pci latencies can contribute to overruns */
164 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
166 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
167 if (limit && limit < latency)
168 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
171 /* Try to check whether we can access Scratch Register of
172 * Host Controller or not. The initial PCI access is retried until
173 * local init for the PCI bridge is completed
177 while ((reg_data != 0xFACE) && retry_count) {
178 /*by default host is in 16bit mode, so
179 * io operations at this stage must be 16 bit
181 writel(0xface, chip_addr + HC_SCRATCH_REG);
183 reg_data = readl(chip_addr + HC_SCRATCH_REG);
187 /* Host Controller presence is detected by writing to scratch register
188 * and reading back and checking the contents are same or not
190 if (reg_data != 0xFACE) {
191 err("scratch register mismatch %x", reg_data);
197 status = readl(iobase + 0x68);
199 writel(status, iobase + 0x68);
201 dev->dev.dma_mask = NULL;
202 hcd = isp1760_register(pci_mem_phy0, length, dev->irq,
203 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id);
204 pci_set_drvdata(dev, hcd);
210 release_mem_region(pci_mem_phy0, length);
211 release_mem_region(nxp_pci_io_base, iolength);
214 static void isp1761_pci_remove(struct pci_dev *dev)
218 hcd = pci_get_drvdata(dev);
222 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
225 pci_disable_device(dev);
230 release_mem_region(nxp_pci_io_base, iolength);
231 release_mem_region(pci_mem_phy0, length);
234 static void isp1761_pci_shutdown(struct pci_dev *dev)
236 printk(KERN_ERR "ips1761_pci_shutdown\n");
239 static const struct pci_device_id isp1760_plx [] = { {
240 /* handle any USB 2.0 EHCI controller */
241 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_OTHER << 8) | (0x06 << 16)), ~0),
244 { /* end: all zeroes */ }
246 MODULE_DEVICE_TABLE(pci, isp1760_plx);
248 static struct pci_driver isp1761_pci_driver = {
250 .id_table = isp1760_plx,
251 .probe = isp1761_pci_probe,
252 .remove = isp1761_pci_remove,
253 .shutdown = isp1761_pci_shutdown,
257 static int __init isp1760_init(void)
263 #ifdef CONFIG_USB_ISP1760_OF
264 ret = of_register_platform_driver(&isp1760_of_driver);
270 #ifdef CONFIG_USB_ISP1760_PCI
271 ret = pci_register_driver(&isp1761_pci_driver);
277 #ifdef CONFIG_USB_ISP1760_PCI
280 #ifdef CONFIG_USB_ISP1760_OF
281 of_unregister_platform_driver(&isp1760_of_driver);
286 module_init(isp1760_init);
288 static void __exit isp1760_exit(void)
290 #ifdef CONFIG_USB_ISP1760_OF
291 of_unregister_platform_driver(&isp1760_of_driver);
293 #ifdef CONFIG_USB_ISP1760_PCI
294 pci_unregister_driver(&isp1761_pci_driver);
298 module_exit(isp1760_exit);