ARM: 5873/1: ARM: Fix the reset logic for ARM RealView boards
[safe/jmp/linux-2.6] / arch / arm / mach-s3c2410 / usb-simtec.c
index 7f2b613..6b9d0d8 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/mach-s3c2410/usb-simtec.c
  *
- * Copyright (c) 2004 Simtec Electronics
+ * Copyright 2004-2005 Simtec Electronics
  *   Ben Dooks <ben@simtec.co.uk>
  *
  * http://www.simtec.co.uk/products/EB2410ITX/
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
- *
- * Modifications:
- *     14-Sep-2004 BJD  Created
- *     18-Oct-2004 BJD  Cleanups, and added code to report OC cleared
 */
 
 #define DEBUG
 #include <linux/types.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
+#include <linux/gpio.h>
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/io.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
 
-#include <asm/arch/bast-map.h>
-#include <asm/arch/bast-irq.h>
-#include <asm/arch/usb-control.h>
-#include <asm/arch/regs-gpio.h>
+#include <mach/bast-map.h>
+#include <mach/bast-irq.h>
 
-#include <asm/hardware.h>
-#include <asm/io.h>
+#include <mach/hardware.h>
 #include <asm/irq.h>
-#include <asm/mach-types.h>
 
-#include "devs.h"
+#include <plat/usb-control.h>
+#include <plat/devs.h>
+
 #include "usb-simtec.h"
 
 /* control power and monitor over-current events on various Simtec
  * designed boards.
 */
 
+static unsigned int power_state[2];
+
 static void
 usb_simtec_powercontrol(int port, int to)
 {
        pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);
 
-       if (port == 1)
-               s3c2410_gpio_setpin(S3C2410_GPB4, to ? 0:1);
+       power_state[port] = to;
+
+       if (power_state[0] && power_state[1])
+               gpio_set_value(S3C2410_GPB(4), 0);
+       else
+               gpio_set_value(S3C2410_GPB(4), 1);
 }
 
 static irqreturn_t
-usb_simtec_ocirq(int irq, void *pw, struct pt_regs *regs)
+usb_simtec_ocirq(int irq, void *pw)
 {
-       struct s3c2410_hcd_info *info = (struct s3c2410_hcd_info *)pw;
+       struct s3c2410_hcd_info *info = pw;
 
-       if (s3c2410_gpio_getpin(S3C2410_GPG10) == 0) {
+       if (gpio_get_value(S3C2410_GPG(10)) == 0) {
                pr_debug("usb_simtec: over-current irq (oc detected)\n");
-               s3c2410_report_oc(info, 3);
+               s3c2410_usb_report_oc(info, 3);
        } else {
                pr_debug("usb_simtec: over-current irq (oc cleared)\n");
-               s3c2410_report_oc(info, 0);
+               s3c2410_usb_report_oc(info, 0);
        }
 
        return IRQ_HANDLED;
@@ -77,13 +79,13 @@ static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
        int ret;
 
        if (on) {
-               ret = request_irq(IRQ_USBOC, usb_simtec_ocirq, SA_INTERRUPT,
+               ret = request_irq(IRQ_USBOC, usb_simtec_ocirq,
+                                 IRQF_DISABLED | IRQF_TRIGGER_RISING |
+                                  IRQF_TRIGGER_FALLING,
                                  "USB Over-current", info);
                if (ret != 0) {
                        printk(KERN_ERR "failed to request usb oc irq\n");
                }
-
-               set_irq_type(IRQ_USBOC, IRQT_BOTHEDGE);
        } else {
                free_irq(IRQ_USBOC, info);
        }
@@ -104,10 +106,27 @@ static struct s3c2410_hcd_info usb_simtec_info = {
 
 int usb_simtec_init(void)
 {
-       printk("USB Power Control, (c) 2004 Simtec Electronics\n");
-       s3c_device_usb.dev.platform_data = &usb_simtec_info;
+       int ret;
 
-       s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
-       s3c2410_gpio_setpin(S3C2410_GPB4, 1);
+       printk("USB Power Control, Copyright 2004 Simtec Electronics\n");
+
+       ret = gpio_request(S3C2410_GPB(4), "USB power control");
+       if (ret < 0) {
+               pr_err("%s: failed to get GPB4\n", __func__);
+               return ret;
+       }
+
+       ret = gpio_request(S3C2410_GPG(10), "USB overcurrent");
+       if (ret < 0) {
+               pr_err("%s: failed to get GPG10\n", __func__);
+               gpio_free(S3C2410_GPB(4));
+               return ret;
+       }
+
+       /* turn power on */
+       gpio_direction_output(S3C2410_GPB(4), 1);
+       gpio_direction_input(S3C2410_GPG(10));
+
+       s3c_device_usb.dev.platform_data = &usb_simtec_info;
        return 0;
 }