| 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>
|
|---|
| 29 | #include <errno.h>
|
|---|
| 30 |
|
|---|
| 31 | #include "iface.h"
|
|---|
| 32 | #include "uhci.h"
|
|---|
| 33 |
|
|---|
| 34 | static int get_address(device_t *dev, devman_handle_t handle,
|
|---|
| 35 | usb_address_t *address)
|
|---|
| 36 | {
|
|---|
| 37 | return ENOTSUP;
|
|---|
| 38 | }
|
|---|
| 39 | /*----------------------------------------------------------------------------*/
|
|---|
| 40 | static int interrupt_out(device_t *dev, usb_target_t target,
|
|---|
| 41 | void *data, size_t size,
|
|---|
| 42 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 43 | {
|
|---|
| 44 | return uhci_transfer(dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_OUT,
|
|---|
| 45 | data, size, callback, NULL, arg);
|
|---|
| 46 | }
|
|---|
| 47 | /*----------------------------------------------------------------------------*/
|
|---|
| 48 | static int interrupt_in(device_t *dev, usb_target_t target,
|
|---|
| 49 | void *data, size_t size,
|
|---|
| 50 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 51 | {
|
|---|
| 52 | return uhci_transfer(dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_IN,
|
|---|
| 53 | data, size, NULL, callback, arg);
|
|---|
| 54 | }
|
|---|
| 55 | /*----------------------------------------------------------------------------*/
|
|---|
| 56 | static int control_write_setup(device_t *dev, usb_target_t target,
|
|---|
| 57 | void *data, size_t size,
|
|---|
| 58 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 59 | {
|
|---|
| 60 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP,
|
|---|
| 61 | data, size, callback, NULL, arg);
|
|---|
| 62 | }
|
|---|
| 63 | /*----------------------------------------------------------------------------*/
|
|---|
| 64 | static int control_write_data(device_t *dev, usb_target_t target,
|
|---|
| 65 | void *data, size_t size,
|
|---|
| 66 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 67 | {
|
|---|
| 68 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_OUT,
|
|---|
| 69 | data, size, callback, NULL, arg);
|
|---|
| 70 | }
|
|---|
| 71 | /*----------------------------------------------------------------------------*/
|
|---|
| 72 | static int control_write_status(device_t *dev, usb_target_t target,
|
|---|
| 73 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 74 | {
|
|---|
| 75 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_IN,
|
|---|
| 76 | NULL, 0, NULL, callback, arg);
|
|---|
| 77 | }
|
|---|
| 78 | /*----------------------------------------------------------------------------*/
|
|---|
| 79 | static int control_read_setup(device_t *dev, usb_target_t target,
|
|---|
| 80 | void *data, size_t size,
|
|---|
| 81 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 82 | {
|
|---|
| 83 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP,
|
|---|
| 84 | data, size, callback, NULL, arg);
|
|---|
| 85 | }
|
|---|
| 86 | /*----------------------------------------------------------------------------*/
|
|---|
| 87 | static int control_read_data(device_t *dev, usb_target_t target,
|
|---|
| 88 | void *data, size_t size,
|
|---|
| 89 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 90 | {
|
|---|
| 91 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_IN,
|
|---|
| 92 | data, size, NULL, callback, arg);
|
|---|
| 93 | }
|
|---|
| 94 | /*----------------------------------------------------------------------------*/
|
|---|
| 95 | static int control_read_status(device_t *dev, usb_target_t target,
|
|---|
| 96 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 97 | {
|
|---|
| 98 | return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_OUT,
|
|---|
| 99 | NULL, 0, callback, NULL, arg);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | usbhc_iface_t uhci_iface = {
|
|---|
| 104 | .tell_address = get_address,
|
|---|
| 105 |
|
|---|
| 106 | .reserve_default_address = NULL,
|
|---|
| 107 | .release_default_address = NULL,
|
|---|
| 108 | .request_address = NULL,
|
|---|
| 109 | .bind_address = NULL,
|
|---|
| 110 | .release_address = NULL,
|
|---|
| 111 |
|
|---|
| 112 | .interrupt_out = interrupt_out,
|
|---|
| 113 | .interrupt_in = interrupt_in,
|
|---|
| 114 |
|
|---|
| 115 | .control_write_setup = control_write_setup,
|
|---|
| 116 | .control_write_data = control_write_data,
|
|---|
| 117 | .control_write_status = control_write_status,
|
|---|
| 118 |
|
|---|
| 119 | .control_read_setup = control_read_setup,
|
|---|
| 120 | .control_read_data = control_read_data,
|
|---|
| 121 | .control_read_status = control_read_status
|
|---|
| 122 | };
|
|---|