aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-11 16:39:31 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-11 16:39:49 -0400
commit7135f08e47de094f8748507806efa8d7ba27a964 (patch)
tree4e0bd28908a35cb3ce3b44a87402641c959775c7 /include/linux/usb
parent73d4066055e0e2830533041f4b91df8e6e5976ff (diff)
parent5c4d46eb89fe99011a02048533857345d9e8b506 (diff)
Merge tag 'gadget-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
usb: gadget: patches for v3.7 merge window This pull request is large but the biggest part is the first part of the cleanup on the gadget framework so we have a saner setup to add configfs support for v3.8. We have also some more conversions to the new udc_start/udc_stop which makes us closer from dropping the old interfaces. USB_GADGET_DUALSPEED and USB_GADGET_SUPERSPEED are finally gone, thanks to Michal for his awesome work. Other than that, we have the usual set of miscellaneous changes and cleanups involving improvements to debug messages, removal of duplicated includes, moving dereference after NULL test, making renesas_hsbhs' irq handler Shared, unused code being dropped, prevention of sleep-inside-spinlock bugs and a race condition fix on udc-core.
Diffstat (limited to 'include/linux/usb')
-rw-r--r--include/linux/usb/composite.h97
-rw-r--r--include/linux/usb/gadget.h33
2 files changed, 87 insertions, 43 deletions
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 9d8c3b634493..f8dda0621800 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -34,6 +34,8 @@
34 * the composite model the host can use both functions at the same time. 34 * the composite model the host can use both functions at the same time.
35 */ 35 */
36 36
37#include <linux/bcd.h>
38#include <linux/version.h>
37#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
38#include <linux/usb/gadget.h> 40#include <linux/usb/gadget.h>
39 41
@@ -46,6 +48,9 @@
46 */ 48 */
47#define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */ 49#define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */
48 50
51/* big enough to hold our biggest descriptor */
52#define USB_COMP_EP0_BUFSIZ 1024
53
49struct usb_configuration; 54struct usb_configuration;
50 55
51/** 56/**
@@ -245,24 +250,31 @@ int usb_add_config(struct usb_composite_dev *,
245void usb_remove_config(struct usb_composite_dev *, 250void usb_remove_config(struct usb_composite_dev *,
246 struct usb_configuration *); 251 struct usb_configuration *);
247 252
253/* predefined index for usb_composite_driver */
254enum {
255 USB_GADGET_MANUFACTURER_IDX = 0,
256 USB_GADGET_PRODUCT_IDX,
257 USB_GADGET_SERIAL_IDX,
258 USB_GADGET_FIRST_AVAIL_IDX,
259};
260
248/** 261/**
249 * struct usb_composite_driver - groups configurations into a gadget 262 * struct usb_composite_driver - groups configurations into a gadget
250 * @name: For diagnostics, identifies the driver. 263 * @name: For diagnostics, identifies the driver.
251 * @iProduct: Used as iProduct override if @dev->iProduct is not set.
252 * If NULL value of @name is taken.
253 * @iManufacturer: Used as iManufacturer override if @dev->iManufacturer is
254 * not set. If NULL a default "<system> <release> with <udc>" value
255 * will be used.
256 * @iSerialNumber: Used as iSerialNumber override if @dev->iSerialNumber is
257 * not set.
258 * @dev: Template descriptor for the device, including default device 264 * @dev: Template descriptor for the device, including default device
259 * identifiers. 265 * identifiers.
260 * @strings: tables of strings, keyed by identifiers assigned during bind() 266 * @strings: tables of strings, keyed by identifiers assigned during @bind
261 * and language IDs provided in control requests 267 * and language IDs provided in control requests. Note: The first entries
268 * are predefined. The first entry that may be used is
269 * USB_GADGET_FIRST_AVAIL_IDX
262 * @max_speed: Highest speed the driver supports. 270 * @max_speed: Highest speed the driver supports.
263 * @needs_serial: set to 1 if the gadget needs userspace to provide 271 * @needs_serial: set to 1 if the gadget needs userspace to provide
264 * a serial number. If one is not provided, warning will be printed. 272 * a serial number. If one is not provided, warning will be printed.
265 * @unbind: Reverses bind; called as a side effect of unregistering 273 * @bind: (REQUIRED) Used to allocate resources that are shared across the
274 * whole device, such as string IDs, and add its configurations using
275 * @usb_add_config(). This may fail by returning a negative errno
276 * value; it should return zero on successful initialization.
277 * @unbind: Reverses @bind; called as a side effect of unregistering
266 * this driver. 278 * this driver.
267 * @disconnect: optional driver disconnect method 279 * @disconnect: optional driver disconnect method
268 * @suspend: Notifies when the host stops sending USB traffic, 280 * @suspend: Notifies when the host stops sending USB traffic,
@@ -271,9 +283,9 @@ void usb_remove_config(struct usb_composite_dev *,
271 * before function notifications 283 * before function notifications
272 * 284 *
273 * Devices default to reporting self powered operation. Devices which rely 285 * Devices default to reporting self powered operation. Devices which rely
274 * on bus powered operation should report this in their @bind() method. 286 * on bus powered operation should report this in their @bind method.
275 * 287 *
276 * Before returning from bind, various fields in the template descriptor 288 * Before returning from @bind, various fields in the template descriptor
277 * may be overridden. These include the idVendor/idProduct/bcdDevice values 289 * may be overridden. These include the idVendor/idProduct/bcdDevice values
278 * normally to bind the appropriate host side driver, and the three strings 290 * normally to bind the appropriate host side driver, and the three strings
279 * (iManufacturer, iProduct, iSerialNumber) normally used to provide user 291 * (iManufacturer, iProduct, iSerialNumber) normally used to provide user
@@ -283,14 +295,12 @@ void usb_remove_config(struct usb_composite_dev *,
283 */ 295 */
284struct usb_composite_driver { 296struct usb_composite_driver {
285 const char *name; 297 const char *name;
286 const char *iProduct;
287 const char *iManufacturer;
288 const char *iSerialNumber;
289 const struct usb_device_descriptor *dev; 298 const struct usb_device_descriptor *dev;
290 struct usb_gadget_strings **strings; 299 struct usb_gadget_strings **strings;
291 enum usb_device_speed max_speed; 300 enum usb_device_speed max_speed;
292 unsigned needs_serial:1; 301 unsigned needs_serial:1;
293 302
303 int (*bind)(struct usb_composite_dev *cdev);
294 int (*unbind)(struct usb_composite_dev *); 304 int (*unbind)(struct usb_composite_dev *);
295 305
296 void (*disconnect)(struct usb_composite_dev *); 306 void (*disconnect)(struct usb_composite_dev *);
@@ -298,10 +308,10 @@ struct usb_composite_driver {
298 /* global suspend hooks */ 308 /* global suspend hooks */
299 void (*suspend)(struct usb_composite_dev *); 309 void (*suspend)(struct usb_composite_dev *);
300 void (*resume)(struct usb_composite_dev *); 310 void (*resume)(struct usb_composite_dev *);
311 struct usb_gadget_driver gadget_driver;
301}; 312};
302 313
303extern int usb_composite_probe(struct usb_composite_driver *driver, 314extern int usb_composite_probe(struct usb_composite_driver *driver);
304 int (*bind)(struct usb_composite_dev *cdev));
305extern void usb_composite_unregister(struct usb_composite_driver *driver); 315extern void usb_composite_unregister(struct usb_composite_driver *driver);
306extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); 316extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
307 317
@@ -310,7 +320,6 @@ extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
310 * struct usb_composite_device - represents one composite usb gadget 320 * struct usb_composite_device - represents one composite usb gadget
311 * @gadget: read-only, abstracts the gadget's usb peripheral controller 321 * @gadget: read-only, abstracts the gadget's usb peripheral controller
312 * @req: used for control responses; buffer is pre-allocated 322 * @req: used for control responses; buffer is pre-allocated
313 * @bufsiz: size of buffer pre-allocated in @req
314 * @config: the currently active configuration 323 * @config: the currently active configuration
315 * 324 *
316 * One of these devices is allocated and initialized before the 325 * One of these devices is allocated and initialized before the
@@ -341,7 +350,6 @@ extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
341struct usb_composite_dev { 350struct usb_composite_dev {
342 struct usb_gadget *gadget; 351 struct usb_gadget *gadget;
343 struct usb_request *req; 352 struct usb_request *req;
344 unsigned bufsiz;
345 353
346 struct usb_configuration *config; 354 struct usb_configuration *config;
347 355
@@ -352,9 +360,7 @@ struct usb_composite_dev {
352 struct list_head configs; 360 struct list_head configs;
353 struct usb_composite_driver *driver; 361 struct usb_composite_driver *driver;
354 u8 next_string_id; 362 u8 next_string_id;
355 u8 manufacturer_override; 363 char *def_manufacturer;
356 u8 product_override;
357 u8 serial_override;
358 364
359 /* the gadget driver won't enable the data pullup 365 /* the gadget driver won't enable the data pullup
360 * while the deactivation count is nonzero. 366 * while the deactivation count is nonzero.
@@ -375,6 +381,53 @@ extern int usb_string_ids_tab(struct usb_composite_dev *c,
375 struct usb_string *str); 381 struct usb_string *str);
376extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 382extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
377 383
384/*
385 * Some systems will need runtime overrides for the product identifiers
386 * published in the device descriptor, either numbers or strings or both.
387 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
388 */
389struct usb_composite_overwrite {
390 u16 idVendor;
391 u16 idProduct;
392 u16 bcdDevice;
393 char *serial_number;
394 char *manufacturer;
395 char *product;
396};
397#define USB_GADGET_COMPOSITE_OPTIONS() \
398 static struct usb_composite_overwrite coverwrite; \
399 \
400 module_param_named(idVendor, coverwrite.idVendor, ushort, S_IRUGO); \
401 MODULE_PARM_DESC(idVendor, "USB Vendor ID"); \
402 \
403 module_param_named(idProduct, coverwrite.idProduct, ushort, S_IRUGO); \
404 MODULE_PARM_DESC(idProduct, "USB Product ID"); \
405 \
406 module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \
407 MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); \
408 \
409 module_param_named(iSerialNumber, coverwrite.serial_number, charp, \
410 S_IRUGO); \
411 MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); \
412 \
413 module_param_named(iManufacturer, coverwrite.manufacturer, charp, \
414 S_IRUGO); \
415 MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); \
416 \
417 module_param_named(iProduct, coverwrite.product, charp, S_IRUGO); \
418 MODULE_PARM_DESC(iProduct, "USB Product string")
419
420void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
421 struct usb_composite_overwrite *covr);
422
423static inline u16 get_default_bcdDevice(void)
424{
425 u16 bcdDevice;
426
427 bcdDevice = bin2bcd((LINUX_VERSION_CODE >> 16 & 0xff)) << 8;
428 bcdDevice |= bin2bcd((LINUX_VERSION_CODE >> 8 & 0xff));
429 return bcdDevice;
430}
378 431
379/* messaging utils */ 432/* messaging utils */
380#define DBG(d, fmt, args...) \ 433#define DBG(d, fmt, args...) \
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 9517466ababb..5b6e50888248 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -474,7 +474,8 @@ struct usb_gadget_ops {
474 474
475 /* Those two are deprecated */ 475 /* Those two are deprecated */
476 int (*start)(struct usb_gadget_driver *, 476 int (*start)(struct usb_gadget_driver *,
477 int (*bind)(struct usb_gadget *)); 477 int (*bind)(struct usb_gadget *,
478 struct usb_gadget_driver *driver));
478 int (*stop)(struct usb_gadget_driver *); 479 int (*stop)(struct usb_gadget_driver *);
479}; 480};
480 481
@@ -502,6 +503,8 @@ struct usb_gadget_ops {
502 * @name: Identifies the controller hardware type. Used in diagnostics 503 * @name: Identifies the controller hardware type. Used in diagnostics
503 * and sometimes configuration. 504 * and sometimes configuration.
504 * @dev: Driver model state for this abstract device. 505 * @dev: Driver model state for this abstract device.
506 * @out_epnum: last used out ep number
507 * @in_epnum: last used in ep number
505 * 508 *
506 * Gadgets have a mostly-portable "gadget driver" implementing device 509 * Gadgets have a mostly-portable "gadget driver" implementing device
507 * functions, handling all usb configurations and interfaces. Gadget 510 * functions, handling all usb configurations and interfaces. Gadget
@@ -536,6 +539,8 @@ struct usb_gadget {
536 unsigned a_alt_hnp_support:1; 539 unsigned a_alt_hnp_support:1;
537 const char *name; 540 const char *name;
538 struct device dev; 541 struct device dev;
542 unsigned out_epnum;
543 unsigned in_epnum;
539}; 544};
540 545
541static inline void set_gadget_data(struct usb_gadget *gadget, void *data) 546static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
@@ -558,14 +563,7 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
558 */ 563 */
559static inline int gadget_is_dualspeed(struct usb_gadget *g) 564static inline int gadget_is_dualspeed(struct usb_gadget *g)
560{ 565{
561#ifdef CONFIG_USB_GADGET_DUALSPEED 566 return g->max_speed >= USB_SPEED_HIGH;
562 /* runtime test would check "g->max_speed" ... that might be
563 * useful to work around hardware bugs, but is mostly pointless
564 */
565 return 1;
566#else
567 return 0;
568#endif
569} 567}
570 568
571/** 569/**
@@ -575,15 +573,7 @@ static inline int gadget_is_dualspeed(struct usb_gadget *g)
575 */ 573 */
576static inline int gadget_is_superspeed(struct usb_gadget *g) 574static inline int gadget_is_superspeed(struct usb_gadget *g)
577{ 575{
578#ifdef CONFIG_USB_GADGET_SUPERSPEED 576 return g->max_speed >= USB_SPEED_SUPER;
579 /*
580 * runtime test would check "g->max_speed" ... that might be
581 * useful to work around hardware bugs, but is mostly pointless
582 */
583 return 1;
584#else
585 return 0;
586#endif
587} 577}
588 578
589/** 579/**
@@ -781,6 +771,7 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
781 * when the host is disconnected. May be called in_interrupt; this 771 * when the host is disconnected. May be called in_interrupt; this
782 * may not sleep. Some devices can't detect disconnect, so this might 772 * may not sleep. Some devices can't detect disconnect, so this might
783 * not be called except as part of controller shutdown. 773 * not be called except as part of controller shutdown.
774 * @bind: the driver's bind callback
784 * @unbind: Invoked when the driver is unbound from a gadget, 775 * @unbind: Invoked when the driver is unbound from a gadget,
785 * usually from rmmod (after a disconnect is reported). 776 * usually from rmmod (after a disconnect is reported).
786 * Called in a context that permits sleeping. 777 * Called in a context that permits sleeping.
@@ -835,6 +826,8 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
835struct usb_gadget_driver { 826struct usb_gadget_driver {
836 char *function; 827 char *function;
837 enum usb_device_speed max_speed; 828 enum usb_device_speed max_speed;
829 int (*bind)(struct usb_gadget *gadget,
830 struct usb_gadget_driver *driver);
838 void (*unbind)(struct usb_gadget *); 831 void (*unbind)(struct usb_gadget *);
839 int (*setup)(struct usb_gadget *, 832 int (*setup)(struct usb_gadget *,
840 const struct usb_ctrlrequest *); 833 const struct usb_ctrlrequest *);
@@ -860,7 +853,6 @@ struct usb_gadget_driver {
860/** 853/**
861 * usb_gadget_probe_driver - probe a gadget driver 854 * usb_gadget_probe_driver - probe a gadget driver
862 * @driver: the driver being registered 855 * @driver: the driver being registered
863 * @bind: the driver's bind callback
864 * Context: can sleep 856 * Context: can sleep
865 * 857 *
866 * Call this in your gadget driver's module initialization function, 858 * Call this in your gadget driver's module initialization function,
@@ -869,8 +861,7 @@ struct usb_gadget_driver {
869 * registration call returns. It's expected that the @bind() function will 861 * registration call returns. It's expected that the @bind() function will
870 * be in init sections. 862 * be in init sections.
871 */ 863 */
872int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 864int usb_gadget_probe_driver(struct usb_gadget_driver *driver);
873 int (*bind)(struct usb_gadget *));
874 865
875/** 866/**
876 * usb_gadget_unregister_driver - unregister a gadget driver 867 * usb_gadget_unregister_driver - unregister a gadget driver