blob: 506252b33fef7f000600b77bf7a08370b7b40023 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/usb-simtec.c
2 *
Ben Dooks484ae6b2005-08-10 16:45:14 +01003 * Copyright (c) 2004,2005 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://www.simtec.co.uk/products/EB2410ITX/
7 *
8 * Simtec BAST and Thorcom VR1000 USB port support functions
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013*/
14
15#define DEBUG
16
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/interrupt.h>
20#include <linux/list.h>
Ben Dooksec976d62009-05-13 22:52:24 +010021#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/timer.h>
23#include <linux/init.h>
24#include <linux/device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/mach/arch.h>
28#include <asm/mach/map.h>
29#include <asm/mach/irq.h>
30
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/bast-map.h>
32#include <mach/bast-irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010033#include <mach/regs-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Ben Dooks49121aa2009-03-07 11:44:21 +000038#include <plat/usb-control.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010039#include <plat/devs.h>
Ben Dooks49121aa2009-03-07 11:44:21 +000040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "usb-simtec.h"
42
43/* control power and monitor over-current events on various Simtec
44 * designed boards.
45*/
46
Ben Dooks484ae6b2005-08-10 16:45:14 +010047static unsigned int power_state[2];
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static void
50usb_simtec_powercontrol(int port, int to)
51{
52 pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);
53
Ben Dooks484ae6b2005-08-10 16:45:14 +010054 power_state[port] = to;
55
56 if (power_state[0] && power_state[1])
57 s3c2410_gpio_setpin(S3C2410_GPB4, 0);
58 else
59 s3c2410_gpio_setpin(S3C2410_GPB4, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
62static irqreturn_t
Linus Torvalds0cd61b62006-10-06 10:53:39 -070063usb_simtec_ocirq(int irq, void *pw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Jeff Garzik2a7057e2007-10-26 05:40:22 -040065 struct s3c2410_hcd_info *info = pw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 if (s3c2410_gpio_getpin(S3C2410_GPG10) == 0) {
68 pr_debug("usb_simtec: over-current irq (oc detected)\n");
Ben Dooks484ae6b2005-08-10 16:45:14 +010069 s3c2410_usb_report_oc(info, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 } else {
71 pr_debug("usb_simtec: over-current irq (oc cleared)\n");
Ben Dooks484ae6b2005-08-10 16:45:14 +010072 s3c2410_usb_report_oc(info, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
74
75 return IRQ_HANDLED;
76}
77
78static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
79{
80 int ret;
81
82 if (on) {
Russell King9ded96f2006-01-08 01:02:07 -080083 ret = request_irq(IRQ_USBOC, usb_simtec_ocirq,
Thomas Gleixner52e405e2006-07-03 02:20:05 +020084 IRQF_DISABLED | IRQF_TRIGGER_RISING |
85 IRQF_TRIGGER_FALLING,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 "USB Over-current", info);
87 if (ret != 0) {
88 printk(KERN_ERR "failed to request usb oc irq\n");
89 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 } else {
91 free_irq(IRQ_USBOC, info);
92 }
93}
94
95static struct s3c2410_hcd_info usb_simtec_info = {
96 .port[0] = {
97 .flags = S3C_HCDFLG_USED
98 },
99 .port[1] = {
100 .flags = S3C_HCDFLG_USED
101 },
102
103 .power_control = usb_simtec_powercontrol,
104 .enable_oc = usb_simtec_enableoc,
105};
106
107
108int usb_simtec_init(void)
109{
110 printk("USB Power Control, (c) 2004 Simtec Electronics\n");
111 s3c_device_usb.dev.platform_data = &usb_simtec_info;
112
Ben Dooks9f05f6a2009-05-13 21:46:15 +0100113 s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPIO_OUTPUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 s3c2410_gpio_setpin(S3C2410_GPB4, 1);
115 return 0;
116}