Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 1 | /* |
| 2 | * DA7210 ALSA Soc codec driver |
| 3 | * |
| 4 | * Copyright (c) 2009 Dialog Semiconductor |
| 5 | * Written by David Chen <Dajun.chen@diasemi.com> |
| 6 | * |
| 7 | * Copyright (C) 2009 Renesas Solutions Corp. |
| 8 | * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com> |
| 9 | * |
| 10 | * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | */ |
| 17 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 18 | #include <linux/delay.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 19 | #include <linux/i2c.h> |
| 20 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 24 | #include <sound/soc.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 25 | #include <sound/initval.h> |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 26 | #include <sound/tlv.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 27 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 28 | /* DA7210 register space */ |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 29 | #define DA7210_CONTROL 0x01 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 30 | #define DA7210_STATUS 0x02 |
| 31 | #define DA7210_STARTUP1 0x03 |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 32 | #define DA7210_STARTUP2 0x04 |
| 33 | #define DA7210_STARTUP3 0x05 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 34 | #define DA7210_MIC_L 0x07 |
| 35 | #define DA7210_MIC_R 0x08 |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 36 | #define DA7210_AUX1_L 0x09 |
| 37 | #define DA7210_AUX1_R 0x0A |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 38 | #define DA7210_AUX2 0x0B |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 39 | #define DA7210_IN_GAIN 0x0C |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 40 | #define DA7210_INMIX_L 0x0D |
| 41 | #define DA7210_INMIX_R 0x0E |
| 42 | #define DA7210_ADC_HPF 0x0F |
| 43 | #define DA7210_ADC 0x10 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 44 | #define DA7210_ADC_EQ1_2 0X11 |
| 45 | #define DA7210_ADC_EQ3_4 0x12 |
| 46 | #define DA7210_ADC_EQ5 0x13 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 47 | #define DA7210_DAC_HPF 0x14 |
| 48 | #define DA7210_DAC_L 0x15 |
| 49 | #define DA7210_DAC_R 0x16 |
| 50 | #define DA7210_DAC_SEL 0x17 |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 51 | #define DA7210_SOFTMUTE 0x18 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 52 | #define DA7210_DAC_EQ1_2 0x19 |
| 53 | #define DA7210_DAC_EQ3_4 0x1A |
| 54 | #define DA7210_DAC_EQ5 0x1B |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 55 | #define DA7210_OUTMIX_L 0x1C |
| 56 | #define DA7210_OUTMIX_R 0x1D |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 57 | #define DA7210_OUT1_L 0x1E |
| 58 | #define DA7210_OUT1_R 0x1F |
| 59 | #define DA7210_OUT2 0x20 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 60 | #define DA7210_HP_L_VOL 0x21 |
| 61 | #define DA7210_HP_R_VOL 0x22 |
| 62 | #define DA7210_HP_CFG 0x23 |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 63 | #define DA7210_ZERO_CROSS 0x24 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 64 | #define DA7210_DAI_SRC_SEL 0x25 |
| 65 | #define DA7210_DAI_CFG1 0x26 |
| 66 | #define DA7210_DAI_CFG3 0x28 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 67 | #define DA7210_PLL_DIV1 0x29 |
| 68 | #define DA7210_PLL_DIV2 0x2A |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 69 | #define DA7210_PLL_DIV3 0x2B |
| 70 | #define DA7210_PLL 0x2C |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 71 | #define DA7210_ALC_MAX 0x83 |
| 72 | #define DA7210_ALC_MIN 0x84 |
| 73 | #define DA7210_ALC_NOIS 0x85 |
| 74 | #define DA7210_ALC_ATT 0x86 |
| 75 | #define DA7210_ALC_REL 0x87 |
| 76 | #define DA7210_ALC_DEL 0x88 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 77 | #define DA7210_A_HID_UNLOCK 0x8A |
| 78 | #define DA7210_A_TEST_UNLOCK 0x8B |
| 79 | #define DA7210_A_PLL1 0x90 |
| 80 | #define DA7210_A_CP_MODE 0xA7 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 81 | |
| 82 | /* STARTUP1 bit fields */ |
| 83 | #define DA7210_SC_MST_EN (1 << 0) |
| 84 | |
| 85 | /* MIC_L bit fields */ |
| 86 | #define DA7210_MICBIAS_EN (1 << 6) |
| 87 | #define DA7210_MIC_L_EN (1 << 7) |
| 88 | |
| 89 | /* MIC_R bit fields */ |
| 90 | #define DA7210_MIC_R_EN (1 << 7) |
| 91 | |
| 92 | /* INMIX_L bit fields */ |
| 93 | #define DA7210_IN_L_EN (1 << 7) |
| 94 | |
| 95 | /* INMIX_R bit fields */ |
| 96 | #define DA7210_IN_R_EN (1 << 7) |
| 97 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 98 | /* ADC bit fields */ |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 99 | #define DA7210_ADC_ALC_EN (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 100 | #define DA7210_ADC_L_EN (1 << 3) |
| 101 | #define DA7210_ADC_R_EN (1 << 7) |
| 102 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 103 | /* DAC/ADC HPF fields */ |
| 104 | #define DA7210_VOICE_F0_MASK (0x7 << 4) |
| 105 | #define DA7210_VOICE_F0_25 (1 << 4) |
| 106 | #define DA7210_VOICE_EN (1 << 7) |
Mark Brown | c215143 | 2009-12-16 20:36:37 +0000 | [diff] [blame] | 107 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 108 | /* DAC_SEL bit fields */ |
| 109 | #define DA7210_DAC_L_SRC_DAI_L (4 << 0) |
| 110 | #define DA7210_DAC_L_EN (1 << 3) |
| 111 | #define DA7210_DAC_R_SRC_DAI_R (5 << 4) |
| 112 | #define DA7210_DAC_R_EN (1 << 7) |
| 113 | |
| 114 | /* OUTMIX_L bit fields */ |
| 115 | #define DA7210_OUT_L_EN (1 << 7) |
| 116 | |
| 117 | /* OUTMIX_R bit fields */ |
| 118 | #define DA7210_OUT_R_EN (1 << 7) |
| 119 | |
| 120 | /* HP_CFG bit fields */ |
| 121 | #define DA7210_HP_2CAP_MODE (1 << 1) |
| 122 | #define DA7210_HP_SENSE_EN (1 << 2) |
| 123 | #define DA7210_HP_L_EN (1 << 3) |
| 124 | #define DA7210_HP_MODE (1 << 6) |
| 125 | #define DA7210_HP_R_EN (1 << 7) |
| 126 | |
| 127 | /* DAI_SRC_SEL bit fields */ |
| 128 | #define DA7210_DAI_OUT_L_SRC (6 << 0) |
| 129 | #define DA7210_DAI_OUT_R_SRC (7 << 4) |
| 130 | |
| 131 | /* DAI_CFG1 bit fields */ |
| 132 | #define DA7210_DAI_WORD_S16_LE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 133 | #define DA7210_DAI_WORD_S20_3LE (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 134 | #define DA7210_DAI_WORD_S24_LE (2 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 135 | #define DA7210_DAI_WORD_S32_LE (3 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 136 | #define DA7210_DAI_FLEN_64BIT (1 << 2) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 137 | #define DA7210_DAI_MODE_SLAVE (0 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 138 | #define DA7210_DAI_MODE_MASTER (1 << 7) |
| 139 | |
| 140 | /* DAI_CFG3 bit fields */ |
| 141 | #define DA7210_DAI_FORMAT_I2SMODE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 142 | #define DA7210_DAI_FORMAT_LEFT_J (1 << 0) |
| 143 | #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 144 | #define DA7210_DAI_OE (1 << 3) |
| 145 | #define DA7210_DAI_EN (1 << 7) |
| 146 | |
| 147 | /*PLL_DIV3 bit fields */ |
| 148 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) |
| 149 | #define DA7210_PLL_BYP (1 << 6) |
| 150 | |
| 151 | /* PLL bit fields */ |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 152 | #define DA7210_PLL_FS_MASK (0xF << 0) |
| 153 | #define DA7210_PLL_FS_8000 (0x1 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 154 | #define DA7210_PLL_FS_11025 (0x2 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 155 | #define DA7210_PLL_FS_12000 (0x3 << 0) |
| 156 | #define DA7210_PLL_FS_16000 (0x5 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 157 | #define DA7210_PLL_FS_22050 (0x6 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 158 | #define DA7210_PLL_FS_24000 (0x7 << 0) |
| 159 | #define DA7210_PLL_FS_32000 (0x9 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 160 | #define DA7210_PLL_FS_44100 (0xA << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 161 | #define DA7210_PLL_FS_48000 (0xB << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 162 | #define DA7210_PLL_FS_88200 (0xE << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 163 | #define DA7210_PLL_FS_96000 (0xF << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 164 | #define DA7210_PLL_EN (0x1 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 165 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 166 | /* SOFTMUTE bit fields */ |
| 167 | #define DA7210_RAMP_EN (1 << 6) |
| 168 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 169 | /* CONTROL bit fields */ |
| 170 | #define DA7210_NOISE_SUP_EN (1 << 3) |
| 171 | |
| 172 | /* IN_GAIN bit fields */ |
| 173 | #define DA7210_INPGA_L_VOL (0x0F << 0) |
| 174 | #define DA7210_INPGA_R_VOL (0xF0 << 0) |
| 175 | |
| 176 | /* ZERO_CROSS bit fields */ |
| 177 | #define DA7210_AUX1_L_ZC (1 << 0) |
| 178 | #define DA7210_AUX1_R_ZC (1 << 1) |
| 179 | #define DA7210_HP_L_ZC (1 << 6) |
| 180 | #define DA7210_HP_R_ZC (1 << 7) |
| 181 | |
| 182 | /* AUX1_L bit fields */ |
| 183 | #define DA7210_AUX1_L_VOL (0x3F << 0) |
| 184 | |
| 185 | /* AUX1_R bit fields */ |
| 186 | #define DA7210_AUX1_R_VOL (0x3F << 0) |
| 187 | |
| 188 | /* Minimum INPGA and AUX1 volume to enable noise suppression */ |
| 189 | #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */ |
| 190 | #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */ |
| 191 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 192 | /* OUT1_L bit fields */ |
| 193 | #define DA7210_OUT1_L_EN (1 << 7) |
| 194 | |
| 195 | /* OUT1_R bit fields */ |
| 196 | #define DA7210_OUT1_R_EN (1 << 7) |
| 197 | |
| 198 | /* OUT2 bit fields */ |
| 199 | #define DA7210_OUT2_OUTMIX_R (1 << 5) |
| 200 | #define DA7210_OUT2_OUTMIX_L (1 << 6) |
| 201 | #define DA7210_OUT2_EN (1 << 7) |
| 202 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 203 | #define DA7210_VERSION "0.0.1" |
| 204 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 205 | /* |
| 206 | * Playback Volume |
| 207 | * |
| 208 | * max : 0x3F (+15.0 dB) |
| 209 | * (1.5 dB step) |
| 210 | * min : 0x11 (-54.0 dB) |
| 211 | * mute : 0x10 |
| 212 | * reserved : 0x00 - 0x0F |
| 213 | * |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 214 | * Reserved area are considered as "mute". |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 215 | */ |
Ashish Chavan | 7a0e67b | 2011-10-14 16:25:25 +0530 | [diff] [blame] | 216 | static const unsigned int hp_out_tlv[] = { |
| 217 | TLV_DB_RANGE_HEAD(2), |
| 218 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 219 | /* -54 dB to +15 dB */ |
| 220 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0), |
| 221 | }; |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 222 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 223 | static const unsigned int lineout_vol_tlv[] = { |
| 224 | TLV_DB_RANGE_HEAD(2), |
| 225 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 226 | /* -54dB to 15dB */ |
| 227 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0) |
| 228 | }; |
| 229 | |
| 230 | static const unsigned int mono_vol_tlv[] = { |
| 231 | TLV_DB_RANGE_HEAD(2), |
| 232 | 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1), |
| 233 | /* -18dB to 6dB */ |
| 234 | 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0) |
| 235 | }; |
| 236 | |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 237 | static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0); |
| 238 | 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^] | 239 | static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0); |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 240 | |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 241 | /* ADC and DAC high pass filter f0 value */ |
| 242 | static const char const *da7210_hpf_cutoff_txt[] = { |
| 243 | "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi" |
| 244 | }; |
| 245 | |
| 246 | static const struct soc_enum da7210_dac_hpf_cutoff = |
| 247 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt); |
| 248 | |
| 249 | static const struct soc_enum da7210_adc_hpf_cutoff = |
| 250 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt); |
| 251 | |
| 252 | /* ADC and DAC voice (8kHz) high pass cutoff value */ |
| 253 | static const char const *da7210_vf_cutoff_txt[] = { |
| 254 | "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" |
| 255 | }; |
| 256 | |
| 257 | static const struct soc_enum da7210_dac_vf_cutoff = |
| 258 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt); |
| 259 | |
| 260 | static const struct soc_enum da7210_adc_vf_cutoff = |
| 261 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt); |
| 262 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 263 | static const char *da7210_hp_mode_txt[] = { |
| 264 | "Class H", "Class G" |
| 265 | }; |
| 266 | |
| 267 | static const struct soc_enum da7210_hp_mode_sel = |
| 268 | SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt); |
| 269 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 270 | /* ALC can be enabled only if noise suppression is disabled */ |
| 271 | static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol, |
| 272 | struct snd_ctl_elem_value *ucontrol) |
| 273 | { |
| 274 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 275 | |
| 276 | if (ucontrol->value.integer.value[0]) { |
| 277 | /* Check if noise suppression is enabled */ |
| 278 | if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) { |
| 279 | dev_dbg(codec->dev, |
| 280 | "Disable noise suppression to enable ALC\n"); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | } |
| 284 | /* If all conditions are met or we are actually disabling ALC */ |
| 285 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 286 | } |
| 287 | |
| 288 | /* Noise suppression can be enabled only if following conditions are met |
| 289 | * ALC disabled |
| 290 | * ZC enabled for HP and AUX1 PGA |
| 291 | * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB |
| 292 | * AUX1_L_VOL and AUX1_R_VOL >= 6 dB |
| 293 | */ |
| 294 | static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol, |
| 295 | struct snd_ctl_elem_value *ucontrol) |
| 296 | { |
| 297 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 298 | u8 val; |
| 299 | |
| 300 | if (ucontrol->value.integer.value[0]) { |
| 301 | /* Check if ALC is enabled */ |
| 302 | if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN) |
| 303 | goto err; |
| 304 | |
| 305 | /* Check ZC for HP and AUX1 PGA */ |
| 306 | if ((snd_soc_read(codec, DA7210_ZERO_CROSS) & |
| 307 | (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | |
| 308 | DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC | |
| 309 | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC)) |
| 310 | goto err; |
| 311 | |
| 312 | /* Check INPGA_L_VOL and INPGA_R_VOL */ |
| 313 | val = snd_soc_read(codec, DA7210_IN_GAIN); |
| 314 | if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) || |
| 315 | (((val & DA7210_INPGA_R_VOL) >> 4) < |
| 316 | DA7210_INPGA_MIN_VOL_NS)) |
| 317 | goto err; |
| 318 | |
| 319 | /* Check AUX1_L_VOL and AUX1_R_VOL */ |
| 320 | if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) < |
| 321 | DA7210_AUX1_MIN_VOL_NS) || |
| 322 | ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) < |
| 323 | DA7210_AUX1_MIN_VOL_NS)) |
| 324 | goto err; |
| 325 | } |
| 326 | /* If all conditions are met or we are actually disabling Noise sup */ |
| 327 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 328 | |
| 329 | err: |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 333 | static const struct snd_kcontrol_new da7210_snd_controls[] = { |
| 334 | |
| 335 | SOC_DOUBLE_R_TLV("HeadPhone Playback Volume", |
| 336 | DA7210_HP_L_VOL, DA7210_HP_R_VOL, |
| 337 | 0, 0x3F, 0, hp_out_tlv), |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 338 | SOC_DOUBLE_R_TLV("Digital Playback Volume", |
| 339 | DA7210_DAC_L, DA7210_DAC_R, |
| 340 | 0, 0x77, 1, dac_gain_tlv), |
| 341 | SOC_DOUBLE_R_TLV("Lineout Playback Volume", |
| 342 | DA7210_OUT1_L, DA7210_OUT1_R, |
| 343 | 0, 0x3f, 0, lineout_vol_tlv), |
| 344 | SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0, |
| 345 | mono_vol_tlv), |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 346 | |
| 347 | /* DAC Equalizer controls */ |
| 348 | SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0), |
| 349 | SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1, |
| 350 | eq_gain_tlv), |
| 351 | SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1, |
| 352 | eq_gain_tlv), |
| 353 | SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1, |
| 354 | eq_gain_tlv), |
| 355 | SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1, |
| 356 | eq_gain_tlv), |
| 357 | SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1, |
| 358 | eq_gain_tlv), |
| 359 | |
| 360 | /* ADC Equalizer controls */ |
| 361 | SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0), |
| 362 | SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3, |
| 363 | 1, adc_eq_master_gain_tlv), |
| 364 | SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1, |
| 365 | eq_gain_tlv), |
| 366 | SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1, |
| 367 | eq_gain_tlv), |
| 368 | SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1, |
| 369 | eq_gain_tlv), |
| 370 | SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1, |
| 371 | eq_gain_tlv), |
| 372 | SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1, |
| 373 | eq_gain_tlv), |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 374 | |
| 375 | SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0), |
| 376 | SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff), |
| 377 | SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0), |
| 378 | SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff), |
| 379 | |
| 380 | SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0), |
| 381 | SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff), |
| 382 | SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0), |
| 383 | SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff), |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 384 | |
| 385 | /* Mute controls */ |
| 386 | SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0), |
| 387 | SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0), |
| 388 | SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0), |
| 389 | SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0), |
| 390 | SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0), |
| 391 | |
| 392 | /* Zero cross controls */ |
| 393 | SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0), |
| 394 | SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0), |
| 395 | SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0), |
| 396 | SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0), |
| 397 | |
| 398 | SOC_ENUM("Headphone Class", da7210_hp_mode_sel), |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame] | 399 | |
| 400 | /* ALC controls */ |
| 401 | SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0, |
| 402 | snd_soc_get_volsw, da7210_put_alc_sw), |
| 403 | SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0), |
| 404 | SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0), |
| 405 | SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0), |
| 406 | SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0), |
| 407 | SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0), |
| 408 | SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0), |
| 409 | |
| 410 | SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1, |
| 411 | 0, snd_soc_get_volsw, da7210_put_noise_sup_sw), |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 412 | }; |
| 413 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 414 | /* |
| 415 | * DAPM Controls |
| 416 | * |
| 417 | * Current DAPM implementation covers almost all codec components e.g. IOs, |
| 418 | * mixers, PGAs,ADC and DAC. |
| 419 | */ |
| 420 | /* In Mixer Left */ |
| 421 | static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = { |
| 422 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0), |
| 423 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0), |
| 424 | }; |
| 425 | |
| 426 | /* In Mixer Right */ |
| 427 | static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = { |
| 428 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0), |
| 429 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0), |
| 430 | }; |
| 431 | |
| 432 | /* Out Mixer Left */ |
| 433 | static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = { |
| 434 | SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0), |
| 435 | }; |
| 436 | |
| 437 | /* Out Mixer Right */ |
| 438 | static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = { |
| 439 | SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0), |
| 440 | }; |
| 441 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 442 | /* Mono Mixer */ |
| 443 | static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = { |
| 444 | SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0), |
| 445 | SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0), |
| 446 | }; |
| 447 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 448 | /* DAPM widgets */ |
| 449 | static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = { |
| 450 | /* Input Side */ |
| 451 | /* Input Lines */ |
| 452 | SND_SOC_DAPM_INPUT("MICL"), |
| 453 | SND_SOC_DAPM_INPUT("MICR"), |
| 454 | |
| 455 | /* Input PGAs */ |
| 456 | SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0), |
| 457 | SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0), |
| 458 | |
| 459 | SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0), |
| 460 | SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0), |
| 461 | |
| 462 | /* Input Mixers */ |
| 463 | SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0, |
| 464 | &da7210_dapm_inmixl_controls[0], |
| 465 | ARRAY_SIZE(da7210_dapm_inmixl_controls)), |
| 466 | |
| 467 | SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0, |
| 468 | &da7210_dapm_inmixr_controls[0], |
| 469 | ARRAY_SIZE(da7210_dapm_inmixr_controls)), |
| 470 | |
| 471 | /* ADCs */ |
| 472 | SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1), |
| 473 | SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1), |
| 474 | |
| 475 | /* Output Side */ |
| 476 | /* DACs */ |
| 477 | SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1), |
| 478 | SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1), |
| 479 | |
| 480 | /* Output Mixers */ |
| 481 | SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0, |
| 482 | &da7210_dapm_outmixl_controls[0], |
| 483 | ARRAY_SIZE(da7210_dapm_outmixl_controls)), |
| 484 | |
| 485 | SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0, |
| 486 | &da7210_dapm_outmixr_controls[0], |
| 487 | ARRAY_SIZE(da7210_dapm_outmixr_controls)), |
| 488 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 489 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, |
| 490 | &da7210_dapm_monomix_controls[0], |
| 491 | ARRAY_SIZE(da7210_dapm_monomix_controls)), |
| 492 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 493 | /* Output PGAs */ |
| 494 | SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0), |
| 495 | SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0), |
| 496 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 497 | SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0), |
| 498 | SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0), |
| 499 | SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 500 | SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0), |
| 501 | SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0), |
| 502 | |
| 503 | /* Output Lines */ |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 504 | SND_SOC_DAPM_OUTPUT("OUT1L"), |
| 505 | SND_SOC_DAPM_OUTPUT("OUT1R"), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 506 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 507 | SND_SOC_DAPM_OUTPUT("HPR"), |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 508 | SND_SOC_DAPM_OUTPUT("OUT2"), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | /* DAPM audio route definition */ |
| 512 | static const struct snd_soc_dapm_route da7210_audio_map[] = { |
| 513 | /* Dest Connecting Widget source */ |
| 514 | /* Input path */ |
| 515 | {"Mic Left", NULL, "MICL"}, |
| 516 | {"Mic Right", NULL, "MICR"}, |
| 517 | |
| 518 | {"In Mixer Left", "Mic Left Switch", "Mic Left"}, |
| 519 | {"In Mixer Left", "Mic Right Switch", "Mic Right"}, |
| 520 | |
| 521 | {"In Mixer Right", "Mic Right Switch", "Mic Right"}, |
| 522 | {"In Mixer Right", "Mic Left Switch", "Mic Left"}, |
| 523 | |
| 524 | {"INPGA Left", NULL, "In Mixer Left"}, |
| 525 | {"ADC Left", NULL, "INPGA Left"}, |
| 526 | |
| 527 | {"INPGA Right", NULL, "In Mixer Right"}, |
| 528 | {"ADC Right", NULL, "INPGA Right"}, |
| 529 | |
| 530 | /* Output path */ |
| 531 | {"Out Mixer Left", "DAC Left Switch", "DAC Left"}, |
| 532 | {"Out Mixer Right", "DAC Right Switch", "DAC Right"}, |
| 533 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 534 | {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"}, |
| 535 | {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"}, |
| 536 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 537 | {"OUTPGA Left Enable", NULL, "Out Mixer Left"}, |
| 538 | {"OUTPGA Right Enable", NULL, "Out Mixer Right"}, |
| 539 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 540 | {"Out1 Left", NULL, "OUTPGA Left Enable"}, |
| 541 | {"OUT1L", NULL, "Out1 Left"}, |
| 542 | |
| 543 | {"Out1 Right", NULL, "OUTPGA Right Enable"}, |
| 544 | {"OUT1R", NULL, "Out1 Right"}, |
| 545 | |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 546 | {"Headphone Left", NULL, "OUTPGA Left Enable"}, |
| 547 | {"HPL", NULL, "Headphone Left"}, |
| 548 | |
| 549 | {"Headphone Right", NULL, "OUTPGA Right Enable"}, |
| 550 | {"HPR", NULL, "Headphone Right"}, |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 551 | |
| 552 | {"Out2 Mono", NULL, "Mono Mixer"}, |
| 553 | {"OUT2", NULL, "Out2 Mono"}, |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 554 | }; |
| 555 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 556 | /* Codec private data */ |
| 557 | struct da7210_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 558 | enum snd_soc_control_type control_type; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 559 | }; |
| 560 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 561 | /* |
| 562 | * Register cache |
| 563 | */ |
| 564 | static const u8 da7210_reg[] = { |
| 565 | 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */ |
| 566 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */ |
| 567 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */ |
| 568 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */ |
| 569 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */ |
| 570 | 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */ |
| 571 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */ |
| 572 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */ |
| 573 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */ |
| 574 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */ |
| 575 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */ |
| 576 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */ |
| 577 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */ |
| 578 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */ |
| 579 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */ |
| 580 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */ |
| 581 | 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */ |
| 582 | 0x00, /* R88 */ |
| 583 | }; |
| 584 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 585 | static int da7210_volatile_register(struct snd_soc_codec *codec, |
| 586 | unsigned int reg) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 587 | { |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 588 | switch (reg) { |
| 589 | case DA7210_STATUS: |
| 590 | return 1; |
| 591 | default: |
| 592 | return 0; |
| 593 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 594 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * Set PCM DAI word length. |
| 598 | */ |
| 599 | static int da7210_hw_params(struct snd_pcm_substream *substream, |
| 600 | struct snd_pcm_hw_params *params, |
| 601 | struct snd_soc_dai *dai) |
| 602 | { |
| 603 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 604 | struct snd_soc_codec *codec = rtd->codec; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 605 | u32 dai_cfg1; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 606 | u32 fs, bypass; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 607 | |
| 608 | /* set DAI source to Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 609 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 610 | DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); |
| 611 | |
| 612 | /* Enable DAI */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 613 | snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 614 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 615 | dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 616 | |
| 617 | switch (params_format(params)) { |
| 618 | case SNDRV_PCM_FORMAT_S16_LE: |
| 619 | dai_cfg1 |= DA7210_DAI_WORD_S16_LE; |
| 620 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 621 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 622 | dai_cfg1 |= DA7210_DAI_WORD_S20_3LE; |
| 623 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 624 | case SNDRV_PCM_FORMAT_S24_LE: |
| 625 | dai_cfg1 |= DA7210_DAI_WORD_S24_LE; |
| 626 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 627 | case SNDRV_PCM_FORMAT_S32_LE: |
| 628 | dai_cfg1 |= DA7210_DAI_WORD_S32_LE; |
| 629 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 630 | default: |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 634 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 635 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 636 | switch (params_rate(params)) { |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 637 | case 8000: |
| 638 | fs = DA7210_PLL_FS_8000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 639 | bypass = DA7210_PLL_BYP; |
| 640 | break; |
| 641 | case 11025: |
| 642 | fs = DA7210_PLL_FS_11025; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 643 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 644 | break; |
| 645 | case 12000: |
| 646 | fs = DA7210_PLL_FS_12000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 647 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 648 | break; |
| 649 | case 16000: |
| 650 | fs = DA7210_PLL_FS_16000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 651 | bypass = DA7210_PLL_BYP; |
| 652 | break; |
| 653 | case 22050: |
| 654 | fs = DA7210_PLL_FS_22050; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 655 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 656 | break; |
| 657 | case 32000: |
| 658 | fs = DA7210_PLL_FS_32000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 659 | bypass = DA7210_PLL_BYP; |
| 660 | break; |
| 661 | case 44100: |
| 662 | fs = DA7210_PLL_FS_44100; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 663 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 664 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 665 | case 48000: |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 666 | fs = DA7210_PLL_FS_48000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 667 | bypass = DA7210_PLL_BYP; |
| 668 | break; |
| 669 | case 88200: |
| 670 | fs = DA7210_PLL_FS_88200; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 671 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 672 | break; |
| 673 | case 96000: |
| 674 | fs = DA7210_PLL_FS_96000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 675 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 676 | break; |
| 677 | default: |
| 678 | return -EINVAL; |
| 679 | } |
| 680 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 681 | /* Disable active mode */ |
| 682 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
| 683 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 684 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 685 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); |
| 686 | |
| 687 | /* Enable active mode */ |
| 688 | snd_soc_update_bits(codec, DA7210_STARTUP1, |
| 689 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | /* |
| 695 | * Set DAI mode and Format |
| 696 | */ |
| 697 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) |
| 698 | { |
| 699 | struct snd_soc_codec *codec = codec_dai->codec; |
| 700 | u32 dai_cfg1; |
| 701 | u32 dai_cfg3; |
| 702 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 703 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); |
| 704 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 705 | |
| 706 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 707 | case SND_SOC_DAIFMT_CBM_CFM: |
| 708 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; |
| 709 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 710 | case SND_SOC_DAIFMT_CBS_CFS: |
| 711 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; |
| 712 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 713 | default: |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
| 717 | /* FIXME |
| 718 | * |
| 719 | * It support I2S only now |
| 720 | */ |
| 721 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 722 | case SND_SOC_DAIFMT_I2S: |
| 723 | dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; |
| 724 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 725 | case SND_SOC_DAIFMT_LEFT_J: |
| 726 | dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J; |
| 727 | break; |
| 728 | case SND_SOC_DAIFMT_RIGHT_J: |
| 729 | dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J; |
| 730 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 731 | default: |
| 732 | return -EINVAL; |
| 733 | } |
| 734 | |
| 735 | /* FIXME |
| 736 | * |
| 737 | * It support 64bit data transmission only now |
| 738 | */ |
| 739 | dai_cfg1 |= DA7210_DAI_FLEN_64BIT; |
| 740 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 741 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
| 742 | snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 747 | static int da7210_mute(struct snd_soc_dai *dai, int mute) |
| 748 | { |
| 749 | struct snd_soc_codec *codec = dai->codec; |
| 750 | u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB; |
| 751 | |
| 752 | if (mute) |
| 753 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4); |
| 754 | else |
| 755 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg); |
| 756 | return 0; |
| 757 | } |
| 758 | |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 759 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 760 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 761 | |
| 762 | /* DAI operations */ |
| 763 | static struct snd_soc_dai_ops da7210_dai_ops = { |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 764 | .hw_params = da7210_hw_params, |
| 765 | .set_fmt = da7210_set_dai_fmt, |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 766 | .digital_mute = da7210_mute, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 767 | }; |
| 768 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 769 | static struct snd_soc_dai_driver da7210_dai = { |
| 770 | .name = "da7210-hifi", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 771 | /* playback capabilities */ |
| 772 | .playback = { |
| 773 | .stream_name = "Playback", |
| 774 | .channels_min = 1, |
| 775 | .channels_max = 2, |
| 776 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 777 | .formats = DA7210_FORMATS, |
| 778 | }, |
| 779 | /* capture capabilities */ |
| 780 | .capture = { |
| 781 | .stream_name = "Capture", |
| 782 | .channels_min = 1, |
| 783 | .channels_max = 2, |
| 784 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 785 | .formats = DA7210_FORMATS, |
| 786 | }, |
| 787 | .ops = &da7210_dai_ops, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 788 | .symmetric_rates = 1, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 789 | }; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 790 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 791 | static int da7210_probe(struct snd_soc_codec *codec) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 792 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 793 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 794 | int ret; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 795 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 796 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 797 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 798 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type); |
| 799 | if (ret < 0) { |
| 800 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 801 | return ret; |
| 802 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 803 | |
| 804 | /* FIXME |
| 805 | * |
| 806 | * This driver use fixed value here |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 807 | * And below settings expects MCLK = 12.288MHz |
| 808 | * |
| 809 | * When you select different MCLK, please check... |
| 810 | * DA7210_PLL_DIV1 val |
| 811 | * DA7210_PLL_DIV2 val |
| 812 | * DA7210_PLL_DIV3 val |
| 813 | * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 814 | */ |
| 815 | |
| 816 | /* |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 817 | * make sure that DA7210 use bypass mode before start up |
| 818 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 819 | snd_soc_write(codec, DA7210_STARTUP1, 0); |
| 820 | snd_soc_write(codec, DA7210_PLL_DIV3, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 821 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
| 822 | |
| 823 | /* |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 824 | * ADC settings |
| 825 | */ |
| 826 | |
| 827 | /* Enable Left & Right MIC PGA and Mic Bias */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 828 | snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); |
| 829 | snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 830 | |
| 831 | /* Enable Left and Right input PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 832 | snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); |
| 833 | snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 834 | |
| 835 | /* Enable Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 836 | snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 837 | |
| 838 | /* |
| 839 | * DAC settings |
| 840 | */ |
| 841 | |
| 842 | /* Enable Left and Right DAC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 843 | snd_soc_write(codec, DA7210_DAC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 844 | DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | |
| 845 | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); |
| 846 | |
| 847 | /* Enable Left and Right out PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 848 | snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); |
| 849 | snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 850 | |
| 851 | /* Enable Left and Right HeadPhone PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 852 | snd_soc_write(codec, DA7210_HP_CFG, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 853 | DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | |
| 854 | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); |
| 855 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 856 | /* Enable ramp mode for DAC gain update */ |
| 857 | snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN); |
| 858 | |
Ashish Chavan | 52082d8 | 2011-10-21 19:06:23 +0530 | [diff] [blame^] | 859 | /* |
| 860 | * For DA7210 codec, there are two ways to enable/disable analog IOs |
| 861 | * and ADC/DAC, |
| 862 | * (1) Using "Enable Bit" of register associated with that IO |
| 863 | * (or ADC/DAC) |
| 864 | * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg |
| 865 | * |
| 866 | * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register |
| 867 | * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5) |
| 868 | * |
| 869 | * Out of these two methods, the one using STANDBY bits is preferred |
| 870 | * way to enable/disable individual blocks. This is because STANDBY |
| 871 | * registers are part of system controller which allows system power |
| 872 | * up/down in a controlled, pop-free manner. Also, as per application |
| 873 | * note of DA7210, STANDBY register bits are only effective if a |
| 874 | * particular IO (or ADC/DAC) is already enabled using enable/disable |
| 875 | * register bits. Keeping these things in mind, current DAPM |
| 876 | * implementation manipulates only STANDBY bits. |
| 877 | * |
| 878 | * Overall implementation can be outlined as below, |
| 879 | * |
| 880 | * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe() |
| 881 | * - "STANDBY bit" is controlled by DAPM |
| 882 | */ |
| 883 | |
| 884 | /* Enable Line out amplifiers */ |
| 885 | snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN); |
| 886 | snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN); |
| 887 | snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN | |
| 888 | DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R); |
| 889 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 890 | /* Diable PLL and bypass it */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 891 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 892 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 893 | /* |
| 894 | * If 48kHz sound came, it use bypass mode, |
| 895 | * and when it is 44.1kHz, it use PLL. |
| 896 | * |
| 897 | * This time, this driver sets PLL always ON |
| 898 | * and controls bypass/PLL mode by switching |
| 899 | * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. |
| 900 | * see da7210_hw_params |
| 901 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 902 | snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ |
| 903 | snd_soc_write(codec, DA7210_PLL_DIV2, 0x99); |
| 904 | snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 905 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 906 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); |
| 907 | |
| 908 | /* As suggested by Dialog */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 909 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ |
| 910 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); |
| 911 | snd_soc_write(codec, DA7210_A_PLL1, 0x01); |
| 912 | snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C); |
| 913 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ |
| 914 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 915 | |
| 916 | /* Activate all enabled subsystem */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 917 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 918 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 919 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 920 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 921 | return 0; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 922 | } |
| 923 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 924 | static struct snd_soc_codec_driver soc_codec_dev_da7210 = { |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 925 | .probe = da7210_probe, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 926 | .reg_cache_size = ARRAY_SIZE(da7210_reg), |
| 927 | .reg_word_size = sizeof(u8), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 928 | .reg_cache_default = da7210_reg, |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 929 | .volatile_register = da7210_volatile_register, |
Mark Brown | a6f096f | 2011-10-14 20:18:49 +0100 | [diff] [blame] | 930 | |
| 931 | .controls = da7210_snd_controls, |
| 932 | .num_controls = ARRAY_SIZE(da7210_snd_controls), |
Ashish Chavan | 6950c60 | 2011-10-21 18:16:08 +0530 | [diff] [blame] | 933 | |
| 934 | .dapm_widgets = da7210_dapm_widgets, |
| 935 | .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets), |
| 936 | .dapm_routes = da7210_audio_map, |
| 937 | .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 938 | }; |
| 939 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 940 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 941 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, |
| 942 | const struct i2c_device_id *id) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 943 | { |
| 944 | struct da7210_priv *da7210; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 945 | int ret; |
| 946 | |
| 947 | da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL); |
| 948 | if (!da7210) |
| 949 | return -ENOMEM; |
| 950 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 951 | i2c_set_clientdata(i2c, da7210); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 952 | da7210->control_type = SND_SOC_I2C; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 953 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 954 | ret = snd_soc_register_codec(&i2c->dev, |
| 955 | &soc_codec_dev_da7210, &da7210_dai, 1); |
| 956 | if (ret < 0) |
Axel Lin | 085efd2 | 2010-07-23 05:53:45 +0000 | [diff] [blame] | 957 | kfree(da7210); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 958 | |
| 959 | return ret; |
| 960 | } |
| 961 | |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 962 | static int __devexit da7210_i2c_remove(struct i2c_client *client) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 963 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 964 | snd_soc_unregister_codec(&client->dev); |
| 965 | kfree(i2c_get_clientdata(client)); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static const struct i2c_device_id da7210_i2c_id[] = { |
| 970 | { "da7210", 0 }, |
| 971 | { } |
| 972 | }; |
| 973 | MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); |
| 974 | |
| 975 | /* I2C codec control layer */ |
| 976 | static struct i2c_driver da7210_i2c_driver = { |
| 977 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 978 | .name = "da7210-codec", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 979 | .owner = THIS_MODULE, |
| 980 | }, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 981 | .probe = da7210_i2c_probe, |
| 982 | .remove = __devexit_p(da7210_i2c_remove), |
| 983 | .id_table = da7210_i2c_id, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 984 | }; |
| 985 | #endif |
| 986 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 987 | static int __init da7210_modinit(void) |
| 988 | { |
| 989 | int ret = 0; |
| 990 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 991 | ret = i2c_add_driver(&da7210_i2c_driver); |
| 992 | #endif |
| 993 | return ret; |
| 994 | } |
| 995 | module_init(da7210_modinit); |
| 996 | |
| 997 | static void __exit da7210_exit(void) |
| 998 | { |
| 999 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1000 | i2c_del_driver(&da7210_i2c_driver); |
| 1001 | #endif |
| 1002 | } |
| 1003 | module_exit(da7210_exit); |
| 1004 | |
| 1005 | MODULE_DESCRIPTION("ASoC DA7210 driver"); |
| 1006 | MODULE_AUTHOR("David Chen, Kuninori Morimoto"); |
| 1007 | MODULE_LICENSE("GPL"); |