Changeset 058fd76 in mainline


Ignore:
Timestamp:
2011-09-16T10:22:11Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
790318e
Parents:
25d224c6
Message:

ohci: Use new batch_direction function.

Get rid of nasty setup data parsing hack to determine direction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r25d224c6 r058fd76  
    4242#include "utils/malloc32.h"
    4343
    44 void (*const batch_setup[4][3])(ohci_transfer_batch_t*);
     44static void (*const batch_setup[4][3])(ohci_transfer_batch_t*, usb_direction_t);
    4545/*----------------------------------------------------------------------------*/
    4646/** Safely destructs ohci_transfer_batch_t structure
     
    136136        ohci_batch->usb_batch = usb_batch;
    137137
    138         assert(
    139            batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction]);
    140         batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction](
    141             ohci_batch);
     138        const usb_direction_t dir = usb_transfer_batch_direction(usb_batch);
     139        assert(batch_setup[usb_batch->ep->transfer_type][dir]);
     140        batch_setup[usb_batch->ep->transfer_type][dir](ohci_batch, dir);
    142141
    143142        return ohci_batch;
     
    224223 *
    225224 * @param[in] ohci_batch Batch structure to use.
    226  * @param[in] data_dir Direction to use for data stage.
    227  * @param[in] status_dir Direction to use for status stage.
     225 * @param[in] dir Communication direction
    228226 *
    229227 * Setup stage with toggle 0 and direction BOTH(SETUP_PID)
     
    231229 * Status stage with toggle 1 and direction supplied by parameter.
    232230 */
    233 static void batch_control(ohci_transfer_batch_t *ohci_batch,
    234     usb_direction_t data_dir, usb_direction_t status_dir)
     231static void batch_control(ohci_transfer_batch_t *ohci_batch, usb_direction_t dir)
    235232{
    236233        assert(ohci_batch);
    237234        assert(ohci_batch->usb_batch);
     235        assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT);
    238236        usb_log_debug("Using ED(%p): %x:%x:%x:%x.\n", ohci_batch->ed,
    239237            ohci_batch->ed->status, ohci_batch->ed->td_tail,
    240238            ohci_batch->ed->td_head, ohci_batch->ed->next);
     239        static const usb_direction_t reverse_dir[] = {
     240                [USB_DIRECTION_IN]  = USB_DIRECTION_OUT,
     241                [USB_DIRECTION_OUT] = USB_DIRECTION_IN,
     242        };
    241243
    242244        int toggle = 0;
    243         char* buffer = ohci_batch->device_buffer;
     245        const char* buffer = ohci_batch->device_buffer;
     246        const usb_direction_t data_dir = dir;
     247        const usb_direction_t status_dir = reverse_dir[dir];
    244248
    245249        /* setup stage */
     
    287291            ohci_batch->tds[td_current]->next,
    288292            ohci_batch->tds[td_current]->be);
     293        usb_log_debug2(
     294            "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
     295            ohci_batch->usb_batch,
     296            usb_str_transfer_type(ohci_batch->usb_batch->ep->transfer_type),
     297            usb_str_direction(dir),
     298            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    289299}
    290300/*----------------------------------------------------------------------------*/
     
    292302 *
    293303 * @param[in] ohci_batch Batch structure to use.
     304 * @paramp[in] dir Communication direction.
    294305 *
    295306 * Direction is supplied by the associated ep and toggle is maintained by the
    296307 * OHCI hw in ED.
    297308 */
    298 static void batch_data(ohci_transfer_batch_t *ohci_batch)
    299 {
    300         assert(ohci_batch);
     309static void batch_data(ohci_transfer_batch_t *ohci_batch, usb_direction_t dir)
     310{
     311        assert(ohci_batch);
     312        assert(ohci_batch->usb_batch);
     313        assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT);
    301314        usb_log_debug("Using ED(%p): %x:%x:%x:%x.\n", ohci_batch->ed,
    302315            ohci_batch->ed->status, ohci_batch->ed->td_tail,
    303316            ohci_batch->ed->td_head, ohci_batch->ed->next);
    304317
    305         const usb_direction_t direction = ohci_batch->usb_batch->ep->direction;
    306318        size_t td_current = 0;
    307319        size_t remain_size = ohci_batch->usb_batch->buffer_size;
     
    311323                    ? OHCI_TD_MAX_TRANSFER : remain_size;
    312324
    313                 td_init(ohci_batch->tds[td_current], direction,
    314                     buffer, transfer_size, -1);
     325                td_init(ohci_batch->tds[td_current], dir, buffer,
     326                    transfer_size, -1);
    315327                td_set_next(ohci_batch->tds[td_current],
    316328                    ohci_batch->tds[td_current + 1]);
     329
    317330                usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
    318331                    ohci_batch->tds[td_current]->status,
     
    330343            ohci_batch->usb_batch,
    331344            usb_str_transfer_type(ohci_batch->usb_batch->ep->transfer_type),
    332             usb_str_direction(ohci_batch->usb_batch->ep->direction),
     345            usb_str_direction(dir),
    333346            USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    334347}
    335348/*----------------------------------------------------------------------------*/
    336 static void setup_control(ohci_transfer_batch_t *ohci_batch)
    337 {
    338         // TODO Find a better way to do this
    339         /* Check first bit of the first setup request byte
    340          * (it signals hc-> dev or dev->hc communication) */
    341         const char *direction;
    342         if (ohci_batch->device_buffer[0] & (1 << 7)) {
    343                 batch_control(ohci_batch, USB_DIRECTION_IN, USB_DIRECTION_OUT);
    344                 direction = "read";
    345         } else {
    346                 batch_control(ohci_batch, USB_DIRECTION_OUT, USB_DIRECTION_IN);
    347                 direction = "write";
    348         }
    349         usb_log_debug2(
    350             "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
    351             ohci_batch->usb_batch,
    352             usb_str_transfer_type(ohci_batch->usb_batch->ep->transfer_type),
    353             direction, USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch));
    354 }
    355 /*----------------------------------------------------------------------------*/
    356 void (*const batch_setup[4][3])(ohci_transfer_batch_t*) =
    357 {
    358         { NULL, NULL, setup_control },
     349static void (*const batch_setup[4][3])(ohci_transfer_batch_t*, usb_direction_t) =
     350{
     351        { batch_control, batch_control, NULL },
    359352        { NULL, NULL, NULL },
    360353        { batch_data, batch_data, NULL },
Note: See TracChangeset for help on using the changeset viewer.