blob: 63261f7c2f795da54963355cb3fd11f471faa4e3 [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>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040032
Roland Stigge53dc25a2012-03-12 22:54:51 +010033#define USB_CONFIG_BASE 0x31020000
34#define PWRMAN_BASE 0x40004000
35
36#define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040037
38/* USB_CTRL bit defines */
39#define USB_SLAVE_HCLK_EN (1 << 24)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020040#define USB_DEV_NEED_CLK_EN (1 << 22)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040041#define USB_HOST_NEED_CLK_EN (1 << 21)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020042#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040043
Roland Stigge53dc25a2012-03-12 22:54:51 +010044#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
45#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040046
47/* USB_OTG_CLK_CTRL bit defines */
48#define AHB_M_CLOCK_ON (1 << 4)
49#define OTG_CLOCK_ON (1 << 3)
50#define I2C_CLOCK_ON (1 << 2)
51#define DEV_CLOCK_ON (1 << 1)
52#define HOST_CLOCK_ON (1 << 0)
53
Roland Stigge53dc25a2012-03-12 22:54:51 +010054#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040055
56/* USB_OTG_STAT_CONTROL bit defines */
57#define TRANSPARENT_I2C_EN (1 << 7)
58#define HOST_EN (1 << 0)
59
60/* ISP1301 USB transceiver I2C registers */
61#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
62
63#define MC1_SPEED_REG (1 << 0)
64#define MC1_SUSPEND_REG (1 << 1)
65#define MC1_DAT_SE0 (1 << 2)
66#define MC1_TRANSPARENT (1 << 3)
67#define MC1_BDIS_ACON_EN (1 << 4)
68#define MC1_OE_INT_EN (1 << 5)
69#define MC1_UART_EN (1 << 6)
70#define MC1_MASK 0x7f
71
72#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
73
74#define MC2_GLOBAL_PWR_DN (1 << 0)
75#define MC2_SPD_SUSP_CTRL (1 << 1)
76#define MC2_BI_DI (1 << 2)
77#define MC2_TRANSP_BDIR0 (1 << 3)
78#define MC2_TRANSP_BDIR1 (1 << 4)
79#define MC2_AUDIO_EN (1 << 5)
80#define MC2_PSW_EN (1 << 6)
81#define MC2_EN2V7 (1 << 7)
82
83#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
84# define OTG1_DP_PULLUP (1 << 0)
85# define OTG1_DM_PULLUP (1 << 1)
86# define OTG1_DP_PULLDOWN (1 << 2)
87# define OTG1_DM_PULLDOWN (1 << 3)
88# define OTG1_ID_PULLDOWN (1 << 4)
89# define OTG1_VBUS_DRV (1 << 5)
90# define OTG1_VBUS_DISCHRG (1 << 6)
91# define OTG1_VBUS_CHRG (1 << 7)
92#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
93# define OTG_B_SESS_END (1 << 6)
94# define OTG_B_SESS_VLD (1 << 7)
95
96#define ISP1301_I2C_ADDR 0x2C
97
98#define ISP1301_I2C_MODE_CONTROL_1 0x4
99#define ISP1301_I2C_MODE_CONTROL_2 0x12
100#define ISP1301_I2C_OTG_CONTROL_1 0x6
101#define ISP1301_I2C_OTG_CONTROL_2 0x10
102#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
103#define ISP1301_I2C_INTERRUPT_LATCH 0xA
104#define ISP1301_I2C_INTERRUPT_FALLING 0xC
105#define ISP1301_I2C_INTERRUPT_RISING 0xE
106#define ISP1301_I2C_REG_CLEAR_ADDR 1
107
Roland Stigge53dc25a2012-03-12 22:54:51 +0100108/* On LPC32xx, those are undefined */
109#ifndef start_int_set_falling_edge
110#define start_int_set_falling_edge(irq)
111#define start_int_set_rising_edge(irq)
112#define start_int_ack(irq)
113#define start_int_mask(irq)
114#define start_int_umask(irq)
115#endif
116
Jean Delvare09ce4972009-10-01 19:03:13 +0200117static struct i2c_driver isp1301_driver;
118static struct i2c_client *isp1301_i2c_client;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400119
120extern int usb_disabled(void);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400121
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
Roland Stigge53dc25a2012-03-12 22:54:51 +0100152static void isp1301_configure_pnx4008(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400153{
154 /* PNX4008 only supports DAT_SE0 USB mode */
155 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
156 /* Power up externel charge-pump */
157
Roland Stiggea6a36002012-03-12 22:54:52 +0100158 i2c_smbus_write_byte_data(isp1301_i2c_client,
159 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG);
160 i2c_smbus_write_byte_data(isp1301_i2c_client,
161 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
162 ~(MC1_DAT_SE0 | MC1_SPEED_REG));
163 i2c_smbus_write_byte_data(isp1301_i2c_client,
164 ISP1301_I2C_MODE_CONTROL_2,
165 MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL);
166 i2c_smbus_write_byte_data(isp1301_i2c_client,
167 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR,
168 ~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
169 i2c_smbus_write_byte_data(isp1301_i2c_client,
170 ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
171 i2c_smbus_write_byte_data(isp1301_i2c_client,
172 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
173 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
174 i2c_smbus_write_byte_data(isp1301_i2c_client,
175 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF);
176 i2c_smbus_write_byte_data(isp1301_i2c_client,
177 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
178 0xFF);
179 i2c_smbus_write_byte_data(isp1301_i2c_client,
180 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
181 0xFF);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100182}
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400183
Roland Stigge53dc25a2012-03-12 22:54:51 +0100184static void isp1301_configure_lpc32xx(void)
185{
186 /* LPC32XX only supports DAT_SE0 USB mode */
187 /* This sequence is important */
188
189 /* Disable transparent UART mode first */
190 i2c_smbus_write_byte_data(isp1301_i2c_client,
191 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
192 MC1_UART_EN);
193 i2c_smbus_write_byte_data(isp1301_i2c_client,
194 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
195 ~MC1_SPEED_REG);
196 i2c_smbus_write_byte_data(isp1301_i2c_client,
197 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
198 i2c_smbus_write_byte_data(isp1301_i2c_client,
199 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
200 ~0);
201 i2c_smbus_write_byte_data(isp1301_i2c_client,
202 ISP1301_I2C_MODE_CONTROL_2,
203 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
204 i2c_smbus_write_byte_data(isp1301_i2c_client,
205 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
206 i2c_smbus_write_byte_data(isp1301_i2c_client,
207 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
208 i2c_smbus_write_byte_data(isp1301_i2c_client,
209 ISP1301_I2C_OTG_CONTROL_1,
210 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
211 i2c_smbus_write_byte_data(isp1301_i2c_client,
212 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
213 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
214 i2c_smbus_write_byte_data(isp1301_i2c_client,
215 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
216 i2c_smbus_write_byte_data(isp1301_i2c_client,
217 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
218 ~0);
219 i2c_smbus_write_byte_data(isp1301_i2c_client,
220 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
221
222 /* Enable usb_need_clk clock after transceiver is initialized */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200223 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100224
225 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
226 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
227 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
228 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
229 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
230 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
231}
232
233static void isp1301_configure(void)
234{
235 if (machine_is_pnx4008())
236 isp1301_configure_pnx4008();
237 else
238 isp1301_configure_lpc32xx();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400239}
240
241static inline void isp1301_vbus_on(void)
242{
Roland Stiggea6a36002012-03-12 22:54:52 +0100243 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
244 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400245}
246
247static inline void isp1301_vbus_off(void)
248{
Roland Stiggea6a36002012-03-12 22:54:52 +0100249 i2c_smbus_write_byte_data(isp1301_i2c_client,
250 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
251 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400252}
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;
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200377 struct resource *res;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400378
379 int ret = 0, irq;
380
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200381 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
382 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
383
Roland Stigge28643102012-03-12 22:54:50 +0100384 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400385 if (usb_disabled()) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700386 dev_err(&pdev->dev, "USB is disabled\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400387 ret = -ENODEV;
388 goto out;
389 }
390
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400391 /* Enable AHB slave USB clock, needed for further USB clock control */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200392 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400393
394 ret = i2c_add_driver(&isp1301_driver);
395 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700396 dev_err(&pdev->dev, "failed to add ISP1301 driver\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400397 goto out;
398 }
Jean Delvare3a407e72008-11-13 18:57:53 +0100399 i2c_adap = i2c_get_adapter(2);
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200400 if (!i2c_adap) {
401 dev_err(&pdev->dev, "failed on i2c_get_adapter");
402 goto out_i2c_driver;
403 }
404
Jean Delvare3a407e72008-11-13 18:57:53 +0100405 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
Roland Stigge28643102012-03-12 22:54:50 +0100406 strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE);
Jean Delvare3a407e72008-11-13 18:57:53 +0100407 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
Jean Delvare9a942412010-08-11 18:20:56 +0200408 normal_i2c, NULL);
Jean Delvare3a407e72008-11-13 18:57:53 +0100409 i2c_put_adapter(i2c_adap);
410 if (!isp1301_i2c_client) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700411 dev_err(&pdev->dev, "failed to connect I2C to ISP1301 USB Transceiver\n");
Jean Delvare3a407e72008-11-13 18:57:53 +0100412 ret = -ENODEV;
413 goto out_i2c_driver;
414 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400415
416 isp1301_configure();
417
418 /* Enable USB PLL */
419 usb_clk = clk_get(&pdev->dev, "ck_pll5");
420 if (IS_ERR(usb_clk)) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700421 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400422 ret = PTR_ERR(usb_clk);
423 goto out1;
424 }
425
426 ret = clk_enable(usb_clk);
427 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700428 dev_err(&pdev->dev, "failed to start USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400429 goto out2;
430 }
431
432 ret = clk_set_rate(usb_clk, 48000);
433 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700434 dev_err(&pdev->dev, "failed to set USB clock rate\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400435 goto out3;
436 }
437
438 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
439
440 /* Set to enable all needed USB clocks */
441 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
442
443 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
444 USB_CLOCK_MASK) ;
445
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200446 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400447 if (!hcd) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700448 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400449 ret = -ENOMEM;
450 goto out3;
451 }
452
453 /* Set all USB bits in the Start Enable register */
Roland Stigge28643102012-03-12 22:54:50 +0100454 nxp_set_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400455
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200456 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
457 if (!res) {
458 dev_err(&pdev->dev, "Failed to get MEM resource\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400459 ret = -ENOMEM;
460 goto out4;
461 }
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200462
463 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
464 if (!hcd->regs) {
465 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
466 ret = -ENOMEM;
467 goto out4;
468 }
469 hcd->rsrc_start = res->start;
470 hcd->rsrc_len = resource_size(res);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400471
472 irq = platform_get_irq(pdev, 0);
473 if (irq < 0) {
474 ret = -ENXIO;
475 goto out4;
476 }
477
Roland Stigge28643102012-03-12 22:54:50 +0100478 nxp_start_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400479 platform_set_drvdata(pdev, hcd);
480 ohci = hcd_to_ohci(hcd);
481 ohci_hcd_init(ohci);
482
483 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800484 ret = usb_add_hcd(hcd, irq, 0);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400485 if (ret == 0)
486 return ret;
487
Roland Stigge28643102012-03-12 22:54:50 +0100488 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400489out4:
Roland Stigge28643102012-03-12 22:54:50 +0100490 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400491 usb_put_hcd(hcd);
492out3:
493 clk_disable(usb_clk);
494out2:
495 clk_put(usb_clk);
496out1:
Luotao Fu8740cc72010-02-19 15:42:00 +0100497 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100498 isp1301_i2c_client = NULL;
499out_i2c_driver:
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400500 i2c_del_driver(&isp1301_driver);
501out:
502 return ret;
503}
504
Roland Stigge28643102012-03-12 22:54:50 +0100505static int usb_hcd_nxp_remove(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400506{
507 struct usb_hcd *hcd = platform_get_drvdata(pdev);
508
509 usb_remove_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100510 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400511 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
512 usb_put_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100513 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400514 clk_disable(usb_clk);
515 clk_put(usb_clk);
Luotao Fu8740cc72010-02-19 15:42:00 +0100516 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100517 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400518 i2c_del_driver(&isp1301_driver);
519
520 platform_set_drvdata(pdev, NULL);
521
522 return 0;
523}
524
Kay Sieversf4fce612008-04-10 21:29:22 -0700525/* work with hotplug and coldplug */
526MODULE_ALIAS("platform:usb-ohci");
527
Roland Stigge28643102012-03-12 22:54:50 +0100528static struct platform_driver usb_hcd_nxp_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400529 .driver = {
530 .name = "usb-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700531 .owner = THIS_MODULE,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400532 },
Roland Stigge28643102012-03-12 22:54:50 +0100533 .probe = usb_hcd_nxp_probe,
534 .remove = usb_hcd_nxp_remove,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400535};
536