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>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/usb/isp1760.h>
19 #include <linux/usb/hcd.h>
21 #include "isp1760-hcd.h"
24 #include <linux/pci.h>
28 static int isp1761_pci_probe(struct pci_dev
*dev
,
29 const struct pci_device_id
*id
)
34 unsigned int devflags
= 0;
37 resource_size_t pci_mem_phy0
;
38 resource_size_t memlength
;
40 u8 __iomem
*chip_addr
;
42 resource_size_t nxp_pci_io_base
;
43 resource_size_t iolength
;
48 if (pci_enable_device(dev
) < 0)
54 /* Grab the PLX PCI mem maped port start address we need */
55 nxp_pci_io_base
= pci_resource_start(dev
, 0);
56 iolength
= pci_resource_len(dev
, 0);
58 if (!request_mem_region(nxp_pci_io_base
, iolength
, "ISP1761 IO MEM")) {
59 printk(KERN_ERR
"request region #1\n");
63 iobase
= ioremap_nocache(nxp_pci_io_base
, iolength
);
65 printk(KERN_ERR
"ioremap #1\n");
69 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
70 pci_mem_phy0
= pci_resource_start(dev
, 3);
71 memlength
= pci_resource_len(dev
, 3);
72 if (memlength
< 0xffff) {
73 printk(KERN_ERR
"memory length for this resource is wrong\n");
78 if (!request_mem_region(pci_mem_phy0
, memlength
, "ISP-PCI")) {
79 printk(KERN_ERR
"host controller already in use\n");
84 /* map available memory */
85 chip_addr
= ioremap_nocache(pci_mem_phy0
,memlength
);
87 printk(KERN_ERR
"Error ioremap failed\n");
92 /* bad pci latencies can contribute to overruns */
93 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &latency
);
95 pci_read_config_byte(dev
, PCI_MAX_LAT
, &limit
);
96 if (limit
&& limit
< latency
)
97 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, limit
);
100 /* Try to check whether we can access Scratch Register of
101 * Host Controller or not. The initial PCI access is retried until
102 * local init for the PCI bridge is completed
106 while ((reg_data
!= 0xFACE) && retry_count
) {
107 /*by default host is in 16bit mode, so
108 * io operations at this stage must be 16 bit
110 writel(0xface, chip_addr
+ HC_SCRATCH_REG
);
112 reg_data
= readl(chip_addr
+ HC_SCRATCH_REG
) & 0x0000ffff;
118 /* Host Controller presence is detected by writing to scratch register
119 * and reading back and checking the contents are same or not
121 if (reg_data
!= 0xFACE) {
122 dev_err(&dev
->dev
, "scratch register mismatch %x\n", reg_data
);
123 ret_status
= -ENOMEM
;
129 /* configure PLX PCI chip to pass interrupts */
130 #define PLX_INT_CSR_REG 0x68
131 reg_data
= readl(iobase
+ PLX_INT_CSR_REG
);
133 writel(reg_data
, iobase
+ PLX_INT_CSR_REG
);
135 dev
->dev
.dma_mask
= NULL
;
136 ret_status
= isp1760_register(pci_mem_phy0
, memlength
, dev
->irq
,
137 IRQF_SHARED
, &dev
->dev
, devflags
);
141 /* done with PLX IO access */
143 release_mem_region(nxp_pci_io_base
, iolength
);
148 release_mem_region(pci_mem_phy0
, memlength
);
152 release_mem_region(nxp_pci_io_base
, iolength
);
156 static void isp1761_pci_remove(struct pci_dev
*dev
)
158 isp1760_unregister(&dev
->dev
);
160 pci_disable_device(dev
);
163 static void isp1761_pci_shutdown(struct pci_dev
*dev
)
165 printk(KERN_ERR
"ips1761_pci_shutdown\n");
168 static const struct pci_device_id isp1760_plx
[] = {
170 .class = PCI_CLASS_BRIDGE_OTHER
<< 8,
172 .vendor
= PCI_VENDOR_ID_PLX
,
174 .subvendor
= PCI_VENDOR_ID_PLX
,
179 MODULE_DEVICE_TABLE(pci
, isp1760_plx
);
181 static struct pci_driver isp1761_pci_driver
= {
183 .id_table
= isp1760_plx
,
184 .probe
= isp1761_pci_probe
,
185 .remove
= isp1761_pci_remove
,
186 .shutdown
= isp1761_pci_shutdown
,
190 static int isp1760_plat_probe(struct platform_device
*pdev
)
192 unsigned long irqflags
= IRQF_SHARED
;
193 unsigned int devflags
= 0;
194 struct resource
*mem_res
;
195 struct resource
*irq_res
;
196 resource_size_t mem_size
;
199 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
201 pr_warning("isp1760: Memory resource not available\n");
204 mem_size
= resource_size(mem_res
);
205 if (!request_mem_region(mem_res
->start
, mem_size
, "isp1760")) {
206 pr_warning("isp1760: Cannot reserve the memory resource\n");
210 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
212 pr_warning("isp1760: IRQ resource not available\n");
217 irqflags
|= irq_res
->flags
& IRQF_TRIGGER_MASK
;
219 if (IS_ENABLED(CONFIG_OF
) && pdev
->dev
.of_node
) {
220 struct device_node
*dp
= pdev
->dev
.of_node
;
223 if (of_device_is_compatible(dp
, "nxp,usb-isp1761"))
224 devflags
|= ISP1760_FLAG_ISP1761
;
226 /* Some systems wire up only 16 of the 32 data lines */
227 of_property_read_u32(dp
, "bus-width", &bus_width
);
229 devflags
|= ISP1760_FLAG_BUS_WIDTH_16
;
231 if (of_property_read_bool(dp
, "port1-otg"))
232 devflags
|= ISP1760_FLAG_OTG_EN
;
234 if (of_property_read_bool(dp
, "analog-oc"))
235 devflags
|= ISP1760_FLAG_ANALOG_OC
;
237 if (of_property_read_bool(dp
, "dack-polarity"))
238 devflags
|= ISP1760_FLAG_DACK_POL_HIGH
;
240 if (of_property_read_bool(dp
, "dreq-polarity"))
241 devflags
|= ISP1760_FLAG_DREQ_POL_HIGH
;
242 } else if (dev_get_platdata(&pdev
->dev
)) {
243 struct isp1760_platform_data
*pdata
=
244 dev_get_platdata(&pdev
->dev
);
246 if (pdata
->is_isp1761
)
247 devflags
|= ISP1760_FLAG_ISP1761
;
248 if (pdata
->bus_width_16
)
249 devflags
|= ISP1760_FLAG_BUS_WIDTH_16
;
250 if (pdata
->port1_otg
)
251 devflags
|= ISP1760_FLAG_OTG_EN
;
252 if (pdata
->analog_oc
)
253 devflags
|= ISP1760_FLAG_ANALOG_OC
;
254 if (pdata
->dack_polarity_high
)
255 devflags
|= ISP1760_FLAG_DACK_POL_HIGH
;
256 if (pdata
->dreq_polarity_high
)
257 devflags
|= ISP1760_FLAG_DREQ_POL_HIGH
;
260 ret
= isp1760_register(mem_res
->start
, mem_size
, irq_res
->start
,
261 irqflags
, &pdev
->dev
, devflags
);
265 pr_info("ISP1760 USB device initialised\n");
269 release_mem_region(mem_res
->start
, mem_size
);
273 static int isp1760_plat_remove(struct platform_device
*pdev
)
275 isp1760_unregister(&pdev
->dev
);
281 static const struct of_device_id isp1760_of_match
[] = {
282 { .compatible
= "nxp,usb-isp1760", },
283 { .compatible
= "nxp,usb-isp1761", },
286 MODULE_DEVICE_TABLE(of
, isp1760_of_match
);
289 static struct platform_driver isp1760_plat_driver
= {
290 .probe
= isp1760_plat_probe
,
291 .remove
= isp1760_plat_remove
,
294 .of_match_table
= of_match_ptr(isp1760_of_match
),
298 static int __init
isp1760_init(void)
300 int ret
, any_ret
= -ENODEV
;
302 isp1760_init_kmem_once();
304 ret
= platform_driver_register(&isp1760_plat_driver
);
308 ret
= pci_register_driver(&isp1761_pci_driver
);
314 isp1760_deinit_kmem_cache();
317 module_init(isp1760_init
);
319 static void __exit
isp1760_exit(void)
321 platform_driver_unregister(&isp1760_plat_driver
);
323 pci_unregister_driver(&isp1761_pci_driver
);
325 isp1760_deinit_kmem_cache();
327 module_exit(isp1760_exit
);