xref: /linux/sound/soc/codecs/es8311.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1*baf98991SMatteo Martelli /* SPDX-License-Identifier: GPL-2.0-only */
2*baf98991SMatteo Martelli /*
3*baf98991SMatteo Martelli  * es8311.c -- es8311 ALSA SoC audio driver
4*baf98991SMatteo Martelli  *
5*baf98991SMatteo Martelli  * Copyright (C) 2024 Matteo Martelli <matteomartelli3@gmail.com>
6*baf98991SMatteo Martelli  *
7*baf98991SMatteo Martelli  * Author: Matteo Martelli <matteomartelli3@gmail.com>
8*baf98991SMatteo Martelli  */
9*baf98991SMatteo Martelli 
10*baf98991SMatteo Martelli #ifndef _ES8311_H
11*baf98991SMatteo Martelli #define _ES8311_H
12*baf98991SMatteo Martelli 
13*baf98991SMatteo Martelli #include <linux/bitops.h>
14*baf98991SMatteo Martelli 
15*baf98991SMatteo Martelli #define ES8311_RESET 0x00
16*baf98991SMatteo Martelli #define ES8311_RESET_CSM_ON BIT(7)
17*baf98991SMatteo Martelli #define ES8311_RESET_MSC BIT(6)
18*baf98991SMatteo Martelli #define ES8311_RESET_RST_MASK GENMASK(4, 0)
19*baf98991SMatteo Martelli 
20*baf98991SMatteo Martelli /* Clock Manager Registers */
21*baf98991SMatteo Martelli #define ES8311_CLKMGR1 0x01
22*baf98991SMatteo Martelli #define ES8311_CLKMGR1_MCLK_SEL BIT(7)
23*baf98991SMatteo Martelli #define ES8311_CLKMGR1_MCLK_ON BIT(5)
24*baf98991SMatteo Martelli #define ES8311_CLKMGR1_BCLK_ON BIT(4)
25*baf98991SMatteo Martelli #define ES8311_CLKMGR1_CLKADC_ON_SHIFT 3
26*baf98991SMatteo Martelli #define ES8311_CLKMGR1_CLKDAC_ON_SHIFT 2
27*baf98991SMatteo Martelli #define ES8311_CLKMGR1_ANACLKADC_ON_SHIFT 1
28*baf98991SMatteo Martelli #define ES8311_CLKMGR1_ANACLKDAC_ON_SHIFT 0
29*baf98991SMatteo Martelli #define ES8311_CLKMGR2 0x02
30*baf98991SMatteo Martelli #define ES8311_CLKMGR2_DIV_PRE_MASK GENMASK(7, 5)
31*baf98991SMatteo Martelli #define ES8311_CLKMGR2_DIV_PRE_SHIFT 5
32*baf98991SMatteo Martelli #define ES8311_CLKMGR2_DIV_PRE_MAX 0x07
33*baf98991SMatteo Martelli #define ES8311_CLKMGR2_MULT_PRE_MASK GENMASK(4, 3)
34*baf98991SMatteo Martelli #define ES8311_CLKMGR2_MULT_PRE_SHIFT 3
35*baf98991SMatteo Martelli #define ES8311_CLKMGR3 0x03
36*baf98991SMatteo Martelli #define ES8311_CLKMGR4 0x04
37*baf98991SMatteo Martelli #define ES8311_CLKMGR5 0x05
38*baf98991SMatteo Martelli #define ES8311_CLKMGR5_ADC_DIV_MASK GENMASK(7, 4)
39*baf98991SMatteo Martelli #define ES8311_CLKMGR5_ADC_DIV_SHIFT 4
40*baf98991SMatteo Martelli #define ES8311_CLKMGR5_DAC_DIV_MASK GENMASK(3, 0)
41*baf98991SMatteo Martelli #define ES8311_CLKMGR5_DAC_DIV_SHIFT 0
42*baf98991SMatteo Martelli #define ES8311_CLKMGR6 0x06
43*baf98991SMatteo Martelli #define ES8311_CLKMGR6_BCLK_INV BIT(5)
44*baf98991SMatteo Martelli #define ES8311_CLKMGR6_DIV_BCLK_MASK GENMASK(4, 0)
45*baf98991SMatteo Martelli #define ES8311_CLKMGR7 0x07
46*baf98991SMatteo Martelli #define ES8311_CLKMGR7_LRCLK_DIV_H_MASK GENMASK(3, 0)
47*baf98991SMatteo Martelli #define ES8311_CLKMGR8 0x08
48*baf98991SMatteo Martelli #define ES8311_CLKMGR_LRCLK_DIV_MAX 0x0FFF
49*baf98991SMatteo Martelli 
50*baf98991SMatteo Martelli /* SDP Mode Registers */
51*baf98991SMatteo Martelli #define ES8311_SDP_IN 0x09
52*baf98991SMatteo Martelli #define ES8311_SDP_IN_SEL_SHIFT 7
53*baf98991SMatteo Martelli #define ES8311_SDP_OUT 0x0A
54*baf98991SMatteo Martelli /* Following values are the same for both SPD_IN and SDP_OUT */
55*baf98991SMatteo Martelli #define ES8311_SDP_MUTE_SHIFT 6
56*baf98991SMatteo Martelli #define ES8311_SDP_LRP BIT(5)
57*baf98991SMatteo Martelli #define ES8311_SDP_WL_MASK GENMASK(4, 2)
58*baf98991SMatteo Martelli #define ES8311_SDP_WL_SHIFT 2
59*baf98991SMatteo Martelli #define ES8311_SDP_WL_24 0x00
60*baf98991SMatteo Martelli #define ES8311_SDP_WL_20 0x01
61*baf98991SMatteo Martelli #define ES8311_SDP_WL_18 0x02
62*baf98991SMatteo Martelli #define ES8311_SDP_WL_16 0x03
63*baf98991SMatteo Martelli #define ES8311_SDP_WL_32 0x04
64*baf98991SMatteo Martelli #define ES8311_SDP_FMT_MASK GENMASK(1, 0)
65*baf98991SMatteo Martelli #define ES8311_SDP_FMT_I2S 0x00
66*baf98991SMatteo Martelli #define ES8311_SDP_FMT_LEFT_J 0x01
67*baf98991SMatteo Martelli #define ES8311_SDP_FMT_DSP 0x03
68*baf98991SMatteo Martelli 
69*baf98991SMatteo Martelli /* System registers */
70*baf98991SMatteo Martelli #define ES8311_SYS1 0x0B
71*baf98991SMatteo Martelli #define ES8311_SYS2 0x0C
72*baf98991SMatteo Martelli #define ES8311_SYS3 0x0D
73*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_ANA_SHIFT 7
74*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_IBIASGEN_SHIFT 6
75*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_ADCBIASGEN_SHIFT 5
76*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_ADCVREFGEN_SHIFT 4
77*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_DACVREFGEN_SHIFT 3
78*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VREF_SHIFT 2
79*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VMIDSEL_MASK GENMASK(1, 0)
80*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VMIDSEL_POWER_DOWN 0
81*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VMIDSEL_STARTUP_NORMAL_SPEED 1
82*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VMIDSEL_NORMAL_OPERATION 2
83*baf98991SMatteo Martelli #define ES8311_SYS3_PDN_VMIDSEL_STARTUP_FAST_SPEED 3
84*baf98991SMatteo Martelli #define ES8311_SYS4 0x0E
85*baf98991SMatteo Martelli #define ES8311_SYS4_PDN_PGA_SHIFT 6
86*baf98991SMatteo Martelli #define ES8311_SYS4_PDN_MOD_SHIFT 5
87*baf98991SMatteo Martelli #define ES8311_SYS5 0x0F
88*baf98991SMatteo Martelli #define ES8311_SYS6 0x10
89*baf98991SMatteo Martelli #define ES8311_SYS7 0x11
90*baf98991SMatteo Martelli #define ES8311_SYS8 0x12
91*baf98991SMatteo Martelli #define ES8311_SYS8_PDN_DAC_SHIFT 1
92*baf98991SMatteo Martelli #define ES8311_SYS9 0x13
93*baf98991SMatteo Martelli #define ES8311_SYS9_HPSW_SHIFT 4
94*baf98991SMatteo Martelli #define ES8311_SYS10 0x14
95*baf98991SMatteo Martelli #define ES8311_SYS10_DMIC_ON_SHIFT 6
96*baf98991SMatteo Martelli #define ES8311_SYS10_LINESEL_SHIFT 4
97*baf98991SMatteo Martelli #define ES8311_SYS10_PGAGAIN_SHIFT 0
98*baf98991SMatteo Martelli #define ES8311_SYS10_PGAGAIN_MAX 0x0A
99*baf98991SMatteo Martelli 
100*baf98991SMatteo Martelli /* ADC Registers*/
101*baf98991SMatteo Martelli #define ES8311_ADC1 0x15
102*baf98991SMatteo Martelli #define ES8311_ADC1_RAMPRATE_SHIFT 4
103*baf98991SMatteo Martelli #define ES8311_ADC2 0x16
104*baf98991SMatteo Martelli #define ES8311_ADC2_INV_SHIFT 4
105*baf98991SMatteo Martelli #define ES8311_ADC2_SCALE_SHIFT 0
106*baf98991SMatteo Martelli #define ES8311_ADC2_SCALE_MAX 0x07
107*baf98991SMatteo Martelli #define ES8311_ADC3 0x17
108*baf98991SMatteo Martelli #define ES8311_ADC3_VOLUME_SHIFT 0
109*baf98991SMatteo Martelli #define ES8311_ADC3_VOLUME_MAX 0xFF
110*baf98991SMatteo Martelli #define ES8311_ADC4 0x18
111*baf98991SMatteo Martelli #define ES8311_ADC4_ALC_EN_SHIFT 7
112*baf98991SMatteo Martelli #define ES8311_ADC4_AUTOMUTE_EN_SHIFT 6
113*baf98991SMatteo Martelli #define ES8311_ADC4_ALC_WINSIZE_SHIFT 0
114*baf98991SMatteo Martelli #define ES8311_ADC5 0x19
115*baf98991SMatteo Martelli #define ES8311_ADC5_ALC_MAXLEVEL_SHIFT 4
116*baf98991SMatteo Martelli #define ES8311_ADC5_ALC_MAXLEVEL_MAX 0x0F
117*baf98991SMatteo Martelli #define ES8311_ADC5_ALC_MINLEVEL_SHIFT 0
118*baf98991SMatteo Martelli #define ES8311_ADC5_ALC_MINLEVEL_MAX 0x0F
119*baf98991SMatteo Martelli #define ES8311_ADC6 0x1A
120*baf98991SMatteo Martelli #define ES8311_ADC6_AUTOMUTE_WS_SHIFT 4
121*baf98991SMatteo Martelli #define ES8311_ADC6_AUTOMUTE_NG_SHIFT 0
122*baf98991SMatteo Martelli #define ES8311_ADC6_AUTOMUTE_NG_MAX 0x0F
123*baf98991SMatteo Martelli 
124*baf98991SMatteo Martelli #define ES8311_ADC7 0x1B
125*baf98991SMatteo Martelli #define ES8311_ADC7_AUTOMUTE_VOL_SHIFT 5
126*baf98991SMatteo Martelli #define ES8311_ADC7_AUTOMUTE_VOL_MAX 0x07
127*baf98991SMatteo Martelli #define ES8311_ADC8 0x1C
128*baf98991SMatteo Martelli #define ES8311_ADC8_EQBYPASS_SHIFT 6
129*baf98991SMatteo Martelli #define ES8311_ADC8_HPF_SHIFT 5
130*baf98991SMatteo Martelli 
131*baf98991SMatteo Martelli /* DAC Registers */
132*baf98991SMatteo Martelli #define ES8311_DAC1 0x31
133*baf98991SMatteo Martelli #define ES8311_DAC1_DAC_DSMMUTE BIT(6)
134*baf98991SMatteo Martelli #define ES8311_DAC1_DAC_DEMMUTE BIT(5)
135*baf98991SMatteo Martelli #define ES8311_DAC2 0x32
136*baf98991SMatteo Martelli #define ES8311_DAC2_VOLUME_MAX 0xFF
137*baf98991SMatteo Martelli #define ES8311_DAC3 0x33
138*baf98991SMatteo Martelli #define ES8311_DAC4 0x34
139*baf98991SMatteo Martelli #define ES8311_DAC4_DRC_EN_SHIFT 7
140*baf98991SMatteo Martelli #define ES8311_DAC4_DRC_WINSIZE_SHIFT 0
141*baf98991SMatteo Martelli #define ES8311_DAC5 0x35
142*baf98991SMatteo Martelli #define ES8311_DAC5_DRC_MAXLEVEL_SHIFT 4
143*baf98991SMatteo Martelli #define ES8311_DAC5_DRC_MAXLEVEL_MAX 0x0F
144*baf98991SMatteo Martelli #define ES8311_DAC5_DRC_MINLEVEL_SHIFT 0
145*baf98991SMatteo Martelli #define ES8311_DAC5_DRC_MINLEVEL_MAX 0x0F
146*baf98991SMatteo Martelli #define ES8311_DAC6 0x37
147*baf98991SMatteo Martelli #define ES8311_DAC6_RAMPRATE_SHIFT 4
148*baf98991SMatteo Martelli #define ES8311_DAC6_EQBYPASS_SHIFT 3
149*baf98991SMatteo Martelli 
150*baf98991SMatteo Martelli /* GPIO Registers */
151*baf98991SMatteo Martelli #define ES8311_GPIO 0x44
152*baf98991SMatteo Martelli #define ES8311_GPIO_ADC2DAC_SEL_SHIFT 7
153*baf98991SMatteo Martelli #define ES8311_GPIO_ADCDAT_SEL_SHIFT 4
154*baf98991SMatteo Martelli 
155*baf98991SMatteo Martelli /* Chip Info Registers */
156*baf98991SMatteo Martelli #define ES8311_CHIPID1 0xFD /* 0x83 */
157*baf98991SMatteo Martelli #define ES8311_CHIPID2 0xFE /* 0x11 */
158*baf98991SMatteo Martelli #define ES8311_CHIPVER 0xFF
159*baf98991SMatteo Martelli 
160*baf98991SMatteo Martelli #define ES8311_REG_MAX 0xFF
161*baf98991SMatteo Martelli 
162*baf98991SMatteo Martelli #endif
163