blob: bf542e7e2b1c8f3e03650350d6edc0b9d1998776 [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>
Roland Stigge2265efe2012-04-29 16:47:03 +020025#include <linux/of.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040026
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/hardware.h>
Roland Stigge53dc25a2012-03-12 22:54:51 +010028#include <asm/mach-types.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040029#include <asm/io.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040030
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/platform.h>
32#include <mach/irqs.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)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020041#define USB_DEV_NEED_CLK_EN (1 << 22)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040042#define USB_HOST_NEED_CLK_EN (1 << 21)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020043#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040044
Roland Stigge53dc25a2012-03-12 22:54:51 +010045#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
46#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040047
48/* USB_OTG_CLK_CTRL bit defines */
49#define AHB_M_CLOCK_ON (1 << 4)
50#define OTG_CLOCK_ON (1 << 3)
51#define I2C_CLOCK_ON (1 << 2)
52#define DEV_CLOCK_ON (1 << 1)
53#define HOST_CLOCK_ON (1 << 0)
54
Roland Stigge53dc25a2012-03-12 22:54:51 +010055#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040056
57/* USB_OTG_STAT_CONTROL bit defines */
58#define TRANSPARENT_I2C_EN (1 << 7)
59#define HOST_EN (1 << 0)
60
61/* ISP1301 USB transceiver I2C registers */
62#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
63
64#define MC1_SPEED_REG (1 << 0)
65#define MC1_SUSPEND_REG (1 << 1)
66#define MC1_DAT_SE0 (1 << 2)
67#define MC1_TRANSPARENT (1 << 3)
68#define MC1_BDIS_ACON_EN (1 << 4)
69#define MC1_OE_INT_EN (1 << 5)
70#define MC1_UART_EN (1 << 6)
71#define MC1_MASK 0x7f
72
73#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
74
75#define MC2_GLOBAL_PWR_DN (1 << 0)
76#define MC2_SPD_SUSP_CTRL (1 << 1)
77#define MC2_BI_DI (1 << 2)
78#define MC2_TRANSP_BDIR0 (1 << 3)
79#define MC2_TRANSP_BDIR1 (1 << 4)
80#define MC2_AUDIO_EN (1 << 5)
81#define MC2_PSW_EN (1 << 6)
82#define MC2_EN2V7 (1 << 7)
83
84#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
85# define OTG1_DP_PULLUP (1 << 0)
86# define OTG1_DM_PULLUP (1 << 1)
87# define OTG1_DP_PULLDOWN (1 << 2)
88# define OTG1_DM_PULLDOWN (1 << 3)
89# define OTG1_ID_PULLDOWN (1 << 4)
90# define OTG1_VBUS_DRV (1 << 5)
91# define OTG1_VBUS_DISCHRG (1 << 6)
92# define OTG1_VBUS_CHRG (1 << 7)
93#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
94# define OTG_B_SESS_END (1 << 6)
95# define OTG_B_SESS_VLD (1 << 7)
96
97#define ISP1301_I2C_ADDR 0x2C
98
99#define ISP1301_I2C_MODE_CONTROL_1 0x4
100#define ISP1301_I2C_MODE_CONTROL_2 0x12
101#define ISP1301_I2C_OTG_CONTROL_1 0x6
102#define ISP1301_I2C_OTG_CONTROL_2 0x10
103#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
104#define ISP1301_I2C_INTERRUPT_LATCH 0xA
105#define ISP1301_I2C_INTERRUPT_FALLING 0xC
106#define ISP1301_I2C_INTERRUPT_RISING 0xE
107#define ISP1301_I2C_REG_CLEAR_ADDR 1
108
Roland Stigge53dc25a2012-03-12 22:54:51 +0100109/* On LPC32xx, those are undefined */
110#ifndef start_int_set_falling_edge
111#define start_int_set_falling_edge(irq)
112#define start_int_set_rising_edge(irq)
113#define start_int_ack(irq)
114#define start_int_mask(irq)
115#define start_int_umask(irq)
116#endif
117
Jean Delvare09ce4972009-10-01 19:03:13 +0200118static struct i2c_driver isp1301_driver;
119static struct i2c_client *isp1301_i2c_client;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400120
121extern int usb_disabled(void);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400122
123static struct clk *usb_clk;
124
Jean Delvare2cdddeb2008-01-27 18:14:47 +0100125static const unsigned short normal_i2c[] =
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400126 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400127
Jean Delvare3a407e72008-11-13 18:57:53 +0100128static int isp1301_probe(struct i2c_client *client,
129 const struct i2c_device_id *id)
130{
131 return 0;
132}
133
134static int isp1301_remove(struct i2c_client *client)
135{
136 return 0;
137}
138
Jean Delvare09ce4972009-10-01 19:03:13 +0200139static const struct i2c_device_id isp1301_id[] = {
Roland Stigge28643102012-03-12 22:54:50 +0100140 { "isp1301_nxp", 0 },
Jean Delvare3a407e72008-11-13 18:57:53 +0100141 { }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400142};
143
Jean Delvare09ce4972009-10-01 19:03:13 +0200144static struct i2c_driver isp1301_driver = {
Jean Delvare64b3d6d2008-06-18 14:46:27 +0200145 .driver = {
Roland Stigge28643102012-03-12 22:54:50 +0100146 .name = "isp1301_nxp",
Jean Delvare64b3d6d2008-06-18 14:46:27 +0200147 },
Jean Delvare3a407e72008-11-13 18:57:53 +0100148 .probe = isp1301_probe,
149 .remove = isp1301_remove,
150 .id_table = isp1301_id,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400151};
152
Roland Stigge53dc25a2012-03-12 22:54:51 +0100153static void isp1301_configure_pnx4008(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400154{
155 /* PNX4008 only supports DAT_SE0 USB mode */
156 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
157 /* Power up externel charge-pump */
158
Roland Stiggea6a36002012-03-12 22:54:52 +0100159 i2c_smbus_write_byte_data(isp1301_i2c_client,
160 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG);
161 i2c_smbus_write_byte_data(isp1301_i2c_client,
162 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
163 ~(MC1_DAT_SE0 | MC1_SPEED_REG));
164 i2c_smbus_write_byte_data(isp1301_i2c_client,
165 ISP1301_I2C_MODE_CONTROL_2,
166 MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL);
167 i2c_smbus_write_byte_data(isp1301_i2c_client,
168 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR,
169 ~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
170 i2c_smbus_write_byte_data(isp1301_i2c_client,
171 ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
172 i2c_smbus_write_byte_data(isp1301_i2c_client,
173 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
174 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
175 i2c_smbus_write_byte_data(isp1301_i2c_client,
176 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF);
177 i2c_smbus_write_byte_data(isp1301_i2c_client,
178 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
179 0xFF);
180 i2c_smbus_write_byte_data(isp1301_i2c_client,
181 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
182 0xFF);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100183}
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400184
Roland Stigge53dc25a2012-03-12 22:54:51 +0100185static void isp1301_configure_lpc32xx(void)
186{
187 /* LPC32XX only supports DAT_SE0 USB mode */
188 /* This sequence is important */
189
190 /* Disable transparent UART mode first */
191 i2c_smbus_write_byte_data(isp1301_i2c_client,
192 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
193 MC1_UART_EN);
194 i2c_smbus_write_byte_data(isp1301_i2c_client,
195 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
196 ~MC1_SPEED_REG);
197 i2c_smbus_write_byte_data(isp1301_i2c_client,
198 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
199 i2c_smbus_write_byte_data(isp1301_i2c_client,
200 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
201 ~0);
202 i2c_smbus_write_byte_data(isp1301_i2c_client,
203 ISP1301_I2C_MODE_CONTROL_2,
204 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
205 i2c_smbus_write_byte_data(isp1301_i2c_client,
206 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
207 i2c_smbus_write_byte_data(isp1301_i2c_client,
208 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
209 i2c_smbus_write_byte_data(isp1301_i2c_client,
210 ISP1301_I2C_OTG_CONTROL_1,
211 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
212 i2c_smbus_write_byte_data(isp1301_i2c_client,
213 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
214 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
215 i2c_smbus_write_byte_data(isp1301_i2c_client,
216 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
217 i2c_smbus_write_byte_data(isp1301_i2c_client,
218 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
219 ~0);
220 i2c_smbus_write_byte_data(isp1301_i2c_client,
221 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
222
223 /* Enable usb_need_clk clock after transceiver is initialized */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200224 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100225
226 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
227 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
228 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
229 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
230 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
231 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
232}
233
234static void isp1301_configure(void)
235{
236 if (machine_is_pnx4008())
237 isp1301_configure_pnx4008();
238 else
239 isp1301_configure_lpc32xx();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400240}
241
242static inline void isp1301_vbus_on(void)
243{
Roland Stiggea6a36002012-03-12 22:54:52 +0100244 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
245 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400246}
247
248static inline void isp1301_vbus_off(void)
249{
Roland Stiggea6a36002012-03-12 22:54:52 +0100250 i2c_smbus_write_byte_data(isp1301_i2c_client,
251 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
252 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400253}
254
Roland Stigge28643102012-03-12 22:54:50 +0100255static void nxp_start_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400256{
257 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
258 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
259 isp1301_vbus_on();
260}
261
Roland Stigge28643102012-03-12 22:54:50 +0100262static void nxp_stop_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400263{
264 unsigned long tmp;
265 isp1301_vbus_off();
266 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
267 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
268}
269
Roland Stigge28643102012-03-12 22:54:50 +0100270static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400271{
272 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
273 int ret;
274
275 if ((ret = ohci_init(ohci)) < 0)
276 return ret;
277
278 if ((ret = ohci_run(ohci)) < 0) {
279 dev_err(hcd->self.controller, "can't start\n");
280 ohci_stop(hcd);
281 return ret;
282 }
283 return 0;
284}
285
Roland Stigge28643102012-03-12 22:54:50 +0100286static const struct hc_driver ohci_nxp_hc_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400287 .description = hcd_name,
Roland Stigge28643102012-03-12 22:54:50 +0100288 .product_desc = "nxp OHCI",
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400289
290 /*
291 * generic hardware linkage
292 */
293 .irq = ohci_irq,
294 .flags = HCD_USB11 | HCD_MEMORY,
295
296 .hcd_priv_size = sizeof(struct ohci_hcd),
297 /*
298 * basic lifecycle operations
299 */
Roland Stigge28643102012-03-12 22:54:50 +0100300 .start = ohci_nxp_start,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400301 .stop = ohci_stop,
David Brownell8442ae02006-10-02 07:20:10 -0700302 .shutdown = ohci_shutdown,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400303
304 /*
305 * managing i/o requests and associated device resources
306 */
307 .urb_enqueue = ohci_urb_enqueue,
308 .urb_dequeue = ohci_urb_dequeue,
309 .endpoint_disable = ohci_endpoint_disable,
310
311 /*
312 * scheduling support
313 */
314 .get_frame_number = ohci_get_frame,
315
316 /*
317 * root hub support
318 */
319 .hub_status_data = ohci_hub_status_data,
320 .hub_control = ohci_hub_control,
David Brownell8442ae02006-10-02 07:20:10 -0700321#ifdef CONFIG_PM
322 .bus_suspend = ohci_bus_suspend,
323 .bus_resume = ohci_bus_resume,
324#endif
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400325 .start_port_reset = ohci_start_port_reset,
326};
327
328#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
329
Roland Stigge28643102012-03-12 22:54:50 +0100330static void nxp_set_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400331{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100332 if (machine_is_pnx4008()) {
333 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
334 start_int_ack(SE_USB_OTG_ATX_INT_N);
335 start_int_umask(SE_USB_OTG_ATX_INT_N);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400336
Roland Stigge53dc25a2012-03-12 22:54:51 +0100337 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
338 start_int_ack(SE_USB_OTG_TIMER_INT);
339 start_int_umask(SE_USB_OTG_TIMER_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400340
Roland Stigge53dc25a2012-03-12 22:54:51 +0100341 start_int_set_rising_edge(SE_USB_I2C_INT);
342 start_int_ack(SE_USB_I2C_INT);
343 start_int_umask(SE_USB_I2C_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400344
Roland Stigge53dc25a2012-03-12 22:54:51 +0100345 start_int_set_rising_edge(SE_USB_INT);
346 start_int_ack(SE_USB_INT);
347 start_int_umask(SE_USB_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400348
Roland Stigge53dc25a2012-03-12 22:54:51 +0100349 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
350 start_int_ack(SE_USB_NEED_CLK_INT);
351 start_int_umask(SE_USB_NEED_CLK_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400352
Roland Stigge53dc25a2012-03-12 22:54:51 +0100353 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
354 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
355 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
356 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400357}
358
Roland Stigge28643102012-03-12 22:54:50 +0100359static void nxp_unset_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400360{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100361 if (machine_is_pnx4008()) {
362 start_int_mask(SE_USB_OTG_ATX_INT_N);
363 start_int_mask(SE_USB_OTG_TIMER_INT);
364 start_int_mask(SE_USB_I2C_INT);
365 start_int_mask(SE_USB_INT);
366 start_int_mask(SE_USB_NEED_CLK_INT);
367 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
368 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400369}
370
Roland Stigge28643102012-03-12 22:54:50 +0100371static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400372{
373 struct usb_hcd *hcd = 0;
374 struct ohci_hcd *ohci;
Roland Stigge28643102012-03-12 22:54:50 +0100375 const struct hc_driver *driver = &ohci_nxp_hc_driver;
Jean Delvare3a407e72008-11-13 18:57:53 +0100376 struct i2c_adapter *i2c_adap;
377 struct i2c_board_info i2c_info;
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200378 struct resource *res;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400379
380 int ret = 0, irq;
381
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200382 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
383 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
384
Roland Stigge28643102012-03-12 22:54:50 +0100385 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400386 if (usb_disabled()) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700387 dev_err(&pdev->dev, "USB is disabled\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400388 ret = -ENODEV;
389 goto out;
390 }
391
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400392 /* Enable AHB slave USB clock, needed for further USB clock control */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200393 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400394
395 ret = i2c_add_driver(&isp1301_driver);
396 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700397 dev_err(&pdev->dev, "failed to add ISP1301 driver\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400398 goto out;
399 }
Jean Delvare3a407e72008-11-13 18:57:53 +0100400 i2c_adap = i2c_get_adapter(2);
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200401 if (!i2c_adap) {
402 dev_err(&pdev->dev, "failed on i2c_get_adapter");
403 goto out_i2c_driver;
404 }
405
Jean Delvare3a407e72008-11-13 18:57:53 +0100406 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
Roland Stigge28643102012-03-12 22:54:50 +0100407 strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE);
Jean Delvare3a407e72008-11-13 18:57:53 +0100408 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
Jean Delvare9a942412010-08-11 18:20:56 +0200409 normal_i2c, NULL);
Jean Delvare3a407e72008-11-13 18:57:53 +0100410 i2c_put_adapter(i2c_adap);
411 if (!isp1301_i2c_client) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700412 dev_err(&pdev->dev, "failed to connect I2C to ISP1301 USB Transceiver\n");
Jean Delvare3a407e72008-11-13 18:57:53 +0100413 ret = -ENODEV;
414 goto out_i2c_driver;
415 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400416
417 isp1301_configure();
418
419 /* Enable USB PLL */
420 usb_clk = clk_get(&pdev->dev, "ck_pll5");
421 if (IS_ERR(usb_clk)) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700422 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400423 ret = PTR_ERR(usb_clk);
424 goto out1;
425 }
426
427 ret = clk_enable(usb_clk);
428 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700429 dev_err(&pdev->dev, "failed to start USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400430 goto out2;
431 }
432
433 ret = clk_set_rate(usb_clk, 48000);
434 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700435 dev_err(&pdev->dev, "failed to set USB clock rate\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400436 goto out3;
437 }
438
439 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
440
441 /* Set to enable all needed USB clocks */
442 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
443
444 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
445 USB_CLOCK_MASK) ;
446
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200447 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400448 if (!hcd) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700449 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400450 ret = -ENOMEM;
451 goto out3;
452 }
453
454 /* Set all USB bits in the Start Enable register */
Roland Stigge28643102012-03-12 22:54:50 +0100455 nxp_set_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400456
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200457 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
458 if (!res) {
459 dev_err(&pdev->dev, "Failed to get MEM resource\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400460 ret = -ENOMEM;
461 goto out4;
462 }
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200463
464 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
465 if (!hcd->regs) {
466 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
467 ret = -ENOMEM;
468 goto out4;
469 }
470 hcd->rsrc_start = res->start;
471 hcd->rsrc_len = resource_size(res);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400472
473 irq = platform_get_irq(pdev, 0);
474 if (irq < 0) {
475 ret = -ENXIO;
476 goto out4;
477 }
478
Roland Stigge28643102012-03-12 22:54:50 +0100479 nxp_start_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400480 platform_set_drvdata(pdev, hcd);
481 ohci = hcd_to_ohci(hcd);
482 ohci_hcd_init(ohci);
483
484 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800485 ret = usb_add_hcd(hcd, irq, 0);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400486 if (ret == 0)
487 return ret;
488
Roland Stigge28643102012-03-12 22:54:50 +0100489 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400490out4:
Roland Stigge28643102012-03-12 22:54:50 +0100491 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400492 usb_put_hcd(hcd);
493out3:
494 clk_disable(usb_clk);
495out2:
496 clk_put(usb_clk);
497out1:
Luotao Fu8740cc72010-02-19 15:42:00 +0100498 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100499 isp1301_i2c_client = NULL;
500out_i2c_driver:
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400501 i2c_del_driver(&isp1301_driver);
502out:
503 return ret;
504}
505
Roland Stigge28643102012-03-12 22:54:50 +0100506static int usb_hcd_nxp_remove(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400507{
508 struct usb_hcd *hcd = platform_get_drvdata(pdev);
509
510 usb_remove_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100511 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400512 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
513 usb_put_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100514 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400515 clk_disable(usb_clk);
516 clk_put(usb_clk);
Luotao Fu8740cc72010-02-19 15:42:00 +0100517 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100518 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400519 i2c_del_driver(&isp1301_driver);
520
521 platform_set_drvdata(pdev, NULL);
522
523 return 0;
524}
525
Kay Sieversf4fce612008-04-10 21:29:22 -0700526/* work with hotplug and coldplug */
527MODULE_ALIAS("platform:usb-ohci");
528
Roland Stigge2265efe2012-04-29 16:47:03 +0200529#ifdef CONFIG_OF
530static const struct of_device_id usb_hcd_nxp_match[] = {
531 { .compatible = "nxp,ohci-nxp" },
532 {},
533};
534MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
535#endif
536
Roland Stigge28643102012-03-12 22:54:50 +0100537static struct platform_driver usb_hcd_nxp_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400538 .driver = {
539 .name = "usb-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700540 .owner = THIS_MODULE,
Roland Stigge2265efe2012-04-29 16:47:03 +0200541 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400542 },
Roland Stigge28643102012-03-12 22:54:50 +0100543 .probe = usb_hcd_nxp_probe,
544 .remove = usb_hcd_nxp_remove,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400545};
546