Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 1 | /** |
| 2 | * udc.c - Core UDC Framework |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments |
| 5 | * Author: Felipe Balbi <balbi@ti.com> |
| 6 | * |
| 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 of |
| 9 | * the License as published by the Free Software Foundation. |
| 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, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/err.h> |
Felipe Balbi | a698908 | 2011-12-15 13:31:48 +0200 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 26 | |
| 27 | #include <linux/usb/ch9.h> |
| 28 | #include <linux/usb/gadget.h> |
| 29 | |
| 30 | /** |
| 31 | * struct usb_udc - describes one usb device controller |
| 32 | * @driver - the gadget driver pointer. For use by the class code |
| 33 | * @dev - the child device to the actual controller |
| 34 | * @gadget - the gadget. For use by the class code |
| 35 | * @list - for use by the udc class driver |
| 36 | * |
| 37 | * This represents the internal data structure which is used by the UDC-class |
| 38 | * to hold information about udc driver and gadget together. |
| 39 | */ |
| 40 | struct usb_udc { |
| 41 | struct usb_gadget_driver *driver; |
| 42 | struct usb_gadget *gadget; |
| 43 | struct device dev; |
| 44 | struct list_head list; |
| 45 | }; |
| 46 | |
| 47 | static struct class *udc_class; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 48 | static LIST_HEAD(udc_list); |
| 49 | static DEFINE_MUTEX(udc_lock); |
| 50 | |
| 51 | /* ------------------------------------------------------------------------- */ |
| 52 | |
Felipe Balbi | a698908 | 2011-12-15 13:31:48 +0200 | [diff] [blame] | 53 | int usb_gadget_map_request(struct usb_gadget *gadget, |
| 54 | struct usb_request *req, int is_in) |
| 55 | { |
| 56 | if (req->length == 0) |
| 57 | return 0; |
| 58 | |
| 59 | if (req->num_sgs) { |
| 60 | int mapped; |
| 61 | |
| 62 | mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs, |
| 63 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 64 | if (mapped == 0) { |
| 65 | dev_err(&gadget->dev, "failed to map SGs\n"); |
| 66 | return -EFAULT; |
| 67 | } |
| 68 | |
| 69 | req->num_mapped_sgs = mapped; |
| 70 | } else { |
| 71 | req->dma = dma_map_single(&gadget->dev, req->buf, req->length, |
| 72 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 73 | |
| 74 | if (dma_mapping_error(&gadget->dev, req->dma)) { |
| 75 | dev_err(&gadget->dev, "failed to map buffer\n"); |
| 76 | return -EFAULT; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | EXPORT_SYMBOL_GPL(usb_gadget_map_request); |
| 83 | |
| 84 | void usb_gadget_unmap_request(struct usb_gadget *gadget, |
| 85 | struct usb_request *req, int is_in) |
| 86 | { |
| 87 | if (req->length == 0) |
| 88 | return; |
| 89 | |
| 90 | if (req->num_mapped_sgs) { |
| 91 | dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs, |
| 92 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 93 | |
| 94 | req->num_mapped_sgs = 0; |
| 95 | } else { |
| 96 | dma_unmap_single(&gadget->dev, req->dma, req->length, |
| 97 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 98 | } |
| 99 | } |
| 100 | EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); |
| 101 | |
| 102 | /* ------------------------------------------------------------------------- */ |
| 103 | |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 104 | /** |
Sebastian Andrzej Siewior | 352c2dc | 2011-06-23 14:26:15 +0200 | [diff] [blame] | 105 | * usb_gadget_udc_start - tells usb device controller to start up |
| 106 | * @gadget: The gadget we want to get started |
| 107 | * @driver: The driver we want to bind to @gadget |
| 108 | * |
| 109 | * This call is issued by the UDC Class driver when it's about |
| 110 | * to register a gadget driver to the device controller, before |
| 111 | * calling gadget driver's bind() method. |
| 112 | * |
| 113 | * It allows the controller to be powered off until strictly |
| 114 | * necessary to have it powered on. |
| 115 | * |
| 116 | * Returns zero on success, else negative errno. |
| 117 | */ |
| 118 | static inline int usb_gadget_udc_start(struct usb_gadget *gadget, |
| 119 | struct usb_gadget_driver *driver) |
| 120 | { |
| 121 | return gadget->ops->udc_start(gadget, driver); |
| 122 | } |
| 123 | |
| 124 | /** |
Sebastian Andrzej Siewior | 352c2dc | 2011-06-23 14:26:15 +0200 | [diff] [blame] | 125 | * usb_gadget_udc_stop - tells usb device controller we don't need it anymore |
| 126 | * @gadget: The device we want to stop activity |
| 127 | * @driver: The driver to unbind from @gadget |
| 128 | * |
| 129 | * This call is issued by the UDC Class driver after calling |
| 130 | * gadget driver's unbind() method. |
| 131 | * |
| 132 | * The details are implementation specific, but it can go as |
| 133 | * far as powering off UDC completely and disable its data |
| 134 | * line pullups. |
| 135 | */ |
| 136 | static inline void usb_gadget_udc_stop(struct usb_gadget *gadget, |
| 137 | struct usb_gadget_driver *driver) |
| 138 | { |
| 139 | gadget->ops->udc_stop(gadget, driver); |
| 140 | } |
| 141 | |
| 142 | /** |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 143 | * usb_udc_release - release the usb_udc struct |
| 144 | * @dev: the dev member within usb_udc |
| 145 | * |
| 146 | * This is called by driver's core in order to free memory once the last |
| 147 | * reference is released. |
| 148 | */ |
| 149 | static void usb_udc_release(struct device *dev) |
| 150 | { |
| 151 | struct usb_udc *udc; |
| 152 | |
| 153 | udc = container_of(dev, struct usb_udc, dev); |
| 154 | dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); |
| 155 | kfree(udc); |
| 156 | } |
| 157 | |
Sebastian Andrzej Siewior | 019f976 | 2011-06-23 14:28:38 +0200 | [diff] [blame] | 158 | static const struct attribute_group *usb_udc_attr_groups[]; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 159 | /** |
| 160 | * usb_add_gadget_udc - adds a new gadget to the udc class driver list |
| 161 | * @parent: the parent device to this udc. Usually the controller |
| 162 | * driver's device. |
| 163 | * @gadget: the gadget to be added to the list |
| 164 | * |
| 165 | * Returns zero on success, negative errno otherwise. |
| 166 | */ |
| 167 | int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) |
| 168 | { |
| 169 | struct usb_udc *udc; |
| 170 | int ret = -ENOMEM; |
| 171 | |
| 172 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); |
| 173 | if (!udc) |
| 174 | goto err1; |
| 175 | |
| 176 | device_initialize(&udc->dev); |
| 177 | udc->dev.release = usb_udc_release; |
| 178 | udc->dev.class = udc_class; |
Sebastian Andrzej Siewior | 019f976 | 2011-06-23 14:28:38 +0200 | [diff] [blame] | 179 | udc->dev.groups = usb_udc_attr_groups; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 180 | udc->dev.parent = parent; |
| 181 | ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); |
| 182 | if (ret) |
| 183 | goto err2; |
| 184 | |
| 185 | udc->gadget = gadget; |
| 186 | |
| 187 | mutex_lock(&udc_lock); |
| 188 | list_add_tail(&udc->list, &udc_list); |
| 189 | |
| 190 | ret = device_add(&udc->dev); |
| 191 | if (ret) |
| 192 | goto err3; |
| 193 | |
| 194 | mutex_unlock(&udc_lock); |
| 195 | |
| 196 | return 0; |
| 197 | err3: |
| 198 | list_del(&udc->list); |
| 199 | mutex_unlock(&udc_lock); |
| 200 | |
| 201 | err2: |
| 202 | put_device(&udc->dev); |
| 203 | |
| 204 | err1: |
| 205 | return ret; |
| 206 | } |
| 207 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc); |
| 208 | |
| 209 | static void usb_gadget_remove_driver(struct usb_udc *udc) |
| 210 | { |
| 211 | dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", |
| 212 | udc->gadget->name); |
| 213 | |
| 214 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
| 215 | |
Felipe Balbi | 2d7ebbb | 2013-01-24 11:00:15 +0200 | [diff] [blame] | 216 | usb_gadget_disconnect(udc->gadget); |
| 217 | udc->driver->disconnect(udc->gadget); |
| 218 | udc->driver->unbind(udc->gadget); |
Alan Stern | 511f3c5 | 2013-03-15 14:02:14 -0400 | [diff] [blame] | 219 | usb_gadget_udc_stop(udc->gadget, NULL); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 220 | |
| 221 | udc->driver = NULL; |
| 222 | udc->dev.driver = NULL; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * usb_del_gadget_udc - deletes @udc from udc_list |
| 227 | * @gadget: the gadget to be removed. |
| 228 | * |
| 229 | * This, will call usb_gadget_unregister_driver() if |
| 230 | * the @udc is still busy. |
| 231 | */ |
| 232 | void usb_del_gadget_udc(struct usb_gadget *gadget) |
| 233 | { |
| 234 | struct usb_udc *udc = NULL; |
| 235 | |
| 236 | mutex_lock(&udc_lock); |
| 237 | list_for_each_entry(udc, &udc_list, list) |
| 238 | if (udc->gadget == gadget) |
| 239 | goto found; |
| 240 | |
| 241 | dev_err(gadget->dev.parent, "gadget not registered.\n"); |
| 242 | mutex_unlock(&udc_lock); |
| 243 | |
| 244 | return; |
| 245 | |
| 246 | found: |
| 247 | dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); |
| 248 | |
| 249 | list_del(&udc->list); |
| 250 | mutex_unlock(&udc_lock); |
| 251 | |
| 252 | if (udc->driver) |
| 253 | usb_gadget_remove_driver(udc); |
| 254 | |
| 255 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); |
| 256 | device_unregister(&udc->dev); |
| 257 | } |
| 258 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); |
| 259 | |
| 260 | /* ------------------------------------------------------------------------- */ |
| 261 | |
Sebastian Andrzej Siewior | 4c49a5f | 2012-12-23 21:10:19 +0100 | [diff] [blame] | 262 | static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 263 | { |
Sebastian Andrzej Siewior | 4c49a5f | 2012-12-23 21:10:19 +0100 | [diff] [blame] | 264 | int ret; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 265 | |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 266 | dev_dbg(&udc->dev, "registering UDC driver [%s]\n", |
| 267 | driver->function); |
| 268 | |
| 269 | udc->driver = driver; |
| 270 | udc->dev.driver = &driver->driver; |
| 271 | |
Felipe Balbi | 2d7ebbb | 2013-01-24 11:00:15 +0200 | [diff] [blame] | 272 | ret = driver->bind(udc->gadget, driver); |
| 273 | if (ret) |
| 274 | goto err1; |
| 275 | ret = usb_gadget_udc_start(udc->gadget, driver); |
| 276 | if (ret) { |
| 277 | driver->unbind(udc->gadget); |
| 278 | goto err1; |
Sebastian Andrzej Siewior | 352c2dc | 2011-06-23 14:26:15 +0200 | [diff] [blame] | 279 | } |
Felipe Balbi | 2d7ebbb | 2013-01-24 11:00:15 +0200 | [diff] [blame] | 280 | usb_gadget_connect(udc->gadget); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 281 | |
| 282 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 283 | return 0; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 284 | err1: |
| 285 | dev_err(&udc->dev, "failed to start %s: %d\n", |
| 286 | udc->driver->function, ret); |
| 287 | udc->driver = NULL; |
| 288 | udc->dev.driver = NULL; |
Sebastian Andrzej Siewior | 4c49a5f | 2012-12-23 21:10:19 +0100 | [diff] [blame] | 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | int udc_attach_driver(const char *name, struct usb_gadget_driver *driver) |
| 293 | { |
| 294 | struct usb_udc *udc = NULL; |
| 295 | int ret = -ENODEV; |
| 296 | |
| 297 | mutex_lock(&udc_lock); |
| 298 | list_for_each_entry(udc, &udc_list, list) { |
| 299 | ret = strcmp(name, dev_name(&udc->dev)); |
| 300 | if (!ret) |
| 301 | break; |
| 302 | } |
| 303 | if (ret) { |
| 304 | ret = -ENODEV; |
| 305 | goto out; |
| 306 | } |
| 307 | if (udc->driver) { |
| 308 | ret = -EBUSY; |
| 309 | goto out; |
| 310 | } |
| 311 | ret = udc_bind_to_driver(udc, driver); |
| 312 | out: |
| 313 | mutex_unlock(&udc_lock); |
| 314 | return ret; |
| 315 | } |
| 316 | EXPORT_SYMBOL_GPL(udc_attach_driver); |
| 317 | |
| 318 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver) |
| 319 | { |
| 320 | struct usb_udc *udc = NULL; |
| 321 | int ret; |
| 322 | |
| 323 | if (!driver || !driver->bind || !driver->setup) |
| 324 | return -EINVAL; |
| 325 | |
| 326 | mutex_lock(&udc_lock); |
| 327 | list_for_each_entry(udc, &udc_list, list) { |
| 328 | /* For now we take the first one */ |
| 329 | if (!udc->driver) |
| 330 | goto found; |
| 331 | } |
| 332 | |
| 333 | pr_debug("couldn't find an available UDC\n"); |
| 334 | mutex_unlock(&udc_lock); |
| 335 | return -ENODEV; |
| 336 | found: |
| 337 | ret = udc_bind_to_driver(udc, driver); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 338 | mutex_unlock(&udc_lock); |
| 339 | return ret; |
| 340 | } |
| 341 | EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); |
| 342 | |
| 343 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) |
| 344 | { |
| 345 | struct usb_udc *udc = NULL; |
| 346 | int ret = -ENODEV; |
| 347 | |
| 348 | if (!driver || !driver->unbind) |
| 349 | return -EINVAL; |
| 350 | |
| 351 | mutex_lock(&udc_lock); |
| 352 | list_for_each_entry(udc, &udc_list, list) |
| 353 | if (udc->driver == driver) { |
| 354 | usb_gadget_remove_driver(udc); |
| 355 | ret = 0; |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | mutex_unlock(&udc_lock); |
| 360 | return ret; |
| 361 | } |
| 362 | EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); |
| 363 | |
| 364 | /* ------------------------------------------------------------------------- */ |
| 365 | |
| 366 | static ssize_t usb_udc_srp_store(struct device *dev, |
| 367 | struct device_attribute *attr, const char *buf, size_t n) |
| 368 | { |
Felipe Balbi | 1d91a96 | 2011-09-08 14:11:17 +0300 | [diff] [blame] | 369 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 370 | |
| 371 | if (sysfs_streq(buf, "1")) |
| 372 | usb_gadget_wakeup(udc->gadget); |
| 373 | |
| 374 | return n; |
| 375 | } |
| 376 | static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); |
| 377 | |
| 378 | static ssize_t usb_udc_softconn_store(struct device *dev, |
| 379 | struct device_attribute *attr, const char *buf, size_t n) |
| 380 | { |
Felipe Balbi | 865569b | 2011-09-08 14:12:18 +0300 | [diff] [blame] | 381 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 382 | |
| 383 | if (sysfs_streq(buf, "connect")) { |
Felipe Balbi | 2d7ebbb | 2013-01-24 11:00:15 +0200 | [diff] [blame] | 384 | usb_gadget_udc_start(udc->gadget, udc->driver); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 385 | usb_gadget_connect(udc->gadget); |
| 386 | } else if (sysfs_streq(buf, "disconnect")) { |
Felipe Balbi | 83a787a | 2012-04-27 11:02:15 +0300 | [diff] [blame] | 387 | usb_gadget_disconnect(udc->gadget); |
Felipe Balbi | 2d7ebbb | 2013-01-24 11:00:15 +0200 | [diff] [blame] | 388 | usb_gadget_udc_stop(udc->gadget, udc->driver); |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 389 | } else { |
| 390 | dev_err(dev, "unsupported command '%s'\n", buf); |
| 391 | return -EINVAL; |
| 392 | } |
| 393 | |
| 394 | return n; |
| 395 | } |
| 396 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); |
| 397 | |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 398 | #define USB_UDC_SPEED_ATTR(name, param) \ |
| 399 | ssize_t usb_udc_##param##_show(struct device *dev, \ |
| 400 | struct device_attribute *attr, char *buf) \ |
| 401 | { \ |
| 402 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ |
| 403 | return snprintf(buf, PAGE_SIZE, "%s\n", \ |
| 404 | usb_speed_string(udc->gadget->param)); \ |
| 405 | } \ |
| 406 | static DEVICE_ATTR(name, S_IRUSR, usb_udc_##param##_show, NULL) |
| 407 | |
| 408 | static USB_UDC_SPEED_ATTR(current_speed, speed); |
| 409 | static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); |
| 410 | |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 411 | #define USB_UDC_ATTR(name) \ |
| 412 | ssize_t usb_udc_##name##_show(struct device *dev, \ |
| 413 | struct device_attribute *attr, char *buf) \ |
| 414 | { \ |
Sebastian Andrzej Siewior | 019f976 | 2011-06-23 14:28:38 +0200 | [diff] [blame] | 415 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 416 | struct usb_gadget *gadget = udc->gadget; \ |
| 417 | \ |
| 418 | return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ |
| 419 | } \ |
Felipe Balbi | 59d81f8 | 2011-10-03 16:43:56 +0300 | [diff] [blame] | 420 | static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL) |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 421 | |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 422 | static USB_UDC_ATTR(is_otg); |
| 423 | static USB_UDC_ATTR(is_a_peripheral); |
| 424 | static USB_UDC_ATTR(b_hnp_enable); |
| 425 | static USB_UDC_ATTR(a_hnp_support); |
| 426 | static USB_UDC_ATTR(a_alt_hnp_support); |
| 427 | |
| 428 | static struct attribute *usb_udc_attrs[] = { |
| 429 | &dev_attr_srp.attr, |
| 430 | &dev_attr_soft_connect.attr, |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 431 | &dev_attr_current_speed.attr, |
| 432 | &dev_attr_maximum_speed.attr, |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 433 | |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 434 | &dev_attr_is_otg.attr, |
| 435 | &dev_attr_is_a_peripheral.attr, |
| 436 | &dev_attr_b_hnp_enable.attr, |
| 437 | &dev_attr_a_hnp_support.attr, |
| 438 | &dev_attr_a_alt_hnp_support.attr, |
| 439 | NULL, |
| 440 | }; |
| 441 | |
| 442 | static const struct attribute_group usb_udc_attr_group = { |
| 443 | .attrs = usb_udc_attrs, |
| 444 | }; |
| 445 | |
| 446 | static const struct attribute_group *usb_udc_attr_groups[] = { |
| 447 | &usb_udc_attr_group, |
| 448 | NULL, |
| 449 | }; |
| 450 | |
| 451 | static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 452 | { |
| 453 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
| 454 | int ret; |
| 455 | |
| 456 | ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); |
| 457 | if (ret) { |
| 458 | dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); |
| 459 | return ret; |
| 460 | } |
| 461 | |
| 462 | if (udc->driver) { |
| 463 | ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", |
| 464 | udc->driver->function); |
| 465 | if (ret) { |
| 466 | dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); |
| 467 | return ret; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int __init usb_udc_init(void) |
| 475 | { |
| 476 | udc_class = class_create(THIS_MODULE, "udc"); |
| 477 | if (IS_ERR(udc_class)) { |
| 478 | pr_err("failed to create udc class --> %ld\n", |
| 479 | PTR_ERR(udc_class)); |
| 480 | return PTR_ERR(udc_class); |
| 481 | } |
| 482 | |
| 483 | udc_class->dev_uevent = usb_udc_uevent; |
Felipe Balbi | 2ccea03 | 2011-06-28 16:33:46 +0300 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | subsys_initcall(usb_udc_init); |
| 487 | |
| 488 | static void __exit usb_udc_exit(void) |
| 489 | { |
| 490 | class_destroy(udc_class); |
| 491 | } |
| 492 | module_exit(usb_udc_exit); |
| 493 | |
| 494 | MODULE_DESCRIPTION("UDC Framework"); |
| 495 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 496 | MODULE_LICENSE("GPL v2"); |