Changeset 5944244 in mainline for uspace/drv/uhci-hcd/uhci.c


Ignore:
Timestamp:
2011-02-01T23:25:48Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1f5c1e61
Parents:
c56dbe0
Message:

Refactoring uhci_ functions are called on uhci_t not device_t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/uhci.c

    rc56dbe0 r5944244  
    3737#include <usb/usb.h>
    3838
    39 #include "utils/malloc32.h"
    4039#include "uhci.h"
    4140
     
    4443static int uhci_debug_checker(void *arg);
    4544
    46 int uhci_init(device_t *device, void *regs, size_t reg_size)
    47 {
    48         assert(device);
    49         usb_log_info("Initializing device at address %p.\n", device);
    50 
    51 #define CHECK_RET_FREE_INSTANCE(message...) \
     45int uhci_init(uhci_t *instance, void *regs, size_t reg_size)
     46{
     47#define CHECK_RET_RETURN(message...) \
    5248        if (ret != EOK) { \
    5349                usb_log_error(message); \
    54                 if (instance) { \
    55                         free(instance); \
    56                 } \
    5750                return ret; \
    5851        } else (void) 0
    59 
    60         /* create instance */
    61         uhci_t *instance = malloc(sizeof(uhci_t));
    62         int ret = instance ? EOK : ENOMEM;
    63         CHECK_RET_FREE_INSTANCE("Failed to allocate uhci driver instance.\n");
    64 
    65         bzero(instance, sizeof(uhci_t));
    6652
    6753        /* init address keeper(libusb) */
     
    7258        regs_t *io;
    7359        assert(reg_size >= sizeof(regs_t));
    74         ret = pio_enable(regs, reg_size, (void**)&io);
    75         CHECK_RET_FREE_INSTANCE("Failed to gain access to registers at %p.\n", io);
     60        int ret = pio_enable(regs, reg_size, (void**)&io);
     61        CHECK_RET_RETURN("Failed to gain access to registers at %p.\n", io);
    7662        instance->registers = io;
    7763        usb_log_debug("Device registers accessible.\n");
     
    7965        /* init transfer lists */
    8066        ret = uhci_init_transfer_lists(instance->transfers);
    81         CHECK_RET_FREE_INSTANCE("Failed to initialize transfer lists.\n");
     67        CHECK_RET_RETURN("Failed to initialize transfer lists.\n");
    8268        usb_log_debug("Transfer lists initialized.\n");
    8369
     
    8672        instance->frame_list = get_page();
    8773        ret = instance ? EOK : ENOMEM;
    88         CHECK_RET_FREE_INSTANCE("Failed to get frame list page.\n");
     74        CHECK_RET_RETURN("Failed to get frame list page.\n");
    8975
    9076        /* initialize all frames to point to the first queue head */
    91         unsigned i = 0;
    9277        const uint32_t queue =
    9378          instance->transfers[USB_TRANSFER_INTERRUPT].queue_head_pa
    9479          | LINK_POINTER_QUEUE_HEAD_FLAG;
     80        unsigned i = 0;
    9581        for(; i < UHCI_FRAME_LIST_COUNT; ++i) {
    9682                instance->frame_list[i] = queue;
     
    10793        fibril_add_ready(instance->debug_checker);
    10894
    109         usb_log_debug("Starting UHCI HC.\n");
    110         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_RUN_STOP);
     95        /* Start the hc with large(64b) packet FSBR */
     96        pio_write_16(&instance->registers->usbcmd,
     97            UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET);
     98        usb_log_debug("Started UHCI HC.\n");
    11199/*
    112100        uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
     
    114102        pio_write_16(&instance->registers->usbcmd, cmd);
    115103*/
    116         device->driver_data = instance;
    117104        return EOK;
    118105}
     
    152139/*----------------------------------------------------------------------------*/
    153140int uhci_transfer(
     141  uhci_t *instance,
    154142  device_t *dev,
    155143  usb_target_t target,
     
    172160        callback_t *job = NULL;
    173161        int ret = EOK;
     162        assert(dev);
    174163
    175164#define CHECK_RET_TRANS_FREE_JOB_TD(message) \
     
    183172        } else (void) 0
    184173
    185 
    186174        job = callback_get(dev, buffer, size, callback_in, callback_out, arg);
    187175        ret = job ? EOK : ENOMEM;
     
    193181
    194182        td->callback = job;
    195 
    196         assert(dev);
    197         uhci_t *instance = (uhci_t*)dev->driver_data;
    198         assert(instance);
    199183
    200184        usb_log_debug("Appending a new transfer to queue.\n");
Note: See TracChangeset for help on using the changeset viewer.