gpu: host1x: Remove second host1x driver
[deliverable/linux.git] / drivers / usb / host / ohci-nxp.c
CommitLineData
60bbfc84 1/*
28643104 2 * driver for NXP USB Host devices
60bbfc84 3 *
28643104 4 * Currently supported OHCI host devices:
53dc25ad 5 * - NXP LPC32xx
60bbfc84
VW
6 *
7 * Authors: Dmitry Chigirev <source@mvista.com>
dd9048af 8 * Vitaly Wool <vitalywool@gmail.com>
60bbfc84
VW
9 *
10 * register initialization is based on code examples provided by Philips
11 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
12 *
13 * NOTE: This driver does not have suspend/resume functionality
14 * This driver is intended for engineering development purposes only
15 *
16 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
17 * the terms of the GNU General Public License version 2. This program
18 * is licensed "as is" without any warranty of any kind, whether express
19 * or implied.
20 */
21#include <linux/clk.h>
22#include <linux/platform_device.h>
23#include <linux/i2c.h>
2265efea 24#include <linux/of.h>
73108aa9 25#include <linux/usb/isp1301.h>
60bbfc84 26
a09e64fb 27#include <mach/hardware.h>
53dc25ad 28#include <asm/mach-types.h>
60bbfc84 29#include <asm/io.h>
60bbfc84 30
a09e64fb
RK
31#include <mach/platform.h>
32#include <mach/irqs.h>
60bbfc84 33
53dc25ad
RS
34#define USB_CONFIG_BASE 0x31020000
35#define PWRMAN_BASE 0x40004000
36
37#define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64)
60bbfc84
VW
38
39/* USB_CTRL bit defines */
40#define USB_SLAVE_HCLK_EN (1 << 24)
a6a99cf0 41#define USB_DEV_NEED_CLK_EN (1 << 22)
60bbfc84 42#define USB_HOST_NEED_CLK_EN (1 << 21)
a6a99cf0 43#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
60bbfc84 44
53dc25ad 45#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
60bbfc84
VW
46
47/* USB_OTG_STAT_CONTROL bit defines */
48#define TRANSPARENT_I2C_EN (1 << 7)
49#define HOST_EN (1 << 0)
50
53dc25ad
RS
51/* On LPC32xx, those are undefined */
52#ifndef start_int_set_falling_edge
53#define start_int_set_falling_edge(irq)
54#define start_int_set_rising_edge(irq)
55#define start_int_ack(irq)
56#define start_int_mask(irq)
57#define start_int_umask(irq)
58#endif
59
09ce497e 60static struct i2c_client *isp1301_i2c_client;
60bbfc84
VW
61
62extern int usb_disabled(void);
60bbfc84 63
78091dc2
APS
64static struct clk *usb_pll_clk;
65static struct clk *usb_dev_clk;
66static struct clk *usb_otg_clk;
60bbfc84 67
53dc25ad
RS
68static void isp1301_configure_lpc32xx(void)
69{
70 /* LPC32XX only supports DAT_SE0 USB mode */
71 /* This sequence is important */
72
73 /* Disable transparent UART mode first */
74 i2c_smbus_write_byte_data(isp1301_i2c_client,
75 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
76 MC1_UART_EN);
77 i2c_smbus_write_byte_data(isp1301_i2c_client,
78 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
79 ~MC1_SPEED_REG);
80 i2c_smbus_write_byte_data(isp1301_i2c_client,
81 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
82 i2c_smbus_write_byte_data(isp1301_i2c_client,
83 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
84 ~0);
85 i2c_smbus_write_byte_data(isp1301_i2c_client,
86 ISP1301_I2C_MODE_CONTROL_2,
87 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
88 i2c_smbus_write_byte_data(isp1301_i2c_client,
89 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
90 i2c_smbus_write_byte_data(isp1301_i2c_client,
91 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
92 i2c_smbus_write_byte_data(isp1301_i2c_client,
93 ISP1301_I2C_OTG_CONTROL_1,
94 (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
95 i2c_smbus_write_byte_data(isp1301_i2c_client,
96 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
97 (OTG1_DM_PULLUP | OTG1_DP_PULLUP));
98 i2c_smbus_write_byte_data(isp1301_i2c_client,
99 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
100 i2c_smbus_write_byte_data(isp1301_i2c_client,
101 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
102 ~0);
103 i2c_smbus_write_byte_data(isp1301_i2c_client,
104 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
105
106 /* Enable usb_need_clk clock after transceiver is initialized */
a6a99cf0 107 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
53dc25ad
RS
108
109 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
110 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
111 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
112 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
113 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
114 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
115}
116
117static void isp1301_configure(void)
118{
d684f05f 119 isp1301_configure_lpc32xx();
60bbfc84
VW
120}
121
122static inline void isp1301_vbus_on(void)
123{
a6a36008
RS
124 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
125 OTG1_VBUS_DRV);
60bbfc84
VW
126}
127
128static inline void isp1301_vbus_off(void)
129{
a6a36008
RS
130 i2c_smbus_write_byte_data(isp1301_i2c_client,
131 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
132 OTG1_VBUS_DRV);
60bbfc84
VW
133}
134
28643104 135static void nxp_start_hc(void)
60bbfc84
VW
136{
137 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
138 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
139 isp1301_vbus_on();
140}
141
28643104 142static void nxp_stop_hc(void)
60bbfc84
VW
143{
144 unsigned long tmp;
145 isp1301_vbus_off();
146 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
147 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
148}
149
41ac7b3a 150static int ohci_nxp_start(struct usb_hcd *hcd)
60bbfc84
VW
151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
153 int ret;
154
155 if ((ret = ohci_init(ohci)) < 0)
156 return ret;
157
158 if ((ret = ohci_run(ohci)) < 0) {
159 dev_err(hcd->self.controller, "can't start\n");
160 ohci_stop(hcd);
161 return ret;
162 }
163 return 0;
164}
165
28643104 166static const struct hc_driver ohci_nxp_hc_driver = {
60bbfc84 167 .description = hcd_name,
28643104 168 .product_desc = "nxp OHCI",
60bbfc84
VW
169
170 /*
171 * generic hardware linkage
172 */
173 .irq = ohci_irq,
174 .flags = HCD_USB11 | HCD_MEMORY,
175
176 .hcd_priv_size = sizeof(struct ohci_hcd),
177 /*
178 * basic lifecycle operations
179 */
28643104 180 .start = ohci_nxp_start,
60bbfc84 181 .stop = ohci_stop,
8442ae00 182 .shutdown = ohci_shutdown,
60bbfc84
VW
183
184 /*
185 * managing i/o requests and associated device resources
186 */
187 .urb_enqueue = ohci_urb_enqueue,
188 .urb_dequeue = ohci_urb_dequeue,
189 .endpoint_disable = ohci_endpoint_disable,
190
191 /*
192 * scheduling support
193 */
194 .get_frame_number = ohci_get_frame,
195
196 /*
197 * root hub support
198 */
199 .hub_status_data = ohci_hub_status_data,
200 .hub_control = ohci_hub_control,
8442ae00
DB
201#ifdef CONFIG_PM
202 .bus_suspend = ohci_bus_suspend,
203 .bus_resume = ohci_bus_resume,
204#endif
60bbfc84
VW
205 .start_port_reset = ohci_start_port_reset,
206};
207
41ac7b3a 208static int usb_hcd_nxp_probe(struct platform_device *pdev)
60bbfc84
VW
209{
210 struct usb_hcd *hcd = 0;
211 struct ohci_hcd *ohci;
28643104 212 const struct hc_driver *driver = &ohci_nxp_hc_driver;
a6a99cf0 213 struct resource *res;
60bbfc84 214 int ret = 0, irq;
73108aa9
RS
215 struct device_node *isp1301_node;
216
217 if (pdev->dev.of_node) {
218 isp1301_node = of_parse_phandle(pdev->dev.of_node,
219 "transceiver", 0);
220 } else {
221 isp1301_node = NULL;
222 }
223
224 isp1301_i2c_client = isp1301_get_client(isp1301_node);
225 if (!isp1301_i2c_client) {
226 ret = -EPROBE_DEFER;
227 goto out;
228 }
60bbfc84 229
a6a99cf0
RS
230 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
231 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
232
28643104 233 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
60bbfc84 234 if (usb_disabled()) {
b6c227ed 235 dev_err(&pdev->dev, "USB is disabled\n");
60bbfc84
VW
236 ret = -ENODEV;
237 goto out;
238 }
239
60bbfc84 240 /* Enable AHB slave USB clock, needed for further USB clock control */
a6a99cf0 241 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
60bbfc84 242
60bbfc84 243 /* Enable USB PLL */
78091dc2
APS
244 usb_pll_clk = clk_get(&pdev->dev, "ck_pll5");
245 if (IS_ERR(usb_pll_clk)) {
b6c227ed 246 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
78091dc2 247 ret = PTR_ERR(usb_pll_clk);
60bbfc84
VW
248 goto out1;
249 }
250
78091dc2 251 ret = clk_enable(usb_pll_clk);
60bbfc84 252 if (ret < 0) {
b6c227ed 253 dev_err(&pdev->dev, "failed to start USB PLL\n");
60bbfc84
VW
254 goto out2;
255 }
256
78091dc2 257 ret = clk_set_rate(usb_pll_clk, 48000);
60bbfc84 258 if (ret < 0) {
b6c227ed 259 dev_err(&pdev->dev, "failed to set USB clock rate\n");
60bbfc84
VW
260 goto out3;
261 }
262
78091dc2
APS
263 /* Enable USB device clock */
264 usb_dev_clk = clk_get(&pdev->dev, "ck_usbd");
265 if (IS_ERR(usb_dev_clk)) {
266 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
267 ret = PTR_ERR(usb_dev_clk);
268 goto out4;
269 }
270
271 ret = clk_enable(usb_dev_clk);
272 if (ret < 0) {
273 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
274 goto out5;
275 }
276
277 /* Enable USB otg clocks */
278 usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
279 if (IS_ERR(usb_otg_clk)) {
280 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
2ec15a6f 281 ret = PTR_ERR(usb_otg_clk);
78091dc2
APS
282 goto out6;
283 }
284
60bbfc84
VW
285 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
286
78091dc2
APS
287 ret = clk_enable(usb_otg_clk);
288 if (ret < 0) {
289 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
290 goto out7;
291 }
60bbfc84 292
78091dc2 293 isp1301_configure();
60bbfc84 294
a6a99cf0 295 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
60bbfc84 296 if (!hcd) {
b6c227ed 297 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
60bbfc84 298 ret = -ENOMEM;
78091dc2 299 goto out8;
60bbfc84
VW
300 }
301
a6a99cf0
RS
302 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
303 if (!res) {
304 dev_err(&pdev->dev, "Failed to get MEM resource\n");
305 ret = -ENOMEM;
78091dc2 306 goto out8;
a6a99cf0
RS
307 }
308
148e1134
TR
309 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
310 if (IS_ERR(hcd->regs)) {
311 ret = PTR_ERR(hcd->regs);
78091dc2 312 goto out8;
60bbfc84 313 }
a6a99cf0
RS
314 hcd->rsrc_start = res->start;
315 hcd->rsrc_len = resource_size(res);
60bbfc84
VW
316
317 irq = platform_get_irq(pdev, 0);
318 if (irq < 0) {
319 ret = -ENXIO;
78091dc2 320 goto out8;
60bbfc84
VW
321 }
322
28643104 323 nxp_start_hc();
60bbfc84
VW
324 platform_set_drvdata(pdev, hcd);
325 ohci = hcd_to_ohci(hcd);
326 ohci_hcd_init(ohci);
327
328 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
b5dd18d8 329 ret = usb_add_hcd(hcd, irq, 0);
60bbfc84
VW
330 if (ret == 0)
331 return ret;
332
28643104 333 nxp_stop_hc();
78091dc2 334out8:
60bbfc84 335 usb_put_hcd(hcd);
78091dc2
APS
336out7:
337 clk_disable(usb_otg_clk);
338out6:
339 clk_put(usb_otg_clk);
340out5:
341 clk_disable(usb_dev_clk);
342out4:
343 clk_put(usb_dev_clk);
60bbfc84 344out3:
78091dc2 345 clk_disable(usb_pll_clk);
60bbfc84 346out2:
78091dc2 347 clk_put(usb_pll_clk);
60bbfc84 348out1:
3a407e73 349 isp1301_i2c_client = NULL;
60bbfc84
VW
350out:
351 return ret;
352}
353
28643104 354static int usb_hcd_nxp_remove(struct platform_device *pdev)
60bbfc84
VW
355{
356 struct usb_hcd *hcd = platform_get_drvdata(pdev);
357
358 usb_remove_hcd(hcd);
28643104 359 nxp_stop_hc();
60bbfc84
VW
360 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
361 usb_put_hcd(hcd);
78091dc2
APS
362 clk_disable(usb_pll_clk);
363 clk_put(usb_pll_clk);
364 clk_disable(usb_dev_clk);
365 clk_put(usb_dev_clk);
8740cc7d 366 i2c_unregister_device(isp1301_i2c_client);
3a407e73 367 isp1301_i2c_client = NULL;
60bbfc84
VW
368
369 platform_set_drvdata(pdev, NULL);
370
371 return 0;
372}
373
f4fce61d
KS
374/* work with hotplug and coldplug */
375MODULE_ALIAS("platform:usb-ohci");
376
2265efea
RS
377#ifdef CONFIG_OF
378static const struct of_device_id usb_hcd_nxp_match[] = {
379 { .compatible = "nxp,ohci-nxp" },
380 {},
381};
382MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
383#endif
384
28643104 385static struct platform_driver usb_hcd_nxp_driver = {
60bbfc84
VW
386 .driver = {
387 .name = "usb-ohci",
f4fce61d 388 .owner = THIS_MODULE,
2265efea 389 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
60bbfc84 390 },
28643104
RS
391 .probe = usb_hcd_nxp_probe,
392 .remove = usb_hcd_nxp_remove,
60bbfc84
VW
393};
394
This page took 0.8987 seconds and 5 git commands to generate.