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 public: 48 explicit Aic_x1600_channel(l4_addr_t aic_start, l4_addr_t start, 49 enum Clock_identifiers clock_rx, 50 enum Clock_identifiers clock_tx, 51 Cpm_x1600_chip *cpm, 52 Dma_x1600_channel *dma); 53 54 uint32_t transfer(l4re_dma_space_dma_addr_t paddr, uint32_t count, 55 uint32_t sample_rate, uint8_t sample_size); 56 57 private: 58 void disable(); 59 void enable(); 60 61 void config(); 62 uint32_t encode_input_size(uint8_t sample_size); 63 uint32_t encode_output_size(uint8_t sample_size); 64 void set_divider(uint32_t divider, uint32_t mask, uint32_t limit, int bit); 65 void set_recv_frequency(uint32_t sample_rate); 66 void set_trans_frequency(uint32_t sample_rate); 67 }; 68 69 /* AIC device control. */ 70 71 class Aic_x1600_chip 72 { 73 private: 74 l4_addr_t _aic_start, _start, _end; 75 Cpm_x1600_chip *_cpm; 76 77 public: 78 explicit Aic_x1600_chip(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, 79 Cpm_x1600_chip *cpm); 80 81 Aic_x1600_channel *get_channel(uint8_t channel, Dma_x1600_channel *dma); 82 }; 83 84 #endif /* __cplusplus */ 85 86 87 88 /* C language interface. */ 89 90 EXTERN_C_BEGIN 91 92 void *x1600_aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm); 93 94 void *x1600_aic_get_channel(void *aic, uint8_t channel, void *dma); 95 96 uint32_t x1600_aic_transfer(void *channel, l4re_dma_space_dma_addr_t paddr, 97 uint32_t count, uint32_t sample_rate, 98 uint8_t sample_size); 99 100 EXTERN_C_END