Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * composite.h -- framework for usb gadgets which are composite devices |
| 3 | * |
| 4 | * Copyright (C) 2006-2008 David Brownell |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef __LINUX_USB_COMPOSITE_H |
| 22 | #define __LINUX_USB_COMPOSITE_H |
| 23 | |
| 24 | |
| 25 | #include <linux/usb/ch9.h> |
| 26 | #include <linux/usb/gadget.h> |
| 27 | #include <linux/switch.h> |
| 28 | |
| 29 | #define USB_GADGET_DELAYED_STATUS 0x7fff |
| 30 | |
| 31 | struct usb_configuration; |
| 32 | |
| 33 | struct usb_function { |
| 34 | const char *name; |
| 35 | struct usb_gadget_strings **strings; |
| 36 | struct usb_descriptor_header **descriptors; |
| 37 | struct usb_descriptor_header **hs_descriptors; |
| 38 | struct usb_descriptor_header **ss_descriptors; |
| 39 | |
| 40 | struct usb_configuration *config; |
| 41 | |
| 42 | |
| 43 | |
| 44 | int (*bind)(struct usb_configuration *, |
| 45 | struct usb_function *); |
| 46 | void (*unbind)(struct usb_configuration *, |
| 47 | struct usb_function *); |
| 48 | |
| 49 | |
| 50 | int (*set_alt)(struct usb_function *, |
| 51 | unsigned interface, unsigned alt); |
| 52 | int (*get_alt)(struct usb_function *, |
| 53 | unsigned interface); |
| 54 | void (*disable)(struct usb_function *); |
| 55 | int (*setup)(struct usb_function *, |
| 56 | const struct usb_ctrlrequest *); |
| 57 | void (*suspend)(struct usb_function *); |
| 58 | void (*resume)(struct usb_function *); |
| 59 | |
| 60 | |
| 61 | int (*get_status)(struct usb_function *); |
| 62 | int (*func_suspend)(struct usb_function *, |
| 63 | u8 suspend_opt); |
| 64 | |
| 65 | |
| 66 | struct list_head list; |
| 67 | DECLARE_BITMAP(endpoints, 32); |
| 68 | }; |
| 69 | |
| 70 | int usb_add_function(struct usb_configuration *, struct usb_function *); |
| 71 | |
| 72 | int usb_function_deactivate(struct usb_function *); |
| 73 | int usb_function_activate(struct usb_function *); |
| 74 | |
| 75 | int usb_interface_id(struct usb_configuration *, struct usb_function *); |
| 76 | |
| 77 | int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, |
| 78 | struct usb_ep *_ep); |
| 79 | |
| 80 | #define MAX_CONFIG_INTERFACES 16 |
| 81 | |
| 82 | struct usb_configuration { |
| 83 | const char *label; |
| 84 | struct usb_gadget_strings **strings; |
| 85 | const struct usb_descriptor_header **descriptors; |
| 86 | |
| 87 | |
| 88 | |
| 89 | void (*unbind)(struct usb_configuration *); |
| 90 | int (*setup)(struct usb_configuration *, |
| 91 | const struct usb_ctrlrequest *); |
| 92 | |
| 93 | |
| 94 | u8 bConfigurationValue; |
| 95 | u8 iConfiguration; |
| 96 | u8 bmAttributes; |
| 97 | u8 bMaxPower; |
| 98 | |
| 99 | struct usb_composite_dev *cdev; |
| 100 | |
| 101 | |
| 102 | |
| 103 | struct list_head list; |
| 104 | struct list_head functions; |
| 105 | u8 next_interface_id; |
| 106 | unsigned superspeed:1; |
| 107 | unsigned highspeed:1; |
| 108 | unsigned fullspeed:1; |
| 109 | struct usb_function *interface[MAX_CONFIG_INTERFACES]; |
| 110 | }; |
| 111 | |
| 112 | int usb_add_config(struct usb_composite_dev *, |
| 113 | struct usb_configuration *, |
| 114 | int (*)(struct usb_configuration *)); |
| 115 | |
| 116 | int usb_remove_config(struct usb_composite_dev *, |
| 117 | struct usb_configuration *); |
| 118 | |
| 119 | struct usb_composite_driver { |
| 120 | const char *name; |
| 121 | const char *iProduct; |
| 122 | const char *iManufacturer; |
| 123 | const struct usb_device_descriptor *dev; |
| 124 | struct usb_gadget_strings **strings; |
| 125 | enum usb_device_speed max_speed; |
| 126 | unsigned needs_serial:1; |
| 127 | |
| 128 | int (*unbind)(struct usb_composite_dev *); |
| 129 | |
| 130 | void (*disconnect)(struct usb_composite_dev *); |
| 131 | |
| 132 | |
| 133 | void (*suspend)(struct usb_composite_dev *); |
| 134 | void (*resume)(struct usb_composite_dev *); |
| 135 | }; |
| 136 | |
| 137 | extern int usb_composite_probe(struct usb_composite_driver *driver, |
| 138 | int (*bind)(struct usb_composite_dev *cdev)); |
| 139 | extern void usb_composite_unregister(struct usb_composite_driver *driver); |
| 140 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); |
| 141 | |
| 142 | |
| 143 | struct usb_composite_dev { |
| 144 | struct usb_gadget *gadget; |
| 145 | struct usb_request *req; |
| 146 | unsigned bufsiz; |
| 147 | |
| 148 | struct usb_configuration *config; |
| 149 | |
| 150 | |
| 151 | |
| 152 | unsigned int suspended:1; |
| 153 | struct usb_device_descriptor desc; |
| 154 | struct list_head configs; |
| 155 | struct usb_composite_driver *driver; |
| 156 | u8 next_string_id; |
| 157 | u8 manufacturer_override; |
| 158 | u8 product_override; |
| 159 | u8 serial_override; |
| 160 | |
| 161 | unsigned deactivations; |
| 162 | |
| 163 | int delayed_status; |
| 164 | |
| 165 | |
| 166 | spinlock_t lock; |
| 167 | |
| 168 | |
| 169 | struct switch_dev sw_connect2pc; |
| 170 | |
| 171 | bool connected; |
| 172 | |
| 173 | struct work_struct switch_work; |
| 174 | struct delayed_work request_reset; |
| 175 | }; |
| 176 | |
| 177 | extern int usb_string_id(struct usb_composite_dev *c); |
| 178 | extern int usb_string_ids_tab(struct usb_composite_dev *c, |
| 179 | struct usb_string *str); |
| 180 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); |
| 181 | |
| 182 | |
| 183 | #define DBG(d, fmt, args...) \ |
| 184 | dev_dbg(&(d)->gadget->dev , fmt , ## args) |
| 185 | #define VDBG(d, fmt, args...) \ |
| 186 | dev_vdbg(&(d)->gadget->dev , fmt , ## args) |
| 187 | #define ERROR(d, fmt, args...) \ |
| 188 | dev_err(&(d)->gadget->dev , fmt , ## args) |
| 189 | #define WARNING(d, fmt, args...) \ |
| 190 | dev_warn(&(d)->gadget->dev , fmt , ## args) |
| 191 | #define INFO(d, fmt, args...) \ |
| 192 | dev_info(&(d)->gadget->dev , fmt , ## args) |
| 193 | |
| 194 | #endif |