1 /* 2 * AIC support for the X1600. 3 * 4 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/re/c/dma_space.h> 25 #include <l4/sys/types.h> 26 #include <stdint.h> 27 28 29 30 #ifdef __cplusplus 31 32 #include <l4/devices/cpm-x1600.h> 33 #include <l4/devices/dma-x1600.h> 34 #include <l4/devices/hw_mmio_register_block.h> 35 36 // AIC channel. 37 38 class Aic_x1600_channel 39 { 40 private: 41 l4_addr_t _aic_start; 42 Hw::Register_block<32> _regs; 43 enum Clock_identifiers _clock_rx, _clock_tx; 44 Cpm_x1600_chip *_cpm; 45 Dma_x1600_channel *_dma; 46 47 // Buffer management. 48 49 unsigned int _size = 0; 50 l4_addr_t _vaddr = 0; 51 l4re_dma_space_dma_addr_t _paddr = 0; 52 l4_cap_idx_t _mem = L4_INVALID_CAP; 53 54 public: 55 Aic_x1600_channel(l4_addr_t aic_start, l4_addr_t start, 56 enum Clock_identifiers clock_rx, 57 enum Clock_identifiers clock_tx, 58 Cpm_x1600_chip *cpm, 59 Dma_x1600_channel *dma); 60 61 long get_buffer(uint32_t count, l4_addr_t *addr); 62 unsigned int transfer(uint32_t count, uint32_t sample_rate, uint8_t sample_size); 63 64 private: 65 void disable(); 66 void enable(); 67 68 void config(); 69 uint32_t encode_input_size(uint8_t sample_size); 70 uint32_t encode_output_size(uint8_t sample_size); 71 void set_divider(uint32_t divider, uint32_t mask, uint32_t limit, int bit); 72 void set_recv_frequency(uint32_t sample_rate); 73 void set_trans_frequency(uint32_t sample_rate); 74 }; 75 76 // AIC device control. 77 78 class Aic_x1600_chip 79 { 80 private: 81 l4_addr_t _aic_start, _start, _end; 82 Cpm_x1600_chip *_cpm; 83 84 public: 85 Aic_x1600_chip(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, Cpm_x1600_chip *cpm); 86 87 Aic_x1600_channel *get_channel(uint8_t channel, Dma_x1600_channel *dma); 88 }; 89 90 #endif /* __cplusplus */ 91 92 93 94 /* C language interface. */ 95 96 EXTERN_C_BEGIN 97 98 void *x1600_aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm); 99 100 void *x1600_aic_get_channel(void *aic, uint8_t channel, void *dma); 101 102 long x1600_aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr); 103 104 unsigned int x1600_aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size); 105 106 EXTERN_C_END