1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/aic/include/aic-x1600.h Tue Oct 24 17:34:51 2023 +0200
1.3 @@ -0,0 +1,106 @@
1.4 +/*
1.5 + * AIC support for the X1600.
1.6 + *
1.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/re/c/dma_space.h>
1.28 +#include <l4/sys/types.h>
1.29 +#include <stdint.h>
1.30 +
1.31 +
1.32 +
1.33 +#ifdef __cplusplus
1.34 +
1.35 +#include <l4/devices/cpm-x1600.h>
1.36 +#include <l4/devices/dma-x1600.h>
1.37 +#include <l4/devices/hw_mmio_register_block.h>
1.38 +
1.39 +// AIC channel.
1.40 +
1.41 +class Aic_x1600_channel
1.42 +{
1.43 +private:
1.44 + l4_addr_t _aic_start;
1.45 + Hw::Register_block<32> _regs;
1.46 + enum Clock_identifiers _clock_rx, _clock_tx;
1.47 + Cpm_x1600_chip *_cpm;
1.48 + Dma_x1600_channel *_dma;
1.49 +
1.50 + // Buffer management.
1.51 +
1.52 + unsigned int _size = 0;
1.53 + l4_addr_t _vaddr = 0;
1.54 + l4re_dma_space_dma_addr_t _paddr = 0;
1.55 + l4_cap_idx_t _mem = L4_INVALID_CAP;
1.56 +
1.57 +public:
1.58 + Aic_x1600_channel(l4_addr_t aic_start, l4_addr_t start,
1.59 + enum Clock_identifiers clock_rx,
1.60 + enum Clock_identifiers clock_tx,
1.61 + Cpm_x1600_chip *cpm,
1.62 + Dma_x1600_channel *dma);
1.63 +
1.64 + long get_buffer(uint32_t count, l4_addr_t *addr);
1.65 + unsigned int transfer(uint32_t count, uint32_t sample_rate, uint8_t sample_size);
1.66 +
1.67 +private:
1.68 + void disable();
1.69 + void enable();
1.70 +
1.71 + void config();
1.72 + uint32_t encode_input_size(uint8_t sample_size);
1.73 + uint32_t encode_output_size(uint8_t sample_size);
1.74 + void set_divider(uint32_t divider, uint32_t mask, uint32_t limit, int bit);
1.75 + void set_recv_frequency(uint32_t sample_rate);
1.76 + void set_trans_frequency(uint32_t sample_rate);
1.77 +};
1.78 +
1.79 +// AIC device control.
1.80 +
1.81 +class Aic_x1600_chip
1.82 +{
1.83 +private:
1.84 + l4_addr_t _aic_start, _start, _end;
1.85 + Cpm_x1600_chip *_cpm;
1.86 +
1.87 +public:
1.88 + Aic_x1600_chip(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, Cpm_x1600_chip *cpm);
1.89 +
1.90 + Aic_x1600_channel *get_channel(uint8_t channel, Dma_x1600_channel *dma);
1.91 +};
1.92 +
1.93 +#endif /* __cplusplus */
1.94 +
1.95 +
1.96 +
1.97 +/* C language interface. */
1.98 +
1.99 +EXTERN_C_BEGIN
1.100 +
1.101 +void *x1600_aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm);
1.102 +
1.103 +void *x1600_aic_get_channel(void *aic, uint8_t channel, void *dma);
1.104 +
1.105 +long x1600_aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr);
1.106 +
1.107 +unsigned int x1600_aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size);
1.108 +
1.109 +EXTERN_C_END