2 * driver for NXP USB Host devices
4 * Currently supported OHCI host devices:
10 * register initialization is based on code examples provided by Philips
11 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
13 * NOTE: This driver does not have suspend/resume functionality
14 * This driver is intended for engineering development purposes only
16 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
17 * the terms of the GNU General Public License version 2. This program
18 * is licensed "as is" without any warranty of any kind, whether express
21 #include <linux/clk.h>
22 #include <linux/dma-mapping.h>
24 #include <linux/i2c.h>
25 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/usb/isp1301.h>
29 #include <linux/usb.h>
30 #include <linux/usb/hcd.h>
34 #include <mach/hardware.h>
36 #define USB_CONFIG_BASE 0x31020000
37 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
39 /* USB_OTG_STAT_CONTROL bit defines */
40 #define TRANSPARENT_I2C_EN (1 << 7)
41 #define HOST_EN (1 << 0)
43 /* On LPC32xx, those are undefined */
44 #ifndef start_int_set_falling_edge
45 #define start_int_set_falling_edge(irq)
46 #define start_int_set_rising_edge(irq)
47 #define start_int_ack(irq)
48 #define start_int_mask(irq)
49 #define start_int_umask(irq)
52 #define DRIVER_DESC "OHCI NXP driver"
54 static const char hcd_name[] = "ohci-nxp";
55 static struct hc_driver __read_mostly ohci_nxp_hc_driver;
57 static struct i2c_client *isp1301_i2c_client;
59 extern int usb_disabled(void);
61 static struct clk *usb_host_clk;
63 static void isp1301_configure_lpc32xx(void)
65 /* LPC32XX only supports DAT_SE0 USB mode */
66 /* This sequence is important */
68 /* Disable transparent UART mode first */
69 i2c_smbus_write_byte_data(isp1301_i2c_client,
70 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
72 i2c_smbus_write_byte_data(isp1301_i2c_client,
73 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
75 i2c_smbus_write_byte_data(isp1301_i2c_client,
76 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
77 i2c_smbus_write_byte_data(isp1301_i2c_client,
78 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
80 i2c_smbus_write_byte_data(isp1301_i2c_client,
81 ISP1301_I2C_MODE_CONTROL_2,
82 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
83 i2c_smbus_write_byte_data(isp1301_i2c_client,
84 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
85 i2c_smbus_write_byte_data(isp1301_i2c_client,
86 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
87 i2c_smbus_write_byte_data(isp1301_i2c_client,
88 ISP1301_I2C_OTG_CONTROL_1,
89 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
90 i2c_smbus_write_byte_data(isp1301_i2c_client,
91 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
92 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
93 i2c_smbus_write_byte_data(isp1301_i2c_client,
94 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
95 i2c_smbus_write_byte_data(isp1301_i2c_client,
96 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
98 i2c_smbus_write_byte_data(isp1301_i2c_client,
99 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
101 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
102 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
103 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
104 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
105 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
106 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
109 static void isp1301_configure(void)
111 isp1301_configure_lpc32xx();
114 static inline void isp1301_vbus_on(void)
116 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
120 static inline void isp1301_vbus_off(void)
122 i2c_smbus_write_byte_data(isp1301_i2c_client,
123 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
127 static void ohci_nxp_start_hc(void)
129 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
130 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
134 static void ohci_nxp_stop_hc(void)
138 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
139 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
142 static int ohci_hcd_nxp_probe(struct platform_device *pdev)
144 struct usb_hcd *hcd = 0;
145 const struct hc_driver *driver = &ohci_nxp_hc_driver;
146 struct resource *res;
148 struct device_node *isp1301_node;
150 if (pdev->dev.of_node) {
151 isp1301_node = of_parse_phandle(pdev->dev.of_node,
157 isp1301_i2c_client = isp1301_get_client(isp1301_node);
158 if (!isp1301_i2c_client) {
159 return -EPROBE_DEFER;
162 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
166 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
167 if (usb_disabled()) {
168 dev_err(&pdev->dev, "USB is disabled\n");
173 /* Enable USB host clock */
174 usb_host_clk = devm_clk_get(&pdev->dev, NULL);
175 if (IS_ERR(usb_host_clk)) {
176 dev_err(&pdev->dev, "failed to acquire USB OHCI clock\n");
177 ret = PTR_ERR(usb_host_clk);
181 ret = clk_prepare_enable(usb_host_clk);
183 dev_err(&pdev->dev, "failed to start USB OHCI clock\n");
189 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
191 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
198 if (IS_ERR(hcd->regs)) {
199 ret = PTR_ERR(hcd->regs);
202 hcd->rsrc_start = res->start;
203 hcd->rsrc_len = resource_size(res);
205 irq = platform_get_irq(pdev, 0);
212 platform_set_drvdata(pdev, hcd);
214 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
215 ret = usb_add_hcd(hcd, irq, 0);
217 device_wakeup_enable(hcd->self.controller);
225 clk_disable_unprepare(usb_host_clk);
227 isp1301_i2c_client = NULL;
231 static int ohci_hcd_nxp_remove(struct platform_device *pdev)
233 struct usb_hcd *hcd = platform_get_drvdata(pdev);
238 clk_disable_unprepare(usb_host_clk);
239 isp1301_i2c_client = NULL;
244 /* work with hotplug and coldplug */
245 MODULE_ALIAS("platform:usb-ohci");
248 static const struct of_device_id ohci_hcd_nxp_match[] = {
249 { .compatible = "nxp,ohci-nxp" },
252 MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
255 static struct platform_driver ohci_hcd_nxp_driver = {
258 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
260 .probe = ohci_hcd_nxp_probe,
261 .remove = ohci_hcd_nxp_remove,
264 static int __init ohci_nxp_init(void)
269 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
271 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
272 return platform_driver_register(&ohci_hcd_nxp_driver);
274 module_init(ohci_nxp_init);
276 static void __exit ohci_nxp_cleanup(void)
278 platform_driver_unregister(&ohci_hcd_nxp_driver);
280 module_exit(ohci_nxp_cleanup);
282 MODULE_DESCRIPTION(DRIVER_DESC);
283 MODULE_LICENSE("GPL v2");