From: Sylwester Nawrocki Date: Wed, 25 Nov 2020 17:54:28 +0000 (+0100) Subject: thor: Add API for status notifications X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=556f876f5a4853b8c363eae92cebffcd266e3fd2;p=platform%2Fkernel%2Fu-boot.git thor: Add API for status notifications This allows to register a callback by the board code for thor status notifications, e.g. for flashing progress updates. Change-Id: Ic1eaad7f3f5adbca404162b745a9287d5a9ae247 Signed-off-by: Sylwester Nawrocki --- diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 1368684a58..7a66bccc3c 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "f_thor.h" @@ -61,6 +62,7 @@ static unsigned long long int thor_file_size; #ifdef CONFIG_TIZEN static unsigned long long int total_file_size; static unsigned long long int downloaded_file_size; +static thor_notify_func thor_notify_fn = NULL; #endif static int alt_setting_num; @@ -587,6 +589,12 @@ static int thor_rx_data(size_t *received) data_to_rx -= dev->out_req->actual; #ifdef CONFIG_TIZEN downloaded_file_size += dev->out_req->actual; + + if (thor_notify_fn) + thor_notify_fn(THOR_NOTIFY_PROGRESS, + total_file_size, + downloaded_file_size); + #ifdef CONFIG_LCD /* TODO : Need to enable LCD*/ #ifdef CONFIG_OF_MULTI if (board_is_trats2()) @@ -761,6 +769,9 @@ int thor_init(void) draw_thor_connected(); #endif #endif + if (thor_notify_fn) + thor_notify_fn(THOR_NOTIFY_CONNECTED, 0, 0); + #endif /* CONFIG_TIZEN */ thor_set_dma(thor_rx_data_buf, strlen("THOR")); /* detect the download request from Host PC */ @@ -1105,3 +1116,15 @@ int thor_add(struct usb_configuration *c) } DECLARE_GADGET_BIND_CALLBACK(usb_dnl_thor, thor_add); + +#ifdef CONFIG_TIZEN +int thor_register_notifier(thor_notify_func fn) +{ + if (thor_notify_fn) + return -EINVAL; + + thor_notify_fn = fn; + + return 0; +} +#endif diff --git a/include/thor.h b/include/thor.h index 62501bda17..a630f10316 100644 --- a/include/thor.h +++ b/include/thor.h @@ -15,4 +15,23 @@ int thor_handle(void); int thor_init(void); int thor_add(struct usb_configuration *c); + +enum thor_notify_type { + THOR_NOTIFY_INIT, + THOR_NOTIFY_CONNECTED, + THOR_NOTIFY_PROGRESS, +}; + +typedef void (*thor_notify_func)(enum thor_notify_type, unsigned long long int, + unsigned long long int); + +#ifdef CONFIG_TIZEN +int thor_register_notifier(thor_notify_func fn); +#else +static inline int thor_register_notifier(thor_notify_func fn) +{ + return -ENOSYS; +} +#endif /* CONFIG_TIZEN */ + #endif /* __THOR_H_ */