• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef ES8323_CODEC_IMPL_H
10 #define ES8323_CODEC_IMPL_H
11 
12 #include "audio_codec_if.h"
13 #include "osal_mem.h"
14 #include "osal_time.h"
15 #include "osal_io.h"
16 #include "securec.h"
17 #include <linux/types.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif /* __cplusplus */
26 
27 enum Es8323I2sFormatRegVal {
28     ES8323_I2S_SAMPLE_FORMAT_REG_VAL_24 = 0x0,    /*  24-bit serial audio data word length(default) */
29     ES8323_I2S_SAMPLE_FORMAT_REG_VAL_20 = 0x1,    /*  20-bit serial audio data word length */
30     ES8323_I2S_SAMPLE_FORMAT_REG_VAL_16 = 0x2,    /*  18-bit serial audio data word length */
31     ES8323_I2S_SAMPLE_FORMAT_REG_VAL_18 = 0x3,    /*  16-bit serial audio data word length */
32     ES8323_I2S_SAMPLE_FORMAT_REG_VAL_32 = 0x4,    /*  32-bit serial audio data word length */
33 };
34 
35 /**
36  The following enum values correspond to the location of the configuration parameters in the HCS file.
37  If you modify the configuration parameters, you need to modify this value.
38 */
39 enum Es8323DaiHwParamsIndex {
40     ES8323_DHP_RENDER_FREQUENCY_INX = 0,
41     ES8323_DHP_RENDER_FORMAT_INX = 1,
42     ES8323_DHP_RENDER_CHANNEL_INX = 2,
43     ES8323_DHP_CAPTURE_FREQUENCY_INX = 3,
44     ES8323_DHP_CAPTURE_FORMAT_INX = 4,
45     ES8323_DHP_CAPTURE_CHANNEL_INX = 5,
46 };
47 
48 struct Es8323DaiHwParamsTransferData {
49     uint8_t inputParamsBeginIndex;
50     uint8_t inputParamsEndIndex;
51     uint8_t otherParamsBeginIndex;
52     uint8_t otherParamsEndIndex;
53     uint8_t daiHwParamsRegCfgItemCount;
54 };
55 
56 /* Original accessory base declare */
57 enum Es8323I2sFrequency {
58     ES8323_I2S_SAMPLE_FREQUENCY_8000  = 8000,    /* 8kHz sample_rate */
59     ES8323_I2S_SAMPLE_FREQUENCY_11025 = 11025,   /* 11.025kHz sample_rate */
60     ES8323_I2S_SAMPLE_FREQUENCY_12000 = 12000,   /* 12kHz sample_rate */
61     ES8323_I2S_SAMPLE_FREQUENCY_16000 = 16000,   /* 16kHz sample_rate */
62     ES8323_I2S_SAMPLE_FREQUENCY_22050 = 22050,   /* 22.050kHz sample_rate */
63     ES8323_I2S_SAMPLE_FREQUENCY_24000 = 24000,   /* 24kHz sample_rate */
64     ES8323_I2S_SAMPLE_FREQUENCY_32000 = 32000,   /* 32kHz sample_rate */
65     ES8323_I2S_SAMPLE_FREQUENCY_44100 = 44100,   /* 44.1kHz sample_rate */
66     ES8323_I2S_SAMPLE_FREQUENCY_48000 = 48000,   /* 48kHz sample_rate */
67     ES8323_I2S_SAMPLE_FREQUENCY_64000 = 64000,   /* 64kHz sample_rate */
68     ES8323_I2S_SAMPLE_FREQUENCY_88200 = 88200,   /* 88.2kHz sample_rate */
69     ES8323_I2S_SAMPLE_FREQUENCY_96000 = 96000    /* 96kHz sample_rate */
70 };
71 
72 enum Es8323I2sFrequencyRegVal {
73     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_8000  = 0x0,   /* 8kHz sample_rate */
74     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_11025 = 0x1,   /* 11.025kHz sample_rate */
75     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_12000 = 0x2,   /* 12kHz sample_rate */
76     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_16000 = 0x3,   /* 16kHz sample_rate */
77     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_22050 = 0x4,   /* 22.050kHz sample_rate */
78     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_24000 = 0x5,   /* 24kHz sample_rate */
79     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_32000 = 0x6,   /* 32kHz sample_rate */
80     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_44100 = 0x7,   /* 44.1kHz sample_rate */
81     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_48000 = 0x8,   /* 48kHz sample_rate */
82     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_64000 = 0x9,   /* 64kHz sample_rate */
83     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_88200 = 0xA,   /* 88.2kHz sample_rate */
84     ES8323_I2S_SAMPLE_FREQUENCY_REG_VAL_96000 = 0xB    /* 96kHz sample_rate */
85 };
86 
87 struct Es8323TransferData {
88     uint32_t codecCfgCtrlCount;
89     struct AudioRegCfgGroupNode **codecRegCfgGroupNode;
90     struct AudioKcontrol *codecControls;
91 };
92 
93 struct Es8323DaiParamsVal {
94     uint32_t frequencyVal;
95     uint32_t formatVal;
96     uint32_t channelVal;
97 };
98 
99 int32_t Es8323DeviceRegRead(const struct CodecDevice *codec, uint32_t reg, uint32_t *value);
100 int32_t Es8323DeviceRegWrite(const struct CodecDevice *codec, uint32_t reg, uint32_t value);
101 int32_t Es8323GetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData);
102 
103 /* Original es8323 declare */
104 int32_t Es8323DeviceInit(struct AudioCard *audioCard, const struct CodecDevice *device);
105 int32_t Es8323DaiDeviceInit(struct AudioCard *card, const struct DaiDevice *device);
106 int32_t Es8323DaiStartup(const struct AudioCard *card, const struct DaiDevice *device);
107 int32_t Es8323DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param);
108 int32_t Es8323NormalTrigger(const struct AudioCard *card, int cmd, const struct DaiDevice *device);
109 
110 
111 #define ES8323_CONTROL1         0x00
112 #define ES8323_CONTROL2         0x01
113 #define ES8323_CHIPPOWER        0x02
114 #define ES8323_ADCPOWER         0x03
115 #define ES8323_DACPOWER         0x04
116 #define ES8323_CHIPLOPOW1       0x05
117 #define ES8323_CHIPLOPOW2       0x06
118 #define ES8323_ANAVOLMANAG      0x07
119 #define ES8323_MASTERMODE       0x08
120 #define ES8323_ADCCONTROL1      0x09
121 #define ES8323_ADCCONTROL2      0x0a
122 #define ES8323_ADCCONTROL3      0x0b
123 #define ES8323_ADCCONTROL4      0x0c
124 #define ES8323_ADCCONTROL5      0x0d
125 #define ES8323_ADCCONTROL6      0x0e
126 #define ES8323_ADCCONTROL7      0x0f
127 #define ES8323_ADCCONTROL8      0x10
128 #define ES8323_ADCCONTROL9      0x11
129 #define ES8323_ADCCONTROL10     0x12
130 #define ES8323_ADCCONTROL11     0x13
131 #define ES8323_ADCCONTROL12     0x14
132 #define ES8323_ADCCONTROL13     0x15
133 #define ES8323_ADCCONTROL14     0x16
134 
135 #define ES8323_DACCONTROL1      0x17
136 #define ES8323_DACCONTROL2      0x18
137 #define ES8323_DACCONTROL3      0x19
138 #define ES8323_DACCONTROL4      0x1a
139 #define ES8323_DACCONTROL5      0x1b
140 #define ES8323_DACCONTROL6      0x1c
141 #define ES8323_DACCONTROL7      0x1d
142 #define ES8323_DACCONTROL8      0x1e
143 #define ES8323_DACCONTROL9      0x1f
144 #define ES8323_DACCONTROL10     0x20
145 #define ES8323_DACCONTROL11     0x21
146 #define ES8323_DACCONTROL12     0x22
147 #define ES8323_DACCONTROL13     0x23
148 #define ES8323_DACCONTROL14     0x24
149 #define ES8323_DACCONTROL15     0x25
150 #define ES8323_DACCONTROL16     0x26
151 #define ES8323_DACCONTROL17     0x27
152 #define ES8323_DACCONTROL18     0x28
153 #define ES8323_DACCONTROL19     0x29
154 #define ES8323_DACCONTROL20     0x2a
155 #define ES8323_DACCONTROL21     0x2b
156 #define ES8323_DACCONTROL22     0x2c
157 #define ES8323_DACCONTROL23     0x2d
158 #define ES8323_DACCONTROL24     0x2e
159 #define ES8323_DACCONTROL25     0x2f
160 #define ES8323_DACCONTROL26     0x30
161 #define ES8323_DACCONTROL27     0x31
162 #define ES8323_DACCONTROL28     0x32
163 #define ES8323_DACCONTROL29     0x33
164 #define ES8323_DACCONTROL30     0x34
165 
166 #define ES8323_LADC_VOL         ES8323_ADCCONTROL8
167 #define ES8323_RADC_VOL         ES8323_ADCCONTROL9
168 
169 #define ES8323_LDAC_VOL         ES8323_DACCONTROL4
170 #define ES8323_RDAC_VOL         ES8323_DACCONTROL5
171 
172 #define ES8323_LOUT1_VOL        ES8323_DACCONTROL24
173 #define ES8323_ROUT1_VOL        ES8323_DACCONTROL25
174 #define ES8323_LOUT2_VOL        ES8323_DACCONTROL26
175 #define ES8323_ROUT2_VOL        ES8323_DACCONTROL27
176 
177 #define ES8323_ADC_MUTE         ES8323_ADCCONTROL7
178 #define ES8323_DAC_MUTE         ES8323_DACCONTROL3
179 
180 
181 
182 #define ES8323_IFACE            ES8323_MASTERMODE
183 
184 #define ES8323_ADC_IFACE        ES8323_ADCCONTROL4
185 #define ES8323_ADC_SRATE        ES8323_ADCCONTROL5
186 
187 #define ES8323_DAC_IFACE        ES8323_DACCONTROL1
188 #define ES8323_DAC_SRATE        ES8323_DACCONTROL2
189 
190 #define NR_SUPPORTED_MCLK_LRCK_RATIOS 5
191 /* codec private data */
192 struct es8323_priv {
193 	unsigned int sysclk;
194 	unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS];
195 	struct clk *mclk;
196 	struct snd_pcm_hw_constraint_list sysclk_constraints;
197 	struct snd_soc_component *component;
198 	struct regmap *regmap;
199 };
200 
201 extern struct es8323_priv *GetCodecDevice(void);
202 #ifdef __cplusplus
203 #if __cplusplus
204 }
205 #endif
206 #endif
207 
208 #endif
209