1 // SPDX-License-Identifier: GPL-2.0
3 * driver for NXP USB Host devices
5 * Currently supported OHCI host devices:
8 * Authors: Dmitry Chigirev <source@mvista.com>
9 * Vitaly Wool <vitalywool@gmail.com>
11 * register initialization is based on code examples provided by Philips
12 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
14 * NOTE: This driver does not have suspend/resume functionality
15 * This driver is intended for engineering development purposes only
17 * 2005-2006 (c) MontaVista Software, Inc.
19 #include <linux/clk.h>
20 #include <linux/dma-mapping.h>
22 #include <linux/i2c.h>
23 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/usb/isp1301.h>
27 #include <linux/usb.h>
28 #include <linux/usb/hcd.h>
32 #include <mach/hardware.h>
34 #define USB_CONFIG_BASE 0x31020000
35 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
37 /* USB_OTG_STAT_CONTROL bit defines */
38 #define TRANSPARENT_I2C_EN (1 << 7)
39 #define HOST_EN (1 << 0)
41 /* On LPC32xx, those are undefined */
42 #ifndef start_int_set_falling_edge
43 #define start_int_set_falling_edge(irq)
44 #define start_int_set_rising_edge(irq)
45 #define start_int_ack(irq)
46 #define start_int_mask(irq)
47 #define start_int_umask(irq)
50 #define DRIVER_DESC "OHCI NXP driver"
52 static const char hcd_name
[] = "ohci-nxp";
53 static struct hc_driver __read_mostly ohci_nxp_hc_driver
;
55 static struct i2c_client
*isp1301_i2c_client
;
57 static struct clk
*usb_host_clk
;
59 static void isp1301_configure_lpc32xx(void)
61 /* LPC32XX only supports DAT_SE0 USB mode */
62 /* This sequence is important */
64 /* Disable transparent UART mode first */
65 i2c_smbus_write_byte_data(isp1301_i2c_client
,
66 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
68 i2c_smbus_write_byte_data(isp1301_i2c_client
,
69 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
71 i2c_smbus_write_byte_data(isp1301_i2c_client
,
72 ISP1301_I2C_MODE_CONTROL_1
, MC1_SPEED_REG
);
73 i2c_smbus_write_byte_data(isp1301_i2c_client
,
74 (ISP1301_I2C_MODE_CONTROL_2
| ISP1301_I2C_REG_CLEAR_ADDR
),
76 i2c_smbus_write_byte_data(isp1301_i2c_client
,
77 ISP1301_I2C_MODE_CONTROL_2
,
78 (MC2_BI_DI
| MC2_PSW_EN
| MC2_SPD_SUSP_CTRL
));
79 i2c_smbus_write_byte_data(isp1301_i2c_client
,
80 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
), ~0);
81 i2c_smbus_write_byte_data(isp1301_i2c_client
,
82 ISP1301_I2C_MODE_CONTROL_1
, MC1_DAT_SE0
);
83 i2c_smbus_write_byte_data(isp1301_i2c_client
,
84 ISP1301_I2C_OTG_CONTROL_1
,
85 (OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
86 i2c_smbus_write_byte_data(isp1301_i2c_client
,
87 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
88 (OTG1_DM_PULLUP
| OTG1_DP_PULLUP
));
89 i2c_smbus_write_byte_data(isp1301_i2c_client
,
90 ISP1301_I2C_INTERRUPT_LATCH
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
91 i2c_smbus_write_byte_data(isp1301_i2c_client
,
92 ISP1301_I2C_INTERRUPT_FALLING
| ISP1301_I2C_REG_CLEAR_ADDR
,
94 i2c_smbus_write_byte_data(isp1301_i2c_client
,
95 ISP1301_I2C_INTERRUPT_RISING
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
97 printk(KERN_INFO
"ISP1301 Vendor ID : 0x%04x\n",
98 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x00));
99 printk(KERN_INFO
"ISP1301 Product ID : 0x%04x\n",
100 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x02));
101 printk(KERN_INFO
"ISP1301 Version ID : 0x%04x\n",
102 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x14));
105 static void isp1301_configure(void)
107 isp1301_configure_lpc32xx();
110 static inline void isp1301_vbus_on(void)
112 i2c_smbus_write_byte_data(isp1301_i2c_client
, ISP1301_I2C_OTG_CONTROL_1
,
116 static inline void isp1301_vbus_off(void)
118 i2c_smbus_write_byte_data(isp1301_i2c_client
,
119 ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
,
123 static void ohci_nxp_start_hc(void)
125 unsigned long tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) | HOST_EN
;
127 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
131 static void ohci_nxp_stop_hc(void)
136 tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) & ~HOST_EN
;
137 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
140 static int ohci_hcd_nxp_probe(struct platform_device
*pdev
)
142 struct usb_hcd
*hcd
= 0;
143 const struct hc_driver
*driver
= &ohci_nxp_hc_driver
;
144 struct resource
*res
;
146 struct device_node
*isp1301_node
;
148 if (pdev
->dev
.of_node
) {
149 isp1301_node
= of_parse_phandle(pdev
->dev
.of_node
,
155 isp1301_i2c_client
= isp1301_get_client(isp1301_node
);
156 if (!isp1301_i2c_client
)
157 return -EPROBE_DEFER
;
159 ret
= dma_coerce_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
163 dev_dbg(&pdev
->dev
, "%s: " DRIVER_DESC
" (nxp)\n", hcd_name
);
164 if (usb_disabled()) {
165 dev_err(&pdev
->dev
, "USB is disabled\n");
170 /* Enable USB host clock */
171 usb_host_clk
= devm_clk_get(&pdev
->dev
, NULL
);
172 if (IS_ERR(usb_host_clk
)) {
173 dev_err(&pdev
->dev
, "failed to acquire USB OHCI clock\n");
174 ret
= PTR_ERR(usb_host_clk
);
178 ret
= clk_prepare_enable(usb_host_clk
);
180 dev_err(&pdev
->dev
, "failed to start USB OHCI clock\n");
186 hcd
= usb_create_hcd(driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
188 dev_err(&pdev
->dev
, "Failed to allocate HC buffer\n");
193 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
194 hcd
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
195 if (IS_ERR(hcd
->regs
)) {
196 ret
= PTR_ERR(hcd
->regs
);
199 hcd
->rsrc_start
= res
->start
;
200 hcd
->rsrc_len
= resource_size(res
);
202 irq
= platform_get_irq(pdev
, 0);
209 platform_set_drvdata(pdev
, hcd
);
211 dev_info(&pdev
->dev
, "at 0x%p, irq %d\n", hcd
->regs
, hcd
->irq
);
212 ret
= usb_add_hcd(hcd
, irq
, 0);
214 device_wakeup_enable(hcd
->self
.controller
);
222 clk_disable_unprepare(usb_host_clk
);
224 isp1301_i2c_client
= NULL
;
228 static int ohci_hcd_nxp_remove(struct platform_device
*pdev
)
230 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
235 clk_disable_unprepare(usb_host_clk
);
236 isp1301_i2c_client
= NULL
;
241 /* work with hotplug and coldplug */
242 MODULE_ALIAS("platform:usb-ohci");
245 static const struct of_device_id ohci_hcd_nxp_match
[] = {
246 { .compatible
= "nxp,ohci-nxp" },
249 MODULE_DEVICE_TABLE(of
, ohci_hcd_nxp_match
);
252 static struct platform_driver ohci_hcd_nxp_driver
= {
255 .of_match_table
= of_match_ptr(ohci_hcd_nxp_match
),
257 .probe
= ohci_hcd_nxp_probe
,
258 .remove
= ohci_hcd_nxp_remove
,
261 static int __init
ohci_nxp_init(void)
266 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
268 ohci_init_driver(&ohci_nxp_hc_driver
, NULL
);
269 return platform_driver_register(&ohci_hcd_nxp_driver
);
271 module_init(ohci_nxp_init
);
273 static void __exit
ohci_nxp_cleanup(void)
275 platform_driver_unregister(&ohci_hcd_nxp_driver
);
277 module_exit(ohci_nxp_cleanup
);
279 MODULE_DESCRIPTION(DRIVER_DESC
);
280 MODULE_LICENSE("GPL v2");