1 From 6d17298d12f873a9b03e5e79ab745fda75bd5b4e Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Tue, 21 Jul 2009 12:51:33 +0200
4 Subject: [PATCH] 100-udc-poll-vbus.patch
7 arch/arm/plat-s3c24xx/include/plat/udc.h | 1 +
8 drivers/usb/gadget/s3c2410_udc.c | 38 ++++++++++++++++++++++
9 drivers/usb/host/ohci-s3c2410.c | 50 ++++++++++++++++++++++++++++-
10 3 files changed, 87 insertions(+), 2 deletions(-)
12 diff --git a/arch/arm/plat-s3c24xx/include/plat/udc.h b/arch/arm/plat-s3c24xx/include/plat/udc.h
13 index 546bb40..763aeba 100644
14 --- a/arch/arm/plat-s3c24xx/include/plat/udc.h
15 +++ b/arch/arm/plat-s3c24xx/include/plat/udc.h
16 @@ -27,6 +27,7 @@ enum s3c2410_udc_cmd_e {
17 struct s3c2410_udc_mach_info {
18 void (*udc_command)(enum s3c2410_udc_cmd_e);
19 void (*vbus_draw)(unsigned int ma);
20 + int (*get_vbus_status)(void);
21 unsigned int vbus_pin;
22 unsigned char vbus_pin_inverted;
24 diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
25 index a9b452f..1c7e5d7 100644
26 --- a/drivers/usb/gadget/s3c2410_udc.c
27 +++ b/drivers/usb/gadget/s3c2410_udc.c
28 @@ -73,6 +73,7 @@ static void __iomem *base_addr;
29 static u64 rsrc_start;
31 static struct dentry *s3c2410_udc_debugfs_root;
32 +static struct timer_list vbus_poll_timer;
34 static inline u32 udc_read(u32 reg)
36 @@ -133,6 +134,8 @@ static int dprintk(int level, const char *fmt, ...)
41 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
42 static int s3c2410_udc_debugfs_seq_show(struct seq_file *m, void *p)
44 u32 addr_reg,pwr_reg,ep_int_reg,usb_int_reg;
45 @@ -196,6 +199,7 @@ static const struct file_operations s3c2410_udc_debugfs_fops = {
46 .release = single_release,
53 @@ -842,6 +846,7 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
58 if (likely (!list_empty(&ep->queue)))
59 req = list_entry(ep->queue.next,
60 struct s3c2410_request, queue);
61 @@ -881,6 +886,8 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
63 if ((ep_csr1 & S3C2410_UDC_OCSR1_PKTRDY) && req) {
64 s3c2410_udc_read_fifo(ep,req);
65 + if (s3c2410_udc_fifo_count_out())
66 + goto handle_ep_again;
70 @@ -1519,6 +1526,20 @@ static irqreturn_t s3c2410_udc_vbus_irq(int irq, void *_dev)
74 +static void s3c2410_udc_vbus_poll(unsigned long _data)
76 + struct s3c2410_udc *data = (struct s3c2410_udc *)_data;
79 + dprintk(DEBUG_NORMAL, "%s()\n", __func__);
80 + if (udc_info && udc_info->get_vbus_status) {
81 + v = udc_info->get_vbus_status();
82 + if ((v > -1) && (v != data->vbus))
83 + s3c2410_udc_vbus_session(&data->gadget, v);
84 + mod_timer(&vbus_poll_timer, jiffies + msecs_to_jiffies(900));
88 static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
90 dprintk(DEBUG_NORMAL, "%s()\n", __func__);
91 @@ -1676,6 +1697,11 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
95 + if (udc_info && udc_info->get_vbus_status && !udc_info->vbus_pin) {
96 + mod_timer(&vbus_poll_timer, jiffies + msecs_to_jiffies(50));
97 + return 0; /* just return, vbus change will enable udc */
101 s3c2410_udc_enable(udc);
103 @@ -1706,6 +1732,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
104 if (driver->disconnect)
105 driver->disconnect(&udc->gadget);
107 + driver->unbind(&udc->gadget);
108 device_del(&udc->gadget.dev);
111 @@ -1892,10 +1919,16 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
114 dev_dbg(dev, "got irq %i\n", irq);
115 + } else if (udc_info && udc_info->get_vbus_status) {
117 + init_timer(&vbus_poll_timer);
118 + vbus_poll_timer.function = s3c2410_udc_vbus_poll;
119 + vbus_poll_timer.data = (unsigned long) udc;
124 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
125 if (s3c2410_udc_debugfs_root) {
126 udc->regs_info = debugfs_create_file("registers", S_IRUGO,
127 s3c2410_udc_debugfs_root,
128 @@ -1903,6 +1936,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
130 dev_warn(dev, "debugfs file creation failed\n");
134 dev_dbg(dev, "probe ok\n");
136 @@ -1938,6 +1972,8 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
137 if (udc_info && udc_info->vbus_pin > 0) {
138 irq = gpio_to_irq(udc_info->vbus_pin);
140 + } else if (udc_info && udc_info->get_vbus_status) {
141 + del_timer_sync(&vbus_poll_timer);
144 free_irq(IRQ_USBD, udc);
145 @@ -2012,12 +2048,14 @@ static int __init udc_init(void)
147 dprintk(DEBUG_NORMAL, "%s: version %s\n", gadget_name, DRIVER_VERSION);
149 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
150 s3c2410_udc_debugfs_root = debugfs_create_dir(gadget_name, NULL);
151 if (IS_ERR(s3c2410_udc_debugfs_root)) {
152 printk(KERN_ERR "%s: debugfs dir creation failed %ld\n",
153 gadget_name, PTR_ERR(s3c2410_udc_debugfs_root));
154 s3c2410_udc_debugfs_root = NULL;
158 retval = platform_driver_register(&udc_driver_2410);
160 diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
161 index a68af2d..3b85d41 100644
162 --- a/drivers/usb/host/ohci-s3c2410.c
163 +++ b/drivers/usb/host/ohci-s3c2410.c
166 #include <linux/platform_device.h>
167 #include <linux/clk.h>
168 +#include <mach/gpio-fns.h>
169 +#include <mach/regs-gpio.h>
170 #include <plat/usb-control.h>
172 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
173 @@ -306,6 +308,42 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
174 local_irq_restore(flags);
177 +/* switching of USB pads */
178 +static ssize_t show_usb_mode(struct device *dev, struct device_attribute *attr,
181 + if (__raw_readl(S3C24XX_MISCCR) & S3C2410_MISCCR_USBHOST)
182 + return sprintf(buf, "host\n");
184 + return sprintf(buf, "device\n");
187 +static ssize_t set_usb_mode(struct device *dev, struct device_attribute *attr,
188 + const char *buf, size_t count)
190 + if (!strncmp(buf, "host", 4)) {
191 + printk(KERN_WARNING "s3c2410: changing usb to host\n");
192 + s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST,
193 + S3C2410_MISCCR_USBHOST);
195 + * - call machine-specific disable-pullup function i
196 + * - enable +Vbus (if hardware supports it)
198 + s3c2410_gpio_setpin(S3C2410_GPB(9), 0);
199 + } else if (!strncmp(buf, "device", 6)) {
200 + printk(KERN_WARNING "s3c2410: changing usb to device\n");
201 + s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST, 0);
202 + s3c2410_gpio_setpin(S3C2410_GPB(9), 1);
204 + printk(KERN_WARNING "s3c2410: unknown mode\n");
211 +static DEVICE_ATTR(usb_mode, S_IRUGO | S_IWUSR, show_usb_mode, set_usb_mode);
213 /* may be called without controller electrically present */
214 /* may be called with controller, bus, and devices active */
216 @@ -486,15 +524,23 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
220 +static int ohci_hcd_s3c2410_drv_resume(struct platform_device *pdev)
222 + struct usb_hcd *hcd = platform_get_drvdata(pdev);
224 + ohci_finish_controller_resume(hcd);
228 static struct platform_driver ohci_hcd_s3c2410_driver = {
229 .probe = ohci_hcd_s3c2410_drv_probe,
230 .remove = ohci_hcd_s3c2410_drv_remove,
231 .shutdown = usb_hcd_platform_shutdown,
232 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
233 - /*.resume = ohci_hcd_s3c2410_drv_resume, */
234 + .resume = ohci_hcd_s3c2410_drv_resume,
236 .owner = THIS_MODULE,
237 - .name = "s3c2410-ohci",
238 + .name = "s3c-ohci",