Lines Matching refs:f_dfu
30 struct f_dfu { struct
49 typedef int (*dfu_state_fn) (struct f_dfu *, argument
54 static inline struct f_dfu *func_to_dfu(struct usb_function *f) in func_to_dfu()
56 return container_of(f, struct f_dfu, usb_function); in func_to_dfu()
158 struct f_dfu *f_dfu = req->context; in dnload_request_complete() local
161 ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf, in dnload_request_complete()
162 req->actual, f_dfu->blk_seq_num); in dnload_request_complete()
164 f_dfu->dfu_status = DFU_STATUS_errUNKNOWN; in dnload_request_complete()
165 f_dfu->dfu_state = DFU_STATE_dfuERROR; in dnload_request_complete()
171 struct f_dfu *f_dfu = req->context; in dnload_request_flush() local
172 dfu_set_defer_flush(dfu_get_entity(f_dfu->altsetting)); in dnload_request_flush()
184 struct f_dfu *f_dfu = req->context; in handle_getstatus() local
185 struct dfu_entity *dfu = dfu_get_entity(f_dfu->altsetting); in handle_getstatus()
189 switch (f_dfu->dfu_state) { in handle_getstatus()
192 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_IDLE; in handle_getstatus()
195 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST; in handle_getstatus()
204 if (f_dfu->poll_timeout) in handle_getstatus()
205 if (!(f_dfu->blk_seq_num % in handle_getstatus()
207 dfu_set_poll_timeout(dstat, f_dfu->poll_timeout); in handle_getstatus()
210 dstat->bStatus = f_dfu->dfu_status; in handle_getstatus()
211 dstat->bState = f_dfu->dfu_state; in handle_getstatus()
219 struct f_dfu *f_dfu = req->context; in handle_getstate() local
221 ((u8 *)req->buf)[0] = f_dfu->dfu_state; in handle_getstate()
225 static inline void to_dfu_mode(struct f_dfu *f_dfu) in to_dfu_mode() argument
227 f_dfu->usb_function.strings = dfu_strings; in to_dfu_mode()
228 f_dfu->usb_function.hs_descriptors = f_dfu->function; in to_dfu_mode()
229 f_dfu->usb_function.descriptors = f_dfu->function; in to_dfu_mode()
230 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in to_dfu_mode()
233 static inline void to_runtime_mode(struct f_dfu *f_dfu) in to_runtime_mode() argument
235 f_dfu->usb_function.strings = NULL; in to_runtime_mode()
236 f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; in to_runtime_mode()
237 f_dfu->usb_function.descriptors = dfu_runtime_descs; in to_runtime_mode()
242 struct f_dfu *f_dfu = req->context; in handle_upload() local
244 return dfu_read(dfu_get_entity(f_dfu->altsetting), req->buf, in handle_upload()
245 req->length, f_dfu->blk_seq_num); in handle_upload()
252 struct f_dfu *f_dfu = req->context; in handle_dnload() local
255 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST_SYNC; in handle_dnload()
264 static int state_app_idle(struct f_dfu *f_dfu, in state_app_idle() argument
279 f_dfu->dfu_state = DFU_STATE_appDETACH; in state_app_idle()
280 to_dfu_mode(f_dfu); in state_app_idle()
291 static int state_app_detach(struct f_dfu *f_dfu, in state_app_detach() argument
306 f_dfu->dfu_state = DFU_STATE_appIDLE; in state_app_detach()
314 static int state_dfu_idle(struct f_dfu *f_dfu, in state_dfu_idle() argument
326 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_idle()
330 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_SYNC; in state_dfu_idle()
331 f_dfu->blk_seq_num = w_value; in state_dfu_idle()
335 f_dfu->dfu_state = DFU_STATE_dfuUPLOAD_IDLE; in state_dfu_idle()
336 f_dfu->blk_seq_num = 0; in state_dfu_idle()
358 f_dfu->dfu_state = in state_dfu_idle()
360 to_runtime_mode(f_dfu); in state_dfu_idle()
361 f_dfu->dfu_state = DFU_STATE_appIDLE; in state_dfu_idle()
366 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_idle()
374 static int state_dfu_dnload_sync(struct f_dfu *f_dfu, in state_dfu_dnload_sync() argument
389 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnload_sync()
397 static int state_dfu_dnbusy(struct f_dfu *f_dfu, in state_dfu_dnbusy() argument
409 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnbusy()
417 static int state_dfu_dnload_idle(struct f_dfu *f_dfu, in state_dfu_dnload_idle() argument
428 f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_SYNC; in state_dfu_dnload_idle()
429 f_dfu->blk_seq_num = w_value; in state_dfu_dnload_idle()
433 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_dnload_idle()
443 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_dnload_idle()
451 static int state_dfu_manifest_sync(struct f_dfu *f_dfu, in state_dfu_manifest_sync() argument
461 f_dfu->dfu_state = DFU_STATE_dfuMANIFEST; in state_dfu_manifest_sync()
463 f_dfu->blk_seq_num = 0; in state_dfu_manifest_sync()
470 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_manifest_sync()
478 static int state_dfu_manifest(struct f_dfu *f_dfu, in state_dfu_manifest() argument
488 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_manifest()
490 f_dfu->blk_seq_num = 0; in state_dfu_manifest()
497 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_manifest()
504 static int state_dfu_upload_idle(struct f_dfu *f_dfu, in state_dfu_upload_idle() argument
516 f_dfu->blk_seq_num = w_value; in state_dfu_upload_idle()
519 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_upload_idle()
522 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_upload_idle()
533 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_upload_idle()
541 static int state_dfu_error(struct f_dfu *f_dfu, in state_dfu_error() argument
556 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in state_dfu_error()
557 f_dfu->dfu_status = DFU_STATUS_OK; in state_dfu_error()
562 f_dfu->dfu_state = DFU_STATE_dfuERROR; in state_dfu_error()
589 struct f_dfu *f_dfu = f->config->cdev->req->context; in dfu_handle() local
597 req_type, ctrl->bRequest, f_dfu->dfu_state); in dfu_handle()
606 value = dfu_state[f_dfu->dfu_state] (f_dfu, ctrl, gadget, req); in dfu_handle()
624 dfu_prepare_strings(struct f_dfu *f_dfu, int n) in dfu_prepare_strings() argument
629 f_dfu->strings = calloc(sizeof(struct usb_string), n + 1); in dfu_prepare_strings()
630 if (!f_dfu->strings) in dfu_prepare_strings()
635 f_dfu->strings[i].s = de->name; in dfu_prepare_strings()
638 f_dfu->strings[i].id = 0; in dfu_prepare_strings()
639 f_dfu->strings[i].s = NULL; in dfu_prepare_strings()
644 static int dfu_prepare_function(struct f_dfu *f_dfu, int n) in dfu_prepare_function() argument
649 f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 2); in dfu_prepare_function()
650 if (!f_dfu->function) in dfu_prepare_function()
666 f_dfu->function[i] = (struct usb_descriptor_header *)d; in dfu_prepare_function()
670 f_dfu->function[i] = calloc(sizeof(dfu_func), 1); in dfu_prepare_function()
671 if (!f_dfu->function[i]) in dfu_prepare_function()
673 memcpy(f_dfu->function[i], &dfu_func, sizeof(dfu_func)); in dfu_prepare_function()
676 f_dfu->function[i] = NULL; in dfu_prepare_function()
682 free(f_dfu->function[--i]); in dfu_prepare_function()
683 f_dfu->function[i] = NULL; in dfu_prepare_function()
685 free(f_dfu->function); in dfu_prepare_function()
693 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_bind() local
703 f_dfu->dfu_state = DFU_STATE_appIDLE; in dfu_bind()
704 f_dfu->dfu_status = DFU_STATUS_OK; in dfu_bind()
706 rv = dfu_prepare_function(f_dfu, alt_num); in dfu_bind()
710 rv = dfu_prepare_strings(f_dfu, alt_num); in dfu_bind()
717 f_dfu->strings[i].id = id; in dfu_bind()
718 ((struct usb_interface_descriptor *)f_dfu->function[i]) in dfu_bind()
722 to_dfu_mode(f_dfu); in dfu_bind()
724 stringtab_dfu.strings = f_dfu->strings; in dfu_bind()
726 cdev->req->context = f_dfu; in dfu_bind()
738 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_unbind() local
742 if (f_dfu->strings) { in dfu_unbind()
745 f_dfu->strings[--i].s = NULL; in dfu_unbind()
747 free(f_dfu->strings); in dfu_unbind()
750 if (f_dfu->function) { in dfu_unbind()
754 free(f_dfu->function[--i]); in dfu_unbind()
755 f_dfu->function[i] = NULL; in dfu_unbind()
757 free(f_dfu->function); in dfu_unbind()
760 free(f_dfu); in dfu_unbind()
765 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_set_alt() local
769 f_dfu->altsetting = alt; in dfu_set_alt()
770 f_dfu->dfu_state = DFU_STATE_dfuIDLE; in dfu_set_alt()
771 f_dfu->dfu_status = DFU_STATUS_OK; in dfu_set_alt()
778 struct f_dfu *f_dfu = func_to_dfu(f); in __dfu_get_alt() local
780 return f_dfu->altsetting; in __dfu_get_alt()
786 struct f_dfu *f_dfu = func_to_dfu(f); in dfu_disable() local
787 if (f_dfu->config == 0) in dfu_disable()
792 f_dfu->config = 0; in dfu_disable()
797 struct f_dfu *f_dfu; in dfu_bind_config() local
800 f_dfu = calloc(sizeof(*f_dfu), 1); in dfu_bind_config()
801 if (!f_dfu) in dfu_bind_config()
803 f_dfu->usb_function.name = "dfu"; in dfu_bind_config()
804 f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; in dfu_bind_config()
805 f_dfu->usb_function.descriptors = dfu_runtime_descs; in dfu_bind_config()
806 f_dfu->usb_function.bind = dfu_bind; in dfu_bind_config()
807 f_dfu->usb_function.unbind = dfu_unbind; in dfu_bind_config()
808 f_dfu->usb_function.set_alt = dfu_set_alt; in dfu_bind_config()
809 f_dfu->usb_function.get_alt = __dfu_get_alt; in dfu_bind_config()
810 f_dfu->usb_function.disable = dfu_disable; in dfu_bind_config()
811 f_dfu->usb_function.strings = dfu_generic_strings; in dfu_bind_config()
812 f_dfu->usb_function.setup = dfu_handle; in dfu_bind_config()
813 f_dfu->poll_timeout = DFU_DEFAULT_POLL_TIMEOUT; in dfu_bind_config()
815 status = usb_add_function(c, &f_dfu->usb_function); in dfu_bind_config()
817 free(f_dfu); in dfu_bind_config()