Changeset 53f1c87 in mainline
- Timestamp:
- 2011-03-25T23:37:10Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b3f655f
- Parents:
- fa3de85
- Location:
- uspace/drv/ohci
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/Makefile
rfa3de85 r53f1c87 37 37 main.c \ 38 38 hc.c \ 39 ohci.c \ 39 40 root_hub.c \ 40 41 pci.c -
uspace/drv/ohci/hc.c
rfa3de85 r53f1c87 39 39 #include <usb/debug.h> 40 40 #include <usb/usb.h> 41 #include <usb/hub.h>42 41 #include <usb/ddfiface.h> 43 42 #include <usb/usbdevice.h> … … 45 44 #include "hc.h" 46 45 47 static int dummy_reset(int foo, void *arg);48 46 static int interrupt_emulator(hc_t *instance); 47 /*----------------------------------------------------------------------------*/ 48 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun) 49 { 50 assert(instance); 51 assert(hub_fun); 52 53 usb_address_t hub_address = 54 device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL); 55 instance->rh.address = hub_address; 56 usb_device_keeper_bind( 57 &instance->manager, hub_address, hub_fun->handle); 58 59 char *match_str = NULL; 60 int ret = asprintf(&match_str, "usb&mid"); 61 ret = (match_str == NULL) ? ret : EOK; 62 if (ret < 0) { 63 usb_log_error("Failed to create root hub match-id string.\n"); 64 return ret; 65 } 66 67 ret = ddf_fun_add_match_id(hub_fun, match_str, 100); 68 if (ret != EOK) { 69 usb_log_error("Failed add create root hub match-id.\n"); 70 } 71 return ret; 72 } 49 73 /*----------------------------------------------------------------------------*/ 50 74 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, … … 68 92 } 69 93 94 rh_init(&instance->rh, dev, instance->registers); 70 95 71 rh_init(&instance->rh, dev, instance->registers);72 96 /* TODO: implement */ 73 return EOK;74 }75 /*----------------------------------------------------------------------------*/76 int hc_register_hub(hc_t *instance)77 {78 async_usleep(1000000);79 #define CHECK_RET_RETURN(ret, msg...) \80 if (ret != EOK) { \81 usb_log_error(msg); \82 return ret; \83 } else (void)084 assert(instance);85 assert(instance->ddf_instance);86 assert(instance->ddf_instance->handle);87 ddf_dev_t *dev = instance->rh.device;88 int ret = EOK;89 90 usb_hc_connection_t conn;91 ret =92 usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);93 CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");94 95 ret = usb_hc_connection_open(&conn);96 CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");97 98 usb_address_t address;99 devman_handle_t handle;100 ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,101 0, instance, &address, &handle, NULL, NULL, NULL);102 if (ret != EOK) {103 usb_log_error("Failed to add rh device.\n");104 instance->rh.address = -1;105 return ret;106 }107 108 ret = usb_hc_connection_close(&conn);109 CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");110 97 return EOK; 111 98 } … … 134 121 } 135 122 /*----------------------------------------------------------------------------*/ 136 static int dummy_reset(int foo, void *arg) 137 { 138 hc_t *hc = (hc_t*)arg; 139 assert(hc); 140 hc->rh.address = 0; 141 return EOK; 142 } 143 /*----------------------------------------------------------------------------*/ 144 static int interrupt_emulator(hc_t *instance) 123 int interrupt_emulator(hc_t *instance) 145 124 { 146 125 assert(instance); -
uspace/drv/ohci/hc.h
rfa3de85 r53f1c87 57 57 } hc_t; 58 58 59 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun); 60 59 61 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 60 62 uintptr_t regs, size_t reg_size, bool interrupts); 61 62 int hc_register_hub(hc_t *instance);63 63 64 64 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); -
uspace/drv/ohci/iface.h
rfa3de85 r53f1c87 33 33 * Common OHCI definitions. 34 34 */ 35 #ifndef DRV_OHCI_ OHCI_H36 #define DRV_OHCI_ OHCI_H35 #ifndef DRV_OHCI_IFACE_H 36 #define DRV_OHCI_IFACE_H 37 37 38 38 #include <usbhc_iface.h> 39 40 #define NAME "ohci"41 39 42 40 extern usbhc_iface_t hc_iface; -
uspace/drv/ohci/main.c
rfa3de85 r53f1c87 34 34 */ 35 35 #include <ddf/driver.h> 36 #include <ddf/interrupt.h>37 #include <device/hw_res.h>38 36 #include <errno.h> 39 37 #include <str_error.h> 40 38 41 #include <usb_iface.h>42 #include <usb/ddfiface.h>43 39 #include <usb/debug.h> 44 40 45 #include " pci.h"46 #include "iface.h" 47 # include "hc.h"41 #include "ohci.h" 42 43 #define NAME "ohci" 48 44 49 45 static int ohci_add_device(ddf_dev_t *device); 50 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)51 {52 assert(handle);53 assert(fun != NULL);54 55 *handle = fun->handle;56 return EOK;57 }58 /*----------------------------------------------------------------------------*/59 static int get_address(60 ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)61 {62 assert(fun);63 usb_device_keeper_t *manager = &fun_to_hc(fun)->manager;64 usb_address_t addr = usb_device_keeper_find(manager, handle);65 if (addr < 0) {66 return addr;67 }68 69 if (address != NULL) {70 *address = addr;71 }72 73 return EOK;74 }75 /*----------------------------------------------------------------------------*/76 /** IRQ handling callback, identifies device77 *78 * @param[in] dev DDF instance of the device to use.79 * @param[in] iid (Unused).80 * @param[in] call Pointer to the call that represents interrupt.81 */82 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)83 {84 assert(dev);85 hc_t *hc = (hc_t*)dev->driver_data;86 assert(hc);87 hc_interrupt(hc, 0);88 }89 46 /*----------------------------------------------------------------------------*/ 90 47 static driver_ops_t ohci_driver_ops = { … … 97 54 }; 98 55 /*----------------------------------------------------------------------------*/ 99 static usb_iface_t hc_usb_iface = {100 .get_address = get_address,101 .get_hc_handle = get_hc_handle,102 };103 /*----------------------------------------------------------------------------*/104 static ddf_dev_ops_t hc_ops = {105 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,106 .interfaces[USBHC_DEV_IFACE] = &hc_iface,107 };108 /*----------------------------------------------------------------------------*/109 56 /** Initializes a new ddf driver instance of OHCI hcd. 110 57 * … … 112 59 * @return Error code. 113 60 */ 114 staticint ohci_add_device(ddf_dev_t *device)61 int ohci_add_device(ddf_dev_t *device) 115 62 { 63 usb_log_debug("ohci_add_device() called\n"); 116 64 assert(device); 117 #define CHECK_RET_RETURN(ret, message...) \ 118 if (ret != EOK) { \ 119 usb_log_error(message); \ 120 return ret; \ 121 } 122 123 uintptr_t mem_reg_base = 0; 124 size_t mem_reg_size = 0; 125 int irq = 0; 126 127 int ret = 128 pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq); 129 CHECK_RET_RETURN(ret, 130 "Failed(%d) to get memory addresses:.\n", ret, device->handle); 131 usb_log_info("Memory mapped regs at 0x%X (size %zu), IRQ %d.\n", 132 mem_reg_base, mem_reg_size, irq); 133 134 ret = pci_disable_legacy(device); 135 CHECK_RET_RETURN(ret, 136 "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret)); 137 138 hc_t *hcd = malloc(sizeof(hc_t)); 139 if (hcd == NULL) { 65 ohci_t *ohci = malloc(sizeof(ohci_t)); 66 if (ohci == NULL) { 140 67 usb_log_error("Failed to allocate OHCI driver.\n"); 141 68 return ENOMEM; 142 69 } 143 70 144 ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 145 if (hc_fun == NULL) { 146 usb_log_error("Failed to create OHCI function.\n"); 147 free(hcd); 148 return ENOMEM; 149 } 150 151 152 bool interrupts = false; 153 #ifdef CONFIG_USBHC_NO_INTERRUPTS 154 usb_log_warning("Interrupts disabled in OS config, " \ 155 "falling back to polling.\n"); 156 #else 157 ret = pci_enable_interrupts(device); 71 int ret = ohci_init(ohci, device); 158 72 if (ret != EOK) { 159 usb_log_ warning("Failed to enable interrupts: %s.\n",73 usb_log_error("Failed to initialize OHCI driver: %s.\n", 160 74 str_error(ret)); 161 usb_log_info("HW interrupts not available, " \162 "falling back to polling.\n");163 } else {164 usb_log_debug("Hw interrupts enabled.\n");165 interrupts = true;166 }167 #endif168 169 ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);170 if (ret != EOK) {171 usb_log_error("Failed to initialize OHCI driver.\n");172 free(hcd);173 75 return ret; 174 76 } 77 device->driver_data = ohci; 175 78 176 ret = register_interrupt_handler(device, irq, irq_handler, NULL); 177 178 hc_fun->ops = &hc_ops; 179 ret = ddf_fun_bind(hc_fun); 180 if (ret != EOK) { 181 usb_log_error("Failed to bind OHCI function.\n"); 182 ddf_fun_destroy(hc_fun); 183 free(hcd); 184 return ret; 185 } 186 hc_fun->driver_data = hcd; 187 188 fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd); 189 fibril_add_ready(later); 190 191 usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n", 192 device->name, device->handle); 79 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); 193 80 194 81 return EOK; 195 #undef CHECK_RET_RETURN196 82 } 197 83 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.