Ignore:
File:
1 edited

Legend:

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

    r8b54fe6 rd57122c  
    7676}
    7777/*----------------------------------------------------------------------------*/
    78 /** Get address of the device identified by handle.
    79  *
    80  * @param[in] dev DDF instance of the device to use.
    81  * @param[in] iid (Unused).
    82  * @param[in] call Pointer to the call that represents interrupt.
    83  */
    84 static int usb_iface_get_address(
    85     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
     78/** Get USB address assigned to root hub.
     79 *
     80 * @param[in] fun Root hub function.
     81 * @param[out] address Store the address here.
     82 * @return Error code.
     83 */
     84static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)
    8685{
    8786        assert(fun);
    88         usb_device_manager_t *manager =
    89             &dev_to_ohci(fun->dev)->hc.generic.dev_manager;
    90 
    91         const usb_address_t addr = usb_device_manager_find(manager, handle);
    92         if (addr < 0) {
    93                 return addr;
    94         }
    9587
    9688        if (address != NULL) {
    97                 *address = addr;
     89                *address = dev_to_ohci(fun->dev)->hc.rh.address;
    9890        }
    9991
     
    10799 * @return Error code.
    108100 */
    109 static int usb_iface_get_hc_handle(
     101static int rh_get_hc_handle(
    110102    ddf_fun_t *fun, devman_handle_t *handle)
    111103{
     
    121113/** Root hub USB interface */
    122114static usb_iface_t usb_iface = {
    123         .get_hc_handle = usb_iface_get_hc_handle,
    124         .get_address = usb_iface_get_address
     115        .get_hc_handle = rh_get_hc_handle,
     116        .get_my_address = rh_get_my_address,
    125117};
    126118/*----------------------------------------------------------------------------*/
     
    148140int device_setup_ohci(ddf_dev_t *device)
    149141{
    150         assert(device);
    151 
    152         ohci_t *instance = malloc(sizeof(ohci_t));
     142        if (device == NULL)
     143                return EBADMEM;
     144
     145        ohci_t *instance = ddf_dev_data_alloc(device,sizeof(ohci_t));
    153146        if (instance == NULL) {
    154147                usb_log_error("Failed to allocate OHCI driver.\n");
    155148                return ENOMEM;
    156149        }
    157         instance->rh_fun = NULL;
    158         instance->hc_fun = NULL;
    159150
    160151#define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
    161152if (ret != EOK) { \
    162153        if (instance->hc_fun) { \
     154                instance->hc_fun->driver_data = NULL; \
    163155                ddf_fun_destroy(instance->hc_fun); \
    164156        } \
    165157        if (instance->rh_fun) { \
     158                instance->rh_fun->driver_data = NULL; \
    166159                ddf_fun_destroy(instance->rh_fun); \
    167160        } \
    168         free(instance); \
    169161        usb_log_error(message); \
    170162        return ret; \
     
    195187            (void *) reg_base, reg_size, irq);
    196188
    197         const size_t cmd_count = hc_irq_cmd_count();
    198         irq_cmd_t irq_cmds[cmd_count];
    199         irq_code_t irq_code = { .cmdcount = cmd_count, .cmds = irq_cmds };
    200 
    201         ret =
    202             hc_get_irq_commands(irq_cmds, sizeof(irq_cmds), reg_base, reg_size);
    203         CHECK_RET_DEST_FREE_RETURN(ret,
    204             "Failed to generate IRQ commands: %s.\n", str_error(ret));
     189        const size_t ranges_count = hc_irq_pio_range_count();
     190        const size_t cmds_count = hc_irq_cmd_count();
     191        irq_pio_range_t irq_ranges[ranges_count];
     192        irq_cmd_t irq_cmds[cmds_count];
     193        irq_code_t irq_code = {
     194                .rangecount = ranges_count,
     195                .ranges = irq_ranges,
     196                .cmdcount = cmds_count,
     197                .cmds = irq_cmds
     198        };
     199
     200        ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
     201            sizeof(irq_cmds), reg_base, reg_size);
     202        CHECK_RET_DEST_FREE_RETURN(ret,
     203            "Failed to generate IRQ code: %s.\n", str_error(ret));
    205204
    206205
     
    227226            "Failed to init ohci_hcd: %s.\n", str_error(ret));
    228227
    229         device->driver_data = instance;
    230 
    231228#define CHECK_RET_FINI_RETURN(ret, message...) \
    232229if (ret != EOK) { \
Note: See TracChangeset for help on using the changeset viewer.