blob: 1e364ec962fb90ea75573c92fc6a92ec6b25612c [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>
Roland Stigge73108aa2012-04-29 16:47:06 +020026#include <linux/usb/isp1301.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040027
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Roland Stigge53dc25a2012-03-12 22:54:51 +010029#include <asm/mach-types.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040030#include <asm/io.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040031
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/platform.h>
33#include <mach/irqs.h>
Vitaly Wool60bbfc82006-06-29 18:28:18 +040034
Roland Stigge53dc25a2012-03-12 22:54:51 +010035#define USB_CONFIG_BASE 0x31020000
36#define PWRMAN_BASE 0x40004000
37
38#define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040039
40/* USB_CTRL bit defines */
41#define USB_SLAVE_HCLK_EN (1 << 24)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020042#define USB_DEV_NEED_CLK_EN (1 << 22)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040043#define USB_HOST_NEED_CLK_EN (1 << 21)
Roland Stiggea6a99cf2012-04-29 16:47:02 +020044#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040045
Roland Stigge53dc25a2012-03-12 22:54:51 +010046#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
47#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040048
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)
55
Roland Stigge53dc25a2012-03-12 22:54:51 +010056#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040057
58/* USB_OTG_STAT_CONTROL bit defines */
59#define TRANSPARENT_I2C_EN (1 << 7)
60#define HOST_EN (1 << 0)
61
Roland Stigge53dc25a2012-03-12 22:54:51 +010062/* 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)
69#endif
70
Jean Delvare09ce4972009-10-01 19:03:13 +020071static struct i2c_client *isp1301_i2c_client;
Vitaly Wool60bbfc82006-06-29 18:28:18 +040072
73extern int usb_disabled(void);
Vitaly Wool60bbfc82006-06-29 18:28:18 +040074
75static struct clk *usb_clk;
76
Roland Stigge53dc25a2012-03-12 22:54:51 +010077static void isp1301_configure_pnx4008(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040078{
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 */
82
Roland Stiggea6a36002012-03-12 22:54:52 +010083 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,
103 0xFF);
104 i2c_smbus_write_byte_data(isp1301_i2c_client,
105 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
106 0xFF);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100107}
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400108
Roland Stigge53dc25a2012-03-12 22:54:51 +0100109static void isp1301_configure_lpc32xx(void)
110{
111 /* LPC32XX only supports DAT_SE0 USB mode */
112 /* This sequence is important */
113
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),
117 MC1_UART_EN);
118 i2c_smbus_write_byte_data(isp1301_i2c_client,
119 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
120 ~MC1_SPEED_REG);
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),
125 ~0);
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,
143 ~0);
144 i2c_smbus_write_byte_data(isp1301_i2c_client,
145 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
146
147 /* Enable usb_need_clk clock after transceiver is initialized */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200148 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100149
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));
156}
157
158static void isp1301_configure(void)
159{
160 if (machine_is_pnx4008())
161 isp1301_configure_pnx4008();
162 else
163 isp1301_configure_lpc32xx();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400164}
165
166static inline void isp1301_vbus_on(void)
167{
Roland Stiggea6a36002012-03-12 22:54:52 +0100168 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
169 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400170}
171
172static inline void isp1301_vbus_off(void)
173{
Roland Stiggea6a36002012-03-12 22:54:52 +0100174 i2c_smbus_write_byte_data(isp1301_i2c_client,
175 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
176 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400177}
178
Roland Stigge28643102012-03-12 22:54:50 +0100179static void nxp_start_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400180{
181 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
182 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
183 isp1301_vbus_on();
184}
185
Roland Stigge28643102012-03-12 22:54:50 +0100186static void nxp_stop_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400187{
188 unsigned long tmp;
189 isp1301_vbus_off();
190 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
191 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
192}
193
Roland Stigge28643102012-03-12 22:54:50 +0100194static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400195{
196 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
197 int ret;
198
199 if ((ret = ohci_init(ohci)) < 0)
200 return ret;
201
202 if ((ret = ohci_run(ohci)) < 0) {
203 dev_err(hcd->self.controller, "can't start\n");
204 ohci_stop(hcd);
205 return ret;
206 }
207 return 0;
208}
209
Roland Stigge28643102012-03-12 22:54:50 +0100210static const struct hc_driver ohci_nxp_hc_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400211 .description = hcd_name,
Roland Stigge28643102012-03-12 22:54:50 +0100212 .product_desc = "nxp OHCI",
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400213
214 /*
215 * generic hardware linkage
216 */
217 .irq = ohci_irq,
218 .flags = HCD_USB11 | HCD_MEMORY,
219
220 .hcd_priv_size = sizeof(struct ohci_hcd),
221 /*
222 * basic lifecycle operations
223 */
Roland Stigge28643102012-03-12 22:54:50 +0100224 .start = ohci_nxp_start,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400225 .stop = ohci_stop,
David Brownell8442ae02006-10-02 07:20:10 -0700226 .shutdown = ohci_shutdown,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400227
228 /*
229 * managing i/o requests and associated device resources
230 */
231 .urb_enqueue = ohci_urb_enqueue,
232 .urb_dequeue = ohci_urb_dequeue,
233 .endpoint_disable = ohci_endpoint_disable,
234
235 /*
236 * scheduling support
237 */
238 .get_frame_number = ohci_get_frame,
239
240 /*
241 * root hub support
242 */
243 .hub_status_data = ohci_hub_status_data,
244 .hub_control = ohci_hub_control,
David Brownell8442ae02006-10-02 07:20:10 -0700245#ifdef CONFIG_PM
246 .bus_suspend = ohci_bus_suspend,
247 .bus_resume = ohci_bus_resume,
248#endif
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400249 .start_port_reset = ohci_start_port_reset,
250};
251
252#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
253
Roland Stigge28643102012-03-12 22:54:50 +0100254static void nxp_set_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400255{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100256 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);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400260
Roland Stigge53dc25a2012-03-12 22:54:51 +0100261 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);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400264
Roland Stigge53dc25a2012-03-12 22:54:51 +0100265 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);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400268
Roland Stigge53dc25a2012-03-12 22:54:51 +0100269 start_int_set_rising_edge(SE_USB_INT);
270 start_int_ack(SE_USB_INT);
271 start_int_umask(SE_USB_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400272
Roland Stigge53dc25a2012-03-12 22:54:51 +0100273 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);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400276
Roland Stigge53dc25a2012-03-12 22:54:51 +0100277 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);
280 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400281}
282
Roland Stigge28643102012-03-12 22:54:50 +0100283static void nxp_unset_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400284{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100285 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);
292 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400293}
294
Roland Stigge28643102012-03-12 22:54:50 +0100295static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400296{
297 struct usb_hcd *hcd = 0;
298 struct ohci_hcd *ohci;
Roland Stigge28643102012-03-12 22:54:50 +0100299 const struct hc_driver *driver = &ohci_nxp_hc_driver;
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200300 struct resource *res;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400301 int ret = 0, irq;
Roland Stigge73108aa2012-04-29 16:47:06 +0200302 struct device_node *isp1301_node;
303
304 if (pdev->dev.of_node) {
305 isp1301_node = of_parse_phandle(pdev->dev.of_node,
306 "transceiver", 0);
307 } else {
308 isp1301_node = NULL;
309 }
310
311 isp1301_i2c_client = isp1301_get_client(isp1301_node);
312 if (!isp1301_i2c_client) {
313 ret = -EPROBE_DEFER;
314 goto out;
315 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400316
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200317 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
318 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
319
Roland Stigge28643102012-03-12 22:54:50 +0100320 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400321 if (usb_disabled()) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700322 dev_err(&pdev->dev, "USB is disabled\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400323 ret = -ENODEV;
324 goto out;
325 }
326
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400327 /* Enable AHB slave USB clock, needed for further USB clock control */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200328 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400329
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400330 isp1301_configure();
331
332 /* Enable USB PLL */
333 usb_clk = clk_get(&pdev->dev, "ck_pll5");
334 if (IS_ERR(usb_clk)) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700335 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400336 ret = PTR_ERR(usb_clk);
337 goto out1;
338 }
339
340 ret = clk_enable(usb_clk);
341 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700342 dev_err(&pdev->dev, "failed to start USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400343 goto out2;
344 }
345
346 ret = clk_set_rate(usb_clk, 48000);
347 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700348 dev_err(&pdev->dev, "failed to set USB clock rate\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400349 goto out3;
350 }
351
352 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
353
354 /* Set to enable all needed USB clocks */
355 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
356
357 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
358 USB_CLOCK_MASK) ;
359
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200360 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400361 if (!hcd) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700362 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400363 ret = -ENOMEM;
364 goto out3;
365 }
366
367 /* Set all USB bits in the Start Enable register */
Roland Stigge28643102012-03-12 22:54:50 +0100368 nxp_set_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400369
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200370 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
371 if (!res) {
372 dev_err(&pdev->dev, "Failed to get MEM resource\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400373 ret = -ENOMEM;
374 goto out4;
375 }
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200376
377 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
378 if (!hcd->regs) {
379 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
380 ret = -ENOMEM;
381 goto out4;
382 }
383 hcd->rsrc_start = res->start;
384 hcd->rsrc_len = resource_size(res);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400385
386 irq = platform_get_irq(pdev, 0);
387 if (irq < 0) {
388 ret = -ENXIO;
389 goto out4;
390 }
391
Roland Stigge28643102012-03-12 22:54:50 +0100392 nxp_start_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400393 platform_set_drvdata(pdev, hcd);
394 ohci = hcd_to_ohci(hcd);
395 ohci_hcd_init(ohci);
396
397 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800398 ret = usb_add_hcd(hcd, irq, 0);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400399 if (ret == 0)
400 return ret;
401
Roland Stigge28643102012-03-12 22:54:50 +0100402 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400403out4:
Roland Stigge28643102012-03-12 22:54:50 +0100404 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400405 usb_put_hcd(hcd);
406out3:
407 clk_disable(usb_clk);
408out2:
409 clk_put(usb_clk);
410out1:
Jean Delvare3a407e72008-11-13 18:57:53 +0100411 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400412out:
413 return ret;
414}
415
Roland Stigge28643102012-03-12 22:54:50 +0100416static int usb_hcd_nxp_remove(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400417{
418 struct usb_hcd *hcd = platform_get_drvdata(pdev);
419
420 usb_remove_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100421 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400422 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
423 usb_put_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100424 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400425 clk_disable(usb_clk);
426 clk_put(usb_clk);
Luotao Fu8740cc72010-02-19 15:42:00 +0100427 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100428 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400429
430 platform_set_drvdata(pdev, NULL);
431
432 return 0;
433}
434
Kay Sieversf4fce612008-04-10 21:29:22 -0700435/* work with hotplug and coldplug */
436MODULE_ALIAS("platform:usb-ohci");
437
Roland Stigge2265efe2012-04-29 16:47:03 +0200438#ifdef CONFIG_OF
439static const struct of_device_id usb_hcd_nxp_match[] = {
440 { .compatible = "nxp,ohci-nxp" },
441 {},
442};
443MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
444#endif
445
Roland Stigge28643102012-03-12 22:54:50 +0100446static struct platform_driver usb_hcd_nxp_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400447 .driver = {
448 .name = "usb-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700449 .owner = THIS_MODULE,
Roland Stigge2265efe2012-04-29 16:47:03 +0200450 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400451 },
Roland Stigge28643102012-03-12 22:54:50 +0100452 .probe = usb_hcd_nxp_probe,
453 .remove = usb_hcd_nxp_remove,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400454};
455