aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-08-02 02:58:22 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:03 -0400
commita4e3ef5597e26dad006544d38b9ab6ff42382b76 (patch)
treeea35833ffe27301bd058f64dda90d190decc0265
parenta1d534bb23e5c5c28fb6f6fb48588362df0907e8 (diff)
USB: gadget: gadget_is_{dualspeed,otg} predicates and cleanup
This adds two small inlines to the gadget stack, which will often evaluate to compile-time constants. That can help shrink object code and remove #ifdeffery. - gadget_is_dualspeed(), currently always a compile-time constant (depending on which controller is selected). - gadget_is_otg(), usually a compile time "false", but this is a runtime test if the platform enables OTG (since it's reasonable to populate boards with different USB sockets). It also updates two peripheral controller drivers to use these: - fsl_usb2_udc, mostly OTG-related bugfixes: non-OTG devices must follow the rules about drawing VBUS power, and OTG ones need to reject invalid SET_FEATURE requests. - omap_udc, just scrubbing a bit of #ifdeffery. And also gadgetfs, which lost some #ifdefs and moved to a more standard handling of DEBUG and VERBOSE_DEBUG. The main benefits come from patches which will follow. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c9
-rw-r--r--drivers/usb/gadget/inode.c44
-rw-r--r--drivers/usb/gadget/omap_udc.c10
-rw-r--r--include/linux/usb_gadget.h33
4 files changed, 59 insertions, 37 deletions
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index d57bcfbc08a5..89c768e2aed7 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -1090,14 +1090,11 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
1090 */ 1090 */
1091static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA) 1091static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1092{ 1092{
1093#ifdef CONFIG_USB_OTG
1094 struct fsl_udc *udc; 1093 struct fsl_udc *udc;
1095 1094
1096 udc = container_of(gadget, struct fsl_udc, gadget); 1095 udc = container_of(gadget, struct fsl_udc, gadget);
1097
1098 if (udc->transceiver) 1096 if (udc->transceiver)
1099 return otg_set_power(udc->transceiver, mA); 1097 return otg_set_power(udc->transceiver, mA);
1100#endif
1101 return -ENOTSUPP; 1098 return -ENOTSUPP;
1102} 1099}
1103 1100
@@ -1321,7 +1318,7 @@ static void setup_received_irq(struct fsl_udc *udc,
1321 | USB_TYPE_STANDARD)) { 1318 | USB_TYPE_STANDARD)) {
1322 /* Note: The driver has not include OTG support yet. 1319 /* Note: The driver has not include OTG support yet.
1323 * This will be set when OTG support is added */ 1320 * This will be set when OTG support is added */
1324 if (!udc->gadget.is_otg) 1321 if (!gadget_is_otg(udc->gadget))
1325 break; 1322 break;
1326 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) 1323 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE)
1327 udc->gadget.b_hnp_enable = 1; 1324 udc->gadget.b_hnp_enable = 1;
@@ -1330,6 +1327,8 @@ static void setup_received_irq(struct fsl_udc *udc,
1330 else if (setup->bRequest == 1327 else if (setup->bRequest ==
1331 USB_DEVICE_A_ALT_HNP_SUPPORT) 1328 USB_DEVICE_A_ALT_HNP_SUPPORT)
1332 udc->gadget.a_alt_hnp_support = 1; 1329 udc->gadget.a_alt_hnp_support = 1;
1330 else
1331 break;
1333 rc = 0; 1332 rc = 0;
1334 } else 1333 } else
1335 break; 1334 break;
@@ -1840,10 +1839,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1840 if (!driver || driver != udc_controller->driver || !driver->unbind) 1839 if (!driver || driver != udc_controller->driver || !driver->unbind)
1841 return -EINVAL; 1840 return -EINVAL;
1842 1841
1843#ifdef CONFIG_USB_OTG
1844 if (udc_controller->transceiver) 1842 if (udc_controller->transceiver)
1845 (void)otg_set_peripheral(udc_controller->transceiver, 0); 1843 (void)otg_set_peripheral(udc_controller->transceiver, 0);
1846#endif
1847 1844
1848 /* stop DR, disable intr */ 1845 /* stop DR, disable intr */
1849 dr_controller_stop(udc_controller); 1846 dr_controller_stop(udc_controller);
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 173004f60fea..129eda5358f7 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -20,8 +20,7 @@
20 */ 20 */
21 21
22 22
23// #define DEBUG /* data to help fault diagnosis */ 23/* #define VERBOSE_DEBUG */
24// #define VERBOSE /* extra debug messages (success too) */
25 24
26#include <linux/init.h> 25#include <linux/init.h>
27#include <linux/module.h> 26#include <linux/module.h>
@@ -253,7 +252,7 @@ static const char *CHIP;
253 do { } while (0) 252 do { } while (0)
254#endif /* DEBUG */ 253#endif /* DEBUG */
255 254
256#ifdef VERBOSE 255#ifdef VERBOSE_DEBUG
257#define VDEBUG DBG 256#define VDEBUG DBG
258#else 257#else
259#define VDEBUG(dev,fmt,args...) \ 258#define VDEBUG(dev,fmt,args...) \
@@ -1010,11 +1009,12 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1010 /* assume that was SET_CONFIGURATION */ 1009 /* assume that was SET_CONFIGURATION */
1011 if (dev->current_config) { 1010 if (dev->current_config) {
1012 unsigned power; 1011 unsigned power;
1013#ifdef CONFIG_USB_GADGET_DUALSPEED 1012
1014 if (dev->gadget->speed == USB_SPEED_HIGH) 1013 if (gadget_is_dualspeed(dev->gadget)
1014 && (dev->gadget->speed
1015 == USB_SPEED_HIGH))
1015 power = dev->hs_config->bMaxPower; 1016 power = dev->hs_config->bMaxPower;
1016 else 1017 else
1017#endif
1018 power = dev->config->bMaxPower; 1018 power = dev->config->bMaxPower;
1019 usb_gadget_vbus_draw(dev->gadget, 2 * power); 1019 usb_gadget_vbus_draw(dev->gadget, 2 * power);
1020 } 1020 }
@@ -1355,24 +1355,21 @@ static int
1355config_buf (struct dev_data *dev, u8 type, unsigned index) 1355config_buf (struct dev_data *dev, u8 type, unsigned index)
1356{ 1356{
1357 int len; 1357 int len;
1358#ifdef CONFIG_USB_GADGET_DUALSPEED 1358 int hs = 0;
1359 int hs;
1360#endif
1361 1359
1362 /* only one configuration */ 1360 /* only one configuration */
1363 if (index > 0) 1361 if (index > 0)
1364 return -EINVAL; 1362 return -EINVAL;
1365 1363
1366#ifdef CONFIG_USB_GADGET_DUALSPEED 1364 if (gadget_is_dualspeed(dev->gadget)) {
1367 hs = (dev->gadget->speed == USB_SPEED_HIGH); 1365 hs = (dev->gadget->speed == USB_SPEED_HIGH);
1368 if (type == USB_DT_OTHER_SPEED_CONFIG) 1366 if (type == USB_DT_OTHER_SPEED_CONFIG)
1369 hs = !hs; 1367 hs = !hs;
1368 }
1370 if (hs) { 1369 if (hs) {
1371 dev->req->buf = dev->hs_config; 1370 dev->req->buf = dev->hs_config;
1372 len = le16_to_cpu(dev->hs_config->wTotalLength); 1371 len = le16_to_cpu(dev->hs_config->wTotalLength);
1373 } else 1372 } else {
1374#endif
1375 {
1376 dev->req->buf = dev->config; 1373 dev->req->buf = dev->config;
1377 len = le16_to_cpu(dev->config->wTotalLength); 1374 len = le16_to_cpu(dev->config->wTotalLength);
1378 } 1375 }
@@ -1393,13 +1390,13 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1393 spin_lock (&dev->lock); 1390 spin_lock (&dev->lock);
1394 dev->setup_abort = 0; 1391 dev->setup_abort = 0;
1395 if (dev->state == STATE_DEV_UNCONNECTED) { 1392 if (dev->state == STATE_DEV_UNCONNECTED) {
1396#ifdef CONFIG_USB_GADGET_DUALSPEED 1393 if (gadget_is_dualspeed(gadget)
1397 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == NULL) { 1394 && gadget->speed == USB_SPEED_HIGH
1395 && dev->hs_config == NULL) {
1398 spin_unlock(&dev->lock); 1396 spin_unlock(&dev->lock);
1399 ERROR (dev, "no high speed config??\n"); 1397 ERROR (dev, "no high speed config??\n");
1400 return -EINVAL; 1398 return -EINVAL;
1401 } 1399 }
1402#endif /* CONFIG_USB_GADGET_DUALSPEED */
1403 1400
1404 dev->state = STATE_DEV_CONNECTED; 1401 dev->state = STATE_DEV_CONNECTED;
1405 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; 1402 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
@@ -1469,13 +1466,12 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1469 // user mode expected to disable endpoints 1466 // user mode expected to disable endpoints
1470 } else { 1467 } else {
1471 u8 config, power; 1468 u8 config, power;
1472#ifdef CONFIG_USB_GADGET_DUALSPEED 1469
1473 if (gadget->speed == USB_SPEED_HIGH) { 1470 if (gadget_is_dualspeed(gadget)
1471 && gadget->speed == USB_SPEED_HIGH) {
1474 config = dev->hs_config->bConfigurationValue; 1472 config = dev->hs_config->bConfigurationValue;
1475 power = dev->hs_config->bMaxPower; 1473 power = dev->hs_config->bMaxPower;
1476 } else 1474 } else {
1477#endif
1478 {
1479 config = dev->config->bConfigurationValue; 1475 config = dev->config->bConfigurationValue;
1480 power = dev->config->bMaxPower; 1476 power = dev->config->bMaxPower;
1481 } 1477 }
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 9b0f0925dddf..bf2788dfb32b 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1241,19 +1241,15 @@ static void pullup_enable(struct omap_udc *udc)
1241 udc->gadget.dev.parent->power.power_state = PMSG_ON; 1241 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1242 udc->gadget.dev.power.power_state = PMSG_ON; 1242 udc->gadget.dev.power.power_state = PMSG_ON;
1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1244#ifndef CONFIG_USB_OTG 1244 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx())
1245 if (!cpu_is_omap15xx())
1246 OTG_CTRL_REG |= OTG_BSESSVLD; 1245 OTG_CTRL_REG |= OTG_BSESSVLD;
1247#endif
1248 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1246 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1249} 1247}
1250 1248
1251static void pullup_disable(struct omap_udc *udc) 1249static void pullup_disable(struct omap_udc *udc)
1252{ 1250{
1253#ifndef CONFIG_USB_OTG 1251 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx())
1254 if (!cpu_is_omap15xx())
1255 OTG_CTRL_REG &= ~OTG_BSESSVLD; 1252 OTG_CTRL_REG &= ~OTG_BSESSVLD;
1256#endif
1257 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1253 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1258 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; 1254 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN;
1259} 1255}
@@ -1390,7 +1386,7 @@ static void update_otg(struct omap_udc *udc)
1390{ 1386{
1391 u16 devstat; 1387 u16 devstat;
1392 1388
1393 if (!udc->gadget.is_otg) 1389 if (!gadget_is_otg(udc->gadget))
1394 return; 1390 return;
1395 1391
1396 if (OTG_CTRL_REG & OTG_ID) 1392 if (OTG_CTRL_REG & OTG_ID)
diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
index ec9732e7fea2..5ea611e48ec1 100644
--- a/include/linux/usb_gadget.h
+++ b/include/linux/usb_gadget.h
@@ -480,6 +480,39 @@ static inline void *get_gadget_data (struct usb_gadget *gadget)
480 480
481 481
482/** 482/**
483 * gadget_is_dualspeed - return true iff the hardware handles high speed
484 * @gadget: controller that might support both high and full speeds
485 */
486static inline int gadget_is_dualspeed(struct usb_gadget *g)
487{
488#ifdef CONFIG_USB_GADGET_DUALSPEED
489 /* runtime test would check "g->is_dualspeed" ... that might be
490 * useful to work around hardware bugs, but is mostly pointless
491 */
492 return 1;
493#else
494 return 0;
495#endif
496}
497
498/**
499 * gadget_is_otg - return true iff the hardware is OTG-ready
500 * @gadget: controller that might have a Mini-AB connector
501 *
502 * This is a runtime test, since kernels with a USB-OTG stack sometimes
503 * run on boards which only have a Mini-B (or Mini-A) connector.
504 */
505static inline int gadget_is_otg(struct usb_gadget *g)
506{
507#ifdef CONFIG_USB_OTG
508 return g->is_otg;
509#else
510 return 0;
511#endif
512}
513
514
515/**
483 * usb_gadget_frame_number - returns the current frame number 516 * usb_gadget_frame_number - returns the current frame number
484 * @gadget: controller that reports the frame number 517 * @gadget: controller that reports the frame number
485 * 518 *