Changeset b4857bc in mainline


Ignore:
Timestamp:
2011-10-23T21:39:15Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
25f8e5d
Parents:
ac149d5
Message:

b16: DMA controller fixes and increased debug verbosity.

Fix of by one size representation.
Size of 16bit channels is reported in 16 bit words not bytes.
Lower two bytes of address need to shifted by one for 16 bit transfers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/dma_controller.c

    rac149d5 rb4857bc  
    3737#include <libarch/ddi.h>
    3838
     39#include "ddf_log.h"
    3940#include "dma_controller.h"
    4041
     
    7677#define DMA_MODE_CHAN_AUTO_FLAG (1 << 4)
    7778#define DMA_MODE_CHAN_DOWN_FLAG (1 << 5)
    78 #define DMA_MODE_CHAN_MOD_MASK (0x3)
    79 #define DMA_MODE_CHAN_MOD_SHIFT (6)
    80 #define DMA_MODE_CHAN_MOD_DEMAND (0)
    81 #define DMA_MODE_CHAN_MOD_SINGLE (1)
    82 #define DMA_MODE_CHAN_MOD_BLOCK (2)
    83 #define DMA_MODE_CHAN_MOD_CASCADE (3)
     79#define DMA_MODE_CHAN_MODE_MASK (0x3)
     80#define DMA_MODE_CHAN_MODE_SHIFT (6)
     81#define DMA_MODE_CHAN_MODE_DEMAND (0)
     82#define DMA_MODE_CHAN_MODE_SINGLE (1)
     83#define DMA_MODE_CHAN_MODE_BLOCK (2)
     84#define DMA_MODE_CHAN_MODE_CASCADE (3)
    8485
    8586        uint8_t flip_flop;
     
    163164} dma_controller_t;
    164165
     166
     167/* http://zet.aluzina.org/index.php/8237_DMA_controller#DMA_Channel_Registers */
    165168static dma_controller_t controller_8237 = {
    166169        .channels = {
     
    227230                return EIO;
    228231
    229         dma_channel_t dma_channel = controller_8237.channels[channel];
    230 
     232        /* 16 bit transfers are a bit special */
     233        ddf_log_debug("Unspoiled address and size: %p(%zu).\n", pa, size);
     234        if (channel > 4) {
     235                /* Size is the count of 16bit words */
     236                assert(size % 2 == 0);
     237                size /= 2;
     238                /* Address is fun: lower 16bits need to be shifted by 1 */
     239                pa = ((pa & 0xffff) >> 1) | (pa & 0xff0000);
     240        }
     241
     242        const dma_channel_t dma_channel = controller_8237.channels[channel];
     243
     244        ddf_log_debug("Setting channel %u, to address %p(%zu).\n",
     245            channel, pa, size);
    231246        /* Mask DMA request */
    232247        uint8_t value = DMA_SINGLE_MASK_CHAN_TO_REG(channel)
     
    239254        /* Low byte */
    240255        value = pa & 0xff;
     256        ddf_log_verbose("Writing address low byte: %hhx.\n", value);
    241257        pio_write_8(dma_channel.offset_reg_address, value);
    242258
    243259        /* High byte */
    244260        value = (pa >> 8) & 0xff;
     261        ddf_log_verbose("Writing address high byte: %hhx.\n", value);
    245262        pio_write_8(dma_channel.offset_reg_address, value);
    246263
    247264        /* Page address - third byte */
    248265        value = (pa >> 16) & 0xff;
     266        ddf_log_verbose("Writing address page byte: %hhx.\n", value);
    249267        pio_write_8(dma_channel.offset_reg_address, value);
    250268
     
    253271
    254272        /* Low byte */
    255         value = size & 0xff;
     273        value = (size - 1) & 0xff;
     274        ddf_log_verbose("Writing size low byte: %hhx.\n", value);
    256275        pio_write_8(dma_channel.offset_reg_address, value);
    257276
    258277        /* High byte */
    259         value = (size >> 8) & 0xff;
     278        value = ((size - 1) >> 8) & 0xff;
     279        ddf_log_verbose("Writing size high byte: %hhx.\n", value);
    260280        pio_write_8(dma_channel.offset_reg_address, value);
    261281
     
    265285
    266286        return EOK;
    267 
    268287}
    269288/*----------------------------------------------------------------------------*/
     
    291310                << DMA_MODE_CHAN_TRA_SHIFT)
    292311            | (auto_mode ? DMA_MODE_CHAN_AUTO_FLAG : 0)
    293             | (mode << DMA_MODE_CHAN_MOD_SHIFT);
     312            | (mode << DMA_MODE_CHAN_MODE_SHIFT);
     313        ddf_log_verbose("Setting mode: %hhx.\n", value);
    294314        pio_write_8(dma_channel.mode_address, value);
    295315
Note: See TracChangeset for help on using the changeset viewer.