| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* Copyright 2019 NXP |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef _FSL_ASRC_COMMON_H |
| 8 |
#define _FSL_ASRC_COMMON_H |
| 9 |
|
| 10 |
/* directions */ |
| 11 |
#define IN 0 |
| 12 |
#define OUT 1 |
| 13 |
|
| 14 |
enum asrc_pair_index { |
| 15 |
ASRC_INVALID_PAIR = -1, |
| 16 |
ASRC_PAIR_A = 0, |
| 17 |
ASRC_PAIR_B = 1, |
| 18 |
ASRC_PAIR_C = 2, |
| 19 |
ASRC_PAIR_D = 3, |
| 20 |
}; |
| 21 |
|
| 22 |
#define PAIR_CTX_NUM 0x4 |
| 23 |
|
| 24 |
/** |
| 25 |
* struct fsl_asrc_m2m_cap - capability data |
| 26 |
* @fmt_in: input sample format |
| 27 |
* @fmt_out: output sample format |
| 28 |
* @chan_min: minimum channel number |
| 29 |
* @chan_max: maximum channel number |
| 30 |
* @rate_in: minimum rate |
| 31 |
* @rate_out: maximum rete |
| 32 |
*/ |
| 33 |
struct fsl_asrc_m2m_cap { |
| 34 |
u64 fmt_in; |
| 35 |
u64 fmt_out; |
| 36 |
int chan_min; |
| 37 |
int chan_max; |
| 38 |
const unsigned int *rate_in; |
| 39 |
int rate_in_count; |
| 40 |
const unsigned int *rate_out; |
| 41 |
int rate_out_count; |
| 42 |
}; |
| 43 |
|
| 44 |
/** |
| 45 |
* fsl_asrc_pair: ASRC Pair common data |
| 46 |
* |
| 47 |
* @asrc: pointer to its parent module |
| 48 |
* @error: error record |
| 49 |
* @index: pair index (ASRC_PAIR_A, ASRC_PAIR_B, ASRC_PAIR_C) |
| 50 |
* @channels: occupied channel number |
| 51 |
* @desc: input and output dma descriptors |
| 52 |
* @dma_chan: inputer and output DMA channels |
| 53 |
* @dma_data: private dma data |
| 54 |
* @pos: hardware pointer position |
| 55 |
* @req_dma_chan: flag to release dev_to_dev chan |
| 56 |
* @private: pair private area |
| 57 |
* @complete: dma task complete |
| 58 |
* @sample_format: format of m2m |
| 59 |
* @rate: rate of m2m |
| 60 |
* @buf_len: buffer length of m2m |
| 61 |
* @dma_buffer: buffer pointers |
| 62 |
* @first_convert: start of conversion |
| 63 |
* @ratio_mod_flag: flag for new ratio modifier |
| 64 |
* @ratio_mod: ratio modification |
| 65 |
*/ |
| 66 |
struct fsl_asrc_pair { |
| 67 |
struct fsl_asrc *asrc; |
| 68 |
unsigned int error; |
| 69 |
|
| 70 |
enum asrc_pair_index index; |
| 71 |
unsigned int channels; |
| 72 |
|
| 73 |
struct dma_async_tx_descriptor *desc[2]; |
| 74 |
struct dma_chan *dma_chan[2]; |
| 75 |
struct imx_dma_data dma_data; |
| 76 |
unsigned int pos; |
| 77 |
bool req_dma_chan; |
| 78 |
|
| 79 |
void *private; |
| 80 |
|
| 81 |
/* used for m2m */ |
| 82 |
struct completion complete[2]; |
| 83 |
snd_pcm_format_t sample_format[2]; |
| 84 |
unsigned int rate[2]; |
| 85 |
unsigned int buf_len[2]; |
| 86 |
struct snd_dma_buffer dma_buffer[2]; |
| 87 |
unsigned int first_convert; |
| 88 |
bool ratio_mod_flag; |
| 89 |
unsigned int ratio_mod; |
| 90 |
}; |
| 91 |
|
| 92 |
/** |
| 93 |
* fsl_asrc: ASRC common data |
| 94 |
* |
| 95 |
* @dma_params_rx: DMA parameters for receive channel |
| 96 |
* @dma_params_tx: DMA parameters for transmit channel |
| 97 |
* @pdev: platform device pointer |
| 98 |
* @regmap: regmap handler |
| 99 |
* @paddr: physical address to the base address of registers |
| 100 |
* @mem_clk: clock source to access register |
| 101 |
* @ipg_clk: clock source to drive peripheral |
| 102 |
* @spba_clk: SPBA clock (optional, depending on SoC design) |
| 103 |
* @card: compress sound card |
| 104 |
* @lock: spin lock for resource protection |
| 105 |
* @pair: pair pointers |
| 106 |
* @channel_avail: non-occupied channel numbers |
| 107 |
* @asrc_rate: default sample rate for ASoC Back-Ends |
| 108 |
* @asrc_format: default sample format for ASoC Back-Ends |
| 109 |
* @use_edma: edma is used |
| 110 |
* @start_before_dma: start asrc before dma |
| 111 |
* @get_dma_channel: function pointer |
| 112 |
* @request_pair: function pointer |
| 113 |
* @release_pair: function pointer |
| 114 |
* @get_fifo_addr: function pointer |
| 115 |
* @m2m_get_cap: function pointer |
| 116 |
* @m2m_prepare: function pointer |
| 117 |
* @m2m_start: function pointer |
| 118 |
* @m2m_unprepare: function pointer |
| 119 |
* @m2m_stop: function pointer |
| 120 |
* @m2m_output_ready: function pointer, check output fifo ready or not |
| 121 |
* @m2m_calc_out_len: function pointer |
| 122 |
* @m2m_get_maxburst: function pointer |
| 123 |
* @m2m_pair_suspend: function pointer |
| 124 |
* @m2m_pair_resume: function pointer |
| 125 |
* @m2m_set_ratio_mod: function pointer |
| 126 |
* @get_output_fifo_size: function pointer |
| 127 |
* @pair_priv_size: size of pair private struct. |
| 128 |
* @private: private data structure |
| 129 |
*/ |
| 130 |
struct fsl_asrc { |
| 131 |
struct snd_dmaengine_dai_dma_data dma_params_rx; |
| 132 |
struct snd_dmaengine_dai_dma_data dma_params_tx; |
| 133 |
struct platform_device *pdev; |
| 134 |
struct regmap *regmap; |
| 135 |
unsigned long paddr; |
| 136 |
struct clk *mem_clk; |
| 137 |
struct clk *ipg_clk; |
| 138 |
struct clk *spba_clk; |
| 139 |
struct snd_card *card; |
| 140 |
spinlock_t lock; /* spin lock for resource protection */ |
| 141 |
|
| 142 |
struct fsl_asrc_pair *pair[PAIR_CTX_NUM]; |
| 143 |
unsigned int channel_avail; |
| 144 |
|
| 145 |
int asrc_rate; |
| 146 |
snd_pcm_format_t asrc_format; |
| 147 |
bool use_edma; |
| 148 |
bool start_before_dma; |
| 149 |
|
| 150 |
struct dma_chan *(*get_dma_channel)(struct fsl_asrc_pair *pair, bool dir); |
| 151 |
int (*request_pair)(int channels, struct fsl_asrc_pair *pair); |
| 152 |
void (*release_pair)(struct fsl_asrc_pair *pair); |
| 153 |
int (*get_fifo_addr)(u8 dir, enum asrc_pair_index index); |
| 154 |
int (*m2m_get_cap)(struct fsl_asrc_m2m_cap *cap); |
| 155 |
|
| 156 |
int (*m2m_prepare)(struct fsl_asrc_pair *pair); |
| 157 |
int (*m2m_start)(struct fsl_asrc_pair *pair); |
| 158 |
int (*m2m_unprepare)(struct fsl_asrc_pair *pair); |
| 159 |
int (*m2m_stop)(struct fsl_asrc_pair *pair); |
| 160 |
bool (*m2m_output_ready)(struct fsl_asrc_pair *pair); |
| 161 |
|
| 162 |
int (*m2m_calc_out_len)(struct fsl_asrc_pair *pair, int input_buffer_length); |
| 163 |
int (*m2m_get_maxburst)(u8 dir, struct fsl_asrc_pair *pair); |
| 164 |
int (*m2m_pair_suspend)(struct fsl_asrc_pair *pair); |
| 165 |
int (*m2m_pair_resume)(struct fsl_asrc_pair *pair); |
| 166 |
int (*m2m_set_ratio_mod)(struct fsl_asrc_pair *pair, int val); |
| 167 |
|
| 168 |
unsigned int (*get_output_fifo_size)(struct fsl_asrc_pair *pair); |
| 169 |
size_t pair_priv_size; |
| 170 |
|
| 171 |
void *private; |
| 172 |
}; |
| 173 |
|
| 174 |
#define DRV_NAME "fsl-asrc-dai" |
| 175 |
extern struct snd_soc_component_driver fsl_asrc_component; |
| 176 |
|
| 177 |
int fsl_asrc_m2m_init(struct fsl_asrc *asrc); |
| 178 |
void fsl_asrc_m2m_exit(struct fsl_asrc *asrc); |
| 179 |
int fsl_asrc_m2m_resume(struct fsl_asrc *asrc); |
| 180 |
int fsl_asrc_m2m_suspend(struct fsl_asrc *asrc); |
| 181 |
|
| 182 |
#endif /* _FSL_ASRC_COMMON_H */ |