Kuninori Morimoto | c0ca560 | 2018-07-30 07:52:46 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // DA7210 ALSA Soc codec driver |
| 4 | // |
| 5 | // Copyright (c) 2009 Dialog Semiconductor |
| 6 | // Written by David Chen <Dajun.chen@diasemi.com> |
| 7 | // |
| 8 | // Copyright (C) 2009 Renesas Solutions Corp. |
| 9 | // Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com> |
| 10 | // |
| 11 | // Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 12 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 13 | #include <linux/delay.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 14 | #include <linux/i2c.h> |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 15 | #include <linux/spi/spi.h> |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 16 | #include <linux/regmap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 18 | #include <linux/module.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 19 | #include <sound/pcm.h> |
| 20 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 21 | #include <sound/soc.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 22 | #include <sound/initval.h> |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 23 | #include <sound/tlv.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 24 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 25 | /* DA7210 register space */ |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 26 | #define DA7210_PAGE_CONTROL 0x00 |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 27 | #define DA7210_CONTROL 0x01 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 28 | #define DA7210_STATUS 0x02 |
| 29 | #define DA7210_STARTUP1 0x03 |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 30 | #define DA7210_STARTUP2 0x04 |
| 31 | #define DA7210_STARTUP3 0x05 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 32 | #define DA7210_MIC_L 0x07 |
| 33 | #define DA7210_MIC_R 0x08 |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 34 | #define DA7210_AUX1_L 0x09 |
| 35 | #define DA7210_AUX1_R 0x0A |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 36 | #define DA7210_AUX2 0x0B |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 37 | #define DA7210_IN_GAIN 0x0C |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 38 | #define DA7210_INMIX_L 0x0D |
| 39 | #define DA7210_INMIX_R 0x0E |
| 40 | #define DA7210_ADC_HPF 0x0F |
| 41 | #define DA7210_ADC 0x10 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 42 | #define DA7210_ADC_EQ1_2 0X11 |
| 43 | #define DA7210_ADC_EQ3_4 0x12 |
| 44 | #define DA7210_ADC_EQ5 0x13 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 45 | #define DA7210_DAC_HPF 0x14 |
| 46 | #define DA7210_DAC_L 0x15 |
| 47 | #define DA7210_DAC_R 0x16 |
| 48 | #define DA7210_DAC_SEL 0x17 |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 49 | #define DA7210_SOFTMUTE 0x18 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 50 | #define DA7210_DAC_EQ1_2 0x19 |
| 51 | #define DA7210_DAC_EQ3_4 0x1A |
| 52 | #define DA7210_DAC_EQ5 0x1B |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 53 | #define DA7210_OUTMIX_L 0x1C |
| 54 | #define DA7210_OUTMIX_R 0x1D |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 55 | #define DA7210_OUT1_L 0x1E |
| 56 | #define DA7210_OUT1_R 0x1F |
| 57 | #define DA7210_OUT2 0x20 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 58 | #define DA7210_HP_L_VOL 0x21 |
| 59 | #define DA7210_HP_R_VOL 0x22 |
| 60 | #define DA7210_HP_CFG 0x23 |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 61 | #define DA7210_ZERO_CROSS 0x24 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 62 | #define DA7210_DAI_SRC_SEL 0x25 |
| 63 | #define DA7210_DAI_CFG1 0x26 |
| 64 | #define DA7210_DAI_CFG3 0x28 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 65 | #define DA7210_PLL_DIV1 0x29 |
| 66 | #define DA7210_PLL_DIV2 0x2A |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 67 | #define DA7210_PLL_DIV3 0x2B |
| 68 | #define DA7210_PLL 0x2C |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 69 | #define DA7210_ALC_MAX 0x83 |
| 70 | #define DA7210_ALC_MIN 0x84 |
| 71 | #define DA7210_ALC_NOIS 0x85 |
| 72 | #define DA7210_ALC_ATT 0x86 |
| 73 | #define DA7210_ALC_REL 0x87 |
| 74 | #define DA7210_ALC_DEL 0x88 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 75 | #define DA7210_A_HID_UNLOCK 0x8A |
| 76 | #define DA7210_A_TEST_UNLOCK 0x8B |
| 77 | #define DA7210_A_PLL1 0x90 |
| 78 | #define DA7210_A_CP_MODE 0xA7 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 79 | |
| 80 | /* STARTUP1 bit fields */ |
| 81 | #define DA7210_SC_MST_EN (1 << 0) |
| 82 | |
| 83 | /* MIC_L bit fields */ |
| 84 | #define DA7210_MICBIAS_EN (1 << 6) |
| 85 | #define DA7210_MIC_L_EN (1 << 7) |
| 86 | |
| 87 | /* MIC_R bit fields */ |
| 88 | #define DA7210_MIC_R_EN (1 << 7) |
| 89 | |
| 90 | /* INMIX_L bit fields */ |
| 91 | #define DA7210_IN_L_EN (1 << 7) |
| 92 | |
| 93 | /* INMIX_R bit fields */ |
| 94 | #define DA7210_IN_R_EN (1 << 7) |
| 95 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 96 | /* ADC bit fields */ |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 97 | #define DA7210_ADC_ALC_EN (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 98 | #define DA7210_ADC_L_EN (1 << 3) |
| 99 | #define DA7210_ADC_R_EN (1 << 7) |
| 100 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 101 | /* DAC/ADC HPF fields */ |
| 102 | #define DA7210_VOICE_F0_MASK (0x7 << 4) |
| 103 | #define DA7210_VOICE_F0_25 (1 << 4) |
| 104 | #define DA7210_VOICE_EN (1 << 7) |
Mark Brown | c215143 | 2009-12-16 20:36:37 +0000 | [diff] [blame] | 105 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 106 | /* DAC_SEL bit fields */ |
| 107 | #define DA7210_DAC_L_SRC_DAI_L (4 << 0) |
| 108 | #define DA7210_DAC_L_EN (1 << 3) |
| 109 | #define DA7210_DAC_R_SRC_DAI_R (5 << 4) |
| 110 | #define DA7210_DAC_R_EN (1 << 7) |
| 111 | |
| 112 | /* OUTMIX_L bit fields */ |
| 113 | #define DA7210_OUT_L_EN (1 << 7) |
| 114 | |
| 115 | /* OUTMIX_R bit fields */ |
| 116 | #define DA7210_OUT_R_EN (1 << 7) |
| 117 | |
| 118 | /* HP_CFG bit fields */ |
| 119 | #define DA7210_HP_2CAP_MODE (1 << 1) |
| 120 | #define DA7210_HP_SENSE_EN (1 << 2) |
| 121 | #define DA7210_HP_L_EN (1 << 3) |
| 122 | #define DA7210_HP_MODE (1 << 6) |
| 123 | #define DA7210_HP_R_EN (1 << 7) |
| 124 | |
| 125 | /* DAI_SRC_SEL bit fields */ |
| 126 | #define DA7210_DAI_OUT_L_SRC (6 << 0) |
| 127 | #define DA7210_DAI_OUT_R_SRC (7 << 4) |
| 128 | |
| 129 | /* DAI_CFG1 bit fields */ |
| 130 | #define DA7210_DAI_WORD_S16_LE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 131 | #define DA7210_DAI_WORD_S20_3LE (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 132 | #define DA7210_DAI_WORD_S24_LE (2 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 133 | #define DA7210_DAI_WORD_S32_LE (3 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 134 | #define DA7210_DAI_FLEN_64BIT (1 << 2) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 135 | #define DA7210_DAI_MODE_SLAVE (0 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 136 | #define DA7210_DAI_MODE_MASTER (1 << 7) |
| 137 | |
| 138 | /* DAI_CFG3 bit fields */ |
| 139 | #define DA7210_DAI_FORMAT_I2SMODE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 140 | #define DA7210_DAI_FORMAT_LEFT_J (1 << 0) |
| 141 | #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 142 | #define DA7210_DAI_OE (1 << 3) |
| 143 | #define DA7210_DAI_EN (1 << 7) |
| 144 | |
| 145 | /*PLL_DIV3 bit fields */ |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 146 | #define DA7210_PLL_DIV_L_MASK (0xF << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 147 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) |
| 148 | #define DA7210_PLL_BYP (1 << 6) |
| 149 | |
| 150 | /* PLL bit fields */ |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 151 | #define DA7210_PLL_FS_MASK (0xF << 0) |
| 152 | #define DA7210_PLL_FS_8000 (0x1 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 153 | #define DA7210_PLL_FS_11025 (0x2 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 154 | #define DA7210_PLL_FS_12000 (0x3 << 0) |
| 155 | #define DA7210_PLL_FS_16000 (0x5 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 156 | #define DA7210_PLL_FS_22050 (0x6 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 157 | #define DA7210_PLL_FS_24000 (0x7 << 0) |
| 158 | #define DA7210_PLL_FS_32000 (0x9 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 159 | #define DA7210_PLL_FS_44100 (0xA << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 160 | #define DA7210_PLL_FS_48000 (0xB << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 161 | #define DA7210_PLL_FS_88200 (0xE << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 162 | #define DA7210_PLL_FS_96000 (0xF << 0) |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 163 | #define DA7210_MCLK_DET_EN (0x1 << 5) |
| 164 | #define DA7210_MCLK_SRM_EN (0x1 << 6) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 165 | #define DA7210_PLL_EN (0x1 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 166 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 167 | /* SOFTMUTE bit fields */ |
| 168 | #define DA7210_RAMP_EN (1 << 6) |
| 169 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 170 | /* CONTROL bit fields */ |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 171 | #define DA7210_REG_EN (1 << 0) |
| 172 | #define DA7210_BIAS_EN (1 << 2) |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 173 | #define DA7210_NOISE_SUP_EN (1 << 3) |
| 174 | |
| 175 | /* IN_GAIN bit fields */ |
| 176 | #define DA7210_INPGA_L_VOL (0x0F << 0) |
| 177 | #define DA7210_INPGA_R_VOL (0xF0 << 0) |
| 178 | |
| 179 | /* ZERO_CROSS bit fields */ |
| 180 | #define DA7210_AUX1_L_ZC (1 << 0) |
| 181 | #define DA7210_AUX1_R_ZC (1 << 1) |
| 182 | #define DA7210_HP_L_ZC (1 << 6) |
| 183 | #define DA7210_HP_R_ZC (1 << 7) |
| 184 | |
| 185 | /* AUX1_L bit fields */ |
| 186 | #define DA7210_AUX1_L_VOL (0x3F << 0) |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 187 | #define DA7210_AUX1_L_EN (1 << 7) |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 188 | |
| 189 | /* AUX1_R bit fields */ |
| 190 | #define DA7210_AUX1_R_VOL (0x3F << 0) |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 191 | #define DA7210_AUX1_R_EN (1 << 7) |
| 192 | |
| 193 | /* AUX2 bit fields */ |
| 194 | #define DA7210_AUX2_EN (1 << 3) |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 195 | |
| 196 | /* Minimum INPGA and AUX1 volume to enable noise suppression */ |
| 197 | #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */ |
| 198 | #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */ |
| 199 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 200 | /* OUT1_L bit fields */ |
| 201 | #define DA7210_OUT1_L_EN (1 << 7) |
| 202 | |
| 203 | /* OUT1_R bit fields */ |
| 204 | #define DA7210_OUT1_R_EN (1 << 7) |
| 205 | |
| 206 | /* OUT2 bit fields */ |
| 207 | #define DA7210_OUT2_OUTMIX_R (1 << 5) |
| 208 | #define DA7210_OUT2_OUTMIX_L (1 << 6) |
| 209 | #define DA7210_OUT2_EN (1 << 7) |
| 210 | |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 211 | struct pll_div { |
| 212 | int fref; |
| 213 | int fout; |
| 214 | u8 div1; |
| 215 | u8 div2; |
| 216 | u8 div3; |
| 217 | u8 mode; /* 0 = slave, 1 = master */ |
| 218 | }; |
| 219 | |
| 220 | /* PLL dividers table */ |
| 221 | static const struct pll_div da7210_pll_div[] = { |
| 222 | /* for MASTER mode, fs = 44.1Khz */ |
| 223 | { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */ |
| 224 | { 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */ |
| 225 | { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */ |
| 226 | { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */ |
| 227 | { 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */ |
| 228 | { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */ |
| 229 | { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */ |
| 230 | /* for MASTER mode, fs = 48Khz */ |
| 231 | { 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */ |
| 232 | { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */ |
| 233 | { 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */ |
| 234 | { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */ |
| 235 | { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */ |
| 236 | { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */ |
| 237 | { 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */ |
| 238 | /* for SLAVE mode with SRM */ |
| 239 | { 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */ |
| 240 | { 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */ |
| 241 | { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */ |
| 242 | { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */ |
| 243 | { 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */ |
| 244 | { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */ |
| 245 | { 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */ |
| 246 | }; |
| 247 | |
| 248 | enum clk_src { |
| 249 | DA7210_CLKSRC_MCLK |
| 250 | }; |
| 251 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 252 | #define DA7210_VERSION "0.0.1" |
| 253 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 254 | /* |
| 255 | * Playback Volume |
| 256 | * |
| 257 | * max : 0x3F (+15.0 dB) |
| 258 | * (1.5 dB step) |
| 259 | * min : 0x11 (-54.0 dB) |
| 260 | * mute : 0x10 |
| 261 | * reserved : 0x00 - 0x0F |
| 262 | * |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 263 | * Reserved area are considered as "mute". |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 264 | */ |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 265 | static const DECLARE_TLV_DB_RANGE(hp_out_tlv, |
Ashish Chavan | 7a0e67b | 2011-10-14 16:25:25 +0530 | [diff] [blame] | 266 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 267 | /* -54 dB to +15 dB */ |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 268 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0) |
| 269 | ); |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 270 | |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 271 | static const DECLARE_TLV_DB_RANGE(lineout_vol_tlv, |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 272 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 273 | /* -54dB to 15dB */ |
| 274 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0) |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 275 | ); |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 276 | |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 277 | static const DECLARE_TLV_DB_RANGE(mono_vol_tlv, |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 278 | 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1), |
| 279 | /* -18dB to 6dB */ |
| 280 | 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0) |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 281 | ); |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 282 | |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 283 | static const DECLARE_TLV_DB_RANGE(aux1_vol_tlv, |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 284 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 285 | /* -48dB to 21dB */ |
| 286 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0) |
Lars-Peter Clausen | 6c1e1bf | 2015-08-02 17:19:37 +0200 | [diff] [blame] | 287 | ); |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 288 | |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 289 | static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0); |
| 290 | static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1); |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 291 | static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0); |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 292 | static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0); |
| 293 | static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0); |
| 294 | static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0); |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 295 | |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 296 | /* ADC and DAC high pass filter f0 value */ |
Mark Brown | f403414 | 2011-11-09 23:15:26 +0000 | [diff] [blame] | 297 | static const char * const da7210_hpf_cutoff_txt[] = { |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 298 | "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi" |
| 299 | }; |
| 300 | |
Takashi Iwai | e34042d | 2014-02-18 10:06:00 +0100 | [diff] [blame] | 301 | static SOC_ENUM_SINGLE_DECL(da7210_dac_hpf_cutoff, |
| 302 | DA7210_DAC_HPF, 0, da7210_hpf_cutoff_txt); |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 303 | |
Takashi Iwai | e34042d | 2014-02-18 10:06:00 +0100 | [diff] [blame] | 304 | static SOC_ENUM_SINGLE_DECL(da7210_adc_hpf_cutoff, |
| 305 | DA7210_ADC_HPF, 0, da7210_hpf_cutoff_txt); |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 306 | |
| 307 | /* ADC and DAC voice (8kHz) high pass cutoff value */ |
Mark Brown | f403414 | 2011-11-09 23:15:26 +0000 | [diff] [blame] | 308 | static const char * const da7210_vf_cutoff_txt[] = { |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 309 | "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" |
| 310 | }; |
| 311 | |
Takashi Iwai | e34042d | 2014-02-18 10:06:00 +0100 | [diff] [blame] | 312 | static SOC_ENUM_SINGLE_DECL(da7210_dac_vf_cutoff, |
| 313 | DA7210_DAC_HPF, 4, da7210_vf_cutoff_txt); |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 314 | |
Takashi Iwai | e34042d | 2014-02-18 10:06:00 +0100 | [diff] [blame] | 315 | static SOC_ENUM_SINGLE_DECL(da7210_adc_vf_cutoff, |
| 316 | DA7210_ADC_HPF, 4, da7210_vf_cutoff_txt); |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 317 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 318 | static const char *da7210_hp_mode_txt[] = { |
| 319 | "Class H", "Class G" |
| 320 | }; |
| 321 | |
Takashi Iwai | e34042d | 2014-02-18 10:06:00 +0100 | [diff] [blame] | 322 | static SOC_ENUM_SINGLE_DECL(da7210_hp_mode_sel, |
| 323 | DA7210_HP_CFG, 0, da7210_hp_mode_txt); |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 324 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 325 | /* ALC can be enabled only if noise suppression is disabled */ |
| 326 | static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol, |
| 327 | struct snd_ctl_elem_value *ucontrol) |
| 328 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 329 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 330 | |
| 331 | if (ucontrol->value.integer.value[0]) { |
| 332 | /* Check if noise suppression is enabled */ |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 333 | if (snd_soc_component_read(component, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 334 | dev_dbg(component->dev, |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 335 | "Disable noise suppression to enable ALC\n"); |
| 336 | return -EINVAL; |
| 337 | } |
| 338 | } |
| 339 | /* If all conditions are met or we are actually disabling ALC */ |
| 340 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 341 | } |
| 342 | |
| 343 | /* Noise suppression can be enabled only if following conditions are met |
| 344 | * ALC disabled |
| 345 | * ZC enabled for HP and AUX1 PGA |
| 346 | * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB |
| 347 | * AUX1_L_VOL and AUX1_R_VOL >= 6 dB |
| 348 | */ |
| 349 | static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol, |
| 350 | struct snd_ctl_elem_value *ucontrol) |
| 351 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 352 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 353 | u8 val; |
| 354 | |
| 355 | if (ucontrol->value.integer.value[0]) { |
| 356 | /* Check if ALC is enabled */ |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 357 | if (snd_soc_component_read(component, DA7210_ADC) & DA7210_ADC_ALC_EN) |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 358 | goto err; |
| 359 | |
| 360 | /* Check ZC for HP and AUX1 PGA */ |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 361 | if ((snd_soc_component_read(component, DA7210_ZERO_CROSS) & |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 362 | (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | |
| 363 | DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC | |
| 364 | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC)) |
| 365 | goto err; |
| 366 | |
| 367 | /* Check INPGA_L_VOL and INPGA_R_VOL */ |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 368 | val = snd_soc_component_read(component, DA7210_IN_GAIN); |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 369 | if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) || |
| 370 | (((val & DA7210_INPGA_R_VOL) >> 4) < |
| 371 | DA7210_INPGA_MIN_VOL_NS)) |
| 372 | goto err; |
| 373 | |
| 374 | /* Check AUX1_L_VOL and AUX1_R_VOL */ |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 375 | if (((snd_soc_component_read(component, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) < |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 376 | DA7210_AUX1_MIN_VOL_NS) || |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 377 | ((snd_soc_component_read(component, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) < |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 378 | DA7210_AUX1_MIN_VOL_NS)) |
| 379 | goto err; |
| 380 | } |
| 381 | /* If all conditions are met or we are actually disabling Noise sup */ |
| 382 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 383 | |
| 384 | err: |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 388 | static const struct snd_kcontrol_new da7210_snd_controls[] = { |
| 389 | |
| 390 | SOC_DOUBLE_R_TLV("HeadPhone Playback Volume", |
| 391 | DA7210_HP_L_VOL, DA7210_HP_R_VOL, |
| 392 | 0, 0x3F, 0, hp_out_tlv), |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 393 | SOC_DOUBLE_R_TLV("Digital Playback Volume", |
| 394 | DA7210_DAC_L, DA7210_DAC_R, |
| 395 | 0, 0x77, 1, dac_gain_tlv), |
| 396 | SOC_DOUBLE_R_TLV("Lineout Playback Volume", |
| 397 | DA7210_OUT1_L, DA7210_OUT1_R, |
| 398 | 0, 0x3f, 0, lineout_vol_tlv), |
| 399 | SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0, |
| 400 | mono_vol_tlv), |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 401 | |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 402 | SOC_DOUBLE_R_TLV("Mic Capture Volume", |
| 403 | DA7210_MIC_L, DA7210_MIC_R, |
| 404 | 0, 0x5, 0, mic_vol_tlv), |
| 405 | SOC_DOUBLE_R_TLV("Aux1 Capture Volume", |
| 406 | DA7210_AUX1_L, DA7210_AUX1_R, |
| 407 | 0, 0x3f, 0, aux1_vol_tlv), |
| 408 | SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0, |
| 409 | aux2_vol_tlv), |
| 410 | SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0, |
| 411 | inpga_gain_tlv), |
| 412 | |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 413 | /* DAC Equalizer controls */ |
| 414 | SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0), |
| 415 | SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1, |
| 416 | eq_gain_tlv), |
| 417 | SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1, |
| 418 | eq_gain_tlv), |
| 419 | SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1, |
| 420 | eq_gain_tlv), |
| 421 | SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1, |
| 422 | eq_gain_tlv), |
| 423 | SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1, |
| 424 | eq_gain_tlv), |
| 425 | |
| 426 | /* ADC Equalizer controls */ |
| 427 | SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0), |
| 428 | SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3, |
| 429 | 1, adc_eq_master_gain_tlv), |
| 430 | SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1, |
| 431 | eq_gain_tlv), |
| 432 | SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1, |
| 433 | eq_gain_tlv), |
| 434 | SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1, |
| 435 | eq_gain_tlv), |
| 436 | SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1, |
| 437 | eq_gain_tlv), |
| 438 | SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1, |
| 439 | eq_gain_tlv), |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 440 | |
| 441 | SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0), |
| 442 | SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff), |
| 443 | SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0), |
| 444 | SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff), |
| 445 | |
| 446 | SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0), |
| 447 | SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff), |
| 448 | SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0), |
| 449 | SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff), |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 450 | |
| 451 | /* Mute controls */ |
| 452 | SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0), |
| 453 | SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0), |
| 454 | SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0), |
| 455 | SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0), |
| 456 | SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0), |
| 457 | |
| 458 | /* Zero cross controls */ |
| 459 | SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0), |
| 460 | SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0), |
| 461 | SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0), |
| 462 | SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0), |
| 463 | |
| 464 | SOC_ENUM("Headphone Class", da7210_hp_mode_sel), |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 465 | |
| 466 | /* ALC controls */ |
| 467 | SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0, |
| 468 | snd_soc_get_volsw, da7210_put_alc_sw), |
| 469 | SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0), |
| 470 | SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0), |
| 471 | SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0), |
| 472 | SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0), |
| 473 | SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0), |
| 474 | SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0), |
| 475 | |
| 476 | SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1, |
| 477 | 0, snd_soc_get_volsw, da7210_put_noise_sup_sw), |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 478 | }; |
| 479 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 480 | /* |
| 481 | * DAPM Controls |
| 482 | * |
| 483 | * Current DAPM implementation covers almost all codec components e.g. IOs, |
| 484 | * mixers, PGAs,ADC and DAC. |
| 485 | */ |
| 486 | /* In Mixer Left */ |
| 487 | static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = { |
| 488 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0), |
| 489 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0), |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 490 | SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0), |
| 491 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0), |
| 492 | SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | /* In Mixer Right */ |
| 496 | static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = { |
| 497 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0), |
| 498 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0), |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 499 | SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0), |
| 500 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0), |
| 501 | SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 502 | }; |
| 503 | |
| 504 | /* Out Mixer Left */ |
| 505 | static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = { |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 506 | SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0), |
| 507 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0), |
| 508 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0), |
| 509 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 510 | SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0), |
| 511 | }; |
| 512 | |
| 513 | /* Out Mixer Right */ |
| 514 | static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = { |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 515 | SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0), |
| 516 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0), |
| 517 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0), |
| 518 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 519 | SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0), |
| 520 | }; |
| 521 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 522 | /* Mono Mixer */ |
| 523 | static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = { |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 524 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0), |
| 525 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0), |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 526 | SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0), |
| 527 | SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0), |
| 528 | }; |
| 529 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 530 | /* DAPM widgets */ |
| 531 | static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = { |
| 532 | /* Input Side */ |
| 533 | /* Input Lines */ |
| 534 | SND_SOC_DAPM_INPUT("MICL"), |
| 535 | SND_SOC_DAPM_INPUT("MICR"), |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 536 | SND_SOC_DAPM_INPUT("AUX1L"), |
| 537 | SND_SOC_DAPM_INPUT("AUX1R"), |
| 538 | SND_SOC_DAPM_INPUT("AUX2"), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 539 | |
| 540 | /* Input PGAs */ |
| 541 | SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0), |
| 542 | SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0), |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 543 | SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0), |
| 544 | SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0), |
| 545 | SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 546 | |
| 547 | SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0), |
| 548 | SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0), |
| 549 | |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 550 | /* MICBIAS */ |
| 551 | SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0), |
| 552 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 553 | /* Input Mixers */ |
| 554 | SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0, |
| 555 | &da7210_dapm_inmixl_controls[0], |
| 556 | ARRAY_SIZE(da7210_dapm_inmixl_controls)), |
| 557 | |
| 558 | SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0, |
| 559 | &da7210_dapm_inmixr_controls[0], |
| 560 | ARRAY_SIZE(da7210_dapm_inmixr_controls)), |
| 561 | |
| 562 | /* ADCs */ |
| 563 | SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1), |
| 564 | SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1), |
| 565 | |
| 566 | /* Output Side */ |
| 567 | /* DACs */ |
| 568 | SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1), |
| 569 | SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1), |
| 570 | |
| 571 | /* Output Mixers */ |
| 572 | SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0, |
| 573 | &da7210_dapm_outmixl_controls[0], |
| 574 | ARRAY_SIZE(da7210_dapm_outmixl_controls)), |
| 575 | |
| 576 | SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0, |
| 577 | &da7210_dapm_outmixr_controls[0], |
| 578 | ARRAY_SIZE(da7210_dapm_outmixr_controls)), |
| 579 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 580 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, |
| 581 | &da7210_dapm_monomix_controls[0], |
| 582 | ARRAY_SIZE(da7210_dapm_monomix_controls)), |
| 583 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 584 | /* Output PGAs */ |
| 585 | SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0), |
| 586 | SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0), |
| 587 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 588 | SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0), |
| 589 | SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0), |
| 590 | SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 591 | SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0), |
| 592 | SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0), |
| 593 | |
| 594 | /* Output Lines */ |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 595 | SND_SOC_DAPM_OUTPUT("OUT1L"), |
| 596 | SND_SOC_DAPM_OUTPUT("OUT1R"), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 597 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 598 | SND_SOC_DAPM_OUTPUT("HPR"), |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 599 | SND_SOC_DAPM_OUTPUT("OUT2"), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 600 | }; |
| 601 | |
| 602 | /* DAPM audio route definition */ |
| 603 | static const struct snd_soc_dapm_route da7210_audio_map[] = { |
| 604 | /* Dest Connecting Widget source */ |
| 605 | /* Input path */ |
| 606 | {"Mic Left", NULL, "MICL"}, |
| 607 | {"Mic Right", NULL, "MICR"}, |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 608 | {"Aux1 Left", NULL, "AUX1L"}, |
| 609 | {"Aux1 Right", NULL, "AUX1R"}, |
| 610 | {"Aux2 Mono", NULL, "AUX2"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 611 | |
| 612 | {"In Mixer Left", "Mic Left Switch", "Mic Left"}, |
| 613 | {"In Mixer Left", "Mic Right Switch", "Mic Right"}, |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 614 | {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"}, |
| 615 | {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"}, |
| 616 | {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 617 | |
| 618 | {"In Mixer Right", "Mic Right Switch", "Mic Right"}, |
| 619 | {"In Mixer Right", "Mic Left Switch", "Mic Left"}, |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 620 | {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"}, |
| 621 | {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"}, |
| 622 | {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 623 | |
| 624 | {"INPGA Left", NULL, "In Mixer Left"}, |
| 625 | {"ADC Left", NULL, "INPGA Left"}, |
| 626 | |
| 627 | {"INPGA Right", NULL, "In Mixer Right"}, |
| 628 | {"ADC Right", NULL, "INPGA Right"}, |
| 629 | |
| 630 | /* Output path */ |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 631 | {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"}, |
| 632 | {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"}, |
| 633 | {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"}, |
| 634 | {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 635 | {"Out Mixer Left", "DAC Left Switch", "DAC Left"}, |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 636 | |
| 637 | {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"}, |
| 638 | {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"}, |
| 639 | {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"}, |
| 640 | {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 641 | {"Out Mixer Right", "DAC Right Switch", "DAC Right"}, |
| 642 | |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 643 | {"Mono Mixer", "INPGA Right Switch", "INPGA Right"}, |
| 644 | {"Mono Mixer", "INPGA Left Switch", "INPGA Left"}, |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 645 | {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"}, |
| 646 | {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"}, |
| 647 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 648 | {"OUTPGA Left Enable", NULL, "Out Mixer Left"}, |
| 649 | {"OUTPGA Right Enable", NULL, "Out Mixer Right"}, |
| 650 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 651 | {"Out1 Left", NULL, "OUTPGA Left Enable"}, |
| 652 | {"OUT1L", NULL, "Out1 Left"}, |
| 653 | |
| 654 | {"Out1 Right", NULL, "OUTPGA Right Enable"}, |
| 655 | {"OUT1R", NULL, "Out1 Right"}, |
| 656 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 657 | {"Headphone Left", NULL, "OUTPGA Left Enable"}, |
| 658 | {"HPL", NULL, "Headphone Left"}, |
| 659 | |
| 660 | {"Headphone Right", NULL, "OUTPGA Right Enable"}, |
| 661 | {"HPR", NULL, "Headphone Right"}, |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 662 | |
| 663 | {"Out2 Mono", NULL, "Mono Mixer"}, |
| 664 | {"OUT2", NULL, "Out2 Mono"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 665 | }; |
| 666 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 667 | /* Codec private data */ |
| 668 | struct da7210_priv { |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 669 | struct regmap *regmap; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 670 | unsigned int mclk_rate; |
| 671 | int master; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 672 | }; |
| 673 | |
Axel Lin | c418a84 | 2015-07-05 17:48:29 +0800 | [diff] [blame] | 674 | static const struct reg_default da7210_reg_defaults[] = { |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 675 | { 0x00, 0x00 }, |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 676 | { 0x01, 0x11 }, |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 677 | { 0x03, 0x00 }, |
| 678 | { 0x04, 0x00 }, |
| 679 | { 0x05, 0x00 }, |
| 680 | { 0x06, 0x00 }, |
| 681 | { 0x07, 0x00 }, |
| 682 | { 0x08, 0x00 }, |
| 683 | { 0x09, 0x00 }, |
| 684 | { 0x0a, 0x00 }, |
| 685 | { 0x0b, 0x00 }, |
| 686 | { 0x0c, 0x00 }, |
| 687 | { 0x0d, 0x00 }, |
| 688 | { 0x0e, 0x00 }, |
| 689 | { 0x0f, 0x08 }, |
| 690 | { 0x10, 0x00 }, |
| 691 | { 0x11, 0x00 }, |
| 692 | { 0x12, 0x00 }, |
| 693 | { 0x13, 0x00 }, |
| 694 | { 0x14, 0x08 }, |
| 695 | { 0x15, 0x10 }, |
| 696 | { 0x16, 0x10 }, |
| 697 | { 0x17, 0x54 }, |
| 698 | { 0x18, 0x40 }, |
| 699 | { 0x19, 0x00 }, |
| 700 | { 0x1a, 0x00 }, |
| 701 | { 0x1b, 0x00 }, |
| 702 | { 0x1c, 0x00 }, |
| 703 | { 0x1d, 0x00 }, |
| 704 | { 0x1e, 0x00 }, |
| 705 | { 0x1f, 0x00 }, |
| 706 | { 0x20, 0x00 }, |
| 707 | { 0x21, 0x00 }, |
| 708 | { 0x22, 0x00 }, |
| 709 | { 0x23, 0x02 }, |
| 710 | { 0x24, 0x00 }, |
| 711 | { 0x25, 0x76 }, |
| 712 | { 0x26, 0x00 }, |
| 713 | { 0x27, 0x00 }, |
| 714 | { 0x28, 0x04 }, |
| 715 | { 0x29, 0x00 }, |
| 716 | { 0x2a, 0x00 }, |
| 717 | { 0x2b, 0x30 }, |
| 718 | { 0x2c, 0x2A }, |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 719 | { 0x83, 0x00 }, |
| 720 | { 0x84, 0x00 }, |
| 721 | { 0x85, 0x00 }, |
| 722 | { 0x86, 0x00 }, |
| 723 | { 0x87, 0x00 }, |
| 724 | { 0x88, 0x00 }, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 725 | }; |
| 726 | |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 727 | static bool da7210_readable_register(struct device *dev, unsigned int reg) |
| 728 | { |
| 729 | switch (reg) { |
| 730 | case DA7210_A_HID_UNLOCK: |
| 731 | case DA7210_A_TEST_UNLOCK: |
| 732 | case DA7210_A_PLL1: |
| 733 | case DA7210_A_CP_MODE: |
| 734 | return false; |
| 735 | default: |
| 736 | return true; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | static bool da7210_volatile_register(struct device *dev, |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 741 | unsigned int reg) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 742 | { |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 743 | switch (reg) { |
| 744 | case DA7210_STATUS: |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 745 | return true; |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 746 | default: |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 747 | return false; |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 748 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 749 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 750 | |
| 751 | /* |
| 752 | * Set PCM DAI word length. |
| 753 | */ |
| 754 | static int da7210_hw_params(struct snd_pcm_substream *substream, |
| 755 | struct snd_pcm_hw_params *params, |
| 756 | struct snd_soc_dai *dai) |
| 757 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 758 | struct snd_soc_component *component = dai->component; |
| 759 | struct da7210_priv *da7210 = snd_soc_component_get_drvdata(component); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 760 | u32 dai_cfg1; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 761 | u32 fs, sysclk; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 762 | |
| 763 | /* set DAI source to Left and Right ADC */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 764 | snd_soc_component_write(component, DA7210_DAI_SRC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 765 | DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); |
| 766 | |
| 767 | /* Enable DAI */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 768 | snd_soc_component_write(component, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 769 | |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 770 | dai_cfg1 = 0xFC & snd_soc_component_read(component, DA7210_DAI_CFG1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 771 | |
Mark Brown | 0194c42 | 2014-01-08 19:49:37 +0000 | [diff] [blame] | 772 | switch (params_width(params)) { |
| 773 | case 16: |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 774 | dai_cfg1 |= DA7210_DAI_WORD_S16_LE; |
| 775 | break; |
Mark Brown | 0194c42 | 2014-01-08 19:49:37 +0000 | [diff] [blame] | 776 | case 20: |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 777 | dai_cfg1 |= DA7210_DAI_WORD_S20_3LE; |
| 778 | break; |
Mark Brown | 0194c42 | 2014-01-08 19:49:37 +0000 | [diff] [blame] | 779 | case 24: |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 780 | dai_cfg1 |= DA7210_DAI_WORD_S24_LE; |
| 781 | break; |
Mark Brown | 0194c42 | 2014-01-08 19:49:37 +0000 | [diff] [blame] | 782 | case 32: |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 783 | dai_cfg1 |= DA7210_DAI_WORD_S32_LE; |
| 784 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 785 | default: |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 789 | snd_soc_component_write(component, DA7210_DAI_CFG1, dai_cfg1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 790 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 791 | switch (params_rate(params)) { |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 792 | case 8000: |
| 793 | fs = DA7210_PLL_FS_8000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 794 | sysclk = 3072000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 795 | break; |
| 796 | case 11025: |
| 797 | fs = DA7210_PLL_FS_11025; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 798 | sysclk = 2822400; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 799 | break; |
| 800 | case 12000: |
| 801 | fs = DA7210_PLL_FS_12000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 802 | sysclk = 3072000; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 803 | break; |
| 804 | case 16000: |
| 805 | fs = DA7210_PLL_FS_16000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 806 | sysclk = 3072000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 807 | break; |
| 808 | case 22050: |
| 809 | fs = DA7210_PLL_FS_22050; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 810 | sysclk = 2822400; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 811 | break; |
| 812 | case 32000: |
| 813 | fs = DA7210_PLL_FS_32000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 814 | sysclk = 3072000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 815 | break; |
| 816 | case 44100: |
| 817 | fs = DA7210_PLL_FS_44100; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 818 | sysclk = 2822400; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 819 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 820 | case 48000: |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 821 | fs = DA7210_PLL_FS_48000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 822 | sysclk = 3072000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 823 | break; |
| 824 | case 88200: |
| 825 | fs = DA7210_PLL_FS_88200; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 826 | sysclk = 2822400; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 827 | break; |
| 828 | case 96000: |
| 829 | fs = DA7210_PLL_FS_96000; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 830 | sysclk = 3072000; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 831 | break; |
| 832 | default: |
| 833 | return -EINVAL; |
| 834 | } |
| 835 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 836 | /* Disable active mode */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 837 | snd_soc_component_update_bits(component, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 838 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 839 | snd_soc_component_update_bits(component, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 840 | |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 841 | if (da7210->mclk_rate && (da7210->mclk_rate != sysclk)) { |
| 842 | /* PLL mode, disable PLL bypass */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 843 | snd_soc_component_update_bits(component, DA7210_PLL_DIV3, DA7210_PLL_BYP, 0); |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 844 | |
| 845 | if (!da7210->master) { |
| 846 | /* PLL slave mode, also enable SRM */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 847 | snd_soc_component_update_bits(component, DA7210_PLL, |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 848 | (DA7210_MCLK_SRM_EN | |
| 849 | DA7210_MCLK_DET_EN), |
| 850 | (DA7210_MCLK_SRM_EN | |
| 851 | DA7210_MCLK_DET_EN)); |
| 852 | } |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 853 | } else { |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 854 | /* PLL bypass mode, enable PLL bypass and Auto Detection */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 855 | snd_soc_component_update_bits(component, DA7210_PLL, DA7210_MCLK_DET_EN, |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 856 | DA7210_MCLK_DET_EN); |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 857 | snd_soc_component_update_bits(component, DA7210_PLL_DIV3, DA7210_PLL_BYP, |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 858 | DA7210_PLL_BYP); |
| 859 | } |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 860 | /* Enable active mode */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 861 | snd_soc_component_update_bits(component, DA7210_STARTUP1, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 862 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * Set DAI mode and Format |
| 869 | */ |
| 870 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) |
| 871 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 872 | struct snd_soc_component *component = codec_dai->component; |
| 873 | struct da7210_priv *da7210 = snd_soc_component_get_drvdata(component); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 874 | u32 dai_cfg1; |
| 875 | u32 dai_cfg3; |
| 876 | |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 877 | dai_cfg1 = 0x7f & snd_soc_component_read(component, DA7210_DAI_CFG1); |
| 878 | dai_cfg3 = 0xfc & snd_soc_component_read(component, DA7210_DAI_CFG3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 879 | |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 880 | if ((snd_soc_component_read(component, DA7210_PLL) & DA7210_PLL_EN) && |
| 881 | (!(snd_soc_component_read(component, DA7210_PLL_DIV3) & DA7210_PLL_BYP))) |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 882 | return -EINVAL; |
| 883 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 884 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 885 | case SND_SOC_DAIFMT_CBM_CFM: |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 886 | da7210->master = 1; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 887 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; |
| 888 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 889 | case SND_SOC_DAIFMT_CBS_CFS: |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 890 | da7210->master = 0; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 891 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; |
| 892 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 893 | default: |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | |
| 897 | /* FIXME |
| 898 | * |
| 899 | * It support I2S only now |
| 900 | */ |
| 901 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 902 | case SND_SOC_DAIFMT_I2S: |
| 903 | dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; |
| 904 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 905 | case SND_SOC_DAIFMT_LEFT_J: |
| 906 | dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J; |
| 907 | break; |
| 908 | case SND_SOC_DAIFMT_RIGHT_J: |
| 909 | dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J; |
| 910 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 911 | default: |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
| 915 | /* FIXME |
| 916 | * |
| 917 | * It support 64bit data transmission only now |
| 918 | */ |
| 919 | dai_cfg1 |= DA7210_DAI_FLEN_64BIT; |
| 920 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 921 | snd_soc_component_write(component, DA7210_DAI_CFG1, dai_cfg1); |
| 922 | snd_soc_component_write(component, DA7210_DAI_CFG3, dai_cfg3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 923 | |
| 924 | return 0; |
| 925 | } |
| 926 | |
Kuninori Morimoto | f39c054 | 2020-07-09 10:57:02 +0900 | [diff] [blame] | 927 | static int da7210_mute(struct snd_soc_dai *dai, int mute, int direction) |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 928 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 929 | struct snd_soc_component *component = dai->component; |
Kuninori Morimoto | 2925b58 | 2020-06-16 14:21:42 +0900 | [diff] [blame] | 930 | u8 mute_reg = snd_soc_component_read(component, DA7210_DAC_HPF) & 0xFB; |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 931 | |
| 932 | if (mute) |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 933 | snd_soc_component_write(component, DA7210_DAC_HPF, mute_reg | 0x4); |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 934 | else |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 935 | snd_soc_component_write(component, DA7210_DAC_HPF, mute_reg); |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 939 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 940 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 941 | |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 942 | static int da7210_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 943 | int clk_id, unsigned int freq, int dir) |
| 944 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 945 | struct snd_soc_component *component = codec_dai->component; |
| 946 | struct da7210_priv *da7210 = snd_soc_component_get_drvdata(component); |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 947 | |
| 948 | switch (clk_id) { |
| 949 | case DA7210_CLKSRC_MCLK: |
| 950 | switch (freq) { |
| 951 | case 12000000: |
| 952 | case 13000000: |
| 953 | case 13500000: |
| 954 | case 14400000: |
| 955 | case 19200000: |
| 956 | case 19680000: |
| 957 | case 19800000: |
| 958 | da7210->mclk_rate = freq; |
| 959 | return 0; |
| 960 | default: |
| 961 | dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", |
| 962 | freq); |
| 963 | return -EINVAL; |
| 964 | } |
| 965 | break; |
| 966 | default: |
| 967 | dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id); |
| 968 | return -EINVAL; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * da7210_set_dai_pll :Configure the codec PLL |
Pierre-Louis Bossart | d3d0502 | 2020-07-07 14:06:05 -0500 | [diff] [blame] | 974 | * @codec_dai: pointer to codec DAI |
| 975 | * @pll_id: da7210 has only one pll, so pll_id is always zero |
| 976 | * @source: clock source |
| 977 | * @fref: MCLK frequency, should be < 20MHz |
| 978 | * @fout: FsDM value, Refer page 44 & 45 of datasheet |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 979 | * |
| 980 | * Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz, |
| 981 | * 19.2MHz, 19.6MHz and 19.8MHz |
Pierre-Louis Bossart | d3d0502 | 2020-07-07 14:06:05 -0500 | [diff] [blame] | 982 | * |
| 983 | * Return: Zero for success, negative error code for error |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 984 | */ |
| 985 | static int da7210_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 986 | int source, unsigned int fref, unsigned int fout) |
| 987 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 988 | struct snd_soc_component *component = codec_dai->component; |
| 989 | struct da7210_priv *da7210 = snd_soc_component_get_drvdata(component); |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 990 | |
| 991 | u8 pll_div1, pll_div2, pll_div3, cnt; |
| 992 | |
| 993 | /* In slave mode, there is only one set of divisors */ |
| 994 | if (!da7210->master) |
| 995 | fout = 2822400; |
| 996 | |
| 997 | /* Search pll div array for correct divisors */ |
| 998 | for (cnt = 0; cnt < ARRAY_SIZE(da7210_pll_div); cnt++) { |
Ashish Chavan | c4b14e7 | 2012-04-17 21:07:44 +0530 | [diff] [blame] | 999 | /* check fref, mode and fout */ |
| 1000 | if ((fref == da7210_pll_div[cnt].fref) && |
| 1001 | (da7210->master == da7210_pll_div[cnt].mode) && |
| 1002 | (fout == da7210_pll_div[cnt].fout)) { |
| 1003 | /* all match, pick up divisors */ |
| 1004 | pll_div1 = da7210_pll_div[cnt].div1; |
| 1005 | pll_div2 = da7210_pll_div[cnt].div2; |
| 1006 | pll_div3 = da7210_pll_div[cnt].div3; |
| 1007 | break; |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | if (cnt >= ARRAY_SIZE(da7210_pll_div)) |
| 1011 | goto err; |
| 1012 | |
| 1013 | /* Disable active mode */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1014 | snd_soc_component_update_bits(component, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1015 | /* Write PLL dividers */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1016 | snd_soc_component_write(component, DA7210_PLL_DIV1, pll_div1); |
| 1017 | snd_soc_component_write(component, DA7210_PLL_DIV2, pll_div2); |
| 1018 | snd_soc_component_update_bits(component, DA7210_PLL_DIV3, |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1019 | DA7210_PLL_DIV_L_MASK, pll_div3); |
| 1020 | |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 1021 | /* Enable PLL */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1022 | snd_soc_component_update_bits(component, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); |
Ashish Chavan | 3cb8165 | 2012-05-03 19:27:52 +0530 | [diff] [blame] | 1023 | |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1024 | /* Enable active mode */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1025 | snd_soc_component_update_bits(component, DA7210_STARTUP1, DA7210_SC_MST_EN, |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1026 | DA7210_SC_MST_EN); |
| 1027 | return 0; |
| 1028 | err: |
| 1029 | dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n", fref); |
| 1030 | return -EINVAL; |
| 1031 | } |
| 1032 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1033 | /* DAI operations */ |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1034 | static const struct snd_soc_dai_ops da7210_dai_ops = { |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1035 | .hw_params = da7210_hw_params, |
| 1036 | .set_fmt = da7210_set_dai_fmt, |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1037 | .set_sysclk = da7210_set_dai_sysclk, |
| 1038 | .set_pll = da7210_set_dai_pll, |
Kuninori Morimoto | f39c054 | 2020-07-09 10:57:02 +0900 | [diff] [blame] | 1039 | .mute_stream = da7210_mute, |
| 1040 | .no_capture_mute = 1, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1041 | }; |
| 1042 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1043 | static struct snd_soc_dai_driver da7210_dai = { |
| 1044 | .name = "da7210-hifi", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1045 | /* playback capabilities */ |
| 1046 | .playback = { |
| 1047 | .stream_name = "Playback", |
| 1048 | .channels_min = 1, |
| 1049 | .channels_max = 2, |
| 1050 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 1051 | .formats = DA7210_FORMATS, |
| 1052 | }, |
| 1053 | /* capture capabilities */ |
| 1054 | .capture = { |
| 1055 | .stream_name = "Capture", |
| 1056 | .channels_min = 1, |
| 1057 | .channels_max = 2, |
| 1058 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 1059 | .formats = DA7210_FORMATS, |
| 1060 | }, |
| 1061 | .ops = &da7210_dai_ops, |
Kuninori Morimoto | 1c6d1c4 | 2021-01-15 13:54:33 +0900 | [diff] [blame] | 1062 | .symmetric_rate = 1, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1063 | }; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1064 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1065 | static int da7210_probe(struct snd_soc_component *component) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1066 | { |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1067 | struct da7210_priv *da7210 = snd_soc_component_get_drvdata(component); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1068 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1069 | dev_info(component->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1070 | |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1071 | da7210->mclk_rate = 0; /* This will be set from set_sysclk() */ |
| 1072 | da7210->master = 0; /* This will be set from set_fmt() */ |
| 1073 | |
| 1074 | /* Enable internal regulator & bias current */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1075 | snd_soc_component_write(component, DA7210_CONTROL, DA7210_REG_EN | DA7210_BIAS_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1076 | |
| 1077 | /* |
| 1078 | * ADC settings |
| 1079 | */ |
| 1080 | |
| 1081 | /* Enable Left & Right MIC PGA and Mic Bias */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1082 | snd_soc_component_write(component, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); |
| 1083 | snd_soc_component_write(component, DA7210_MIC_R, DA7210_MIC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1084 | |
| 1085 | /* Enable Left and Right input PGA */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1086 | snd_soc_component_write(component, DA7210_INMIX_L, DA7210_IN_L_EN); |
| 1087 | snd_soc_component_write(component, DA7210_INMIX_R, DA7210_IN_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1088 | |
| 1089 | /* Enable Left and Right ADC */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1090 | snd_soc_component_write(component, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1091 | |
| 1092 | /* |
| 1093 | * DAC settings |
| 1094 | */ |
| 1095 | |
| 1096 | /* Enable Left and Right DAC */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1097 | snd_soc_component_write(component, DA7210_DAC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1098 | DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | |
| 1099 | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); |
| 1100 | |
| 1101 | /* Enable Left and Right out PGA */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1102 | snd_soc_component_write(component, DA7210_OUTMIX_L, DA7210_OUT_L_EN); |
| 1103 | snd_soc_component_write(component, DA7210_OUTMIX_R, DA7210_OUT_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1104 | |
| 1105 | /* Enable Left and Right HeadPhone PGA */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1106 | snd_soc_component_write(component, DA7210_HP_CFG, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1107 | DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | |
| 1108 | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); |
| 1109 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 1110 | /* Enable ramp mode for DAC gain update */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1111 | snd_soc_component_write(component, DA7210_SOFTMUTE, DA7210_RAMP_EN); |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 1112 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 1113 | /* |
| 1114 | * For DA7210 codec, there are two ways to enable/disable analog IOs |
| 1115 | * and ADC/DAC, |
| 1116 | * (1) Using "Enable Bit" of register associated with that IO |
| 1117 | * (or ADC/DAC) |
| 1118 | * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg |
| 1119 | * |
| 1120 | * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register |
| 1121 | * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5) |
| 1122 | * |
| 1123 | * Out of these two methods, the one using STANDBY bits is preferred |
| 1124 | * way to enable/disable individual blocks. This is because STANDBY |
| 1125 | * registers are part of system controller which allows system power |
| 1126 | * up/down in a controlled, pop-free manner. Also, as per application |
| 1127 | * note of DA7210, STANDBY register bits are only effective if a |
| 1128 | * particular IO (or ADC/DAC) is already enabled using enable/disable |
| 1129 | * register bits. Keeping these things in mind, current DAPM |
| 1130 | * implementation manipulates only STANDBY bits. |
| 1131 | * |
| 1132 | * Overall implementation can be outlined as below, |
| 1133 | * |
| 1134 | * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe() |
| 1135 | * - "STANDBY bit" is controlled by DAPM |
| 1136 | */ |
| 1137 | |
| 1138 | /* Enable Line out amplifiers */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1139 | snd_soc_component_write(component, DA7210_OUT1_L, DA7210_OUT1_L_EN); |
| 1140 | snd_soc_component_write(component, DA7210_OUT1_R, DA7210_OUT1_R_EN); |
| 1141 | snd_soc_component_write(component, DA7210_OUT2, DA7210_OUT2_EN | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame] | 1142 | DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R); |
| 1143 | |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 1144 | /* Enable Aux1 */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1145 | snd_soc_component_write(component, DA7210_AUX1_L, DA7210_AUX1_L_EN); |
| 1146 | snd_soc_component_write(component, DA7210_AUX1_R, DA7210_AUX1_R_EN); |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 1147 | /* Enable Aux2 */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1148 | snd_soc_component_write(component, DA7210_AUX2, DA7210_AUX2_EN); |
Ashish Chavan | 24b6f26 | 2012-01-02 17:35:52 +0530 | [diff] [blame] | 1149 | |
Ashish Chavan | 604bb22 | 2012-04-27 16:44:04 +0530 | [diff] [blame] | 1150 | /* Set PLL Master clock range 10-20 MHz, enable PLL bypass */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1151 | snd_soc_component_write(component, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | |
Ashish Chavan | 604bb22 | 2012-04-27 16:44:04 +0530 | [diff] [blame] | 1152 | DA7210_PLL_BYP); |
Ashish Chavan | 570aa7b | 2012-04-17 18:04:06 +0530 | [diff] [blame] | 1153 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1154 | /* Diable PLL and bypass it */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1155 | snd_soc_component_write(component, DA7210_PLL, DA7210_PLL_FS_48000); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1156 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1157 | /* Activate all enabled subsystem */ |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1158 | snd_soc_component_write(component, DA7210_STARTUP1, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1159 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1160 | dev_info(component->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1161 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1162 | return 0; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1163 | } |
| 1164 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1165 | static const struct snd_soc_component_driver soc_component_dev_da7210 = { |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 1166 | .probe = da7210_probe, |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1167 | .controls = da7210_snd_controls, |
| 1168 | .num_controls = ARRAY_SIZE(da7210_snd_controls), |
| 1169 | .dapm_widgets = da7210_dapm_widgets, |
| 1170 | .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets), |
| 1171 | .dapm_routes = da7210_audio_map, |
| 1172 | .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), |
| 1173 | .idle_bias_on = 1, |
| 1174 | .use_pmdown_time = 1, |
| 1175 | .endianness = 1, |
| 1176 | .non_legacy_dai_naming = 1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1177 | }; |
| 1178 | |
Fabio Estevam | 25c1a63 | 2013-11-21 12:38:40 -0200 | [diff] [blame] | 1179 | #if IS_ENABLED(CONFIG_I2C) |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1180 | |
Mark Brown | 41a5fefe | 2015-07-17 19:32:04 +0100 | [diff] [blame] | 1181 | static const struct reg_sequence da7210_regmap_i2c_patch[] = { |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1182 | |
| 1183 | /* System controller master disable */ |
| 1184 | { DA7210_STARTUP1, 0x00 }, |
Ashish Chavan | 604bb22 | 2012-04-27 16:44:04 +0530 | [diff] [blame] | 1185 | /* Set PLL Master clock range 10-20 MHz */ |
| 1186 | { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ }, |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1187 | |
| 1188 | /* to unlock */ |
| 1189 | { DA7210_A_HID_UNLOCK, 0x8B}, |
| 1190 | { DA7210_A_TEST_UNLOCK, 0xB4}, |
| 1191 | { DA7210_A_PLL1, 0x01}, |
| 1192 | { DA7210_A_CP_MODE, 0x7C}, |
| 1193 | /* to re-lock */ |
| 1194 | { DA7210_A_HID_UNLOCK, 0x00}, |
| 1195 | { DA7210_A_TEST_UNLOCK, 0x00}, |
| 1196 | }; |
| 1197 | |
| 1198 | static const struct regmap_config da7210_regmap_config_i2c = { |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 1199 | .reg_bits = 8, |
| 1200 | .val_bits = 8, |
| 1201 | |
| 1202 | .reg_defaults = da7210_reg_defaults, |
| 1203 | .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults), |
| 1204 | .volatile_reg = da7210_volatile_register, |
| 1205 | .readable_reg = da7210_readable_register, |
| 1206 | .cache_type = REGCACHE_RBTREE, |
| 1207 | }; |
| 1208 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1209 | static int da7210_i2c_probe(struct i2c_client *i2c, |
| 1210 | const struct i2c_device_id *id) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1211 | { |
| 1212 | struct da7210_priv *da7210; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1213 | int ret; |
| 1214 | |
Axel Lin | 306bf6b | 2011-12-26 20:54:04 +0800 | [diff] [blame] | 1215 | da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv), |
| 1216 | GFP_KERNEL); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1217 | if (!da7210) |
| 1218 | return -ENOMEM; |
| 1219 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1220 | i2c_set_clientdata(i2c, da7210); |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 1221 | |
Sachin Kamat | 4e75955 | 2012-11-26 17:19:39 +0530 | [diff] [blame] | 1222 | da7210->regmap = devm_regmap_init_i2c(i2c, &da7210_regmap_config_i2c); |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 1223 | if (IS_ERR(da7210->regmap)) { |
| 1224 | ret = PTR_ERR(da7210->regmap); |
| 1225 | dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); |
| 1226 | return ret; |
| 1227 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1228 | |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1229 | ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch, |
| 1230 | ARRAY_SIZE(da7210_regmap_i2c_patch)); |
| 1231 | if (ret != 0) |
| 1232 | dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); |
| 1233 | |
weiyongjun (A) | c0153b1 | 2018-03-16 07:32:14 +0000 | [diff] [blame] | 1234 | ret = devm_snd_soc_register_component(&i2c->dev, |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1235 | &soc_component_dev_da7210, &da7210_dai, 1); |
Sachin Kamat | 4e75955 | 2012-11-26 17:19:39 +0530 | [diff] [blame] | 1236 | if (ret < 0) |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1237 | dev_err(&i2c->dev, "Failed to register component: %d\n", ret); |
Ashish Chavan | 33593b5 | 2012-03-08 19:04:56 +0530 | [diff] [blame] | 1238 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1239 | return ret; |
| 1240 | } |
| 1241 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1242 | static const struct i2c_device_id da7210_i2c_id[] = { |
| 1243 | { "da7210", 0 }, |
| 1244 | { } |
| 1245 | }; |
| 1246 | MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); |
| 1247 | |
| 1248 | /* I2C codec control layer */ |
| 1249 | static struct i2c_driver da7210_i2c_driver = { |
| 1250 | .driver = { |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1251 | .name = "da7210", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1252 | }, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 1253 | .probe = da7210_i2c_probe, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 1254 | .id_table = da7210_i2c_id, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1255 | }; |
| 1256 | #endif |
| 1257 | |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1258 | #if defined(CONFIG_SPI_MASTER) |
| 1259 | |
Mark Brown | 41a5fefe | 2015-07-17 19:32:04 +0100 | [diff] [blame] | 1260 | static const struct reg_sequence da7210_regmap_spi_patch[] = { |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1261 | /* Dummy read to give two pulses over nCS for SPI */ |
| 1262 | { DA7210_AUX2, 0x00 }, |
| 1263 | { DA7210_AUX2, 0x00 }, |
| 1264 | |
| 1265 | /* System controller master disable */ |
| 1266 | { DA7210_STARTUP1, 0x00 }, |
Ashish Chavan | 604bb22 | 2012-04-27 16:44:04 +0530 | [diff] [blame] | 1267 | /* Set PLL Master clock range 10-20 MHz */ |
| 1268 | { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ }, |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1269 | |
| 1270 | /* to set PAGE1 of SPI register space */ |
| 1271 | { DA7210_PAGE_CONTROL, 0x80 }, |
| 1272 | /* to unlock */ |
| 1273 | { DA7210_A_HID_UNLOCK, 0x8B}, |
| 1274 | { DA7210_A_TEST_UNLOCK, 0xB4}, |
| 1275 | { DA7210_A_PLL1, 0x01}, |
| 1276 | { DA7210_A_CP_MODE, 0x7C}, |
| 1277 | /* to re-lock */ |
| 1278 | { DA7210_A_HID_UNLOCK, 0x00}, |
| 1279 | { DA7210_A_TEST_UNLOCK, 0x00}, |
| 1280 | /* to set back PAGE0 of SPI register space */ |
| 1281 | { DA7210_PAGE_CONTROL, 0x00 }, |
| 1282 | }; |
| 1283 | |
| 1284 | static const struct regmap_config da7210_regmap_config_spi = { |
| 1285 | .reg_bits = 8, |
| 1286 | .val_bits = 8, |
| 1287 | .read_flag_mask = 0x01, |
| 1288 | .write_flag_mask = 0x00, |
| 1289 | |
| 1290 | .reg_defaults = da7210_reg_defaults, |
| 1291 | .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults), |
| 1292 | .volatile_reg = da7210_volatile_register, |
| 1293 | .readable_reg = da7210_readable_register, |
| 1294 | .cache_type = REGCACHE_RBTREE, |
| 1295 | }; |
| 1296 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1297 | static int da7210_spi_probe(struct spi_device *spi) |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1298 | { |
| 1299 | struct da7210_priv *da7210; |
| 1300 | int ret; |
| 1301 | |
| 1302 | da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv), |
| 1303 | GFP_KERNEL); |
| 1304 | if (!da7210) |
| 1305 | return -ENOMEM; |
| 1306 | |
| 1307 | spi_set_drvdata(spi, da7210); |
| 1308 | da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi); |
| 1309 | if (IS_ERR(da7210->regmap)) { |
| 1310 | ret = PTR_ERR(da7210->regmap); |
| 1311 | dev_err(&spi->dev, "Failed to register regmap: %d\n", ret); |
| 1312 | return ret; |
| 1313 | } |
| 1314 | |
| 1315 | ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch, |
| 1316 | ARRAY_SIZE(da7210_regmap_spi_patch)); |
| 1317 | if (ret != 0) |
| 1318 | dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret); |
| 1319 | |
Kuninori Morimoto | d06f33a | 2018-01-29 04:01:06 +0000 | [diff] [blame] | 1320 | ret = devm_snd_soc_register_component(&spi->dev, |
| 1321 | &soc_component_dev_da7210, &da7210_dai, 1); |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1322 | |
| 1323 | return ret; |
| 1324 | } |
| 1325 | |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1326 | static struct spi_driver da7210_spi_driver = { |
| 1327 | .driver = { |
| 1328 | .name = "da7210", |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1329 | }, |
| 1330 | .probe = da7210_spi_probe, |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1331 | }; |
| 1332 | #endif |
| 1333 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1334 | static int __init da7210_modinit(void) |
| 1335 | { |
| 1336 | int ret = 0; |
Fabio Estevam | 25c1a63 | 2013-11-21 12:38:40 -0200 | [diff] [blame] | 1337 | #if IS_ENABLED(CONFIG_I2C) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1338 | ret = i2c_add_driver(&da7210_i2c_driver); |
| 1339 | #endif |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1340 | #if defined(CONFIG_SPI_MASTER) |
| 1341 | ret = spi_register_driver(&da7210_spi_driver); |
| 1342 | if (ret) { |
| 1343 | printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n", |
| 1344 | ret); |
| 1345 | } |
| 1346 | #endif |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1347 | return ret; |
| 1348 | } |
| 1349 | module_init(da7210_modinit); |
| 1350 | |
| 1351 | static void __exit da7210_exit(void) |
| 1352 | { |
Fabio Estevam | 25c1a63 | 2013-11-21 12:38:40 -0200 | [diff] [blame] | 1353 | #if IS_ENABLED(CONFIG_I2C) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1354 | i2c_del_driver(&da7210_i2c_driver); |
| 1355 | #endif |
Ashish Chavan | aa0e25c | 2012-03-29 19:06:29 +0530 | [diff] [blame] | 1356 | #if defined(CONFIG_SPI_MASTER) |
| 1357 | spi_unregister_driver(&da7210_spi_driver); |
| 1358 | #endif |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1359 | } |
| 1360 | module_exit(da7210_exit); |
| 1361 | |
| 1362 | MODULE_DESCRIPTION("ASoC DA7210 driver"); |
| 1363 | MODULE_AUTHOR("David Chen, Kuninori Morimoto"); |
| 1364 | MODULE_LICENSE("GPL"); |