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