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/platform_device.h>
15 #include <linux/usb/isp1760.h>
16 #include <linux/usb/hcd.h>
18 #include "isp1760-hcd.h"
22 #include <linux/of_platform.h>
26 #include <linux/pci.h>
30 static int of_isp1760_probe(struct platform_device
*dev
)
33 struct device_node
*dp
= dev
->dev
.of_node
;
35 struct resource memory
;
38 resource_size_t res_len
;
40 const unsigned int *prop
;
41 unsigned int devflags
= 0;
43 ret
= of_address_to_resource(dp
, 0, &memory
);
47 res_len
= resource_size(&memory
);
49 res
= request_mem_region(memory
.start
, res_len
, dev_name(&dev
->dev
));
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
, res_len
);
97 static int of_isp1760_remove(struct platform_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 const 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 platform_driver isp1760_of_driver
= {
123 .name
= "nxp-isp1760",
124 .owner
= THIS_MODULE
,
125 .of_match_table
= of_isp1760_match
,
127 .probe
= of_isp1760_probe
,
128 .remove
= of_isp1760_remove
,
133 static int __devinit
isp1761_pci_probe(struct pci_dev
*dev
,
134 const struct pci_device_id
*id
)
140 unsigned int devflags
= 0;
143 resource_size_t pci_mem_phy0
;
144 resource_size_t memlength
;
146 u8 __iomem
*chip_addr
;
148 resource_size_t nxp_pci_io_base
;
149 resource_size_t iolength
;
154 if (pci_enable_device(dev
) < 0)
160 /* Grab the PLX PCI mem maped port start address we need */
161 nxp_pci_io_base
= pci_resource_start(dev
, 0);
162 iolength
= pci_resource_len(dev
, 0);
164 if (!request_mem_region(nxp_pci_io_base
, iolength
, "ISP1761 IO MEM")) {
165 printk(KERN_ERR
"request region #1\n");
169 iobase
= ioremap_nocache(nxp_pci_io_base
, iolength
);
171 printk(KERN_ERR
"ioremap #1\n");
172 ret_status
= -ENOMEM
;
175 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
176 pci_mem_phy0
= pci_resource_start(dev
, 3);
177 memlength
= pci_resource_len(dev
, 3);
178 if (memlength
< 0xffff) {
179 printk(KERN_ERR
"memory length for this resource is wrong\n");
180 ret_status
= -ENOMEM
;
184 if (!request_mem_region(pci_mem_phy0
, memlength
, "ISP-PCI")) {
185 printk(KERN_ERR
"host controller already in use\n");
190 /* map available memory */
191 chip_addr
= ioremap_nocache(pci_mem_phy0
,memlength
);
193 printk(KERN_ERR
"Error ioremap failed\n");
194 ret_status
= -ENOMEM
;
198 /* bad pci latencies can contribute to overruns */
199 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &latency
);
201 pci_read_config_byte(dev
, PCI_MAX_LAT
, &limit
);
202 if (limit
&& limit
< latency
)
203 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, limit
);
206 /* Try to check whether we can access Scratch Register of
207 * Host Controller or not. The initial PCI access is retried until
208 * local init for the PCI bridge is completed
212 while ((reg_data
!= 0xFACE) && retry_count
) {
213 /*by default host is in 16bit mode, so
214 * io operations at this stage must be 16 bit
216 writel(0xface, chip_addr
+ HC_SCRATCH_REG
);
218 reg_data
= readl(chip_addr
+ HC_SCRATCH_REG
) & 0x0000ffff;
224 /* Host Controller presence is detected by writing to scratch register
225 * and reading back and checking the contents are same or not
227 if (reg_data
!= 0xFACE) {
228 dev_err(&dev
->dev
, "scratch register mismatch %x\n", reg_data
);
229 ret_status
= -ENOMEM
;
235 /* configure PLX PCI chip to pass interrupts */
236 #define PLX_INT_CSR_REG 0x68
237 reg_data
= readl(iobase
+ PLX_INT_CSR_REG
);
239 writel(reg_data
, iobase
+ PLX_INT_CSR_REG
);
241 dev
->dev
.dma_mask
= NULL
;
242 hcd
= isp1760_register(pci_mem_phy0
, memlength
, dev
->irq
,
243 IRQF_SHARED
| IRQF_DISABLED
, &dev
->dev
, dev_name(&dev
->dev
),
246 ret_status
= -ENODEV
;
250 /* done with PLX IO access */
252 release_mem_region(nxp_pci_io_base
, iolength
);
254 pci_set_drvdata(dev
, hcd
);
258 release_mem_region(pci_mem_phy0
, memlength
);
262 release_mem_region(nxp_pci_io_base
, iolength
);
266 static void isp1761_pci_remove(struct pci_dev
*dev
)
270 hcd
= pci_get_drvdata(dev
);
274 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
277 pci_disable_device(dev
);
280 static void isp1761_pci_shutdown(struct pci_dev
*dev
)
282 printk(KERN_ERR
"ips1761_pci_shutdown\n");
285 static const struct pci_device_id isp1760_plx
[] = {
287 .class = PCI_CLASS_BRIDGE_OTHER
<< 8,
289 .vendor
= PCI_VENDOR_ID_PLX
,
291 .subvendor
= PCI_VENDOR_ID_PLX
,
296 MODULE_DEVICE_TABLE(pci
, isp1760_plx
);
298 static struct pci_driver isp1761_pci_driver
= {
300 .id_table
= isp1760_plx
,
301 .probe
= isp1761_pci_probe
,
302 .remove
= isp1761_pci_remove
,
303 .shutdown
= isp1761_pci_shutdown
,
307 static int __devinit
isp1760_plat_probe(struct platform_device
*pdev
)
311 struct resource
*mem_res
;
312 struct resource
*irq_res
;
313 resource_size_t mem_size
;
314 struct isp1760_platform_data
*priv
= pdev
->dev
.platform_data
;
315 unsigned int devflags
= 0;
316 unsigned long irqflags
= IRQF_SHARED
| IRQF_DISABLED
;
318 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
320 pr_warning("isp1760: Memory resource not available\n");
324 mem_size
= resource_size(mem_res
);
325 if (!request_mem_region(mem_res
->start
, mem_size
, "isp1760")) {
326 pr_warning("isp1760: Cannot reserve the memory resource\n");
331 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
333 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
), devflags
);
356 pr_warning("isp1760: Failed to register the HCD device\n");
361 pr_info("ISP1760 USB device initialised\n");
365 release_mem_region(mem_res
->start
, mem_size
);
370 static int __devexit
isp1760_plat_remove(struct platform_device
*pdev
)
372 struct resource
*mem_res
;
373 resource_size_t mem_size
;
375 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
376 mem_size
= resource_size(mem_res
);
377 release_mem_region(mem_res
->start
, mem_size
);
382 static struct platform_driver isp1760_plat_driver
= {
383 .probe
= isp1760_plat_probe
,
384 .remove
= __devexit_p(isp1760_plat_remove
),
390 static int __init
isp1760_init(void)
392 int ret
, any_ret
= -ENODEV
;
396 ret
= platform_driver_register(&isp1760_plat_driver
);
400 ret
= platform_driver_register(&isp1760_of_driver
);
405 ret
= pci_register_driver(&isp1761_pci_driver
);
414 module_init(isp1760_init
);
416 static void __exit
isp1760_exit(void)
418 platform_driver_unregister(&isp1760_plat_driver
);
420 platform_driver_unregister(&isp1760_of_driver
);
423 pci_unregister_driver(&isp1761_pci_driver
);
427 module_exit(isp1760_exit
);