thor: Add API for status notifications
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Wed, 25 Nov 2020 17:54:28 +0000 (18:54 +0100)
committerSylwester Nawrocki <s.nawrocki@samsung.com>
Tue, 1 Dec 2020 09:10:44 +0000 (10:10 +0100)
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 <s.nawrocki@samsung.com>
drivers/usb/gadget/f_thor.c
include/thor.h

index 1368684..7a66bcc 100644 (file)
@@ -35,6 +35,7 @@
 #include <samsung/misc.h>
 #include <linux/input.h>
 #include <usb.h>
+#include <thor.h>
 
 #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
index 62501bd..a630f10 100644 (file)
 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_ */