{
struct usb_function *f;
list_for_each_entry(f, &android_config_driver.functions, list) {
- if (product_has_function(p, f) == !!f->hidden)
+ if (product_has_function(p, f) == !!f->disabled)
return 0;
}
return 1;
int disable = !enable;
int product_id;
- if (!!f->hidden != disable) {
- f->hidden = disable;
+ if (!!f->disabled != disable) {
+ usb_function_set_enabled(f, !disable);
#ifdef CONFIG_USB_ANDROID_RNDIS
if (!strcmp(f->name, "rndis")) {
*/
list_for_each_entry(func, &android_config_driver.functions, list) {
if (!strcmp(func->name, "usb_mass_storage")) {
- func->hidden = enable;
+ usb_function_set_enabled(f, !enable);
break;
}
}
char *buf)
{
struct usb_function *f = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", !f->hidden);
+ return sprintf(buf, "%d\n", !f->disabled);
}
static ssize_t enable_store(
if (driver->enable_function)
driver->enable_function(f, value);
else
- f->hidden = !value;
+ usb_function_set_enabled(f, value);
return size;
}
static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
+void usb_function_set_enabled(struct usb_function *f, int enabled)
+{
+ f->disabled = !enabled;
+ kobject_uevent(&f->dev->kobj, KOBJ_CHANGE);
+}
/**
* usb_add_function() - add a function to a configuration
descriptors = f->hs_descriptors;
else
descriptors = f->descriptors;
- if (f->hidden || !descriptors || descriptors[0] == NULL)
+ if (f->disabled || !descriptors || descriptors[0] == NULL)
continue;
status = usb_descriptor_fillbuf(next, len,
(const struct usb_descriptor_header **) descriptors);
if (!f)
break;
- if (f->hidden)
+ if (f->disabled)
continue;
/*
power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
done:
usb_gadget_vbus_draw(gadget, power);
+
+ switch_set_state(&cdev->sdev, number);
+
if (result >= 0 && cdev->delayed_status)
result = USB_GADGET_DELAYED_STATUS;
return result;
if (composite->disconnect)
composite->disconnect(cdev);
spin_unlock_irqrestore(&cdev->lock, flags);
+
+ switch_set_state(&cdev->sdev, 0);
}
/*-------------------------------------------------------------------------*/
kfree(cdev->req->buf);
usb_ep_free_request(gadget->ep0, cdev->req);
}
+ switch_dev_unregister(&cdev->sdev);
device_remove_file(&gadget->dev, &dev_attr_suspended);
kfree(cdev);
set_gadget_data(gadget, NULL);
if (status < 0)
goto fail;
+ cdev->sdev.name = "usb_configuration";
+ status = switch_dev_register(&cdev->sdev);
+ if (status < 0)
+ goto fail;
+
cdev->desc = *composite->dev;
cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
cdev->suspended = 0;
}
+static int
+composite_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ struct usb_function *f = dev_get_drvdata(dev);
+
+ if (!f) {
+ /* this happens when the device is first created */
+ return 0;
+ }
+
+ if (add_uevent_var(env, "FUNCTION=%s", f->name))
+ return -ENOMEM;
+ if (add_uevent_var(env, "ENABLED=%d", !f->disabled))
+ return -ENOMEM;
+ return 0;
+}
+
/*-------------------------------------------------------------------------*/
static struct usb_gadget_driver composite_driver = {
driver->class = class_create(THIS_MODULE, "usb_composite");
if (IS_ERR(driver->class))
return PTR_ERR(driver->class);
+ driver->class->dev_uevent = composite_uevent;
return usb_gadget_probe_driver(&composite_driver, composite_bind);
}
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
+#include <linux/switch.h>
/*
* USB function drivers should return USB_GADGET_DELAYED_STATUS if they
struct usb_descriptor_header **hs_descriptors;
struct usb_configuration *config;
- int hidden;
+
+ /* disabled is zero if the function is enabled */
+ int disabled;
/* REVISIT: bind() functions can be marked __init, which
* makes trouble for section mismatch analysis. See if
int usb_interface_id(struct usb_configuration *, struct usb_function *);
+void usb_function_set_enabled(struct usb_function *, int);
+
/**
* ep_choose - select descriptor endpoint at current device speed
* @g: gadget, connected and running at some speed
/* protects deactivations and delayed_status counts*/
spinlock_t lock;
+
+ struct switch_dev sdev;
};
extern int usb_string_id(struct usb_composite_dev *c);