Changeset d51ba359 in mainline


Ignore:
Timestamp:
2015-07-04T01:51:01Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2dbfe44
Parents:
a799708
Message:

libusbhost: merge ddf_hcd_device_setup_all to hcd_ddf_add_hc

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    ra799708 rd51ba359  
    7777    int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *));
    7878void 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 *));
    8579
    8680#endif
  • uspace/lib/usbhost/src/ddf_helpers.c

    ra799708 rd51ba359  
    609609}
    610610
    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 
    653611/** Initialize hc structures.
    654612 *
     
    867825 *  - registers root hub
    868826 */
    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);
     827int 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        }
    878852
    879853        hw_res_list_parsed_t hw_res;
    880         int ret = hcd_ddf_get_registers(device, &hw_res);
     854        ret = hcd_ddf_get_registers(device, &hw_res);
    881855        if (ret != EOK) {
    882856                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),
    884858                    str_error(ret));
    885859                return ret;
    886860        }
    887861
    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);
    889863        if (ret != EOK) {
    890864                usb_log_error("Failed to setup generic HCD.\n");
     
    893867        }
    894868
     869        interrupt_handler_t *irq_handler =
     870            driver->irq_handler ? driver->irq_handler : ddf_hcd_gen_irq_handler;
    895871        const int irq = hcd_ddf_setup_interrupts(device, &hw_res, irq_handler,
    896             gen_irq_code);
     872            driver->irq_code_gen);
    897873        if (!(irq < 0)) {
    898874                usb_log_debug("Hw interrupts enabled.\n");
     
    901877        /* Init hw driver */
    902878        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));
    904880        hw_res_list_parsed_clean(&hw_res);
    905881        if (ret != EOK) {
     
    929905                usb_log_error("Failed to setup HC root hub: %s.\n",
    930906                    str_error(ret));
    931                 driver_fini(dev_to_hcd(device));
     907                driver->fini(dev_to_hcd(device));
    932908irq_unregister:
    933909                /* Unregistering non-existent should be ok */
    934910                unregister_interrupt_handler(device, irq);
    935911                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;
    938918}
    939919/**
Note: See TracChangeset for help on using the changeset viewer.