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"
23 #include <linux/of_platform.h>
27 #include <linux/pci.h>
31 static int of_isp1760_probe(struct platform_device
*dev
)
34 struct device_node
*dp
= dev
->dev
.of_node
;
36 struct resource memory
;
39 resource_size_t res_len
;
41 const unsigned int *prop
;
42 unsigned int devflags
= 0;
44 ret
= of_address_to_resource(dp
, 0, &memory
);
48 res_len
= resource_size(&memory
);
50 res
= request_mem_region(memory
.start
, res_len
, dev_name(&dev
->dev
));
54 if (of_irq_map_one(dp
, 0, &oirq
)) {
59 virq
= irq_create_of_mapping(oirq
.controller
, oirq
.specifier
,
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 prop
= of_get_property(dp
, "bus-width", NULL
);
67 if (prop
&& *prop
== 16)
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
,
83 IRQF_SHARED
| IRQF_DISABLED
, &dev
->dev
, dev_name(&dev
->dev
),
90 dev_set_drvdata(&dev
->dev
, hcd
);
94 release_mem_region(memory
.start
, res_len
);
98 static int of_isp1760_remove(struct platform_device
*dev
)
100 struct usb_hcd
*hcd
= dev_get_drvdata(&dev
->dev
);
102 dev_set_drvdata(&dev
->dev
, NULL
);
106 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
111 static const struct of_device_id of_isp1760_match
[] = {
113 .compatible
= "nxp,usb-isp1760",
116 .compatible
= "nxp,usb-isp1761",
120 MODULE_DEVICE_TABLE(of
, of_isp1760_match
);
122 static struct platform_driver isp1760_of_driver
= {
124 .name
= "nxp-isp1760",
125 .owner
= THIS_MODULE
,
126 .of_match_table
= of_isp1760_match
,
128 .probe
= of_isp1760_probe
,
129 .remove
= of_isp1760_remove
,
134 static int __devinit
isp1761_pci_probe(struct pci_dev
*dev
,
135 const struct pci_device_id
*id
)
141 unsigned int devflags
= 0;
144 resource_size_t pci_mem_phy0
;
145 resource_size_t memlength
;
147 u8 __iomem
*chip_addr
;
149 resource_size_t nxp_pci_io_base
;
150 resource_size_t iolength
;
155 if (pci_enable_device(dev
) < 0)
161 /* Grab the PLX PCI mem maped port start address we need */
162 nxp_pci_io_base
= pci_resource_start(dev
, 0);
163 iolength
= pci_resource_len(dev
, 0);
165 if (!request_mem_region(nxp_pci_io_base
, iolength
, "ISP1761 IO MEM")) {
166 printk(KERN_ERR
"request region #1\n");
170 iobase
= ioremap_nocache(nxp_pci_io_base
, iolength
);
172 printk(KERN_ERR
"ioremap #1\n");
173 ret_status
= -ENOMEM
;
176 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
177 pci_mem_phy0
= pci_resource_start(dev
, 3);
178 memlength
= pci_resource_len(dev
, 3);
179 if (memlength
< 0xffff) {
180 printk(KERN_ERR
"memory length for this resource is wrong\n");
181 ret_status
= -ENOMEM
;
185 if (!request_mem_region(pci_mem_phy0
, memlength
, "ISP-PCI")) {
186 printk(KERN_ERR
"host controller already in use\n");
191 /* map available memory */
192 chip_addr
= ioremap_nocache(pci_mem_phy0
,memlength
);
194 printk(KERN_ERR
"Error ioremap failed\n");
195 ret_status
= -ENOMEM
;
199 /* bad pci latencies can contribute to overruns */
200 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &latency
);
202 pci_read_config_byte(dev
, PCI_MAX_LAT
, &limit
);
203 if (limit
&& limit
< latency
)
204 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, limit
);
207 /* Try to check whether we can access Scratch Register of
208 * Host Controller or not. The initial PCI access is retried until
209 * local init for the PCI bridge is completed
213 while ((reg_data
!= 0xFACE) && retry_count
) {
214 /*by default host is in 16bit mode, so
215 * io operations at this stage must be 16 bit
217 writel(0xface, chip_addr
+ HC_SCRATCH_REG
);
219 reg_data
= readl(chip_addr
+ HC_SCRATCH_REG
) & 0x0000ffff;
225 /* Host Controller presence is detected by writing to scratch register
226 * and reading back and checking the contents are same or not
228 if (reg_data
!= 0xFACE) {
229 dev_err(&dev
->dev
, "scratch register mismatch %x\n", reg_data
);
230 ret_status
= -ENOMEM
;
236 /* configure PLX PCI chip to pass interrupts */
237 #define PLX_INT_CSR_REG 0x68
238 reg_data
= readl(iobase
+ PLX_INT_CSR_REG
);
240 writel(reg_data
, iobase
+ PLX_INT_CSR_REG
);
242 dev
->dev
.dma_mask
= NULL
;
243 hcd
= isp1760_register(pci_mem_phy0
, memlength
, dev
->irq
,
244 IRQF_SHARED
| IRQF_DISABLED
, &dev
->dev
, dev_name(&dev
->dev
),
247 ret_status
= -ENODEV
;
251 /* done with PLX IO access */
253 release_mem_region(nxp_pci_io_base
, iolength
);
255 pci_set_drvdata(dev
, hcd
);
259 release_mem_region(pci_mem_phy0
, memlength
);
263 release_mem_region(nxp_pci_io_base
, iolength
);
267 static void isp1761_pci_remove(struct pci_dev
*dev
)
271 hcd
= pci_get_drvdata(dev
);
275 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
278 pci_disable_device(dev
);
281 static void isp1761_pci_shutdown(struct pci_dev
*dev
)
283 printk(KERN_ERR
"ips1761_pci_shutdown\n");
286 static const struct pci_device_id isp1760_plx
[] = {
288 .class = PCI_CLASS_BRIDGE_OTHER
<< 8,
290 .vendor
= PCI_VENDOR_ID_PLX
,
292 .subvendor
= PCI_VENDOR_ID_PLX
,
297 MODULE_DEVICE_TABLE(pci
, isp1760_plx
);
299 static struct pci_driver isp1761_pci_driver
= {
301 .id_table
= isp1760_plx
,
302 .probe
= isp1761_pci_probe
,
303 .remove
= isp1761_pci_remove
,
304 .shutdown
= isp1761_pci_shutdown
,
308 static int __devinit
isp1760_plat_probe(struct platform_device
*pdev
)
312 struct resource
*mem_res
;
313 struct resource
*irq_res
;
314 resource_size_t mem_size
;
315 struct isp1760_platform_data
*priv
= pdev
->dev
.platform_data
;
316 unsigned int devflags
= 0;
317 unsigned long irqflags
= IRQF_SHARED
| IRQF_DISABLED
;
319 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
321 pr_warning("isp1760: Memory resource not available\n");
325 mem_size
= resource_size(mem_res
);
326 if (!request_mem_region(mem_res
->start
, mem_size
, "isp1760")) {
327 pr_warning("isp1760: Cannot reserve the memory resource\n");
332 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
334 pr_warning("isp1760: IRQ resource not available\n");
337 irqflags
|= irq_res
->flags
& IRQF_TRIGGER_MASK
;
340 if (priv
->is_isp1761
)
341 devflags
|= ISP1760_FLAG_ISP1761
;
342 if (priv
->bus_width_16
)
343 devflags
|= ISP1760_FLAG_BUS_WIDTH_16
;
345 devflags
|= ISP1760_FLAG_OTG_EN
;
347 devflags
|= ISP1760_FLAG_ANALOG_OC
;
348 if (priv
->dack_polarity_high
)
349 devflags
|= ISP1760_FLAG_DACK_POL_HIGH
;
350 if (priv
->dreq_polarity_high
)
351 devflags
|= ISP1760_FLAG_DREQ_POL_HIGH
;
354 hcd
= isp1760_register(mem_res
->start
, mem_size
, irq_res
->start
,
355 irqflags
, &pdev
->dev
, dev_name(&pdev
->dev
), devflags
);
357 pr_warning("isp1760: Failed to register the HCD device\n");
362 pr_info("ISP1760 USB device initialised\n");
366 release_mem_region(mem_res
->start
, mem_size
);
371 static int __devexit
isp1760_plat_remove(struct platform_device
*pdev
)
373 struct resource
*mem_res
;
374 resource_size_t mem_size
;
376 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
377 mem_size
= resource_size(mem_res
);
378 release_mem_region(mem_res
->start
, mem_size
);
383 static struct platform_driver isp1760_plat_driver
= {
384 .probe
= isp1760_plat_probe
,
385 .remove
= __devexit_p(isp1760_plat_remove
),
391 static int __init
isp1760_init(void)
393 int ret
, any_ret
= -ENODEV
;
397 ret
= platform_driver_register(&isp1760_plat_driver
);
401 ret
= platform_driver_register(&isp1760_of_driver
);
406 ret
= pci_register_driver(&isp1761_pci_driver
);
415 module_init(isp1760_init
);
417 static void __exit
isp1760_exit(void)
419 platform_driver_unregister(&isp1760_plat_driver
);
421 platform_driver_unregister(&isp1760_of_driver
);
424 pci_unregister_driver(&isp1761_pci_driver
);
428 module_exit(isp1760_exit
);