aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/host/Kconfig2
-rw-r--r--drivers/usb/host/ohci-hcd.c5
-rw-r--r--drivers/usb/host/ohci-pnx4008.c476
4 files changed, 484 insertions, 0 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 005043197527..f9b1719b9a37 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -25,6 +25,7 @@ config USB_ARCH_HAS_OHCI
25 default y if PXA27x 25 default y if PXA27x
26 default y if ARCH_EP93XX 26 default y if ARCH_EP93XX
27 default y if (ARCH_AT91RM9200 || ARCH_AT91SAM9261) 27 default y if (ARCH_AT91RM9200 || ARCH_AT91SAM9261)
28 default y if ARCH_PNX4008
28 # PPC: 29 # PPC:
29 default y if STB03xxx 30 default y if STB03xxx
30 default y if PPC_MPC52xx 31 default y if PPC_MPC52xx
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b93d71d28db7..77ba2b0bf0b7 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -83,6 +83,8 @@ config USB_OHCI_HCD
83 tristate "OHCI HCD support" 83 tristate "OHCI HCD support"
84 depends on USB && USB_ARCH_HAS_OHCI 84 depends on USB && USB_ARCH_HAS_OHCI
85 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 85 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
86 select I2C if ARCH_PNX4008
87 select I2C_PNX if ARCH_PNX4008
86 ---help--- 88 ---help---
87 The Open Host Controller Interface (OHCI) is a standard for accessing 89 The Open Host Controller Interface (OHCI) is a standard for accessing
88 USB 1.1 host controller hardware. It does more in hardware than Intel's 90 USB 1.1 host controller hardware. It does more in hardware than Intel's
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 0684f57c14a0..cbf38ae5ae76 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -940,6 +940,10 @@ MODULE_LICENSE ("GPL");
940#include "ohci-at91.c" 940#include "ohci-at91.c"
941#endif 941#endif
942 942
943#ifdef CONFIG_ARCH_PNX4008
944#include "ohci-pnx4008.c"
945#endif
946
943#if !(defined(CONFIG_PCI) \ 947#if !(defined(CONFIG_PCI) \
944 || defined(CONFIG_SA1111) \ 948 || defined(CONFIG_SA1111) \
945 || defined(CONFIG_ARCH_S3C2410) \ 949 || defined(CONFIG_ARCH_S3C2410) \
@@ -951,6 +955,7 @@ MODULE_LICENSE ("GPL");
951 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \ 955 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \
952 || defined (CONFIG_ARCH_AT91RM9200) \ 956 || defined (CONFIG_ARCH_AT91RM9200) \
953 || defined (CONFIG_ARCH_AT91SAM9261) \ 957 || defined (CONFIG_ARCH_AT91SAM9261) \
958 || defined (CONFIG_ARCH_PNX4008) \
954 ) 959 )
955#error "missing bus glue for ohci-hcd" 960#error "missing bus glue for ohci-hcd"
956#endif 961#endif
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
new file mode 100644
index 000000000000..82cb22f002e7
--- /dev/null
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -0,0 +1,476 @@
1/*
2 * drivers/usb/host/ohci-pnx4008.c
3 *
4 * driver for Philips PNX4008 USB Host
5 *
6 * Authors: Dmitry Chigirev <source@mvista.com>
7 * Vitaly Wool <vitalywool@gmail.com>
8 *
9 * register initialization is based on code examples provided by Philips
10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
11 *
12 * NOTE: This driver does not have suspend/resume functionality
13 * This driver is intended for engineering development purposes only
14 *
15 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
16 * the terms of the GNU General Public License version 2. This program
17 * is licensed "as is" without any warranty of any kind, whether express
18 * or implied.
19 */
20#include <linux/clk.h>
21#include <linux/platform_device.h>
22#include <linux/i2c.h>
23
24#include <asm/hardware.h>
25#include <asm/io.h>
26#include <asm/mach-types.h>
27
28#include <asm/arch/platform.h>
29#include <asm/arch/irqs.h>
30#include <asm/arch/gpio.h>
31
32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64)
33
34/* USB_CTRL bit defines */
35#define USB_SLAVE_HCLK_EN (1 << 24)
36#define USB_HOST_NEED_CLK_EN (1 << 21)
37
38#define USB_OTG_CLK_CTRL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF4)
39#define USB_OTG_CLK_STAT IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF8)
40
41/* USB_OTG_CLK_CTRL bit defines */
42#define AHB_M_CLOCK_ON (1 << 4)
43#define OTG_CLOCK_ON (1 << 3)
44#define I2C_CLOCK_ON (1 << 2)
45#define DEV_CLOCK_ON (1 << 1)
46#define HOST_CLOCK_ON (1 << 0)
47
48#define USB_OTG_STAT_CONTROL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0x110)
49
50/* USB_OTG_STAT_CONTROL bit defines */
51#define TRANSPARENT_I2C_EN (1 << 7)
52#define HOST_EN (1 << 0)
53
54/* ISP1301 USB transceiver I2C registers */
55#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
56
57#define MC1_SPEED_REG (1 << 0)
58#define MC1_SUSPEND_REG (1 << 1)
59#define MC1_DAT_SE0 (1 << 2)
60#define MC1_TRANSPARENT (1 << 3)
61#define MC1_BDIS_ACON_EN (1 << 4)
62#define MC1_OE_INT_EN (1 << 5)
63#define MC1_UART_EN (1 << 6)
64#define MC1_MASK 0x7f
65
66#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
67
68#define MC2_GLOBAL_PWR_DN (1 << 0)
69#define MC2_SPD_SUSP_CTRL (1 << 1)
70#define MC2_BI_DI (1 << 2)
71#define MC2_TRANSP_BDIR0 (1 << 3)
72#define MC2_TRANSP_BDIR1 (1 << 4)
73#define MC2_AUDIO_EN (1 << 5)
74#define MC2_PSW_EN (1 << 6)
75#define MC2_EN2V7 (1 << 7)
76
77#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
78# define OTG1_DP_PULLUP (1 << 0)
79# define OTG1_DM_PULLUP (1 << 1)
80# define OTG1_DP_PULLDOWN (1 << 2)
81# define OTG1_DM_PULLDOWN (1 << 3)
82# define OTG1_ID_PULLDOWN (1 << 4)
83# define OTG1_VBUS_DRV (1 << 5)
84# define OTG1_VBUS_DISCHRG (1 << 6)
85# define OTG1_VBUS_CHRG (1 << 7)
86#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
87# define OTG_B_SESS_END (1 << 6)
88# define OTG_B_SESS_VLD (1 << 7)
89
90#define ISP1301_I2C_ADDR 0x2C
91
92#define ISP1301_I2C_MODE_CONTROL_1 0x4
93#define ISP1301_I2C_MODE_CONTROL_2 0x12
94#define ISP1301_I2C_OTG_CONTROL_1 0x6
95#define ISP1301_I2C_OTG_CONTROL_2 0x10
96#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
97#define ISP1301_I2C_INTERRUPT_LATCH 0xA
98#define ISP1301_I2C_INTERRUPT_FALLING 0xC
99#define ISP1301_I2C_INTERRUPT_RISING 0xE
100#define ISP1301_I2C_REG_CLEAR_ADDR 1
101
102struct i2c_driver isp1301_driver;
103struct i2c_client *isp1301_i2c_client;
104
105extern int usb_disabled(void);
106extern int ocpi_enable(void);
107
108static struct clk *usb_clk;
109
110static int isp1301_probe(struct i2c_adapter *adap);
111static int isp1301_detach(struct i2c_client *client);
112static int isp1301_command(struct i2c_client *client, unsigned int cmd,
113 void *arg);
114
115static unsigned short normal_i2c[] =
116 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
117static unsigned short dummy_i2c_addrlist[] = { I2C_CLIENT_END };
118
119static struct i2c_client_address_data addr_data = {
120 .normal_i2c = normal_i2c,
121 .probe = dummy_i2c_addrlist,
122 .ignore = dummy_i2c_addrlist,
123};
124
125struct i2c_driver isp1301_driver = {
126 .id = I2C_DRIVERID_I2CDEV, /* Fake Id */
127 .class = I2C_CLASS_HWMON,
128 .attach_adapter = isp1301_probe,
129 .detach_client = isp1301_detach,
130 .command = isp1301_command
131};
132
133static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind)
134{
135 struct i2c_client *c;
136
137 c = (struct i2c_client *)kzalloc(sizeof(*c), SLAB_KERNEL);
138
139 if (!c)
140 return -ENOMEM;
141
142 strcpy(c->name, "isp1301");
143 c->flags = 0;
144 c->addr = addr;
145 c->adapter = adap;
146 c->driver = &isp1301_driver;
147
148 isp1301_i2c_client = c;
149
150 return i2c_attach_client(c);
151}
152
153static int isp1301_probe(struct i2c_adapter *adap)
154{
155 return i2c_probe(adap, &addr_data, isp1301_attach);
156}
157
158static int isp1301_detach(struct i2c_client *client)
159{
160 i2c_detach_client(client);
161 kfree(isp1301_i2c_client);
162 return 0;
163}
164
165/* No commands defined */
166static int isp1301_command(struct i2c_client *client, unsigned int cmd,
167 void *arg)
168{
169 return 0;
170}
171
172static void i2c_write(u8 buf, u8 subaddr)
173{
174 char tmpbuf[2];
175
176 tmpbuf[0] = subaddr; /*register number */
177 tmpbuf[1] = buf; /*register data */
178 i2c_master_send(isp1301_i2c_client, &tmpbuf[0], 2);
179}
180
181static void isp1301_configure(void)
182{
183 /* PNX4008 only supports DAT_SE0 USB mode */
184 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
185 /* Power up externel charge-pump */
186
187 i2c_write(MC1_DAT_SE0 | MC1_SPEED_REG, ISP1301_I2C_MODE_CONTROL_1);
188 i2c_write(~(MC1_DAT_SE0 | MC1_SPEED_REG),
189 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
190 i2c_write(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL,
191 ISP1301_I2C_MODE_CONTROL_2);
192 i2c_write(~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL),
193 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR);
194 i2c_write(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN,
195 ISP1301_I2C_OTG_CONTROL_1);
196 i2c_write(~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN),
197 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
198 i2c_write(0xFF,
199 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR);
200 i2c_write(0xFF,
201 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR);
202 i2c_write(0xFF,
203 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR);
204
205}
206
207static inline void isp1301_vbus_on(void)
208{
209 i2c_write(OTG1_VBUS_DRV, ISP1301_I2C_OTG_CONTROL_1);
210}
211
212static inline void isp1301_vbus_off(void)
213{
214 i2c_write(OTG1_VBUS_DRV,
215 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
216}
217
218static void pnx4008_start_hc(void)
219{
220 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
221 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
222 isp1301_vbus_on();
223}
224
225static void pnx4008_stop_hc(void)
226{
227 unsigned long tmp;
228 isp1301_vbus_off();
229 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
230 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
231}
232
233static int __devinit ohci_pnx4008_start(struct usb_hcd *hcd)
234{
235 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
236 int ret;
237
238 if ((ret = ohci_init(ohci)) < 0)
239 return ret;
240
241 if ((ret = ohci_run(ohci)) < 0) {
242 dev_err(hcd->self.controller, "can't start\n");
243 ohci_stop(hcd);
244 return ret;
245 }
246 return 0;
247}
248
249static const struct hc_driver ohci_pnx4008_hc_driver = {
250 .description = hcd_name,
251 .product_desc = "pnx4008 OHCI",
252
253 /*
254 * generic hardware linkage
255 */
256 .irq = ohci_irq,
257 .flags = HCD_USB11 | HCD_MEMORY,
258
259 .hcd_priv_size = sizeof(struct ohci_hcd),
260 /*
261 * basic lifecycle operations
262 */
263 .start = ohci_pnx4008_start,
264 .stop = ohci_stop,
265
266 /*
267 * managing i/o requests and associated device resources
268 */
269 .urb_enqueue = ohci_urb_enqueue,
270 .urb_dequeue = ohci_urb_dequeue,
271 .endpoint_disable = ohci_endpoint_disable,
272
273 /*
274 * scheduling support
275 */
276 .get_frame_number = ohci_get_frame,
277
278 /*
279 * root hub support
280 */
281 .hub_status_data = ohci_hub_status_data,
282 .hub_control = ohci_hub_control,
283
284 .start_port_reset = ohci_start_port_reset,
285};
286
287#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
288
289static void pnx4008_set_usb_bits(void)
290{
291 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
292 start_int_ack(SE_USB_OTG_ATX_INT_N);
293 start_int_umask(SE_USB_OTG_ATX_INT_N);
294
295 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
296 start_int_ack(SE_USB_OTG_TIMER_INT);
297 start_int_umask(SE_USB_OTG_TIMER_INT);
298
299 start_int_set_rising_edge(SE_USB_I2C_INT);
300 start_int_ack(SE_USB_I2C_INT);
301 start_int_umask(SE_USB_I2C_INT);
302
303 start_int_set_rising_edge(SE_USB_INT);
304 start_int_ack(SE_USB_INT);
305 start_int_umask(SE_USB_INT);
306
307 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
308 start_int_ack(SE_USB_NEED_CLK_INT);
309 start_int_umask(SE_USB_NEED_CLK_INT);
310
311 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
312 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
313 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
314}
315
316static void pnx4008_unset_usb_bits(void)
317{
318 start_int_mask(SE_USB_OTG_ATX_INT_N);
319 start_int_mask(SE_USB_OTG_TIMER_INT);
320 start_int_mask(SE_USB_I2C_INT);
321 start_int_mask(SE_USB_INT);
322 start_int_mask(SE_USB_NEED_CLK_INT);
323 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
324}
325
326static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
327{
328 struct usb_hcd *hcd = 0;
329 struct ohci_hcd *ohci;
330 const struct hc_driver *driver = &ohci_pnx4008_hc_driver;
331
332 int ret = 0, irq;
333
334 dev_dbg(&pdev->dev, "%s: " DRIVER_INFO " (pnx4008)\n", hcd_name);
335 if (usb_disabled()) {
336 err("USB is disabled");
337 ret = -ENODEV;
338 goto out;
339 }
340
341 if (pdev->num_resources != 2
342 || pdev->resource[0].flags != IORESOURCE_MEM
343 || pdev->resource[1].flags != IORESOURCE_IRQ) {
344 err("Invalid resource configuration");
345 ret = -ENODEV;
346 goto out;
347 }
348
349 /* Enable AHB slave USB clock, needed for further USB clock control */
350 __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL);
351
352 ret = i2c_add_driver(&isp1301_driver);
353 if (ret < 0) {
354 err("failed to connect I2C to ISP1301 USB Transceiver");
355 goto out;
356 }
357
358 isp1301_configure();
359
360 /* Enable USB PLL */
361 usb_clk = clk_get(&pdev->dev, "ck_pll5");
362 if (IS_ERR(usb_clk)) {
363 err("failed to acquire USB PLL");
364 ret = PTR_ERR(usb_clk);
365 goto out1;
366 }
367
368 ret = clk_enable(usb_clk);
369 if (ret < 0) {
370 err("failed to start USB PLL");
371 goto out2;
372 }
373
374 ret = clk_set_rate(usb_clk, 48000);
375 if (ret < 0) {
376 err("failed to set USB clock rate");
377 goto out3;
378 }
379
380 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
381
382 /* Set to enable all needed USB clocks */
383 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
384
385 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
386 USB_CLOCK_MASK) ;
387
388 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id);
389 if (!hcd) {
390 err("Failed to allocate HC buffer");
391 ret = -ENOMEM;
392 goto out3;
393 }
394
395 /* Set all USB bits in the Start Enable register */
396 pnx4008_set_usb_bits();
397
398 hcd->rsrc_start = pdev->resource[0].start;
399 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
400 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
401 dev_dbg(&pdev->dev, "request_mem_region failed\n");
402 ret = -ENOMEM;
403 goto out4;
404 }
405 hcd->regs = (void __iomem *)pdev->resource[0].start;
406
407 irq = platform_get_irq(pdev, 0);
408 if (irq < 0) {
409 ret = -ENXIO;
410 goto out4;
411 }
412
413 hcd->self.hcpriv = (void *)hcd;
414
415 pnx4008_start_hc();
416 platform_set_drvdata(pdev, hcd);
417 ohci = hcd_to_ohci(hcd);
418 ohci_hcd_init(ohci);
419
420 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
421 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
422 if (ret == 0)
423 return ret;
424
425 pnx4008_stop_hc();
426out4:
427 pnx4008_unset_usb_bits();
428 usb_put_hcd(hcd);
429out3:
430 clk_disable(usb_clk);
431out2:
432 clk_put(usb_clk);
433out1:
434 i2c_del_driver(&isp1301_driver);
435out:
436 return ret;
437}
438
439static int usb_hcd_pnx4008_remove(struct platform_device *pdev)
440{
441 struct usb_hcd *hcd = platform_get_drvdata(pdev);
442
443 usb_remove_hcd(hcd);
444 pnx4008_stop_hc();
445 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
446 usb_put_hcd(hcd);
447 pnx4008_unset_usb_bits();
448 clk_disable(usb_clk);
449 clk_put(usb_clk);
450 i2c_del_driver(&isp1301_driver);
451
452 platform_set_drvdata(pdev, NULL);
453
454 return 0;
455}
456
457static struct platform_driver usb_hcd_pnx4008_driver = {
458 .driver = {
459 .name = "usb-ohci",
460 },
461 .probe = usb_hcd_pnx4008_probe,
462 .remove = usb_hcd_pnx4008_remove,
463};
464
465static int __init usb_hcd_pnx4008_init(void)
466{
467 return platform_driver_register(&usb_hcd_pnx4008_driver);
468}
469
470static void __exit usb_hcd_pnx4008_cleanup(void)
471{
472 return platform_driver_unregister(&usb_hcd_pnx4008_driver);
473}
474
475module_init(usb_hcd_pnx4008_init);
476module_exit(usb_hcd_pnx4008_cleanup);