1 /*
2  * Copyright (c) 2023 Centralp
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_AUDIO_TAS6422DAC_H_
8 #define ZEPHYR_DRIVERS_AUDIO_TAS6422DAC_H_
9 
10 #include <zephyr/sys/util_macro.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /* Mode Control Register */
17 #define MODE_CTRL_ADDR 0x00
18 #define MODE_CTRL_RESET            BIT(7)
19 #define MODE_CTRL_RESET_MASK       BIT(7)
20 #define MODE_CTRL_PBTL_CH12        BIT(4)
21 #define MODE_CTRL_PBTL_CH12_MASK   BIT(4)
22 #define MODE_CTRL_CH1_LO_MODE      BIT(3)
23 #define MODE_CTRL_CH1_LO_MODE_MASK BIT(3)
24 #define MODE_CTRL_CH2_LO_MODE      BIT(2)
25 #define MODE_CTRL_CH2_LO_MODE_MASK BIT(2)
26 
27 /* Miscellaneous Control 1 Register */
28 #define MISC_CTRL_1_ADDR 0x01
29 #define MISC_CTRL_1_HPF_BYPASS                       BIT(7)
30 #define MISC_CTRL_1_HPF_BYPASS_MASK                  BIT(7)
31 #define MISC_CTRL_1_OTW_CONTROL_MASK                 (BIT_MASK(2) << 5)
32 #define MISC_CTRL_1_OTW_CONTROL(val)                 (((val) << 5) & MISC_CTRL_1_OTW_CONTROL_MASK)
33 #define MISC_CTRL_1_OTW_CONTROL_140_DEGREE           0
34 #define MISC_CTRL_1_OTW_CONTROL_130_DEGREE           1
35 #define MISC_CTRL_1_OTW_CONTROL_120_DEGREE           2
36 #define MISC_CTRL_1_OTW_CONTROL_110_DEGREE           3
37 #define MISC_CTRL_1_OC_CONTROL                       BIT(4)
38 #define MISC_CTRL_1_OC_CONTROL_MASK                  BIT(4)
39 #define MISC_CTRL_1_VOLUME_RATE_MASK                 (BIT_MASK(2) << 2)
40 #define MISC_CTRL_1_VOLUME_RATE(val)                 (((val) << 2) & MISC_CTRL_1_VOLUME_RATE_MASK)
41 #define MISC_CTRL_1_VOLUME_RATE_1_STEP_EVERY_1_FSYNC 0
42 #define MISC_CTRL_1_VOLUME_RATE_1_STEP_EVERY_2_FSYNC 1
43 #define MISC_CTRL_1_VOLUME_RATE_1_STEP_EVERY_4_FSYNC 2
44 #define MISC_CTRL_1_VOLUME_RATE_1_STEP_EVERY_8_FSYNC 3
45 #define MISC_CTRL_1_GAIN_MASK                        BIT_MASK(2)
46 #define MISC_CTRL_1_GAIN(val)                        ((val) & MISC_CTRL_1_GAIN_MASK)
47 #define MISC_CTRL_1_GAIN_7_5_V_PEAK_OUTPUT           0
48 #define MISC_CTRL_1_GAIN_15_V_PEAK_OUTPUT            1
49 #define MISC_CTRL_1_GAIN_21_V_PEAK_OUTPUT            2
50 #define MISC_CTRL_1_GAIN_29_V_PEAK_OUTPUT            3
51 
52 /* Miscellaneous Control 2 Register */
53 #define MISC_CTRL_2_ADDR 0x02
54 #define MISC_CTRL_2_PWM_FREQUENCY_MASK      (BIT_MASK(3) << 4)
55 #define MISC_CTRL_2_PWM_FREQUENCY(val)      (((val) << 4) & MISC_CTRL_2_PWM_FREQUENCY_MASK)
56 #define MISC_CTRL_2_PWM_FREQUENCY_8_FS      0
57 #define MISC_CTRL_2_PWM_FREQUENCY_10_FS     1
58 #define MISC_CTRL_2_PWM_FREQUENCY_38_FS     5
59 #define MISC_CTRL_2_PWM_FREQUENCY_44_FS     6
60 #define MISC_CTRL_2_PWM_FREQUENCY_48_FS     7
61 #define MISC_CTRL_2_SDM_OSR                 BIT(2)
62 #define MISC_CTRL_2_SDM_OSR_MASK            BIT(2)
63 #define MISC_CTRL_2_OUTPUT_PHASE_MASK       BIT_MASK(2)
64 #define MISC_CTRL_2_OUTPUT_PHASE(val)       ((val) & MISC_CTRL_2_OUTPUT_PHASE_MASK)
65 #define MISC_CTRL_2_OUTPUT_PHASE_210_DEGREES 1
66 #define MISC_CTRL_2_OUTPUT_PHASE_225_DEGREES 2
67 #define MISC_CTRL_2_OUTPUT_PHASE_240_DEGREES 3
68 
69 /* Serial Audio-Port Control Register */
70 #define SAP_CTRL_ADDR 0x03
71 #define SAP_CTRL_INPUT_SAMPLING_RATE_MASK     (BIT_MASK(2) << 6)
72 #define SAP_CTRL_INPUT_SAMPLING_RATE(val)     (((val) << 6) & SAP_CTRL_INPUT_SAMPLING_RATE_MASK)
73 #define SAP_CTRL_INPUT_SAMPLING_RATE_44_1_KHZ 0
74 #define SAP_CTRL_INPUT_SAMPLING_RATE_48_KHZ   1
75 #define SAP_CTRL_INPUT_SAMPLING_RATE_96_KHZ   2
76 #define SAP_CTRL_TDM_SLOT_SELECT              BIT(5)
77 #define SAP_CTRL_TDM_SLOT_SELECT_MASK         BIT(5)
78 #define SAP_CTRL_TDM_SLOT_SIZE                BIT(4)
79 #define SAP_CTRL_TDM_SLOT_SIZE_MASK           BIT(4)
80 #define SAP_CTRL_TDM_SLOT_SELECT_2            BIT(3)
81 #define SAP_CTRL_TDM_SLOT_SELECT_2_MASK       BIT(3)
82 #define SAP_CTRL_INPUT_FORMAT_MASK            BIT_MASK(3)
83 #define SAP_CTRL_INPUT_FORMAT(val)            ((val) & SAP_CTRL_INPUT_FORMAT_MASK)
84 #define SAP_CTRL_INPUT_FORMAT_24_BITS_RIGHT   0
85 #define SAP_CTRL_INPUT_FORMAT_20_BITS_RIGHT   1
86 #define SAP_CTRL_INPUT_FORMAT_18_BITS_RIGHT   2
87 #define SAP_CTRL_INPUT_FORMAT_16_BITS_RIGHT   3
88 #define SAP_CTRL_INPUT_FORMAT_I2S             4
89 #define SAP_CTRL_INPUT_FORMAT_LEFT            5
90 #define SAP_CTRL_INPUT_FORMAT_DSP             6
91 
92 /* Channel State Control Register */
93 #define CH_STATE_CTRL_ADDR 0x04
94 #define CH_STATE_CTRL_CH1_STATE_CTRL_MASK (BIT_MASK(2) << 6)
95 #define CH_STATE_CTRL_CH1_STATE_CTRL(val) (((val) << 6) & CH_STATE_CTRL_CH1_STATE_CTRL_MASK)
96 #define CH_STATE_CTRL_CH2_STATE_CTRL_MASK (BIT_MASK(2) << 4)
97 #define CH_STATE_CTRL_CH2_STATE_CTRL(val) (((val) << 4) & CH_STATE_CTRL_CH2_STATE_CTRL_MASK)
98 #define CH_STATE_CTRL_PLAY                0
99 #define CH_STATE_CTRL_HIZ                 1
100 #define CH_STATE_CTRL_MUTE                2
101 #define CH_STATE_CTRL_DC_LOAD             3
102 
103 /* Channel 1 and 2 Volume Control Registers */
104 #define CH1_VOLUME_CTRL_ADDR 0x05
105 #define CH2_VOLUME_CTRL_ADDR 0x06
106 #define CH_VOLUME_CTRL_VOLUME_MASK BIT_MASK(8)
107 #define CH_VOLUME_CTRL_VOLUME(val) ((val) & CH_VOLUME_CTRL_VOLUME_MASK)
108 
109 /* DC Load Diagnostic Control 1 Register */
110 #define DC_LDG_CTRL_1_ADDR 0x09
111 #define DC_LDG_CTRL_1_ABORT              BIT(7)
112 #define DC_LDG_CTRL_1_ABORT_MASK         BIT(7)
113 #define DC_LDG_CTRL_1_DOUBLE_RAMP        BIT(6)
114 #define DC_LDG_CTRL_1_DOUBLE_RAMP_MASK   BIT(6)
115 #define DC_LDG_CTRL_1_DOUBLE_SETTLE      BIT(5)
116 #define DC_LDG_CTRL_1_DOUBLE_SETTLE_MASK BIT(5)
117 #define DC_LDG_CTRL_1_LO_ENABLE          BIT(1)
118 #define DC_LDG_CTRL_1_LO_ENABLE_MASK     BIT(1)
119 #define DC_LDG_CTRL_1_BYPASS             BIT(0)
120 #define DC_LDG_CTRL_1_BYPASS_MASK        BIT(0)
121 
122 /* DC Load Diagnostic Control 2 Register */
123 #define DC_LDG_CTRL_2_ADDR 0x0A
124 #define DC_LDG_CTRL_2_CH1_SL_MASK (BIT_MASK(4) << 4)
125 #define DC_LDG_CTRL_2_CH1_SL(val) (((val) << 4) & DC_LDG_CTRL_2_CH1_SL_MASK)
126 #define DC_LDG_CTRL_2_CH2_SL_MASK BIT_MASK(4)
127 #define DC_LDG_CTRL_2_CH2_SL(val) ((val) & DC_LDG_CTRL_2_CH2_SL_MASK)
128 
129 /* DC Load Diagnostics Report 1 */
130 #define DC_LDG_REPORT_1_ADDR 0x0C
131 #define DC_LDG_REPORT_1_CH1_S2G      BIT(7)
132 #define DC_LDG_REPORT_1_CH1_S2G_MASK BIT(7)
133 #define DC_LDG_REPORT_1_CH1_S2P      BIT(6)
134 #define DC_LDG_REPORT_1_CH1_S2P_MASK BIT(6)
135 #define DC_LDG_REPORT_1_CH1_OL       BIT(5)
136 #define DC_LDG_REPORT_1_CH1_OL_MASK  BIT(5)
137 #define DC_LDG_REPORT_1_CH1_SL       BIT(4)
138 #define DC_LDG_REPORT_1_CH1_SL_MASK  BIT(4)
139 #define DC_LDG_REPORT_1_CH2_S2G      BIT(3)
140 #define DC_LDG_REPORT_1_CH2_S2G_MASK BIT(3)
141 #define DC_LDG_REPORT_1_CH2_S2P      BIT(2)
142 #define DC_LDG_REPORT_1_CH2_S2P_MASK BIT(2)
143 #define DC_LDG_REPORT_1_CH2_OL       BIT(1)
144 #define DC_LDG_REPORT_1_CH2_OL_MASK  BIT(1)
145 #define DC_LDG_REPORT_1_CH2_SL       BIT(0)
146 #define DC_LDG_REPORT_1_CH2_SL_MASK  BIT(0)
147 
148 /* DC Load Diagnostics Report 3 */
149 #define DC_LDG_REPORT_3_ADDR 0x0E
150 #define DC_LDG_REPORT_3_CH1_LO      BIT(3)
151 #define DC_LDG_REPORT_3_CH1_LO_MASK BIT(3)
152 #define DC_LDG_REPORT_3_CH2_LO      BIT(2)
153 #define DC_LDG_REPORT_3_CH2_LO_MASK BIT(2)
154 
155 /* Channel Faults Register */
156 #define CH_FAULTS_ADDR 0x10
157 #define CH_FAULTS_CH1_OC      BIT(7)
158 #define CH_FAULTS_CH1_OC_MASK BIT(7)
159 #define CH_FAULTS_CH2_OC      BIT(6)
160 #define CH_FAULTS_CH2_OC_MASK BIT(6)
161 #define CH_FAULTS_CH1_DC      BIT(3)
162 #define CH_FAULTS_CH1_DC_MASK BIT(3)
163 #define CH_FAULTS_CH2_DC      BIT(2)
164 #define CH_FAULTS_CH2_DC_MASK BIT(2)
165 
166 /* Global Faults 1 Register */
167 #define GLOBAL_FAULTS_1_ADDR 0x11
168 #define GLOBAL_FAULTS_1_INVALID_CLOCK      BIT(4)
169 #define GLOBAL_FAULTS_1_INVALID_CLOCK_MASK BIT(4)
170 #define GLOBAL_FAULTS_1_PVDD_OV            BIT(3)
171 #define GLOBAL_FAULTS_1_PVDD_OV_MASK       BIT(3)
172 #define GLOBAL_FAULTS_1_VBAT_OV            BIT(2)
173 #define GLOBAL_FAULTS_1_VBAT_OV_MASK       BIT(2)
174 #define GLOBAL_FAULTS_1_PVDD_UV            BIT(1)
175 #define GLOBAL_FAULTS_1_PVDD_UV_MASK       BIT(1)
176 #define GLOBAL_FAULTS_1_VBAT_UV            BIT(0)
177 #define GLOBAL_FAULTS_1_VBAT_UV_MASK       BIT(0)
178 
179 /* Global Faults 2 Register */
180 #define GLOBAL_FAULTS_2_ADDR 0x12
181 #define GLOBAL_FAULTS_2_OTSD          BIT(4)
182 #define GLOBAL_FAULTS_2_OTSD_MASK     BIT(4)
183 #define GLOBAL_FAULTS_2_CH1_OTSD      BIT(3)
184 #define GLOBAL_FAULTS_2_CH1_OTSD_MASK BIT(3)
185 #define GLOBAL_FAULTS_2_CH2_OTSD      BIT(2)
186 #define GLOBAL_FAULTS_2_CH2_OTSD_MASK BIT(2)
187 
188 /* Warnings Register */
189 #define WARNINGS_ADDR 0x13
190 #define WARNINGS_VDD_POR      BIT(5)
191 #define WARNINGS_VDD_POR_MASK BIT(5)
192 #define WARNINGS_OTW          BIT(4)
193 #define WARNINGS_OTW_MASK     BIT(4)
194 #define WARNINGS_OTW_CH1      BIT(3)
195 #define WARNINGS_OTW_CH1_MASK BIT(3)
196 #define WARNINGS_OTW_CH2      BIT(2)
197 #define WARNINGS_OTW_CH2_MASK BIT(2)
198 
199 /* Pin Control Register */
200 #define PIN_CTRL_ADDR 0x14
201 #define PIN_CTRL_MASK_OC          BIT(7)
202 #define PIN_CTRL_MASK_OC_MASK     BIT(7)
203 #define PIN_CTRL_MASK_OTSD        BIT(6)
204 #define PIN_CTRL_MASK_OTSD_MASK   BIT(6)
205 #define PIN_CTRL_MASK_UV          BIT(5)
206 #define PIN_CTRL_MASK_UV_MASK     BIT(5)
207 #define PIN_CTRL_MASK_OV          BIT(4)
208 #define PIN_CTRL_MASK_OV_MASK     BIT(4)
209 #define PIN_CTRL_MASK_DC          BIT(3)
210 #define PIN_CTRL_MASK_DC_MASK     BIT(3)
211 #define PIN_CTRL_MASK_ILIMIT      BIT(2)
212 #define PIN_CTRL_MASK_ILIMIT_MASK BIT(2)
213 #define PIN_CTRL_MASK_CLIP        BIT(1)
214 #define PIN_CTRL_MASK_CLIP_MASK   BIT(1)
215 #define PIN_CTRL_MASK_OTW         BIT(0)
216 #define PIN_CTRL_MASK_OTW_MASK    BIT(0)
217 
218 /* Miscellaneous Control 3 Register */
219 #define MISC_CTRL_3_ADDR 0x21
220 #define MISC_CTRL_3_CLEAR_FAULT             BIT(7)
221 #define MISC_CTRL_3_CLEAR_FAULT_MASK        BIT(7)
222 #define MISC_CTRL_3_PBTL_CH_SEL             BIT(6)
223 #define MISC_CTRL_3_PBTL_CH_SEL_MASK        BIT(6)
224 #define MISC_CTRL_3_MASK_ILIMIT             BIT(5)
225 #define MISC_CTRL_3_MASK_ILIMIT_MASK        BIT(5)
226 #define MISC_CTRL_3_OTSD_AUTO_RECOVERY      BIT(3)
227 #define MISC_CTRL_3_OTSD_AUTO_RECOVERY_MASK BIT(3)
228 
229 /* ILIMIT Status Register */
230 #define ILIMIT_STATUS_ADDR 0x25
231 #define ILIMIT_STATUS_CH2_ILIMIT_WARN      BIT(1)
232 #define ILIMIT_STATUS_CH2_ILIMIT_WARN_MASK BIT(1)
233 #define ILIMIT_STATUS_CH1_ILIMIT_WARN      BIT(0)
234 #define ILIMIT_STATUS_CH1_ILIMIT_WARN_MASK BIT(0)
235 
236 /* Miscellaneous Control 4 Register */
237 #define MISC_CTRL_4_ADDR 0x26
238 #define MISC_CTRL_4_HPF_CORNER_MASK   BIT_MASK(3)
239 #define MISC_CTRL_4_HPF_CORNER(val)   ((val) & MISC_CTRL_4_HPF_CORNER_MASK)
240 #define MISC_CTRL_4_HPF_CORNER_3_7_HZ 0
241 #define MISC_CTRL_4_HPF_CORNER_7_4_HZ 1
242 #define MISC_CTRL_4_HPF_CORNER_15_HZ  2
243 #define MISC_CTRL_4_HPF_CORNER_30_HZ  3
244 #define MISC_CTRL_4_HPF_CORNER_59_HZ  4
245 #define MISC_CTRL_4_HPF_CORNER_118_HZ 5
246 #define MISC_CTRL_4_HPF_CORNER_235_HZ 6
247 #define MISC_CTRL_4_HPF_CORNER_463_HZ 7
248 
249 /* Miscellaneous Control 5 Register */
250 #define MISC_CTRL_5_ADDR 0x28
251 #define MISC_CTRL_5_SS_BW_SEL          BIT(7)
252 #define MISC_CTRL_5_SS_BW_SEL_MASK     BIT(7)
253 #define MISC_CTRL_5_SS_DIV2            BIT(6)
254 #define MISC_CTRL_5_SS_DIV2_MASK       BIT(6)
255 #define MISC_CTRL_5_PHASE_SEL_MSB      BIT(5)
256 #define MISC_CTRL_5_PHASE_SEL_MSB_MASK BIT(5)
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif /* ZEPHYR_DRIVERS_AUDIO_TAS6422DAC_H_ */
263