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