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"
19 #include <linux/of_platform.h>
23 #include <linux/pci.h>
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;
38 const unsigned int *prop;
39 unsigned int devflags = 0;
41 ret = of_address_to_resource(dp, 0, &memory);
45 res = request_mem_region(memory.start, memory.end - memory.start + 1,
50 res_len = memory.end - memory.start + 1;
52 if (of_irq_map_one(dp, 0, &oirq)) {
57 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
60 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
61 devflags |= ISP1760_FLAG_ISP1761;
63 /* Some systems wire up only 16 of the 32 data lines */
64 prop = of_get_property(dp, "bus-width", NULL);
65 if (prop && *prop == 16)
66 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
68 if (of_get_property(dp, "port1-otg", NULL) != NULL)
69 devflags |= ISP1760_FLAG_OTG_EN;
71 if (of_get_property(dp, "analog-oc", NULL) != NULL)
72 devflags |= ISP1760_FLAG_ANALOG_OC;
74 if (of_get_property(dp, "dack-polarity", NULL) != NULL)
75 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
77 if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
78 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
80 hcd = isp1760_register(memory.start, res_len, virq,
81 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
88 dev_set_drvdata(&dev->dev, hcd);
92 release_mem_region(memory.start, memory.end - memory.start + 1);
96 static int of_isp1760_remove(struct of_device *dev)
98 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
100 dev_set_drvdata(&dev->dev, NULL);
104 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
109 static 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 of_platform_driver isp1760_of_driver = {
121 .name = "nxp-isp1760",
122 .match_table = of_isp1760_match,
123 .probe = of_isp1760_probe,
124 .remove = of_isp1760_remove,
129 static int __devinit isp1761_pci_probe(struct pci_dev *dev,
130 const struct pci_device_id *id)
136 unsigned int devflags = 0;
139 resource_size_t pci_mem_phy0;
140 resource_size_t memlength;
142 u8 __iomem *chip_addr;
144 resource_size_t nxp_pci_io_base;
145 resource_size_t iolength;
150 if (pci_enable_device(dev) < 0)
156 /* Grab the PLX PCI mem maped port start address we need */
157 nxp_pci_io_base = pci_resource_start(dev, 0);
158 iolength = pci_resource_len(dev, 0);
160 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
161 printk(KERN_ERR "request region #1\n");
165 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
167 printk(KERN_ERR "ioremap #1\n");
168 ret_status = -ENOMEM;
171 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
172 pci_mem_phy0 = pci_resource_start(dev, 3);
173 memlength = pci_resource_len(dev, 3);
174 if (memlength < 0xffff) {
175 printk(KERN_ERR "memory length for this resource is wrong\n");
176 ret_status = -ENOMEM;
180 if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) {
181 printk(KERN_ERR "host controller already in use\n");
186 /* map available memory */
187 chip_addr = ioremap_nocache(pci_mem_phy0,memlength);
189 printk(KERN_ERR "Error ioremap failed\n");
190 ret_status = -ENOMEM;
194 /* bad pci latencies can contribute to overruns */
195 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
197 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
198 if (limit && limit < latency)
199 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
202 /* Try to check whether we can access Scratch Register of
203 * Host Controller or not. The initial PCI access is retried until
204 * local init for the PCI bridge is completed
208 while ((reg_data != 0xFACE) && retry_count) {
209 /*by default host is in 16bit mode, so
210 * io operations at this stage must be 16 bit
212 writel(0xface, chip_addr + HC_SCRATCH_REG);
214 reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff;
220 /* Host Controller presence is detected by writing to scratch register
221 * and reading back and checking the contents are same or not
223 if (reg_data != 0xFACE) {
224 dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
225 ret_status = -ENOMEM;
231 /* configure PLX PCI chip to pass interrupts */
232 #define PLX_INT_CSR_REG 0x68
233 reg_data = readl(iobase + PLX_INT_CSR_REG);
235 writel(reg_data, iobase + PLX_INT_CSR_REG);
237 dev->dev.dma_mask = NULL;
238 hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq,
239 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
242 ret_status = -ENODEV;
246 /* done with PLX IO access */
248 release_mem_region(nxp_pci_io_base, iolength);
250 pci_set_drvdata(dev, hcd);
254 release_mem_region(pci_mem_phy0, memlength);
258 release_mem_region(nxp_pci_io_base, iolength);
262 static void isp1761_pci_remove(struct pci_dev *dev)
266 hcd = pci_get_drvdata(dev);
270 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
273 pci_disable_device(dev);
276 static void isp1761_pci_shutdown(struct pci_dev *dev)
278 printk(KERN_ERR "ips1761_pci_shutdown\n");
281 static const struct pci_device_id isp1760_plx [] = {
283 .class = PCI_CLASS_BRIDGE_OTHER << 8,
285 .vendor = PCI_VENDOR_ID_PLX,
287 .subvendor = PCI_VENDOR_ID_PLX,
292 MODULE_DEVICE_TABLE(pci, isp1760_plx);
294 static struct pci_driver isp1761_pci_driver = {
296 .id_table = isp1760_plx,
297 .probe = isp1761_pci_probe,
298 .remove = isp1761_pci_remove,
299 .shutdown = isp1761_pci_shutdown,
303 static int __init isp1760_init(void)
310 ret = of_register_platform_driver(&isp1760_of_driver);
317 ret = pci_register_driver(&isp1761_pci_driver);
327 of_unregister_platform_driver(&isp1760_of_driver);
332 module_init(isp1760_init);
334 static void __exit isp1760_exit(void)
337 of_unregister_platform_driver(&isp1760_of_driver);
340 pci_unregister_driver(&isp1761_pci_driver);
344 module_exit(isp1760_exit);