2 * driver for NXP USB Host devices
4 * 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. This file is licensed under
18 * the terms of the GNU General Public License version 2. This program
19 * is licensed "as is" without any warranty of any kind, whether express
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/i2c.h>
26 #include <linux/usb/isp1301.h>
28 #include <mach/hardware.h>
29 #include <asm/mach-types.h>
32 #include <mach/platform.h>
33 #include <mach/irqs.h>
35 #define USB_CONFIG_BASE 0x31020000
36 #define PWRMAN_BASE 0x40004000
38 #define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
40 /* USB_CTRL bit defines */
41 #define USB_SLAVE_HCLK_EN (1 << 24)
42 #define USB_DEV_NEED_CLK_EN (1 << 22)
43 #define USB_HOST_NEED_CLK_EN (1 << 21)
44 #define PAD_CONTROL_LAST_DRIVEN (1 << 19)
46 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
48 /* USB_OTG_STAT_CONTROL bit defines */
49 #define TRANSPARENT_I2C_EN (1 << 7)
50 #define HOST_EN (1 << 0)
52 /* On LPC32xx, those are undefined */
53 #ifndef start_int_set_falling_edge
54 #define start_int_set_falling_edge(irq)
55 #define start_int_set_rising_edge(irq)
56 #define start_int_ack(irq)
57 #define start_int_mask(irq)
58 #define start_int_umask(irq)
61 static struct i2c_client *isp1301_i2c_client;
63 extern int usb_disabled(void);
65 static struct clk *usb_pll_clk;
66 static struct clk *usb_dev_clk;
67 static struct clk *usb_otg_clk;
69 static void isp1301_configure_pnx4008(void)
71 /* PNX4008 only supports DAT_SE0 USB mode */
72 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
73 /* Power up externel charge-pump */
75 i2c_smbus_write_byte_data(isp1301_i2c_client,
76 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG);
77 i2c_smbus_write_byte_data(isp1301_i2c_client,
78 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
79 ~(MC1_DAT_SE0 | MC1_SPEED_REG));
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_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR,
85 ~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
86 i2c_smbus_write_byte_data(isp1301_i2c_client,
87 ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
88 i2c_smbus_write_byte_data(isp1301_i2c_client,
89 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
90 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
91 i2c_smbus_write_byte_data(isp1301_i2c_client,
92 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF);
93 i2c_smbus_write_byte_data(isp1301_i2c_client,
94 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
96 i2c_smbus_write_byte_data(isp1301_i2c_client,
97 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
101 static void isp1301_configure_lpc32xx(void)
103 /* LPC32XX only supports DAT_SE0 USB mode */
104 /* This sequence is important */
106 /* Disable transparent UART mode first */
107 i2c_smbus_write_byte_data(isp1301_i2c_client,
108 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
110 i2c_smbus_write_byte_data(isp1301_i2c_client,
111 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
113 i2c_smbus_write_byte_data(isp1301_i2c_client,
114 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
115 i2c_smbus_write_byte_data(isp1301_i2c_client,
116 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
118 i2c_smbus_write_byte_data(isp1301_i2c_client,
119 ISP1301_I2C_MODE_CONTROL_2,
120 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
121 i2c_smbus_write_byte_data(isp1301_i2c_client,
122 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
123 i2c_smbus_write_byte_data(isp1301_i2c_client,
124 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
125 i2c_smbus_write_byte_data(isp1301_i2c_client,
126 ISP1301_I2C_OTG_CONTROL_1,
127 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
128 i2c_smbus_write_byte_data(isp1301_i2c_client,
129 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
130 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
131 i2c_smbus_write_byte_data(isp1301_i2c_client,
132 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
133 i2c_smbus_write_byte_data(isp1301_i2c_client,
134 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
136 i2c_smbus_write_byte_data(isp1301_i2c_client,
137 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
139 /* Enable usb_need_clk clock after transceiver is initialized */
140 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
142 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
143 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
144 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
145 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
146 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
147 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
150 static void isp1301_configure(void)
152 if (machine_is_pnx4008())
153 isp1301_configure_pnx4008();
155 isp1301_configure_lpc32xx();
158 static inline void isp1301_vbus_on(void)
160 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
164 static inline void isp1301_vbus_off(void)
166 i2c_smbus_write_byte_data(isp1301_i2c_client,
167 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
171 static void nxp_start_hc(void)
173 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
174 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
178 static void nxp_stop_hc(void)
182 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
183 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
186 static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
188 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
191 if ((ret = ohci_init(ohci)) < 0)
194 if ((ret = ohci_run(ohci)) < 0) {
195 dev_err(hcd->self.controller, "can't start\n");
202 static const struct hc_driver ohci_nxp_hc_driver = {
203 .description = hcd_name,
204 .product_desc = "nxp OHCI",
207 * generic hardware linkage
210 .flags = HCD_USB11 | HCD_MEMORY,
212 .hcd_priv_size = sizeof(struct ohci_hcd),
214 * basic lifecycle operations
216 .start = ohci_nxp_start,
218 .shutdown = ohci_shutdown,
221 * managing i/o requests and associated device resources
223 .urb_enqueue = ohci_urb_enqueue,
224 .urb_dequeue = ohci_urb_dequeue,
225 .endpoint_disable = ohci_endpoint_disable,
230 .get_frame_number = ohci_get_frame,
235 .hub_status_data = ohci_hub_status_data,
236 .hub_control = ohci_hub_control,
238 .bus_suspend = ohci_bus_suspend,
239 .bus_resume = ohci_bus_resume,
241 .start_port_reset = ohci_start_port_reset,
244 static void nxp_set_usb_bits(void)
246 if (machine_is_pnx4008()) {
247 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
248 start_int_ack(SE_USB_OTG_ATX_INT_N);
249 start_int_umask(SE_USB_OTG_ATX_INT_N);
251 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
252 start_int_ack(SE_USB_OTG_TIMER_INT);
253 start_int_umask(SE_USB_OTG_TIMER_INT);
255 start_int_set_rising_edge(SE_USB_I2C_INT);
256 start_int_ack(SE_USB_I2C_INT);
257 start_int_umask(SE_USB_I2C_INT);
259 start_int_set_rising_edge(SE_USB_INT);
260 start_int_ack(SE_USB_INT);
261 start_int_umask(SE_USB_INT);
263 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
264 start_int_ack(SE_USB_NEED_CLK_INT);
265 start_int_umask(SE_USB_NEED_CLK_INT);
267 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
268 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
269 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
273 static void nxp_unset_usb_bits(void)
275 if (machine_is_pnx4008()) {
276 start_int_mask(SE_USB_OTG_ATX_INT_N);
277 start_int_mask(SE_USB_OTG_TIMER_INT);
278 start_int_mask(SE_USB_I2C_INT);
279 start_int_mask(SE_USB_INT);
280 start_int_mask(SE_USB_NEED_CLK_INT);
281 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
285 static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
287 struct usb_hcd *hcd = 0;
288 struct ohci_hcd *ohci;
289 const struct hc_driver *driver = &ohci_nxp_hc_driver;
290 struct resource *res;
292 struct device_node *isp1301_node;
294 if (pdev->dev.of_node) {
295 isp1301_node = of_parse_phandle(pdev->dev.of_node,
301 isp1301_i2c_client = isp1301_get_client(isp1301_node);
302 if (!isp1301_i2c_client) {
307 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
308 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
310 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
311 if (usb_disabled()) {
312 dev_err(&pdev->dev, "USB is disabled\n");
317 /* Enable AHB slave USB clock, needed for further USB clock control */
318 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
321 usb_pll_clk = clk_get(&pdev->dev, "ck_pll5");
322 if (IS_ERR(usb_pll_clk)) {
323 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
324 ret = PTR_ERR(usb_pll_clk);
328 ret = clk_enable(usb_pll_clk);
330 dev_err(&pdev->dev, "failed to start USB PLL\n");
334 ret = clk_set_rate(usb_pll_clk, 48000);
336 dev_err(&pdev->dev, "failed to set USB clock rate\n");
340 /* Enable USB device clock */
341 usb_dev_clk = clk_get(&pdev->dev, "ck_usbd");
342 if (IS_ERR(usb_dev_clk)) {
343 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
344 ret = PTR_ERR(usb_dev_clk);
348 ret = clk_enable(usb_dev_clk);
350 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
354 /* Enable USB otg clocks */
355 usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
356 if (IS_ERR(usb_otg_clk)) {
357 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
358 ret = PTR_ERR(usb_otg_clk);
362 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
364 ret = clk_enable(usb_otg_clk);
366 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
372 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
374 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
379 /* Set all USB bits in the Start Enable register */
382 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
384 dev_err(&pdev->dev, "Failed to get MEM resource\n");
389 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
391 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
395 hcd->rsrc_start = res->start;
396 hcd->rsrc_len = resource_size(res);
398 irq = platform_get_irq(pdev, 0);
405 platform_set_drvdata(pdev, hcd);
406 ohci = hcd_to_ohci(hcd);
409 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
410 ret = usb_add_hcd(hcd, irq, 0);
416 nxp_unset_usb_bits();
419 clk_disable(usb_otg_clk);
421 clk_put(usb_otg_clk);
423 clk_disable(usb_dev_clk);
425 clk_put(usb_dev_clk);
427 clk_disable(usb_pll_clk);
429 clk_put(usb_pll_clk);
431 isp1301_i2c_client = NULL;
436 static int usb_hcd_nxp_remove(struct platform_device *pdev)
438 struct usb_hcd *hcd = platform_get_drvdata(pdev);
442 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
444 nxp_unset_usb_bits();
445 clk_disable(usb_pll_clk);
446 clk_put(usb_pll_clk);
447 clk_disable(usb_dev_clk);
448 clk_put(usb_dev_clk);
449 i2c_unregister_device(isp1301_i2c_client);
450 isp1301_i2c_client = NULL;
452 platform_set_drvdata(pdev, NULL);
457 /* work with hotplug and coldplug */
458 MODULE_ALIAS("platform:usb-ohci");
461 static const struct of_device_id usb_hcd_nxp_match[] = {
462 { .compatible = "nxp,ohci-nxp" },
465 MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
468 static struct platform_driver usb_hcd_nxp_driver = {
471 .owner = THIS_MODULE,
472 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
474 .probe = usb_hcd_nxp_probe,
475 .remove = usb_hcd_nxp_remove,