[dac43be] | 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 |
|
---|
[3b77628] | 29 | /** @addtogroup libusb
|
---|
[dac43be] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief HC driver.
|
---|
| 34 | */
|
---|
| 35 | #include <usb/hcdhubd.h>
|
---|
| 36 | #include <usb/devreq.h>
|
---|
| 37 | #include <usbhc_iface.h>
|
---|
| 38 | #include <usb/descriptor.h>
|
---|
| 39 | #include <driver.h>
|
---|
| 40 | #include <bool.h>
|
---|
| 41 | #include <errno.h>
|
---|
| 42 | #include <usb/classes/hub.h>
|
---|
| 43 |
|
---|
| 44 | #include "hcdhubd_private.h"
|
---|
| 45 |
|
---|
| 46 | /** List of handled host controllers. */
|
---|
| 47 | LIST_INITIALIZE(hc_list);
|
---|
| 48 |
|
---|
[4317827] | 49 | /* Fake driver to have the name item initialized. */
|
---|
| 50 | static usb_hc_driver_t hc_driver_fake = {
|
---|
| 51 | .name = "HCD",
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[dac43be] | 54 | /** Our HC driver. */
|
---|
[4317827] | 55 | usb_hc_driver_t *hc_driver = &hc_driver_fake;
|
---|
[dac43be] | 56 |
|
---|
[4144630] | 57 | int usb_lowest_address = 1;
|
---|
| 58 |
|
---|
| 59 | int usb_highest_address = 255;
|
---|
| 60 |
|
---|
[dac43be] | 61 | static device_ops_t usb_device_ops = {
|
---|
[fe5e00d6] | 62 | .interfaces[USBHC_DEV_IFACE] = &usbhc_interface
|
---|
[dac43be] | 63 | };
|
---|
| 64 |
|
---|
[4144630] | 65 |
|
---|
| 66 | void usb_create_address_list(usb_hc_device_t * hcd){
|
---|
| 67 | list_initialize(&hcd->addresses);
|
---|
| 68 | usb_address_list_t * range =
|
---|
| 69 | (usb_address_list_t*)malloc(sizeof(usb_address_list_t));
|
---|
| 70 | range->lower_bound = usb_lowest_address;
|
---|
| 71 | range->upper_bound = usb_highest_address + 1;
|
---|
| 72 | list_append(&range->link, &hcd->addresses);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[1f43c8f] | 75 | static usb_hc_device_t *usb_hc_device_create(device_t *dev) {
|
---|
[dac43be] | 76 | usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t));
|
---|
[1f43c8f] | 77 |
|
---|
[dac43be] | 78 | list_initialize(&hc_dev->link);
|
---|
[1f43c8f] | 79 | list_initialize(&hc_dev->hubs);
|
---|
[4144630] | 80 | usb_create_address_list(hc_dev);
|
---|
[1f43c8f] | 81 | list_initialize(&hc_dev->attached_devices);
|
---|
[dac43be] | 82 | hc_dev->transfer_ops = NULL;
|
---|
| 83 |
|
---|
| 84 | hc_dev->generic = dev;
|
---|
| 85 | dev->ops = &usb_device_ops;
|
---|
| 86 | hc_dev->generic->driver_data = hc_dev;
|
---|
| 87 |
|
---|
[1f43c8f] | 88 | return hc_dev;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | int usb_add_hc_device(device_t *dev)
|
---|
| 92 | {
|
---|
[4317827] | 93 | return ENOTSUP;
|
---|
[1f43c8f] | 94 | usb_hc_device_t *hc_dev = usb_hc_device_create(dev);
|
---|
| 95 |
|
---|
[dac43be] | 96 | int rc = hc_driver->add_hc(hc_dev);
|
---|
| 97 | if (rc != EOK) {
|
---|
| 98 | free(hc_dev);
|
---|
| 99 | return rc;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /*
|
---|
| 103 | * FIXME: The following line causes devman to hang.
|
---|
| 104 | * Will investigate later why.
|
---|
| 105 | */
|
---|
| 106 | // add_device_to_class(dev, "usbhc");
|
---|
| 107 |
|
---|
| 108 | list_append(&hc_dev->link, &hc_list);
|
---|
| 109 |
|
---|
| 110 | /*
|
---|
[ba7f671] | 111 | * FIXME: the following is a workaround to force loading of USB
|
---|
| 112 | * keyboard driver.
|
---|
| 113 | * Will be removed as soon as the hub driver is completed and
|
---|
| 114 | * can detect connected devices.
|
---|
[dac43be] | 115 | */
|
---|
[ba7f671] | 116 | printf("%s: trying to add USB HID child device...\n", hc_driver->name);
|
---|
[1f43c8f] | 117 | rc = usb_hc_add_child_device(dev, USB_KBD_DEVICE_NAME, "usb&hid", false);
|
---|
[dac43be] | 118 | if (rc != EOK) {
|
---|
[ba7f671] | 119 | printf("%s: adding USB HID child failed...\n", hc_driver->name);
|
---|
[dac43be] | 120 | }
|
---|
| 121 |
|
---|
| 122 | return EOK;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * @}
|
---|
| 127 | */
|
---|