Changeset 063ead6f in mainline for uspace/drv/uhci-hcd/main.c


Ignore:
Timestamp:
2011-02-20T21:37:20Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41e645c, da7c0a9
Parents:
c20da9f (diff), 423e8c81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

File:
1 edited

Legend:

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

    rc20da9f r063ead6f  
    3434#include <driver.h>
    3535#include <usb_iface.h>
     36#include <usb/ddfiface.h>
     37#include <device/hw_res.h>
    3638
    3739#include <errno.h>
     
    4648#define NAME "uhci-hcd"
    4749
    48 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    49 {
    50         /* This shall be called only for the UHCI itself. */
    51         assert(dev->parent == NULL);
    52 
    53         *handle = dev->handle;
    54         return EOK;
    55 }
     50static int uhci_add_device(device_t *device);
    5651
    5752static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
     
    7570}
    7671
     72
    7773static usb_iface_t hc_usb_iface = {
    78         .get_hc_handle = usb_iface_get_hc_handle,
     74        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    7975        .get_address = usb_iface_get_address
    8076};
    81 
     77/*----------------------------------------------------------------------------*/
    8278static device_ops_t uhci_ops = {
    8379        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    8480        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    8581};
     82/*----------------------------------------------------------------------------*/
     83static driver_ops_t uhci_driver_ops = {
     84        .add_device = uhci_add_device,
     85};
     86/*----------------------------------------------------------------------------*/
     87static driver_t uhci_driver = {
     88        .name = NAME,
     89        .driver_ops = &uhci_driver_ops
     90};
     91/*----------------------------------------------------------------------------*/
     92static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call)
     93{
     94        assert(device);
     95        uhci_t *hc = dev_to_uhci(device);
     96        uint16_t status = IPC_GET_ARG1(*call);
     97        assert(hc);
     98        uhci_interrupt(hc, status);
     99}
     100/*----------------------------------------------------------------------------*/
     101#define CHECK_RET_RETURN(ret, message...) \
     102if (ret != EOK) { \
     103        usb_log_error(message); \
     104        return ret; \
     105}
    86106
    87107static int uhci_add_device(device_t *device)
     
    96116        int irq;
    97117
    98         int rc = pci_get_my_registers(device,
    99             &io_reg_base, &io_reg_size, &irq);
     118        int ret =
     119            pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    100120
    101         if (rc != EOK) {
    102                 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n",
    103                     rc, device->handle);
    104                 return rc;
    105         }
    106 
     121        CHECK_RET_RETURN(ret,
     122            "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    107123        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    108124            io_reg_base, io_reg_size, irq);
    109125
     126        ret = pci_enable_interrupts(device);
     127        CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
     128
    110129        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
    111         if (!uhci_hc) {
    112                 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n");
    113                 return ENOMEM;
     130        ret = (uhci_hc != NULL) ? EOK : ENOMEM;
     131        CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
     132
     133        ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
     134        if (ret != EOK) {
     135                usb_log_error("Failed to init uhci-hcd.\n");
     136                free(uhci_hc);
     137                return ret;
    114138        }
    115139
    116         int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
     140        ret = register_interrupt_handler(device, irq, irq_handler,
     141            &uhci_hc->interrupt_code);
    117142        if (ret != EOK) {
    118                 usb_log_error("Failed to init uhci-hcd.\n");
     143                usb_log_error("Failed to register interrupt handler.\n");
     144                uhci_fini(uhci_hc);
     145                free(uhci_hc);
    119146                return ret;
    120147        }
     148
    121149        device_t *rh;
    122150        ret = setup_root_hub(&rh, device);
    123 
    124151        if (ret != EOK) {
    125152                usb_log_error("Failed to setup uhci root hub.\n");
    126                 /* TODO: destroy uhci here */
     153                uhci_fini(uhci_hc);
     154                free(uhci_hc);
    127155                return ret;
    128156        }
     
    131159        if (ret != EOK) {
    132160                usb_log_error("Failed to register root hub.\n");
    133                 /* TODO: destroy uhci here */
     161                uhci_fini(uhci_hc);
     162                free(uhci_hc);
     163                free(rh);
    134164                return ret;
    135165        }
    136166
    137167        device->driver_data = uhci_hc;
    138 
    139168        return EOK;
    140169}
    141 
    142 static driver_ops_t uhci_driver_ops = {
    143         .add_device = uhci_add_device,
    144 };
    145 
    146 static driver_t uhci_driver = {
    147         .name = NAME,
    148         .driver_ops = &uhci_driver_ops
    149 };
    150 
     170/*----------------------------------------------------------------------------*/
    151171int main(int argc, char *argv[])
    152172{
    153         /*
    154          * Do some global initializations.
    155          */
    156         sleep(5);
    157         usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
     173        sleep(3);
     174        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    158175
    159176        return driver_main(&uhci_driver);
Note: See TracChangeset for help on using the changeset viewer.