diff options
author | Felipe Balbi <balbi@ti.com> | 2011-12-19 05:57:04 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-03-18 05:17:12 -0400 |
commit | 49401f4169c0e5a1b38f1a676d6f12eecaf77485 (patch) | |
tree | 274f68e04c13e7bf959cd7878eb22ffde16813b6 | |
parent | d1e3d757f7aa91f15db347fc05ffd7ef7f413091 (diff) |
usb: gadget: introduce gadget state tracking
that's useful information to expose to userland.
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/gadget/udc-core.c | 23 | ||||
-rw-r--r-- | include/linux/usb/gadget.h | 9 |
2 files changed, 32 insertions, 0 deletions
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 40b1d888d5a1..8a1eeb24ae6a 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -101,6 +101,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); | |||
101 | 101 | ||
102 | /* ------------------------------------------------------------------------- */ | 102 | /* ------------------------------------------------------------------------- */ |
103 | 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, "status"); | ||
109 | } | ||
110 | EXPORT_SYMBOL_GPL(usb_gadget_set_state); | ||
111 | |||
112 | /* ------------------------------------------------------------------------- */ | ||
113 | |||
104 | /** | 114 | /** |
105 | * usb_gadget_udc_start - tells usb device controller to start up | 115 | * usb_gadget_udc_start - tells usb device controller to start up |
106 | * @gadget: The gadget we want to get started | 116 | * @gadget: The gadget we want to get started |
@@ -197,6 +207,8 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | |||
197 | if (ret) | 207 | if (ret) |
198 | goto err4; | 208 | goto err4; |
199 | 209 | ||
210 | usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); | ||
211 | |||
200 | mutex_unlock(&udc_lock); | 212 | mutex_unlock(&udc_lock); |
201 | 213 | ||
202 | return 0; | 214 | return 0; |
@@ -406,6 +418,16 @@ static ssize_t usb_udc_softconn_store(struct device *dev, | |||
406 | } | 418 | } |
407 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); | 419 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); |
408 | 420 | ||
421 | static ssize_t usb_gadget_state_show(struct device *dev, | ||
422 | struct device_attribute *attr, char *buf) | ||
423 | { | ||
424 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); | ||
425 | struct usb_gadget *gadget = udc->gadget; | ||
426 | |||
427 | return sprintf(buf, "%s\n", usb_state_string(gadget->state)); | ||
428 | } | ||
429 | static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL); | ||
430 | |||
409 | #define USB_UDC_SPEED_ATTR(name, param) \ | 431 | #define USB_UDC_SPEED_ATTR(name, param) \ |
410 | ssize_t usb_udc_##param##_show(struct device *dev, \ | 432 | ssize_t usb_udc_##param##_show(struct device *dev, \ |
411 | struct device_attribute *attr, char *buf) \ | 433 | struct device_attribute *attr, char *buf) \ |
@@ -439,6 +461,7 @@ static USB_UDC_ATTR(a_alt_hnp_support); | |||
439 | static struct attribute *usb_udc_attrs[] = { | 461 | static struct attribute *usb_udc_attrs[] = { |
440 | &dev_attr_srp.attr, | 462 | &dev_attr_srp.attr, |
441 | &dev_attr_soft_connect.attr, | 463 | &dev_attr_soft_connect.attr, |
464 | &dev_attr_state.attr, | ||
442 | &dev_attr_current_speed.attr, | 465 | &dev_attr_current_speed.attr, |
443 | &dev_attr_maximum_speed.attr, | 466 | &dev_attr_maximum_speed.attr, |
444 | 467 | ||
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 2e297e80d59a..32b734d88d6b 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h | |||
@@ -482,6 +482,7 @@ struct usb_gadget_ops { | |||
482 | * @speed: Speed of current connection to USB host. | 482 | * @speed: Speed of current connection to USB host. |
483 | * @max_speed: Maximal speed the UDC can handle. UDC must support this | 483 | * @max_speed: Maximal speed the UDC can handle. UDC must support this |
484 | * and all slower speeds. | 484 | * and all slower speeds. |
485 | * @state: the state we are now (attached, suspended, configured, etc) | ||
485 | * @sg_supported: true if we can handle scatter-gather | 486 | * @sg_supported: true if we can handle scatter-gather |
486 | * @is_otg: True if the USB device port uses a Mini-AB jack, so that the | 487 | * @is_otg: True if the USB device port uses a Mini-AB jack, so that the |
487 | * gadget driver must provide a USB OTG descriptor. | 488 | * gadget driver must provide a USB OTG descriptor. |
@@ -525,6 +526,7 @@ struct usb_gadget { | |||
525 | struct list_head ep_list; /* of usb_ep */ | 526 | struct list_head ep_list; /* of usb_ep */ |
526 | enum usb_device_speed speed; | 527 | enum usb_device_speed speed; |
527 | enum usb_device_speed max_speed; | 528 | enum usb_device_speed max_speed; |
529 | enum usb_device_state state; | ||
528 | unsigned sg_supported:1; | 530 | unsigned sg_supported:1; |
529 | unsigned is_otg:1; | 531 | unsigned is_otg:1; |
530 | unsigned is_a_peripheral:1; | 532 | unsigned is_a_peripheral:1; |
@@ -959,6 +961,13 @@ extern void usb_gadget_unmap_request(struct usb_gadget *gadget, | |||
959 | 961 | ||
960 | /*-------------------------------------------------------------------------*/ | 962 | /*-------------------------------------------------------------------------*/ |
961 | 963 | ||
964 | /* utility to set gadget state properly */ | ||
965 | |||
966 | extern void usb_gadget_set_state(struct usb_gadget *gadget, | ||
967 | enum usb_device_state state); | ||
968 | |||
969 | /*-------------------------------------------------------------------------*/ | ||
970 | |||
962 | /* utility wrapping a simple endpoint selection policy */ | 971 | /* utility wrapping a simple endpoint selection policy */ |
963 | 972 | ||
964 | extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, | 973 | extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, |