Changeset 62265ce in mainline


Ignore:
Timestamp:
2011-05-07T14:26:58Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dc5f2fb
Parents:
7ab7c7f6
Message:

OHCI initialization refactoring

Location:
uspace/drv/ohci
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/hc.c

    r7ab7c7f6 r62265ce  
    9595}
    9696/*----------------------------------------------------------------------------*/
    97 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
    98     uintptr_t regs, size_t reg_size, bool interrupts)
     97int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts)
    9998{
    10099        assert(instance);
  • uspace/drv/ohci/hc.h

    r7ab7c7f6 r62265ce  
    7777int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    7878
    79 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
    80      uintptr_t regs, size_t reg_size, bool interrupts);
     79int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
    8180
    8281void hc_start_hw(hc_t *instance);
  • uspace/drv/ohci/main.c

    r7ab7c7f6 r62265ce  
    6969        }
    7070
    71         int ret = ohci_init(ohci, device);
     71        int ret = device_setup_ohci(device, ohci);
    7272        if (ret != EOK) {
    7373                usb_log_error("Failed to initialize OHCI driver: %s.\n",
  • uspace/drv/ohci/ohci.c

    r7ab7c7f6 r62265ce  
    127127 *  - registers interrupt handler
    128128 */
    129 int ohci_init(ohci_t *instance, ddf_dev_t *device)
     129int device_setup_ohci(ddf_dev_t *device, ohci_t *instance)
    130130{
    131131        assert(instance);
    132         instance->hc_fun = NULL;
    133         instance->rh_fun = NULL;
     132
     133        instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
     134        if (instance->hc_fun == NULL) {
     135                usb_log_error("Failed to create HC function.\n");
     136                return ENOMEM;
     137        }
     138        instance->hc_fun->ops = &hc_ops;
     139        instance->hc_fun->driver_data = &instance->hc;
     140
     141        instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
     142        if (instance->rh_fun == NULL) {
     143                ddf_fun_destroy(instance->hc_fun);
     144                usb_log_error("Failed to create RH function.\n");
     145                return ENOMEM;
     146        }
     147        instance->rh_fun->ops = &rh_ops;
     148        instance->rh_fun->driver_data = NULL;
     149
    134150#define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
    135151if (ret != EOK) { \
    136152        usb_log_error(message); \
    137         if (instance->hc_fun) \
    138                 ddf_fun_destroy(instance->hc_fun); \
    139         if (instance->rh_fun) \
    140                 ddf_fun_destroy(instance->rh_fun); \
     153        instance->hc_fun->ops = NULL; \
     154        instance->hc_fun->driver_data = NULL; \
     155        instance->rh_fun->ops = NULL; \
     156        instance->rh_fun->driver_data = NULL; \
     157        ddf_fun_destroy(instance->hc_fun); \
     158        ddf_fun_destroy(instance->rh_fun); \
    141159        return ret; \
    142160}
     
    156174        bool interrupts = false;
    157175#ifdef CONFIG_USBHC_NO_INTERRUPTS
    158         usb_log_warning("Interrupts disabled in OS config, " \
     176        usb_log_warning("Interrupts disabled in OS config, "
    159177            "falling back to polling.\n");
    160178#else
     
    163181                usb_log_warning("Failed to enable interrupts: %s.\n",
    164182                    str_error(ret));
    165                 usb_log_info("HW interrupts not available, " \
     183                usb_log_info("HW interrupts not available, "
    166184                    "falling back to polling.\n");
    167185        } else {
     
    171189#endif
    172190
    173         instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
    174         ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    175         CHECK_RET_DEST_FUN_RETURN(ret,
    176             "Failed(%d) to create HC function.\n", ret);
    177 
    178         ret = hc_init(&instance->hc, instance->hc_fun, device,
    179             mem_reg_base, mem_reg_size, interrupts);
     191        ret = hc_init(&instance->hc, mem_reg_base, mem_reg_size, interrupts);
    180192        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);
    181         instance->hc_fun->ops = &hc_ops;
    182         instance->hc_fun->driver_data = &instance->hc;
    183         ret = ddf_fun_bind(instance->hc_fun);
    184         CHECK_RET_DEST_FUN_RETURN(ret,
    185             "Failed(%d) to bind OHCI device function: %s.\n",
    186             ret, str_error(ret));
    187 #undef CHECK_RET_HC_RETURN
    188193
    189194#define CHECK_RET_FINI_RETURN(ret, message...) \
    190195if (ret != EOK) { \
    191         usb_log_error(message); \
    192         if (instance->hc_fun) \
    193                 ddf_fun_destroy(instance->hc_fun); \
    194         if (instance->rh_fun) \
    195                 ddf_fun_destroy(instance->rh_fun); \
    196196        hc_fini(&instance->hc); \
    197         return ret; \
     197        CHECK_RET_DEST_FUN_RETURN(ret, message); \
    198198}
    199199
     
    204204            "Failed(%d) to register interrupt handler.\n", ret);
    205205
    206         instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
    207         ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
     206        ret = ddf_fun_bind(instance->hc_fun);
    208207        CHECK_RET_FINI_RETURN(ret,
    209             "Failed(%d) to create root hub function.\n", ret);
    210 
    211 
    212         instance->rh_fun->ops = &rh_ops;
    213         instance->rh_fun->driver_data = NULL;
    214        
     208            "Failed(%d) to bind OHCI device function: %s.\n",
     209            ret, str_error(ret));
     210
    215211        device->driver_data = instance;
    216212
    217213        hc_start_hw(&instance->hc);
    218214        return EOK;
     215
     216#undef CHECK_RET_DEST_FUN_RETURN
    219217#undef CHECK_RET_FINI_RETURN
    220218}
  • uspace/drv/ohci/ohci.h

    r7ab7c7f6 r62265ce  
    4949} ohci_t;
    5050
    51 int ohci_init(ohci_t *instance, ddf_dev_t *device);
     51int device_setup_ohci(ddf_dev_t *device, ohci_t *instance);
    5252
    5353#endif
Note: See TracChangeset for help on using the changeset viewer.