Changeset 063ead6f in mainline for uspace/drv/uhci-hcd/main.c
- Timestamp:
- 2011-02-20T21:37:20Z (14 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/main.c
rc20da9f r063ead6f 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h> 37 #include <device/hw_res.h> 36 38 37 39 #include <errno.h> … … 46 48 #define NAME "uhci-hcd" 47 49 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 } 50 static int uhci_add_device(device_t *device); 56 51 57 52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle, … … 75 70 } 76 71 72 77 73 static 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, 79 75 .get_address = usb_iface_get_address 80 76 }; 81 77 /*----------------------------------------------------------------------------*/ 82 78 static device_ops_t uhci_ops = { 83 79 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 84 80 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 85 81 }; 82 /*----------------------------------------------------------------------------*/ 83 static driver_ops_t uhci_driver_ops = { 84 .add_device = uhci_add_device, 85 }; 86 /*----------------------------------------------------------------------------*/ 87 static driver_t uhci_driver = { 88 .name = NAME, 89 .driver_ops = &uhci_driver_ops 90 }; 91 /*----------------------------------------------------------------------------*/ 92 static 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...) \ 102 if (ret != EOK) { \ 103 usb_log_error(message); \ 104 return ret; \ 105 } 86 106 87 107 static int uhci_add_device(device_t *device) … … 96 116 int irq; 97 117 98 int r c = 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); 100 120 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); 107 123 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 108 124 io_reg_base, io_reg_size, irq); 109 125 126 ret = pci_enable_interrupts(device); 127 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 128 110 129 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; 114 138 } 115 139 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); 117 142 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); 119 146 return ret; 120 147 } 148 121 149 device_t *rh; 122 150 ret = setup_root_hub(&rh, device); 123 124 151 if (ret != EOK) { 125 152 usb_log_error("Failed to setup uhci root hub.\n"); 126 /* TODO: destroy uhci here */ 153 uhci_fini(uhci_hc); 154 free(uhci_hc); 127 155 return ret; 128 156 } … … 131 159 if (ret != EOK) { 132 160 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); 134 164 return ret; 135 165 } 136 166 137 167 device->driver_data = uhci_hc; 138 139 168 return EOK; 140 169 } 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 /*----------------------------------------------------------------------------*/ 151 171 int main(int argc, char *argv[]) 152 172 { 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); 158 175 159 176 return driver_main(&uhci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.