xref: /openbmc/linux/sound/soc/codecs/pcm512x.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*1802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25a3af129SMark Brown /*
35a3af129SMark Brown  * Driver for the PCM512x CODECs
45a3af129SMark Brown  *
5da924c3aSMark Brown  * Author:	Mark Brown <broonie@kernel.org>
65a3af129SMark Brown  *		Copyright 2014 Linaro Ltd
75a3af129SMark Brown  */
85a3af129SMark Brown 
95a3af129SMark Brown #ifndef _SND_SOC_PCM512X
105a3af129SMark Brown #define _SND_SOC_PCM512X
115a3af129SMark Brown 
1222066226SMark Brown #include <linux/pm.h>
1322066226SMark Brown #include <linux/regmap.h>
1422066226SMark Brown 
15806d6466SMark Brown #define PCM512x_VIRT_BASE 0x100
16806d6466SMark Brown #define PCM512x_PAGE_LEN  0x100
17806d6466SMark Brown #define PCM512x_PAGE_BASE(n)  (PCM512x_VIRT_BASE + (PCM512x_PAGE_LEN * n))
185a3af129SMark Brown 
195a3af129SMark Brown #define PCM512x_PAGE              0
205a3af129SMark Brown 
21806d6466SMark Brown #define PCM512x_RESET             (PCM512x_PAGE_BASE(0) +   1)
22806d6466SMark Brown #define PCM512x_POWER             (PCM512x_PAGE_BASE(0) +   2)
23806d6466SMark Brown #define PCM512x_MUTE              (PCM512x_PAGE_BASE(0) +   3)
24806d6466SMark Brown #define PCM512x_PLL_EN            (PCM512x_PAGE_BASE(0) +   4)
25806d6466SMark Brown #define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_BASE(0) +   6)
26806d6466SMark Brown #define PCM512x_DSP               (PCM512x_PAGE_BASE(0) +   7)
27806d6466SMark Brown #define PCM512x_GPIO_EN           (PCM512x_PAGE_BASE(0) +   8)
28806d6466SMark Brown #define PCM512x_BCLK_LRCLK_CFG    (PCM512x_PAGE_BASE(0) +   9)
29806d6466SMark Brown #define PCM512x_DSP_GPIO_INPUT    (PCM512x_PAGE_BASE(0) +  10)
30806d6466SMark Brown #define PCM512x_MASTER_MODE       (PCM512x_PAGE_BASE(0) +  12)
31806d6466SMark Brown #define PCM512x_PLL_REF           (PCM512x_PAGE_BASE(0) +  13)
3281249307SPeter Rosin #define PCM512x_DAC_REF           (PCM512x_PAGE_BASE(0) +  14)
337c4e1119SPeter Rosin #define PCM512x_GPIO_DACIN        (PCM512x_PAGE_BASE(0) +  16)
34f086ba9dSPeter Rosin #define PCM512x_GPIO_PLLIN        (PCM512x_PAGE_BASE(0) +  18)
3581249307SPeter Rosin #define PCM512x_SYNCHRONIZE       (PCM512x_PAGE_BASE(0) +  19)
36806d6466SMark Brown #define PCM512x_PLL_COEFF_0       (PCM512x_PAGE_BASE(0) +  20)
37806d6466SMark Brown #define PCM512x_PLL_COEFF_1       (PCM512x_PAGE_BASE(0) +  21)
38806d6466SMark Brown #define PCM512x_PLL_COEFF_2       (PCM512x_PAGE_BASE(0) +  22)
39806d6466SMark Brown #define PCM512x_PLL_COEFF_3       (PCM512x_PAGE_BASE(0) +  23)
40806d6466SMark Brown #define PCM512x_PLL_COEFF_4       (PCM512x_PAGE_BASE(0) +  24)
41806d6466SMark Brown #define PCM512x_DSP_CLKDIV        (PCM512x_PAGE_BASE(0) +  27)
42806d6466SMark Brown #define PCM512x_DAC_CLKDIV        (PCM512x_PAGE_BASE(0) +  28)
43806d6466SMark Brown #define PCM512x_NCP_CLKDIV        (PCM512x_PAGE_BASE(0) +  29)
44806d6466SMark Brown #define PCM512x_OSR_CLKDIV        (PCM512x_PAGE_BASE(0) +  30)
45806d6466SMark Brown #define PCM512x_MASTER_CLKDIV_1   (PCM512x_PAGE_BASE(0) +  32)
46806d6466SMark Brown #define PCM512x_MASTER_CLKDIV_2   (PCM512x_PAGE_BASE(0) +  33)
47806d6466SMark Brown #define PCM512x_FS_SPEED_MODE     (PCM512x_PAGE_BASE(0) +  34)
48806d6466SMark Brown #define PCM512x_IDAC_1            (PCM512x_PAGE_BASE(0) +  35)
49806d6466SMark Brown #define PCM512x_IDAC_2            (PCM512x_PAGE_BASE(0) +  36)
50806d6466SMark Brown #define PCM512x_ERROR_DETECT      (PCM512x_PAGE_BASE(0) +  37)
51806d6466SMark Brown #define PCM512x_I2S_1             (PCM512x_PAGE_BASE(0) +  40)
52806d6466SMark Brown #define PCM512x_I2S_2             (PCM512x_PAGE_BASE(0) +  41)
53806d6466SMark Brown #define PCM512x_DAC_ROUTING       (PCM512x_PAGE_BASE(0) +  42)
54806d6466SMark Brown #define PCM512x_DSP_PROGRAM       (PCM512x_PAGE_BASE(0) +  43)
55806d6466SMark Brown #define PCM512x_CLKDET            (PCM512x_PAGE_BASE(0) +  44)
56806d6466SMark Brown #define PCM512x_AUTO_MUTE         (PCM512x_PAGE_BASE(0) +  59)
57806d6466SMark Brown #define PCM512x_DIGITAL_VOLUME_1  (PCM512x_PAGE_BASE(0) +  60)
58806d6466SMark Brown #define PCM512x_DIGITAL_VOLUME_2  (PCM512x_PAGE_BASE(0) +  61)
59806d6466SMark Brown #define PCM512x_DIGITAL_VOLUME_3  (PCM512x_PAGE_BASE(0) +  62)
60806d6466SMark Brown #define PCM512x_DIGITAL_MUTE_1    (PCM512x_PAGE_BASE(0) +  63)
61806d6466SMark Brown #define PCM512x_DIGITAL_MUTE_2    (PCM512x_PAGE_BASE(0) +  64)
62806d6466SMark Brown #define PCM512x_DIGITAL_MUTE_3    (PCM512x_PAGE_BASE(0) +  65)
63806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_1     (PCM512x_PAGE_BASE(0) +  80)
64806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_2     (PCM512x_PAGE_BASE(0) +  81)
65806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_3     (PCM512x_PAGE_BASE(0) +  82)
66806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_4     (PCM512x_PAGE_BASE(0) +  83)
67806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_5     (PCM512x_PAGE_BASE(0) +  84)
68806d6466SMark Brown #define PCM512x_GPIO_OUTPUT_6     (PCM512x_PAGE_BASE(0) +  85)
69806d6466SMark Brown #define PCM512x_GPIO_CONTROL_1    (PCM512x_PAGE_BASE(0) +  86)
70806d6466SMark Brown #define PCM512x_GPIO_CONTROL_2    (PCM512x_PAGE_BASE(0) +  87)
71806d6466SMark Brown #define PCM512x_OVERFLOW          (PCM512x_PAGE_BASE(0) +  90)
72806d6466SMark Brown #define PCM512x_RATE_DET_1        (PCM512x_PAGE_BASE(0) +  91)
73806d6466SMark Brown #define PCM512x_RATE_DET_2        (PCM512x_PAGE_BASE(0) +  92)
74806d6466SMark Brown #define PCM512x_RATE_DET_3        (PCM512x_PAGE_BASE(0) +  93)
75806d6466SMark Brown #define PCM512x_RATE_DET_4        (PCM512x_PAGE_BASE(0) +  94)
76f086ba9dSPeter Rosin #define PCM512x_CLOCK_STATUS      (PCM512x_PAGE_BASE(0) +  95)
77806d6466SMark Brown #define PCM512x_ANALOG_MUTE_DET   (PCM512x_PAGE_BASE(0) + 108)
78806d6466SMark Brown #define PCM512x_GPIN              (PCM512x_PAGE_BASE(0) + 119)
79806d6466SMark Brown #define PCM512x_DIGITAL_MUTE_DET  (PCM512x_PAGE_BASE(0) + 120)
805a3af129SMark Brown 
81806d6466SMark Brown #define PCM512x_OUTPUT_AMPLITUDE  (PCM512x_PAGE_BASE(1) +   1)
82806d6466SMark Brown #define PCM512x_ANALOG_GAIN_CTRL  (PCM512x_PAGE_BASE(1) +   2)
83806d6466SMark Brown #define PCM512x_UNDERVOLTAGE_PROT (PCM512x_PAGE_BASE(1) +   5)
84806d6466SMark Brown #define PCM512x_ANALOG_MUTE_CTRL  (PCM512x_PAGE_BASE(1) +   6)
85806d6466SMark Brown #define PCM512x_ANALOG_GAIN_BOOST (PCM512x_PAGE_BASE(1) +   7)
86806d6466SMark Brown #define PCM512x_VCOM_CTRL_1       (PCM512x_PAGE_BASE(1) +   8)
87806d6466SMark Brown #define PCM512x_VCOM_CTRL_2       (PCM512x_PAGE_BASE(1) +   9)
88806d6466SMark Brown 
89806d6466SMark Brown #define PCM512x_CRAM_CTRL         (PCM512x_PAGE_BASE(44) +  1)
90806d6466SMark Brown 
91f086ba9dSPeter Rosin #define PCM512x_FLEX_A            (PCM512x_PAGE_BASE(253) + 63)
92f086ba9dSPeter Rosin #define PCM512x_FLEX_B            (PCM512x_PAGE_BASE(253) + 64)
93f086ba9dSPeter Rosin 
94f086ba9dSPeter Rosin #define PCM512x_MAX_REGISTER      (PCM512x_PAGE_BASE(253) + 64)
955a3af129SMark Brown 
965a3af129SMark Brown /* Page 0, Register 1 - reset */
975a3af129SMark Brown #define PCM512x_RSTR (1 << 0)
985a3af129SMark Brown #define PCM512x_RSTM (1 << 4)
995a3af129SMark Brown 
1005a3af129SMark Brown /* Page 0, Register 2 - power */
1015a3af129SMark Brown #define PCM512x_RQPD       (1 << 0)
1025a3af129SMark Brown #define PCM512x_RQPD_SHIFT 0
1035a3af129SMark Brown #define PCM512x_RQST       (1 << 4)
1045a3af129SMark Brown #define PCM512x_RQST_SHIFT 4
1055a3af129SMark Brown 
1065a3af129SMark Brown /* Page 0, Register 3 - mute */
1073500f1c5SDimitris Papavasiliou #define PCM512x_RQMR (1 << 0)
1085a3af129SMark Brown #define PCM512x_RQMR_SHIFT 0
1093500f1c5SDimitris Papavasiliou #define PCM512x_RQML (1 << 4)
1105a3af129SMark Brown #define PCM512x_RQML_SHIFT 4
1115a3af129SMark Brown 
1125a3af129SMark Brown /* Page 0, Register 4 - PLL */
113376dc490SPeter Rosin #define PCM512x_PLLE       (1 << 0)
114376dc490SPeter Rosin #define PCM512x_PLLE_SHIFT 0
1155a3af129SMark Brown #define PCM512x_PLCK       (1 << 4)
1165a3af129SMark Brown #define PCM512x_PLCK_SHIFT 4
1175a3af129SMark Brown 
1185a3af129SMark Brown /* Page 0, Register 7 - DSP */
1195a3af129SMark Brown #define PCM512x_SDSL       (1 << 0)
1205a3af129SMark Brown #define PCM512x_SDSL_SHIFT 0
1215a3af129SMark Brown #define PCM512x_DEMP       (1 << 4)
1225a3af129SMark Brown #define PCM512x_DEMP_SHIFT 4
1235a3af129SMark Brown 
124f086ba9dSPeter Rosin /* Page 0, Register 8 - GPIO output enable */
125f086ba9dSPeter Rosin #define PCM512x_G1OE       (1 << 0)
126f086ba9dSPeter Rosin #define PCM512x_G2OE       (1 << 1)
127f086ba9dSPeter Rosin #define PCM512x_G3OE       (1 << 2)
128f086ba9dSPeter Rosin #define PCM512x_G4OE       (1 << 3)
129f086ba9dSPeter Rosin #define PCM512x_G5OE       (1 << 4)
130f086ba9dSPeter Rosin #define PCM512x_G6OE       (1 << 5)
131f086ba9dSPeter Rosin 
13281249307SPeter Rosin /* Page 0, Register 9 - BCK, LRCLK configuration */
13381249307SPeter Rosin #define PCM512x_LRKO       (1 << 0)
13481249307SPeter Rosin #define PCM512x_LRKO_SHIFT 0
13581249307SPeter Rosin #define PCM512x_BCKO       (1 << 4)
13681249307SPeter Rosin #define PCM512x_BCKO_SHIFT 4
13781249307SPeter Rosin #define PCM512x_BCKP       (1 << 5)
13881249307SPeter Rosin #define PCM512x_BCKP_SHIFT 5
13981249307SPeter Rosin 
14081249307SPeter Rosin /* Page 0, Register 12 - Master mode BCK, LRCLK reset */
14181249307SPeter Rosin #define PCM512x_RLRK       (1 << 0)
14281249307SPeter Rosin #define PCM512x_RLRK_SHIFT 0
14381249307SPeter Rosin #define PCM512x_RBCK       (1 << 1)
14481249307SPeter Rosin #define PCM512x_RBCK_SHIFT 1
14581249307SPeter Rosin 
1465a3af129SMark Brown /* Page 0, Register 13 - PLL reference */
14781249307SPeter Rosin #define PCM512x_SREF        (7 << 4)
14881249307SPeter Rosin #define PCM512x_SREF_SHIFT  4
14981249307SPeter Rosin #define PCM512x_SREF_SCK    (0 << 4)
15081249307SPeter Rosin #define PCM512x_SREF_BCK    (1 << 4)
15181249307SPeter Rosin #define PCM512x_SREF_GPIO   (3 << 4)
15281249307SPeter Rosin 
15381249307SPeter Rosin /* Page 0, Register 14 - DAC reference */
15481249307SPeter Rosin #define PCM512x_SDAC        (7 << 4)
15581249307SPeter Rosin #define PCM512x_SDAC_SHIFT  4
15681249307SPeter Rosin #define PCM512x_SDAC_MCK    (0 << 4)
15781249307SPeter Rosin #define PCM512x_SDAC_PLL    (1 << 4)
15881249307SPeter Rosin #define PCM512x_SDAC_SCK    (3 << 4)
15981249307SPeter Rosin #define PCM512x_SDAC_BCK    (4 << 4)
1607c4e1119SPeter Rosin #define PCM512x_SDAC_GPIO   (5 << 4)
16181249307SPeter Rosin 
1627c4e1119SPeter Rosin /* Page 0, Register 16, 18 - GPIO source for DAC, PLL */
163f086ba9dSPeter Rosin #define PCM512x_GREF        (7 << 0)
164f086ba9dSPeter Rosin #define PCM512x_GREF_SHIFT  0
165f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO1  (0 << 0)
166f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO2  (1 << 0)
167f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO3  (2 << 0)
168f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO4  (3 << 0)
169f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO5  (4 << 0)
170f086ba9dSPeter Rosin #define PCM512x_GREF_GPIO6  (5 << 0)
171f086ba9dSPeter Rosin 
17281249307SPeter Rosin /* Page 0, Register 19 - synchronize */
17381249307SPeter Rosin #define PCM512x_RQSY        (1 << 0)
17481249307SPeter Rosin #define PCM512x_RQSY_RESUME (0 << 0)
17581249307SPeter Rosin #define PCM512x_RQSY_HALT   (1 << 0)
17681249307SPeter Rosin 
17781249307SPeter Rosin /* Page 0, Register 34 - fs speed mode */
17881249307SPeter Rosin #define PCM512x_FSSP        (3 << 0)
17981249307SPeter Rosin #define PCM512x_FSSP_SHIFT  0
18081249307SPeter Rosin #define PCM512x_FSSP_48KHZ  (0 << 0)
18181249307SPeter Rosin #define PCM512x_FSSP_96KHZ  (1 << 0)
18281249307SPeter Rosin #define PCM512x_FSSP_192KHZ (2 << 0)
18381249307SPeter Rosin #define PCM512x_FSSP_384KHZ (3 << 0)
1845a3af129SMark Brown 
1855a3af129SMark Brown /* Page 0, Register 37 - Error detection */
1865a3af129SMark Brown #define PCM512x_IPLK (1 << 0)
1875a3af129SMark Brown #define PCM512x_DCAS (1 << 1)
1885a3af129SMark Brown #define PCM512x_IDCM (1 << 2)
1895a3af129SMark Brown #define PCM512x_IDCH (1 << 3)
1905a3af129SMark Brown #define PCM512x_IDSK (1 << 4)
1915a3af129SMark Brown #define PCM512x_IDBK (1 << 5)
1925a3af129SMark Brown #define PCM512x_IDFS (1 << 6)
1935a3af129SMark Brown 
19481249307SPeter Rosin /* Page 0, Register 40 - I2S configuration */
19581249307SPeter Rosin #define PCM512x_ALEN       (3 << 0)
19681249307SPeter Rosin #define PCM512x_ALEN_SHIFT 0
19781249307SPeter Rosin #define PCM512x_ALEN_16    (0 << 0)
19881249307SPeter Rosin #define PCM512x_ALEN_20    (1 << 0)
19981249307SPeter Rosin #define PCM512x_ALEN_24    (2 << 0)
20081249307SPeter Rosin #define PCM512x_ALEN_32    (3 << 0)
20181249307SPeter Rosin #define PCM512x_AFMT       (3 << 4)
20281249307SPeter Rosin #define PCM512x_AFMT_SHIFT 4
20381249307SPeter Rosin #define PCM512x_AFMT_I2S   (0 << 4)
20481249307SPeter Rosin #define PCM512x_AFMT_DSP   (1 << 4)
20581249307SPeter Rosin #define PCM512x_AFMT_RTJ   (2 << 4)
20681249307SPeter Rosin #define PCM512x_AFMT_LTJ   (3 << 4)
20781249307SPeter Rosin 
2085a3af129SMark Brown /* Page 0, Register 42 - DAC routing */
2095a3af129SMark Brown #define PCM512x_AUPR_SHIFT 0
2105a3af129SMark Brown #define PCM512x_AUPL_SHIFT 4
2115a3af129SMark Brown 
2125a3af129SMark Brown /* Page 0, Register 59 - auto mute */
2135a3af129SMark Brown #define PCM512x_ATMR_SHIFT 0
2145a3af129SMark Brown #define PCM512x_ATML_SHIFT 4
2155a3af129SMark Brown 
2165a3af129SMark Brown /* Page 0, Register 63 - ramp rates */
2175a3af129SMark Brown #define PCM512x_VNDF_SHIFT 6
2185a3af129SMark Brown #define PCM512x_VNDS_SHIFT 4
2195a3af129SMark Brown #define PCM512x_VNUF_SHIFT 2
2205a3af129SMark Brown #define PCM512x_VNUS_SHIFT 0
2215a3af129SMark Brown 
2225a3af129SMark Brown /* Page 0, Register 64 - emergency ramp rates */
2235a3af129SMark Brown #define PCM512x_VEDF_SHIFT 6
2245a3af129SMark Brown #define PCM512x_VEDS_SHIFT 4
2255a3af129SMark Brown 
2265a3af129SMark Brown /* Page 0, Register 65 - Digital mute enables */
2275a3af129SMark Brown #define PCM512x_ACTL_SHIFT 2
2285a3af129SMark Brown #define PCM512x_AMLE_SHIFT 1
229376dc490SPeter Rosin #define PCM512x_AMRE_SHIFT 0
2305a3af129SMark Brown 
231f086ba9dSPeter Rosin /* Page 0, Register 80-85, GPIO output selection */
232f086ba9dSPeter Rosin #define PCM512x_GxSL       (31 << 0)
233f086ba9dSPeter Rosin #define PCM512x_GxSL_SHIFT 0
234f086ba9dSPeter Rosin #define PCM512x_GxSL_OFF   (0 << 0)
235f086ba9dSPeter Rosin #define PCM512x_GxSL_DSP   (1 << 0)
236f086ba9dSPeter Rosin #define PCM512x_GxSL_REG   (2 << 0)
237f086ba9dSPeter Rosin #define PCM512x_GxSL_AMUTB (3 << 0)
238f086ba9dSPeter Rosin #define PCM512x_GxSL_AMUTL (4 << 0)
239f086ba9dSPeter Rosin #define PCM512x_GxSL_AMUTR (5 << 0)
240f086ba9dSPeter Rosin #define PCM512x_GxSL_CLKI  (6 << 0)
241f086ba9dSPeter Rosin #define PCM512x_GxSL_SDOUT (7 << 0)
242f086ba9dSPeter Rosin #define PCM512x_GxSL_ANMUL (8 << 0)
243f086ba9dSPeter Rosin #define PCM512x_GxSL_ANMUR (9 << 0)
244f086ba9dSPeter Rosin #define PCM512x_GxSL_PLLLK (10 << 0)
245f086ba9dSPeter Rosin #define PCM512x_GxSL_CPCLK (11 << 0)
246f086ba9dSPeter Rosin #define PCM512x_GxSL_UV0_7 (14 << 0)
247f086ba9dSPeter Rosin #define PCM512x_GxSL_UV0_3 (15 << 0)
248f086ba9dSPeter Rosin #define PCM512x_GxSL_PLLCK (16 << 0)
249f086ba9dSPeter Rosin 
2505be2fc20SMark Brown /* Page 1, Register 2 - analog volume control */
2515be2fc20SMark Brown #define PCM512x_RAGN_SHIFT 0
2525be2fc20SMark Brown #define PCM512x_LAGN_SHIFT 4
2535be2fc20SMark Brown 
2545be2fc20SMark Brown /* Page 1, Register 7 - analog boost control */
2555be2fc20SMark Brown #define PCM512x_AGBR_SHIFT 0
2565be2fc20SMark Brown #define PCM512x_AGBL_SHIFT 4
2575be2fc20SMark Brown 
25822066226SMark Brown extern const struct dev_pm_ops pcm512x_pm_ops;
25922066226SMark Brown extern const struct regmap_config pcm512x_regmap;
26022066226SMark Brown 
26122066226SMark Brown int pcm512x_probe(struct device *dev, struct regmap *regmap);
26222066226SMark Brown void pcm512x_remove(struct device *dev);
26322066226SMark Brown 
2645a3af129SMark Brown #endif
265