piSmasher Configuration Libraries
piSmasher peripheral device configuration libraries
tlv320aic3104.h
Go to the documentation of this file.
1 
46 #ifndef __TLV320AIC3104_H
47 #define __TLV320AIC3104_H
48 
49 #include <stdio.h>
50 #include <stdint.h>
51 
52 
53 #define AIC3X_ADDR (0x18U)
55 #define PAGE_REG_ADDR(__PAGE__, __ADDR__) ((((uint16_t)(__PAGE__)) << 8) | ((uint16_t)(__ADDR__) & 0x00FFU))
56 
57 #define AIC3X_SOFT_RESET (0x80U)
58 
59 /* Codec Datapath Setup Register - Page 0, Reg 7 */
60 #define DATAPATH_FREF_MASK (1 << 7)
61 
62 enum aic3x_fref {
63  DATAPATH_FREF_48kHz = 0x00,
64  DATAPATH_FREF_44_1kHz = 0x01
65 };
66 
67 #define DATAPATH_ADC_DUAL_RATE (1 << 6)
68 #define DATAPATH_DAC_DUAL_RATE (1 << 5)
69 
70 #define DATAPATH_RDAC_SHIFT (1)
71 #define DATAPATH_LDAC_SHIFT (3)
72 #define DATAPATH_CTRL_MASK (0x03U)
73 
74 enum aic3x_datapath_dac {
75  DATAPATH_RDAC = 0x01,
76  DATAPATH_LDAC = 0x03
77 };
78 
80  DATAPATH_MUTED = 0x00,
84 };
85 
86 /* Audio Serial Data Interface Control Register A - Page 0, Reg 8 */
87 #define ASD_IFA_MODE_SHIFT (6)
88 #define ASD_IFA_BCLK_MASTER (1 << 7)
89 #define ASD_IFA_WCLK_MASTER (1 << 6)
90 #define ASD_IFA_DOUT_HIZ (1 << 5)
91 
92 enum aic3x_asd_ifa_ctrl {
93  ASD_IFA_SLAVE = 0x00,
94  ASD_IFA_MASTER = 0x03
95 };
96 
97 
98 /* Audio Serial Data Interface Control Register B - Page 0, Reg 9 */
99 #define ASD_IFB_MODE_SHIFT (6)
100 #define ASD_IFB_MODE_MASK (0x03U << ASD_IFB_MODE_SHIFT)
101 
102 enum aic3x_asd_ifb_mode {
103  ASD_IFB_MODE_I2S = 0x00,
104  ASD_IFB_MODE_DSP = 0x01,
105  ASD_IFB_MODE_RJUST = 0x02,
106  ASD_IFB_MODE_LJUST = 0x03
107 };
108 
109 #define ASD_IFB_LEN_SHIFT (4)
110 #define ASD_IFB_LEN_MASK (0x03U << ASD_IFB_LEN_SHIFT)
111 
112 enum aic3x_asd_ifb_len {
113  ASD_IFB_LEN_16BIT = 0x00,
114  ASD_IFB_LEN_20BIT = 0x01,
115  ASD_IFB_LEN_24BIT = 0x02,
116  ASD_IFB_LEN_32BIT = 0x03
117 };
118 
120  enum aic3x_asd_ifa_ctrl mode;
121  enum aic3x_asd_ifb_mode xfer_mode;
122  enum aic3x_asd_ifb_len data_len;
123 };
124 
125 #define AIC3X_MICBIAS_LEVEL_SHIFT (6)
126 #define AIC3X_MICBIAS_LEVEL_MASK (0x03U << AIC3X_MICBIAS_LEVEL_SHIFT)
127 
128 #define INVERT_VOL(val) (0x7FU - val)
129 
130 /* Default output volume (inverted) */
131 #define AIC3X_DEFAULT_VOL INVERT_VOL(0x50)
132 
133 /* Default input volume (16dB) */
134 #define AIC3X_DEFAULT_GAIN (0x20U)
135 
136 /* Route bits */
137 #define AIC3X_ROUTE_ON (1 << 7)
138 
139 /* Mute bits */
140 #define AIC3X_UNMUTE (1 << 3)
141 #define AIC3X_MUTE_ON (1 << 7)
142 
143 #define AIC3X_POWER_ON (1 << 0)
144 
145 
146 /* MIC2/LINE2 to Right ADC Control Register - Page 0, Reg 18 */
147 #define MIC2LINE2_RADC_CTRL_MASK (0x0FU)
148 
152 };
153 
154 
155 /* DAC Power and Output Driver Control Register - Page 0, Reg 37 */
156 enum aic3x_dac_pwr_dac {
157  DAC_PWR_RDAC = 0x06,
158  DAC_PWR_LDAC = 0x07
159 };
160 
161 enum aic3x_input_ctrl_gain {
162  INPUT_CTRL_GAIN_0dB = 0x00,
163  INPUT_CTRL_GAIN_1_5dB = 0x01,
164  INPUT_CTRL_GAIN_3dB = 0x02,
165  INPUT_CTRL_GAIN_4_5dB = 0x03,
166  INPUT_CTRL_GAIN_6dB = 0x04,
167  INPUT_CTRL_GAIN_7_5dB = 0x05,
168  INPUT_CTRL_GAIN_9dB = 0x06,
169  INPUT_CTRL_GAIN_10_5dB = 0x07,
170  INPUT_CTRL_GAIN_12dB = 0x08,
171  INPUT_CTRL_ADC_DISCONNECT = 0x0F
172 };
173 
174 enum aic3x_rate_div {
175  AIC3X_DIV_FS_1 = 0x00,
176  AIC3X_DIV_FS_1_5 = 0x01,
177  AIC3X_DIV_FS_2 = 0x02,
178  AIC3X_DIV_FS_2_5 = 0x03,
179  AIC3X_DIV_FS_3 = 0x04,
180  AIC3X_DIV_FS_3_5 = 0x05,
181  AIC3X_DIV_FS_4 = 0x06,
182  AIC3X_DIV_FS_4_5 = 0x07,
183  AIC3X_DIV_FS_5 = 0x08,
184  AIC3X_DIV_FS_5_5 = 0x09,
185  AIC3X_DIV_FS_6 = 0x0A
186 };
187 
188 enum aic3x_micbias {
189  AIC3X_MICBIAS_OFF = 0x00,
190  AIC3X_MICBIAS_2V = 0x01,
191  AIC3X_MICBIAS_2V5 = 0x02,
192  AIC3X_MICBIAS_AVDD = 0x03,
193 };
194 
195 #define CLKGEN_CTRL_SOURCE_MASK (0x03U)
196 
197 enum aic3x_clkgen_ctrl {
198  CLKGEN_CTRL_PLLCLK_IN = 0x04,
199  CLKGEN_CTRL_CLKDIV_IN = 0x06
200 };
201 
202 enum aic3x_clkgen_ctrl_source {
203  CLKGEN_SOURCE_MCLK = 0x00,
204  CLKGEN_SOURCE_GPIO2 = 0x01,
205  CLKGEN_SOURCE_BCLK = 0x02
206 };
207 
208 enum aic3x_outroute {
209  AIC3X_LINE_OUT_STEREO,
210  AIC3X_HP_OUT_STEREO,
211 };
212 
213 enum aic3x_inroute {
214  AIC3X_LINE_IN_STEREO,
215  AIC3X_MIC_IN_MONO,
216 };
217 
218 struct aic3x_gain {
219  uint8_t ladc_pga;
220  uint8_t radc_pga;
221  uint8_t ldac_dvc;
222  uint8_t rdac_dvc;
223  uint8_t lpga_vol;
224  uint8_t rpga_vol;
225  uint8_t ldac_vol;
226  uint8_t rdac_vol;
227 };
228 
229 struct aic3x_cfg {
230  int id;
231  uint16_t sl_addr;
232  int (*i2c_write)(uint16_t addr, uint8_t reg, uint8_t *data);
233  int (*i2c_read)(uint16_t addr, uint8_t reg, uint8_t *data);
234  enum aic3x_outroute out_route;
235  enum aic3x_inroute in_route;
236  struct aic3x_gain *gains;
237 };
238 
239 
240 struct aic3x_dev {
241  struct aic3x_cfg *cfg;
242  uint8_t cur_page;
243 };
244 
245 int aic3x_init(struct aic3x_dev *codec, struct aic3x_cfg *cfg);
246 int aic3x_reset(struct aic3x_dev *codec);
247 int aic3x_configure_fref(struct aic3x_dev *codec, enum aic3x_fref fref);
248 int aic3x_configure_datapath(struct aic3x_dev *codec, enum aic3x_datapath_dac dac, enum aic3x_datapath_ctrl path);
249 int aic3x_set_sample_rate(struct aic3x_dev *codec, enum aic3x_rate_div adc_div, enum aic3x_rate_div dac_div);
250 int aic3x_enable_dac_pwr(struct aic3x_dev *codec, enum aic3x_dac_pwr_dac dac, unsigned char en);
251 
252 #endif /* __TLV320AIC3104_H */
uint8_t rdac_vol
Definition: tlv320aic3104.h:226
Definition: tlv320aic3104.h:81
uint8_t ladc_pga
Definition: tlv320aic3104.h:219
Definition: tlv320aic3104.h:151
enum aic3x_asd_ifb_mode xfer_mode
Definition: tlv320aic3104.h:121
Definition: tlv320aic3104.h:119
uint8_t lpga_vol
Definition: tlv320aic3104.h:223
uint8_t ldac_vol
Definition: tlv320aic3104.h:225
Definition: tlv320aic3104.h:82
aic3x_mic2line2_radc_ctrl
Definition: tlv320aic3104.h:149
uint8_t radc_pga
Definition: tlv320aic3104.h:220
Definition: tlv320aic3104.h:240
uint8_t rdac_dvc
Definition: tlv320aic3104.h:222
Definition: tlv320aic3104.h:80
Definition: tlv320aic3104.h:83
uint8_t rpga_vol
Definition: tlv320aic3104.h:224
uint8_t ldac_dvc
Definition: tlv320aic3104.h:221
Definition: tlv320aic3104.h:150
enum aic3x_asd_ifa_ctrl mode
Definition: tlv320aic3104.h:120
int aic3x_init(struct aic3x_dev *codec, struct aic3x_cfg *cfg)
Initialize AIC3x Codec.
Definition: tlv320aic3104.c:397
Definition: tlv320aic3104.h:218
aic3x_datapath_ctrl
Definition: tlv320aic3104.h:79
Definition: tlv320aic3104.h:229
enum aic3x_asd_ifb_len data_len
Definition: tlv320aic3104.h:122