Changeset b4b534ac in mainline for uspace/drv/bus/usb/uhci/main.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

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

    r5b18137 rb4b534ac  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup drvusbuhci
    2929 * @{
    3030 */
     
    3232 * @brief UHCI driver initialization
    3333 */
     34
     35#include <assert.h>
    3436#include <ddf/driver.h>
     37#include <devman.h>
    3538#include <errno.h>
     39#include <io/log.h>
     40#include <io/logctl.h>
     41#include <pci_dev_iface.h>
     42#include <stdio.h>
    3643#include <str_error.h>
     44#include <usb/debug.h>
     45#include <usb/host/ddf_helpers.h>
    3746
    38 #include <usb/ddfiface.h>
    39 #include <usb/debug.h>
    40 
    41 #include "uhci.h"
     47#include "hc.h"
    4248
    4349#define NAME "uhci"
    4450
    45 static int uhci_dev_add(ddf_dev_t *device);
     51static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
     52static void uhci_driver_fini(hcd_t *);
     53static int disable_legacy(ddf_dev_t *);
    4654
    47 static driver_ops_t uhci_driver_ops = {
    48         .dev_add = uhci_dev_add,
     55static const ddf_hc_driver_t uhci_hc_driver = {
     56        .claim = disable_legacy,
     57        .hc_speed = USB_SPEED_FULL,
     58        .irq_code_gen = uhci_hc_gen_irq_code,
     59        .init = uhci_driver_init,
     60        .fini = uhci_driver_fini,
     61        .name = "UHCI",
     62        .ops = {
     63                .schedule    = uhci_hc_schedule,
     64                .irq_hook    = uhci_hc_interrupt,
     65                .status_hook = uhci_hc_status,
     66        },
    4967};
    5068
    51 static driver_t uhci_driver = {
    52         .name = NAME,
    53         .driver_ops = &uhci_driver_ops
    54 };
     69static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
     70{
     71        assert(hcd);
     72        assert(hcd_get_driver_data(hcd) == NULL);
     73
     74        hc_t *instance = malloc(sizeof(hc_t));
     75        if (!instance)
     76                return ENOMEM;
     77
     78        const int ret = hc_init(instance, res, irq);
     79        if (ret == EOK) {
     80                hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
     81        } else {
     82                free(instance);
     83        }
     84        return ret;
     85}
     86
     87static void uhci_driver_fini(hcd_t *hcd)
     88{
     89        assert(hcd);
     90        hc_t *hc = hcd_get_driver_data(hcd);
     91        if (hc)
     92                hc_fini(hc);
     93
     94        hcd_set_implementation(hcd, NULL, NULL);
     95        free(hc);
     96}
     97
     98/** Call the PCI driver with a request to clear legacy support register
     99 *
     100 * @param[in] device Device asking to disable interrupts
     101 * @return Error code.
     102 */
     103static int disable_legacy(ddf_dev_t *device)
     104{
     105        assert(device);
     106
     107        async_sess_t *parent_sess = devman_parent_device_connect(
     108            ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
     109        if (!parent_sess)
     110                return ENOMEM;
     111
     112        /* See UHCI design guide page 45 for these values.
     113         * Write all WC bits in USB legacy register */
     114        const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
     115
     116        async_hangup(parent_sess);
     117        return rc;
     118}
    55119
    56120/** Initialize a new ddf driver instance for uhci hc and hub.
     
    59123 * @return Error code.
    60124 */
    61 int uhci_dev_add(ddf_dev_t *device)
     125static int uhci_dev_add(ddf_dev_t *device)
    62126{
    63127        usb_log_debug2("uhci_dev_add() called\n");
    64128        assert(device);
     129        return hcd_ddf_add_hc(device, &uhci_hc_driver);
     130}
    65131
    66         const int ret = device_setup_uhci(device);
    67         if (ret != EOK) {
    68                 usb_log_error("Failed to initialize UHCI driver: %s.\n",
    69                     str_error(ret));
    70         } else {
    71                 usb_log_info("Controlling new UHCI device '%s'.\n",
    72                     ddf_dev_get_name(device));
    73         }
     132static const driver_ops_t uhci_driver_ops = {
     133        .dev_add = uhci_dev_add,
     134};
    74135
    75         return ret;
    76 }
     136static const driver_t uhci_driver = {
     137        .name = NAME,
     138        .driver_ops = &uhci_driver_ops
     139};
     140
    77141
    78142/** Initialize global driver structures (NONE).
     
    88152        printf(NAME ": HelenOS UHCI driver.\n");
    89153        log_init(NAME);
    90 
     154        logctl_set_log_level(NAME, LVL_NOTE);
    91155        return ddf_driver_main(&uhci_driver);
    92156}
Note: See TracChangeset for help on using the changeset viewer.