From patchwork Thu Jan 9 14:31:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Zalega X-Patchwork-Id: 308828 X-Patchwork-Delegate: promsoft@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id BEAAC2C00A5 for ; Fri, 10 Jan 2014 01:41:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BFF864AB2C; Thu, 9 Jan 2014 15:40:58 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wnGBuQBEak8y; Thu, 9 Jan 2014 15:40:58 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DD7664AC4E; Thu, 9 Jan 2014 15:40:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1BB5D4ABFF for ; Thu, 9 Jan 2014 15:40:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g2J5uEHu9pQ2 for ; Thu, 9 Jan 2014 15:40:04 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by theia.denx.de (Postfix) with ESMTPS id 791AA4AB30 for ; Thu, 9 Jan 2014 15:39:50 +0100 (CET) Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MZ5007SB1L8FCA0@mailout2.w1.samsung.com> for u-boot@lists.denx.de; Thu, 09 Jan 2014 14:29:32 +0000 (GMT) X-AuditID: cbfec7f5-b7fc96d000004885-7b-52ceb24e2cd8 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 87.F6.18565.E42BEC25; Thu, 09 Jan 2014 14:29:34 +0000 (GMT) Received: from kernelpanic.DIGITAL.local ([106.120.53.14]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MZ5004DQ1L7WS60@eusync4.samsung.com>; Thu, 09 Jan 2014 14:29:33 +0000 (GMT) From: Mateusz Zalega To: u-boot@lists.denx.de Date: Thu, 09 Jan 2014 15:31:59 +0100 Message-id: <1389277919-15279-9-git-send-email-m.zalega@samsung.com> X-Mailer: git-send-email 1.8.2.1 In-reply-to: <1389277919-15279-1-git-send-email-m.zalega@samsung.com> References: <1389277919-15279-1-git-send-email-m.zalega@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFJMWRmVeSWpSXmKPExsVy+t/xa7p+m84FGbyayWRxtukNu8Wbh5sZ Lea+m8Jk8XZvJ7sDi8fZOzsYPfq2rGIMYIrisklJzcksSy3St0vgyphw6hVbQW9oxfXmW0wN jE9cuxg5OSQETCSaF81jhrDFJC7cW8/WxcjFISSwlFFi2vw7UE4/k8Szix2MIFVsAtoSN/bO ZwexRQQkJH71X2UEKWIWaGKUuLF2JitIQlggROLR8rdMIDaLgKrE2Q0tYCt4BVwk/t1YxgSx TkHi+PZtYEM5BVwlXvU0gtlCQDWNm/6yTGDkXcDIsIpRNLU0uaA4KT3XSK84Mbe4NC9dLzk/ dxMjJDy+7mBceszqEKMAB6MSD++K4rNBQqyJZcWVuYcYJTiYlUR4jTecCxLiTUmsrEotyo8v Ks1JLT7EyMTBKdXAmHZuKo+L7JwD0iYncvad/2z/IfvNs1XrWZk/rZQ49f/5x61cq5lLPftS Uhl4Mm4d+rx+3ZE1hu1X0kKj15zIkZl/iCHWS1Qrfc3RwwXfmo/vV/dpOX38f9JLuX8/WxVu 3pXTk++7MTf26SOm2K8vXtd949ZW37pq6ie7LYs1Fofv/xu8VWK1zT0lluKMREMt5qLiRABZ YTAn7QEAAA== Cc: Kyungmin Park Subject: [U-Boot] [PATCH 9/9] USB: gadget: added a saner gadget downloader registration API X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Preprocessor definitions and hardcoded implementation selection in g_dnl core were replaced by a linker list made of {usb_function_name, bind_callback) pairs. Change-Id: I4e0515e7fd61ff19793e9ac9a6c48b07c616c9dc Signed-off-by: Mateusz Zalega Cc: Lukasz Majewski Cc: Kyungmin Park Tested-by: Heiko Schocher Tested-by: Lukasz Majewski Acked-by: Lukasz Majewski --- common/cmd_dfu.c | 3 +- common/cmd_thordown.c | 3 +- common/cmd_usb_mass_storage.c | 2 +- drivers/usb/gadget/f_dfu.c | 11 ++++-- drivers/usb/gadget/f_mass_storage.c | 6 +++ drivers/usb/gadget/f_thor.c | 5 +++ drivers/usb/gadget/g_dnl.c | 74 +++++++++++++++++-------------------- include/dfu.h | 7 ---- include/g_dnl.h | 11 ++++++ include/thor.h | 8 ---- include/usb_mass_storage.h | 8 ---- 11 files changed, 66 insertions(+), 72 deletions(-) diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c index 5547678..a03538d 100644 --- a/common/cmd_dfu.c +++ b/common/cmd_dfu.c @@ -22,7 +22,6 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *interface = argv[2]; char *devstring = argv[3]; - char *s = "dfu"; int ret, i = 0; ret = dfu_init_env_entities(interface, simple_strtoul(devstring, @@ -38,7 +37,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int controller_index = simple_strtoul(usb_controller, NULL, 0); board_usb_init(controller_index, USB_INIT_DEVICE); - g_dnl_register(s); + g_dnl_register("usb_dnl_dfu"); while (1) { if (dfu_reset()) /* diff --git a/common/cmd_thordown.c b/common/cmd_thordown.c index c4b3511..2dd7509 100644 --- a/common/cmd_thordown.c +++ b/common/cmd_thordown.c @@ -22,7 +22,6 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *interface = argv[2]; char *devstring = argv[3]; - const char *s = "thor"; int ret; puts("TIZEN \"THOR\" Downloader\n"); @@ -40,7 +39,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) goto exit; } - g_dnl_register(s); + g_dnl_register("usb_dnl_thor"); ret = thor_init(); if (ret) { diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index 99487f4..c8e152c 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -40,7 +40,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; } - g_dnl_register("ums"); + g_dnl_register("usb_dnl_ums"); while (1) { usb_gadget_handle_interrupts(); diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c index a045864..cde1895 100644 --- a/drivers/usb/gadget/f_dfu.c +++ b/drivers/usb/gadget/f_dfu.c @@ -18,12 +18,14 @@ #include #include #include +#include #include #include #include #include +#include #include "f_dfu.h" struct f_dfu { @@ -768,9 +770,7 @@ static int dfu_bind_config(struct usb_configuration *c) int dfu_add(struct usb_configuration *c) { - int id; - - id = usb_string_id(c->cdev); + int id = usb_string_id(c->cdev); if (id < 0) return id; strings_dfu_generic[0].id = id; @@ -781,3 +781,8 @@ int dfu_add(struct usb_configuration *c) return dfu_bind_config(c); } + +/* export dfu_add to g_dnl.o */ +ll_entry_declare(struct g_dnl_bind_callback, dfu_bind_callback, + g_dnl_bind_callbacks) = { .usb_function_name = "usb_dnl_dfu", + .fptr = dfu_add }; diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index b1fe8bd..b7d03f2 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -243,6 +243,7 @@ #include #include #include +#include #include #include @@ -255,6 +256,7 @@ #include #include #include +#include /*------------------------------------------------------------------------*/ @@ -2778,3 +2780,7 @@ int fsg_init(struct ums *ums_dev) return 0; } + +ll_entry_declare(struct g_dnl_bind_callback, fsg_bind_callback, + g_dnl_bind_callbacks) = { .usb_function_name = "usb_dnl_ums", + .fptr = fsg_add }; diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index c4c9909..3f428c8 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -1001,3 +1002,7 @@ int thor_add(struct usb_configuration *c) debug("%s:\n", __func__); return thor_func_init(c); } + +ll_entry_declare(struct g_dnl_bind_callback, thor_bind_callback, + g_dnl_bind_callbacks) = { .usb_function_name = "usb_dnl_thor", + .fptr = thor_add }; diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index dd95afe..00ace2c 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -41,7 +41,6 @@ #define DRIVER_VERSION "usb_dnl 2.0" -static const char shortname[] = "usb_dnl_"; static const char product[] = "USB download gadget"; static char g_dnl_serial[MAX_STRING_SERIAL]; static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER; @@ -95,30 +94,38 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev) free(cdev->config); cdev->config = NULL; - debug("%s: calling usb_gadget_disconnect for " - "controller '%s'\n", shortname, gadget->name); + debug("%s: calling usb_gadget_disconnect for controller '%s'\n", + __func__, gadget->name); usb_gadget_disconnect(gadget); return 0; } +static inline struct g_dnl_bind_callback * g_dnl_first_bind_callback(void) +{ + return ll_entry_start(struct g_dnl_bind_callback, + g_dnl_bind_callbacks); +} + +static inline struct g_dnl_bind_callback * g_dnl_last_bind_callback(void) +{ + return ll_entry_end(struct g_dnl_bind_callback, + g_dnl_bind_callbacks); +} + static int g_dnl_do_config(struct usb_configuration *c) { const char *s = c->cdev->driver->name; - int ret = -1; debug("%s: configuration: 0x%p composite dev: 0x%p\n", - __func__, c, c->cdev); - + __func__, c, c->cdev); printf("GADGET DRIVER: %s\n", s); - if (!strcmp(s, "usb_dnl_dfu")) - ret = dfu_add(c); - else if (!strcmp(s, "usb_dnl_ums")) - ret = fsg_add(c); - else if (!strcmp(s, "usb_dnl_thor")) - ret = thor_add(c); - - return ret; + + struct g_dnl_bind_callback *callback = g_dnl_first_bind_callback(); + for (; callback != g_dnl_last_bind_callback(); ++callback) + if (!strcmp(s, callback->usb_function_name)) + return callback->fptr(c); + return -ENODEV; } static int g_dnl_config_register(struct usb_composite_dev *cdev) @@ -203,12 +210,12 @@ static int g_dnl_bind(struct usb_composite_dev *cdev) device_desc.bcdDevice = cpu_to_le16(gcnum); else { debug("%s: controller '%s' not recognized\n", - shortname, gadget->name); + __func__, gadget->name); device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); } - debug("%s: calling usb_gadget_connect for " - "controller '%s'\n", shortname, gadget->name); + debug("%s: calling usb_gadget_connect for controller '%s'\n", + __func__, gadget->name); usb_gadget_connect(gadget); return 0; @@ -227,36 +234,21 @@ static struct usb_composite_driver g_dnl_driver = { .unbind = g_dnl_unbind, }; -int g_dnl_register(const char *type) +/* + * NOTICE: + * Registering via USB function name won't be necessary after rewriting + * g_dnl to support multiple USB functions. + */ +int g_dnl_register(const char *name) { - /* The largest function name is 4 */ - static char name[sizeof(shortname) + 4]; - int ret; - - if (!strcmp(type, "dfu")) { - strcpy(name, shortname); - strcat(name, type); - } else if (!strcmp(type, "ums")) { - strcpy(name, shortname); - strcat(name, type); - } else if (!strcmp(type, "thor")) { - strcpy(name, shortname); - strcat(name, type); - } else { - printf("%s: unknown command: %s\n", __func__, type); - return -EINVAL; - } - + debug("%s: g_dnl_driver.name = %s\n", __func__, name); g_dnl_driver.name = name; - debug("%s: g_dnl_driver.name: %s\n", __func__, g_dnl_driver.name); - ret = usb_composite_register(&g_dnl_driver); - + int ret = usb_composite_register(&g_dnl_driver); if (ret) { - printf("%s: failed!, error: %d\n", __func__, ret); + debug("%s: failed!, error: %d\n", __func__, ret); return ret; } - return 0; } diff --git a/include/dfu.h b/include/dfu.h index f2e83db..6fd75d0 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -164,12 +164,5 @@ static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s) } #endif -#ifdef CONFIG_DFU_FUNCTION int dfu_add(struct usb_configuration *c); -#else -int dfu_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __DFU_ENTITY_H_ */ diff --git a/include/g_dnl.h b/include/g_dnl.h index 8f813c2..4392f76 100644 --- a/include/g_dnl.h +++ b/include/g_dnl.h @@ -10,6 +10,17 @@ #include #include +#include + +typedef int (*g_dnl_bind_callback_f)(struct usb_configuration *); + +/* used in Gadget downloader callback linker list */ +struct g_dnl_bind_callback +{ + const char *usb_function_name; + g_dnl_bind_callback_f fptr; +}; + int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *); int g_dnl_register(const char *s); void g_dnl_unregister(void); diff --git a/include/thor.h b/include/thor.h index afeade4..5051be7 100644 --- a/include/thor.h +++ b/include/thor.h @@ -15,13 +15,5 @@ int thor_handle(void); int thor_init(void); - -#ifdef CONFIG_THOR_FUNCTION int thor_add(struct usb_configuration *c); -#else -int thor_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __THOR_H_ */ diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index 9df3adc..6ee4f34 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -37,13 +37,5 @@ int fsg_init(struct ums *); void fsg_cleanup(void); struct ums *ums_init(unsigned int); int fsg_main_thread(void *); - -#ifdef CONFIG_USB_GADGET_MASS_STORAGE int fsg_add(struct usb_configuration *c); -#else -int fsg_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __USB_MASS_STORAGE_H__ */