blob: c60066a636068addf10ad8b66539fd370ce6af71 [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_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040047
48/* USB_OTG_STAT_CONTROL bit defines */
49#define TRANSPARENT_I2C_EN (1 << 7)
50#define HOST_EN (1 << 0)
51
Roland Stigge53dc25a2012-03-12 22:54:51 +010052/* On LPC32xx, those are undefined */
53#ifndef start_int_set_falling_edge
54#define start_int_set_falling_edge(irq)
55#define start_int_set_rising_edge(irq)
56#define start_int_ack(irq)
57#define start_int_mask(irq)
58#define start_int_umask(irq)
59#endif
60
Jean Delvare09ce4972009-10-01 19:03:13 +020061static struct i2c_client *isp1301_i2c_client;
Vitaly Wool60bbfc82006-06-29 18:28:18 +040062
63extern int usb_disabled(void);
Vitaly Wool60bbfc82006-06-29 18:28:18 +040064
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -030065static struct clk *usb_pll_clk;
66static struct clk *usb_dev_clk;
67static struct clk *usb_otg_clk;
Vitaly Wool60bbfc82006-06-29 18:28:18 +040068
Roland Stigge53dc25a2012-03-12 22:54:51 +010069static void isp1301_configure_pnx4008(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +040070{
71 /* PNX4008 only supports DAT_SE0 USB mode */
72 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
73 /* Power up externel charge-pump */
74
Roland Stiggea6a36002012-03-12 22:54:52 +010075 i2c_smbus_write_byte_data(isp1301_i2c_client,
76 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG);
77 i2c_smbus_write_byte_data(isp1301_i2c_client,
78 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
79 ~(MC1_DAT_SE0 | MC1_SPEED_REG));
80 i2c_smbus_write_byte_data(isp1301_i2c_client,
81 ISP1301_I2C_MODE_CONTROL_2,
82 MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL);
83 i2c_smbus_write_byte_data(isp1301_i2c_client,
84 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR,
85 ~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
86 i2c_smbus_write_byte_data(isp1301_i2c_client,
87 ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
88 i2c_smbus_write_byte_data(isp1301_i2c_client,
89 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
90 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
91 i2c_smbus_write_byte_data(isp1301_i2c_client,
92 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF);
93 i2c_smbus_write_byte_data(isp1301_i2c_client,
94 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
95 0xFF);
96 i2c_smbus_write_byte_data(isp1301_i2c_client,
97 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
98 0xFF);
Roland Stigge53dc25a2012-03-12 22:54:51 +010099}
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400100
Roland Stigge53dc25a2012-03-12 22:54:51 +0100101static void isp1301_configure_lpc32xx(void)
102{
103 /* LPC32XX only supports DAT_SE0 USB mode */
104 /* This sequence is important */
105
106 /* Disable transparent UART mode first */
107 i2c_smbus_write_byte_data(isp1301_i2c_client,
108 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
109 MC1_UART_EN);
110 i2c_smbus_write_byte_data(isp1301_i2c_client,
111 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
112 ~MC1_SPEED_REG);
113 i2c_smbus_write_byte_data(isp1301_i2c_client,
114 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
115 i2c_smbus_write_byte_data(isp1301_i2c_client,
116 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
117 ~0);
118 i2c_smbus_write_byte_data(isp1301_i2c_client,
119 ISP1301_I2C_MODE_CONTROL_2,
120 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
121 i2c_smbus_write_byte_data(isp1301_i2c_client,
122 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
123 i2c_smbus_write_byte_data(isp1301_i2c_client,
124 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
125 i2c_smbus_write_byte_data(isp1301_i2c_client,
126 ISP1301_I2C_OTG_CONTROL_1,
127 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
128 i2c_smbus_write_byte_data(isp1301_i2c_client,
129 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
130 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
131 i2c_smbus_write_byte_data(isp1301_i2c_client,
132 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
133 i2c_smbus_write_byte_data(isp1301_i2c_client,
134 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
135 ~0);
136 i2c_smbus_write_byte_data(isp1301_i2c_client,
137 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
138
139 /* Enable usb_need_clk clock after transceiver is initialized */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200140 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
Roland Stigge53dc25a2012-03-12 22:54:51 +0100141
142 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
143 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
144 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
145 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
146 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
147 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
148}
149
150static void isp1301_configure(void)
151{
152 if (machine_is_pnx4008())
153 isp1301_configure_pnx4008();
154 else
155 isp1301_configure_lpc32xx();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400156}
157
158static inline void isp1301_vbus_on(void)
159{
Roland Stiggea6a36002012-03-12 22:54:52 +0100160 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
161 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400162}
163
164static inline void isp1301_vbus_off(void)
165{
Roland Stiggea6a36002012-03-12 22:54:52 +0100166 i2c_smbus_write_byte_data(isp1301_i2c_client,
167 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
168 OTG1_VBUS_DRV);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400169}
170
Roland Stigge28643102012-03-12 22:54:50 +0100171static void nxp_start_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400172{
173 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
174 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
175 isp1301_vbus_on();
176}
177
Roland Stigge28643102012-03-12 22:54:50 +0100178static void nxp_stop_hc(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400179{
180 unsigned long tmp;
181 isp1301_vbus_off();
182 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
183 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
184}
185
Roland Stigge28643102012-03-12 22:54:50 +0100186static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400187{
188 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
189 int ret;
190
191 if ((ret = ohci_init(ohci)) < 0)
192 return ret;
193
194 if ((ret = ohci_run(ohci)) < 0) {
195 dev_err(hcd->self.controller, "can't start\n");
196 ohci_stop(hcd);
197 return ret;
198 }
199 return 0;
200}
201
Roland Stigge28643102012-03-12 22:54:50 +0100202static const struct hc_driver ohci_nxp_hc_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400203 .description = hcd_name,
Roland Stigge28643102012-03-12 22:54:50 +0100204 .product_desc = "nxp OHCI",
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400205
206 /*
207 * generic hardware linkage
208 */
209 .irq = ohci_irq,
210 .flags = HCD_USB11 | HCD_MEMORY,
211
212 .hcd_priv_size = sizeof(struct ohci_hcd),
213 /*
214 * basic lifecycle operations
215 */
Roland Stigge28643102012-03-12 22:54:50 +0100216 .start = ohci_nxp_start,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400217 .stop = ohci_stop,
David Brownell8442ae02006-10-02 07:20:10 -0700218 .shutdown = ohci_shutdown,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400219
220 /*
221 * managing i/o requests and associated device resources
222 */
223 .urb_enqueue = ohci_urb_enqueue,
224 .urb_dequeue = ohci_urb_dequeue,
225 .endpoint_disable = ohci_endpoint_disable,
226
227 /*
228 * scheduling support
229 */
230 .get_frame_number = ohci_get_frame,
231
232 /*
233 * root hub support
234 */
235 .hub_status_data = ohci_hub_status_data,
236 .hub_control = ohci_hub_control,
David Brownell8442ae02006-10-02 07:20:10 -0700237#ifdef CONFIG_PM
238 .bus_suspend = ohci_bus_suspend,
239 .bus_resume = ohci_bus_resume,
240#endif
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400241 .start_port_reset = ohci_start_port_reset,
242};
243
Roland Stigge28643102012-03-12 22:54:50 +0100244static void nxp_set_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400245{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100246 if (machine_is_pnx4008()) {
247 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
248 start_int_ack(SE_USB_OTG_ATX_INT_N);
249 start_int_umask(SE_USB_OTG_ATX_INT_N);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400250
Roland Stigge53dc25a2012-03-12 22:54:51 +0100251 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
252 start_int_ack(SE_USB_OTG_TIMER_INT);
253 start_int_umask(SE_USB_OTG_TIMER_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400254
Roland Stigge53dc25a2012-03-12 22:54:51 +0100255 start_int_set_rising_edge(SE_USB_I2C_INT);
256 start_int_ack(SE_USB_I2C_INT);
257 start_int_umask(SE_USB_I2C_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400258
Roland Stigge53dc25a2012-03-12 22:54:51 +0100259 start_int_set_rising_edge(SE_USB_INT);
260 start_int_ack(SE_USB_INT);
261 start_int_umask(SE_USB_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400262
Roland Stigge53dc25a2012-03-12 22:54:51 +0100263 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
264 start_int_ack(SE_USB_NEED_CLK_INT);
265 start_int_umask(SE_USB_NEED_CLK_INT);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400266
Roland Stigge53dc25a2012-03-12 22:54:51 +0100267 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
268 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
269 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
270 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400271}
272
Roland Stigge28643102012-03-12 22:54:50 +0100273static void nxp_unset_usb_bits(void)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400274{
Roland Stigge53dc25a2012-03-12 22:54:51 +0100275 if (machine_is_pnx4008()) {
276 start_int_mask(SE_USB_OTG_ATX_INT_N);
277 start_int_mask(SE_USB_OTG_TIMER_INT);
278 start_int_mask(SE_USB_I2C_INT);
279 start_int_mask(SE_USB_INT);
280 start_int_mask(SE_USB_NEED_CLK_INT);
281 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
282 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400283}
284
Roland Stigge28643102012-03-12 22:54:50 +0100285static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400286{
287 struct usb_hcd *hcd = 0;
288 struct ohci_hcd *ohci;
Roland Stigge28643102012-03-12 22:54:50 +0100289 const struct hc_driver *driver = &ohci_nxp_hc_driver;
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200290 struct resource *res;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400291 int ret = 0, irq;
Roland Stigge73108aa2012-04-29 16:47:06 +0200292 struct device_node *isp1301_node;
293
294 if (pdev->dev.of_node) {
295 isp1301_node = of_parse_phandle(pdev->dev.of_node,
296 "transceiver", 0);
297 } else {
298 isp1301_node = NULL;
299 }
300
301 isp1301_i2c_client = isp1301_get_client(isp1301_node);
302 if (!isp1301_i2c_client) {
303 ret = -EPROBE_DEFER;
304 goto out;
305 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400306
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200307 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
308 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
309
Roland Stigge28643102012-03-12 22:54:50 +0100310 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400311 if (usb_disabled()) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700312 dev_err(&pdev->dev, "USB is disabled\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400313 ret = -ENODEV;
314 goto out;
315 }
316
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400317 /* Enable AHB slave USB clock, needed for further USB clock control */
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200318 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400319
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400320 /* Enable USB PLL */
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300321 usb_pll_clk = clk_get(&pdev->dev, "ck_pll5");
322 if (IS_ERR(usb_pll_clk)) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700323 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300324 ret = PTR_ERR(usb_pll_clk);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400325 goto out1;
326 }
327
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300328 ret = clk_enable(usb_pll_clk);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400329 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700330 dev_err(&pdev->dev, "failed to start USB PLL\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400331 goto out2;
332 }
333
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300334 ret = clk_set_rate(usb_pll_clk, 48000);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400335 if (ret < 0) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700336 dev_err(&pdev->dev, "failed to set USB clock rate\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400337 goto out3;
338 }
339
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300340 /* Enable USB device clock */
341 usb_dev_clk = clk_get(&pdev->dev, "ck_usbd");
342 if (IS_ERR(usb_dev_clk)) {
343 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
344 ret = PTR_ERR(usb_dev_clk);
345 goto out4;
346 }
347
348 ret = clk_enable(usb_dev_clk);
349 if (ret < 0) {
350 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
351 goto out5;
352 }
353
354 /* Enable USB otg clocks */
355 usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
356 if (IS_ERR(usb_otg_clk)) {
357 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
Julia Lawall2ec15a62012-08-25 21:57:07 +0200358 ret = PTR_ERR(usb_otg_clk);
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300359 goto out6;
360 }
361
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400362 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
363
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300364 ret = clk_enable(usb_otg_clk);
365 if (ret < 0) {
366 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
367 goto out7;
368 }
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400369
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300370 isp1301_configure();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400371
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200372 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400373 if (!hcd) {
Greg Kroah-Hartmanb6c227e2012-04-27 11:24:41 -0700374 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400375 ret = -ENOMEM;
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300376 goto out8;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400377 }
378
379 /* Set all USB bits in the Start Enable register */
Roland Stigge28643102012-03-12 22:54:50 +0100380 nxp_set_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400381
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200382 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383 if (!res) {
384 dev_err(&pdev->dev, "Failed to get MEM resource\n");
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400385 ret = -ENOMEM;
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300386 goto out8;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400387 }
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200388
389 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
390 if (!hcd->regs) {
391 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
392 ret = -ENOMEM;
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300393 goto out8;
Roland Stiggea6a99cf2012-04-29 16:47:02 +0200394 }
395 hcd->rsrc_start = res->start;
396 hcd->rsrc_len = resource_size(res);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400397
398 irq = platform_get_irq(pdev, 0);
399 if (irq < 0) {
400 ret = -ENXIO;
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300401 goto out8;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400402 }
403
Roland Stigge28643102012-03-12 22:54:50 +0100404 nxp_start_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400405 platform_set_drvdata(pdev, hcd);
406 ohci = hcd_to_ohci(hcd);
407 ohci_hcd_init(ohci);
408
409 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800410 ret = usb_add_hcd(hcd, irq, 0);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400411 if (ret == 0)
412 return ret;
413
Roland Stigge28643102012-03-12 22:54:50 +0100414 nxp_stop_hc();
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300415out8:
Roland Stigge28643102012-03-12 22:54:50 +0100416 nxp_unset_usb_bits();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400417 usb_put_hcd(hcd);
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300418out7:
419 clk_disable(usb_otg_clk);
420out6:
421 clk_put(usb_otg_clk);
422out5:
423 clk_disable(usb_dev_clk);
424out4:
425 clk_put(usb_dev_clk);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400426out3:
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300427 clk_disable(usb_pll_clk);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400428out2:
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300429 clk_put(usb_pll_clk);
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400430out1:
Jean Delvare3a407e72008-11-13 18:57:53 +0100431 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400432out:
433 return ret;
434}
435
Roland Stigge28643102012-03-12 22:54:50 +0100436static int usb_hcd_nxp_remove(struct platform_device *pdev)
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400437{
438 struct usb_hcd *hcd = platform_get_drvdata(pdev);
439
440 usb_remove_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100441 nxp_stop_hc();
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400442 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
443 usb_put_hcd(hcd);
Roland Stigge28643102012-03-12 22:54:50 +0100444 nxp_unset_usb_bits();
Alexandre Pereira da Silva78091dc2012-06-20 09:02:23 -0300445 clk_disable(usb_pll_clk);
446 clk_put(usb_pll_clk);
447 clk_disable(usb_dev_clk);
448 clk_put(usb_dev_clk);
Luotao Fu8740cc72010-02-19 15:42:00 +0100449 i2c_unregister_device(isp1301_i2c_client);
Jean Delvare3a407e72008-11-13 18:57:53 +0100450 isp1301_i2c_client = NULL;
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400451
452 platform_set_drvdata(pdev, NULL);
453
454 return 0;
455}
456
Kay Sieversf4fce612008-04-10 21:29:22 -0700457/* work with hotplug and coldplug */
458MODULE_ALIAS("platform:usb-ohci");
459
Roland Stigge2265efe2012-04-29 16:47:03 +0200460#ifdef CONFIG_OF
461static const struct of_device_id usb_hcd_nxp_match[] = {
462 { .compatible = "nxp,ohci-nxp" },
463 {},
464};
465MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
466#endif
467
Roland Stigge28643102012-03-12 22:54:50 +0100468static struct platform_driver usb_hcd_nxp_driver = {
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400469 .driver = {
470 .name = "usb-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700471 .owner = THIS_MODULE,
Roland Stigge2265efe2012-04-29 16:47:03 +0200472 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400473 },
Roland Stigge28643102012-03-12 22:54:50 +0100474 .probe = usb_hcd_nxp_probe,
475 .remove = usb_hcd_nxp_remove,
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400476};
477