blob: 817a26cbfab19227c92a557b3b5cb69251d2ee18 [file] [log] [blame]
Felipe Balbi2ccea032011-06-28 16:33:46 +03001/**
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 Balbia6989082011-12-15 13:31:48 +020025#include <linux/dma-mapping.h>
Felipe Balbi2ccea032011-06-28 16:33:46 +030026
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 */
40struct usb_udc {
41 struct usb_gadget_driver *driver;
42 struct usb_gadget *gadget;
43 struct device dev;
44 struct list_head list;
45};
46
47static struct class *udc_class;
Felipe Balbi2ccea032011-06-28 16:33:46 +030048static LIST_HEAD(udc_list);
49static DEFINE_MUTEX(udc_lock);
50
51/* ------------------------------------------------------------------------- */
52
Felipe Balbia6989082011-12-15 13:31:48 +020053int 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}
82EXPORT_SYMBOL_GPL(usb_gadget_map_request);
83
84void 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}
100EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
101
102/* ------------------------------------------------------------------------- */
103
Felipe Balbi49401f42011-12-19 12:57:04 +0200104void usb_gadget_set_state(struct usb_gadget *gadget,
105 enum usb_device_state state)
106{
107 gadget->state = state;
Rong Wang8fc2b132013-07-28 23:01:35 +0800108 sysfs_notify(&gadget->dev.kobj, NULL, "state");
Felipe Balbi49401f42011-12-19 12:57:04 +0200109}
110EXPORT_SYMBOL_GPL(usb_gadget_set_state);
111
112/* ------------------------------------------------------------------------- */
113
Felipe Balbi2ccea032011-06-28 16:33:46 +0300114/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200115 * 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 */
128static 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/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200135 * 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 */
146static 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/**
Felipe Balbi2ccea032011-06-28 16:33:46 +0300153 * 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 */
159static 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
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200168static const struct attribute_group *usb_udc_attr_groups[];
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200169
170static void usb_udc_nop_release(struct device *dev)
171{
172 dev_vdbg(dev, "%s\n", __func__);
173}
174
Felipe Balbi2ccea032011-06-28 16:33:46 +0300175/**
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200176 * 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.
Felipe Balbi2ccea032011-06-28 16:33:46 +0300181 *
182 * Returns zero on success, negative errno otherwise.
183 */
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200184int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
185 void (*release)(struct device *dev))
Felipe Balbi2ccea032011-06-28 16:33:46 +0300186{
187 struct usb_udc *udc;
188 int ret = -ENOMEM;
189
190 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
191 if (!udc)
192 goto err1;
193
Felipe Balbi7bce4012013-01-24 17:41:00 +0200194 dev_set_name(&gadget->dev, "gadget");
Felipe Balbi2ed14322013-02-26 10:59:41 +0200195 gadget->dev.parent = parent;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200196
Felipe Balbi658c8cf2013-02-26 10:50:42 +0200197 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
Felipe Balbiddf47cc2013-02-26 15:25:41 +0200201 if (release)
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200202 gadget->dev.release = release;
Felipe Balbiddf47cc2013-02-26 15:25:41 +0200203 else
204 gadget->dev.release = usb_udc_nop_release;
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200205
Felipe Balbi7bce4012013-01-24 17:41:00 +0200206 ret = device_register(&gadget->dev);
207 if (ret)
208 goto err2;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200209
Felipe Balbi2ccea032011-06-28 16:33:46 +0300210 device_initialize(&udc->dev);
211 udc->dev.release = usb_udc_release;
212 udc->dev.class = udc_class;
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200213 udc->dev.groups = usb_udc_attr_groups;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300214 udc->dev.parent = parent;
215 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
216 if (ret)
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200217 goto err3;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300218
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)
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200226 goto err4;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300227
Felipe Balbi49401f42011-12-19 12:57:04 +0200228 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
229
Felipe Balbi2ccea032011-06-28 16:33:46 +0300230 mutex_unlock(&udc_lock);
231
232 return 0;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200233
234err4:
Felipe Balbi2ccea032011-06-28 16:33:46 +0300235 list_del(&udc->list);
236 mutex_unlock(&udc_lock);
237
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200238err3:
Felipe Balbi2ccea032011-06-28 16:33:46 +0300239 put_device(&udc->dev);
240
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200241err2:
Felipe Balbi7bce4012013-01-24 17:41:00 +0200242 put_device(&gadget->dev);
Felipe Balbic5dbc222013-04-02 17:06:28 +0300243 kfree(udc);
Felipe Balbi7bce4012013-01-24 17:41:00 +0200244
Felipe Balbi2ccea032011-06-28 16:33:46 +0300245err1:
246 return ret;
247}
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200248EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
249
Felipe Balbi2ccea032011-06-28 16:33:46 +0300250/**
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 */
258int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
259{
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200260 return usb_add_gadget_udc_release(parent, gadget, NULL);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300261}
262EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
263
264static 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
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200271 usb_gadget_disconnect(udc->gadget);
272 udc->driver->disconnect(udc->gadget);
273 udc->driver->unbind(udc->gadget);
Alan Stern511f3c52013-03-15 14:02:14 -0400274 usb_gadget_udc_stop(udc->gadget, NULL);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300275
276 udc->driver = NULL;
277 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200278 udc->gadget->dev.driver = NULL;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300279}
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 */
288void 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
302found:
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);
Felipe Balbi7bce4012013-01-24 17:41:00 +0200313 device_unregister(&gadget->dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300314}
315EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
316
317/* ------------------------------------------------------------------------- */
318
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100319static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
Felipe Balbi2ccea032011-06-28 16:33:46 +0300320{
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100321 int ret;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300322
Felipe Balbi2ccea032011-06-28 16:33:46 +0300323 dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
324 driver->function);
325
326 udc->driver = driver;
327 udc->dev.driver = &driver->driver;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200328 udc->gadget->dev.driver = &driver->driver;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300329
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200330 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;
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200337 }
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200338 usb_gadget_connect(udc->gadget);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300339
340 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300341 return 0;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300342err1:
343 dev_err(&udc->dev, "failed to start %s: %d\n",
344 udc->driver->function, ret);
345 udc->driver = NULL;
346 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200347 udc->gadget->dev.driver = NULL;
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100348 return ret;
349}
350
351int udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
352{
353 struct usb_udc *udc = NULL;
354 int ret = -ENODEV;
355
356 mutex_lock(&udc_lock);
357 list_for_each_entry(udc, &udc_list, list) {
358 ret = strcmp(name, dev_name(&udc->dev));
359 if (!ret)
360 break;
361 }
362 if (ret) {
363 ret = -ENODEV;
364 goto out;
365 }
366 if (udc->driver) {
367 ret = -EBUSY;
368 goto out;
369 }
370 ret = udc_bind_to_driver(udc, driver);
371out:
372 mutex_unlock(&udc_lock);
373 return ret;
374}
375EXPORT_SYMBOL_GPL(udc_attach_driver);
376
377int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
378{
379 struct usb_udc *udc = NULL;
380 int ret;
381
382 if (!driver || !driver->bind || !driver->setup)
383 return -EINVAL;
384
385 mutex_lock(&udc_lock);
386 list_for_each_entry(udc, &udc_list, list) {
387 /* For now we take the first one */
388 if (!udc->driver)
389 goto found;
390 }
391
392 pr_debug("couldn't find an available UDC\n");
393 mutex_unlock(&udc_lock);
394 return -ENODEV;
395found:
396 ret = udc_bind_to_driver(udc, driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300397 mutex_unlock(&udc_lock);
398 return ret;
399}
400EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
401
402int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
403{
404 struct usb_udc *udc = NULL;
405 int ret = -ENODEV;
406
407 if (!driver || !driver->unbind)
408 return -EINVAL;
409
410 mutex_lock(&udc_lock);
411 list_for_each_entry(udc, &udc_list, list)
412 if (udc->driver == driver) {
413 usb_gadget_remove_driver(udc);
414 ret = 0;
415 break;
416 }
417
418 mutex_unlock(&udc_lock);
419 return ret;
420}
421EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
422
423/* ------------------------------------------------------------------------- */
424
425static ssize_t usb_udc_srp_store(struct device *dev,
426 struct device_attribute *attr, const char *buf, size_t n)
427{
Felipe Balbi1d91a962011-09-08 14:11:17 +0300428 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300429
430 if (sysfs_streq(buf, "1"))
431 usb_gadget_wakeup(udc->gadget);
432
433 return n;
434}
435static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
436
437static ssize_t usb_udc_softconn_store(struct device *dev,
438 struct device_attribute *attr, const char *buf, size_t n)
439{
Felipe Balbi865569b2011-09-08 14:12:18 +0300440 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300441
Felipe Balbi42a1d032014-11-10 09:06:20 -0600442 if (!udc->driver) {
443 dev_err(dev, "soft-connect without a gadget driver\n");
444 return -EOPNOTSUPP;
445 }
446
Felipe Balbi2ccea032011-06-28 16:33:46 +0300447 if (sysfs_streq(buf, "connect")) {
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200448 usb_gadget_udc_start(udc->gadget, udc->driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300449 usb_gadget_connect(udc->gadget);
450 } else if (sysfs_streq(buf, "disconnect")) {
Felipe Balbi83a787a2012-04-27 11:02:15 +0300451 usb_gadget_disconnect(udc->gadget);
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200452 usb_gadget_udc_stop(udc->gadget, udc->driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300453 } else {
454 dev_err(dev, "unsupported command '%s'\n", buf);
455 return -EINVAL;
456 }
457
458 return n;
459}
460static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
461
Felipe Balbi49401f42011-12-19 12:57:04 +0200462static ssize_t usb_gadget_state_show(struct device *dev,
463 struct device_attribute *attr, char *buf)
464{
465 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
466 struct usb_gadget *gadget = udc->gadget;
467
468 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
469}
470static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL);
471
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100472#define USB_UDC_SPEED_ATTR(name, param) \
473ssize_t usb_udc_##param##_show(struct device *dev, \
474 struct device_attribute *attr, char *buf) \
475{ \
476 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
477 return snprintf(buf, PAGE_SIZE, "%s\n", \
478 usb_speed_string(udc->gadget->param)); \
479} \
Felipe Balbia5fcb062013-02-26 19:15:14 +0200480static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL)
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100481
482static USB_UDC_SPEED_ATTR(current_speed, speed);
483static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
484
Felipe Balbi2ccea032011-06-28 16:33:46 +0300485#define USB_UDC_ATTR(name) \
486ssize_t usb_udc_##name##_show(struct device *dev, \
487 struct device_attribute *attr, char *buf) \
488{ \
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200489 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
Felipe Balbi2ccea032011-06-28 16:33:46 +0300490 struct usb_gadget *gadget = udc->gadget; \
491 \
492 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
493} \
Felipe Balbi59d81f82011-10-03 16:43:56 +0300494static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL)
Felipe Balbi2ccea032011-06-28 16:33:46 +0300495
Felipe Balbi2ccea032011-06-28 16:33:46 +0300496static USB_UDC_ATTR(is_otg);
497static USB_UDC_ATTR(is_a_peripheral);
498static USB_UDC_ATTR(b_hnp_enable);
499static USB_UDC_ATTR(a_hnp_support);
500static USB_UDC_ATTR(a_alt_hnp_support);
501
502static struct attribute *usb_udc_attrs[] = {
503 &dev_attr_srp.attr,
504 &dev_attr_soft_connect.attr,
Felipe Balbi49401f42011-12-19 12:57:04 +0200505 &dev_attr_state.attr,
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100506 &dev_attr_current_speed.attr,
507 &dev_attr_maximum_speed.attr,
Felipe Balbi2ccea032011-06-28 16:33:46 +0300508
Felipe Balbi2ccea032011-06-28 16:33:46 +0300509 &dev_attr_is_otg.attr,
510 &dev_attr_is_a_peripheral.attr,
511 &dev_attr_b_hnp_enable.attr,
512 &dev_attr_a_hnp_support.attr,
513 &dev_attr_a_alt_hnp_support.attr,
514 NULL,
515};
516
517static const struct attribute_group usb_udc_attr_group = {
518 .attrs = usb_udc_attrs,
519};
520
521static const struct attribute_group *usb_udc_attr_groups[] = {
522 &usb_udc_attr_group,
523 NULL,
524};
525
526static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
527{
528 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
529 int ret;
530
531 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
532 if (ret) {
533 dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
534 return ret;
535 }
536
537 if (udc->driver) {
538 ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
539 udc->driver->function);
540 if (ret) {
541 dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
542 return ret;
543 }
544 }
545
546 return 0;
547}
548
549static int __init usb_udc_init(void)
550{
551 udc_class = class_create(THIS_MODULE, "udc");
552 if (IS_ERR(udc_class)) {
553 pr_err("failed to create udc class --> %ld\n",
554 PTR_ERR(udc_class));
555 return PTR_ERR(udc_class);
556 }
557
558 udc_class->dev_uevent = usb_udc_uevent;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300559 return 0;
560}
561subsys_initcall(usb_udc_init);
562
563static void __exit usb_udc_exit(void)
564{
565 class_destroy(udc_class);
566}
567module_exit(usb_udc_exit);
568
569MODULE_DESCRIPTION("UDC Framework");
570MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
571MODULE_LICENSE("GPL v2");