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