![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0+ 0002 /* 0003 * composite.h -- framework for usb gadgets which are composite devices 0004 * 0005 * Copyright (C) 2006-2008 David Brownell 0006 */ 0007 0008 #ifndef __LINUX_USB_COMPOSITE_H 0009 #define __LINUX_USB_COMPOSITE_H 0010 0011 /* 0012 * This framework is an optional layer on top of the USB Gadget interface, 0013 * making it easier to build (a) Composite devices, supporting multiple 0014 * functions within any single configuration, and (b) Multi-configuration 0015 * devices, also supporting multiple functions but without necessarily 0016 * having more than one function per configuration. 0017 * 0018 * Example: a device with a single configuration supporting both network 0019 * link and mass storage functions is a composite device. Those functions 0020 * might alternatively be packaged in individual configurations, but in 0021 * the composite model the host can use both functions at the same time. 0022 */ 0023 0024 #include <linux/bcd.h> 0025 #include <linux/version.h> 0026 #include <linux/usb/ch9.h> 0027 #include <linux/usb/gadget.h> 0028 #include <linux/log2.h> 0029 #include <linux/configfs.h> 0030 0031 /* 0032 * USB function drivers should return USB_GADGET_DELAYED_STATUS if they 0033 * wish to delay the data/status stages of the control transfer till they 0034 * are ready. The control transfer will then be kept from completing till 0035 * all the function drivers that requested for USB_GADGET_DELAYED_STAUS 0036 * invoke usb_composite_setup_continue(). 0037 */ 0038 #define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */ 0039 0040 /* big enough to hold our biggest descriptor */ 0041 #define USB_COMP_EP0_BUFSIZ 4096 0042 0043 /* OS feature descriptor length <= 4kB */ 0044 #define USB_COMP_EP0_OS_DESC_BUFSIZ 4096 0045 0046 #define USB_MS_TO_HS_INTERVAL(x) (ilog2((x * 1000 / 125)) + 1) 0047 struct usb_configuration; 0048 0049 /** 0050 * struct usb_os_desc_ext_prop - describes one "Extended Property" 0051 * @entry: used to keep a list of extended properties 0052 * @type: Extended Property type 0053 * @name_len: Extended Property unicode name length, including terminating '\0' 0054 * @name: Extended Property name 0055 * @data_len: Length of Extended Property blob (for unicode store double len) 0056 * @data: Extended Property blob 0057 * @item: Represents this Extended Property in configfs 0058 */ 0059 struct usb_os_desc_ext_prop { 0060 struct list_head entry; 0061 u8 type; 0062 int name_len; 0063 char *name; 0064 int data_len; 0065 char *data; 0066 struct config_item item; 0067 }; 0068 0069 /** 0070 * struct usb_os_desc - describes OS descriptors associated with one interface 0071 * @ext_compat_id: 16 bytes of "Compatible ID" and "Subcompatible ID" 0072 * @ext_prop: Extended Properties list 0073 * @ext_prop_len: Total length of Extended Properties blobs 0074 * @ext_prop_count: Number of Extended Properties 0075 * @opts_mutex: Optional mutex protecting config data of a usb_function_instance 0076 * @group: Represents OS descriptors associated with an interface in configfs 0077 * @owner: Module associated with this OS descriptor 0078 */ 0079 struct usb_os_desc { 0080 char *ext_compat_id; 0081 struct list_head ext_prop; 0082 int ext_prop_len; 0083 int ext_prop_count; 0084 struct mutex *opts_mutex; 0085 struct config_group group; 0086 struct module *owner; 0087 }; 0088 0089 /** 0090 * struct usb_os_desc_table - describes OS descriptors associated with one 0091 * interface of a usb_function 0092 * @if_id: Interface id 0093 * @os_desc: "Extended Compatibility ID" and "Extended Properties" of the 0094 * interface 0095 * 0096 * Each interface can have at most one "Extended Compatibility ID" and a 0097 * number of "Extended Properties". 0098 */ 0099 struct usb_os_desc_table { 0100 int if_id; 0101 struct usb_os_desc *os_desc; 0102 }; 0103 0104 /** 0105 * struct usb_function - describes one function of a configuration 0106 * @name: For diagnostics, identifies the function. 0107 * @strings: tables of strings, keyed by identifiers assigned during bind() 0108 * and by language IDs provided in control requests 0109 * @fs_descriptors: Table of full (or low) speed descriptors, using interface and 0110 * string identifiers assigned during @bind(). If this pointer is null, 0111 * the function will not be available at full speed (or at low speed). 0112 * @hs_descriptors: Table of high speed descriptors, using interface and 0113 * string identifiers assigned during @bind(). If this pointer is null, 0114 * the function will not be available at high speed. 0115 * @ss_descriptors: Table of super speed descriptors, using interface and 0116 * string identifiers assigned during @bind(). If this 0117 * pointer is null after initiation, the function will not 0118 * be available at super speed. 0119 * @ssp_descriptors: Table of super speed plus descriptors, using 0120 * interface and string identifiers assigned during @bind(). If 0121 * this pointer is null after initiation, the function will not 0122 * be available at super speed plus. 0123 * @config: assigned when @usb_add_function() is called; this is the 0124 * configuration with which this function is associated. 0125 * @os_desc_table: Table of (interface id, os descriptors) pairs. The function 0126 * can expose more than one interface. If an interface is a member of 0127 * an IAD, only the first interface of IAD has its entry in the table. 0128 * @os_desc_n: Number of entries in os_desc_table 0129 * @bind: Before the gadget can register, all of its functions bind() to the 0130 * available resources including string and interface identifiers used 0131 * in interface or class descriptors; endpoints; I/O buffers; and so on. 0132 * @unbind: Reverses @bind; called as a side effect of unregistering the 0133 * driver which added this function. 0134 * @free_func: free the struct usb_function. 0135 * @mod: (internal) points to the module that created this structure. 0136 * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may 0137 * initialize usb_ep.driver data at this time (when it is used). 0138 * Note that setting an interface to its current altsetting resets 0139 * interface state, and that all interfaces have a disabled state. 0140 * @get_alt: Returns the active altsetting. If this is not provided, 0141 * then only altsetting zero is supported. 0142 * @disable: (REQUIRED) Indicates the function should be disabled. Reasons 0143 * include host resetting or reconfiguring the gadget, and disconnection. 0144 * @setup: Used for interface-specific control requests. 0145 * @req_match: Tests if a given class request can be handled by this function. 0146 * @suspend: Notifies functions when the host stops sending USB traffic. 0147 * @resume: Notifies functions when the host restarts USB traffic. 0148 * @get_status: Returns function status as a reply to 0149 * GetStatus() request when the recipient is Interface. 0150 * @func_suspend: callback to be called when 0151 * SetFeature(FUNCTION_SUSPEND) is reseived 0152 * 0153 * A single USB function uses one or more interfaces, and should in most 0154 * cases support operation at both full and high speeds. Each function is 0155 * associated by @usb_add_function() with a one configuration; that function 0156 * causes @bind() to be called so resources can be allocated as part of 0157 * setting up a gadget driver. Those resources include endpoints, which 0158 * should be allocated using @usb_ep_autoconfig(). 0159 * 0160 * To support dual speed operation, a function driver provides descriptors 0161 * for both high and full speed operation. Except in rare cases that don't 0162 * involve bulk endpoints, each speed needs different endpoint descriptors. 0163 * 0164 * Function drivers choose their own strategies for managing instance data. 0165 * The simplest strategy just declares it "static', which means the function 0166 * can only be activated once. If the function needs to be exposed in more 0167 * than one configuration at a given speed, it needs to support multiple 0168 * usb_function structures (one for each configuration). 0169 * 0170 * A more complex strategy might encapsulate a @usb_function structure inside 0171 * a driver-specific instance structure to allows multiple activations. An 0172 * example of multiple activations might be a CDC ACM function that supports 0173 * two or more distinct instances within the same configuration, providing 0174 * several independent logical data links to a USB host. 0175 */ 0176 0177 struct usb_function { 0178 const char *name; 0179 struct usb_gadget_strings **strings; 0180 struct usb_descriptor_header **fs_descriptors; 0181 struct usb_descriptor_header **hs_descriptors; 0182 struct usb_descriptor_header **ss_descriptors; 0183 struct usb_descriptor_header **ssp_descriptors; 0184 0185 struct usb_configuration *config; 0186 0187 struct usb_os_desc_table *os_desc_table; 0188 unsigned os_desc_n; 0189 0190 /* REVISIT: bind() functions can be marked __init, which 0191 * makes trouble for section mismatch analysis. See if 0192 * we can't restructure things to avoid mismatching. 0193 * Related: unbind() may kfree() but bind() won't... 0194 */ 0195 0196 /* configuration management: bind/unbind */ 0197 int (*bind)(struct usb_configuration *, 0198 struct usb_function *); 0199 void (*unbind)(struct usb_configuration *, 0200 struct usb_function *); 0201 void (*free_func)(struct usb_function *f); 0202 struct module *mod; 0203 0204 /* runtime state management */ 0205 int (*set_alt)(struct usb_function *, 0206 unsigned interface, unsigned alt); 0207 int (*get_alt)(struct usb_function *, 0208 unsigned interface); 0209 void (*disable)(struct usb_function *); 0210 int (*setup)(struct usb_function *, 0211 const struct usb_ctrlrequest *); 0212 bool (*req_match)(struct usb_function *, 0213 const struct usb_ctrlrequest *, 0214 bool config0); 0215 void (*suspend)(struct usb_function *); 0216 void (*resume)(struct usb_function *); 0217 0218 /* USB 3.0 additions */ 0219 int (*get_status)(struct usb_function *); 0220 int (*func_suspend)(struct usb_function *, 0221 u8 suspend_opt); 0222 /* private: */ 0223 /* internals */ 0224 struct list_head list; 0225 DECLARE_BITMAP(endpoints, 32); 0226 const struct usb_function_instance *fi; 0227 0228 unsigned int bind_deactivated:1; 0229 }; 0230 0231 int usb_add_function(struct usb_configuration *, struct usb_function *); 0232 0233 int usb_function_deactivate(struct usb_function *); 0234 int usb_function_activate(struct usb_function *); 0235 0236 int usb_interface_id(struct usb_configuration *, struct usb_function *); 0237 0238 int config_ep_by_speed_and_alt(struct usb_gadget *g, struct usb_function *f, 0239 struct usb_ep *_ep, u8 alt); 0240 0241 int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, 0242 struct usb_ep *_ep); 0243 0244 #define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */ 0245 0246 /** 0247 * struct usb_configuration - represents one gadget configuration 0248 * @label: For diagnostics, describes the configuration. 0249 * @strings: Tables of strings, keyed by identifiers assigned during @bind() 0250 * and by language IDs provided in control requests. 0251 * @descriptors: Table of descriptors preceding all function descriptors. 0252 * Examples include OTG and vendor-specific descriptors. 0253 * @unbind: Reverses @bind; called as a side effect of unregistering the 0254 * driver which added this configuration. 0255 * @setup: Used to delegate control requests that aren't handled by standard 0256 * device infrastructure or directed at a specific interface. 0257 * @bConfigurationValue: Copied into configuration descriptor. 0258 * @iConfiguration: Copied into configuration descriptor. 0259 * @bmAttributes: Copied into configuration descriptor. 0260 * @MaxPower: Power consumption in mA. Used to compute bMaxPower in the 0261 * configuration descriptor after considering the bus speed. 0262 * @cdev: assigned by @usb_add_config() before calling @bind(); this is 0263 * the device associated with this configuration. 0264 * 0265 * Configurations are building blocks for gadget drivers structured around 0266 * function drivers. Simple USB gadgets require only one function and one 0267 * configuration, and handle dual-speed hardware by always providing the same 0268 * functionality. Slightly more complex gadgets may have more than one 0269 * single-function configuration at a given speed; or have configurations 0270 * that only work at one speed. 0271 * 0272 * Composite devices are, by definition, ones with configurations which 0273 * include more than one function. 0274 * 0275 * The lifecycle of a usb_configuration includes allocation, initialization 0276 * of the fields described above, and calling @usb_add_config() to set up 0277 * internal data and bind it to a specific device. The configuration's 0278 * @bind() method is then used to initialize all the functions and then 0279 * call @usb_add_function() for them. 0280 * 0281 * Those functions would normally be independent of each other, but that's 0282 * not mandatory. CDC WMC devices are an example where functions often 0283 * depend on other functions, with some functions subsidiary to others. 0284 * Such interdependency may be managed in any way, so long as all of the 0285 * descriptors complete by the time the composite driver returns from 0286 * its bind() routine. 0287 */ 0288 struct usb_configuration { 0289 const char *label; 0290 struct usb_gadget_strings **strings; 0291 const struct usb_descriptor_header **descriptors; 0292 0293 /* REVISIT: bind() functions can be marked __init, which 0294 * makes trouble for section mismatch analysis. See if 0295 * we can't restructure things to avoid mismatching... 0296 */ 0297 0298 /* configuration management: unbind/setup */ 0299 void (*unbind)(struct usb_configuration *); 0300 int (*setup)(struct usb_configuration *, 0301 const struct usb_ctrlrequest *); 0302 0303 /* fields in the config descriptor */ 0304 u8 bConfigurationValue; 0305 u8 iConfiguration; 0306 u8 bmAttributes; 0307 u16 MaxPower; 0308 0309 struct usb_composite_dev *cdev; 0310 0311 /* private: */ 0312 /* internals */ 0313 struct list_head list; 0314 struct list_head functions; 0315 u8 next_interface_id; 0316 unsigned superspeed:1; 0317 unsigned highspeed:1; 0318 unsigned fullspeed:1; 0319 unsigned superspeed_plus:1; 0320 struct usb_function *interface[MAX_CONFIG_INTERFACES]; 0321 }; 0322 0323 int usb_add_config(struct usb_composite_dev *, 0324 struct usb_configuration *, 0325 int (*)(struct usb_configuration *)); 0326 0327 void usb_remove_config(struct usb_composite_dev *, 0328 struct usb_configuration *); 0329 0330 /* predefined index for usb_composite_driver */ 0331 enum { 0332 USB_GADGET_MANUFACTURER_IDX = 0, 0333 USB_GADGET_PRODUCT_IDX, 0334 USB_GADGET_SERIAL_IDX, 0335 USB_GADGET_FIRST_AVAIL_IDX, 0336 }; 0337 0338 /** 0339 * struct usb_composite_driver - groups configurations into a gadget 0340 * @name: For diagnostics, identifies the driver. 0341 * @dev: Template descriptor for the device, including default device 0342 * identifiers. 0343 * @strings: tables of strings, keyed by identifiers assigned during @bind 0344 * and language IDs provided in control requests. Note: The first entries 0345 * are predefined. The first entry that may be used is 0346 * USB_GADGET_FIRST_AVAIL_IDX 0347 * @max_speed: Highest speed the driver supports. 0348 * @needs_serial: set to 1 if the gadget needs userspace to provide 0349 * a serial number. If one is not provided, warning will be printed. 0350 * @bind: (REQUIRED) Used to allocate resources that are shared across the 0351 * whole device, such as string IDs, and add its configurations using 0352 * @usb_add_config(). This may fail by returning a negative errno 0353 * value; it should return zero on successful initialization. 0354 * @unbind: Reverses @bind; called as a side effect of unregistering 0355 * this driver. 0356 * @disconnect: optional driver disconnect method 0357 * @suspend: Notifies when the host stops sending USB traffic, 0358 * after function notifications 0359 * @resume: Notifies configuration when the host restarts USB traffic, 0360 * before function notifications 0361 * @gadget_driver: Gadget driver controlling this driver 0362 * 0363 * Devices default to reporting self powered operation. Devices which rely 0364 * on bus powered operation should report this in their @bind method. 0365 * 0366 * Before returning from @bind, various fields in the template descriptor 0367 * may be overridden. These include the idVendor/idProduct/bcdDevice values 0368 * normally to bind the appropriate host side driver, and the three strings 0369 * (iManufacturer, iProduct, iSerialNumber) normally used to provide user 0370 * meaningful device identifiers. (The strings will not be defined unless 0371 * they are defined in @dev and @strings.) The correct ep0 maxpacket size 0372 * is also reported, as defined by the underlying controller driver. 0373 */ 0374 struct usb_composite_driver { 0375 const char *name; 0376 const struct usb_device_descriptor *dev; 0377 struct usb_gadget_strings **strings; 0378 enum usb_device_speed max_speed; 0379 unsigned needs_serial:1; 0380 0381 int (*bind)(struct usb_composite_dev *cdev); 0382 int (*unbind)(struct usb_composite_dev *); 0383 0384 void (*disconnect)(struct usb_composite_dev *); 0385 0386 /* global suspend hooks */ 0387 void (*suspend)(struct usb_composite_dev *); 0388 void (*resume)(struct usb_composite_dev *); 0389 struct usb_gadget_driver gadget_driver; 0390 }; 0391 0392 extern int usb_composite_probe(struct usb_composite_driver *driver); 0393 extern void usb_composite_unregister(struct usb_composite_driver *driver); 0394 0395 /** 0396 * module_usb_composite_driver() - Helper macro for registering a USB gadget 0397 * composite driver 0398 * @__usb_composite_driver: usb_composite_driver struct 0399 * 0400 * Helper macro for USB gadget composite drivers which do not do anything 0401 * special in module init/exit. This eliminates a lot of boilerplate. Each 0402 * module may only use this macro once, and calling it replaces module_init() 0403 * and module_exit() 0404 */ 0405 #define module_usb_composite_driver(__usb_composite_driver) \ 0406 module_driver(__usb_composite_driver, usb_composite_probe, \ 0407 usb_composite_unregister) 0408 0409 extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); 0410 extern int composite_dev_prepare(struct usb_composite_driver *composite, 0411 struct usb_composite_dev *cdev); 0412 extern int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, 0413 struct usb_ep *ep0); 0414 void composite_dev_cleanup(struct usb_composite_dev *cdev); 0415 0416 static inline struct usb_composite_driver *to_cdriver( 0417 struct usb_gadget_driver *gdrv) 0418 { 0419 return container_of(gdrv, struct usb_composite_driver, gadget_driver); 0420 } 0421 0422 #define OS_STRING_QW_SIGN_LEN 14 0423 #define OS_STRING_IDX 0xEE 0424 0425 /** 0426 * struct usb_composite_dev - represents one composite usb gadget 0427 * @gadget: read-only, abstracts the gadget's usb peripheral controller 0428 * @req: used for control responses; buffer is pre-allocated 0429 * @os_desc_req: used for OS descriptors responses; buffer is pre-allocated 0430 * @config: the currently active configuration 0431 * @qw_sign: qwSignature part of the OS string 0432 * @b_vendor_code: bMS_VendorCode part of the OS string 0433 * @use_os_string: false by default, interested gadgets set it 0434 * @os_desc_config: the configuration to be used with OS descriptors 0435 * @setup_pending: true when setup request is queued but not completed 0436 * @os_desc_pending: true when os_desc request is queued but not completed 0437 * 0438 * One of these devices is allocated and initialized before the 0439 * associated device driver's bind() is called. 0440 * 0441 * OPEN ISSUE: it appears that some WUSB devices will need to be 0442 * built by combining a normal (wired) gadget with a wireless one. 0443 * This revision of the gadget framework should probably try to make 0444 * sure doing that won't hurt too much. 0445 * 0446 * One notion for how to handle Wireless USB devices involves: 0447 * 0448 * (a) a second gadget here, discovery mechanism TBD, but likely 0449 * needing separate "register/unregister WUSB gadget" calls; 0450 * (b) updates to usb_gadget to include flags "is it wireless", 0451 * "is it wired", plus (presumably in a wrapper structure) 0452 * bandgroup and PHY info; 0453 * (c) presumably a wireless_ep wrapping a usb_ep, and reporting 0454 * wireless-specific parameters like maxburst and maxsequence; 0455 * (d) configurations that are specific to wireless links; 0456 * (e) function drivers that understand wireless configs and will 0457 * support wireless for (additional) function instances; 0458 * (f) a function to support association setup (like CBAF), not 0459 * necessarily requiring a wireless adapter; 0460 * (g) composite device setup that can create one or more wireless 0461 * configs, including appropriate association setup support; 0462 * (h) more, TBD. 0463 */ 0464 struct usb_composite_dev { 0465 struct usb_gadget *gadget; 0466 struct usb_request *req; 0467 struct usb_request *os_desc_req; 0468 0469 struct usb_configuration *config; 0470 0471 /* OS String is a custom (yet popular) extension to the USB standard. */ 0472 u8 qw_sign[OS_STRING_QW_SIGN_LEN]; 0473 u8 b_vendor_code; 0474 struct usb_configuration *os_desc_config; 0475 unsigned int use_os_string:1; 0476 0477 /* private: */ 0478 /* internals */ 0479 unsigned int suspended:1; 0480 struct usb_device_descriptor desc; 0481 struct list_head configs; 0482 struct list_head gstrings; 0483 struct usb_composite_driver *driver; 0484 u8 next_string_id; 0485 char *def_manufacturer; 0486 0487 /* the gadget driver won't enable the data pullup 0488 * while the deactivation count is nonzero. 0489 */ 0490 unsigned deactivations; 0491 0492 /* the composite driver won't complete the control transfer's 0493 * data/status stages till delayed_status is zero. 0494 */ 0495 int delayed_status; 0496 0497 /* protects deactivations and delayed_status counts*/ 0498 spinlock_t lock; 0499 0500 /* public: */ 0501 unsigned int setup_pending:1; 0502 unsigned int os_desc_pending:1; 0503 }; 0504 0505 extern int usb_string_id(struct usb_composite_dev *c); 0506 extern int usb_string_ids_tab(struct usb_composite_dev *c, 0507 struct usb_string *str); 0508 extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, 0509 struct usb_gadget_strings **sp, unsigned n_strings); 0510 0511 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 0512 0513 extern void composite_disconnect(struct usb_gadget *gadget); 0514 extern void composite_reset(struct usb_gadget *gadget); 0515 0516 extern int composite_setup(struct usb_gadget *gadget, 0517 const struct usb_ctrlrequest *ctrl); 0518 extern void composite_suspend(struct usb_gadget *gadget); 0519 extern void composite_resume(struct usb_gadget *gadget); 0520 0521 /* 0522 * Some systems will need runtime overrides for the product identifiers 0523 * published in the device descriptor, either numbers or strings or both. 0524 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 0525 */ 0526 struct usb_composite_overwrite { 0527 u16 idVendor; 0528 u16 idProduct; 0529 u16 bcdDevice; 0530 char *serial_number; 0531 char *manufacturer; 0532 char *product; 0533 }; 0534 #define USB_GADGET_COMPOSITE_OPTIONS() \ 0535 static struct usb_composite_overwrite coverwrite; \ 0536 \ 0537 module_param_named(idVendor, coverwrite.idVendor, ushort, S_IRUGO); \ 0538 MODULE_PARM_DESC(idVendor, "USB Vendor ID"); \ 0539 \ 0540 module_param_named(idProduct, coverwrite.idProduct, ushort, S_IRUGO); \ 0541 MODULE_PARM_DESC(idProduct, "USB Product ID"); \ 0542 \ 0543 module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \ 0544 MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); \ 0545 \ 0546 module_param_named(iSerialNumber, coverwrite.serial_number, charp, \ 0547 S_IRUGO); \ 0548 MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); \ 0549 \ 0550 module_param_named(iManufacturer, coverwrite.manufacturer, charp, \ 0551 S_IRUGO); \ 0552 MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); \ 0553 \ 0554 module_param_named(iProduct, coverwrite.product, charp, S_IRUGO); \ 0555 MODULE_PARM_DESC(iProduct, "USB Product string") 0556 0557 void usb_composite_overwrite_options(struct usb_composite_dev *cdev, 0558 struct usb_composite_overwrite *covr); 0559 0560 static inline u16 get_default_bcdDevice(void) 0561 { 0562 u16 bcdDevice; 0563 0564 bcdDevice = bin2bcd(LINUX_VERSION_MAJOR) << 8; 0565 bcdDevice |= bin2bcd(LINUX_VERSION_PATCHLEVEL); 0566 return bcdDevice; 0567 } 0568 0569 struct usb_function_driver { 0570 const char *name; 0571 struct module *mod; 0572 struct list_head list; 0573 struct usb_function_instance *(*alloc_inst)(void); 0574 struct usb_function *(*alloc_func)(struct usb_function_instance *inst); 0575 }; 0576 0577 struct usb_function_instance { 0578 struct config_group group; 0579 struct list_head cfs_list; 0580 struct usb_function_driver *fd; 0581 int (*set_inst_name)(struct usb_function_instance *inst, 0582 const char *name); 0583 void (*free_func_inst)(struct usb_function_instance *inst); 0584 }; 0585 0586 void usb_function_unregister(struct usb_function_driver *f); 0587 int usb_function_register(struct usb_function_driver *newf); 0588 void usb_put_function_instance(struct usb_function_instance *fi); 0589 void usb_put_function(struct usb_function *f); 0590 struct usb_function_instance *usb_get_function_instance(const char *name); 0591 struct usb_function *usb_get_function(struct usb_function_instance *fi); 0592 0593 struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, 0594 int val); 0595 int usb_add_config_only(struct usb_composite_dev *cdev, 0596 struct usb_configuration *config); 0597 void usb_remove_function(struct usb_configuration *c, struct usb_function *f); 0598 0599 #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ 0600 static struct usb_function_driver _name ## usb_func = { \ 0601 .name = __stringify(_name), \ 0602 .mod = THIS_MODULE, \ 0603 .alloc_inst = _inst_alloc, \ 0604 .alloc_func = _func_alloc, \ 0605 }; \ 0606 MODULE_ALIAS("usbfunc:"__stringify(_name)); 0607 0608 #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \ 0609 DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ 0610 static int __init _name ## mod_init(void) \ 0611 { \ 0612 return usb_function_register(&_name ## usb_func); \ 0613 } \ 0614 static void __exit _name ## mod_exit(void) \ 0615 { \ 0616 usb_function_unregister(&_name ## usb_func); \ 0617 } \ 0618 module_init(_name ## mod_init); \ 0619 module_exit(_name ## mod_exit) 0620 0621 /* messaging utils */ 0622 #define DBG(d, fmt, args...) \ 0623 dev_dbg(&(d)->gadget->dev , fmt , ## args) 0624 #define VDBG(d, fmt, args...) \ 0625 dev_vdbg(&(d)->gadget->dev , fmt , ## args) 0626 #define ERROR(d, fmt, args...) \ 0627 dev_err(&(d)->gadget->dev , fmt , ## args) 0628 #define WARNING(d, fmt, args...) \ 0629 dev_warn(&(d)->gadget->dev , fmt , ## args) 0630 #define INFO(d, fmt, args...) \ 0631 dev_info(&(d)->gadget->dev , fmt , ## args) 0632 0633 #endif /* __LINUX_USB_COMPOSITE_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |