From a4e3ef5597e26dad006544d38b9ab6ff42382b76 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Wed, 1 Aug 2007 23:58:22 -0700 Subject: 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 Signed-off-by: Greg Kroah-Hartman --- include/linux/usb_gadget.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include') 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 @@ -479,6 +479,39 @@ static inline void *get_gadget_data (struct usb_gadget *gadget) list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) +/** + * gadget_is_dualspeed - return true iff the hardware handles high speed + * @gadget: controller that might support both high and full speeds + */ +static inline int gadget_is_dualspeed(struct usb_gadget *g) +{ +#ifdef CONFIG_USB_GADGET_DUALSPEED + /* runtime test would check "g->is_dualspeed" ... that might be + * useful to work around hardware bugs, but is mostly pointless + */ + return 1; +#else + return 0; +#endif +} + +/** + * gadget_is_otg - return true iff the hardware is OTG-ready + * @gadget: controller that might have a Mini-AB connector + * + * This is a runtime test, since kernels with a USB-OTG stack sometimes + * run on boards which only have a Mini-B (or Mini-A) connector. + */ +static inline int gadget_is_otg(struct usb_gadget *g) +{ +#ifdef CONFIG_USB_OTG + return g->is_otg; +#else + return 0; +#endif +} + + /** * usb_gadget_frame_number - returns the current frame number * @gadget: controller that reports the frame number -- cgit v1.2.3