usb: gadget: introduce gadget state tracking
authorFelipe Balbi <balbi@ti.com>
Mon, 19 Dec 2011 10:57:04 +0000 (12:57 +0200)
committerFelipe Balbi <balbi@ti.com>
Mon, 18 Mar 2013 09:17:12 +0000 (11:17 +0200)
that's useful information to expose to userland.

Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/udc-core.c
include/linux/usb/gadget.h

index 40b1d888d5a11e83a1df6d67dd6121f303af33fa..8a1eeb24ae6a13ad7d98bfe5287b37f2b2fd20fd 100644 (file)
@@ -101,6 +101,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 
 /* ------------------------------------------------------------------------- */
 
+void usb_gadget_set_state(struct usb_gadget *gadget,
+               enum usb_device_state state)
+{
+       gadget->state = state;
+       sysfs_notify(&gadget->dev.kobj, NULL, "status");
+}
+EXPORT_SYMBOL_GPL(usb_gadget_set_state);
+
+/* ------------------------------------------------------------------------- */
+
 /**
  * usb_gadget_udc_start - tells usb device controller to start up
  * @gadget: The gadget we want to get started
@@ -197,6 +207,8 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
        if (ret)
                goto err4;
 
+       usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
+
        mutex_unlock(&udc_lock);
 
        return 0;
@@ -406,6 +418,16 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
 }
 static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
 
+static ssize_t usb_gadget_state_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct usb_udc          *udc = container_of(dev, struct usb_udc, dev);
+       struct usb_gadget       *gadget = udc->gadget;
+
+       return sprintf(buf, "%s\n", usb_state_string(gadget->state));
+}
+static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL);
+
 #define USB_UDC_SPEED_ATTR(name, param)                                        \
 ssize_t usb_udc_##param##_show(struct device *dev,                     \
                struct device_attribute *attr, char *buf)               \
@@ -439,6 +461,7 @@ static USB_UDC_ATTR(a_alt_hnp_support);
 static struct attribute *usb_udc_attrs[] = {
        &dev_attr_srp.attr,
        &dev_attr_soft_connect.attr,
+       &dev_attr_state.attr,
        &dev_attr_current_speed.attr,
        &dev_attr_maximum_speed.attr,
 
index 2e297e80d59a81b0a42cf54098030b12e48125ad..32b734d88d6bb3cdd601e4e8da33d6ca7083def4 100644 (file)
@@ -482,6 +482,7 @@ struct usb_gadget_ops {
  * @speed: Speed of current connection to USB host.
  * @max_speed: Maximal speed the UDC can handle.  UDC must support this
  *      and all slower speeds.
+ * @state: the state we are now (attached, suspended, configured, etc)
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  *     gadget driver must provide a USB OTG descriptor.
@@ -525,6 +526,7 @@ struct usb_gadget {
        struct list_head                ep_list;        /* of usb_ep */
        enum usb_device_speed           speed;
        enum usb_device_speed           max_speed;
+       enum usb_device_state           state;
        unsigned                        sg_supported:1;
        unsigned                        is_otg:1;
        unsigned                        is_a_peripheral:1;
@@ -959,6 +961,13 @@ extern void usb_gadget_unmap_request(struct usb_gadget *gadget,
 
 /*-------------------------------------------------------------------------*/
 
+/* utility to set gadget state properly */
+
+extern void usb_gadget_set_state(struct usb_gadget *gadget,
+               enum usb_device_state state);
+
+/*-------------------------------------------------------------------------*/
+
 /* utility wrapping a simple endpoint selection policy */
 
 extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
This page took 0.028568 seconds and 5 git commands to generate.