| 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> |
| 25 | #include <linux/dma-mapping.h> |
| 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; |
| 48 | static LIST_HEAD(udc_list); |
| 49 | static DEFINE_MUTEX(udc_lock); |
| 50 | |
| 51 | /* ------------------------------------------------------------------------- */ |
| 52 | |
| 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 | |
| 104 | void usb_gadget_set_state(struct usb_gadget *gadget, |
| 105 | enum usb_device_state state) |
| 106 | { |
| 107 | gadget->state = state; |
| 108 | sysfs_notify(&gadget->dev.kobj, NULL, "state"); |
| 109 | } |
| 110 | EXPORT_SYMBOL_GPL(usb_gadget_set_state); |
| 111 | |
| 112 | /* ------------------------------------------------------------------------- */ |
| 113 | |
| 114 | /** |
| 115 | * usb_gadget_udc_start - tells usb device controller to start up |
| 116 | * @gadget: The gadget we want to get started |
| 117 | * @driver: The driver we want to bind to @gadget |
| 118 | * |
| 119 | * This call is issued by the UDC Class driver when it's about |
| 120 | * to register a gadget driver to the device controller, before |
| 121 | * calling gadget driver's bind() method. |
| 122 | * |
| 123 | * It allows the controller to be powered off until strictly |
| 124 | * necessary to have it powered on. |
| 125 | * |
| 126 | * Returns zero on success, else negative errno. |
| 127 | */ |
| 128 | static inline int usb_gadget_udc_start(struct usb_gadget *gadget, |
| 129 | struct usb_gadget_driver *driver) |
| 130 | { |
| 131 | return gadget->ops->udc_start(gadget, driver); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * usb_gadget_udc_stop - tells usb device controller we don't need it anymore |
| 136 | * @gadget: The device we want to stop activity |
| 137 | * @driver: The driver to unbind from @gadget |
| 138 | * |
| 139 | * This call is issued by the UDC Class driver after calling |
| 140 | * gadget driver's unbind() method. |
| 141 | * |
| 142 | * The details are implementation specific, but it can go as |
| 143 | * far as powering off UDC completely and disable its data |
| 144 | * line pullups. |
| 145 | */ |
| 146 | static inline void usb_gadget_udc_stop(struct usb_gadget *gadget, |
| 147 | struct usb_gadget_driver *driver) |
| 148 | { |
| 149 | gadget->ops->udc_stop(gadget, driver); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * usb_udc_release - release the usb_udc struct |
| 154 | * @dev: the dev member within usb_udc |
| 155 | * |
| 156 | * This is called by driver's core in order to free memory once the last |
| 157 | * reference is released. |
| 158 | */ |
| 159 | static void usb_udc_release(struct device *dev) |
| 160 | { |
| 161 | struct usb_udc *udc; |
| 162 | |
| 163 | udc = container_of(dev, struct usb_udc, dev); |
| 164 | dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); |
| 165 | kfree(udc); |
| 166 | } |
| 167 | |
| 168 | static const struct attribute_group *usb_udc_attr_groups[]; |
| 169 | |
| 170 | static void usb_udc_nop_release(struct device *dev) |
| 171 | { |
| 172 | dev_vdbg(dev, "%s\n", __func__); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list |
| 177 | * @parent: the parent device to this udc. Usually the controller driver's |
| 178 | * device. |
| 179 | * @gadget: the gadget to be added to the list. |
| 180 | * @release: a gadget release function. |
| 181 | * |
| 182 | * Returns zero on success, negative errno otherwise. |
| 183 | */ |
| 184 | int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, |
| 185 | void (*release)(struct device *dev)) |
| 186 | { |
| 187 | struct usb_udc *udc; |
| 188 | int ret = -ENOMEM; |
| 189 | |
| 190 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); |
| 191 | if (!udc) |
| 192 | goto err1; |
| 193 | |
| 194 | dev_set_name(&gadget->dev, "gadget"); |
| 195 | gadget->dev.parent = parent; |
| 196 | |
| 197 | dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask); |
| 198 | gadget->dev.dma_parms = parent->dma_parms; |
| 199 | gadget->dev.dma_mask = parent->dma_mask; |
| 200 | |
| 201 | if (release) |
| 202 | gadget->dev.release = release; |
| 203 | else |
| 204 | gadget->dev.release = usb_udc_nop_release; |
| 205 | |
| 206 | ret = device_register(&gadget->dev); |
| 207 | if (ret) |
| 208 | goto err2; |
| 209 | |
| 210 | device_initialize(&udc->dev); |
| 211 | udc->dev.release = usb_udc_release; |
| 212 | udc->dev.class = udc_class; |
| 213 | udc->dev.groups = usb_udc_attr_groups; |
| 214 | udc->dev.parent = parent; |
| 215 | ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); |
| 216 | if (ret) |
| 217 | goto err3; |
| 218 | |
| 219 | udc->gadget = gadget; |
| 220 | |
| 221 | mutex_lock(&udc_lock); |
| 222 | list_add_tail(&udc->list, &udc_list); |
| 223 | |
| 224 | ret = device_add(&udc->dev); |
| 225 | if (ret) |
| 226 | goto err4; |
| 227 | |
| 228 | usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); |
| 229 | |
| 230 | mutex_unlock(&udc_lock); |
| 231 | |
| 232 | return 0; |
| 233 | |
| 234 | err4: |
| 235 | list_del(&udc->list); |
| 236 | mutex_unlock(&udc_lock); |
| 237 | |
| 238 | err3: |
| 239 | put_device(&udc->dev); |
| 240 | |
| 241 | err2: |
| 242 | put_device(&gadget->dev); |
| 243 | kfree(udc); |
| 244 | |
| 245 | err1: |
| 246 | return ret; |
| 247 | } |
| 248 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); |
| 249 | |
| 250 | /** |
| 251 | * usb_add_gadget_udc - adds a new gadget to the udc class driver list |
| 252 | * @parent: the parent device to this udc. Usually the controller |
| 253 | * driver's device. |
| 254 | * @gadget: the gadget to be added to the list |
| 255 | * |
| 256 | * Returns zero on success, negative errno otherwise. |
| 257 | */ |
| 258 | int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) |
| 259 | { |
| 260 | return usb_add_gadget_udc_release(parent, gadget, NULL); |
| 261 | } |
| 262 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc); |
| 263 | |
| 264 | static void usb_gadget_remove_driver(struct usb_udc *udc) |
| 265 | { |
| 266 | dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", |
| 267 | udc->gadget->name); |
| 268 | |
| 269 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
| 270 | |
| 271 | usb_gadget_disconnect(udc->gadget); |
| 272 | udc->driver->disconnect(udc->gadget); |
| 273 | udc->driver->unbind(udc->gadget); |
| 274 | usb_gadget_udc_stop(udc->gadget, NULL); |
| 275 | |
| 276 | udc->driver = NULL; |
| 277 | udc->dev.driver = NULL; |
| 278 | udc->gadget->dev.driver = NULL; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * usb_del_gadget_udc - deletes @udc from udc_list |
| 283 | * @gadget: the gadget to be removed. |
| 284 | * |
| 285 | * This, will call usb_gadget_unregister_driver() if |
| 286 | * the @udc is still busy. |
| 287 | */ |
| 288 | void usb_del_gadget_udc(struct usb_gadget *gadget) |
| 289 | { |
| 290 | struct usb_udc *udc = NULL; |
| 291 | |
| 292 | mutex_lock(&udc_lock); |
| 293 | list_for_each_entry(udc, &udc_list, list) |
| 294 | if (udc->gadget == gadget) |
| 295 | goto found; |
| 296 | |
| 297 | dev_err(gadget->dev.parent, "gadget not registered.\n"); |
| 298 | mutex_unlock(&udc_lock); |
| 299 | |
| 300 | return; |
| 301 | |
| 302 | found: |
| 303 | dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); |
| 304 | |
| 305 | list_del(&udc->list); |
| 306 | mutex_unlock(&udc_lock); |
| 307 | |
| 308 | if (udc->driver) |
| 309 | usb_gadget_remove_driver(udc); |
| 310 | |
| 311 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); |
| 312 | device_unregister(&udc->dev); |
| 313 | device_unregister(&gadget->dev); |
| 314 | } |
| 315 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); |
| 316 | |
| 317 | /* ------------------------------------------------------------------------- */ |
| 318 | |
| 319 | static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) |
| 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | dev_dbg(&udc->dev, "registering UDC driver [%s]\n", |
| 324 | driver->function); |
| 325 | |
| 326 | udc->driver = driver; |
| 327 | udc->dev.driver = &driver->driver; |
| 328 | udc->gadget->dev.driver = &driver->driver; |
| 329 | |
| 330 | ret = driver->bind(udc->gadget, driver); |
| 331 | if (ret) |
| 332 | goto err1; |
| 333 | ret = usb_gadget_udc_start(udc->gadget, driver); |
| 334 | if (ret) { |
| 335 | driver->unbind(udc->gadget); |
| 336 | goto err1; |
| 337 | } |
| 338 | /* |
| 339 | * HACK: The Android gadget driver disconnects the gadget |
| 340 | * on bind and expects the gadget to stay disconnected until |
| 341 | * it calls usb_gadget_connect when userspace is ready. Remove |
| 342 | * the call to usb_gadget_connect bellow to avoid enabling the |
| 343 | * pullup before userspace is ready. |
| 344 | * |
| 345 | * usb_gadget_connect(udc->gadget); |
| 346 | */ |
| 347 | |
| 348 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
| 349 | return 0; |
| 350 | err1: |
| 351 | dev_err(&udc->dev, "failed to start %s: %d\n", |
| 352 | udc->driver->function, ret); |
| 353 | udc->driver = NULL; |
| 354 | udc->dev.driver = NULL; |
| 355 | udc->gadget->dev.driver = NULL; |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | int udc_attach_driver(const char *name, struct usb_gadget_driver *driver) |
| 360 | { |
| 361 | struct usb_udc *udc = NULL; |
| 362 | int ret = -ENODEV; |
| 363 | |
| 364 | mutex_lock(&udc_lock); |
| 365 | list_for_each_entry(udc, &udc_list, list) { |
| 366 | ret = strcmp(name, dev_name(&udc->dev)); |
| 367 | if (!ret) |
| 368 | break; |
| 369 | } |
| 370 | if (ret) { |
| 371 | ret = -ENODEV; |
| 372 | goto out; |
| 373 | } |
| 374 | if (udc->driver) { |
| 375 | ret = -EBUSY; |
| 376 | goto out; |
| 377 | } |
| 378 | ret = udc_bind_to_driver(udc, driver); |
| 379 | out: |
| 380 | mutex_unlock(&udc_lock); |
| 381 | return ret; |
| 382 | } |
| 383 | EXPORT_SYMBOL_GPL(udc_attach_driver); |
| 384 | |
| 385 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver) |
| 386 | { |
| 387 | struct usb_udc *udc = NULL; |
| 388 | int ret; |
| 389 | |
| 390 | if (!driver || !driver->bind || !driver->setup) |
| 391 | return -EINVAL; |
| 392 | |
| 393 | mutex_lock(&udc_lock); |
| 394 | list_for_each_entry(udc, &udc_list, list) { |
| 395 | /* For now we take the first one */ |
| 396 | if (!udc->driver) |
| 397 | goto found; |
| 398 | } |
| 399 | |
| 400 | pr_debug("couldn't find an available UDC\n"); |
| 401 | mutex_unlock(&udc_lock); |
| 402 | return -ENODEV; |
| 403 | found: |
| 404 | ret = udc_bind_to_driver(udc, driver); |
| 405 | mutex_unlock(&udc_lock); |
| 406 | return ret; |
| 407 | } |
| 408 | EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); |
| 409 | |
| 410 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) |
| 411 | { |
| 412 | struct usb_udc *udc = NULL; |
| 413 | int ret = -ENODEV; |
| 414 | |
| 415 | if (!driver || !driver->unbind) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | mutex_lock(&udc_lock); |
| 419 | list_for_each_entry(udc, &udc_list, list) |
| 420 | if (udc->driver == driver) { |
| 421 | usb_gadget_remove_driver(udc); |
| 422 | ret = 0; |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | mutex_unlock(&udc_lock); |
| 427 | return ret; |
| 428 | } |
| 429 | EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); |
| 430 | |
| 431 | /* ------------------------------------------------------------------------- */ |
| 432 | |
| 433 | static ssize_t usb_udc_srp_store(struct device *dev, |
| 434 | struct device_attribute *attr, const char *buf, size_t n) |
| 435 | { |
| 436 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
| 437 | |
| 438 | if (sysfs_streq(buf, "1")) |
| 439 | usb_gadget_wakeup(udc->gadget); |
| 440 | |
| 441 | return n; |
| 442 | } |
| 443 | static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); |
| 444 | |
| 445 | static ssize_t usb_udc_softconn_store(struct device *dev, |
| 446 | struct device_attribute *attr, const char *buf, size_t n) |
| 447 | { |
| 448 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
| 449 | |
| 450 | if (!udc->driver) { |
| 451 | dev_err(dev, "soft-connect without a gadget driver\n"); |
| 452 | return -EOPNOTSUPP; |
| 453 | } |
| 454 | |
| 455 | if (sysfs_streq(buf, "connect")) { |
| 456 | usb_gadget_udc_start(udc->gadget, udc->driver); |
| 457 | usb_gadget_connect(udc->gadget); |
| 458 | } else if (sysfs_streq(buf, "disconnect")) { |
| 459 | usb_gadget_disconnect(udc->gadget); |
| 460 | usb_gadget_udc_stop(udc->gadget, udc->driver); |
| 461 | } else { |
| 462 | dev_err(dev, "unsupported command '%s'\n", buf); |
| 463 | return -EINVAL; |
| 464 | } |
| 465 | |
| 466 | return n; |
| 467 | } |
| 468 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); |
| 469 | |
| 470 | static ssize_t usb_gadget_state_show(struct device *dev, |
| 471 | struct device_attribute *attr, char *buf) |
| 472 | { |
| 473 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
| 474 | struct usb_gadget *gadget = udc->gadget; |
| 475 | |
| 476 | return sprintf(buf, "%s\n", usb_state_string(gadget->state)); |
| 477 | } |
| 478 | static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL); |
| 479 | |
| 480 | #define USB_UDC_SPEED_ATTR(name, param) \ |
| 481 | ssize_t usb_udc_##param##_show(struct device *dev, \ |
| 482 | struct device_attribute *attr, char *buf) \ |
| 483 | { \ |
| 484 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ |
| 485 | return snprintf(buf, PAGE_SIZE, "%s\n", \ |
| 486 | usb_speed_string(udc->gadget->param)); \ |
| 487 | } \ |
| 488 | static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL) |
| 489 | |
| 490 | static USB_UDC_SPEED_ATTR(current_speed, speed); |
| 491 | static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); |
| 492 | |
| 493 | #define USB_UDC_ATTR(name) \ |
| 494 | ssize_t usb_udc_##name##_show(struct device *dev, \ |
| 495 | struct device_attribute *attr, char *buf) \ |
| 496 | { \ |
| 497 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ |
| 498 | struct usb_gadget *gadget = udc->gadget; \ |
| 499 | \ |
| 500 | return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ |
| 501 | } \ |
| 502 | static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL) |
| 503 | |
| 504 | static USB_UDC_ATTR(is_otg); |
| 505 | static USB_UDC_ATTR(is_a_peripheral); |
| 506 | static USB_UDC_ATTR(b_hnp_enable); |
| 507 | static USB_UDC_ATTR(a_hnp_support); |
| 508 | static USB_UDC_ATTR(a_alt_hnp_support); |
| 509 | |
| 510 | static struct attribute *usb_udc_attrs[] = { |
| 511 | &dev_attr_srp.attr, |
| 512 | &dev_attr_soft_connect.attr, |
| 513 | &dev_attr_state.attr, |
| 514 | &dev_attr_current_speed.attr, |
| 515 | &dev_attr_maximum_speed.attr, |
| 516 | |
| 517 | &dev_attr_is_otg.attr, |
| 518 | &dev_attr_is_a_peripheral.attr, |
| 519 | &dev_attr_b_hnp_enable.attr, |
| 520 | &dev_attr_a_hnp_support.attr, |
| 521 | &dev_attr_a_alt_hnp_support.attr, |
| 522 | NULL, |
| 523 | }; |
| 524 | |
| 525 | static const struct attribute_group usb_udc_attr_group = { |
| 526 | .attrs = usb_udc_attrs, |
| 527 | }; |
| 528 | |
| 529 | static const struct attribute_group *usb_udc_attr_groups[] = { |
| 530 | &usb_udc_attr_group, |
| 531 | NULL, |
| 532 | }; |
| 533 | |
| 534 | static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 535 | { |
| 536 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
| 537 | int ret; |
| 538 | |
| 539 | ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); |
| 540 | if (ret) { |
| 541 | dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | if (udc->driver) { |
| 546 | ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", |
| 547 | udc->driver->function); |
| 548 | if (ret) { |
| 549 | dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); |
| 550 | return ret; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int __init usb_udc_init(void) |
| 558 | { |
| 559 | udc_class = class_create(THIS_MODULE, "udc"); |
| 560 | if (IS_ERR(udc_class)) { |
| 561 | pr_err("failed to create udc class --> %ld\n", |
| 562 | PTR_ERR(udc_class)); |
| 563 | return PTR_ERR(udc_class); |
| 564 | } |
| 565 | |
| 566 | udc_class->dev_uevent = usb_udc_uevent; |
| 567 | return 0; |
| 568 | } |
| 569 | subsys_initcall(usb_udc_init); |
| 570 | |
| 571 | static void __exit usb_udc_exit(void) |
| 572 | { |
| 573 | class_destroy(udc_class); |
| 574 | } |
| 575 | module_exit(usb_udc_exit); |
| 576 | |
| 577 | MODULE_DESCRIPTION("UDC Framework"); |
| 578 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 579 | MODULE_LICENSE("GPL v2"); |