Lines Matching refs:f_dfu
29 struct f_dfu { struct
48 typedef int (*dfu_state_fn) (struct f_dfu *, argument
53 static inline struct f_dfu *func_to_dfu(struct usb_function *f) in func_to_dfu()
55 return container_of(f, struct f_dfu, usb_function); in func_to_dfu()
157 struct f_dfu *f_dfu = req->context; in dnload_request_complete() local
160 ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf, in dnload_request_complete()
161 req->actual, f_dfu->blk_seq_num); in dnload_request_complete()
163 f_dfu->dfu_status = DFU_STATUS_errUNKNOWN; in dnload_request_complete()
164 f_dfu->dfu_state = DFU_STATE_dfuERROR; in dnload_request_complete()
170 struct f_dfu *f_dfu = req->context; in dnload_request_flush() local
171 dfu_set_defer_flush(dfu_get_entity(f_dfu->altsetting)); in dnload_request_flush()
183 struct f_dfu *f_dfu = req->context; in handle_getstatus() local
184 struct dfu_entity *dfu = dfu_get_entity(f_dfu->altsetting); in handle_getstatus()
188 switch (f_dfu->dfu_state) { in handle_getstatus()
191 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_IDLE; in handle_getstatus()
194 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST; in handle_getstatus()
203 if (f_dfu->poll_timeout) in handle_getstatus()
204 if (!(f_dfu->blk_seq_num % in handle_getstatus()
206 dfu_set_poll_timeout(dstat, f_dfu->poll_timeout); in handle_getstatus()
209 dstat->bStatus = f_dfu->dfu_status; in handle_getstatus()
210 dstat->bState = f_dfu->dfu_state; in handle_getstatus()
218 struct f_dfu *f_dfu = req->context; in handle_getstate() local
220 ((u8 *)req->buf)[0] = f_dfu->dfu_state; in handle_getstate()
224 static inline void to_dfu_mode(struct f_dfu *f_dfu) in to_dfu_mode() argument
226 f_dfu->usb_function.strings = dfu_strings; in to_dfu_mode()
227 f_dfu->usb_function.hs_descriptors = f_dfu->function; in to_dfu_mode()
228 f_dfu->usb_function.descriptors = f_dfu->function; in to_dfu_mode()
229 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in to_dfu_mode()
232 static inline void to_runtime_mode(struct f_dfu *f_dfu) in to_runtime_mode() argument
234 f_dfu->usb_function.strings = NULL; in to_runtime_mode()
235 f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; in to_runtime_mode()
236 f_dfu->usb_function.descriptors = dfu_runtime_descs; in to_runtime_mode()
241 struct f_dfu *f_dfu = req->context; in handle_upload() local
243 return dfu_read(dfu_get_entity(f_dfu->altsetting), req->buf, in handle_upload()
244 req->length, f_dfu->blk_seq_num); in handle_upload()
251 struct f_dfu *f_dfu = req->context; in handle_dnload() local
254 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST_SYNC; in handle_dnload()
263 static int state_app_idle(struct f_dfu *f_dfu, in state_app_idle() argument
278 f_dfu->dfu_state = DFU_STATE_appDETACH; in state_app_idle()
279 to_dfu_mode(f_dfu); in state_app_idle()
290 static int state_app_detach(struct f_dfu *f_dfu, in state_app_detach() argument
305 f_dfu->dfu_state = DFU_STATE_appIDLE; in state_app_detach()
313 static int state_dfu_idle(struct f_dfu *f_dfu, in state_dfu_idle() argument
325 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_idle()
329 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_SYNC; in state_dfu_idle()
330 f_dfu->blk_seq_num = w_value; in state_dfu_idle()
334 f_dfu->dfu_state = DFU_STATE_dfuUPLOAD_IDLE; in state_dfu_idle()
335 f_dfu->blk_seq_num = 0; in state_dfu_idle()
357 f_dfu->dfu_state = in state_dfu_idle()
359 to_runtime_mode(f_dfu); in state_dfu_idle()
360 f_dfu->dfu_state = DFU_STATE_appIDLE; in state_dfu_idle()
365 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_idle()
373 static int state_dfu_dnload_sync(struct f_dfu *f_dfu, in state_dfu_dnload_sync() argument
388 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnload_sync()
396 static int state_dfu_dnbusy(struct f_dfu *f_dfu, in state_dfu_dnbusy() argument
408 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnbusy()
416 static int state_dfu_dnload_idle(struct f_dfu *f_dfu, in state_dfu_dnload_idle() argument
427 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_SYNC; in state_dfu_dnload_idle()
428 f_dfu->blk_seq_num = w_value; in state_dfu_dnload_idle()
432 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_dnload_idle()
442 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnload_idle()
450 static int state_dfu_manifest_sync(struct f_dfu *f_dfu, in state_dfu_manifest_sync() argument
460 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST; in state_dfu_manifest_sync()
462 f_dfu->blk_seq_num = 0; in state_dfu_manifest_sync()
469 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_manifest_sync()
477 static int state_dfu_manifest(struct f_dfu *f_dfu, in state_dfu_manifest() argument
487 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_manifest()
489 f_dfu->blk_seq_num = 0; in state_dfu_manifest()
496 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_manifest()
503 static int state_dfu_upload_idle(struct f_dfu *f_dfu, in state_dfu_upload_idle() argument
515 f_dfu->blk_seq_num = w_value; in state_dfu_upload_idle()
518 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_upload_idle()
521 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_upload_idle()
532 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_upload_idle()
540 static int state_dfu_error(struct f_dfu *f_dfu, in state_dfu_error() argument
555 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_error()
556 f_dfu->dfu_status = DFU_STATUS_OK; in state_dfu_error()
561 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_error()
588 struct f_dfu *f_dfu = f->config->cdev->req->context; in dfu_handle() local
596 req_type, ctrl->bRequest, f_dfu->dfu_state); in dfu_handle()
605 value = dfu_state[f_dfu->dfu_state] (f_dfu, ctrl, gadget, req); in dfu_handle()
623 dfu_prepare_strings(struct f_dfu *f_dfu, int n) in dfu_prepare_strings() argument
628 f_dfu->strings = calloc(sizeof(struct usb_string), n + 1); in dfu_prepare_strings()
629 if (!f_dfu->strings) in dfu_prepare_strings()
634 f_dfu->strings[i].s = de->name; in dfu_prepare_strings()
637 f_dfu->strings[i].id = 0; in dfu_prepare_strings()
638 f_dfu->strings[i].s = NULL; in dfu_prepare_strings()
643 static int dfu_prepare_function(struct f_dfu *f_dfu, int n) in dfu_prepare_function() argument
648 f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 2); in dfu_prepare_function()
649 if (!f_dfu->function) in dfu_prepare_function()
665 f_dfu->function[i] = (struct usb_descriptor_header *)d; in dfu_prepare_function()
669 f_dfu->function[i] = calloc(sizeof(dfu_func), 1); in dfu_prepare_function()
670 if (!f_dfu->function[i]) in dfu_prepare_function()
672 memcpy(f_dfu->function[i], &dfu_func, sizeof(dfu_func)); in dfu_prepare_function()
675 f_dfu->function[i] = NULL; in dfu_prepare_function()
681 free(f_dfu->function[--i]); in dfu_prepare_function()
682 f_dfu->function[i] = NULL; in dfu_prepare_function()
684 free(f_dfu->function); in dfu_prepare_function()
692 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_bind() local
702 f_dfu->dfu_state = DFU_STATE_appIDLE; in dfu_bind()
703 f_dfu->dfu_status = DFU_STATUS_OK; in dfu_bind()
705 rv = dfu_prepare_function(f_dfu, alt_num); in dfu_bind()
709 rv = dfu_prepare_strings(f_dfu, alt_num); in dfu_bind()
716 f_dfu->strings[i].id = id; in dfu_bind()
717 ((struct usb_interface_descriptor *)f_dfu->function[i]) in dfu_bind()
721 to_dfu_mode(f_dfu); in dfu_bind()
723 stringtab_dfu.strings = f_dfu->strings; in dfu_bind()
725 cdev->req->context = f_dfu; in dfu_bind()
737 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_unbind() local
741 if (f_dfu->strings) { in dfu_unbind()
744 f_dfu->strings[--i].s = NULL; in dfu_unbind()
746 free(f_dfu->strings); in dfu_unbind()
749 if (f_dfu->function) { in dfu_unbind()
752 free(f_dfu->function[--i]); in dfu_unbind()
753 f_dfu->function[i] = NULL; in dfu_unbind()
755 free(f_dfu->function); in dfu_unbind()
758 free(f_dfu); in dfu_unbind()
763 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_set_alt() local
767 f_dfu->altsetting = alt; in dfu_set_alt()
768 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in dfu_set_alt()
769 f_dfu->dfu_status = DFU_STATUS_OK; in dfu_set_alt()
776 struct f_dfu *f_dfu = func_to_dfu(f); in __dfu_get_alt() local
778 return f_dfu->altsetting; in __dfu_get_alt()
784 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_disable() local
785 if (f_dfu->config == 0) in dfu_disable()
790 f_dfu->config = 0; in dfu_disable()
795 struct f_dfu *f_dfu; in dfu_bind_config() local
798 f_dfu = calloc(sizeof(*f_dfu), 1); in dfu_bind_config()
799 if (!f_dfu) in dfu_bind_config()
801 f_dfu->usb_function.name = "dfu"; in dfu_bind_config()
802 f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; in dfu_bind_config()
803 f_dfu->usb_function.descriptors = dfu_runtime_descs; in dfu_bind_config()
804 f_dfu->usb_function.bind = dfu_bind; in dfu_bind_config()
805 f_dfu->usb_function.unbind = dfu_unbind; in dfu_bind_config()
806 f_dfu->usb_function.set_alt = dfu_set_alt; in dfu_bind_config()
807 f_dfu->usb_function.get_alt = __dfu_get_alt; in dfu_bind_config()
808 f_dfu->usb_function.disable = dfu_disable; in dfu_bind_config()
809 f_dfu->usb_function.strings = dfu_generic_strings; in dfu_bind_config()
810 f_dfu->usb_function.setup = dfu_handle; in dfu_bind_config()
811 f_dfu->poll_timeout = DFU_DEFAULT_POLL_TIMEOUT; in dfu_bind_config()
813 status = usb_add_function(c, &f_dfu->usb_function); in dfu_bind_config()
815 free(f_dfu); in dfu_bind_config()