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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4bfcf22 was 4bfcf22, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

ehci,ohci,uhci: Remove interrupt handler wrappers

  • Property mode set to 100644
File size: 4.3 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 */
[e3a07bba]28/** @addtogroup drvusbuhci
[c56dbe0]29 * @{
30 */
31/** @file
[17ceb72]32 * @brief UHCI driver initialization
[c56dbe0]33 */
[8064c2f6]34
35#include <assert.h>
[eb1a2f4]36#include <ddf/driver.h>
[e3a07bba]37#include <devman.h>
[c56dbe0]38#include <errno.h>
[8064c2f6]39#include <io/log.h>
[e3a07bba]40#include <pci_dev_iface.h>
[8064c2f6]41#include <stdio.h>
[ab414a6]42#include <str_error.h>
[afcd86e]43#include <usb/debug.h>
[1a0fa29c]44#include <usb/host/ddf_helpers.h>
[afcd86e]45
[1a0fa29c]46#include "hc.h"
[c7137738]47
[497b6f31]48#define NAME "uhci"
[afcd86e]49
[1a0fa29c]50static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
51{
52 assert(hcd);
53 assert(hcd->driver.data == NULL);
54
55 hc_t *instance = malloc(sizeof(hc_t));
56 if (!instance)
57 return ENOMEM;
58
59 const int ret = hc_init(instance, res, irq);
60 if (ret == EOK)
61 hcd_set_implementation(hcd, instance, hc_schedule, NULL, NULL,
[4bfcf22]62 hc_interrupt, hc_status);
[1a0fa29c]63 return ret;
64}
65
66static void uhci_driver_fini(hcd_t *hcd)
67{
68 assert(hcd);
69 if (hcd->driver.data)
70 hc_fini(hcd->driver.data);
71
72 free(hcd->driver.data);
[e26a9d95]73 hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
[1a0fa29c]74}
75
[0c0f823b]76static int uhci_dev_add(ddf_dev_t *device);
[76fbd9a]77
[2ef8023]78static const driver_ops_t uhci_driver_ops = {
[0c0f823b]79 .dev_add = uhci_dev_add,
[36a4738]80};
[76fbd9a]81
[2ef8023]82static const driver_t uhci_driver = {
[36a4738]83 .name = NAME,
84 .driver_ops = &uhci_driver_ops
85};
[76fbd9a]86
[e3a07bba]87/** Call the PCI driver with a request to clear legacy support register
88 *
89 * @param[in] device Device asking to disable interrupts
90 * @return Error code.
91 */
92static int disable_legacy(ddf_dev_t *device)
93{
94 assert(device);
95
96 async_sess_t *parent_sess = devman_parent_device_connect(
97 EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
98 if (!parent_sess)
99 return ENOMEM;
100
101 /* See UHCI design guide page 45 for these values.
102 * Write all WC bits in USB legacy register */
103 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
104
105 async_hangup(parent_sess);
106 return rc;
107}
108
[17ceb72]109/** Initialize a new ddf driver instance for uhci hc and hub.
[a7e2f0d]110 *
111 * @param[in] device DDF instance of the device to initialize.
112 * @return Error code.
113 */
[0c0f823b]114int uhci_dev_add(ddf_dev_t *device)
[86341e2]115{
[0c0f823b]116 usb_log_debug2("uhci_dev_add() called\n");
[9351353]117 assert(device);
[ea993d18]118
[e3a07bba]119 int ret = disable_legacy(device);
120 if (ret != EOK) {
121 usb_log_error("Failed to disable legacy USB: %s.\n",
122 str_error(ret));
123 return ret;
124 }
125
126
[1a0fa29c]127 ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
128 BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
129 ddf_hcd_gen_irq_handler, hc_gen_irq_code,
130 uhci_driver_init, uhci_driver_fini);
[b375bb8]131 if (ret != EOK) {
[4125b7d]132 usb_log_error("Failed to initialize UHCI driver: %s.\n",
133 str_error(ret));
[5d915b7]134 } else {
135 usb_log_info("Controlling new UHCI device '%s'.\n",
[56fd7cf]136 ddf_dev_get_name(device));
[b375bb8]137 }
[fbefd0e]138
[5d915b7]139 return ret;
[c7137738]140}
[76fbd9a]141
[17ceb72]142/** Initialize global driver structures (NONE).
[a7e2f0d]143 *
[ea993d18]144 * @param[in] argc Number of arguments in argv vector (ignored).
[a7e2f0d]145 * @param[in] argv Cmdline argument vector (ignored).
146 * @return Error code.
147 *
148 * Driver debug level is set here.
149 */
[c7137738]150int main(int argc, char *argv[])
151{
[fbefd0e]152 printf(NAME ": HelenOS UHCI driver.\n");
[920d0fc]153 log_init(NAME);
[c7137738]154
[eb1a2f4]155 return ddf_driver_main(&uhci_driver);
[c7137738]156}
[c56dbe0]157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.