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_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
47 #define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
49 /* USB_OTG_CLK_CTRL bit defines */
50 #define AHB_M_CLOCK_ON (1 << 4)
51 #define OTG_CLOCK_ON (1 << 3)
52 #define I2C_CLOCK_ON (1 << 2)
53 #define DEV_CLOCK_ON (1 << 1)
54 #define HOST_CLOCK_ON (1 << 0)
56 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
58 /* USB_OTG_STAT_CONTROL bit defines */
59 #define TRANSPARENT_I2C_EN (1 << 7)
60 #define HOST_EN (1 << 0)
62 /* On LPC32xx, those are undefined */
63 #ifndef start_int_set_falling_edge
64 #define start_int_set_falling_edge(irq)
65 #define start_int_set_rising_edge(irq)
66 #define start_int_ack(irq)
67 #define start_int_mask(irq)
68 #define start_int_umask(irq)
71 static struct i2c_client
*isp1301_i2c_client
;
73 extern int usb_disabled(void);
75 static struct clk
*usb_clk
;
77 static void isp1301_configure_pnx4008(void)
79 /* PNX4008 only supports DAT_SE0 USB mode */
80 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
81 /* Power up externel charge-pump */
83 i2c_smbus_write_byte_data(isp1301_i2c_client
,
84 ISP1301_I2C_MODE_CONTROL_1
, MC1_DAT_SE0
| MC1_SPEED_REG
);
85 i2c_smbus_write_byte_data(isp1301_i2c_client
,
86 ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
,
87 ~(MC1_DAT_SE0
| MC1_SPEED_REG
));
88 i2c_smbus_write_byte_data(isp1301_i2c_client
,
89 ISP1301_I2C_MODE_CONTROL_2
,
90 MC2_BI_DI
| MC2_PSW_EN
| MC2_SPD_SUSP_CTRL
);
91 i2c_smbus_write_byte_data(isp1301_i2c_client
,
92 ISP1301_I2C_MODE_CONTROL_2
| ISP1301_I2C_REG_CLEAR_ADDR
,
93 ~(MC2_BI_DI
| MC2_PSW_EN
| MC2_SPD_SUSP_CTRL
));
94 i2c_smbus_write_byte_data(isp1301_i2c_client
,
95 ISP1301_I2C_OTG_CONTROL_1
, OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
);
96 i2c_smbus_write_byte_data(isp1301_i2c_client
,
97 ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
,
98 ~(OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
99 i2c_smbus_write_byte_data(isp1301_i2c_client
,
100 ISP1301_I2C_INTERRUPT_LATCH
| ISP1301_I2C_REG_CLEAR_ADDR
, 0xFF);
101 i2c_smbus_write_byte_data(isp1301_i2c_client
,
102 ISP1301_I2C_INTERRUPT_FALLING
| ISP1301_I2C_REG_CLEAR_ADDR
,
104 i2c_smbus_write_byte_data(isp1301_i2c_client
,
105 ISP1301_I2C_INTERRUPT_RISING
| ISP1301_I2C_REG_CLEAR_ADDR
,
109 static void isp1301_configure_lpc32xx(void)
111 /* LPC32XX only supports DAT_SE0 USB mode */
112 /* This sequence is important */
114 /* Disable transparent UART mode first */
115 i2c_smbus_write_byte_data(isp1301_i2c_client
,
116 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
118 i2c_smbus_write_byte_data(isp1301_i2c_client
,
119 (ISP1301_I2C_MODE_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
121 i2c_smbus_write_byte_data(isp1301_i2c_client
,
122 ISP1301_I2C_MODE_CONTROL_1
, MC1_SPEED_REG
);
123 i2c_smbus_write_byte_data(isp1301_i2c_client
,
124 (ISP1301_I2C_MODE_CONTROL_2
| ISP1301_I2C_REG_CLEAR_ADDR
),
126 i2c_smbus_write_byte_data(isp1301_i2c_client
,
127 ISP1301_I2C_MODE_CONTROL_2
,
128 (MC2_BI_DI
| MC2_PSW_EN
| MC2_SPD_SUSP_CTRL
));
129 i2c_smbus_write_byte_data(isp1301_i2c_client
,
130 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
), ~0);
131 i2c_smbus_write_byte_data(isp1301_i2c_client
,
132 ISP1301_I2C_MODE_CONTROL_1
, MC1_DAT_SE0
);
133 i2c_smbus_write_byte_data(isp1301_i2c_client
,
134 ISP1301_I2C_OTG_CONTROL_1
,
135 (OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
136 i2c_smbus_write_byte_data(isp1301_i2c_client
,
137 (ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
),
138 (OTG1_DM_PULLUP
| OTG1_DP_PULLUP
));
139 i2c_smbus_write_byte_data(isp1301_i2c_client
,
140 ISP1301_I2C_INTERRUPT_LATCH
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
141 i2c_smbus_write_byte_data(isp1301_i2c_client
,
142 ISP1301_I2C_INTERRUPT_FALLING
| ISP1301_I2C_REG_CLEAR_ADDR
,
144 i2c_smbus_write_byte_data(isp1301_i2c_client
,
145 ISP1301_I2C_INTERRUPT_RISING
| ISP1301_I2C_REG_CLEAR_ADDR
, ~0);
147 /* Enable usb_need_clk clock after transceiver is initialized */
148 __raw_writel(__raw_readl(USB_CTRL
) | USB_HOST_NEED_CLK_EN
, USB_CTRL
);
150 printk(KERN_INFO
"ISP1301 Vendor ID : 0x%04x\n",
151 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x00));
152 printk(KERN_INFO
"ISP1301 Product ID : 0x%04x\n",
153 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x02));
154 printk(KERN_INFO
"ISP1301 Version ID : 0x%04x\n",
155 i2c_smbus_read_word_data(isp1301_i2c_client
, 0x14));
158 static void isp1301_configure(void)
160 if (machine_is_pnx4008())
161 isp1301_configure_pnx4008();
163 isp1301_configure_lpc32xx();
166 static inline void isp1301_vbus_on(void)
168 i2c_smbus_write_byte_data(isp1301_i2c_client
, ISP1301_I2C_OTG_CONTROL_1
,
172 static inline void isp1301_vbus_off(void)
174 i2c_smbus_write_byte_data(isp1301_i2c_client
,
175 ISP1301_I2C_OTG_CONTROL_1
| ISP1301_I2C_REG_CLEAR_ADDR
,
179 static void nxp_start_hc(void)
181 unsigned long tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) | HOST_EN
;
182 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
186 static void nxp_stop_hc(void)
190 tmp
= __raw_readl(USB_OTG_STAT_CONTROL
) & ~HOST_EN
;
191 __raw_writel(tmp
, USB_OTG_STAT_CONTROL
);
194 static int __devinit
ohci_nxp_start(struct usb_hcd
*hcd
)
196 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
199 if ((ret
= ohci_init(ohci
)) < 0)
202 if ((ret
= ohci_run(ohci
)) < 0) {
203 dev_err(hcd
->self
.controller
, "can't start\n");
210 static const struct hc_driver ohci_nxp_hc_driver
= {
211 .description
= hcd_name
,
212 .product_desc
= "nxp OHCI",
215 * generic hardware linkage
218 .flags
= HCD_USB11
| HCD_MEMORY
,
220 .hcd_priv_size
= sizeof(struct ohci_hcd
),
222 * basic lifecycle operations
224 .start
= ohci_nxp_start
,
226 .shutdown
= ohci_shutdown
,
229 * managing i/o requests and associated device resources
231 .urb_enqueue
= ohci_urb_enqueue
,
232 .urb_dequeue
= ohci_urb_dequeue
,
233 .endpoint_disable
= ohci_endpoint_disable
,
238 .get_frame_number
= ohci_get_frame
,
243 .hub_status_data
= ohci_hub_status_data
,
244 .hub_control
= ohci_hub_control
,
246 .bus_suspend
= ohci_bus_suspend
,
247 .bus_resume
= ohci_bus_resume
,
249 .start_port_reset
= ohci_start_port_reset
,
252 #define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
254 static void nxp_set_usb_bits(void)
256 if (machine_is_pnx4008()) {
257 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N
);
258 start_int_ack(SE_USB_OTG_ATX_INT_N
);
259 start_int_umask(SE_USB_OTG_ATX_INT_N
);
261 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT
);
262 start_int_ack(SE_USB_OTG_TIMER_INT
);
263 start_int_umask(SE_USB_OTG_TIMER_INT
);
265 start_int_set_rising_edge(SE_USB_I2C_INT
);
266 start_int_ack(SE_USB_I2C_INT
);
267 start_int_umask(SE_USB_I2C_INT
);
269 start_int_set_rising_edge(SE_USB_INT
);
270 start_int_ack(SE_USB_INT
);
271 start_int_umask(SE_USB_INT
);
273 start_int_set_rising_edge(SE_USB_NEED_CLK_INT
);
274 start_int_ack(SE_USB_NEED_CLK_INT
);
275 start_int_umask(SE_USB_NEED_CLK_INT
);
277 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT
);
278 start_int_ack(SE_USB_AHB_NEED_CLK_INT
);
279 start_int_umask(SE_USB_AHB_NEED_CLK_INT
);
283 static void nxp_unset_usb_bits(void)
285 if (machine_is_pnx4008()) {
286 start_int_mask(SE_USB_OTG_ATX_INT_N
);
287 start_int_mask(SE_USB_OTG_TIMER_INT
);
288 start_int_mask(SE_USB_I2C_INT
);
289 start_int_mask(SE_USB_INT
);
290 start_int_mask(SE_USB_NEED_CLK_INT
);
291 start_int_mask(SE_USB_AHB_NEED_CLK_INT
);
295 static int __devinit
usb_hcd_nxp_probe(struct platform_device
*pdev
)
297 struct usb_hcd
*hcd
= 0;
298 struct ohci_hcd
*ohci
;
299 const struct hc_driver
*driver
= &ohci_nxp_hc_driver
;
300 struct resource
*res
;
302 struct device_node
*isp1301_node
;
304 if (pdev
->dev
.of_node
) {
305 isp1301_node
= of_parse_phandle(pdev
->dev
.of_node
,
311 isp1301_i2c_client
= isp1301_get_client(isp1301_node
);
312 if (!isp1301_i2c_client
) {
317 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
318 pdev
->dev
.dma_mask
= &pdev
->dev
.coherent_dma_mask
;
320 dev_dbg(&pdev
->dev
, "%s: " DRIVER_DESC
" (nxp)\n", hcd_name
);
321 if (usb_disabled()) {
322 dev_err(&pdev
->dev
, "USB is disabled\n");
327 /* Enable AHB slave USB clock, needed for further USB clock control */
328 __raw_writel(USB_SLAVE_HCLK_EN
| PAD_CONTROL_LAST_DRIVEN
, USB_CTRL
);
333 usb_clk
= clk_get(&pdev
->dev
, "ck_pll5");
334 if (IS_ERR(usb_clk
)) {
335 dev_err(&pdev
->dev
, "failed to acquire USB PLL\n");
336 ret
= PTR_ERR(usb_clk
);
340 ret
= clk_enable(usb_clk
);
342 dev_err(&pdev
->dev
, "failed to start USB PLL\n");
346 ret
= clk_set_rate(usb_clk
, 48000);
348 dev_err(&pdev
->dev
, "failed to set USB clock rate\n");
352 __raw_writel(__raw_readl(USB_CTRL
) | USB_HOST_NEED_CLK_EN
, USB_CTRL
);
354 /* Set to enable all needed USB clocks */
355 __raw_writel(USB_CLOCK_MASK
, USB_OTG_CLK_CTRL
);
357 while ((__raw_readl(USB_OTG_CLK_STAT
) & USB_CLOCK_MASK
) !=
360 hcd
= usb_create_hcd(driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
362 dev_err(&pdev
->dev
, "Failed to allocate HC buffer\n");
367 /* Set all USB bits in the Start Enable register */
370 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
372 dev_err(&pdev
->dev
, "Failed to get MEM resource\n");
377 hcd
->regs
= devm_request_and_ioremap(&pdev
->dev
, res
);
379 dev_err(&pdev
->dev
, "Failed to devm_request_and_ioremap\n");
383 hcd
->rsrc_start
= res
->start
;
384 hcd
->rsrc_len
= resource_size(res
);
386 irq
= platform_get_irq(pdev
, 0);
393 platform_set_drvdata(pdev
, hcd
);
394 ohci
= hcd_to_ohci(hcd
);
397 dev_info(&pdev
->dev
, "at 0x%p, irq %d\n", hcd
->regs
, hcd
->irq
);
398 ret
= usb_add_hcd(hcd
, irq
, 0);
404 nxp_unset_usb_bits();
407 clk_disable(usb_clk
);
411 isp1301_i2c_client
= NULL
;
416 static int usb_hcd_nxp_remove(struct platform_device
*pdev
)
418 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
422 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
424 nxp_unset_usb_bits();
425 clk_disable(usb_clk
);
427 i2c_unregister_device(isp1301_i2c_client
);
428 isp1301_i2c_client
= NULL
;
430 platform_set_drvdata(pdev
, NULL
);
435 /* work with hotplug and coldplug */
436 MODULE_ALIAS("platform:usb-ohci");
439 static const struct of_device_id usb_hcd_nxp_match
[] = {
440 { .compatible
= "nxp,ohci-nxp" },
443 MODULE_DEVICE_TABLE(of
, usb_hcd_nxp_match
);
446 static struct platform_driver usb_hcd_nxp_driver
= {
449 .owner
= THIS_MODULE
,
450 .of_match_table
= of_match_ptr(usb_hcd_nxp_match
),
452 .probe
= usb_hcd_nxp_probe
,
453 .remove
= usb_hcd_nxp_remove
,