blob: e7cc7b6332145a180d6b0614c005d6303da0f316 [file] [log] [blame]
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001/*
Roland Stigge28643102012-03-12 22:54:50 +01002 * driver for NXP USB Host devices
Vitaly Wool60bbfc82006-06-29 18:28:18 +04003 *
Roland Stigge28643102012-03-12 22:54:50 +01004 * Currently supported OHCI host devices:
5 * - Philips PNX4008
Roland Stigge53dc25a2012-03-12 22:54:51 +01006 * - NXP LPC32xx
Vitaly Wool60bbfc82006-06-29 18:28:18 +04007 *
8 * Authors: Dmitry Chigirev <source@mvista.com>
David Brownelldd9048a2006-12-05 03:18:31 -08009 * Vitaly Wool <vitalywool@gmail.com>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040010 *
11 * register initialization is based on code examples provided by Philips
12 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
13 *
14 * NOTE: This driver does not have suspend/resume functionality
15 * This driver is intended for engineering development purposes only
16 *
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
20 * or implied.
21 */
22#include <linux/clk.h>
23#include <linux/platform_device.h>
24#include <linux/i2c.h>
25
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Roland Stigge53dc25a2012-03-12 22:54:51 +010027#include <asm/mach-types.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040028#include <asm/io.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/platform.h>
31#include <mach/irqs.h>
Russell Kingdb3f7282011-07-26 10:58:41 +010032#include <asm/gpio.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040033
Roland Stigge53dc25a2012-03-12 22:54:51 +010034#define USB_CONFIG_BASE 0x31020000
35#define PWRMAN_BASE 0x40004000
36
37#define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040038
39/* USB_CTRL bit defines */
40#define USB_SLAVE_HCLK_EN (1 << 24)
41#define USB_HOST_NEED_CLK_EN (1 << 21)
42
Roland Stigge53dc25a2012-03-12 22:54:51 +010043#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
44#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040045
46/* USB_OTG_CLK_CTRL bit defines */
47#define AHB_M_CLOCK_ON (1 << 4)
48#define OTG_CLOCK_ON (1 << 3)
49#define I2C_CLOCK_ON (1 << 2)
50#define DEV_CLOCK_ON (1 << 1)
51#define HOST_CLOCK_ON (1 << 0)
52
Roland Stigge53dc25a2012-03-12 22:54:51 +010053#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040054
55/* USB_OTG_STAT_CONTROL bit defines */
56#define TRANSPARENT_I2C_EN (1 << 7)
57#define HOST_EN (1 << 0)
58
59/* ISP1301 USB transceiver I2C registers */
60#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
61
62#define MC1_SPEED_REG (1 << 0)
63#define MC1_SUSPEND_REG (1 << 1)
64#define MC1_DAT_SE0 (1 << 2)
65#define MC1_TRANSPARENT (1 << 3)
66#define MC1_BDIS_ACON_EN (1 << 4)
67#define MC1_OE_INT_EN (1 << 5)
68#define MC1_UART_EN (1 << 6)
69#define MC1_MASK 0x7f
70
71#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
72
73#define MC2_GLOBAL_PWR_DN (1 << 0)
74#define MC2_SPD_SUSP_CTRL (1 << 1)
75#define MC2_BI_DI (1 << 2)
76#define MC2_TRANSP_BDIR0 (1 << 3)
77#define MC2_TRANSP_BDIR1 (1 << 4)
78#define MC2_AUDIO_EN (1 << 5)
79#define MC2_PSW_EN (1 << 6)
80#define MC2_EN2V7 (1 << 7)
81
82#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
83# define OTG1_DP_PULLUP (1 << 0)
84# define OTG1_DM_PULLUP (1 << 1)
85# define OTG1_DP_PULLDOWN (1 << 2)
86# define OTG1_DM_PULLDOWN (1 << 3)
87# define OTG1_ID_PULLDOWN (1 << 4)
88# define OTG1_VBUS_DRV (1 << 5)
89# define OTG1_VBUS_DISCHRG (1 << 6)
90# define OTG1_VBUS_CHRG (1 << 7)
91#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
92# define OTG_B_SESS_END (1 << 6)
93# define OTG_B_SESS_VLD (1 << 7)
94
95#define ISP1301_I2C_ADDR 0x2C
96
97#define ISP1301_I2C_MODE_CONTROL_1 0x4
98#define ISP1301_I2C_MODE_CONTROL_2 0x12
99#define ISP1301_I2C_OTG_CONTROL_1 0x6
100#define ISP1301_I2C_OTG_CONTROL_2 0x10
101#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
102#define ISP1301_I2C_INTERRUPT_LATCH 0xA
103#define ISP1301_I2C_INTERRUPT_FALLING 0xC
104#define ISP1301_I2C_INTERRUPT_RISING 0xE
105#define ISP1301_I2C_REG_CLEAR_ADDR 1
106
Roland Stigge53dc25a2012-03-12 22:54:51 +0100107/* On LPC32xx, those are undefined */
108#ifndef start_int_set_falling_edge
109#define start_int_set_falling_edge(irq)
110#define start_int_set_rising_edge(irq)
111#define start_int_ack(irq)
112#define start_int_mask(irq)
113#define start_int_umask(irq)
114#endif
115
Jean Delvare09ce4972009-10-01 19:03:13 +0200116static struct i2c_driver isp1301_driver;
117static struct i2c_client *isp1301_i2c_client;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400118
119extern int usb_disabled(void);
120extern int ocpi_enable(void);
121
122static struct clk *usb_clk;
123
Jean Delvare2cdddeb2008-01-27 18:14:47 +0100124static const unsigned short normal_i2c[] =
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400125 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400126
Jean Delvare3a407e72008-11-13 18:57:53 +0100127static int isp1301_probe(struct i2c_client *client,
128 const struct i2c_device_id *id)
129{
130 return 0;
131}
132
133static int isp1301_remove(struct i2c_client *client)
134{
135 return 0;
136}
137
Jean Delvare09ce4972009-10-01 19:03:13 +0200138static const struct i2c_device_id isp1301_id[] = {
Roland Stigge28643102012-03-12 22:54:50 +0100139 { "isp1301_nxp", 0 },
Jean Delvare3a407e72008-11-13 18:57:53 +0100140 { }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400141};
142
Jean Delvare09ce4972009-10-01 19:03:13 +0200143static struct i2c_driver isp1301_driver = {
Jean Delvare64b3d6d2008-06-18 14:46:27 +0200144 .driver = {
Roland Stigge28643102012-03-12 22:54:50 +0100145 .name = "isp1301_nxp",
Jean Delvare64b3d6d2008-06-18 14:46:27 +0200146 },
Jean Delvare3a407e72008-11-13 18:57:53 +0100147 .probe = isp1301_probe,
148 .remove = isp1301_remove,
149 .id_table = isp1301_id,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400150};
151
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400152static void i2c_write(u8 buf, u8 subaddr)
153{
154 char tmpbuf[2];
155
156 tmpbuf[0] = subaddr; /*register number */
157 tmpbuf[1] = buf; /*register data */
158 i2c_master_send(isp1301_i2c_client, &tmpbuf[0], 2);
159}
160
Roland Stigge53dc25a2012-03-12 22:54:51 +0100161static void isp1301_configure_pnx4008(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400162{
163 /* PNX4008 only supports DAT_SE0 USB mode */
164 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
165 /* Power up externel charge-pump */
166
167 i2c_write(MC1_DAT_SE0 | MC1_SPEED_REG, ISP1301_I2C_MODE_CONTROL_1);
168 i2c_write(~(MC1_DAT_SE0 | MC1_SPEED_REG),
169 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
170 i2c_write(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL,
171 ISP1301_I2C_MODE_CONTROL_2);
172 i2c_write(~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL),
173 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR);
174 i2c_write(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN,
175 ISP1301_I2C_OTG_CONTROL_1);
176 i2c_write(~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN),
177 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
178 i2c_write(0xFF,
179 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR);
180 i2c_write(0xFF,
181 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR);
182 i2c_write(0xFF,
183 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100184}
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400185
Roland Stigge53dc25a2012-03-12 22:54:51 +0100186static void isp1301_configure_lpc32xx(void)
187{
188 /* LPC32XX only supports DAT_SE0 USB mode */
189 /* This sequence is important */
190
191 /* Disable transparent UART mode first */
192 i2c_smbus_write_byte_data(isp1301_i2c_client,
193 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
194 MC1_UART_EN);
195 i2c_smbus_write_byte_data(isp1301_i2c_client,
196 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
197 ~MC1_SPEED_REG);
198 i2c_smbus_write_byte_data(isp1301_i2c_client,
199 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
200 i2c_smbus_write_byte_data(isp1301_i2c_client,
201 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
202 ~0);
203 i2c_smbus_write_byte_data(isp1301_i2c_client,
204 ISP1301_I2C_MODE_CONTROL_2,
205 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
206 i2c_smbus_write_byte_data(isp1301_i2c_client,
207 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
208 i2c_smbus_write_byte_data(isp1301_i2c_client,
209 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
210 i2c_smbus_write_byte_data(isp1301_i2c_client,
211 ISP1301_I2C_OTG_CONTROL_1,
212 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
213 i2c_smbus_write_byte_data(isp1301_i2c_client,
214 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
215 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
216 i2c_smbus_write_byte_data(isp1301_i2c_client,
217 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
218 i2c_smbus_write_byte_data(isp1301_i2c_client,
219 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
220 ~0);
221 i2c_smbus_write_byte_data(isp1301_i2c_client,
222 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
223
224 /* Enable usb_need_clk clock after transceiver is initialized */
225 __raw_writel((__raw_readl(USB_CTRL) | (1 << 22)), USB_CTRL);
226
227 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
228 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
229 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
230 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
231 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
232 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
233}
234
235static void isp1301_configure(void)
236{
237 if (machine_is_pnx4008())
238 isp1301_configure_pnx4008();
239 else
240 isp1301_configure_lpc32xx();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400241}
242
243static inline void isp1301_vbus_on(void)
244{
245 i2c_write(OTG1_VBUS_DRV, ISP1301_I2C_OTG_CONTROL_1);
246}
247
248static inline void isp1301_vbus_off(void)
249{
250 i2c_write(OTG1_VBUS_DRV,
251 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
252}
253
Roland Stigge28643102012-03-12 22:54:50 +0100254static void nxp_start_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400255{
256 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
257 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
258 isp1301_vbus_on();
259}
260
Roland Stigge28643102012-03-12 22:54:50 +0100261static void nxp_stop_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400262{
263 unsigned long tmp;
264 isp1301_vbus_off();
265 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
266 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
267}
268
Roland Stigge28643102012-03-12 22:54:50 +0100269static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400270{
271 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
272 int ret;
273
274 if ((ret = ohci_init(ohci)) < 0)
275 return ret;
276
277 if ((ret = ohci_run(ohci)) < 0) {
278 dev_err(hcd->self.controller, "can't start\n");
279 ohci_stop(hcd);
280 return ret;
281 }
282 return 0;
283}
284
Roland Stigge28643102012-03-12 22:54:50 +0100285static const struct hc_driver ohci_nxp_hc_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400286 .description = hcd_name,
Roland Stigge28643102012-03-12 22:54:50 +0100287 .product_desc = "nxp OHCI",
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400288
289 /*
290 * generic hardware linkage
291 */
292 .irq = ohci_irq,
293 .flags = HCD_USB11 | HCD_MEMORY,
294
295 .hcd_priv_size = sizeof(struct ohci_hcd),
296 /*
297 * basic lifecycle operations
298 */
Roland Stigge28643102012-03-12 22:54:50 +0100299 .start = ohci_nxp_start,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400300 .stop = ohci_stop,
David Brownell8442ae02006-10-02 07:20:10 -0700301 .shutdown = ohci_shutdown,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400302
303 /*
304 * managing i/o requests and associated device resources
305 */
306 .urb_enqueue = ohci_urb_enqueue,
307 .urb_dequeue = ohci_urb_dequeue,
308 .endpoint_disable = ohci_endpoint_disable,
309
310 /*
311 * scheduling support
312 */
313 .get_frame_number = ohci_get_frame,
314
315 /*
316 * root hub support
317 */
318 .hub_status_data = ohci_hub_status_data,
319 .hub_control = ohci_hub_control,
David Brownell8442ae02006-10-02 07:20:10 -0700320#ifdef CONFIG_PM
321 .bus_suspend = ohci_bus_suspend,
322 .bus_resume = ohci_bus_resume,
323#endif
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400324 .start_port_reset = ohci_start_port_reset,
325};
326
327#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
328
Roland Stigge28643102012-03-12 22:54:50 +0100329static void nxp_set_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400330{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100331 if (machine_is_pnx4008()) {
332 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
333 start_int_ack(SE_USB_OTG_ATX_INT_N);
334 start_int_umask(SE_USB_OTG_ATX_INT_N);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400335
Roland Stigge53dc25a2012-03-12 22:54:51 +0100336 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
337 start_int_ack(SE_USB_OTG_TIMER_INT);
338 start_int_umask(SE_USB_OTG_TIMER_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400339
Roland Stigge53dc25a2012-03-12 22:54:51 +0100340 start_int_set_rising_edge(SE_USB_I2C_INT);
341 start_int_ack(SE_USB_I2C_INT);
342 start_int_umask(SE_USB_I2C_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400343
Roland Stigge53dc25a2012-03-12 22:54:51 +0100344 start_int_set_rising_edge(SE_USB_INT);
345 start_int_ack(SE_USB_INT);
346 start_int_umask(SE_USB_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400347
Roland Stigge53dc25a2012-03-12 22:54:51 +0100348 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
349 start_int_ack(SE_USB_NEED_CLK_INT);
350 start_int_umask(SE_USB_NEED_CLK_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400351
Roland Stigge53dc25a2012-03-12 22:54:51 +0100352 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
353 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
354 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
355 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400356}
357
Roland Stigge28643102012-03-12 22:54:50 +0100358static void nxp_unset_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400359{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100360 if (machine_is_pnx4008()) {
361 start_int_mask(SE_USB_OTG_ATX_INT_N);
362 start_int_mask(SE_USB_OTG_TIMER_INT);
363 start_int_mask(SE_USB_I2C_INT);
364 start_int_mask(SE_USB_INT);
365 start_int_mask(SE_USB_NEED_CLK_INT);
366 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
367 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400368}
369
Roland Stigge28643102012-03-12 22:54:50 +0100370static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400371{
372 struct usb_hcd *hcd = 0;
373 struct ohci_hcd *ohci;
Roland Stigge28643102012-03-12 22:54:50 +0100374 const struct hc_driver *driver = &ohci_nxp_hc_driver;
Jean Delvare3a407e72008-11-13 18:57:53 +0100375 struct i2c_adapter *i2c_adap;
376 struct i2c_board_info i2c_info;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400377
378 int ret = 0, irq;
379
Roland Stigge28643102012-03-12 22:54:50 +0100380 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400381 if (usb_disabled()) {
382 err("USB is disabled");
383 ret = -ENODEV;
384 goto out;
385 }
386
387 if (pdev->num_resources != 2
388 || pdev->resource[0].flags != IORESOURCE_MEM
389 || pdev->resource[1].flags != IORESOURCE_IRQ) {
390 err("Invalid resource configuration");
391 ret = -ENODEV;
392 goto out;
393 }
394
395 /* Enable AHB slave USB clock, needed for further USB clock control */
396 __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL);
397
398 ret = i2c_add_driver(&isp1301_driver);
399 if (ret < 0) {
Jean Delvare3a407e72008-11-13 18:57:53 +0100400 err("failed to add ISP1301 driver");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400401 goto out;
402 }
Jean Delvare3a407e72008-11-13 18:57:53 +0100403 i2c_adap = i2c_get_adapter(2);
404 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
Roland Stigge28643102012-03-12 22:54:50 +0100405 strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE);
Jean Delvare3a407e72008-11-13 18:57:53 +0100406 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
Jean Delvare9a942412010-08-11 18:20:56 +0200407 normal_i2c, NULL);
Jean Delvare3a407e72008-11-13 18:57:53 +0100408 i2c_put_adapter(i2c_adap);
409 if (!isp1301_i2c_client) {
410 err("failed to connect I2C to ISP1301 USB Transceiver");
411 ret = -ENODEV;
412 goto out_i2c_driver;
413 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400414
415 isp1301_configure();
416
417 /* Enable USB PLL */
418 usb_clk = clk_get(&pdev->dev, "ck_pll5");
419 if (IS_ERR(usb_clk)) {
420 err("failed to acquire USB PLL");
421 ret = PTR_ERR(usb_clk);
422 goto out1;
423 }
424
425 ret = clk_enable(usb_clk);
426 if (ret < 0) {
427 err("failed to start USB PLL");
428 goto out2;
429 }
430
431 ret = clk_set_rate(usb_clk, 48000);
432 if (ret < 0) {
433 err("failed to set USB clock rate");
434 goto out3;
435 }
436
437 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
438
439 /* Set to enable all needed USB clocks */
440 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
441
442 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
443 USB_CLOCK_MASK) ;
444
Kay Sievers7071a3c2008-05-02 06:02:41 +0200445 hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev));
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400446 if (!hcd) {
447 err("Failed to allocate HC buffer");
448 ret = -ENOMEM;
449 goto out3;
450 }
451
452 /* Set all USB bits in the Start Enable register */
Roland Stigge28643102012-03-12 22:54:50 +0100453 nxp_set_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400454
455 hcd->rsrc_start = pdev->resource[0].start;
456 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
457 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
458 dev_dbg(&pdev->dev, "request_mem_region failed\n");
459 ret = -ENOMEM;
460 goto out4;
461 }
462 hcd->regs = (void __iomem *)pdev->resource[0].start;
463
464 irq = platform_get_irq(pdev, 0);
465 if (irq < 0) {
466 ret = -ENXIO;
467 goto out4;
468 }
469
Roland Stigge28643102012-03-12 22:54:50 +0100470 nxp_start_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400471 platform_set_drvdata(pdev, hcd);
472 ohci = hcd_to_ohci(hcd);
473 ohci_hcd_init(ohci);
474
475 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800476 ret = usb_add_hcd(hcd, irq, 0);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400477 if (ret == 0)
478 return ret;
479
Roland Stigge28643102012-03-12 22:54:50 +0100480 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400481out4:
Roland Stigge28643102012-03-12 22:54:50 +0100482 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400483 usb_put_hcd(hcd);
484out3:
485 clk_disable(usb_clk);
486out2:
487 clk_put(usb_clk);
488out1:
Luotao Fu8740cc72010-02-19 15:42:00 +0100489 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100490 isp1301_i2c_client = NULL;
491out_i2c_driver:
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400492 i2c_del_driver(&isp1301_driver);
493out:
494 return ret;
495}
496
Roland Stigge28643102012-03-12 22:54:50 +0100497static int usb_hcd_nxp_remove(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400498{
499 struct usb_hcd *hcd = platform_get_drvdata(pdev);
500
501 usb_remove_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100502 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400503 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
504 usb_put_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100505 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400506 clk_disable(usb_clk);
507 clk_put(usb_clk);
Luotao Fu8740cc72010-02-19 15:42:00 +0100508 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100509 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400510 i2c_del_driver(&isp1301_driver);
511
512 platform_set_drvdata(pdev, NULL);
513
514 return 0;
515}
516
Kay Sieversf4fce612008-04-10 21:29:22 -0700517/* work with hotplug and coldplug */
518MODULE_ALIAS("platform:usb-ohci");
519
Roland Stigge28643102012-03-12 22:54:50 +0100520static struct platform_driver usb_hcd_nxp_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400521 .driver = {
522 .name = "usb-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700523 .owner = THIS_MODULE,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400524 },
Roland Stigge28643102012-03-12 22:54:50 +0100525 .probe = usb_hcd_nxp_probe,
526 .remove = usb_hcd_nxp_remove,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400527};
528