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 |
| 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 |
| 55 | #define DA7210_HP_L_VOL 0x21 |
| 56 | #define DA7210_HP_R_VOL 0x22 |
| 57 | #define DA7210_HP_CFG 0x23 |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 58 | #define DA7210_ZERO_CROSS 0x24 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 59 | #define DA7210_DAI_SRC_SEL 0x25 |
| 60 | #define DA7210_DAI_CFG1 0x26 |
| 61 | #define DA7210_DAI_CFG3 0x28 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 62 | #define DA7210_PLL_DIV1 0x29 |
| 63 | #define DA7210_PLL_DIV2 0x2A |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 64 | #define DA7210_PLL_DIV3 0x2B |
| 65 | #define DA7210_PLL 0x2C |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame^] | 66 | #define DA7210_ALC_MAX 0x83 |
| 67 | #define DA7210_ALC_MIN 0x84 |
| 68 | #define DA7210_ALC_NOIS 0x85 |
| 69 | #define DA7210_ALC_ATT 0x86 |
| 70 | #define DA7210_ALC_REL 0x87 |
| 71 | #define DA7210_ALC_DEL 0x88 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 72 | #define DA7210_A_HID_UNLOCK 0x8A |
| 73 | #define DA7210_A_TEST_UNLOCK 0x8B |
| 74 | #define DA7210_A_PLL1 0x90 |
| 75 | #define DA7210_A_CP_MODE 0xA7 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 76 | |
| 77 | /* STARTUP1 bit fields */ |
| 78 | #define DA7210_SC_MST_EN (1 << 0) |
| 79 | |
| 80 | /* MIC_L bit fields */ |
| 81 | #define DA7210_MICBIAS_EN (1 << 6) |
| 82 | #define DA7210_MIC_L_EN (1 << 7) |
| 83 | |
| 84 | /* MIC_R bit fields */ |
| 85 | #define DA7210_MIC_R_EN (1 << 7) |
| 86 | |
| 87 | /* INMIX_L bit fields */ |
| 88 | #define DA7210_IN_L_EN (1 << 7) |
| 89 | |
| 90 | /* INMIX_R bit fields */ |
| 91 | #define DA7210_IN_R_EN (1 << 7) |
| 92 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 93 | /* ADC bit fields */ |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame^] | 94 | #define DA7210_ADC_ALC_EN (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 95 | #define DA7210_ADC_L_EN (1 << 3) |
| 96 | #define DA7210_ADC_R_EN (1 << 7) |
| 97 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 98 | /* DAC/ADC HPF fields */ |
| 99 | #define DA7210_VOICE_F0_MASK (0x7 << 4) |
| 100 | #define DA7210_VOICE_F0_25 (1 << 4) |
| 101 | #define DA7210_VOICE_EN (1 << 7) |
Mark Brown | c215143 | 2009-12-16 20:36:37 +0000 | [diff] [blame] | 102 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 103 | /* DAC_SEL bit fields */ |
| 104 | #define DA7210_DAC_L_SRC_DAI_L (4 << 0) |
| 105 | #define DA7210_DAC_L_EN (1 << 3) |
| 106 | #define DA7210_DAC_R_SRC_DAI_R (5 << 4) |
| 107 | #define DA7210_DAC_R_EN (1 << 7) |
| 108 | |
| 109 | /* OUTMIX_L bit fields */ |
| 110 | #define DA7210_OUT_L_EN (1 << 7) |
| 111 | |
| 112 | /* OUTMIX_R bit fields */ |
| 113 | #define DA7210_OUT_R_EN (1 << 7) |
| 114 | |
| 115 | /* HP_CFG bit fields */ |
| 116 | #define DA7210_HP_2CAP_MODE (1 << 1) |
| 117 | #define DA7210_HP_SENSE_EN (1 << 2) |
| 118 | #define DA7210_HP_L_EN (1 << 3) |
| 119 | #define DA7210_HP_MODE (1 << 6) |
| 120 | #define DA7210_HP_R_EN (1 << 7) |
| 121 | |
| 122 | /* DAI_SRC_SEL bit fields */ |
| 123 | #define DA7210_DAI_OUT_L_SRC (6 << 0) |
| 124 | #define DA7210_DAI_OUT_R_SRC (7 << 4) |
| 125 | |
| 126 | /* DAI_CFG1 bit fields */ |
| 127 | #define DA7210_DAI_WORD_S16_LE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 128 | #define DA7210_DAI_WORD_S20_3LE (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 129 | #define DA7210_DAI_WORD_S24_LE (2 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 130 | #define DA7210_DAI_WORD_S32_LE (3 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 131 | #define DA7210_DAI_FLEN_64BIT (1 << 2) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 132 | #define DA7210_DAI_MODE_SLAVE (0 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 133 | #define DA7210_DAI_MODE_MASTER (1 << 7) |
| 134 | |
| 135 | /* DAI_CFG3 bit fields */ |
| 136 | #define DA7210_DAI_FORMAT_I2SMODE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 137 | #define DA7210_DAI_FORMAT_LEFT_J (1 << 0) |
| 138 | #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 139 | #define DA7210_DAI_OE (1 << 3) |
| 140 | #define DA7210_DAI_EN (1 << 7) |
| 141 | |
| 142 | /*PLL_DIV3 bit fields */ |
| 143 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) |
| 144 | #define DA7210_PLL_BYP (1 << 6) |
| 145 | |
| 146 | /* PLL bit fields */ |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 147 | #define DA7210_PLL_FS_MASK (0xF << 0) |
| 148 | #define DA7210_PLL_FS_8000 (0x1 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 149 | #define DA7210_PLL_FS_11025 (0x2 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 150 | #define DA7210_PLL_FS_12000 (0x3 << 0) |
| 151 | #define DA7210_PLL_FS_16000 (0x5 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 152 | #define DA7210_PLL_FS_22050 (0x6 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 153 | #define DA7210_PLL_FS_24000 (0x7 << 0) |
| 154 | #define DA7210_PLL_FS_32000 (0x9 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 155 | #define DA7210_PLL_FS_44100 (0xA << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 156 | #define DA7210_PLL_FS_48000 (0xB << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 157 | #define DA7210_PLL_FS_88200 (0xE << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 158 | #define DA7210_PLL_FS_96000 (0xF << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 159 | #define DA7210_PLL_EN (0x1 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 160 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 161 | /* SOFTMUTE bit fields */ |
| 162 | #define DA7210_RAMP_EN (1 << 6) |
| 163 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame^] | 164 | /* CONTROL bit fields */ |
| 165 | #define DA7210_NOISE_SUP_EN (1 << 3) |
| 166 | |
| 167 | /* IN_GAIN bit fields */ |
| 168 | #define DA7210_INPGA_L_VOL (0x0F << 0) |
| 169 | #define DA7210_INPGA_R_VOL (0xF0 << 0) |
| 170 | |
| 171 | /* ZERO_CROSS bit fields */ |
| 172 | #define DA7210_AUX1_L_ZC (1 << 0) |
| 173 | #define DA7210_AUX1_R_ZC (1 << 1) |
| 174 | #define DA7210_HP_L_ZC (1 << 6) |
| 175 | #define DA7210_HP_R_ZC (1 << 7) |
| 176 | |
| 177 | /* AUX1_L bit fields */ |
| 178 | #define DA7210_AUX1_L_VOL (0x3F << 0) |
| 179 | |
| 180 | /* AUX1_R bit fields */ |
| 181 | #define DA7210_AUX1_R_VOL (0x3F << 0) |
| 182 | |
| 183 | /* Minimum INPGA and AUX1 volume to enable noise suppression */ |
| 184 | #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */ |
| 185 | #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */ |
| 186 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 187 | #define DA7210_VERSION "0.0.1" |
| 188 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 189 | /* |
| 190 | * Playback Volume |
| 191 | * |
| 192 | * max : 0x3F (+15.0 dB) |
| 193 | * (1.5 dB step) |
| 194 | * min : 0x11 (-54.0 dB) |
| 195 | * mute : 0x10 |
| 196 | * reserved : 0x00 - 0x0F |
| 197 | * |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 198 | * Reserved area are considered as "mute". |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 199 | */ |
Ashish Chavan | 7a0e67b | 2011-10-14 16:25:25 +0530 | [diff] [blame] | 200 | static const unsigned int hp_out_tlv[] = { |
| 201 | TLV_DB_RANGE_HEAD(2), |
| 202 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 203 | /* -54 dB to +15 dB */ |
| 204 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0), |
| 205 | }; |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 206 | |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 207 | static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0); |
| 208 | static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1); |
| 209 | |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 210 | /* ADC and DAC high pass filter f0 value */ |
| 211 | static const char const *da7210_hpf_cutoff_txt[] = { |
| 212 | "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi" |
| 213 | }; |
| 214 | |
| 215 | static const struct soc_enum da7210_dac_hpf_cutoff = |
| 216 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt); |
| 217 | |
| 218 | static const struct soc_enum da7210_adc_hpf_cutoff = |
| 219 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt); |
| 220 | |
| 221 | /* ADC and DAC voice (8kHz) high pass cutoff value */ |
| 222 | static const char const *da7210_vf_cutoff_txt[] = { |
| 223 | "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" |
| 224 | }; |
| 225 | |
| 226 | static const struct soc_enum da7210_dac_vf_cutoff = |
| 227 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt); |
| 228 | |
| 229 | static const struct soc_enum da7210_adc_vf_cutoff = |
| 230 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt); |
| 231 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 232 | static const char *da7210_hp_mode_txt[] = { |
| 233 | "Class H", "Class G" |
| 234 | }; |
| 235 | |
| 236 | static const struct soc_enum da7210_hp_mode_sel = |
| 237 | SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt); |
| 238 | |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame^] | 239 | /* ALC can be enabled only if noise suppression is disabled */ |
| 240 | static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol, |
| 241 | struct snd_ctl_elem_value *ucontrol) |
| 242 | { |
| 243 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 244 | |
| 245 | if (ucontrol->value.integer.value[0]) { |
| 246 | /* Check if noise suppression is enabled */ |
| 247 | if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) { |
| 248 | dev_dbg(codec->dev, |
| 249 | "Disable noise suppression to enable ALC\n"); |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | } |
| 253 | /* If all conditions are met or we are actually disabling ALC */ |
| 254 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 255 | } |
| 256 | |
| 257 | /* Noise suppression can be enabled only if following conditions are met |
| 258 | * ALC disabled |
| 259 | * ZC enabled for HP and AUX1 PGA |
| 260 | * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB |
| 261 | * AUX1_L_VOL and AUX1_R_VOL >= 6 dB |
| 262 | */ |
| 263 | static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol, |
| 264 | struct snd_ctl_elem_value *ucontrol) |
| 265 | { |
| 266 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 267 | u8 val; |
| 268 | |
| 269 | if (ucontrol->value.integer.value[0]) { |
| 270 | /* Check if ALC is enabled */ |
| 271 | if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN) |
| 272 | goto err; |
| 273 | |
| 274 | /* Check ZC for HP and AUX1 PGA */ |
| 275 | if ((snd_soc_read(codec, DA7210_ZERO_CROSS) & |
| 276 | (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | |
| 277 | DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC | |
| 278 | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC)) |
| 279 | goto err; |
| 280 | |
| 281 | /* Check INPGA_L_VOL and INPGA_R_VOL */ |
| 282 | val = snd_soc_read(codec, DA7210_IN_GAIN); |
| 283 | if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) || |
| 284 | (((val & DA7210_INPGA_R_VOL) >> 4) < |
| 285 | DA7210_INPGA_MIN_VOL_NS)) |
| 286 | goto err; |
| 287 | |
| 288 | /* Check AUX1_L_VOL and AUX1_R_VOL */ |
| 289 | if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) < |
| 290 | DA7210_AUX1_MIN_VOL_NS) || |
| 291 | ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) < |
| 292 | DA7210_AUX1_MIN_VOL_NS)) |
| 293 | goto err; |
| 294 | } |
| 295 | /* If all conditions are met or we are actually disabling Noise sup */ |
| 296 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 297 | |
| 298 | err: |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 302 | static const struct snd_kcontrol_new da7210_snd_controls[] = { |
| 303 | |
| 304 | SOC_DOUBLE_R_TLV("HeadPhone Playback Volume", |
| 305 | DA7210_HP_L_VOL, DA7210_HP_R_VOL, |
| 306 | 0, 0x3F, 0, hp_out_tlv), |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame] | 307 | |
| 308 | /* DAC Equalizer controls */ |
| 309 | SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0), |
| 310 | SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1, |
| 311 | eq_gain_tlv), |
| 312 | SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1, |
| 313 | eq_gain_tlv), |
| 314 | SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1, |
| 315 | eq_gain_tlv), |
| 316 | SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1, |
| 317 | eq_gain_tlv), |
| 318 | SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1, |
| 319 | eq_gain_tlv), |
| 320 | |
| 321 | /* ADC Equalizer controls */ |
| 322 | SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0), |
| 323 | SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3, |
| 324 | 1, adc_eq_master_gain_tlv), |
| 325 | SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1, |
| 326 | eq_gain_tlv), |
| 327 | SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1, |
| 328 | eq_gain_tlv), |
| 329 | SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1, |
| 330 | eq_gain_tlv), |
| 331 | SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1, |
| 332 | eq_gain_tlv), |
| 333 | SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1, |
| 334 | eq_gain_tlv), |
Ashish Chavan | 4ced2b9 | 2011-10-15 14:50:06 +0530 | [diff] [blame] | 335 | |
| 336 | SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0), |
| 337 | SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff), |
| 338 | SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0), |
| 339 | SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff), |
| 340 | |
| 341 | SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0), |
| 342 | SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff), |
| 343 | SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0), |
| 344 | SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff), |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 345 | |
| 346 | /* Mute controls */ |
| 347 | SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0), |
| 348 | SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0), |
| 349 | SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0), |
| 350 | SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0), |
| 351 | SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0), |
| 352 | |
| 353 | /* Zero cross controls */ |
| 354 | SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0), |
| 355 | SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0), |
| 356 | SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0), |
| 357 | SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0), |
| 358 | |
| 359 | SOC_ENUM("Headphone Class", da7210_hp_mode_sel), |
Ashish Chavan | de5eaf8 | 2011-10-19 14:24:37 +0530 | [diff] [blame^] | 360 | |
| 361 | /* ALC controls */ |
| 362 | SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0, |
| 363 | snd_soc_get_volsw, da7210_put_alc_sw), |
| 364 | SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0), |
| 365 | SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0), |
| 366 | SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0), |
| 367 | SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0), |
| 368 | SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0), |
| 369 | SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0), |
| 370 | |
| 371 | SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1, |
| 372 | 0, snd_soc_get_volsw, da7210_put_noise_sup_sw), |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 373 | }; |
| 374 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 375 | /* Codec private data */ |
| 376 | struct da7210_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 377 | enum snd_soc_control_type control_type; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 378 | }; |
| 379 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 380 | /* |
| 381 | * Register cache |
| 382 | */ |
| 383 | static const u8 da7210_reg[] = { |
| 384 | 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */ |
| 385 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */ |
| 386 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */ |
| 387 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */ |
| 388 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */ |
| 389 | 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */ |
| 390 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */ |
| 391 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */ |
| 392 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */ |
| 393 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */ |
| 394 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */ |
| 395 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */ |
| 396 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */ |
| 397 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */ |
| 398 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */ |
| 399 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */ |
| 400 | 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */ |
| 401 | 0x00, /* R88 */ |
| 402 | }; |
| 403 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 404 | static int da7210_volatile_register(struct snd_soc_codec *codec, |
| 405 | unsigned int reg) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 406 | { |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 407 | switch (reg) { |
| 408 | case DA7210_STATUS: |
| 409 | return 1; |
| 410 | default: |
| 411 | return 0; |
| 412 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 413 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 414 | static int da7210_startup(struct snd_pcm_substream *substream, |
| 415 | struct snd_soc_dai *dai) |
| 416 | { |
| 417 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 418 | struct snd_soc_codec *codec = dai->codec; |
| 419 | |
| 420 | if (is_play) { |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 421 | /* Enable Out */ |
| 422 | snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10); |
| 423 | snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10); |
| 424 | |
| 425 | } else { |
| 426 | /* Volume 7 */ |
| 427 | snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7); |
| 428 | snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7); |
| 429 | |
| 430 | /* Enable Mic */ |
| 431 | snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1); |
| 432 | snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1); |
| 433 | } |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | /* |
| 439 | * Set PCM DAI word length. |
| 440 | */ |
| 441 | static int da7210_hw_params(struct snd_pcm_substream *substream, |
| 442 | struct snd_pcm_hw_params *params, |
| 443 | struct snd_soc_dai *dai) |
| 444 | { |
| 445 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 446 | struct snd_soc_codec *codec = rtd->codec; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 447 | u32 dai_cfg1; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 448 | u32 fs, bypass; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 449 | |
| 450 | /* set DAI source to Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 451 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 452 | DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); |
| 453 | |
| 454 | /* Enable DAI */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 455 | 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] | 456 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 457 | dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 458 | |
| 459 | switch (params_format(params)) { |
| 460 | case SNDRV_PCM_FORMAT_S16_LE: |
| 461 | dai_cfg1 |= DA7210_DAI_WORD_S16_LE; |
| 462 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 463 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 464 | dai_cfg1 |= DA7210_DAI_WORD_S20_3LE; |
| 465 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 466 | case SNDRV_PCM_FORMAT_S24_LE: |
| 467 | dai_cfg1 |= DA7210_DAI_WORD_S24_LE; |
| 468 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 469 | case SNDRV_PCM_FORMAT_S32_LE: |
| 470 | dai_cfg1 |= DA7210_DAI_WORD_S32_LE; |
| 471 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 472 | default: |
| 473 | return -EINVAL; |
| 474 | } |
| 475 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 476 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 477 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 478 | switch (params_rate(params)) { |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 479 | case 8000: |
| 480 | fs = DA7210_PLL_FS_8000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 481 | bypass = DA7210_PLL_BYP; |
| 482 | break; |
| 483 | case 11025: |
| 484 | fs = DA7210_PLL_FS_11025; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 485 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 486 | break; |
| 487 | case 12000: |
| 488 | fs = DA7210_PLL_FS_12000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 489 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 490 | break; |
| 491 | case 16000: |
| 492 | fs = DA7210_PLL_FS_16000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 493 | bypass = DA7210_PLL_BYP; |
| 494 | break; |
| 495 | case 22050: |
| 496 | fs = DA7210_PLL_FS_22050; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 497 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 498 | break; |
| 499 | case 32000: |
| 500 | fs = DA7210_PLL_FS_32000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 501 | bypass = DA7210_PLL_BYP; |
| 502 | break; |
| 503 | case 44100: |
| 504 | fs = DA7210_PLL_FS_44100; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 505 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 506 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 507 | case 48000: |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 508 | fs = DA7210_PLL_FS_48000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 509 | bypass = DA7210_PLL_BYP; |
| 510 | break; |
| 511 | case 88200: |
| 512 | fs = DA7210_PLL_FS_88200; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 513 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 514 | break; |
| 515 | case 96000: |
| 516 | fs = DA7210_PLL_FS_96000; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 517 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 518 | break; |
| 519 | default: |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 523 | /* Disable active mode */ |
| 524 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
| 525 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 526 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 527 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); |
| 528 | |
| 529 | /* Enable active mode */ |
| 530 | snd_soc_update_bits(codec, DA7210_STARTUP1, |
| 531 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * Set DAI mode and Format |
| 538 | */ |
| 539 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) |
| 540 | { |
| 541 | struct snd_soc_codec *codec = codec_dai->codec; |
| 542 | u32 dai_cfg1; |
| 543 | u32 dai_cfg3; |
| 544 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 545 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); |
| 546 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 547 | |
| 548 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 549 | case SND_SOC_DAIFMT_CBM_CFM: |
| 550 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; |
| 551 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 552 | case SND_SOC_DAIFMT_CBS_CFS: |
| 553 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; |
| 554 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 555 | default: |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | /* FIXME |
| 560 | * |
| 561 | * It support I2S only now |
| 562 | */ |
| 563 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 564 | case SND_SOC_DAIFMT_I2S: |
| 565 | dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; |
| 566 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 567 | case SND_SOC_DAIFMT_LEFT_J: |
| 568 | dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J; |
| 569 | break; |
| 570 | case SND_SOC_DAIFMT_RIGHT_J: |
| 571 | dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J; |
| 572 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 573 | default: |
| 574 | return -EINVAL; |
| 575 | } |
| 576 | |
| 577 | /* FIXME |
| 578 | * |
| 579 | * It support 64bit data transmission only now |
| 580 | */ |
| 581 | dai_cfg1 |= DA7210_DAI_FLEN_64BIT; |
| 582 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 583 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
| 584 | snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 589 | static int da7210_mute(struct snd_soc_dai *dai, int mute) |
| 590 | { |
| 591 | struct snd_soc_codec *codec = dai->codec; |
| 592 | u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB; |
| 593 | |
| 594 | if (mute) |
| 595 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4); |
| 596 | else |
| 597 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg); |
| 598 | return 0; |
| 599 | } |
| 600 | |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 601 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 602 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 603 | |
| 604 | /* DAI operations */ |
| 605 | static struct snd_soc_dai_ops da7210_dai_ops = { |
| 606 | .startup = da7210_startup, |
| 607 | .hw_params = da7210_hw_params, |
| 608 | .set_fmt = da7210_set_dai_fmt, |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 609 | .digital_mute = da7210_mute, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 610 | }; |
| 611 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 612 | static struct snd_soc_dai_driver da7210_dai = { |
| 613 | .name = "da7210-hifi", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 614 | /* playback capabilities */ |
| 615 | .playback = { |
| 616 | .stream_name = "Playback", |
| 617 | .channels_min = 1, |
| 618 | .channels_max = 2, |
| 619 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 620 | .formats = DA7210_FORMATS, |
| 621 | }, |
| 622 | /* capture capabilities */ |
| 623 | .capture = { |
| 624 | .stream_name = "Capture", |
| 625 | .channels_min = 1, |
| 626 | .channels_max = 2, |
| 627 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 628 | .formats = DA7210_FORMATS, |
| 629 | }, |
| 630 | .ops = &da7210_dai_ops, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 631 | .symmetric_rates = 1, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 632 | }; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 633 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 634 | static int da7210_probe(struct snd_soc_codec *codec) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 635 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 636 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 637 | int ret; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 638 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 639 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 640 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 641 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type); |
| 642 | if (ret < 0) { |
| 643 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 644 | return ret; |
| 645 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 646 | |
| 647 | /* FIXME |
| 648 | * |
| 649 | * This driver use fixed value here |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 650 | * And below settings expects MCLK = 12.288MHz |
| 651 | * |
| 652 | * When you select different MCLK, please check... |
| 653 | * DA7210_PLL_DIV1 val |
| 654 | * DA7210_PLL_DIV2 val |
| 655 | * DA7210_PLL_DIV3 val |
| 656 | * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 657 | */ |
| 658 | |
| 659 | /* |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 660 | * make sure that DA7210 use bypass mode before start up |
| 661 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 662 | snd_soc_write(codec, DA7210_STARTUP1, 0); |
| 663 | snd_soc_write(codec, DA7210_PLL_DIV3, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 664 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
| 665 | |
| 666 | /* |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 667 | * ADC settings |
| 668 | */ |
| 669 | |
| 670 | /* Enable Left & Right MIC PGA and Mic Bias */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 671 | snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); |
| 672 | snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 673 | |
| 674 | /* Enable Left and Right input PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 675 | snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); |
| 676 | snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 677 | |
| 678 | /* Enable Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 679 | 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] | 680 | |
| 681 | /* |
| 682 | * DAC settings |
| 683 | */ |
| 684 | |
| 685 | /* Enable Left and Right DAC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 686 | snd_soc_write(codec, DA7210_DAC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 687 | DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | |
| 688 | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); |
| 689 | |
| 690 | /* Enable Left and Right out PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 691 | snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); |
| 692 | snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 693 | |
| 694 | /* Enable Left and Right HeadPhone PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 695 | snd_soc_write(codec, DA7210_HP_CFG, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 696 | DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | |
| 697 | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); |
| 698 | |
Ashish Chavan | 5eda194 | 2011-10-19 14:19:06 +0530 | [diff] [blame] | 699 | /* Enable ramp mode for DAC gain update */ |
| 700 | snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN); |
| 701 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 702 | /* Diable PLL and bypass it */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 703 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 704 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 705 | /* |
| 706 | * If 48kHz sound came, it use bypass mode, |
| 707 | * and when it is 44.1kHz, it use PLL. |
| 708 | * |
| 709 | * This time, this driver sets PLL always ON |
| 710 | * and controls bypass/PLL mode by switching |
| 711 | * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. |
| 712 | * see da7210_hw_params |
| 713 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 714 | snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ |
| 715 | snd_soc_write(codec, DA7210_PLL_DIV2, 0x99); |
| 716 | snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 717 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 718 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); |
| 719 | |
| 720 | /* As suggested by Dialog */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 721 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ |
| 722 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); |
| 723 | snd_soc_write(codec, DA7210_A_PLL1, 0x01); |
| 724 | snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C); |
| 725 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ |
| 726 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 727 | |
| 728 | /* Activate all enabled subsystem */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 729 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 730 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 731 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 732 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 733 | return 0; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 734 | } |
| 735 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 736 | static struct snd_soc_codec_driver soc_codec_dev_da7210 = { |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 737 | .probe = da7210_probe, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 738 | .reg_cache_size = ARRAY_SIZE(da7210_reg), |
| 739 | .reg_word_size = sizeof(u8), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 740 | .reg_cache_default = da7210_reg, |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 741 | .volatile_register = da7210_volatile_register, |
Mark Brown | a6f096f | 2011-10-14 20:18:49 +0100 | [diff] [blame] | 742 | |
| 743 | .controls = da7210_snd_controls, |
| 744 | .num_controls = ARRAY_SIZE(da7210_snd_controls), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 745 | }; |
| 746 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 747 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 748 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, |
| 749 | const struct i2c_device_id *id) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 750 | { |
| 751 | struct da7210_priv *da7210; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 752 | int ret; |
| 753 | |
| 754 | da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL); |
| 755 | if (!da7210) |
| 756 | return -ENOMEM; |
| 757 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 758 | i2c_set_clientdata(i2c, da7210); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 759 | da7210->control_type = SND_SOC_I2C; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 760 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 761 | ret = snd_soc_register_codec(&i2c->dev, |
| 762 | &soc_codec_dev_da7210, &da7210_dai, 1); |
| 763 | if (ret < 0) |
Axel Lin | 085efd2 | 2010-07-23 05:53:45 +0000 | [diff] [blame] | 764 | kfree(da7210); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 765 | |
| 766 | return ret; |
| 767 | } |
| 768 | |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 769 | static int __devexit da7210_i2c_remove(struct i2c_client *client) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 770 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 771 | snd_soc_unregister_codec(&client->dev); |
| 772 | kfree(i2c_get_clientdata(client)); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static const struct i2c_device_id da7210_i2c_id[] = { |
| 777 | { "da7210", 0 }, |
| 778 | { } |
| 779 | }; |
| 780 | MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); |
| 781 | |
| 782 | /* I2C codec control layer */ |
| 783 | static struct i2c_driver da7210_i2c_driver = { |
| 784 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 785 | .name = "da7210-codec", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 786 | .owner = THIS_MODULE, |
| 787 | }, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 788 | .probe = da7210_i2c_probe, |
| 789 | .remove = __devexit_p(da7210_i2c_remove), |
| 790 | .id_table = da7210_i2c_id, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 791 | }; |
| 792 | #endif |
| 793 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 794 | static int __init da7210_modinit(void) |
| 795 | { |
| 796 | int ret = 0; |
| 797 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 798 | ret = i2c_add_driver(&da7210_i2c_driver); |
| 799 | #endif |
| 800 | return ret; |
| 801 | } |
| 802 | module_init(da7210_modinit); |
| 803 | |
| 804 | static void __exit da7210_exit(void) |
| 805 | { |
| 806 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 807 | i2c_del_driver(&da7210_i2c_driver); |
| 808 | #endif |
| 809 | } |
| 810 | module_exit(da7210_exit); |
| 811 | |
| 812 | MODULE_DESCRIPTION("ASoC DA7210 driver"); |
| 813 | MODULE_AUTHOR("David Chen, Kuninori Morimoto"); |
| 814 | MODULE_LICENSE("GPL"); |