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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 999efa9 was 999efa9, checked in by Jakub Jermar <jakub@…>, 8 years ago

Reformat copyright messages

The goal is to have one copyright-holder per line so that it is easier
to do some sort of automatic processing.

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