source: mainline/uspace/drv/bus/usb/uhci/main.c@ f971e957

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f971e957 was 366e9b6, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhost: setup of the root hub is now a method of an driver

[oue]hci + vhc still use the previous implementation, renamed to hcd_setup_virtual_root_hub. xhci currently does not do anything, so the virtual hub is not created anymore.

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[c7137738]1/*
[c56dbe0]2 * Copyright (c) 2011 Vojtech Horky, Jan Vesely
[c7137738]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
[58563585]28
[e3a07bba]29/** @addtogroup drvusbuhci
[c56dbe0]30 * @{
31 */
32/** @file
[17ceb72]33 * @brief UHCI driver initialization
[c56dbe0]34 */
[8064c2f6]35
36#include <assert.h>
[eb1a2f4]37#include <ddf/driver.h>
[e3a07bba]38#include <devman.h>
[c56dbe0]39#include <errno.h>
[8064c2f6]40#include <io/log.h>
[b74ec299]41#include <io/logctl.h>
[e3a07bba]42#include <pci_dev_iface.h>
[8064c2f6]43#include <stdio.h>
[ab414a6]44#include <str_error.h>
[afcd86e]45#include <usb/debug.h>
[1a0fa29c]46#include <usb/host/ddf_helpers.h>
[afcd86e]47
[1a0fa29c]48#include "hc.h"
[c7137738]49
[497b6f31]50#define NAME "uhci"
[afcd86e]51
[e4d7363]52static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *);
53static int uhci_driver_start(hcd_t *, bool);
[b5f813c]54static void uhci_driver_fini(hcd_t *);
[e4d7363]55static int disable_legacy(hcd_t *, ddf_dev_t *);
[76fbd9a]56
[b5f813c]57static const ddf_hc_driver_t uhci_hc_driver = {
58 .claim = disable_legacy,
59 .irq_code_gen = uhci_hc_gen_irq_code,
60 .init = uhci_driver_init,
[e4d7363]61 .start = uhci_driver_start,
[366e9b6]62 .setup_root_hub = hcd_setup_virtual_root_hub,
[b5f813c]63 .fini = uhci_driver_fini,
64 .name = "UHCI",
65 .ops = {
66 .schedule = uhci_hc_schedule,
67 .irq_hook = uhci_hc_interrupt,
68 .status_hook = uhci_hc_status,
69 },
[36a4738]70};
[76fbd9a]71
[e4d7363]72static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res)
[1a0fa29c]73{
[fc0271a5]74 int err;
75
[1a0fa29c]76 assert(hcd);
[b5f813c]77 assert(hcd_get_driver_data(hcd) == NULL);
[1a0fa29c]78
79 hc_t *instance = malloc(sizeof(hc_t));
80 if (!instance)
81 return ENOMEM;
82
[fc0271a5]83 if ((err = hc_init(instance, res)) != EOK)
84 goto err;
85
86 hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops, &instance->bus.base);
87
88 return EOK;
89
90err:
91 free(instance);
92 return err;
[1a0fa29c]93}
94
[e4d7363]95static int uhci_driver_start(hcd_t *hcd, bool interrupts)
96{
97 assert(hcd);
98 hc_t *hc = hcd_get_driver_data(hcd);
99
100 hc->hw_interrupts = interrupts;
101 hc_start(hc);
102 return EOK;
103}
104
[1a0fa29c]105static void uhci_driver_fini(hcd_t *hcd)
106{
107 assert(hcd);
[b5f813c]108 hc_t *hc = hcd_get_driver_data(hcd);
109 if (hc)
110 hc_fini(hc);
[1a0fa29c]111
[fc0271a5]112 hcd_set_implementation(hcd, NULL, NULL, NULL);
[b5f813c]113 free(hc);
[1a0fa29c]114}
115
[e3a07bba]116/** Call the PCI driver with a request to clear legacy support register
117 *
118 * @param[in] device Device asking to disable interrupts
119 * @return Error code.
120 */
[e4d7363]121static int disable_legacy(hcd_t *hcd, ddf_dev_t *device)
[e3a07bba]122{
123 assert(device);
124
125 async_sess_t *parent_sess = devman_parent_device_connect(
[b4b534ac]126 ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
[e3a07bba]127 if (!parent_sess)
128 return ENOMEM;
129
130 /* See UHCI design guide page 45 for these values.
131 * Write all WC bits in USB legacy register */
132 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
133
134 async_hangup(parent_sess);
135 return rc;
136}
[76fbd9a]137
[17ceb72]138/** Initialize a new ddf driver instance for uhci hc and hub.
[a7e2f0d]139 *
140 * @param[in] device DDF instance of the device to initialize.
141 * @return Error code.
142 */
[b5f813c]143static int uhci_dev_add(ddf_dev_t *device)
[86341e2]144{
[0c0f823b]145 usb_log_debug2("uhci_dev_add() called\n");
[9351353]146 assert(device);
[a799708]147 return hcd_ddf_add_hc(device, &uhci_hc_driver);
[c7137738]148}
[ea993d18]149
[b5f813c]150static const driver_ops_t uhci_driver_ops = {
151 .dev_add = uhci_dev_add,
152};
153
154static const driver_t uhci_driver = {
155 .name = NAME,
156 .driver_ops = &uhci_driver_ops
157};
[fbefd0e]158
[76fbd9a]159
[17ceb72]160/** Initialize global driver structures (NONE).
[a7e2f0d]161 *
[ea993d18]162 * @param[in] argc Number of arguments in argv vector (ignored).
[a7e2f0d]163 * @param[in] argv Cmdline argument vector (ignored).
164 * @return Error code.
165 *
166 * Driver debug level is set here.
167 */
[c7137738]168int main(int argc, char *argv[])
169{
[fbefd0e]170 printf(NAME ": HelenOS UHCI driver.\n");
[920d0fc]171 log_init(NAME);
[b74ec299]172 logctl_set_log_level(NAME, LVL_NOTE);
[eb1a2f4]173 return ddf_driver_main(&uhci_driver);
[c7137738]174}
[c56dbe0]175/**
176 * @}
177 */
Note: See TracBrowser for help on using the repository browser.