usb-simtec.c 2.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/* linux/arch/arm/mach-s3c2410/usb-simtec.c
 *
3
 * Copyright (c) 2004,2005 Simtec Electronics
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *   Ben Dooks <ben@simtec.co.uk>
 *
 * http://www.simtec.co.uk/products/EB2410ITX/
 *
 * Simtec BAST and Thorcom VR1000 USB port support functions
 *
 * 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.
*/

#define DEBUG

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/list.h>
21
#include <linux/gpio.h>
L
Linus Torvalds 已提交
22 23 24
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/device.h>
25
#include <linux/io.h>
L
Linus Torvalds 已提交
26 27 28 29 30

#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/irq.h>

31 32 33
#include <mach/bast-map.h>
#include <mach/bast-irq.h>
#include <mach/regs-gpio.h>
L
Linus Torvalds 已提交
34

35
#include <mach/hardware.h>
L
Linus Torvalds 已提交
36 37
#include <asm/irq.h>

38
#include <plat/usb-control.h>
39
#include <plat/devs.h>
40

L
Linus Torvalds 已提交
41 42 43 44 45 46
#include "usb-simtec.h"

/* control power and monitor over-current events on various Simtec
 * designed boards.
*/

47 48
static unsigned int power_state[2];

L
Linus Torvalds 已提交
49 50 51 52 53
static void
usb_simtec_powercontrol(int port, int to)
{
	pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);

54 55 56 57 58 59
	power_state[port] = to;

	if (power_state[0] && power_state[1])
		s3c2410_gpio_setpin(S3C2410_GPB4, 0);
	else
		s3c2410_gpio_setpin(S3C2410_GPB4, 1);
L
Linus Torvalds 已提交
60 61 62
}

static irqreturn_t
63
usb_simtec_ocirq(int irq, void *pw)
L
Linus Torvalds 已提交
64
{
65
	struct s3c2410_hcd_info *info = pw;
L
Linus Torvalds 已提交
66 67 68

	if (s3c2410_gpio_getpin(S3C2410_GPG10) == 0) {
		pr_debug("usb_simtec: over-current irq (oc detected)\n");
69
		s3c2410_usb_report_oc(info, 3);
L
Linus Torvalds 已提交
70 71
	} else {
		pr_debug("usb_simtec: over-current irq (oc cleared)\n");
72
		s3c2410_usb_report_oc(info, 0);
L
Linus Torvalds 已提交
73 74 75 76 77 78 79 80 81 82
	}

	return IRQ_HANDLED;
}

static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
{
	int ret;

	if (on) {
R
Russell King 已提交
83
		ret = request_irq(IRQ_USBOC, usb_simtec_ocirq,
84 85
				  IRQF_DISABLED | IRQF_TRIGGER_RISING |
				   IRQF_TRIGGER_FALLING,
L
Linus Torvalds 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
				  "USB Over-current", info);
		if (ret != 0) {
			printk(KERN_ERR "failed to request usb oc irq\n");
		}
	} else {
		free_irq(IRQ_USBOC, info);
	}
}

static struct s3c2410_hcd_info usb_simtec_info = {
	.port[0]	= {
		.flags	= S3C_HCDFLG_USED
	},
	.port[1]	= {
		.flags	= S3C_HCDFLG_USED
	},

	.power_control	= usb_simtec_powercontrol,
	.enable_oc	= usb_simtec_enableoc,
};


int usb_simtec_init(void)
{
	printk("USB Power Control, (c) 2004 Simtec Electronics\n");
	s3c_device_usb.dev.platform_data = &usb_simtec_info;

113
	s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPIO_OUTPUT);
L
Linus Torvalds 已提交
114 115 116
	s3c2410_gpio_setpin(S3C2410_GPB4, 1);
	return 0;
}