| [c7137738] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 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 | #include <usb/hcdhubd.h>
|
|---|
| [71ed4849] | 29 | #include <usb_iface.h>
|
|---|
| [947d788] | 30 | #include <usb/debug.h>
|
|---|
| [c7137738] | 31 | #include <errno.h>
|
|---|
| [ea991e84] | 32 | #include <str_error.h>
|
|---|
| [138a7fd] | 33 | #include <driver.h>
|
|---|
| [4317827] | 34 | #include "uhci.h"
|
|---|
| [c7137738] | 35 |
|
|---|
| [71ed4849] | 36 | static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
|
|---|
| 37 | {
|
|---|
| 38 | /* This shall be called only for the UHCI itself. */
|
|---|
| 39 | assert(dev->parent == NULL);
|
|---|
| 40 |
|
|---|
| 41 | *handle = dev->handle;
|
|---|
| 42 | return EOK;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | static usb_iface_t hc_usb_iface = {
|
|---|
| 46 | .get_hc_handle = usb_iface_get_hc_handle
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| [4317827] | 49 | static device_ops_t uhci_ops = {
|
|---|
| [71ed4849] | 50 | .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
|
|---|
| 51 | .interfaces[USBHC_DEV_IFACE] = &uhci_iface
|
|---|
| [c7137738] | 52 | };
|
|---|
| 53 |
|
|---|
| [4317827] | 54 | static int uhci_add_device(device_t *device)
|
|---|
| [c7137738] | 55 | {
|
|---|
| [947d788] | 56 | usb_dprintf(NAME, 1, "uhci_add_device() called\n");
|
|---|
| [4317827] | 57 | device->ops = &uhci_ops;
|
|---|
| [c7137738] | 58 |
|
|---|
| [ea991e84] | 59 | uintptr_t io_reg_base;
|
|---|
| 60 | size_t io_reg_size;
|
|---|
| 61 | int irq;
|
|---|
| 62 |
|
|---|
| 63 | int rc = pci_get_my_registers(device,
|
|---|
| 64 | &io_reg_base, &io_reg_size, &irq);
|
|---|
| 65 |
|
|---|
| 66 | if (rc != EOK) {
|
|---|
| 67 | fprintf(stderr,
|
|---|
| 68 | NAME ": failed to get I/O registers addresses: %s.\n",
|
|---|
| 69 | str_error(rc));
|
|---|
| 70 | return rc;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | usb_dprintf(NAME, 2, "I/O regs at 0x%X (size %zu), IRQ %d.\n",
|
|---|
| 74 | io_reg_base, io_reg_size, irq);
|
|---|
| 75 |
|
|---|
| [c7137738] | 76 | /*
|
|---|
| 77 | * We need to announce the presence of our root hub.
|
|---|
| 78 | */
|
|---|
| [947d788] | 79 | usb_dprintf(NAME, 2, "adding root hub\n");
|
|---|
| [7972b51] | 80 | usb_hcd_add_root_hub(device);
|
|---|
| [c7137738] | 81 |
|
|---|
| 82 | return EOK;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| [4317827] | 85 | static driver_ops_t uhci_driver_ops = {
|
|---|
| 86 | .add_device = uhci_add_device,
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 | static driver_t uhci_driver = {
|
|---|
| 90 | .name = NAME,
|
|---|
| 91 | .driver_ops = &uhci_driver_ops
|
|---|
| [c7137738] | 92 | };
|
|---|
| 93 |
|
|---|
| 94 | int main(int argc, char *argv[])
|
|---|
| 95 | {
|
|---|
| 96 | /*
|
|---|
| 97 | * Do some global initializations.
|
|---|
| 98 | */
|
|---|
| [4317827] | 99 | sleep(5);
|
|---|
| [947d788] | 100 | usb_dprintf_enable(NAME, 5);
|
|---|
| [c7137738] | 101 |
|
|---|
| [4317827] | 102 | return driver_main(&uhci_driver);
|
|---|
| [c7137738] | 103 | }
|
|---|