Changeset 8d7552c in mainline


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

libusbhost: add generic driver initialization function

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

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

    rd2e66bf r8d7552c  
    4545#include <device/hw_res_parsed.h>
    4646
     47typedef int (*driver_init_t)(hcd_t *, const hw_res_list_parsed_t *, bool);
     48typedef void (*driver_fini_t)(hcd_t *);
     49typedef int (*claim_t)(ddf_dev_t *);
     50typedef int (*irq_code_gen_t)(irq_code_t *, const hw_res_list_parsed_t *);
     51
     52typedef struct {
     53        hc_driver_t ops;
     54        claim_t claim;
     55        usb_speed_t hc_speed;
     56        driver_init_t init;
     57        driver_fini_t fini;
     58        interrupt_handler_t *irq_handler;
     59        irq_code_gen_t irq_code_gen;
     60        const char *name;
     61} ddf_hc_driver_t;
     62
     63int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver);
     64
    4765int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
    4866    size_t bw, bw_count_func_t bw_count);
  • uspace/lib/usbhost/src/ddf_helpers.c

    rd2e66bf r8d7552c  
    4949#include <errno.h>
    5050#include <fibril_synch.h>
     51#include <macros.h>
    5152#include <stdio.h>
    5253#include <stdlib.h>
     
    608609}
    609610
     611int 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
    610653/** Initialize hc structures.
    611654 *
Note: See TracChangeset for help on using the changeset viewer.