Changeset d51ba359 in mainline
- Timestamp:
- 2015-07-04T01:51:01Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2dbfe44
- Parents:
- a799708
- Location:
- uspace/lib/usbhost
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
ra799708 rd51ba359 77 77 int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *)); 78 78 void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev); 79 int ddf_hcd_device_setup_all(ddf_dev_t *device, usb_speed_t speed, size_t bw,80 bw_count_func_t bw_count,81 interrupt_handler_t irq_handler,82 int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *hw_res),83 int (*driver_init)(hcd_t *, const hw_res_list_parsed_t *, bool),84 void (*driver_fini)(hcd_t *));85 79 86 80 #endif -
uspace/lib/usbhost/src/ddf_helpers.c
ra799708 rd51ba359 609 609 } 610 610 611 int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver)612 {613 assert(driver);614 static const struct { size_t bw; bw_count_func_t bw_count; }bw[] = {615 [USB_SPEED_FULL] = { .bw = BANDWIDTH_AVAILABLE_USB11,616 .bw_count = bandwidth_count_usb11 },617 [USB_SPEED_HIGH] = { .bw = BANDWIDTH_AVAILABLE_USB11,618 .bw_count = bandwidth_count_usb11 },619 };620 621 int ret = EOK;622 const usb_speed_t speed = driver->hc_speed;623 if (speed >= ARRAY_SIZE(bw) || bw[speed].bw == 0) {624 usb_log_error("Driver `%s' reported unsupported speed: %s",625 driver->name, usb_str_speed(speed));626 return ENOTSUP;627 }628 629 if (driver->claim)630 ret = driver->claim(device);631 if (ret != EOK) {632 usb_log_error("Failed to claim `%s' for driver `%s'",633 ddf_dev_get_name(device), driver->name);634 return ret;635 }636 interrupt_handler_t *irq_handler =637 driver->irq_handler ? driver->irq_handler : ddf_hcd_gen_irq_handler;638 639 ret = ddf_hcd_device_setup_all(device, speed, bw[speed].bw,640 bw[speed].bw_count, irq_handler, driver->irq_code_gen,641 driver->init, driver->fini);642 if (ret != EOK) {643 usb_log_error("Failed to setup `%s' for driver `%s'",644 ddf_dev_get_name(device), driver->name);645 return ret;646 }647 648 usb_log_info("Controlling new `%s' device `%s'.\n",649 driver->name, ddf_dev_get_name(device));650 return EOK;651 }652 653 611 /** Initialize hc structures. 654 612 * … … 867 825 * - registers root hub 868 826 */ 869 int ddf_hcd_device_setup_all(ddf_dev_t *device, usb_speed_t speed, size_t bw, 870 bw_count_func_t bw_count, 871 interrupt_handler_t irq_handler, 872 int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *hw_res), 873 int (*driver_init)(hcd_t *, const hw_res_list_parsed_t *, bool), 874 void (*driver_fini)(hcd_t *) 875 ) 876 { 877 assert(device); 827 int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver) 828 { 829 assert(driver); 830 static const struct { size_t bw; bw_count_func_t bw_count; }bw[] = { 831 [USB_SPEED_FULL] = { .bw = BANDWIDTH_AVAILABLE_USB11, 832 .bw_count = bandwidth_count_usb11 }, 833 [USB_SPEED_HIGH] = { .bw = BANDWIDTH_AVAILABLE_USB11, 834 .bw_count = bandwidth_count_usb11 }, 835 }; 836 837 int ret = EOK; 838 const usb_speed_t speed = driver->hc_speed; 839 if (speed >= ARRAY_SIZE(bw) || bw[speed].bw == 0) { 840 usb_log_error("Driver `%s' reported unsupported speed: %s", 841 driver->name, usb_str_speed(speed)); 842 return ENOTSUP; 843 } 844 845 if (driver->claim) 846 ret = driver->claim(device); 847 if (ret != EOK) { 848 usb_log_error("Failed to claim `%s' for driver `%s'", 849 ddf_dev_get_name(device), driver->name); 850 return ret; 851 } 878 852 879 853 hw_res_list_parsed_t hw_res; 880 intret = hcd_ddf_get_registers(device, &hw_res);854 ret = hcd_ddf_get_registers(device, &hw_res); 881 855 if (ret != EOK) { 882 856 usb_log_error("Failed to get register memory addresses " 883 "for %" PRIun ": %s.\n", ddf_dev_get_handle(device),857 "for `%s': %s.\n", ddf_dev_get_name(device), 884 858 str_error(ret)); 885 859 return ret; 886 860 } 887 861 888 ret = hcd_ddf_setup_hc(device, speed, bw ,bw_count);862 ret = hcd_ddf_setup_hc(device, speed, bw[speed].bw, bw[speed].bw_count); 889 863 if (ret != EOK) { 890 864 usb_log_error("Failed to setup generic HCD.\n"); … … 893 867 } 894 868 869 interrupt_handler_t *irq_handler = 870 driver->irq_handler ? driver->irq_handler : ddf_hcd_gen_irq_handler; 895 871 const int irq = hcd_ddf_setup_interrupts(device, &hw_res, irq_handler, 896 gen_irq_code);872 driver->irq_code_gen); 897 873 if (!(irq < 0)) { 898 874 usb_log_debug("Hw interrupts enabled.\n"); … … 901 877 /* Init hw driver */ 902 878 hcd_t *hcd = dev_to_hcd(device); 903 ret = driver _init(hcd, &hw_res, !(irq < 0));879 ret = driver->init(hcd, &hw_res, !(irq < 0)); 904 880 hw_res_list_parsed_clean(&hw_res); 905 881 if (ret != EOK) { … … 929 905 usb_log_error("Failed to setup HC root hub: %s.\n", 930 906 str_error(ret)); 931 driver _fini(dev_to_hcd(device));907 driver->fini(dev_to_hcd(device)); 932 908 irq_unregister: 933 909 /* Unregistering non-existent should be ok */ 934 910 unregister_interrupt_handler(device, irq); 935 911 hcd_ddf_clean_hc(device); 936 } 937 return ret; 912 return ret; 913 } 914 915 usb_log_info("Controlling new `%s' device `%s'.\n", 916 driver->name, ddf_dev_get_name(device)); 917 return EOK; 938 918 } 939 919 /**
Note:
See TracChangeset
for help on using the changeset viewer.