aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/pxa2xx_udc.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
commitb6cf160c4b788a31f6a4017a469b956ca77febf4 (patch)
treed4d525000e283fe08905385d91dd0170454eae9a /drivers/usb/gadget/pxa2xx_udc.c
parented50d6cbc394cd0966469d3e249353c9dd1d38b9 (diff)
parent2c044a4803804708984931bcbd03314732e995d5 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (128 commits) USB: fix codingstyle issues in drivers/usb/core/*.c USB: fix codingstyle issues in drivers/usb/core/message.c USB: fix codingstyle issues in drivers/usb/core/hcd-pci.c USB: fix codingstyle issues in drivers/usb/core/devio.c USB: fix codingstyle issues in drivers/usb/core/devices.c USB: fix codingstyle issues in drivers/usb/core/*.h USB: fix codingstyle issues in include/linux/usb/ USB: fix codingstyle issues in include/linux/usb.h USB: mark USB drivers as being GPL only USB: use a real vendor and product id for root hubs USB: mount options: fix usbfs USB: Fix usb_serial_driver structure for Kobil cardreader driver. usb: ehci should use u16 for isochronous intervals usb: ehci, remove false clear-reset path USB: Use menuconfig objects usb: ohci-sm501 driver usb: dma bounce buffer support USB: last abuses of intfdata in close for usb-serial drivers USB: kl5kusb105 don't flush to logically disconnected devices USB: oti6858: cleanup ...
Diffstat (limited to 'drivers/usb/gadget/pxa2xx_udc.c')
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c141
1 files changed, 67 insertions, 74 deletions
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 3173b39f0bfd..4402d6f042d9 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -24,7 +24,7 @@
24 * 24 *
25 */ 25 */
26 26
27// #define VERBOSE DBG_VERBOSE 27/* #define VERBOSE_DEBUG */
28 28
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/module.h> 30#include <linux/module.h>
@@ -38,13 +38,14 @@
38#include <linux/timer.h> 38#include <linux/timer.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/proc_fs.h>
42#include <linux/mm.h> 41#include <linux/mm.h>
43#include <linux/platform_device.h> 42#include <linux/platform_device.h>
44#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
45#include <linux/irq.h> 44#include <linux/irq.h>
46#include <linux/clk.h> 45#include <linux/clk.h>
47#include <linux/err.h> 46#include <linux/err.h>
47#include <linux/seq_file.h>
48#include <linux/debugfs.h>
48 49
49#include <asm/byteorder.h> 50#include <asm/byteorder.h>
50#include <asm/dma.h> 51#include <asm/dma.h>
@@ -127,8 +128,10 @@ static int is_vbus_present(void)
127{ 128{
128 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 129 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
129 130
130 if (mach->gpio_vbus) 131 if (mach->gpio_vbus) {
131 return gpio_get_value(mach->gpio_vbus); 132 int value = gpio_get_value(mach->gpio_vbus);
133 return mach->gpio_vbus_inverted ? !value : value;
134 }
132 if (mach->udc_is_connected) 135 if (mach->udc_is_connected)
133 return mach->udc_is_connected(); 136 return mach->udc_is_connected();
134 return 1; 137 return 1;
@@ -677,7 +680,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
677 680
678 /* kickstart this i/o queue? */ 681 /* kickstart this i/o queue? */
679 if (list_empty(&ep->queue) && !ep->stopped) { 682 if (list_empty(&ep->queue) && !ep->stopped) {
680 if (ep->desc == 0 /* ep0 */) { 683 if (ep->desc == NULL/* ep0 */) {
681 unsigned length = _req->length; 684 unsigned length = _req->length;
682 685
683 switch (dev->ep0state) { 686 switch (dev->ep0state) {
@@ -731,7 +734,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
731 } 734 }
732 735
733 /* pio or dma irq handler advances the queue. */ 736 /* pio or dma irq handler advances the queue. */
734 if (likely (req != 0)) 737 if (likely(req != NULL))
735 list_add_tail(&req->queue, &ep->queue); 738 list_add_tail(&req->queue, &ep->queue);
736 local_irq_restore(flags); 739 local_irq_restore(flags);
737 740
@@ -991,45 +994,32 @@ static const struct usb_gadget_ops pxa2xx_udc_ops = {
991 994
992/*-------------------------------------------------------------------------*/ 995/*-------------------------------------------------------------------------*/
993 996
994#ifdef CONFIG_USB_GADGET_DEBUG_FILES 997#ifdef CONFIG_USB_GADGET_DEBUG_FS
995
996static const char proc_node_name [] = "driver/udc";
997 998
998static int 999static int
999udc_proc_read(char *page, char **start, off_t off, int count, 1000udc_seq_show(struct seq_file *m, void *d)
1000 int *eof, void *_dev)
1001{ 1001{
1002 char *buf = page; 1002 struct pxa2xx_udc *dev = m->private;
1003 struct pxa2xx_udc *dev = _dev;
1004 char *next = buf;
1005 unsigned size = count;
1006 unsigned long flags; 1003 unsigned long flags;
1007 int i, t; 1004 int i;
1008 u32 tmp; 1005 u32 tmp;
1009 1006
1010 if (off != 0)
1011 return 0;
1012
1013 local_irq_save(flags); 1007 local_irq_save(flags);
1014 1008
1015 /* basic device status */ 1009 /* basic device status */
1016 t = scnprintf(next, size, DRIVER_DESC "\n" 1010 seq_printf(m, DRIVER_DESC "\n"
1017 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1011 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1018 driver_name, DRIVER_VERSION SIZE_STR "(pio)", 1012 driver_name, DRIVER_VERSION SIZE_STR "(pio)",
1019 dev->driver ? dev->driver->driver.name : "(none)", 1013 dev->driver ? dev->driver->driver.name : "(none)",
1020 is_vbus_present() ? "full speed" : "disconnected"); 1014 is_vbus_present() ? "full speed" : "disconnected");
1021 size -= t;
1022 next += t;
1023 1015
1024 /* registers for device and ep0 */ 1016 /* registers for device and ep0 */
1025 t = scnprintf(next, size, 1017 seq_printf(m,
1026 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", 1018 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
1027 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); 1019 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
1028 size -= t;
1029 next += t;
1030 1020
1031 tmp = UDCCR; 1021 tmp = UDCCR;
1032 t = scnprintf(next, size, 1022 seq_printf(m,
1033 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp, 1023 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
1034 (tmp & UDCCR_REM) ? " rem" : "", 1024 (tmp & UDCCR_REM) ? " rem" : "",
1035 (tmp & UDCCR_RSTIR) ? " rstir" : "", 1025 (tmp & UDCCR_RSTIR) ? " rstir" : "",
@@ -1039,11 +1029,9 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1039 (tmp & UDCCR_RSM) ? " rsm" : "", 1029 (tmp & UDCCR_RSM) ? " rsm" : "",
1040 (tmp & UDCCR_UDA) ? " uda" : "", 1030 (tmp & UDCCR_UDA) ? " uda" : "",
1041 (tmp & UDCCR_UDE) ? " ude" : ""); 1031 (tmp & UDCCR_UDE) ? " ude" : "");
1042 size -= t;
1043 next += t;
1044 1032
1045 tmp = UDCCS0; 1033 tmp = UDCCS0;
1046 t = scnprintf(next, size, 1034 seq_printf(m,
1047 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp, 1035 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
1048 (tmp & UDCCS0_SA) ? " sa" : "", 1036 (tmp & UDCCS0_SA) ? " sa" : "",
1049 (tmp & UDCCS0_RNE) ? " rne" : "", 1037 (tmp & UDCCS0_RNE) ? " rne" : "",
@@ -1053,28 +1041,22 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1053 (tmp & UDCCS0_FTF) ? " ftf" : "", 1041 (tmp & UDCCS0_FTF) ? " ftf" : "",
1054 (tmp & UDCCS0_IPR) ? " ipr" : "", 1042 (tmp & UDCCS0_IPR) ? " ipr" : "",
1055 (tmp & UDCCS0_OPR) ? " opr" : ""); 1043 (tmp & UDCCS0_OPR) ? " opr" : "");
1056 size -= t;
1057 next += t;
1058 1044
1059 if (dev->has_cfr) { 1045 if (dev->has_cfr) {
1060 tmp = UDCCFR; 1046 tmp = UDCCFR;
1061 t = scnprintf(next, size, 1047 seq_printf(m,
1062 "udccfr %02X =%s%s\n", tmp, 1048 "udccfr %02X =%s%s\n", tmp,
1063 (tmp & UDCCFR_AREN) ? " aren" : "", 1049 (tmp & UDCCFR_AREN) ? " aren" : "",
1064 (tmp & UDCCFR_ACM) ? " acm" : ""); 1050 (tmp & UDCCFR_ACM) ? " acm" : "");
1065 size -= t;
1066 next += t;
1067 } 1051 }
1068 1052
1069 if (!is_vbus_present() || !dev->driver) 1053 if (!is_vbus_present() || !dev->driver)
1070 goto done; 1054 goto done;
1071 1055
1072 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1056 seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1073 dev->stats.write.bytes, dev->stats.write.ops, 1057 dev->stats.write.bytes, dev->stats.write.ops,
1074 dev->stats.read.bytes, dev->stats.read.ops, 1058 dev->stats.read.bytes, dev->stats.read.ops,
1075 dev->stats.irqs); 1059 dev->stats.irqs);
1076 size -= t;
1077 next += t;
1078 1060
1079 /* dump endpoint queues */ 1061 /* dump endpoint queues */
1080 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) { 1062 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
@@ -1082,61 +1064,68 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1082 struct pxa2xx_request *req; 1064 struct pxa2xx_request *req;
1083 1065
1084 if (i != 0) { 1066 if (i != 0) {
1085 const struct usb_endpoint_descriptor *d; 1067 const struct usb_endpoint_descriptor *desc;
1086 1068
1087 d = ep->desc; 1069 desc = ep->desc;
1088 if (!d) 1070 if (!desc)
1089 continue; 1071 continue;
1090 tmp = *dev->ep [i].reg_udccs; 1072 tmp = *dev->ep [i].reg_udccs;
1091 t = scnprintf(next, size, 1073 seq_printf(m,
1092 "%s max %d %s udccs %02x irqs %lu\n", 1074 "%s max %d %s udccs %02x irqs %lu\n",
1093 ep->ep.name, le16_to_cpu (d->wMaxPacketSize), 1075 ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
1094 "pio", tmp, ep->pio_irqs); 1076 "pio", tmp, ep->pio_irqs);
1095 /* TODO translate all five groups of udccs bits! */ 1077 /* TODO translate all five groups of udccs bits! */
1096 1078
1097 } else /* ep0 should only have one transfer queued */ 1079 } else /* ep0 should only have one transfer queued */
1098 t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n", 1080 seq_printf(m, "ep0 max 16 pio irqs %lu\n",
1099 ep->pio_irqs); 1081 ep->pio_irqs);
1100 if (t <= 0 || t > size)
1101 goto done;
1102 size -= t;
1103 next += t;
1104 1082
1105 if (list_empty(&ep->queue)) { 1083 if (list_empty(&ep->queue)) {
1106 t = scnprintf(next, size, "\t(nothing queued)\n"); 1084 seq_printf(m, "\t(nothing queued)\n");
1107 if (t <= 0 || t > size)
1108 goto done;
1109 size -= t;
1110 next += t;
1111 continue; 1085 continue;
1112 } 1086 }
1113 list_for_each_entry(req, &ep->queue, queue) { 1087 list_for_each_entry(req, &ep->queue, queue) {
1114 t = scnprintf(next, size, 1088 seq_printf(m,
1115 "\treq %p len %d/%d buf %p\n", 1089 "\treq %p len %d/%d buf %p\n",
1116 &req->req, req->req.actual, 1090 &req->req, req->req.actual,
1117 req->req.length, req->req.buf); 1091 req->req.length, req->req.buf);
1118 if (t <= 0 || t > size)
1119 goto done;
1120 size -= t;
1121 next += t;
1122 } 1092 }
1123 } 1093 }
1124 1094
1125done: 1095done:
1126 local_irq_restore(flags); 1096 local_irq_restore(flags);
1127 *eof = 1; 1097 return 0;
1128 return count - size;
1129} 1098}
1130 1099
1131#define create_proc_files() \ 1100static int
1132 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev) 1101udc_debugfs_open(struct inode *inode, struct file *file)
1133#define remove_proc_files() \ 1102{
1134 remove_proc_entry(proc_node_name, NULL) 1103 return single_open(file, udc_seq_show, inode->i_private);
1104}
1105
1106static const struct file_operations debug_fops = {
1107 .open = udc_debugfs_open,
1108 .read = seq_read,
1109 .llseek = seq_lseek,
1110 .release = single_release,
1111 .owner = THIS_MODULE,
1112};
1113
1114#define create_debug_files(dev) \
1115 do { \
1116 dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
1117 S_IRUGO, NULL, dev, &debug_fops); \
1118 } while (0)
1119#define remove_debug_files(dev) \
1120 do { \
1121 if (dev->debugfs_udc) \
1122 debugfs_remove(dev->debugfs_udc); \
1123 } while (0)
1135 1124
1136#else /* !CONFIG_USB_GADGET_DEBUG_FILES */ 1125#else /* !CONFIG_USB_GADGET_DEBUG_FILES */
1137 1126
1138#define create_proc_files() do {} while (0) 1127#define create_debug_files(dev) do {} while (0)
1139#define remove_proc_files() do {} while (0) 1128#define remove_debug_files(dev) do {} while (0)
1140 1129
1141#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1130#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1142 1131
@@ -1345,6 +1334,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1345 local_irq_enable(); 1334 local_irq_enable();
1346 1335
1347 driver->unbind(&dev->gadget); 1336 driver->unbind(&dev->gadget);
1337 dev->gadget.dev.driver = NULL;
1348 dev->driver = NULL; 1338 dev->driver = NULL;
1349 1339
1350 device_del (&dev->gadget.dev); 1340 device_del (&dev->gadget.dev);
@@ -1397,6 +1387,9 @@ static irqreturn_t udc_vbus_irq(int irq, void *_dev)
1397 struct pxa2xx_udc *dev = _dev; 1387 struct pxa2xx_udc *dev = _dev;
1398 int vbus = gpio_get_value(dev->mach->gpio_vbus); 1388 int vbus = gpio_get_value(dev->mach->gpio_vbus);
1399 1389
1390 if (dev->mach->gpio_vbus_inverted)
1391 vbus = !vbus;
1392
1400 pxa2xx_udc_vbus_session(&dev->gadget, vbus); 1393 pxa2xx_udc_vbus_session(&dev->gadget, vbus);
1401 return IRQ_HANDLED; 1394 return IRQ_HANDLED;
1402} 1395}
@@ -2099,7 +2092,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2099 /* insist on Intel/ARM/XScale */ 2092 /* insist on Intel/ARM/XScale */
2100 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev)); 2093 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
2101 if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) { 2094 if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
2102 printk(KERN_ERR "%s: not XScale!\n", driver_name); 2095 pr_err("%s: not XScale!\n", driver_name);
2103 return -ENODEV; 2096 return -ENODEV;
2104 } 2097 }
2105 2098
@@ -2128,7 +2121,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2128 break; 2121 break;
2129#endif 2122#endif
2130 default: 2123 default:
2131 printk(KERN_ERR "%s: unrecognized processor: %08x\n", 2124 pr_err("%s: unrecognized processor: %08x\n",
2132 driver_name, chiprev); 2125 driver_name, chiprev);
2133 /* iop3xx, ixp4xx, ... */ 2126 /* iop3xx, ixp4xx, ... */
2134 return -ENODEV; 2127 return -ENODEV;
@@ -2199,7 +2192,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2199 retval = request_irq(irq, pxa2xx_udc_irq, 2192 retval = request_irq(irq, pxa2xx_udc_irq,
2200 IRQF_DISABLED, driver_name, dev); 2193 IRQF_DISABLED, driver_name, dev);
2201 if (retval != 0) { 2194 if (retval != 0) {
2202 printk(KERN_ERR "%s: can't get irq %d, err %d\n", 2195 pr_err("%s: can't get irq %d, err %d\n",
2203 driver_name, irq, retval); 2196 driver_name, irq, retval);
2204 goto err_irq1; 2197 goto err_irq1;
2205 } 2198 }
@@ -2212,7 +2205,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2212 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 2205 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
2213 driver_name, dev); 2206 driver_name, dev);
2214 if (retval != 0) { 2207 if (retval != 0) {
2215 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2208 pr_err("%s: can't get irq %i, err %d\n",
2216 driver_name, LUBBOCK_USB_DISC_IRQ, retval); 2209 driver_name, LUBBOCK_USB_DISC_IRQ, retval);
2217lubbock_fail0: 2210lubbock_fail0:
2218 goto err_irq_lub; 2211 goto err_irq_lub;
@@ -2222,7 +2215,7 @@ lubbock_fail0:
2222 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 2215 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
2223 driver_name, dev); 2216 driver_name, dev);
2224 if (retval != 0) { 2217 if (retval != 0) {
2225 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2218 pr_err("%s: can't get irq %i, err %d\n",
2226 driver_name, LUBBOCK_USB_IRQ, retval); 2219 driver_name, LUBBOCK_USB_IRQ, retval);
2227 free_irq(LUBBOCK_USB_DISC_IRQ, dev); 2220 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2228 goto lubbock_fail0; 2221 goto lubbock_fail0;
@@ -2235,12 +2228,12 @@ lubbock_fail0:
2235 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 2228 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2236 driver_name, dev); 2229 driver_name, dev);
2237 if (retval != 0) { 2230 if (retval != 0) {
2238 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2231 pr_err("%s: can't get irq %i, err %d\n",
2239 driver_name, vbus_irq, retval); 2232 driver_name, vbus_irq, retval);
2240 goto err_vbus_irq; 2233 goto err_vbus_irq;
2241 } 2234 }
2242 } 2235 }
2243 create_proc_files(); 2236 create_debug_files(dev);
2244 2237
2245 return 0; 2238 return 0;
2246 2239
@@ -2277,7 +2270,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
2277 return -EBUSY; 2270 return -EBUSY;
2278 2271
2279 udc_disable(dev); 2272 udc_disable(dev);
2280 remove_proc_files(); 2273 remove_debug_files(dev);
2281 2274
2282 if (dev->got_irq) { 2275 if (dev->got_irq) {
2283 free_irq(platform_get_irq(pdev, 0), dev); 2276 free_irq(platform_get_irq(pdev, 0), dev);
@@ -2361,7 +2354,7 @@ static struct platform_driver udc_driver = {
2361 2354
2362static int __init udc_init(void) 2355static int __init udc_init(void)
2363{ 2356{
2364 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); 2357 pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
2365 return platform_driver_probe(&udc_driver, pxa2xx_udc_probe); 2358 return platform_driver_probe(&udc_driver, pxa2xx_udc_probe);
2366} 2359}
2367module_init(udc_init); 2360module_init(udc_init);