Add USB_FUNCTION_GROUP_WITH_POST_SERVICE for cfs post service. 21/221221/4 accepted/tizen/unified/20191230.120900 submit/tizen/20191230.073928
authorINSUN PYO <insun.pyo@samsung.com>
Mon, 30 Dec 2019 07:21:12 +0000 (16:21 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 30 Dec 2019 07:30:43 +0000 (07:30 +0000)
To support CFS acm and rndis mode, add new USB_FUNCTION_GROUP_WITH_POST_SERVICE mode.

Legacy mode         : usb prepare --> usb enable --> start sdb, mtp, rndis, and data-router service
CFS sdb, mtp mode   : usb prepare -> start sdb and mtp service -> usb enable
CFS acm, rndis mode : usb prepare -> usb enable -> start acm and rndis service

Change-Id: I7199636d0b2bcfeac068e1c1575e89926c8f7134

hw/usb_cfs_client_common.c
hw/usb_client_common.c
hw/usb_gadget.h

index 5d0ea75..8eff847 100755 (executable)
@@ -497,6 +497,7 @@ static bool cfs_is_function_supported(struct usb_client *usb,
 
        switch (func->function_group) {
        case USB_FUNCTION_GROUP_SIMPLE:
+       case USB_FUNCTION_GROUP_WITH_POST_SERVICE:
                ret = usbg_lookup_function_type(func->name);
                res = ret >= 0;
                break;
@@ -702,6 +703,7 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client,
 
                switch (usb_func->function_group) {
                case USB_FUNCTION_GROUP_SIMPLE:
+               case USB_FUNCTION_GROUP_WITH_POST_SERVICE:
                        type = usbg_lookup_function_type(usb_func->name);
                        if (strlen(usb_func->instance) >= MAX_INSTANCE_LEN)
                                return -ENAMETOOLONG;
index abfa6b2..fab8ea1 100755 (executable)
@@ -555,8 +555,7 @@ static int legacy_enable(struct usb_client *usb)
                goto disable_gadget;
 
        for (i = 0; gadget->funcs[i]; ++i) {
-               if (gadget->funcs[i]->function_group !=
-                   USB_FUNCTION_GROUP_WITH_SERVICE)
+               if (gadget->funcs[i]->function_group == USB_FUNCTION_GROUP_SIMPLE)
                        continue;
 
                fws = container_of(gadget->funcs[i],
@@ -584,7 +583,7 @@ static int legacy_disable(struct usb_client *usb)
                return ret;
 
        for (i = 0; gadget->funcs[i]; ++i) {
-               if (gadget->funcs[i]->function_group != USB_FUNCTION_GROUP_WITH_SERVICE)
+               if (gadget->funcs[i]->function_group == USB_FUNCTION_GROUP_SIMPLE)
                        continue;
 
                fws = container_of(gadget->funcs[i], struct usb_function_with_service, func);
index 2b96ad6..e3f460b 100644 (file)
 /* Function IDX in array is number of trailing zeros */
 #define FUNC_IDX_FROM_MASK(mask) _HELPER_CTZ(mask)
 
+/**
+ * USB_FUNCTION_GROUP_WITH_POST_SERVICE is the same as USB_FUNCTION_GROUP_SIMPLE
+ * except running the service as a post.
+ */
 typedef enum {
        USB_FUNCTION_GROUP_SIMPLE,
        USB_FUNCTION_GROUP_WITH_SERVICE,
+       USB_FUNCTION_GROUP_WITH_POST_SERVICE,
 } usb_function_group_e;
 
 struct usb_function {
@@ -253,10 +258,25 @@ out:
                .service = _service,                                    \
        }
 
-DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_ACM, acm, "data-router");
 DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_SDB, sdb, "sdbd");
 DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_MTP, mtp, "mtp-responder");
-DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_RNDIS, rndis, "rndis");
+
+#define DEFINE_USB_FUNCTION_WITH_POST_SERVICE(_id, _name, _service)    \
+       static struct usb_function_with_service _##_name##_function = { \
+               .func = {                                               \
+                       .function_group = USB_FUNCTION_GROUP_WITH_POST_SERVICE, \
+                       .id = _id,                                      \
+                       .name = #_name,                                 \
+                       .instance = "default",                          \
+                       .clone = clone_func_with_service,               \
+                       .free_func = free_func_with_service,            \
+               },                                                      \
+               .service = _service,                                    \
+       }
+
+DEFINE_USB_FUNCTION_WITH_POST_SERVICE(USB_FUNCTION_ACM, acm, "data-router");
+DEFINE_USB_FUNCTION_WITH_POST_SERVICE(USB_FUNCTION_RNDIS, rndis, "rndis");
+
 
 #define MAKE_FUNC_AVAILABLE(_name, _vname)                             \
        [FUNC_IDX_FROM_MASK(USB_FUNCTION_##_name)] = &_##_vname##_function