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

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

Switch back to polling

reduce debug verbosity

  • Property mode set to 100644
File size: 4.5 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 <ddf/driver.h>
35#include <ddf/interrupt.h>
36#include <usb_iface.h>
37#include <usb/ddfiface.h>
38#include <device/hw_res.h>
39
40#include <errno.h>
41
42#include <usb/debug.h>
43
44#include "iface.h"
45#include "pci.h"
46#include "root_hub.h"
47#include "uhci.h"
48
49#define NAME "uhci-hcd"
50
51static int uhci_add_device(ddf_dev_t *device);
52
53/*----------------------------------------------------------------------------*/
54static driver_ops_t uhci_driver_ops = {
55 .add_device = uhci_add_device,
56};
57/*----------------------------------------------------------------------------*/
58static driver_t uhci_driver = {
59 .name = NAME,
60 .driver_ops = &uhci_driver_ops
61};
62/*----------------------------------------------------------------------------*/
63static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
64{
65 assert(dev);
66 uhci_t *hc = dev_to_uhci(dev);
67 uint16_t status = IPC_GET_ARG1(*call);
68 assert(hc);
69 uhci_interrupt(hc, status);
70}
71/*----------------------------------------------------------------------------*/
72#define CHECK_RET_RETURN(ret, message...) \
73if (ret != EOK) { \
74 usb_log_error(message); \
75 return ret; \
76}
77
78static int uhci_add_device(ddf_dev_t *device)
79{
80 assert(device);
81
82 usb_log_info("uhci_add_device() called\n");
83
84 uintptr_t io_reg_base = 0;
85 size_t io_reg_size = 0;
86 int irq = 0;
87
88 int ret =
89 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
90
91 CHECK_RET_RETURN(ret,
92 "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
93 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
94 io_reg_base, io_reg_size, irq);
95 io_reg_size = 32;
96
97// ret = pci_enable_interrupts(device);
98// CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
99
100 uhci_t *uhci_hc = malloc(sizeof(uhci_t));
101 ret = (uhci_hc != NULL) ? EOK : ENOMEM;
102 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
103
104 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
105 if (ret != EOK) {
106 usb_log_error("Failed to init uhci-hcd.\n");
107 free(uhci_hc);
108 return ret;
109 }
110
111 /*
112 * We might free uhci_hc, but that does not matter since no one
113 * else would access driver_data anyway.
114 */
115 device->driver_data = uhci_hc;
116 ret = register_interrupt_handler(device, irq, irq_handler,
117 &uhci_hc->interrupt_code);
118 if (ret != EOK) {
119 usb_log_error("Failed to register interrupt handler.\n");
120 uhci_fini(uhci_hc);
121 free(uhci_hc);
122 return ret;
123 }
124
125 ddf_fun_t *rh;
126 ret = setup_root_hub(&rh, device);
127 if (ret != EOK) {
128 usb_log_error("Failed to setup uhci root hub.\n");
129 uhci_fini(uhci_hc);
130 free(uhci_hc);
131 return ret;
132 }
133 rh->driver_data = uhci_hc->ddf_instance;
134
135 ret = ddf_fun_bind(rh);
136 if (ret != EOK) {
137 usb_log_error("Failed to register root hub.\n");
138 uhci_fini(uhci_hc);
139 free(uhci_hc);
140 free(rh);
141 return ret;
142 }
143
144 return EOK;
145}
146/*----------------------------------------------------------------------------*/
147int main(int argc, char *argv[])
148{
149 sleep(3);
150 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
151
152 return ddf_driver_main(&uhci_driver);
153}
154/**
155 * @}
156 */
Note: See TracBrowser for help on using the repository browser.