Changeset af4e464e in mainline


Ignore:
Timestamp:
2013-02-08T13:05:54Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
711f5fb8
Parents:
4c86c7c
Message:

uhci: Cleanup.

include guard, doxygen, line wrap.

Location:
uspace/drv/bus/usb/uhci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/uhci_rh.c

    r4c86c7c raf4e464e  
    3737        UHCI_RH_PORT_COUNT = 2,
    3838        /* 1 byte for hub status bit and 2 port status bits */
    39         UHCI_PORT_BYTES = 1,
     39        UHCI_PORT_BYTES = (1 + UHCI_RH_PORT_COUNT + 7) / 8,
    4040};
    4141
    4242/** Hub descriptor. */
    4343static const struct {
     44        /** Common hub descriptor header */
    4445        usb_hub_descriptor_header_t header;
     46        /** Port removable status bits */
    4547        uint8_t removable[UHCI_PORT_BYTES];
     48        /** Port powered status bits */
    4649        uint8_t powered[UHCI_PORT_BYTES];
    4750} __attribute__((packed)) hub_descriptor = {
     
    5962};
    6063
    61 
    6264static usbvirt_device_ops_t ops;
    6365
     66/** Initialize uhci rh structure.
     67 * @param instance Memory place to initialize.
     68 * @param ports Pointer to TWO UHCI RH port registers.
     69 * @param name device name, passed to virthub init
     70 * @return Error code, EOK on success.
     71 */
    6472int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name)
    6573{
     
    7381}
    7482
     83/** Schedule USB batch for the root hub.
     84 *
     85 * @param instance UHCI rh instance
     86 * @param batch USB communication batch
     87 * @return EOK.
     88 *
     89 * The result of scheduling is always EOK. The result of communication does
     90 * not have to be.
     91 */
    7592int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch)
    7693{
     
    90107        return EOK;
    91108}
     109
     110/** UHCI port register bits */
    92111enum {
    93112        STATUS_CONNECTED         = (1 << 0),
     
    107126        STATUS_WC_BITS = STATUS_CHANGE_BITS,
    108127};
     128
    109129/* HUB ROUTINES IMPLEMENTATION */
     130
    110131static void uhci_port_reset_enable(ioport16_t *port)
    111132{
     
    146167                usb_log_debug("%s: rh: " msg, d->name, ##__VA_ARGS__) \
    147168
     169/** USB HUB port state request handler.
     170 * @param device Virtual hub device
     171 * @param setup_packet USB setup stage data.
     172 * @param[out] data destination data buffer, size must be at least
     173 *             setup_packet->length bytes
     174 * @param[out] act_size Sized of the valid response part of the buffer.
     175 * @return Error code.
     176 *
     177 * Do not confuse with port status. Port state reports data line states,
     178 * it is usefull for debuging purposes only.
     179 */
    148180static int req_get_port_state(usbvirt_device_t *device,
    149181    const usb_device_request_setup_packet_t *setup_packet,
     
    170202        (BIT_VAL(val, bit) << feat)
    171203
     204/** Port status request handler.
     205 * @param device Virtual hub device
     206 * @param setup_packet USB setup stage data.
     207 * @param[out] data destination data buffer, size must be at least
     208 *             setup_packet->length bytes
     209 * @param[out] act_size Sized of the valid response part of the buffer.
     210 * @return Error code.
     211 *
     212 * Converts status reported via ioport to USB format.
     213 * @note: reset change status needs to be handled in sw.
     214 */
    172215static int req_get_port_status(usbvirt_device_t *device,
    173216    const usb_device_request_setup_packet_t *setup_packet,
     
    201244}
    202245
     246/** Port clear feature request handler.
     247 * @param device Virtual hub device
     248 * @param setup_packet USB setup stage data.
     249 * @param[out] data destination data buffer, size must be at least
     250 *             setup_packet->length bytes
     251 * @param[out] act_size Sized of the valid response part of the buffer.
     252 * @return Error code.
     253 */
    203254static int req_clear_port_feature(usbvirt_device_t *device,
    204255    const usb_device_request_setup_packet_t *setup_packet,
     
    213264        switch (feature) {
    214265        case USB_HUB_FEATURE_PORT_ENABLE:
    215                 RH_DEBUG(device, port, "Clear port enable (status %" PRIx16 ")\n",
    216                     status);
     266                RH_DEBUG(device, port, "Clear port enable (status %"
     267                    PRIx16 ")\n", status);
    217268                pio_write_16(hub->ports[port], val & ~STATUS_ENABLED);
    218269                break;
    219270        case USB_HUB_FEATURE_PORT_SUSPEND:
    220                 RH_DEBUG(device, port, "Clear port suspend (status %" PRIx16 ")\n",
    221                     status);
     271                RH_DEBUG(device, port, "Clear port suspend (status %"
     272                    PRIx16 ")\n", status);
    222273                pio_write_16(hub->ports[port], val & ~STATUS_SUSPEND);
    223274                // TODO we should do resume magic
     
    231282                break;
    232283        case USB_HUB_FEATURE_C_PORT_CONNECTION:
    233                 RH_DEBUG(device, port, "Clear port conn change (status %" PRIx16
    234                     ")\n", status);
     284                RH_DEBUG(device, port, "Clear port conn change (status %"
     285                    PRIx16 ")\n", status);
    235286                pio_write_16(hub->ports[port], val | STATUS_CONNECTED_CHANGED);
    236287                break;
    237288        case USB_HUB_FEATURE_C_PORT_RESET:
    238                 RH_DEBUG(device, port, "Clear port reset change (status %" PRIx16
    239                     ")\n", status);
     289                RH_DEBUG(device, port, "Clear port reset change (status %"
     290                    PRIx16 ")\n", status);
    240291                hub->reset_changed[port] = false;
    241292                break;
    242293        case USB_HUB_FEATURE_C_PORT_ENABLE:
    243                 RH_DEBUG(device, port, "Clear port enable change (status %" PRIx16
    244                     ")\n", status);
     294                RH_DEBUG(device, port, "Clear port enable change (status %"
     295                    PRIx16 ")\n", status);
    245296                pio_write_16(hub->ports[port], status | STATUS_ENABLED_CHANGED);
    246297                break;
    247298        case USB_HUB_FEATURE_C_PORT_SUSPEND:
    248                 RH_DEBUG(device, port, "Clear port suspend change (status %" PRIx16
    249                     ")\n", status);
     299                RH_DEBUG(device, port, "Clear port suspend change (status %"
     300                    PRIx16 ")\n", status);
    250301                //TODO
    251302                return ENOTSUP;
    252303        case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
    253                 RH_DEBUG(device, port, "Clear port OC change (status %" PRIx16
    254                     ")\n", status);
     304                RH_DEBUG(device, port, "Clear port OC change (status %"
     305                    PRIx16 ")\n", status);
    255306                /* UHCI Does not report over current */
     307                //TODO: newer chips do, but some have broken wiring
    256308                break;
    257309        default:
    258                 RH_DEBUG(device, port, "Clear unknown feature %d (status %" PRIx16
    259                     ")\n", feature, status);
     310                RH_DEBUG(device, port, "Clear unknown feature %d (status %"
     311                    PRIx16 ")\n", feature, status);
    260312                usb_log_warning("Clearing feature %d is unsupported\n",
    261313                    feature);
     
    265317}
    266318
     319/** Port set feature request handler.
     320 * @param device Virtual hub device
     321 * @param setup_packet USB setup stage data.
     322 * @param[out] data destination data buffer, size must be at least
     323 *             setup_packet->length bytes
     324 * @param[out] act_size Sized of the valid response part of the buffer.
     325 * @return Error code.
     326 */
    267327static int req_set_port_feature(usbvirt_device_t *device,
    268328    const usb_device_request_setup_packet_t *setup_packet,
     
    295355                /* We are always powered */
    296356                usb_log_warning("Tried to power port %u\n", port);
     357                break;
    297358        case USB_HUB_FEATURE_C_PORT_CONNECTION:
    298359        case USB_HUB_FEATURE_C_PORT_ENABLE:
     
    314375}
    315376
     377/** UHCI root hub request handlers */
    316378static usbvirt_control_request_handler_t control_transfer_handlers[] = {
    317379        {
     
    344406                .name = "ClearHubFeature",
    345407                /* Hub features are overcurrent and supply good,
    346                  * this request may only set changes that we never report*/
     408                 * this request may only clear changes that we never report*/
    347409                .callback = req_nop,
    348410        },
     
    390452};
    391453
     454/** Status change handler.
     455 * @param device Virtual hub device
     456 * @param endpoint Enpoint number
     457 * @param tr_type Transfer type
     458 * @param buffer Response destination
     459 * @param buffer_size BYtes available in buffer
     460 * @param actual_size Size us the used part of the dest buffer.
     461 *
     462 * Produces status mask. Bit 0 indicates hub status change the other bits
     463 * represnet port status change. Endian does not matter as UHCI root hubs
     464 * only need 1 byte.
     465 */
    392466static int req_status_change_handler(usbvirt_device_t *device,
    393467    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
    394468    void *buffer, size_t buffer_size, size_t *actual_size)
    395469{
     470        uhci_rh_t *hub = virthub_get_data(device);
     471        assert(hub);
     472       
    396473        if (buffer_size < 1)
    397474                return ESTALL;
    398         uhci_rh_t *hub = virthub_get_data(device);
    399         assert(hub);
    400475
    401476        const uint16_t status_a = pio_read_16(hub->ports[0]);
  • uspace/drv/bus/usb/uhci/uhci_rh.h

    r4c86c7c raf4e464e  
    3333 * @brief UHCI host controller driver structure
    3434 */
    35 #ifndef DRV_UHCI_RHVIRT_H
    36 #define DRV_UHCI_RHVIRT_H
     35#ifndef DRV_UHCI_UHCI_RH_H
     36#define DRV_UHCI_UHCI_RH_H
    3737
    3838#include <usbvirt/virthub_base.h>
     
    4242#define HUB_STATUS_CHANGE_PIPE   1
    4343
    44 
     44/** Virtual to UHCI hub connector */
    4545typedef struct {
     46        /** Virtual hub software implementation */
    4647        virthub_base_t base;
     48        /** UHCI root hub port io registers */
    4749        ioport16_t *ports[2];
     50        /** Reset change indicator, it is not reported by regs */
    4851        bool reset_changed[2];
    4952} uhci_rh_t;
     
    5154int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name);
    5255int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch);
     56
     57/** Get UHCI rh address.
     58 *
     59 * @param instance UHCI rh instance.
     60 * @return USB address assigned to the hub.
     61 * Wrapper for virtual hub address
     62 */
    5363static inline usb_address_t uhci_rh_get_address(uhci_rh_t *instance)
    5464{
Note: See TracChangeset for help on using the changeset viewer.