| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 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 | #include <driver.h>
|
|---|
| 29 | #include <errno.h>
|
|---|
| 30 | #include <str_error.h>
|
|---|
| 31 | #include <usb_iface.h>
|
|---|
| 32 |
|
|---|
| 33 | #include "debug.h"
|
|---|
| 34 | #include "iface.h"
|
|---|
| 35 | #include "name.h"
|
|---|
| 36 | #include "pci.h"
|
|---|
| 37 | #include "root_hub.h"
|
|---|
| 38 | #include "uhci.h"
|
|---|
| 39 |
|
|---|
| 40 | static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
|
|---|
| 41 | {
|
|---|
| 42 | /* This shall be called only for the UHCI itself. */
|
|---|
| 43 | assert(dev->parent == NULL);
|
|---|
| 44 |
|
|---|
| 45 | *handle = dev->handle;
|
|---|
| 46 | return EOK;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | static usb_iface_t hc_usb_iface = {
|
|---|
| 50 | .get_hc_handle = usb_iface_get_hc_handle
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | static device_ops_t uhci_ops = {
|
|---|
| 54 | .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
|
|---|
| 55 | .interfaces[USBHC_DEV_IFACE] = &uhci_iface
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | static int uhci_add_device(device_t *device)
|
|---|
| 59 | {
|
|---|
| 60 | uhci_print_info( "uhci_add_device() called\n" );
|
|---|
| 61 | device->ops = &uhci_ops;
|
|---|
| 62 |
|
|---|
| 63 | uintptr_t io_reg_base;
|
|---|
| 64 | size_t io_reg_size;
|
|---|
| 65 | int irq;
|
|---|
| 66 |
|
|---|
| 67 | int rc = pci_get_my_registers(device,
|
|---|
| 68 | &io_reg_base, &io_reg_size, &irq);
|
|---|
| 69 |
|
|---|
| 70 | if (rc != EOK) {
|
|---|
| 71 | uhci_print_fatal("failed to get I/O registers addresses: %s.\n",
|
|---|
| 72 | str_error(rc));
|
|---|
| 73 | return rc;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | uhci_print_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
|
|---|
| 77 | io_reg_base, io_reg_size, irq);
|
|---|
| 78 |
|
|---|
| 79 | int ret = uhci_init(device, (void*)io_reg_base, io_reg_size);
|
|---|
| 80 |
|
|---|
| 81 | if (ret != EOK) {
|
|---|
| 82 | uhci_print_error("Failed to init uhci-hcd.\n");
|
|---|
| 83 | return ret;
|
|---|
| 84 | }
|
|---|
| 85 | device_t *rh;
|
|---|
| 86 | ret = setup_root_hub(&rh, device);
|
|---|
| 87 |
|
|---|
| 88 | if (ret != EOK) {
|
|---|
| 89 | uhci_print_error("Failed to setup uhci root hub.\n");
|
|---|
| 90 | /* TODO: destroy uhci here */
|
|---|
| 91 | return ret;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | ret = child_device_register(rh, device);
|
|---|
| 95 | if (ret != EOK) {
|
|---|
| 96 | uhci_print_error("Failed to register root hub.\n");
|
|---|
| 97 | /* TODO: destroy uhci here */
|
|---|
| 98 | return ret;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | return EOK;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | static driver_ops_t uhci_driver_ops = {
|
|---|
| 105 | .add_device = uhci_add_device,
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | static driver_t uhci_driver = {
|
|---|
| 109 | .name = NAME,
|
|---|
| 110 | .driver_ops = &uhci_driver_ops
|
|---|
| 111 | };
|
|---|
| 112 |
|
|---|
| 113 | int main(int argc, char *argv[])
|
|---|
| 114 | {
|
|---|
| 115 | /*
|
|---|
| 116 | * Do some global initializations.
|
|---|
| 117 | */
|
|---|
| 118 | sleep(5);
|
|---|
| 119 | usb_dprintf_enable(NAME, DEBUG_LEVEL_INFO);
|
|---|
| 120 |
|
|---|
| 121 | return driver_main(&uhci_driver);
|
|---|
| 122 | }
|
|---|