Changeset 32fb6bce in mainline for uspace/drv/bus/usb/ohci/main.c


Ignore:
Timestamp:
2017-12-18T22:50:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/main.c

    r1ea0bbf r32fb6bce  
    4848
    4949#define NAME "ohci"
    50 static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
    51 static int ohci_driver_start(hcd_t *, bool);
    52 static int ohci_driver_claim(hcd_t *, ddf_dev_t *);
    53 static void ohci_driver_fini(hcd_t *);
    5450
    55 static const ddf_hc_driver_t ohci_hc_driver = {
    56         .irq_code_gen = ohci_hc_gen_irq_code,
    57         .init = ohci_driver_init,
    58         .claim = ohci_driver_claim,
    59         .start = ohci_driver_start,
     51static const hc_driver_t ohci_driver = {
     52        .name = NAME,
     53        .hc_device_size = sizeof(hc_t),
     54
     55        .hc_add = hc_add,
     56        .irq_code_gen = hc_gen_irq_code,
     57        .claim = hc_gain_control,
     58        .start = hc_start,
    6059        .setup_root_hub = hcd_setup_virtual_root_hub,
    61         .fini = ohci_driver_fini,
    62         .name = "OHCI",
    63         .ops = {
    64                 .schedule       = ohci_hc_schedule,
    65                 .irq_hook       = ohci_hc_interrupt,
    66                 .status_hook    = ohci_hc_status,
    67         },
    68 };
    69 
    70 
    71 static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, ddf_dev_t *device)
    72 {
    73         int err;
    74 
    75         assert(hcd);
    76         assert(hcd_get_driver_data(hcd) == NULL);
    77 
    78         hc_t *instance = malloc(sizeof(hc_t));
    79         if (!instance)
    80                 return ENOMEM;
    81 
    82         if ((err = hc_init(instance, res)) != EOK)
    83                 goto err;
    84 
    85         if ((err = ohci_bus_init(&instance->bus, hcd, instance)))
    86                 goto err;
    87 
    88         hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops, &instance->bus.base.base);
    89 
    90         return EOK;
    91 
    92 err:
    93         free(instance);
    94         return err;
    95 }
    96 
    97 static int ohci_driver_claim(hcd_t *hcd, ddf_dev_t *dev)
    98 {
    99         hc_t *hc = hcd_get_driver_data(hcd);
    100         assert(hc);
    101 
    102         hc_gain_control(hc);
    103 
    104         return EOK;
    105 }
    106 
    107 static int ohci_driver_start(hcd_t *hcd, bool interrupts)
    108 {
    109         hc_t *hc = hcd_get_driver_data(hcd);
    110         assert(hc);
    111 
    112         hc->hw_interrupts = interrupts;
    113         hc_start(hc);
    114         return EOK;
    115 }
    116 
    117 static void ohci_driver_fini(hcd_t *hcd)
    118 {
    119         assert(hcd);
    120         hc_t *hc = hcd_get_driver_data(hcd);
    121         if (hc)
    122                 hc_fini(hc);
    123 
    124         hcd_set_implementation(hcd, NULL, NULL, NULL);
    125         free(hc);
    126 }
    127 
    128 /** Initializes a new ddf driver instance of OHCI hcd.
    129  *
    130  * @param[in] device DDF instance of the device to initialize.
    131  * @return Error code.
    132  */
    133 static int ohci_dev_add(ddf_dev_t *device)
    134 {
    135         usb_log_debug("ohci_dev_add() called\n");
    136         assert(device);
    137         return hcd_ddf_add_hc(device, &ohci_hc_driver);
    138 }
    139 
    140 static int ohci_fun_online(ddf_fun_t *fun)
    141 {
    142         return hcd_ddf_device_online(fun);
    143 }
    144 
    145 static int ohci_fun_offline(ddf_fun_t *fun)
    146 {
    147         return hcd_ddf_device_offline(fun);
    148 }
    149 
    150 
    151 static const driver_ops_t ohci_driver_ops = {
    152         .dev_add = ohci_dev_add,
    153         .fun_online = ohci_fun_online,
    154         .fun_offline = ohci_fun_offline
    155 };
    156 
    157 static const driver_t ohci_driver = {
    158         .name = NAME,
    159         .driver_ops = &ohci_driver_ops
     60        .hc_gone = hc_gone,
    16061};
    16162
     
    17172{
    17273        log_init(NAME);
    173         return ddf_driver_main(&ohci_driver);
     74        return hc_driver_main(&ohci_driver);
    17475}
    17576
Note: See TracChangeset for help on using the changeset viewer.