Landfall

Change of pkg/devices/lib/aic/src/x1600.cc

220:edb87791dfa7
pkg/devices/lib/aic/src/x1600.cc cpm-library-improvements
     1.1 --- a/pkg/devices/lib/aic/src/x1600.cc	Fri Nov 03 18:09:49 2023 +0100
     1.2 +++ b/pkg/devices/lib/aic/src/x1600.cc	Fri Nov 03 19:58:11 2023 +0100
     1.3 @@ -21,12 +21,11 @@
     1.4  
     1.5  #include <l4/devices/aic-x1600.h>
     1.6  #include <l4/devices/dma.h>
     1.7 -#include <l4/devices/hw_mmio_register_block.h>
     1.8 +#include <l4/sys/err.h>
     1.9 +
    1.10  
    1.11 -#include <l4/sys/icu.h>
    1.12 -#include <l4/util/util.h>
    1.13  
    1.14 -#include <stdio.h>
    1.15 +/* Register definitions. */
    1.16  
    1.17  enum Regs
    1.18  {
    1.19 @@ -52,9 +51,12 @@
    1.20    Aic_tmaster               = 0x0004,     // TMASTER
    1.21    Aic_rmaster               = 0x0002,     // RMASTER
    1.22    Aic_enable                = 0x0001,     // ENB
    1.23 +};
    1.24  
    1.25 -  Aic_rfifo_thold_bit       = 24,         // RFTH
    1.26 -  Aic_tfifo_thold_bit       = 16,         // TFTH
    1.27 +enum Aic_config_shifts : unsigned
    1.28 +{
    1.29 +  Aic_rfifo_thold_shift     = 24,         // RFTH
    1.30 +  Aic_tfifo_thold_shift     = 16,         // TFTH
    1.31  };
    1.32  
    1.33  enum Aic_fifo_limits : unsigned
    1.34 @@ -126,10 +128,13 @@
    1.35    Aic_tfifo_request         = 0x08,       // TFS
    1.36    Aic_tfifo_loop_overrun    = 0x04,       // TFLOR
    1.37    Aic_tfifo_loop_request    = 0x02,       // TFLS
    1.38 +};
    1.39  
    1.40 -  Aic_rfifo_level_bit       = 24,         // RFL
    1.41 -  Aic_tfifo_loop_level_bit  = 15,         // TFLL
    1.42 -  Aic_tfifo_level_bit       = 8,          // TFL
    1.43 +enum Aic_fifo_status_shifts : unsigned
    1.44 +{
    1.45 +  Aic_rfifo_level_shift       = 24,       // RFL
    1.46 +  Aic_tfifo_loop_level_shift  = 15,       // TFLL
    1.47 +  Aic_tfifo_level_shift       = 8,        // TFL
    1.48  };
    1.49  
    1.50  enum Aic_i2s_msb_status_bits : unsigned
    1.51 @@ -144,9 +149,12 @@
    1.52  {
    1.53    Aic_recv_divider_mask     = 0x1ff0000,  // RDIV
    1.54    Aic_trans_divider_mask    = 0x00001ff,  // TDIV
    1.55 +};
    1.56  
    1.57 -  Aic_recv_divider_bit      = 16,         // RDIV
    1.58 -  Aic_trans_divider_bit     = 0,          // TDIV
    1.59 +enum Aic_i2s_msb_divider_shifts : unsigned
    1.60 +{
    1.61 +  Aic_recv_divider_shift    = 16,         // RDIV
    1.62 +  Aic_trans_divider_shift   = 0,          // TDIV
    1.63  };
    1.64  
    1.65  enum Aic_i2s_msb_divider_limits : unsigned
    1.66 @@ -172,7 +180,7 @@
    1.67  
    1.68  
    1.69  
    1.70 -// Initialise a channel.
    1.71 +/* Initialise a channel. */
    1.72  
    1.73  Aic_x1600_channel::Aic_x1600_channel(l4_addr_t aic_start, l4_addr_t start,
    1.74                                       enum Clock_identifiers clock_rx,
    1.75 @@ -220,14 +228,10 @@
    1.76  {
    1.77    // NOTE: Setting transmit request threshold to 31 (15 * 2 + 1).
    1.78  
    1.79 -  printf("config = %08x\n", (uint32_t) _regs[Aic_config]);
    1.80 -
    1.81    _regs[Aic_config] = Aic_shared_clock | Aic_select_i2s_msb | Aic_reset |
    1.82 -                      Aic_tmaster | Aic_enable | (15 << Aic_tfifo_thold_bit);
    1.83 +                      Aic_tmaster | Aic_enable | (15 << Aic_tfifo_thold_shift);
    1.84  
    1.85    _regs[Aic_i2s_msb_control] = Aic_select_i2s;
    1.86 -
    1.87 -  printf("config = %08x\n", (uint32_t) _regs[Aic_config]);
    1.88  }
    1.89  
    1.90  /*
    1.91 @@ -254,19 +258,14 @@
    1.92  Aic_x1600_channel::set_recv_frequency(uint32_t sample_rate)
    1.93  {
    1.94    set_divider(_cpm->get_frequency(_clock_rx) / (sample_rate * 32 * 2),
    1.95 -              Aic_recv_divider_mask, Aic_recv_divider_limit, Aic_recv_divider_bit);
    1.96 +              Aic_recv_divider_mask, Aic_recv_divider_limit, Aic_recv_divider_shift);
    1.97  }
    1.98  
    1.99  void
   1.100  Aic_x1600_channel::set_trans_frequency(uint32_t sample_rate)
   1.101  {
   1.102 -  printf("tx %d / (freq %d * %d * 2) = %d vs. %d\n", _cpm->get_frequency(_clock_tx),
   1.103 -                                          sample_rate, 32,
   1.104 -                                          _cpm->get_frequency(_clock_tx) / (sample_rate * 32 * 2),
   1.105 -                                          Aic_trans_divider_limit);
   1.106 -
   1.107    set_divider(_cpm->get_frequency(_clock_tx) / (sample_rate * 32 * 2),
   1.108 -              Aic_trans_divider_mask, Aic_trans_divider_limit, Aic_trans_divider_bit);
   1.109 +              Aic_trans_divider_mask, Aic_trans_divider_limit, Aic_trans_divider_shift);
   1.110  }
   1.111  
   1.112  uint32_t
   1.113 @@ -313,12 +312,11 @@
   1.114    }
   1.115  }
   1.116  
   1.117 -// Obtain a DMA-accessible buffer for sample transfers.
   1.118 +/* Obtain a DMA-accessible buffer for sample transfers. */
   1.119  
   1.120  long
   1.121  Aic_x1600_channel::get_buffer(uint32_t count, l4_addr_t *addr)
   1.122  {
   1.123 -  printf("get_buffer(%d)\n", count);
   1.124    long err = get_dma_region(count, 8, &_vaddr, &_paddr, &_mem);
   1.125  
   1.126    if (err)
   1.127 @@ -328,18 +326,15 @@
   1.128  
   1.129    _size = count;
   1.130    *addr = _vaddr;
   1.131 -  printf("size = %d\n", _size);
   1.132    return L4_EOK;
   1.133  }
   1.134  
   1.135 -// Transfer a sample using the given byte count (total sample size), sample rate
   1.136 -// (or frequency), sample unit size (or resolution, width).
   1.137 +/* Transfer a sample using the given byte count (total sample size), sample rate
   1.138 +   (or frequency), sample unit size (or resolution, width). */
   1.139  
   1.140 -unsigned int
   1.141 +uint32_t
   1.142  Aic_x1600_channel::transfer(uint32_t count, uint32_t sample_rate, uint8_t sample_size)
   1.143  {
   1.144 -  printf("transfer(%d, %d, %d)\n", count, sample_rate, sample_size);
   1.145 -
   1.146    if (count > _size)
   1.147      return 0;
   1.148  
   1.149 @@ -373,38 +368,24 @@
   1.150                         Aic_enable_trans_dma |
   1.151                         Aic_enable_playback;
   1.152  
   1.153 -  printf("control = %08x\n", (uint32_t) _regs[Aic_control]);
   1.154 -  printf("config = %08x\n", (uint32_t) _regs[Aic_config]);
   1.155 -  printf("divider = %d\n", (uint32_t) _regs[Aic_i2s_msb_divider]);
   1.156 -  printf("status = %08x\n", (uint32_t) _regs[Aic_i2s_msb_status]);
   1.157 -  printf("fifo = %08x\n", (uint32_t) _regs[Aic_fifo_status]);
   1.158 -
   1.159 -  // Transfer from the allocated region to the FIFO. Use an incrementing source
   1.160 -  // address with source width, destination width and transfer unit reflecting
   1.161 -  // the sample size, and with transfers initiated by an empty AIC transmit
   1.162 -  // FIFO.
   1.163 -
   1.164 -  printf("transfer from %llx to %lx\n", _paddr, _aic_start + Aic_fifo_data);
   1.165 +  /* Transfer from the allocated region to the FIFO. Use an incrementing source
   1.166 +     address with source width, destination width and transfer unit reflecting
   1.167 +     the sample size, and with transfers initiated by an empty AIC transmit
   1.168 +     FIFO. */
   1.169  
   1.170 -  unsigned int sample_unit = (sample_size == 8) ? 1 :
   1.171 -                             (sample_size == 16) ? 2 :
   1.172 -                             4;
   1.173 -  unsigned int unit_count = count / sample_unit;
   1.174 +  uint32_t sample_unit = (sample_size == 8) ? 1 : (sample_size == 16) ? 2 : 4;
   1.175 +  uint32_t unit_count = count / sample_unit;
   1.176 +  uint32_t to_transfer = _dma->transfer(_paddr,
   1.177 +                                        _aic_start + Aic_fifo_data,
   1.178 +                                        unit_count,
   1.179 +                                        true,
   1.180 +                                        false,
   1.181 +                                        sample_unit,
   1.182 +                                        sample_unit,
   1.183 +                                        sample_unit,
   1.184 +                                        Dma_request_aic_out);
   1.185  
   1.186 -  unsigned int to_transfer = _dma->transfer(_paddr,
   1.187 -                                            _aic_start + Aic_fifo_data,
   1.188 -                                            unit_count,
   1.189 -                                            true,
   1.190 -                                            false,
   1.191 -                                            sample_unit,
   1.192 -                                            sample_unit,
   1.193 -                                            sample_unit,
   1.194 -                                            Dma_request_aic_out);
   1.195 -
   1.196 -  printf("status = %08x\n", (uint32_t) _regs[Aic_i2s_msb_status]);
   1.197 -  printf("fifo = %08x\n", (uint32_t) _regs[Aic_fifo_status]);
   1.198 -
   1.199 -  unsigned int transferred = 0;
   1.200 +  uint32_t transferred = 0;
   1.201  
   1.202    if (to_transfer)
   1.203      transferred = to_transfer ? (unit_count - _dma->wait()) * sample_unit : 0;
   1.204 @@ -460,7 +441,7 @@
   1.205    return static_cast<Aic_x1600_channel *>(channel)->get_buffer(count, addr);
   1.206  }
   1.207  
   1.208 -unsigned int x1600_aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size)
   1.209 +uint32_t x1600_aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size)
   1.210  {
   1.211    return static_cast<Aic_x1600_channel *>(channel)->transfer(count, sample_rate, sample_size);
   1.212  }