summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINSUN PYO <insun.pyo@samsung.com>2020-01-28 04:20:15 (GMT)
committerINSUN PYO <insun.pyo@samsung.com>2020-01-28 04:47:34 (GMT)
commit641eca1920c453595651fea10bc5ee5185081880 (patch)
treeeff2b4772e94d307e8daac9f142f9fa79469ec08
parentdc203c1e3bc1da489b6e26e5c2c922f17e778404 (diff)
downloadlibdevice-node-641eca1920c453595651fea10bc5ee5185081880.zip
libdevice-node-641eca1920c453595651fea10bc5ee5185081880.tar.gz
libdevice-node-641eca1920c453595651fea10bc5ee5185081880.tar.bz2
Change-Id: I2a488ef551a3c92a36cfa428787cdfdd31f82cab (cherry picked from commit 2dbaad820b5f0ca6c9b59ac61c3c14460775f915)
-rw-r--r--hw/usb_cfs_client_common.c6
-rw-r--r--hw/usb_client_common.c19
-rw-r--r--hw/usb_gadget.h44
3 files changed, 44 insertions, 25 deletions
diff --git a/hw/usb_cfs_client_common.c b/hw/usb_cfs_client_common.c
index 03a61d1..99d5923 100644
--- a/hw/usb_cfs_client_common.c
+++ b/hw/usb_cfs_client_common.c
@@ -838,6 +838,9 @@ static int cfs_enable(struct usb_client *usb)
for (i = 0; gadget->funcs[i]; ++i) {
func = gadget->funcs[i];
+ if (func->handler)
+ func->handler(1);
+
if (func->service)
(void)systemd_start_unit_wait_started(func->service, ".service", -1);
}
@@ -867,6 +870,9 @@ static int cfs_disable(struct usb_client *usb)
if (func->service)
(void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
+
+ if (func->handler)
+ func->handler(0);
}
cfs_free_gadget(gadget);
diff --git a/hw/usb_client_common.c b/hw/usb_client_common.c
index 2726049..ad1208e 100644
--- a/hw/usb_client_common.c
+++ b/hw/usb_client_common.c
@@ -463,15 +463,13 @@ static int legacy_set_gadget_strs(struct usb_gadget_strings *strs)
*/
if (strs->manufacturer) {
- ret = sys_set_str(LEGACY_IMANUFACTURER_PATH,
- strs->manufacturer);
+ ret = sys_set_str(LEGACY_IMANUFACTURER_PATH, strs->manufacturer);
if (ret)
return ret;
}
if (strs->product) {
- ret = sys_set_str(LEGACY_IPRODUCT_PATH,
- strs->product);
+ ret = sys_set_str(LEGACY_IPRODUCT_PATH, strs->product);
if (ret)
return ret;
}
@@ -540,13 +538,12 @@ static int legacy_reconfigure_gadget(struct usb_client *usb,
static int legacy_enable(struct usb_client *usb)
{
- int ret;
int i;
+ int ret;
struct usb_gadget *gadget;
struct usb_function *func;
- ret = sys_set_str(LEGACY_ENABLE_PATH,
- LEGACY_ENABLE);
+ ret = sys_set_str(LEGACY_ENABLE_PATH, LEGACY_ENABLE);
if (ret < 0)
return ret;
@@ -557,6 +554,9 @@ static int legacy_enable(struct usb_client *usb)
for (i = 0; gadget->funcs[i]; ++i) {
func = gadget->funcs[i];
+ if (func->handler)
+ func->handler(1);
+
/*
* Reuse configfs data structure to simplify design.
* Configfs has a special service for functionfs. (E.g. sdbd and mtp-responder)
@@ -579,8 +579,8 @@ disable_gadget:
static int legacy_disable(struct usb_client *usb)
{
- int ret;
int i;
+ int ret;
struct usb_gadget *gadget;
struct usb_function *func;
@@ -601,6 +601,9 @@ static int legacy_disable(struct usb_client *usb)
if (func->ffs_service)
(void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1);
+
+ if (func->handler)
+ func->handler(0);
}
ret = sys_set_str(LEGACY_ENABLE_PATH, LEGACY_DISABLE);
diff --git a/hw/usb_gadget.h b/hw/usb_gadget.h
index 629504a..8533228 100644
--- a/hw/usb_gadget.h
+++ b/hw/usb_gadget.h
@@ -50,6 +50,13 @@
/* Function IDX in array is number of trailing zeros */
#define FUNC_IDX_FROM_MASK(mask) _HELPER_CTZ(mask)
+/*
+ * legacy enable : enable gadget -> handler(1) -> ffs_service start -> service start
+ * legacy disable : service stop -> ffs_service stop -> handler(0) -> disable gadget
+ *
+ * configfs enable : ffs_service start -> enable gadget -> handler(1) -> service start
+ * configfs disable : service stop -> handler(0) -> disable gadget (ffs_service is never stopped until changing usb mode)
+ */
struct usb_function {
int id;
const char *name;
@@ -58,6 +65,8 @@ struct usb_function {
const char *ffs_service; /* only used in configfs */
const char *service;
+ void (*handler)(int enable);
+
int (*clone)(struct usb_function *func, struct usb_function **_clone);
void (*free_func)(struct usb_function *func);
};
@@ -156,25 +165,26 @@ out_nomem:
return -ENOMEM;
}
-#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service) \
- static struct usb_function _##_name##_function = { \
- .id = _id, \
- .name = #_name, \
- .instance = "default", \
- .ffs_service = _ffs_service, \
- .service = _service, \
- .clone = clone_simple_func, \
- .free_func = free_simple_func, \
+#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service, _handler) \
+ static struct usb_function _##_name##_function = { \
+ .id = _id, \
+ .name = #_name, \
+ .instance = "default", \
+ .ffs_service = _ffs_service, \
+ .service = _service, \
+ .handler = _handler, \
+ .clone = clone_simple_func, \
+ .free_func = free_simple_func, \
}
-DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, "sdbd", NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, "mtp-responder", NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, NULL, "data-router");
-DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "rndis");
+DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, NULL, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, NULL, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, NULL, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, "sdbd", NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, "mtp-responder", NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, NULL, "data-router", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "rndis", NULL);
#undef DEFINE_USB_FUNCTION
#define MAKE_FUNC_AVAILABLE(_name, _vname) \