source: mainline/uspace/drv/uhci-hcd/main.c@ d6f78857

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

More debug output

reduce timeout

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky, Jan Vesely
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 */
28/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#include <driver.h>
35#include <usb_iface.h>
36
37#include <errno.h>
38
39#include <usb/debug.h>
40
41#include "iface.h"
42#include "pci.h"
43#include "root_hub.h"
44#include "uhci.h"
45
46#define NAME "uhci-hcd"
47
48static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
49{
50 /* This shall be called only for the UHCI itself. */
51 assert(dev->parent == NULL);
52
53 *handle = dev->handle;
54 return EOK;
55}
56
57static usb_iface_t hc_usb_iface = {
58 .get_hc_handle = usb_iface_get_hc_handle
59};
60
61static device_ops_t uhci_ops = {
62 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
63 .interfaces[USBHC_DEV_IFACE] = &uhci_iface
64};
65
66static int uhci_add_device(device_t *device)
67{
68 assert(device);
69
70 usb_log_info("uhci_add_device() called\n");
71 device->ops = &uhci_ops;
72
73 uintptr_t io_reg_base;
74 size_t io_reg_size;
75 int irq;
76
77 int rc = pci_get_my_registers(device,
78 &io_reg_base, &io_reg_size, &irq);
79
80 if (rc != EOK) {
81 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n",
82 rc, device->handle);
83 return rc;
84 }
85
86 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
87 io_reg_base, io_reg_size, irq);
88
89 uhci_t *uhci_hc = malloc(sizeof(uhci_t));
90 if (!uhci_hc) {
91 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n");
92 return ENOMEM;
93 }
94
95 int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
96 if (ret != EOK) {
97 usb_log_error("Failed to init uhci-hcd.\n");
98 return ret;
99 }
100 device_t *rh;
101 ret = setup_root_hub(&rh, device);
102
103 if (ret != EOK) {
104 usb_log_error("Failed to setup uhci root hub.\n");
105 /* TODO: destroy uhci here */
106 return ret;
107 }
108
109 ret = child_device_register(rh, device);
110 if (ret != EOK) {
111 usb_log_error("Failed to register root hub.\n");
112 /* TODO: destroy uhci here */
113 return ret;
114 }
115
116 device->driver_data = uhci_hc;
117
118 return EOK;
119}
120
121static driver_ops_t uhci_driver_ops = {
122 .add_device = uhci_add_device,
123};
124
125static driver_t uhci_driver = {
126 .name = NAME,
127 .driver_ops = &uhci_driver_ops
128};
129
130int main(int argc, char *argv[])
131{
132 /*
133 * Do some global initializations.
134 */
135 sleep(5);
136 usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
137
138 return driver_main(&uhci_driver);
139}
140/**
141 * @}
142 */
Note: See TracBrowser for help on using the repository browser.