Merge branch 'linus' into perfcounters/core
[linux-2.6] / arch / arm / mach-s3c2410 / usb-simtec.c
1 /* linux/arch/arm/mach-s3c2410/usb-simtec.c
2  *
3  * Copyright (c) 2004,2005 Simtec Electronics
4  *   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.
13 */
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>
21 #include <linux/gpio.h>
22 #include <linux/timer.h>
23 #include <linux/init.h>
24 #include <linux/device.h>
25 #include <linux/gpio.h>
26 #include <linux/io.h>
27
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/irq.h>
31
32 #include <mach/bast-map.h>
33 #include <mach/bast-irq.h>
34
35 #include <mach/hardware.h>
36 #include <asm/irq.h>
37
38 #include <plat/usb-control.h>
39 #include <plat/devs.h>
40
41 #include "usb-simtec.h"
42
43 /* control power and monitor over-current events on various Simtec
44  * designed boards.
45 */
46
47 static unsigned int power_state[2];
48
49 static void
50 usb_simtec_powercontrol(int port, int to)
51 {
52         pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);
53
54         power_state[port] = to;
55
56         if (power_state[0] && power_state[1])
57                 gpio_set_value(S3C2410_GPB(4), 0);
58         else
59                 gpio_set_value(S3C2410_GPB(4), 1);
60 }
61
62 static irqreturn_t
63 usb_simtec_ocirq(int irq, void *pw)
64 {
65         struct s3c2410_hcd_info *info = pw;
66
67         if (gpio_get_value(S3C2410_GPG(10)) == 0) {
68                 pr_debug("usb_simtec: over-current irq (oc detected)\n");
69                 s3c2410_usb_report_oc(info, 3);
70         } else {
71                 pr_debug("usb_simtec: over-current irq (oc cleared)\n");
72                 s3c2410_usb_report_oc(info, 0);
73         }
74
75         return IRQ_HANDLED;
76 }
77
78 static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
79 {
80         int ret;
81
82         if (on) {
83                 ret = request_irq(IRQ_USBOC, usb_simtec_ocirq,
84                                   IRQF_DISABLED | IRQF_TRIGGER_RISING |
85                                    IRQF_TRIGGER_FALLING,
86                                   "USB Over-current", info);
87                 if (ret != 0) {
88                         printk(KERN_ERR "failed to request usb oc irq\n");
89                 }
90         } else {
91                 free_irq(IRQ_USBOC, info);
92         }
93 }
94
95 static 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
108 int usb_simtec_init(void)
109 {
110         int ret;
111
112         printk("USB Power Control, (c) 2004 Simtec Electronics\n");
113
114         ret = gpio_request(S3C2410_GPB(4), "USB power control");
115         if (ret < 0) {
116                 pr_err("%s: failed to get GPB4\n", __func__);
117                 return ret;
118         }
119
120         ret = gpio_request(S3C2410_GPG(10), "USB overcurrent");
121         if (ret < 0) {
122                 pr_err("%s: failed to get GPG10\n", __func__);
123                 gpio_free(S3C2410_GPB(4));
124                 return ret;
125         }
126
127         /* turn power on */
128         gpio_direction_output(S3C2410_GPB(4), 1);
129         gpio_direction_input(S3C2410_GPG(10));
130
131         s3c_device_usb.dev.platform_data = &usb_simtec_info;
132         return 0;
133 }