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/kernel.h>
26 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/usb/isp1301.h>
30 #include <linux/usb.h>
31 #include <linux/usb/hcd.h>
36 #include <mach/hardware.h>
37 #include <asm/mach-types.h>
40 #include <mach/platform.h>
41 #include <mach/irqs.h>
43 #define USB_CONFIG_BASE 0x31020000
44 #define PWRMAN_BASE 0x40004000
46 #define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
48 /* USB_CTRL bit defines */
49 #define USB_SLAVE_HCLK_EN (1 << 24)
50 #define USB_DEV_NEED_CLK_EN (1 << 22)
51 #define USB_HOST_NEED_CLK_EN (1 << 21)
52 #define PAD_CONTROL_LAST_DRIVEN (1 << 19)
54 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
56 /* USB_OTG_STAT_CONTROL bit defines */
57 #define TRANSPARENT_I2C_EN (1 << 7)
58 #define HOST_EN (1 << 0)
60 /* On LPC32xx, those are undefined */
61 #ifndef start_int_set_falling_edge
62 #define start_int_set_falling_edge(irq)
63 #define start_int_set_rising_edge(irq)
64 #define start_int_ack(irq)
65 #define start_int_mask(irq)
66 #define start_int_umask(irq)
69 #define DRIVER_DESC "OHCI NXP driver"
71 static const char hcd_name
[] = "ohci-nxp";
72 static struct hc_driver __read_mostly ohci_nxp_hc_driver
;
74 static struct i2c_client
*isp1301_i2c_client
;
76 extern int usb_disabled(void);
78 static struct clk
*usb_pll_clk
;
79 static struct clk
*usb_dev_clk
;
80 static struct clk
*usb_otg_clk
;
82 static void isp1301_configure_lpc32xx(void)
84 /* LPC32XX only supports DAT_SE0 USB mode */
85 /* This sequence is important */
87 /* Disable transparent UART mode first */
88 i2c_smbus_write_byte_data(isp1301_i2c_client
,
89 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
91 i2c_smbus_write_byte_data(isp1301_i2c_client
,
92 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
94 i2c_smbus_write_byte_data(isp1301_i2c_client
,
95 ISP1301_I2C_MODE_CONTROL_1
, MC1_SPEED_REG
);
96 i2c_smbus_write_byte_data(isp1301_i2c_client
,
97 (ISP1301_I2C_MODE_CONTROL_2
| ISP1301_I2C_REG_CLEAR_ADDR
),
99 i2c_smbus_write_byte_data(isp1301_i2c_client
,
100 ISP1301_I2C_MODE_CONTROL_2
,
101 (MC2_BI_DI
| MC2_PSW_EN
| MC2_SPD_SUSP_CTRL
));
102 i2c_smbus_write_byte_data(isp1301_i2c_client
,
103 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
), ~0);
104 i2c_smbus_write_byte_data(isp1301_i2c_client
,
105 ISP1301_I2C_MODE_CONTROL_1
, MC1_DAT_SE0
);
106 i2c_smbus_write_byte_data(isp1301_i2c_client
,
107 ISP1301_I2C_OTG_CONTROL_1
,
108 (OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
109 i2c_smbus_write_byte_data(isp1301_i2c_client
,
110 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
111 (OTG1_DM_PULLUP
| OTG1_DP_PULLUP
));
112 i2c_smbus_write_byte_data(isp1301_i2c_client
,
113 ISP1301_I2C_INTERRUPT_LATCH
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
114 i2c_smbus_write_byte_data(isp1301_i2c_client
,
115 ISP1301_I2C_INTERRUPT_FALLING
| ISP1301_I2C_REG_CLEAR_ADDR
,
117 i2c_smbus_write_byte_data(isp1301_i2c_client
,
118 ISP1301_I2C_INTERRUPT_RISING
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
120 /* Enable usb_need_clk clock after transceiver is initialized */
121 __raw_writel(__raw_readl(USB_CTRL
) | USB_HOST_NEED_CLK_EN
, USB_CTRL
);
123 printk(KERN_INFO
"ISP1301 Vendor ID : 0x%04x\n",
124 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x00));
125 printk(KERN_INFO
"ISP1301 Product ID : 0x%04x\n",
126 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x02));
127 printk(KERN_INFO
"ISP1301 Version ID : 0x%04x\n",
128 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x14));
131 static void isp1301_configure(void)
133 isp1301_configure_lpc32xx();
136 static inline void isp1301_vbus_on(void)
138 i2c_smbus_write_byte_data(isp1301_i2c_client
, ISP1301_I2C_OTG_CONTROL_1
,
142 static inline void isp1301_vbus_off(void)
144 i2c_smbus_write_byte_data(isp1301_i2c_client
,
145 ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
,
149 static void ohci_nxp_start_hc(void)
151 unsigned long tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) | HOST_EN
;
152 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
156 static void ohci_nxp_stop_hc(void)
160 tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) & ~HOST_EN
;
161 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
164 static int ohci_hcd_nxp_probe(struct platform_device
*pdev
)
166 struct usb_hcd
*hcd
= 0;
167 const struct hc_driver
*driver
= &ohci_nxp_hc_driver
;
168 struct resource
*res
;
170 struct device_node
*isp1301_node
;
172 if (pdev
->dev
.of_node
) {
173 isp1301_node
= of_parse_phandle(pdev
->dev
.of_node
,
179 isp1301_i2c_client
= isp1301_get_client(isp1301_node
);
180 if (!isp1301_i2c_client
) {
181 return -EPROBE_DEFER
;
184 ret
= dma_coerce_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
188 dev_dbg(&pdev
->dev
, "%s: " DRIVER_DESC
" (nxp)\n", hcd_name
);
189 if (usb_disabled()) {
190 dev_err(&pdev
->dev
, "USB is disabled\n");
195 /* Enable AHB slave USB clock, needed for further USB clock control */
196 __raw_writel(USB_SLAVE_HCLK_EN
| PAD_CONTROL_LAST_DRIVEN
, USB_CTRL
);
199 usb_pll_clk
= devm_clk_get(&pdev
->dev
, "ck_pll5");
200 if (IS_ERR(usb_pll_clk
)) {
201 dev_err(&pdev
->dev
, "failed to acquire USB PLL\n");
202 ret
= PTR_ERR(usb_pll_clk
);
206 ret
= clk_enable(usb_pll_clk
);
208 dev_err(&pdev
->dev
, "failed to start USB PLL\n");
212 ret
= clk_set_rate(usb_pll_clk
, 48000);
214 dev_err(&pdev
->dev
, "failed to set USB clock rate\n");
218 /* Enable USB device clock */
219 usb_dev_clk
= devm_clk_get(&pdev
->dev
, "ck_usbd");
220 if (IS_ERR(usb_dev_clk
)) {
221 dev_err(&pdev
->dev
, "failed to acquire USB DEV Clock\n");
222 ret
= PTR_ERR(usb_dev_clk
);
226 ret
= clk_enable(usb_dev_clk
);
228 dev_err(&pdev
->dev
, "failed to start USB DEV Clock\n");
232 /* Enable USB otg clocks */
233 usb_otg_clk
= devm_clk_get(&pdev
->dev
, "ck_usb_otg");
234 if (IS_ERR(usb_otg_clk
)) {
235 dev_err(&pdev
->dev
, "failed to acquire USB DEV Clock\n");
236 ret
= PTR_ERR(usb_otg_clk
);
240 __raw_writel(__raw_readl(USB_CTRL
) | USB_HOST_NEED_CLK_EN
, USB_CTRL
);
242 ret
= clk_enable(usb_otg_clk
);
244 dev_err(&pdev
->dev
, "failed to start USB DEV Clock\n");
250 hcd
= usb_create_hcd(driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
252 dev_err(&pdev
->dev
, "Failed to allocate HC buffer\n");
257 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
258 hcd
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
259 if (IS_ERR(hcd
->regs
)) {
260 ret
= PTR_ERR(hcd
->regs
);
263 hcd
->rsrc_start
= res
->start
;
264 hcd
->rsrc_len
= resource_size(res
);
266 irq
= platform_get_irq(pdev
, 0);
273 platform_set_drvdata(pdev
, hcd
);
275 dev_info(&pdev
->dev
, "at 0x%p, irq %d\n", hcd
->regs
, hcd
->irq
);
276 ret
= usb_add_hcd(hcd
, irq
, 0);
278 device_wakeup_enable(hcd
->self
.controller
);
286 clk_disable(usb_otg_clk
);
288 clk_disable(usb_dev_clk
);
290 clk_disable(usb_pll_clk
);
292 isp1301_i2c_client
= NULL
;
296 static int ohci_hcd_nxp_remove(struct platform_device
*pdev
)
298 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
303 clk_disable(usb_pll_clk
);
304 clk_disable(usb_dev_clk
);
305 i2c_unregister_device(isp1301_i2c_client
);
306 isp1301_i2c_client
= NULL
;
311 /* work with hotplug and coldplug */
312 MODULE_ALIAS("platform:usb-ohci");
315 static const struct of_device_id ohci_hcd_nxp_match
[] = {
316 { .compatible
= "nxp,ohci-nxp" },
319 MODULE_DEVICE_TABLE(of
, ohci_hcd_nxp_match
);
322 static struct platform_driver ohci_hcd_nxp_driver
= {
325 .owner
= THIS_MODULE
,
326 .of_match_table
= of_match_ptr(ohci_hcd_nxp_match
),
328 .probe
= ohci_hcd_nxp_probe
,
329 .remove
= ohci_hcd_nxp_remove
,
332 static int __init
ohci_nxp_init(void)
337 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
339 ohci_init_driver(&ohci_nxp_hc_driver
, NULL
);
340 return platform_driver_register(&ohci_hcd_nxp_driver
);
342 module_init(ohci_nxp_init
);
344 static void __exit
ohci_nxp_cleanup(void)
346 platform_driver_unregister(&ohci_hcd_nxp_driver
);
348 module_exit(ohci_nxp_cleanup
);
350 MODULE_DESCRIPTION(DRIVER_DESC
);
351 MODULE_LICENSE("GPL v2");