blob: 18fe0642743a8fa4c74608ad2862cc6ddb64db68 [file] [log] [blame]
Krzysztof Kozlowski84b21702017-12-25 20:54:32 +01001// SPDX-License-Identifier: GPL-2.0
2//
3// Copyright 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#define DEBUG
11
12#include <linux/kernel.h>
13#include <linux/types.h>
14#include <linux/interrupt.h>
15#include <linux/list.h>
Ben Dooksec976d62009-05-13 22:52:24 +010016#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/timer.h>
18#include <linux/init.h>
19#include <linux/device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010020#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/mach/arch.h>
23#include <asm/mach/map.h>
24#include <asm/mach/irq.h>
25
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020026#include "gpio-samsung.h"
Arnd Bergmannb2a587c2020-08-06 20:20:47 +020027#include <mach/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Arnd Bergmann436d42c2012-08-24 15:22:12 +020030#include <linux/platform_data/usb-ohci-s3c2410.h>
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020031#include "devs.h"
Ben Dooks49121aa2009-03-07 11:44:21 +000032
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080033#include "bast.h"
Heiko Stuebnerec2cc752012-03-07 01:47:11 -080034#include "simtec.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/* control power and monitor over-current events on various Simtec
37 * designed boards.
38*/
39
Ben Dooks484ae6b2005-08-10 16:45:14 +010040static unsigned int power_state[2];
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static void
43usb_simtec_powercontrol(int port, int to)
44{
45 pr_debug("usb_simtec_powercontrol(%d,%d)\n", port, to);
46
Ben Dooks484ae6b2005-08-10 16:45:14 +010047 power_state[port] = to;
48
49 if (power_state[0] && power_state[1])
Ben Dooks7a05a2c2009-05-18 20:15:01 +010050 gpio_set_value(S3C2410_GPB(4), 0);
Ben Dooks484ae6b2005-08-10 16:45:14 +010051 else
Ben Dooks7a05a2c2009-05-18 20:15:01 +010052 gpio_set_value(S3C2410_GPB(4), 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55static irqreturn_t
Linus Torvalds0cd61b62006-10-06 10:53:39 -070056usb_simtec_ocirq(int irq, void *pw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Jeff Garzik2a7057e2007-10-26 05:40:22 -040058 struct s3c2410_hcd_info *info = pw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Ben Dooks7a05a2c2009-05-18 20:15:01 +010060 if (gpio_get_value(S3C2410_GPG(10)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 pr_debug("usb_simtec: over-current irq (oc detected)\n");
Ben Dooks484ae6b2005-08-10 16:45:14 +010062 s3c2410_usb_report_oc(info, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 } else {
64 pr_debug("usb_simtec: over-current irq (oc cleared)\n");
Ben Dooks484ae6b2005-08-10 16:45:14 +010065 s3c2410_usb_report_oc(info, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
67
68 return IRQ_HANDLED;
69}
70
71static void usb_simtec_enableoc(struct s3c2410_hcd_info *info, int on)
72{
73 int ret;
74
75 if (on) {
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080076 ret = request_irq(BAST_IRQ_USBOC, usb_simtec_ocirq,
Michael Opdenackerfa53d5c2013-12-12 07:05:19 +090077 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 "USB Over-current", info);
79 if (ret != 0) {
80 printk(KERN_ERR "failed to request usb oc irq\n");
81 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 } else {
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080083 free_irq(BAST_IRQ_USBOC, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85}
86
Ben Dooksf1267522010-01-13 14:59:46 +090087static struct s3c2410_hcd_info usb_simtec_info __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .port[0] = {
89 .flags = S3C_HCDFLG_USED
90 },
91 .port[1] = {
92 .flags = S3C_HCDFLG_USED
93 },
94
95 .power_control = usb_simtec_powercontrol,
96 .enable_oc = usb_simtec_enableoc,
97};
98
99
Arnd Bergmann673550a2012-05-27 02:42:12 +0000100int __init usb_simtec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Ben Dooks7a05a2c2009-05-18 20:15:01 +0100102 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Ben Dooks50f430e2009-11-13 22:54:12 +0000104 printk("USB Power Control, Copyright 2004 Simtec Electronics\n");
Ben Dooks7a05a2c2009-05-18 20:15:01 +0100105
106 ret = gpio_request(S3C2410_GPB(4), "USB power control");
107 if (ret < 0) {
108 pr_err("%s: failed to get GPB4\n", __func__);
109 return ret;
110 }
111
112 ret = gpio_request(S3C2410_GPG(10), "USB overcurrent");
113 if (ret < 0) {
114 pr_err("%s: failed to get GPG10\n", __func__);
115 gpio_free(S3C2410_GPB(4));
116 return ret;
117 }
118
119 /* turn power on */
120 gpio_direction_output(S3C2410_GPB(4), 1);
121 gpio_direction_input(S3C2410_GPG(10));
122
Ben Dooksf1267522010-01-13 14:59:46 +0900123 s3c_ohci_set_platdata(&usb_simtec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return 0;
125}