Changeset a720ff6 in mainline for uspace/drv/bus/usb/uhci/root_hub.c


Ignore:
Timestamp:
2012-12-20T15:42:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
53332b5b
Parents:
d09791e6
Message:

uhci: Use helper routines provided by libusbhost

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/root_hub.c

    rd09791e6 ra720ff6  
    3636#include <str_error.h>
    3737#include <stdio.h>
     38#include <ops/hw_res.h>
    3839
     40#include <usb_iface.h>
    3941#include <usb/debug.h>
    4042
    4143#include "root_hub.h"
     44/** DDF support structure for uhci_rhd driver, provides I/O resources */
     45typedef struct {
     46        /** List of resources available to the root hub. */
     47        hw_resource_list_t resource_list;
     48        /** The only resource in the RH resource list */
     49        hw_resource_t io_regs;
    4250
     51        devman_handle_t hc_handle;
     52} rh_t;
     53
     54/** Gets handle of the respective hc.
     55 *
     56 * @param[in] fun DDF function of uhci device.
     57 * @param[out] handle Host cotnroller handle.
     58 * @return Error code.
     59 */
     60static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     61{
     62        assert(fun);
     63        rh_t *rh = ddf_fun_data_get(fun);
     64
     65        if (handle != NULL)
     66                *handle = rh->hc_handle;
     67        return EOK;
     68}
     69
     70/** USB interface implementation used by RH */
     71static usb_iface_t usb_iface = {
     72        .get_hc_handle = usb_iface_get_hc_handle,
     73};
     74
     75/** Get root hub hw resources (I/O registers).
     76 *
     77 * @param[in] fun Root hub function.
     78 * @return Pointer to the resource list used by the root hub.
     79 */
     80static hw_resource_list_t *get_resource_list(ddf_fun_t *fun)
     81{
     82        assert(fun);
     83        rh_t *rh = ddf_fun_data_get(fun);
     84        assert(rh);
     85        return &rh->resource_list;
     86}
     87
     88/** Interface to provide the root hub driver with hw info */
     89static hw_res_ops_t hw_res_iface = {
     90        .get_resource_list = get_resource_list,
     91        .enable_interrupt = NULL,
     92};
     93
     94/** RH function support for uhci_rhd */
     95static ddf_dev_ops_t rh_ops = {
     96        .interfaces[USB_DEV_IFACE] = &usb_iface,
     97        .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
     98};
    4399/** Root hub initialization
    44100 * @param[in] instance RH structure to initialize
     
    48104 * @return Error code.
    49105 */
    50 int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
     106int rh_init(ddf_dev_t *device, uintptr_t reg_addr, size_t reg_size,
     107    devman_handle_t handle)
    51108{
    52         assert(instance);
    53         assert(fun);
     109        assert(device);
     110       
     111        ddf_fun_t *fun = ddf_fun_create(device, fun_inner, "uhci_rh");
     112        if (!fun) {
     113                usb_log_error("Failed to create UHCI RH function.\n");
     114                return ENOMEM;
     115        }
     116        ddf_fun_set_ops(fun, &rh_ops);
     117
     118        rh_t *instance = ddf_fun_data_alloc(fun, sizeof(rh_t));
    54119
    55120        /* Initialize resource structure */
     
    62127        instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
    63128
    64         const int ret = ddf_fun_add_match_id(fun, "usb&uhci&root-hub", 100);
     129        instance->hc_handle = handle;   
     130
     131        int ret = ddf_fun_add_match_id(fun, "usb&uhci&root-hub", 100);
    65132        if (ret != EOK) {
    66133                usb_log_error("Failed to add root hub match id: %s\n",
    67134                    str_error(ret));
     135                ddf_fun_destroy(fun);
    68136        }
     137
     138        ret = ddf_fun_bind(fun);
     139        if (ret != EOK) {
     140                usb_log_error("Failed to bind root function: %s\n",
     141                    str_error(ret));
     142                ddf_fun_destroy(fun);
     143        }
     144
     145        usb_log_fatal("RH ready, hc handle: %"PRIun"\n", handle);
    69146        return ret;
    70147}
Note: See TracChangeset for help on using the changeset viewer.