blob: 3122ab942f75bcab0685f00d692423012705cfd8 [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 Balbi5702f752013-07-17 11:09:49 +030026#include <linux/workqueue.h>
Felipe Balbi2ccea032011-06-28 16:33:46 +030027
28#include <linux/usb/ch9.h>
29#include <linux/usb/gadget.h>
30
31/**
32 * struct usb_udc - describes one usb device controller
33 * @driver - the gadget driver pointer. For use by the class code
34 * @dev - the child device to the actual controller
35 * @gadget - the gadget. For use by the class code
36 * @list - for use by the udc class driver
37 *
38 * This represents the internal data structure which is used by the UDC-class
39 * to hold information about udc driver and gadget together.
40 */
41struct usb_udc {
42 struct usb_gadget_driver *driver;
43 struct usb_gadget *gadget;
44 struct device dev;
45 struct list_head list;
46};
47
48static struct class *udc_class;
Felipe Balbi2ccea032011-06-28 16:33:46 +030049static LIST_HEAD(udc_list);
50static DEFINE_MUTEX(udc_lock);
51
52/* ------------------------------------------------------------------------- */
53
Alan Stern908b9612013-07-12 11:06:21 -040054#ifdef CONFIG_HAS_DMA
55
Felipe Balbia6989082011-12-15 13:31:48 +020056int usb_gadget_map_request(struct usb_gadget *gadget,
57 struct usb_request *req, int is_in)
58{
59 if (req->length == 0)
60 return 0;
61
62 if (req->num_sgs) {
63 int mapped;
64
65 mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs,
66 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
67 if (mapped == 0) {
68 dev_err(&gadget->dev, "failed to map SGs\n");
69 return -EFAULT;
70 }
71
72 req->num_mapped_sgs = mapped;
73 } else {
74 req->dma = dma_map_single(&gadget->dev, req->buf, req->length,
75 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
76
77 if (dma_mapping_error(&gadget->dev, req->dma)) {
78 dev_err(&gadget->dev, "failed to map buffer\n");
79 return -EFAULT;
80 }
81 }
82
83 return 0;
84}
85EXPORT_SYMBOL_GPL(usb_gadget_map_request);
86
87void usb_gadget_unmap_request(struct usb_gadget *gadget,
88 struct usb_request *req, int is_in)
89{
90 if (req->length == 0)
91 return;
92
93 if (req->num_mapped_sgs) {
94 dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs,
95 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
96
97 req->num_mapped_sgs = 0;
98 } else {
99 dma_unmap_single(&gadget->dev, req->dma, req->length,
100 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
101 }
102}
103EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
104
Alan Stern908b9612013-07-12 11:06:21 -0400105#endif /* CONFIG_HAS_DMA */
106
Felipe Balbia6989082011-12-15 13:31:48 +0200107/* ------------------------------------------------------------------------- */
108
Felipe Balbi5702f752013-07-17 11:09:49 +0300109static void usb_gadget_state_work(struct work_struct *work)
110{
111 struct usb_gadget *gadget = work_to_gadget(work);
112
113 sysfs_notify(&gadget->dev.kobj, NULL, "status");
114}
115
Felipe Balbi49401f42011-12-19 12:57:04 +0200116void usb_gadget_set_state(struct usb_gadget *gadget,
117 enum usb_device_state state)
118{
119 gadget->state = state;
Felipe Balbi5702f752013-07-17 11:09:49 +0300120 schedule_work(&gadget->work);
Felipe Balbi49401f42011-12-19 12:57:04 +0200121}
122EXPORT_SYMBOL_GPL(usb_gadget_set_state);
123
124/* ------------------------------------------------------------------------- */
125
Felipe Balbi2ccea032011-06-28 16:33:46 +0300126/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200127 * usb_gadget_udc_start - tells usb device controller to start up
128 * @gadget: The gadget we want to get started
129 * @driver: The driver we want to bind to @gadget
130 *
131 * This call is issued by the UDC Class driver when it's about
132 * to register a gadget driver to the device controller, before
133 * calling gadget driver's bind() method.
134 *
135 * It allows the controller to be powered off until strictly
136 * necessary to have it powered on.
137 *
138 * Returns zero on success, else negative errno.
139 */
140static inline int usb_gadget_udc_start(struct usb_gadget *gadget,
141 struct usb_gadget_driver *driver)
142{
143 return gadget->ops->udc_start(gadget, driver);
144}
145
146/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200147 * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
148 * @gadget: The device we want to stop activity
149 * @driver: The driver to unbind from @gadget
150 *
151 * This call is issued by the UDC Class driver after calling
152 * gadget driver's unbind() method.
153 *
154 * The details are implementation specific, but it can go as
155 * far as powering off UDC completely and disable its data
156 * line pullups.
157 */
158static inline void usb_gadget_udc_stop(struct usb_gadget *gadget,
159 struct usb_gadget_driver *driver)
160{
161 gadget->ops->udc_stop(gadget, driver);
162}
163
164/**
Felipe Balbi2ccea032011-06-28 16:33:46 +0300165 * usb_udc_release - release the usb_udc struct
166 * @dev: the dev member within usb_udc
167 *
168 * This is called by driver's core in order to free memory once the last
169 * reference is released.
170 */
171static void usb_udc_release(struct device *dev)
172{
173 struct usb_udc *udc;
174
175 udc = container_of(dev, struct usb_udc, dev);
176 dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
177 kfree(udc);
178}
179
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200180static const struct attribute_group *usb_udc_attr_groups[];
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200181
182static void usb_udc_nop_release(struct device *dev)
183{
184 dev_vdbg(dev, "%s\n", __func__);
185}
186
Felipe Balbi2ccea032011-06-28 16:33:46 +0300187/**
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200188 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
189 * @parent: the parent device to this udc. Usually the controller driver's
190 * device.
191 * @gadget: the gadget to be added to the list.
192 * @release: a gadget release function.
Felipe Balbi2ccea032011-06-28 16:33:46 +0300193 *
194 * Returns zero on success, negative errno otherwise.
195 */
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200196int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
197 void (*release)(struct device *dev))
Felipe Balbi2ccea032011-06-28 16:33:46 +0300198{
199 struct usb_udc *udc;
200 int ret = -ENOMEM;
201
202 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
203 if (!udc)
204 goto err1;
205
Felipe Balbi7bce4012013-01-24 17:41:00 +0200206 dev_set_name(&gadget->dev, "gadget");
Felipe Balbi5702f752013-07-17 11:09:49 +0300207 INIT_WORK(&gadget->work, usb_gadget_state_work);
Felipe Balbi2ed14322013-02-26 10:59:41 +0200208 gadget->dev.parent = parent;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200209
Alan Stern908b9612013-07-12 11:06:21 -0400210#ifdef CONFIG_HAS_DMA
Felipe Balbi658c8cf2013-02-26 10:50:42 +0200211 dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask);
212 gadget->dev.dma_parms = parent->dma_parms;
213 gadget->dev.dma_mask = parent->dma_mask;
Alan Stern908b9612013-07-12 11:06:21 -0400214#endif
Felipe Balbi658c8cf2013-02-26 10:50:42 +0200215
Felipe Balbiddf47cc2013-02-26 15:25:41 +0200216 if (release)
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200217 gadget->dev.release = release;
Felipe Balbiddf47cc2013-02-26 15:25:41 +0200218 else
219 gadget->dev.release = usb_udc_nop_release;
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200220
Felipe Balbi7bce4012013-01-24 17:41:00 +0200221 ret = device_register(&gadget->dev);
222 if (ret)
223 goto err2;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200224
Felipe Balbi2ccea032011-06-28 16:33:46 +0300225 device_initialize(&udc->dev);
226 udc->dev.release = usb_udc_release;
227 udc->dev.class = udc_class;
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200228 udc->dev.groups = usb_udc_attr_groups;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300229 udc->dev.parent = parent;
230 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
231 if (ret)
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200232 goto err3;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300233
234 udc->gadget = gadget;
235
236 mutex_lock(&udc_lock);
237 list_add_tail(&udc->list, &udc_list);
238
239 ret = device_add(&udc->dev);
240 if (ret)
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200241 goto err4;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300242
Felipe Balbi49401f42011-12-19 12:57:04 +0200243 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
244
Felipe Balbi2ccea032011-06-28 16:33:46 +0300245 mutex_unlock(&udc_lock);
246
247 return 0;
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200248
249err4:
Felipe Balbi2ccea032011-06-28 16:33:46 +0300250 list_del(&udc->list);
251 mutex_unlock(&udc_lock);
252
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200253err3:
Felipe Balbi2ccea032011-06-28 16:33:46 +0300254 put_device(&udc->dev);
255
Felipe Balbif07bd56b2013-01-24 14:52:24 +0200256err2:
Felipe Balbi7bce4012013-01-24 17:41:00 +0200257 put_device(&gadget->dev);
Felipe Balbic5dbc222013-04-02 17:06:28 +0300258 kfree(udc);
Felipe Balbi7bce4012013-01-24 17:41:00 +0200259
Felipe Balbi2ccea032011-06-28 16:33:46 +0300260err1:
261 return ret;
262}
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200263EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
264
Felipe Balbi2ccea032011-06-28 16:33:46 +0300265/**
266 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
267 * @parent: the parent device to this udc. Usually the controller
268 * driver's device.
269 * @gadget: the gadget to be added to the list
270 *
271 * Returns zero on success, negative errno otherwise.
272 */
273int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
274{
Felipe Balbi792bfcf2013-02-26 14:47:44 +0200275 return usb_add_gadget_udc_release(parent, gadget, NULL);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300276}
277EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
278
279static void usb_gadget_remove_driver(struct usb_udc *udc)
280{
281 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
282 udc->gadget->name);
283
284 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
285
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200286 usb_gadget_disconnect(udc->gadget);
287 udc->driver->disconnect(udc->gadget);
288 udc->driver->unbind(udc->gadget);
Alan Stern511f3c52013-03-15 14:02:14 -0400289 usb_gadget_udc_stop(udc->gadget, NULL);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300290
291 udc->driver = NULL;
292 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200293 udc->gadget->dev.driver = NULL;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300294}
295
296/**
297 * usb_del_gadget_udc - deletes @udc from udc_list
298 * @gadget: the gadget to be removed.
299 *
300 * This, will call usb_gadget_unregister_driver() if
301 * the @udc is still busy.
302 */
303void usb_del_gadget_udc(struct usb_gadget *gadget)
304{
305 struct usb_udc *udc = NULL;
306
307 mutex_lock(&udc_lock);
308 list_for_each_entry(udc, &udc_list, list)
309 if (udc->gadget == gadget)
310 goto found;
311
312 dev_err(gadget->dev.parent, "gadget not registered.\n");
313 mutex_unlock(&udc_lock);
314
315 return;
316
317found:
318 dev_vdbg(gadget->dev.parent, "unregistering gadget\n");
319
320 list_del(&udc->list);
321 mutex_unlock(&udc_lock);
322
323 if (udc->driver)
324 usb_gadget_remove_driver(udc);
325
326 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
Felipe Balbi5702f752013-07-17 11:09:49 +0300327 flush_work(&gadget->work);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300328 device_unregister(&udc->dev);
Felipe Balbi7bce4012013-01-24 17:41:00 +0200329 device_unregister(&gadget->dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300330}
331EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
332
333/* ------------------------------------------------------------------------- */
334
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100335static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
Felipe Balbi2ccea032011-06-28 16:33:46 +0300336{
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100337 int ret;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300338
Felipe Balbi2ccea032011-06-28 16:33:46 +0300339 dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
340 driver->function);
341
342 udc->driver = driver;
343 udc->dev.driver = &driver->driver;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200344 udc->gadget->dev.driver = &driver->driver;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300345
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200346 ret = driver->bind(udc->gadget, driver);
347 if (ret)
348 goto err1;
349 ret = usb_gadget_udc_start(udc->gadget, driver);
350 if (ret) {
351 driver->unbind(udc->gadget);
352 goto err1;
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +0200353 }
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200354 usb_gadget_connect(udc->gadget);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300355
356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300357 return 0;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300358err1:
359 dev_err(&udc->dev, "failed to start %s: %d\n",
360 udc->driver->function, ret);
361 udc->driver = NULL;
362 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +0200363 udc->gadget->dev.driver = NULL;
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +0100364 return ret;
365}
366
367int udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
368{
369 struct usb_udc *udc = NULL;
370 int ret = -ENODEV;
371
372 mutex_lock(&udc_lock);
373 list_for_each_entry(udc, &udc_list, list) {
374 ret = strcmp(name, dev_name(&udc->dev));
375 if (!ret)
376 break;
377 }
378 if (ret) {
379 ret = -ENODEV;
380 goto out;
381 }
382 if (udc->driver) {
383 ret = -EBUSY;
384 goto out;
385 }
386 ret = udc_bind_to_driver(udc, driver);
387out:
388 mutex_unlock(&udc_lock);
389 return ret;
390}
391EXPORT_SYMBOL_GPL(udc_attach_driver);
392
393int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
394{
395 struct usb_udc *udc = NULL;
396 int ret;
397
398 if (!driver || !driver->bind || !driver->setup)
399 return -EINVAL;
400
401 mutex_lock(&udc_lock);
402 list_for_each_entry(udc, &udc_list, list) {
403 /* For now we take the first one */
404 if (!udc->driver)
405 goto found;
406 }
407
408 pr_debug("couldn't find an available UDC\n");
409 mutex_unlock(&udc_lock);
410 return -ENODEV;
411found:
412 ret = udc_bind_to_driver(udc, driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300413 mutex_unlock(&udc_lock);
414 return ret;
415}
416EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
417
418int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
419{
420 struct usb_udc *udc = NULL;
421 int ret = -ENODEV;
422
423 if (!driver || !driver->unbind)
424 return -EINVAL;
425
426 mutex_lock(&udc_lock);
427 list_for_each_entry(udc, &udc_list, list)
428 if (udc->driver == driver) {
429 usb_gadget_remove_driver(udc);
430 ret = 0;
431 break;
432 }
433
434 mutex_unlock(&udc_lock);
435 return ret;
436}
437EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
438
439/* ------------------------------------------------------------------------- */
440
441static ssize_t usb_udc_srp_store(struct device *dev,
442 struct device_attribute *attr, const char *buf, size_t n)
443{
Felipe Balbi1d91a962011-09-08 14:11:17 +0300444 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300445
446 if (sysfs_streq(buf, "1"))
447 usb_gadget_wakeup(udc->gadget);
448
449 return n;
450}
451static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
452
453static ssize_t usb_udc_softconn_store(struct device *dev,
454 struct device_attribute *attr, const char *buf, size_t n)
455{
Felipe Balbi865569b2011-09-08 14:12:18 +0300456 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300457
458 if (sysfs_streq(buf, "connect")) {
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200459 usb_gadget_udc_start(udc->gadget, udc->driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300460 usb_gadget_connect(udc->gadget);
461 } else if (sysfs_streq(buf, "disconnect")) {
Felipe Balbi83a787a2012-04-27 11:02:15 +0300462 usb_gadget_disconnect(udc->gadget);
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +0200463 usb_gadget_udc_stop(udc->gadget, udc->driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +0300464 } else {
465 dev_err(dev, "unsupported command '%s'\n", buf);
466 return -EINVAL;
467 }
468
469 return n;
470}
471static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
472
Felipe Balbi49401f42011-12-19 12:57:04 +0200473static ssize_t usb_gadget_state_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 struct usb_gadget *gadget = udc->gadget;
478
479 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
480}
481static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL);
482
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100483#define USB_UDC_SPEED_ATTR(name, param) \
484ssize_t usb_udc_##param##_show(struct device *dev, \
485 struct device_attribute *attr, char *buf) \
486{ \
487 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
488 return snprintf(buf, PAGE_SIZE, "%s\n", \
489 usb_speed_string(udc->gadget->param)); \
490} \
Felipe Balbia5fcb062013-02-26 19:15:14 +0200491static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL)
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100492
493static USB_UDC_SPEED_ATTR(current_speed, speed);
494static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
495
Felipe Balbi2ccea032011-06-28 16:33:46 +0300496#define USB_UDC_ATTR(name) \
497ssize_t usb_udc_##name##_show(struct device *dev, \
498 struct device_attribute *attr, char *buf) \
499{ \
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +0200500 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
Felipe Balbi2ccea032011-06-28 16:33:46 +0300501 struct usb_gadget *gadget = udc->gadget; \
502 \
503 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
504} \
Felipe Balbi59d81f82011-10-03 16:43:56 +0300505static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL)
Felipe Balbi2ccea032011-06-28 16:33:46 +0300506
Felipe Balbi2ccea032011-06-28 16:33:46 +0300507static USB_UDC_ATTR(is_otg);
508static USB_UDC_ATTR(is_a_peripheral);
509static USB_UDC_ATTR(b_hnp_enable);
510static USB_UDC_ATTR(a_hnp_support);
511static USB_UDC_ATTR(a_alt_hnp_support);
512
513static struct attribute *usb_udc_attrs[] = {
514 &dev_attr_srp.attr,
515 &dev_attr_soft_connect.attr,
Felipe Balbi49401f42011-12-19 12:57:04 +0200516 &dev_attr_state.attr,
Michal Nazarewiczd327ab52011-11-19 18:27:37 +0100517 &dev_attr_current_speed.attr,
518 &dev_attr_maximum_speed.attr,
Felipe Balbi2ccea032011-06-28 16:33:46 +0300519
Felipe Balbi2ccea032011-06-28 16:33:46 +0300520 &dev_attr_is_otg.attr,
521 &dev_attr_is_a_peripheral.attr,
522 &dev_attr_b_hnp_enable.attr,
523 &dev_attr_a_hnp_support.attr,
524 &dev_attr_a_alt_hnp_support.attr,
525 NULL,
526};
527
528static const struct attribute_group usb_udc_attr_group = {
529 .attrs = usb_udc_attrs,
530};
531
532static const struct attribute_group *usb_udc_attr_groups[] = {
533 &usb_udc_attr_group,
534 NULL,
535};
536
537static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
538{
539 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
540 int ret;
541
542 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
543 if (ret) {
544 dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
545 return ret;
546 }
547
548 if (udc->driver) {
549 ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
550 udc->driver->function);
551 if (ret) {
552 dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
553 return ret;
554 }
555 }
556
557 return 0;
558}
559
560static int __init usb_udc_init(void)
561{
562 udc_class = class_create(THIS_MODULE, "udc");
563 if (IS_ERR(udc_class)) {
564 pr_err("failed to create udc class --> %ld\n",
565 PTR_ERR(udc_class));
566 return PTR_ERR(udc_class);
567 }
568
569 udc_class->dev_uevent = usb_udc_uevent;
Felipe Balbi2ccea032011-06-28 16:33:46 +0300570 return 0;
571}
572subsys_initcall(usb_udc_init);
573
574static void __exit usb_udc_exit(void)
575{
576 class_destroy(udc_class);
577}
578module_exit(usb_udc_exit);
579
580MODULE_DESCRIPTION("UDC Framework");
581MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
582MODULE_LICENSE("GPL v2");