^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright 2004-2005 Simtec Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Ben Dooks <ben@simtec.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // http://www.simtec.co.uk/products/EB2410ITX/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Simtec BAST and Thorcom VR1000 USB port support functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/mach/arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/mach/map.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/mach/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "gpio-samsung.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <mach/irqs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/platform_data/usb-ohci-s3c2410.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "devs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "bast.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "simtec.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* control power and monitor over-current events on various Simtec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * designed boards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static unsigned int power_state[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) usb_simtec_powercontrol(int port, int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) power_state[port] = to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (power_state[0] && power_state[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) gpio_set_value(S3C2410_GPB(4), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) gpio_set_value(S3C2410_GPB(4), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) usb_simtec_ocirq(int irq, void *pw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct s3c2410_hcd_info *info = pw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (gpio_get_value(S3C2410_GPG(10)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) pr_debug("usb_simtec: over-current irq (oc detected)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) s3c2410_usb_report_oc(info, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pr_debug("usb_simtec: over-current irq (oc cleared)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) s3c2410_usb_report_oc(info, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ret = request_irq(BAST_IRQ_USBOC, usb_simtec_ocirq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) "USB Over-current", info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) printk(KERN_ERR "failed to request usb oc irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) free_irq(BAST_IRQ_USBOC, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static struct s3c2410_hcd_info usb_simtec_info __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .port[0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .flags = S3C_HCDFLG_USED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .port[1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .flags = S3C_HCDFLG_USED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .power_control = usb_simtec_powercontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .enable_oc = usb_simtec_enableoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int __init usb_simtec_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) printk("USB Power Control, Copyright 2004 Simtec Electronics\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = gpio_request(S3C2410_GPB(4), "USB power control");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) pr_err("%s: failed to get GPB4\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ret = gpio_request(S3C2410_GPG(10), "USB overcurrent");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) pr_err("%s: failed to get GPG10\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) gpio_free(S3C2410_GPB(4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* turn power on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) gpio_direction_output(S3C2410_GPB(4), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) gpio_direction_input(S3C2410_GPG(10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) s3c_ohci_set_platdata(&usb_simtec_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }