Ignore:
File:
1 edited

Legend:

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

    rfb78ae72 re0df6c2  
    3434#include <driver.h>
    3535#include <usb_iface.h>
    36 #include <device/hw_res.h>
    3736
    3837#include <errno.h>
     
    4746#define NAME "uhci-hcd"
    4847
    49 static int uhci_add_device(device_t *device);
    50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle);
    51 /*----------------------------------------------------------------------------*/
    5248static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    5349{
     
    5854        return EOK;
    5955}
    60 /*----------------------------------------------------------------------------*/
     56
    6157static usb_iface_t hc_usb_iface = {
    6258        .get_hc_handle = usb_iface_get_hc_handle
    6359};
    64 /*----------------------------------------------------------------------------*/
     60
    6561static device_ops_t uhci_ops = {
    6662        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    6763        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    6864};
    69 /*----------------------------------------------------------------------------*/
    70 static driver_ops_t uhci_driver_ops = {
    71         .add_device = uhci_add_device,
    72 };
    73 /*----------------------------------------------------------------------------*/
    74 static driver_t uhci_driver = {
    75         .name = NAME,
    76         .driver_ops = &uhci_driver_ops
    77 };
    78 /*----------------------------------------------------------------------------*/
    79 static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call)
    80 {
    81         assert(device);
    82         uhci_t *hc = dev_to_uhci(device);
    83         uint16_t status = IPC_GET_ARG1(*call);
    84         assert(hc);
    85         uhci_interrupt(hc, status);
    86 }
    87 /*----------------------------------------------------------------------------*/
    88 #define CHECK_RET_RETURN(ret, message...) \
    89 if (ret != EOK) { \
    90         usb_log_error(message); \
    91         return ret; \
    92 }
    9365
    9466static int uhci_add_device(device_t *device)
     
    10375        int irq;
    10476
    105         int ret =
    106             pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
     77        int rc = pci_get_my_registers(device,
     78            &io_reg_base, &io_reg_size, &irq);
    10779
    108         CHECK_RET_RETURN(ret,
    109             "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
     80        if (rc != EOK) {
     81                usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n",
     82                    rc, device->handle);
     83                return rc;
     84        }
     85
    11086        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    11187            io_reg_base, io_reg_size, irq);
    11288
    113         ret = pci_enable_interrupts(device);
    114         CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
     89        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
     90        if (!uhci_hc) {
     91                usb_log_error("Failed to allocaete memory for uhci hcd driver.\n");
     92                return ENOMEM;
     93        }
    11594
    116         uhci_t *uhci_hc = malloc(sizeof(uhci_t));
    117         ret = (uhci_hc != NULL) ? EOK : ENOMEM;
    118         CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
    119 
    120         ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
     95        int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
    12196        if (ret != EOK) {
    12297                usb_log_error("Failed to init uhci-hcd.\n");
    123                 free(uhci_hc);
    12498                return ret;
    12599        }
    126 
    127         ret = register_interrupt_handler(device, irq, irq_handler,
    128             &uhci_hc->interrupt_code);
    129         if (ret != EOK) {
    130                 usb_log_error("Failed to register interrupt handler.\n");
    131                 uhci_fini(uhci_hc);
    132                 free(uhci_hc);
    133                 return ret;
    134         }
    135 
    136100        device_t *rh;
    137101        ret = setup_root_hub(&rh, device);
     102
    138103        if (ret != EOK) {
    139104                usb_log_error("Failed to setup uhci root hub.\n");
    140                 uhci_fini(uhci_hc);
    141                 free(uhci_hc);
     105                /* TODO: destroy uhci here */
    142106                return ret;
    143107        }
     
    146110        if (ret != EOK) {
    147111                usb_log_error("Failed to register root hub.\n");
    148                 uhci_fini(uhci_hc);
    149                 free(uhci_hc);
    150                 free(rh);
     112                /* TODO: destroy uhci here */
    151113                return ret;
    152114        }
    153115
    154116        device->driver_data = uhci_hc;
     117
    155118        return EOK;
    156119}
    157 /*----------------------------------------------------------------------------*/
     120
     121static driver_ops_t uhci_driver_ops = {
     122        .add_device = uhci_add_device,
     123};
     124
     125static driver_t uhci_driver = {
     126        .name = NAME,
     127        .driver_ops = &uhci_driver_ops
     128};
     129
    158130int main(int argc, char *argv[])
    159131{
    160         sleep(3);
    161         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     132        /*
     133         * Do some global initializations.
     134         */
     135        sleep(5);
     136        usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
    162137
    163138        return driver_main(&uhci_driver);
Note: See TracChangeset for help on using the changeset viewer.