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
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 */
[c56dbe0]28/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
[4687fcd4]34#include <driver.h>
35#include <usb_iface.h>
[3515533]36
[c56dbe0]37#include <errno.h>
38
[afcd86e]39#include <usb/debug.h>
40
[3515533]41#include "iface.h"
[1256a0a]42#include "pci.h"
43#include "root_hub.h"
[4317827]44#include "uhci.h"
[c7137738]45
[afcd86e]46#define NAME "uhci-hcd"
47
[71ed4849]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};
[3515533]60
[4317827]61static device_ops_t uhci_ops = {
[71ed4849]62 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
63 .interfaces[USBHC_DEV_IFACE] = &uhci_iface
[c7137738]64};
65
[4317827]66static int uhci_add_device(device_t *device)
[c7137738]67{
[afcd86e]68 assert(device);
69
70 usb_log_info("uhci_add_device() called\n");
[4317827]71 device->ops = &uhci_ops;
[c7137738]72
[ea991e84]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) {
[afcd86e]81 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n",
82 rc, device->handle);
[ea991e84]83 return rc;
84 }
85
[afcd86e]86 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
[ea991e84]87 io_reg_base, io_reg_size, irq);
88
[5944244]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 }
[1256a0a]94
[5944244]95 int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
[1256a0a]96 if (ret != EOK) {
[afcd86e]97 usb_log_error("Failed to init uhci-hcd.\n");
[1256a0a]98 return ret;
99 }
100 device_t *rh;
101 ret = setup_root_hub(&rh, device);
102
103 if (ret != EOK) {
[afcd86e]104 usb_log_error("Failed to setup uhci root hub.\n");
[1256a0a]105 /* TODO: destroy uhci here */
106 return ret;
107 }
108
109 ret = child_device_register(rh, device);
110 if (ret != EOK) {
[afcd86e]111 usb_log_error("Failed to register root hub.\n");
[1256a0a]112 /* TODO: destroy uhci here */
113 return ret;
114 }
115
[5944244]116 device->driver_data = uhci_hc;
117
[1256a0a]118 return EOK;
[c7137738]119}
120
[4317827]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
[c7137738]128};
129
130int main(int argc, char *argv[])
131{
132 /*
133 * Do some global initializations.
134 */
[b00163f]135 sleep(5);
[d6f78857]136 usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
[c7137738]137
[4317827]138 return driver_main(&uhci_driver);
[c7137738]139}
[c56dbe0]140/**
141 * @}
142 */
Note: See TracBrowser for help on using the repository browser.