Changeset 7bce1fc in mainline for uspace/drv/bus/usb/ohci/ohci_batch.c


Ignore:
Timestamp:
2011-08-31T23:29:43Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f57929
Parents:
9a790ad1
Message:

ohci: simplify ohci_batch initialization

remove per type/direction functions and use a generic one,
nice array will provide suitable PIDs

File:
1 edited

Legend:

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

    r9a790ad1 r7bce1fc  
    4242#include "utils/malloc32.h"
    4343
    44 static void control_write(ohci_transfer_batch_t *instance);
    45 static void control_read(ohci_transfer_batch_t *instance);
    46 
    47 static void interrupt_in(ohci_transfer_batch_t *instance);
    48 static void interrupt_out(ohci_transfer_batch_t *instance);
    49 
    50 static void bulk_in(ohci_transfer_batch_t *instance);
    51 static void bulk_out(ohci_transfer_batch_t *instance);
    52 
    53 static void setup_control(ohci_transfer_batch_t *ohci_batch)
    54 {
    55         // TODO Find a better way to do this
    56         if (ohci_batch->device_buffer[0] & (1 << 7))
    57                 control_read(ohci_batch);
    58         else
    59                 control_write(ohci_batch);
    60 }
    61 /*----------------------------------------------------------------------------*/
    62 static void batch_control(ohci_transfer_batch_t *instance,
    63     usb_direction_t data_dir, usb_direction_t status_dir);
    64 static void batch_data(ohci_transfer_batch_t *instance);
    65 /*----------------------------------------------------------------------------*/
    66 void (*batch_setup[4][3])(ohci_transfer_batch_t*) =
    67 {
    68         { NULL, NULL, setup_control },
    69         { NULL, NULL, NULL },
    70         { bulk_in, bulk_out, NULL },
    71         { interrupt_in, interrupt_out, NULL },
    72 };
     44void (*const batch_setup[4][3])(ohci_transfer_batch_t*);
    7345/*----------------------------------------------------------------------------*/
    7446/** Safely destructs ohci_transfer_batch_t structure
     
    11789        CHECK_NULL_DISPOSE_RET(ohci_batch,
    11890            "Failed to allocate OHCI batch data.\n");
    119 
     91        link_initialize(&ohci_batch->link);
    12092        ohci_batch->td_count =
    12193            (usb_batch->buffer_size + OHCI_TD_MAX_TRANSFER - 1)
     
    249221}
    250222/*----------------------------------------------------------------------------*/
    251 /** Prepares control write transfer.
    252  *
    253  * @param[in] instance Batch structure to use.
    254  *
    255  * Uses generic control transfer using direction OUT(data stage) and
    256  * IN(status stage).
    257  */
    258 void control_write(ohci_transfer_batch_t *ohci_batch)
    259 {
    260         assert(ohci_batch);
    261         batch_control(ohci_batch, USB_DIRECTION_OUT, USB_DIRECTION_IN);
    262         usb_log_debug("Batch %p CONTROL WRITE initialized.\n", ohci_batch);
    263 }
    264 /*----------------------------------------------------------------------------*/
    265 /** Prepares control read transfer.
    266  *
    267  * @param[in] instance Batch structure to use.
    268  *
    269  * Uses generic control transfer using direction IN(data stage) and
    270  * OUT(status stage).
    271  */
    272 void control_read(ohci_transfer_batch_t *ohci_batch)
    273 {
    274         assert(ohci_batch);
    275         batch_control(ohci_batch, USB_DIRECTION_IN, USB_DIRECTION_OUT);
    276         usb_log_debug("Batch %p CONTROL READ initialized.\n", ohci_batch);
    277 }
    278 /*----------------------------------------------------------------------------*/
    279 /** Prepare interrupt in transfer.
    280  *
    281  * @param[in] instance Batch structure to use.
    282  *
    283  * Data transfer.
    284  */
    285 void interrupt_in(ohci_transfer_batch_t *ohci_batch)
    286 {
    287         assert(ohci_batch);
    288         batch_data(ohci_batch);
    289         usb_log_debug("Batch %p INTERRUPT IN initialized.\n", ohci_batch);
    290 }
    291 /*----------------------------------------------------------------------------*/
    292 /** Prepare interrupt out transfer.
    293  *
    294  * @param[in] instance Batch structure to use.
    295  *
    296  * Data transfer.
    297  */
    298 void interrupt_out(ohci_transfer_batch_t *ohci_batch)
    299 {
    300         assert(ohci_batch);
    301         batch_data(ohci_batch);
    302         usb_log_debug("Batch %p INTERRUPT OUT initialized.\n", ohci_batch);
    303 }
    304 /*----------------------------------------------------------------------------*/
    305 /** Prepare bulk in transfer.
    306  *
    307  * @param[in] instance Batch structure to use.
    308  *
    309  * Data transfer.
    310  */
    311 void bulk_in(ohci_transfer_batch_t *ohci_batch)
    312 {
    313         assert(ohci_batch);
    314         batch_data(ohci_batch);
    315         usb_log_debug("Batch %p BULK IN initialized.\n", ohci_batch);
    316 }
    317 /*----------------------------------------------------------------------------*/
    318 /** Prepare bulk out transfer.
    319  *
    320  * @param[in] instance Batch structure to use.
    321  *
    322  * Data transfer.
    323  */
    324 void bulk_out(ohci_transfer_batch_t *ohci_batch)
    325 {
    326         assert(ohci_batch);
    327         batch_data(ohci_batch);
    328         usb_log_debug("Batch %p BULK OUT initialized.\n", ohci_batch);
    329 }
    330 /*----------------------------------------------------------------------------*/
    331223/** Prepare generic control transfer
    332224 *
     
    339231 * Status stage with toggle 1 and direction supplied by parameter.
    340232 */
    341 void batch_control(ohci_transfer_batch_t *ohci_batch,
     233static void batch_control(ohci_transfer_batch_t *ohci_batch,
    342234    usb_direction_t data_dir, usb_direction_t status_dir)
    343235{
     
    397289}
    398290/*----------------------------------------------------------------------------*/
     291#define LOG_BATCH_INITIALIZED(batch, name, dir) \
     292        usb_log_debug2("Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
     293            (batch), (name), (dir), USB_TRANSFER_BATCH_ARGS(*(batch)))
     294
    399295/** Prepare generic data transfer
    400296 *
     
    404300 * OHCI hw in ED.
    405301 */
    406 void batch_data(ohci_transfer_batch_t *ohci_batch)
     302static void batch_data(ohci_transfer_batch_t *ohci_batch)
    407303{
    408304        assert(ohci_batch);
     
    434330                ++td_current;
    435331        }
    436 }
     332        LOG_BATCH_INITIALIZED(ohci_batch->usb_batch,
     333            usb_str_transfer_type(ohci_batch->usb_batch->ep->transfer_type),
     334            usb_str_direction(ohci_batch->usb_batch->ep->direction));
     335}
     336/*----------------------------------------------------------------------------*/
     337static void setup_control(ohci_transfer_batch_t *ohci_batch)
     338{
     339        // TODO Find a better way to do this
     340        if (ohci_batch->device_buffer[0] & (1 << 7)) {
     341                batch_control(ohci_batch, USB_DIRECTION_IN, USB_DIRECTION_OUT);
     342                LOG_BATCH_INITIALIZED(ohci_batch->usb_batch, "control", "write");
     343        } else {
     344                batch_control(ohci_batch, USB_DIRECTION_OUT, USB_DIRECTION_IN);
     345                LOG_BATCH_INITIALIZED(ohci_batch->usb_batch, "control", "write");
     346        }
     347}
     348/*----------------------------------------------------------------------------*/
     349void (*const batch_setup[4][3])(ohci_transfer_batch_t*) =
     350{
     351        { NULL, NULL, setup_control },
     352        { NULL, NULL, NULL },
     353        { batch_data, batch_data, NULL },
     354        { batch_data, batch_data, NULL },
     355};
    437356/**
    438357 * @}
Note: See TracChangeset for help on using the changeset viewer.