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-core.h"
22 #include "isp1760-regs.h"
25 #include <linux/pci.h>
29 static int isp1761_pci_init(struct pci_dev
*dev
)
31 resource_size_t mem_start
;
32 resource_size_t mem_length
;
38 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
39 mem_start
= pci_resource_start(dev
, 3);
40 mem_length
= pci_resource_len(dev
, 3);
41 if (mem_length
< 0xffff) {
42 printk(KERN_ERR
"memory length for this resource is wrong\n");
46 if (!request_mem_region(mem_start
, mem_length
, "ISP-PCI")) {
47 printk(KERN_ERR
"host controller already in use\n");
51 /* map available memory */
52 iobase
= ioremap_nocache(mem_start
, mem_length
);
54 printk(KERN_ERR
"Error ioremap failed\n");
55 release_mem_region(mem_start
, mem_length
);
59 /* bad pci latencies can contribute to overruns */
60 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &latency
);
62 pci_read_config_byte(dev
, PCI_MAX_LAT
, &limit
);
63 if (limit
&& limit
< latency
)
64 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, limit
);
67 /* Try to check whether we can access Scratch Register of
68 * Host Controller or not. The initial PCI access is retried until
69 * local init for the PCI bridge is completed
73 while ((reg_data
!= 0xFACE) && retry_count
) {
74 /*by default host is in 16bit mode, so
75 * io operations at this stage must be 16 bit
77 writel(0xface, iobase
+ HC_SCRATCH_REG
);
79 reg_data
= readl(iobase
+ HC_SCRATCH_REG
) & 0x0000ffff;
84 release_mem_region(mem_start
, mem_length
);
86 /* Host Controller presence is detected by writing to scratch register
87 * and reading back and checking the contents are same or not
89 if (reg_data
!= 0xFACE) {
90 dev_err(&dev
->dev
, "scratch register mismatch %x\n", reg_data
);
94 /* Grab the PLX PCI mem maped port start address we need */
95 mem_start
= pci_resource_start(dev
, 0);
96 mem_length
= pci_resource_len(dev
, 0);
98 if (!request_mem_region(mem_start
, mem_length
, "ISP1761 IO MEM")) {
99 printk(KERN_ERR
"request region #1\n");
103 iobase
= ioremap_nocache(mem_start
, mem_length
);
105 printk(KERN_ERR
"ioremap #1\n");
106 release_mem_region(mem_start
, mem_length
);
110 /* configure PLX PCI chip to pass interrupts */
111 #define PLX_INT_CSR_REG 0x68
112 reg_data
= readl(iobase
+ PLX_INT_CSR_REG
);
114 writel(reg_data
, iobase
+ PLX_INT_CSR_REG
);
116 /* done with PLX IO access */
118 release_mem_region(mem_start
, mem_length
);
123 static int isp1761_pci_probe(struct pci_dev
*dev
,
124 const struct pci_device_id
*id
)
126 unsigned int devflags
= 0;
135 if (pci_enable_device(dev
) < 0)
138 ret
= isp1761_pci_init(dev
);
144 dev
->dev
.dma_mask
= NULL
;
145 ret
= isp1760_register(&dev
->resource
[3], dev
->irq
, 0, &dev
->dev
,
153 pci_disable_device(dev
);
157 static void isp1761_pci_remove(struct pci_dev
*dev
)
159 isp1760_unregister(&dev
->dev
);
161 pci_disable_device(dev
);
164 static void isp1761_pci_shutdown(struct pci_dev
*dev
)
166 printk(KERN_ERR
"ips1761_pci_shutdown\n");
169 static const struct pci_device_id isp1760_plx
[] = {
171 .class = PCI_CLASS_BRIDGE_OTHER
<< 8,
173 .vendor
= PCI_VENDOR_ID_PLX
,
175 .subvendor
= PCI_VENDOR_ID_PLX
,
180 MODULE_DEVICE_TABLE(pci
, isp1760_plx
);
182 static struct pci_driver isp1761_pci_driver
= {
184 .id_table
= isp1760_plx
,
185 .probe
= isp1761_pci_probe
,
186 .remove
= isp1761_pci_remove
,
187 .shutdown
= isp1761_pci_shutdown
,
191 static int isp1760_plat_probe(struct platform_device
*pdev
)
193 unsigned long irqflags
;
194 unsigned int devflags
= 0;
195 struct resource
*mem_res
;
196 struct resource
*irq_res
;
199 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
201 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
203 pr_warning("isp1760: IRQ resource not available\n");
206 irqflags
= irq_res
->flags
& IRQF_TRIGGER_MASK
;
208 if (IS_ENABLED(CONFIG_OF
) && pdev
->dev
.of_node
) {
209 struct device_node
*dp
= pdev
->dev
.of_node
;
212 if (of_device_is_compatible(dp
, "nxp,usb-isp1761"))
213 devflags
|= ISP1760_FLAG_ISP1761
;
215 /* Some systems wire up only 16 of the 32 data lines */
216 of_property_read_u32(dp
, "bus-width", &bus_width
);
218 devflags
|= ISP1760_FLAG_BUS_WIDTH_16
;
220 if (of_property_read_bool(dp
, "port1-otg"))
221 devflags
|= ISP1760_FLAG_OTG_EN
;
223 if (of_property_read_bool(dp
, "analog-oc"))
224 devflags
|= ISP1760_FLAG_ANALOG_OC
;
226 if (of_property_read_bool(dp
, "dack-polarity"))
227 devflags
|= ISP1760_FLAG_DACK_POL_HIGH
;
229 if (of_property_read_bool(dp
, "dreq-polarity"))
230 devflags
|= ISP1760_FLAG_DREQ_POL_HIGH
;
231 } else if (dev_get_platdata(&pdev
->dev
)) {
232 struct isp1760_platform_data
*pdata
=
233 dev_get_platdata(&pdev
->dev
);
235 if (pdata
->is_isp1761
)
236 devflags
|= ISP1760_FLAG_ISP1761
;
237 if (pdata
->bus_width_16
)
238 devflags
|= ISP1760_FLAG_BUS_WIDTH_16
;
239 if (pdata
->port1_otg
)
240 devflags
|= ISP1760_FLAG_OTG_EN
;
241 if (pdata
->analog_oc
)
242 devflags
|= ISP1760_FLAG_ANALOG_OC
;
243 if (pdata
->dack_polarity_high
)
244 devflags
|= ISP1760_FLAG_DACK_POL_HIGH
;
245 if (pdata
->dreq_polarity_high
)
246 devflags
|= ISP1760_FLAG_DREQ_POL_HIGH
;
249 ret
= isp1760_register(mem_res
, irq_res
->start
, irqflags
, &pdev
->dev
,
254 pr_info("ISP1760 USB device initialised\n");
258 static int isp1760_plat_remove(struct platform_device
*pdev
)
260 isp1760_unregister(&pdev
->dev
);
266 static const struct of_device_id isp1760_of_match
[] = {
267 { .compatible
= "nxp,usb-isp1760", },
268 { .compatible
= "nxp,usb-isp1761", },
271 MODULE_DEVICE_TABLE(of
, isp1760_of_match
);
274 static struct platform_driver isp1760_plat_driver
= {
275 .probe
= isp1760_plat_probe
,
276 .remove
= isp1760_plat_remove
,
279 .of_match_table
= of_match_ptr(isp1760_of_match
),
283 static int __init
isp1760_init(void)
285 int ret
, any_ret
= -ENODEV
;
287 isp1760_init_kmem_once();
289 ret
= platform_driver_register(&isp1760_plat_driver
);
293 ret
= pci_register_driver(&isp1761_pci_driver
);
299 isp1760_deinit_kmem_cache();
302 module_init(isp1760_init
);
304 static void __exit
isp1760_exit(void)
306 platform_driver_unregister(&isp1760_plat_driver
);
308 pci_unregister_driver(&isp1761_pci_driver
);
310 isp1760_deinit_kmem_cache();
312 module_exit(isp1760_exit
);