| 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 |
|
|---|
| 29 | /** @addtogroup libusb usb
|
|---|
| 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 |
|
|---|
| 49 | /** Our HC driver. */
|
|---|
| 50 | usb_hc_driver_t *hc_driver = NULL;
|
|---|
| 51 |
|
|---|
| 52 | static usbhc_iface_t usb_interface = {
|
|---|
| 53 | .interrupt_out = NULL,
|
|---|
| 54 | .interrupt_in = NULL
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | static device_ops_t usb_device_ops = {
|
|---|
| 58 | .interfaces[USBHC_DEV_IFACE] = &usb_interface
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | int usb_add_hc_device(device_t *dev)
|
|---|
| 62 | {
|
|---|
| 63 | usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t));
|
|---|
| 64 | list_initialize(&hc_dev->link);
|
|---|
| 65 | hc_dev->transfer_ops = NULL;
|
|---|
| 66 |
|
|---|
| 67 | hc_dev->generic = dev;
|
|---|
| 68 | dev->ops = &usb_device_ops;
|
|---|
| 69 | hc_dev->generic->driver_data = hc_dev;
|
|---|
| 70 |
|
|---|
| 71 | int rc = hc_driver->add_hc(hc_dev);
|
|---|
| 72 | if (rc != EOK) {
|
|---|
| 73 | free(hc_dev);
|
|---|
| 74 | return rc;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /*
|
|---|
| 78 | * FIXME: The following line causes devman to hang.
|
|---|
| 79 | * Will investigate later why.
|
|---|
| 80 | */
|
|---|
| 81 | // add_device_to_class(dev, "usbhc");
|
|---|
| 82 |
|
|---|
| 83 | list_append(&hc_dev->link, &hc_list);
|
|---|
| 84 |
|
|---|
| 85 | //add keyboard
|
|---|
| 86 | /// @TODO this is not correct code
|
|---|
| 87 |
|
|---|
| 88 | /*
|
|---|
| 89 | * Announce presence of child device.
|
|---|
| 90 | */
|
|---|
| 91 | device_t *kbd = NULL;
|
|---|
| 92 | match_id_t *match_id = NULL;
|
|---|
| 93 |
|
|---|
| 94 | kbd = create_device();
|
|---|
| 95 | if (kbd == NULL) {
|
|---|
| 96 | printf("ERROR: enomem\n");
|
|---|
| 97 | }
|
|---|
| 98 | kbd->name = USB_KBD_DEVICE_NAME;
|
|---|
| 99 |
|
|---|
| 100 | match_id = create_match_id();
|
|---|
| 101 | if (match_id == NULL) {
|
|---|
| 102 | printf("ERROR: enomem\n");
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | char *id;
|
|---|
| 106 | rc = asprintf(&id, USB_KBD_DEVICE_NAME);
|
|---|
| 107 | if (rc <= 0) {
|
|---|
| 108 | printf("ERROR: enomem\n");
|
|---|
| 109 | return rc;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | match_id->id = id;
|
|---|
| 113 | match_id->score = 30;
|
|---|
| 114 |
|
|---|
| 115 | add_match_id(&kbd->match_ids, match_id);
|
|---|
| 116 |
|
|---|
| 117 | rc = child_device_register(kbd, dev);
|
|---|
| 118 | if (rc != EOK) {
|
|---|
| 119 | printf("ERROR: cannot register kbd\n");
|
|---|
| 120 | return rc;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | printf("%s: registered root hub\n", dev->name);
|
|---|
| 124 | return EOK;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * @}
|
|---|
| 129 | */
|
|---|