2 * driver for NXP USB Host devices
4 * Currently supported OHCI host devices:
7 * Authors: Dmitry Chigirev <source@mvista.com>
8 * Vitaly Wool <vitalywool@gmail.com>
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 PWRMAN_BASE 0x40004000
39 #define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
41 /* USB_CTRL bit defines */
42 #define USB_SLAVE_HCLK_EN (1 << 24)
43 #define USB_DEV_NEED_CLK_EN (1 << 22)
44 #define USB_HOST_NEED_CLK_EN (1 << 21)
45 #define PAD_CONTROL_LAST_DRIVEN (1 << 19)
47 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
49 /* USB_OTG_STAT_CONTROL bit defines */
50 #define TRANSPARENT_I2C_EN (1 << 7)
51 #define HOST_EN (1 << 0)
53 /* On LPC32xx, those are undefined */
54 #ifndef start_int_set_falling_edge
55 #define start_int_set_falling_edge(irq)
56 #define start_int_set_rising_edge(irq)
57 #define start_int_ack(irq)
58 #define start_int_mask(irq)
59 #define start_int_umask(irq)
62 #define DRIVER_DESC "OHCI NXP driver"
64 static const char hcd_name[] = "ohci-nxp";
65 static struct hc_driver __read_mostly ohci_nxp_hc_driver;
67 static struct i2c_client *isp1301_i2c_client;
69 extern int usb_disabled(void);
71 static struct clk *usb_pll_clk;
72 static struct clk *usb_dev_clk;
73 static struct clk *usb_otg_clk;
75 static void isp1301_configure_lpc32xx(void)
77 /* LPC32XX only supports DAT_SE0 USB mode */
78 /* This sequence is important */
80 /* Disable transparent UART mode first */
81 i2c_smbus_write_byte_data(isp1301_i2c_client,
82 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
84 i2c_smbus_write_byte_data(isp1301_i2c_client,
85 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
87 i2c_smbus_write_byte_data(isp1301_i2c_client,
88 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
89 i2c_smbus_write_byte_data(isp1301_i2c_client,
90 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
92 i2c_smbus_write_byte_data(isp1301_i2c_client,
93 ISP1301_I2C_MODE_CONTROL_2,
94 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
95 i2c_smbus_write_byte_data(isp1301_i2c_client,
96 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
97 i2c_smbus_write_byte_data(isp1301_i2c_client,
98 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
99 i2c_smbus_write_byte_data(isp1301_i2c_client,
100 ISP1301_I2C_OTG_CONTROL_1,
101 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
102 i2c_smbus_write_byte_data(isp1301_i2c_client,
103 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
104 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
105 i2c_smbus_write_byte_data(isp1301_i2c_client,
106 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
107 i2c_smbus_write_byte_data(isp1301_i2c_client,
108 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
110 i2c_smbus_write_byte_data(isp1301_i2c_client,
111 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
113 /* Enable usb_need_clk clock after transceiver is initialized */
114 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
116 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
117 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
118 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
119 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
120 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
121 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
124 static void isp1301_configure(void)
126 isp1301_configure_lpc32xx();
129 static inline void isp1301_vbus_on(void)
131 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
135 static inline void isp1301_vbus_off(void)
137 i2c_smbus_write_byte_data(isp1301_i2c_client,
138 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
142 static void ohci_nxp_start_hc(void)
144 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
145 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
149 static void ohci_nxp_stop_hc(void)
153 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
154 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
157 static int ohci_hcd_nxp_probe(struct platform_device *pdev)
159 struct usb_hcd *hcd = 0;
160 const struct hc_driver *driver = &ohci_nxp_hc_driver;
161 struct resource *res;
163 struct device_node *isp1301_node;
165 if (pdev->dev.of_node) {
166 isp1301_node = of_parse_phandle(pdev->dev.of_node,
172 isp1301_i2c_client = isp1301_get_client(isp1301_node);
173 if (!isp1301_i2c_client) {
174 return -EPROBE_DEFER;
177 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
181 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
182 if (usb_disabled()) {
183 dev_err(&pdev->dev, "USB is disabled\n");
188 /* Enable AHB slave USB clock, needed for further USB clock control */
189 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
192 usb_pll_clk = devm_clk_get(&pdev->dev, "ck_pll5");
193 if (IS_ERR(usb_pll_clk)) {
194 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
195 ret = PTR_ERR(usb_pll_clk);
199 ret = clk_prepare_enable(usb_pll_clk);
201 dev_err(&pdev->dev, "failed to start USB PLL\n");
205 ret = clk_set_rate(usb_pll_clk, 48000);
207 dev_err(&pdev->dev, "failed to set USB clock rate\n");
211 /* Enable USB device clock */
212 usb_dev_clk = devm_clk_get(&pdev->dev, "ck_usbd");
213 if (IS_ERR(usb_dev_clk)) {
214 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
215 ret = PTR_ERR(usb_dev_clk);
219 ret = clk_prepare_enable(usb_dev_clk);
221 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
225 /* Enable USB otg clocks */
226 usb_otg_clk = devm_clk_get(&pdev->dev, "ck_usb_otg");
227 if (IS_ERR(usb_otg_clk)) {
228 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
229 ret = PTR_ERR(usb_otg_clk);
233 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
235 ret = clk_prepare_enable(usb_otg_clk);
237 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
243 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
245 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
250 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
251 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
252 if (IS_ERR(hcd->regs)) {
253 ret = PTR_ERR(hcd->regs);
256 hcd->rsrc_start = res->start;
257 hcd->rsrc_len = resource_size(res);
259 irq = platform_get_irq(pdev, 0);
266 platform_set_drvdata(pdev, hcd);
268 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
269 ret = usb_add_hcd(hcd, irq, 0);
271 device_wakeup_enable(hcd->self.controller);
279 clk_disable_unprepare(usb_otg_clk);
281 clk_disable_unprepare(usb_dev_clk);
283 clk_disable_unprepare(usb_pll_clk);
285 isp1301_i2c_client = NULL;
289 static int ohci_hcd_nxp_remove(struct platform_device *pdev)
291 struct usb_hcd *hcd = platform_get_drvdata(pdev);
296 clk_disable_unprepare(usb_otg_clk);
297 clk_disable_unprepare(usb_dev_clk);
298 clk_disable_unprepare(usb_pll_clk);
299 isp1301_i2c_client = NULL;
304 /* work with hotplug and coldplug */
305 MODULE_ALIAS("platform:usb-ohci");
308 static const struct of_device_id ohci_hcd_nxp_match[] = {
309 { .compatible = "nxp,ohci-nxp" },
312 MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
315 static struct platform_driver ohci_hcd_nxp_driver = {
318 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
320 .probe = ohci_hcd_nxp_probe,
321 .remove = ohci_hcd_nxp_remove,
324 static int __init ohci_nxp_init(void)
329 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
331 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
332 return platform_driver_register(&ohci_hcd_nxp_driver);
334 module_init(ohci_nxp_init);
336 static void __exit ohci_nxp_cleanup(void)
338 platform_driver_unregister(&ohci_hcd_nxp_driver);
340 module_exit(ohci_nxp_cleanup);
342 MODULE_DESCRIPTION(DRIVER_DESC);
343 MODULE_LICENSE("GPL v2");