Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * alc5632.c -- ALC5632 ALSA SoC Audio Codec |
| 3 | * |
| 4 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> |
| 5 | * |
| 6 | * Authors: Leon Romanovsky <leon@leon.nu> |
| 7 | * Andrey Danin <danindrey@mail.ru> |
| 8 | * Ilya Petrov <ilya.muromec@gmail.com> |
| 9 | * Marc Dietrich <marvin24@gmx.de> |
| 10 | * |
| 11 | * Based on alc5623.c by Arnaud Patard |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/pm.h> |
| 23 | #include <linux/i2c.h> |
| 24 | #include <linux/slab.h> |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 25 | #include <linux/regmap.h> |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/pcm_params.h> |
| 29 | #include <sound/tlv.h> |
| 30 | #include <sound/soc.h> |
| 31 | #include <sound/initval.h> |
| 32 | |
| 33 | #include "alc5632.h" |
| 34 | |
| 35 | /* |
| 36 | * ALC5632 register cache |
| 37 | */ |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 38 | static struct reg_default alc5632_reg_defaults[] = { |
Leon Romanovsky | 43fa8e5 | 2011-11-17 12:01:28 +0200 | [diff] [blame] | 39 | { 2, 0x8080 }, /* R2 - Speaker Output Volume */ |
| 40 | { 4, 0x8080 }, /* R4 - Headphone Output Volume */ |
| 41 | { 6, 0x8080 }, /* R6 - AUXOUT Volume */ |
| 42 | { 8, 0xC800 }, /* R8 - Phone Input */ |
| 43 | { 10, 0xE808 }, /* R10 - LINE_IN Volume */ |
| 44 | { 12, 0x1010 }, /* R12 - STEREO DAC Input Volume */ |
| 45 | { 14, 0x0808 }, /* R14 - MIC Input Volume */ |
| 46 | { 16, 0xEE0F }, /* R16 - Stereo DAC and MIC Routing Control */ |
| 47 | { 18, 0xCBCB }, /* R18 - ADC Record Gain */ |
| 48 | { 20, 0x7F7F }, /* R20 - ADC Record Mixer Control */ |
| 49 | { 24, 0xE010 }, /* R24 - Voice DAC Volume */ |
| 50 | { 28, 0x8008 }, /* R28 - Output Mixer Control */ |
| 51 | { 34, 0x0000 }, /* R34 - Microphone Control */ |
| 52 | { 36, 0x00C0 }, /* R36 - Codec Digital MIC/Digital Boost |
| 53 | Control */ |
Leon Romanovsky | 43fa8e5 | 2011-11-17 12:01:28 +0200 | [diff] [blame] | 54 | { 46, 0x0000 }, /* R46 - Stereo DAC/Voice DAC/Stereo ADC |
| 55 | Function Select */ |
| 56 | { 52, 0x8000 }, /* R52 - Main Serial Data Port Control |
| 57 | (Stereo I2S) */ |
| 58 | { 54, 0x0000 }, /* R54 - Extend Serial Data Port Control |
| 59 | (VoDAC_I2S/PCM) */ |
| 60 | { 58, 0x0000 }, /* R58 - Power Management Addition 1 */ |
| 61 | { 60, 0x0000 }, /* R60 - Power Management Addition 2 */ |
| 62 | { 62, 0x8000 }, /* R62 - Power Management Addition 3 */ |
| 63 | { 64, 0x0C0A }, /* R64 - General Purpose Control Register 1 */ |
| 64 | { 66, 0x0000 }, /* R66 - General Purpose Control Register 2 */ |
| 65 | { 68, 0x0000 }, /* R68 - PLL1 Control */ |
| 66 | { 70, 0x0000 }, /* R70 - PLL2 Control */ |
| 67 | { 76, 0xBE3E }, /* R76 - GPIO Pin Configuration */ |
| 68 | { 78, 0xBE3E }, /* R78 - GPIO Pin Polarity */ |
| 69 | { 80, 0x0000 }, /* R80 - GPIO Pin Sticky */ |
| 70 | { 82, 0x0000 }, /* R82 - GPIO Pin Wake Up */ |
Leon Romanovsky | 43fa8e5 | 2011-11-17 12:01:28 +0200 | [diff] [blame] | 71 | { 86, 0x0000 }, /* R86 - Pin Sharing */ |
Leon Romanovsky | 43fa8e5 | 2011-11-17 12:01:28 +0200 | [diff] [blame] | 72 | { 90, 0x0009 }, /* R90 - Soft Volume Control Setting */ |
| 73 | { 92, 0x0000 }, /* R92 - GPIO_Output Pin Control */ |
| 74 | { 94, 0x3000 }, /* R94 - MISC Control */ |
| 75 | { 96, 0x3075 }, /* R96 - Stereo DAC Clock Control_1 */ |
| 76 | { 98, 0x1010 }, /* R98 - Stereo DAC Clock Control_2 */ |
| 77 | { 100, 0x3110 }, /* R100 - VoDAC_PCM Clock Control_1 */ |
| 78 | { 104, 0x0553 }, /* R104 - Pseudo Stereo and Spatial Effect |
| 79 | Block Control */ |
| 80 | { 106, 0x0000 }, /* R106 - Private Register Address */ |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* codec private data */ |
| 84 | struct alc5632_priv { |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 85 | struct regmap *regmap; |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 86 | u8 id; |
| 87 | unsigned int sysclk; |
| 88 | }; |
| 89 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 90 | static bool alc5632_volatile_register(struct device *dev, |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 91 | unsigned int reg) |
| 92 | { |
| 93 | switch (reg) { |
| 94 | case ALC5632_RESET: |
| 95 | case ALC5632_PWR_DOWN_CTRL_STATUS: |
| 96 | case ALC5632_GPIO_PIN_STATUS: |
| 97 | case ALC5632_OVER_CURR_STATUS: |
| 98 | case ALC5632_HID_CTRL_DATA: |
| 99 | case ALC5632_EQ_CTRL: |
Leon Romanovsky | 9b4156c | 2011-11-17 12:01:29 +0200 | [diff] [blame] | 100 | case ALC5632_VENDOR_ID1: |
| 101 | case ALC5632_VENDOR_ID2: |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 102 | return true; |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 103 | |
| 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 108 | return false; |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 111 | static inline int alc5632_reset(struct regmap *map) |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 112 | { |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 113 | return regmap_write(map, ALC5632_RESET, 0x59B4); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static int amp_mixer_event(struct snd_soc_dapm_widget *w, |
| 117 | struct snd_kcontrol *kcontrol, int event) |
| 118 | { |
| 119 | /* to power-on/off class-d amp generators/speaker */ |
| 120 | /* need to write to 'index-46h' register : */ |
| 121 | /* so write index num (here 0x46) to reg 0x6a */ |
| 122 | /* and then 0xffff/0 to reg 0x6c */ |
| 123 | snd_soc_write(w->codec, ALC5632_HID_CTRL_INDEX, 0x46); |
| 124 | |
| 125 | switch (event) { |
| 126 | case SND_SOC_DAPM_PRE_PMU: |
| 127 | snd_soc_write(w->codec, ALC5632_HID_CTRL_DATA, 0xFFFF); |
| 128 | break; |
| 129 | case SND_SOC_DAPM_POST_PMD: |
| 130 | snd_soc_write(w->codec, ALC5632_HID_CTRL_DATA, 0); |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * ALC5632 Controls |
| 139 | */ |
| 140 | |
| 141 | /* -34.5db min scale, 1.5db steps, no mute */ |
| 142 | static const DECLARE_TLV_DB_SCALE(vol_tlv, -3450, 150, 0); |
| 143 | /* -46.5db min scale, 1.5db steps, no mute */ |
| 144 | static const DECLARE_TLV_DB_SCALE(hp_tlv, -4650, 150, 0); |
| 145 | /* -16.5db min scale, 1.5db steps, no mute */ |
| 146 | static const DECLARE_TLV_DB_SCALE(adc_rec_tlv, -1650, 150, 0); |
| 147 | static const unsigned int boost_tlv[] = { |
| 148 | TLV_DB_RANGE_HEAD(3), |
| 149 | 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), |
| 150 | 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), |
| 151 | 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0), |
| 152 | }; |
| 153 | /* 0db min scale, 6 db steps, no mute */ |
| 154 | static const DECLARE_TLV_DB_SCALE(dig_tlv, 0, 600, 0); |
| 155 | /* 0db min scalem 0.75db steps, no mute */ |
Andrey Danin | 39be1af | 2012-02-11 23:26:28 +0200 | [diff] [blame^] | 156 | static const DECLARE_TLV_DB_SCALE(vdac_tlv, -3525, 75, 0); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 157 | |
| 158 | static const struct snd_kcontrol_new alc5632_vol_snd_controls[] = { |
| 159 | /* left starts at bit 8, right at bit 0 */ |
| 160 | /* 31 steps (5 bit), -46.5db scale */ |
Andrey Danin | 1a08325 | 2011-11-13 21:53:13 +0200 | [diff] [blame] | 161 | SOC_DOUBLE_TLV("Speaker Playback Volume", |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 162 | ALC5632_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 163 | /* bit 15 mutes left, bit 7 right */ |
Andrey Danin | 1a08325 | 2011-11-13 21:53:13 +0200 | [diff] [blame] | 164 | SOC_DOUBLE("Speaker Playback Switch", |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 165 | ALC5632_SPK_OUT_VOL, 15, 7, 1, 1), |
| 166 | SOC_DOUBLE_TLV("Headphone Playback Volume", |
| 167 | ALC5632_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 168 | SOC_DOUBLE("Headphone Playback Switch", |
| 169 | ALC5632_HP_OUT_VOL, 15, 7, 1, 1), |
| 170 | }; |
| 171 | |
| 172 | static const struct snd_kcontrol_new alc5632_snd_controls[] = { |
| 173 | SOC_DOUBLE_TLV("Auxout Playback Volume", |
| 174 | ALC5632_AUX_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 175 | SOC_DOUBLE("Auxout Playback Switch", |
| 176 | ALC5632_AUX_OUT_VOL, 15, 7, 1, 1), |
| 177 | SOC_SINGLE_TLV("Voice DAC Playback Volume", |
| 178 | ALC5632_VOICE_DAC_VOL, 0, 63, 0, vdac_tlv), |
| 179 | SOC_SINGLE_TLV("Phone Capture Volume", |
| 180 | ALC5632_PHONE_IN_VOL, 8, 31, 1, vol_tlv), |
| 181 | SOC_DOUBLE_TLV("LineIn Capture Volume", |
| 182 | ALC5632_LINE_IN_VOL, 8, 0, 31, 1, vol_tlv), |
Andrey Danin | 1a08325 | 2011-11-13 21:53:13 +0200 | [diff] [blame] | 183 | SOC_DOUBLE_TLV("Master Playback Volume", |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 184 | ALC5632_STEREO_DAC_IN_VOL, 8, 0, 63, 1, vdac_tlv), |
Andrey Danin | 1a08325 | 2011-11-13 21:53:13 +0200 | [diff] [blame] | 185 | SOC_DOUBLE("Master Playback Switch", |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 186 | ALC5632_STEREO_DAC_IN_VOL, 15, 7, 1, 1), |
| 187 | SOC_SINGLE_TLV("Mic1 Capture Volume", |
| 188 | ALC5632_MIC_VOL, 8, 31, 1, vol_tlv), |
| 189 | SOC_SINGLE_TLV("Mic2 Capture Volume", |
| 190 | ALC5632_MIC_VOL, 0, 31, 1, vol_tlv), |
| 191 | SOC_DOUBLE_TLV("Rec Capture Volume", |
| 192 | ALC5632_ADC_REC_GAIN, 8, 0, 31, 0, adc_rec_tlv), |
| 193 | SOC_SINGLE_TLV("Mic 1 Boost Volume", |
| 194 | ALC5632_MIC_CTRL, 10, 2, 0, boost_tlv), |
| 195 | SOC_SINGLE_TLV("Mic 2 Boost Volume", |
| 196 | ALC5632_MIC_CTRL, 8, 2, 0, boost_tlv), |
| 197 | SOC_SINGLE_TLV("Digital Boost Volume", |
| 198 | ALC5632_DIGI_BOOST_CTRL, 0, 7, 0, dig_tlv), |
| 199 | }; |
| 200 | |
| 201 | /* |
| 202 | * DAPM Controls |
| 203 | */ |
| 204 | static const struct snd_kcontrol_new alc5632_hp_mixer_controls[] = { |
| 205 | SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5632_LINE_IN_VOL, 15, 1, 1), |
| 206 | SOC_DAPM_SINGLE("PHONE2HP Playback Switch", ALC5632_PHONE_IN_VOL, 15, 1, 1), |
| 207 | SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 15, 1, 1), |
| 208 | SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 11, 1, 1), |
| 209 | SOC_DAPM_SINGLE("VOICE2HP Playback Switch", ALC5632_VOICE_DAC_VOL, 15, 1, 1), |
| 210 | }; |
| 211 | |
| 212 | static const struct snd_kcontrol_new alc5632_hpl_mixer_controls[] = { |
| 213 | SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5632_ADC_REC_GAIN, 15, 1, 1), |
| 214 | SOC_DAPM_SINGLE("DACL2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 3, 1, 1), |
| 215 | }; |
| 216 | |
| 217 | static const struct snd_kcontrol_new alc5632_hpr_mixer_controls[] = { |
| 218 | SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5632_ADC_REC_GAIN, 7, 1, 1), |
| 219 | SOC_DAPM_SINGLE("DACR2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 2, 1, 1), |
| 220 | }; |
| 221 | |
| 222 | static const struct snd_kcontrol_new alc5632_mono_mixer_controls[] = { |
| 223 | SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5632_ADC_REC_GAIN, 14, 1, 1), |
| 224 | SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5632_ADC_REC_GAIN, 6, 1, 1), |
| 225 | SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5632_LINE_IN_VOL, 13, 1, 1), |
| 226 | SOC_DAPM_SINGLE("MIC12MONO Playback Switch", |
| 227 | ALC5632_MIC_ROUTING_CTRL, 13, 1, 1), |
| 228 | SOC_DAPM_SINGLE("MIC22MONO Playback Switch", |
| 229 | ALC5632_MIC_ROUTING_CTRL, 9, 1, 1), |
| 230 | SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5632_MIC_ROUTING_CTRL, 0, 1, 1), |
| 231 | SOC_DAPM_SINGLE("VOICE2MONO Playback Switch", ALC5632_VOICE_DAC_VOL, 13, 1, 1), |
| 232 | }; |
| 233 | |
| 234 | static const struct snd_kcontrol_new alc5632_speaker_mixer_controls[] = { |
| 235 | SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5632_LINE_IN_VOL, 14, 1, 1), |
| 236 | SOC_DAPM_SINGLE("PHONE2SPK Playback Switch", ALC5632_PHONE_IN_VOL, 14, 1, 1), |
| 237 | SOC_DAPM_SINGLE("MIC12SPK Playback Switch", |
| 238 | ALC5632_MIC_ROUTING_CTRL, 14, 1, 1), |
| 239 | SOC_DAPM_SINGLE("MIC22SPK Playback Switch", |
| 240 | ALC5632_MIC_ROUTING_CTRL, 10, 1, 1), |
| 241 | SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5632_MIC_ROUTING_CTRL, 1, 1, 1), |
| 242 | SOC_DAPM_SINGLE("VOICE2SPK Playback Switch", ALC5632_VOICE_DAC_VOL, 14, 1, 1), |
| 243 | }; |
| 244 | |
| 245 | /* Left Record Mixer */ |
| 246 | static const struct snd_kcontrol_new alc5632_captureL_mixer_controls[] = { |
| 247 | SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5632_ADC_REC_MIXER, 14, 1, 1), |
| 248 | SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5632_ADC_REC_MIXER, 13, 1, 1), |
| 249 | SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5632_ADC_REC_MIXER, 12, 1, 1), |
| 250 | SOC_DAPM_SINGLE("Left Phone Capture Switch", ALC5632_ADC_REC_MIXER, 11, 1, 1), |
| 251 | SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5632_ADC_REC_MIXER, 10, 1, 1), |
| 252 | SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5632_ADC_REC_MIXER, 9, 1, 1), |
| 253 | SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5632_ADC_REC_MIXER, 8, 1, 1), |
| 254 | }; |
| 255 | |
| 256 | /* Right Record Mixer */ |
| 257 | static const struct snd_kcontrol_new alc5632_captureR_mixer_controls[] = { |
| 258 | SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5632_ADC_REC_MIXER, 6, 1, 1), |
| 259 | SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5632_ADC_REC_MIXER, 5, 1, 1), |
| 260 | SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5632_ADC_REC_MIXER, 4, 1, 1), |
| 261 | SOC_DAPM_SINGLE("Right Phone Capture Switch", ALC5632_ADC_REC_MIXER, 3, 1, 1), |
| 262 | SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5632_ADC_REC_MIXER, 2, 1, 1), |
| 263 | SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5632_ADC_REC_MIXER, 1, 1, 1), |
| 264 | SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5632_ADC_REC_MIXER, 0, 1, 1), |
| 265 | }; |
| 266 | |
| 267 | static const char *alc5632_spk_n_sour_sel[] = { |
| 268 | "RN/-R", "RP/+R", "LN/-R", "Mute"}; |
| 269 | static const char *alc5632_hpl_out_input_sel[] = { |
| 270 | "Vmid", "HP Left Mix"}; |
| 271 | static const char *alc5632_hpr_out_input_sel[] = { |
| 272 | "Vmid", "HP Right Mix"}; |
| 273 | static const char *alc5632_spkout_input_sel[] = { |
| 274 | "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; |
| 275 | static const char *alc5632_aux_out_input_sel[] = { |
| 276 | "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; |
| 277 | |
| 278 | /* auxout output mux */ |
| 279 | static const struct soc_enum alc5632_aux_out_input_enum = |
| 280 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 6, 4, alc5632_aux_out_input_sel); |
| 281 | static const struct snd_kcontrol_new alc5632_auxout_mux_controls = |
| 282 | SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum); |
| 283 | |
| 284 | /* speaker output mux */ |
| 285 | static const struct soc_enum alc5632_spkout_input_enum = |
| 286 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 10, 4, alc5632_spkout_input_sel); |
| 287 | static const struct snd_kcontrol_new alc5632_spkout_mux_controls = |
| 288 | SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum); |
| 289 | |
| 290 | /* headphone left output mux */ |
| 291 | static const struct soc_enum alc5632_hpl_out_input_enum = |
| 292 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 9, 2, alc5632_hpl_out_input_sel); |
| 293 | static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls = |
| 294 | SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum); |
| 295 | |
| 296 | /* headphone right output mux */ |
| 297 | static const struct soc_enum alc5632_hpr_out_input_enum = |
| 298 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 8, 2, alc5632_hpr_out_input_sel); |
| 299 | static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls = |
| 300 | SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum); |
| 301 | |
| 302 | /* speaker output N select */ |
| 303 | static const struct soc_enum alc5632_spk_n_sour_enum = |
| 304 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 14, 4, alc5632_spk_n_sour_sel); |
| 305 | static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls = |
| 306 | SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum); |
| 307 | |
| 308 | /* speaker amplifier */ |
| 309 | static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"}; |
| 310 | static const struct soc_enum alc5632_amp_enum = |
| 311 | SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 13, 2, alc5632_amp_names); |
| 312 | static const struct snd_kcontrol_new alc5632_amp_mux_controls = |
| 313 | SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum); |
| 314 | |
| 315 | |
| 316 | static const struct snd_soc_dapm_widget alc5632_dapm_widgets[] = { |
| 317 | /* Muxes */ |
| 318 | SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM, 0, 0, |
| 319 | &alc5632_auxout_mux_controls), |
| 320 | SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM, 0, 0, |
| 321 | &alc5632_spkout_mux_controls), |
| 322 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 323 | &alc5632_hpl_out_mux_controls), |
| 324 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 325 | &alc5632_hpr_out_mux_controls), |
| 326 | SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM, 0, 0, |
| 327 | &alc5632_spkoutn_mux_controls), |
| 328 | |
| 329 | /* output mixers */ |
| 330 | SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM, 0, 0, |
| 331 | &alc5632_hp_mixer_controls[0], |
| 332 | ARRAY_SIZE(alc5632_hp_mixer_controls)), |
| 333 | SND_SOC_DAPM_MIXER("HPR Mix", ALC5632_PWR_MANAG_ADD2, 4, 0, |
| 334 | &alc5632_hpr_mixer_controls[0], |
| 335 | ARRAY_SIZE(alc5632_hpr_mixer_controls)), |
| 336 | SND_SOC_DAPM_MIXER("HPL Mix", ALC5632_PWR_MANAG_ADD2, 5, 0, |
| 337 | &alc5632_hpl_mixer_controls[0], |
| 338 | ARRAY_SIZE(alc5632_hpl_mixer_controls)), |
| 339 | SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 340 | SND_SOC_DAPM_MIXER("Mono Mix", ALC5632_PWR_MANAG_ADD2, 2, 0, |
| 341 | &alc5632_mono_mixer_controls[0], |
| 342 | ARRAY_SIZE(alc5632_mono_mixer_controls)), |
| 343 | SND_SOC_DAPM_MIXER("Speaker Mix", ALC5632_PWR_MANAG_ADD2, 3, 0, |
| 344 | &alc5632_speaker_mixer_controls[0], |
| 345 | ARRAY_SIZE(alc5632_speaker_mixer_controls)), |
| 346 | |
| 347 | /* input mixers */ |
| 348 | SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5632_PWR_MANAG_ADD2, 1, 0, |
| 349 | &alc5632_captureL_mixer_controls[0], |
| 350 | ARRAY_SIZE(alc5632_captureL_mixer_controls)), |
| 351 | SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5632_PWR_MANAG_ADD2, 0, 0, |
| 352 | &alc5632_captureR_mixer_controls[0], |
| 353 | ARRAY_SIZE(alc5632_captureR_mixer_controls)), |
| 354 | |
| 355 | SND_SOC_DAPM_DAC("Left DAC", "HiFi Playback", |
| 356 | ALC5632_PWR_MANAG_ADD2, 9, 0), |
| 357 | SND_SOC_DAPM_DAC("Right DAC", "HiFi Playback", |
| 358 | ALC5632_PWR_MANAG_ADD2, 8, 0), |
| 359 | SND_SOC_DAPM_MIXER("DAC Left Channel", ALC5632_PWR_MANAG_ADD1, 15, 0, NULL, 0), |
| 360 | SND_SOC_DAPM_MIXER("DAC Right Channel", |
| 361 | ALC5632_PWR_MANAG_ADD1, 14, 0, NULL, 0), |
| 362 | SND_SOC_DAPM_MIXER("I2S Mix", ALC5632_PWR_MANAG_ADD1, 11, 0, NULL, 0), |
| 363 | SND_SOC_DAPM_MIXER("Phone Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 364 | SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 365 | SND_SOC_DAPM_ADC("Left ADC", "HiFi Capture", |
| 366 | ALC5632_PWR_MANAG_ADD2, 7, 0), |
| 367 | SND_SOC_DAPM_ADC("Right ADC", "HiFi Capture", |
| 368 | ALC5632_PWR_MANAG_ADD2, 6, 0), |
| 369 | SND_SOC_DAPM_PGA("Left Headphone", ALC5632_PWR_MANAG_ADD3, 11, 0, NULL, 0), |
| 370 | SND_SOC_DAPM_PGA("Right Headphone", ALC5632_PWR_MANAG_ADD3, 10, 0, NULL, 0), |
| 371 | SND_SOC_DAPM_PGA("Left Speaker", ALC5632_PWR_MANAG_ADD3, 13, 0, NULL, 0), |
| 372 | SND_SOC_DAPM_PGA("Right Speaker", ALC5632_PWR_MANAG_ADD3, 12, 0, NULL, 0), |
| 373 | SND_SOC_DAPM_PGA("Aux Out", ALC5632_PWR_MANAG_ADD3, 14, 0, NULL, 0), |
| 374 | SND_SOC_DAPM_PGA("Left LineIn", ALC5632_PWR_MANAG_ADD3, 7, 0, NULL, 0), |
| 375 | SND_SOC_DAPM_PGA("Right LineIn", ALC5632_PWR_MANAG_ADD3, 6, 0, NULL, 0), |
| 376 | SND_SOC_DAPM_PGA("Phone", ALC5632_PWR_MANAG_ADD3, 5, 0, NULL, 0), |
| 377 | SND_SOC_DAPM_PGA("Phone ADMix", ALC5632_PWR_MANAG_ADD3, 4, 0, NULL, 0), |
| 378 | SND_SOC_DAPM_PGA("MIC1 PGA", ALC5632_PWR_MANAG_ADD3, 3, 0, NULL, 0), |
| 379 | SND_SOC_DAPM_PGA("MIC2 PGA", ALC5632_PWR_MANAG_ADD3, 2, 0, NULL, 0), |
| 380 | SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5632_PWR_MANAG_ADD3, 1, 0, NULL, 0), |
| 381 | SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5632_PWR_MANAG_ADD3, 0, 0, NULL, 0), |
Leon Romanovsky | 9215aa4 | 2011-12-12 21:43:45 +0200 | [diff] [blame] | 382 | SND_SOC_DAPM_SUPPLY("MICBIAS1", ALC5632_PWR_MANAG_ADD1, 3, 0, NULL, 0), |
| 383 | SND_SOC_DAPM_SUPPLY("MICBIAS2", ALC5632_PWR_MANAG_ADD1, 2, 0, NULL, 0), |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 384 | |
| 385 | SND_SOC_DAPM_PGA_E("D Amp", ALC5632_PWR_MANAG_ADD2, 14, 0, NULL, 0, |
| 386 | amp_mixer_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 387 | SND_SOC_DAPM_PGA("AB Amp", ALC5632_PWR_MANAG_ADD2, 15, 0, NULL, 0), |
| 388 | SND_SOC_DAPM_MUX("AB-D Amp Mux", ALC5632_PWR_MANAG_ADD1, 10, 0, |
| 389 | &alc5632_amp_mux_controls), |
| 390 | |
| 391 | SND_SOC_DAPM_OUTPUT("AUXOUT"), |
| 392 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 393 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 394 | SND_SOC_DAPM_OUTPUT("SPKOUT"), |
| 395 | SND_SOC_DAPM_OUTPUT("SPKOUTN"), |
| 396 | SND_SOC_DAPM_INPUT("LINEINL"), |
| 397 | SND_SOC_DAPM_INPUT("LINEINR"), |
| 398 | SND_SOC_DAPM_INPUT("PHONEP"), |
| 399 | SND_SOC_DAPM_INPUT("PHONEN"), |
| 400 | SND_SOC_DAPM_INPUT("MIC1"), |
| 401 | SND_SOC_DAPM_INPUT("MIC2"), |
| 402 | SND_SOC_DAPM_VMID("Vmid"), |
| 403 | }; |
| 404 | |
| 405 | |
| 406 | static const struct snd_soc_dapm_route alc5632_dapm_routes[] = { |
| 407 | /* virtual mixer - mixes left & right channels */ |
| 408 | {"I2S Mix", NULL, "Left DAC"}, |
| 409 | {"I2S Mix", NULL, "Right DAC"}, |
| 410 | {"Line Mix", NULL, "Right LineIn"}, |
| 411 | {"Line Mix", NULL, "Left LineIn"}, |
| 412 | {"Phone Mix", NULL, "Phone"}, |
| 413 | {"Phone Mix", NULL, "Phone ADMix"}, |
| 414 | {"AUXOUT", NULL, "Aux Out"}, |
| 415 | |
| 416 | /* DAC */ |
| 417 | {"DAC Right Channel", NULL, "I2S Mix"}, |
| 418 | {"DAC Left Channel", NULL, "I2S Mix"}, |
| 419 | |
| 420 | /* HP mixer */ |
| 421 | {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"}, |
| 422 | {"HPL Mix", NULL, "HP Mix"}, |
| 423 | {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"}, |
| 424 | {"HPR Mix", NULL, "HP Mix"}, |
| 425 | {"HP Mix", "LI2HP Playback Switch", "Line Mix"}, |
| 426 | {"HP Mix", "PHONE2HP Playback Switch", "Phone Mix"}, |
| 427 | {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"}, |
| 428 | {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"}, |
| 429 | |
| 430 | {"HPR Mix", "DACR2HP Playback Switch", "DAC Right Channel"}, |
| 431 | {"HPL Mix", "DACL2HP Playback Switch", "DAC Left Channel"}, |
| 432 | |
| 433 | /* speaker mixer */ |
| 434 | {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"}, |
| 435 | {"Speaker Mix", "PHONE2SPK Playback Switch", "Phone Mix"}, |
| 436 | {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"}, |
| 437 | {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"}, |
| 438 | {"Speaker Mix", "DAC2SPK Playback Switch", "DAC Left Channel"}, |
| 439 | |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 440 | /* mono mixer */ |
| 441 | {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"}, |
| 442 | {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"}, |
| 443 | {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"}, |
| 444 | {"Mono Mix", "VOICE2MONO Playback Switch", "Phone Mix"}, |
| 445 | {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"}, |
| 446 | {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"}, |
| 447 | {"Mono Mix", "DAC2MONO Playback Switch", "DAC Left Channel"}, |
| 448 | |
| 449 | /* Left record mixer */ |
| 450 | {"Left Capture Mix", "LineInL Capture Switch", "LINEINL"}, |
| 451 | {"Left Capture Mix", "Left Phone Capture Switch", "PHONEN"}, |
| 452 | {"Left Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"}, |
| 453 | {"Left Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"}, |
| 454 | {"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"}, |
| 455 | {"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"}, |
| 456 | {"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"}, |
| 457 | |
| 458 | /*Right record mixer */ |
| 459 | {"Right Capture Mix", "LineInR Capture Switch", "LINEINR"}, |
| 460 | {"Right Capture Mix", "Right Phone Capture Switch", "PHONEP"}, |
| 461 | {"Right Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"}, |
| 462 | {"Right Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"}, |
| 463 | {"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"}, |
| 464 | {"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"}, |
| 465 | {"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"}, |
| 466 | |
| 467 | /* headphone left mux */ |
| 468 | {"Left Headphone Mux", "HP Left Mix", "HPL Mix"}, |
| 469 | {"Left Headphone Mux", "Vmid", "Vmid"}, |
| 470 | |
| 471 | /* headphone right mux */ |
| 472 | {"Right Headphone Mux", "HP Right Mix", "HPR Mix"}, |
| 473 | {"Right Headphone Mux", "Vmid", "Vmid"}, |
| 474 | |
| 475 | /* speaker out mux */ |
| 476 | {"SpeakerOut Mux", "Vmid", "Vmid"}, |
| 477 | {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"}, |
| 478 | {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"}, |
| 479 | {"SpeakerOut Mux", "Mono Mix", "Mono Mix"}, |
| 480 | |
| 481 | /* Mono/Aux Out mux */ |
| 482 | {"AuxOut Mux", "Vmid", "Vmid"}, |
| 483 | {"AuxOut Mux", "HPOut Mix", "HPOut Mix"}, |
| 484 | {"AuxOut Mux", "Speaker Mix", "Speaker Mix"}, |
| 485 | {"AuxOut Mux", "Mono Mix", "Mono Mix"}, |
| 486 | |
| 487 | /* output pga */ |
| 488 | {"HPL", NULL, "Left Headphone"}, |
| 489 | {"Left Headphone", NULL, "Left Headphone Mux"}, |
| 490 | {"HPR", NULL, "Right Headphone"}, |
| 491 | {"Right Headphone", NULL, "Right Headphone Mux"}, |
| 492 | {"Aux Out", NULL, "AuxOut Mux"}, |
| 493 | |
| 494 | /* input pga */ |
| 495 | {"Left LineIn", NULL, "LINEINL"}, |
| 496 | {"Right LineIn", NULL, "LINEINR"}, |
| 497 | {"Phone", NULL, "PHONEP"}, |
| 498 | {"MIC1 Pre Amp", NULL, "MIC1"}, |
| 499 | {"MIC2 Pre Amp", NULL, "MIC2"}, |
| 500 | {"MIC1 PGA", NULL, "MIC1 Pre Amp"}, |
| 501 | {"MIC2 PGA", NULL, "MIC2 Pre Amp"}, |
| 502 | |
| 503 | /* left ADC */ |
| 504 | {"Left ADC", NULL, "Left Capture Mix"}, |
| 505 | |
| 506 | /* right ADC */ |
| 507 | {"Right ADC", NULL, "Right Capture Mix"}, |
| 508 | |
| 509 | {"SpeakerOut N Mux", "RN/-R", "Left Speaker"}, |
| 510 | {"SpeakerOut N Mux", "RP/+R", "Left Speaker"}, |
| 511 | {"SpeakerOut N Mux", "LN/-R", "Left Speaker"}, |
| 512 | {"SpeakerOut N Mux", "Mute", "Vmid"}, |
| 513 | |
| 514 | {"SpeakerOut N Mux", "RN/-R", "Right Speaker"}, |
| 515 | {"SpeakerOut N Mux", "RP/+R", "Right Speaker"}, |
| 516 | {"SpeakerOut N Mux", "LN/-R", "Right Speaker"}, |
| 517 | {"SpeakerOut N Mux", "Mute", "Vmid"}, |
| 518 | |
| 519 | {"AB Amp", NULL, "SpeakerOut Mux"}, |
| 520 | {"D Amp", NULL, "SpeakerOut Mux"}, |
| 521 | {"AB-D Amp Mux", "AB Amp", "AB Amp"}, |
| 522 | {"AB-D Amp Mux", "D Amp", "D Amp"}, |
| 523 | {"Left Speaker", NULL, "AB-D Amp Mux"}, |
| 524 | {"Right Speaker", NULL, "AB-D Amp Mux"}, |
| 525 | |
| 526 | {"SPKOUT", NULL, "Left Speaker"}, |
| 527 | {"SPKOUT", NULL, "Right Speaker"}, |
| 528 | |
| 529 | {"SPKOUTN", NULL, "SpeakerOut N Mux"}, |
| 530 | |
| 531 | }; |
| 532 | |
| 533 | /* PLL divisors */ |
| 534 | struct _pll_div { |
| 535 | u32 pll_in; |
| 536 | u32 pll_out; |
| 537 | u16 regvalue; |
| 538 | }; |
| 539 | |
| 540 | /* Note : pll code from original alc5632 driver. Not sure of how good it is */ |
| 541 | /* usefull only for master mode */ |
| 542 | static const struct _pll_div codec_master_pll_div[] = { |
| 543 | |
| 544 | { 2048000, 8192000, 0x0ea0}, |
| 545 | { 3686400, 8192000, 0x4e27}, |
| 546 | { 12000000, 8192000, 0x456b}, |
| 547 | { 13000000, 8192000, 0x495f}, |
| 548 | { 13100000, 8192000, 0x0320}, |
| 549 | { 2048000, 11289600, 0xf637}, |
| 550 | { 3686400, 11289600, 0x2f22}, |
| 551 | { 12000000, 11289600, 0x3e2f}, |
| 552 | { 13000000, 11289600, 0x4d5b}, |
| 553 | { 13100000, 11289600, 0x363b}, |
| 554 | { 2048000, 16384000, 0x1ea0}, |
| 555 | { 3686400, 16384000, 0x9e27}, |
| 556 | { 12000000, 16384000, 0x452b}, |
| 557 | { 13000000, 16384000, 0x542f}, |
| 558 | { 13100000, 16384000, 0x03a0}, |
| 559 | { 2048000, 16934400, 0xe625}, |
| 560 | { 3686400, 16934400, 0x9126}, |
| 561 | { 12000000, 16934400, 0x4d2c}, |
| 562 | { 13000000, 16934400, 0x742f}, |
| 563 | { 13100000, 16934400, 0x3c27}, |
| 564 | { 2048000, 22579200, 0x2aa0}, |
| 565 | { 3686400, 22579200, 0x2f20}, |
| 566 | { 12000000, 22579200, 0x7e2f}, |
| 567 | { 13000000, 22579200, 0x742f}, |
| 568 | { 13100000, 22579200, 0x3c27}, |
| 569 | { 2048000, 24576000, 0x2ea0}, |
| 570 | { 3686400, 24576000, 0xee27}, |
| 571 | { 12000000, 24576000, 0x2915}, |
| 572 | { 13000000, 24576000, 0x772e}, |
| 573 | { 13100000, 24576000, 0x0d20}, |
| 574 | }; |
| 575 | |
| 576 | /* FOUT = MCLK*(N+2)/((M+2)*(K+2)) |
| 577 | N: bit 15:8 (div 2 .. div 257) |
| 578 | K: bit 6:4 typical 2 |
| 579 | M: bit 3:0 (div 2 .. div 17) |
| 580 | |
| 581 | same as for 5623 - thanks! |
| 582 | */ |
| 583 | |
| 584 | static const struct _pll_div codec_slave_pll_div[] = { |
| 585 | |
| 586 | { 1024000, 16384000, 0x3ea0}, |
| 587 | { 1411200, 22579200, 0x3ea0}, |
| 588 | { 1536000, 24576000, 0x3ea0}, |
| 589 | { 2048000, 16384000, 0x1ea0}, |
| 590 | { 2822400, 22579200, 0x1ea0}, |
| 591 | { 3072000, 24576000, 0x1ea0}, |
| 592 | |
| 593 | }; |
| 594 | |
| 595 | static int alc5632_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 596 | int source, unsigned int freq_in, unsigned int freq_out) |
| 597 | { |
| 598 | int i; |
| 599 | struct snd_soc_codec *codec = codec_dai->codec; |
| 600 | int gbl_clk = 0, pll_div = 0; |
| 601 | u16 reg; |
| 602 | |
| 603 | if (pll_id < ALC5632_PLL_FR_MCLK || pll_id > ALC5632_PLL_FR_VBCLK) |
| 604 | return -EINVAL; |
| 605 | |
| 606 | /* Disable PLL power */ |
| 607 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 608 | ALC5632_PWR_ADD2_PLL1, |
| 609 | 0); |
| 610 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 611 | ALC5632_PWR_ADD2_PLL2, |
| 612 | 0); |
| 613 | |
| 614 | /* pll is not used in slave mode */ |
| 615 | reg = snd_soc_read(codec, ALC5632_DAI_CONTROL); |
| 616 | if (reg & ALC5632_DAI_SDP_SLAVE_MODE) |
| 617 | return 0; |
| 618 | |
| 619 | if (!freq_in || !freq_out) |
| 620 | return 0; |
| 621 | |
| 622 | switch (pll_id) { |
| 623 | case ALC5632_PLL_FR_MCLK: |
| 624 | for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) { |
| 625 | if (codec_master_pll_div[i].pll_in == freq_in |
| 626 | && codec_master_pll_div[i].pll_out == freq_out) { |
| 627 | /* PLL source from MCLK */ |
| 628 | pll_div = codec_master_pll_div[i].regvalue; |
| 629 | break; |
| 630 | } |
| 631 | } |
| 632 | break; |
| 633 | case ALC5632_PLL_FR_BCLK: |
| 634 | for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) { |
| 635 | if (codec_slave_pll_div[i].pll_in == freq_in |
| 636 | && codec_slave_pll_div[i].pll_out == freq_out) { |
| 637 | /* PLL source from Bitclk */ |
| 638 | gbl_clk = ALC5632_PLL_FR_BCLK; |
| 639 | pll_div = codec_slave_pll_div[i].regvalue; |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | break; |
| 644 | case ALC5632_PLL_FR_VBCLK: |
| 645 | for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) { |
| 646 | if (codec_slave_pll_div[i].pll_in == freq_in |
| 647 | && codec_slave_pll_div[i].pll_out == freq_out) { |
| 648 | /* PLL source from voice clock */ |
| 649 | gbl_clk = ALC5632_PLL_FR_VBCLK; |
| 650 | pll_div = codec_slave_pll_div[i].regvalue; |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | break; |
| 655 | default: |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
| 659 | if (!pll_div) |
| 660 | return -EINVAL; |
| 661 | |
| 662 | /* choose MCLK/BCLK/VBCLK */ |
| 663 | snd_soc_write(codec, ALC5632_GPCR2, gbl_clk); |
| 664 | /* choose PLL1 clock rate */ |
| 665 | snd_soc_write(codec, ALC5632_PLL1_CTRL, pll_div); |
| 666 | /* enable PLL1 */ |
| 667 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 668 | ALC5632_PWR_ADD2_PLL1, |
| 669 | ALC5632_PWR_ADD2_PLL1); |
| 670 | /* enable PLL2 */ |
| 671 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 672 | ALC5632_PWR_ADD2_PLL2, |
| 673 | ALC5632_PWR_ADD2_PLL2); |
| 674 | /* use PLL1 as main SYSCLK */ |
| 675 | snd_soc_update_bits(codec, ALC5632_GPCR1, |
| 676 | ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1, |
| 677 | ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | struct _coeff_div { |
| 683 | u16 fs; |
| 684 | u16 regvalue; |
| 685 | }; |
| 686 | |
| 687 | /* codec hifi mclk (after PLL) clock divider coefficients */ |
| 688 | /* values inspired from column BCLK=32Fs of Appendix A table */ |
| 689 | static const struct _coeff_div coeff_div[] = { |
| 690 | {512*1, 0x3075}, |
| 691 | }; |
| 692 | |
| 693 | static int get_coeff(struct snd_soc_codec *codec, int rate) |
| 694 | { |
| 695 | struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); |
| 696 | int i; |
| 697 | |
| 698 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { |
| 699 | if (coeff_div[i].fs * rate == alc5632->sysclk) |
| 700 | return i; |
| 701 | } |
| 702 | return -EINVAL; |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Clock after PLL and dividers |
| 707 | */ |
| 708 | static int alc5632_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 709 | int clk_id, unsigned int freq, int dir) |
| 710 | { |
| 711 | struct snd_soc_codec *codec = codec_dai->codec; |
| 712 | struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); |
| 713 | |
| 714 | switch (freq) { |
| 715 | case 8192000: |
| 716 | case 11289600: |
| 717 | case 12288000: |
| 718 | case 16384000: |
| 719 | case 16934400: |
| 720 | case 18432000: |
| 721 | case 22579200: |
| 722 | case 24576000: |
| 723 | alc5632->sysclk = freq; |
| 724 | return 0; |
| 725 | } |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | |
| 729 | static int alc5632_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 730 | unsigned int fmt) |
| 731 | { |
| 732 | struct snd_soc_codec *codec = codec_dai->codec; |
| 733 | u16 iface = 0; |
| 734 | |
| 735 | /* set master/slave audio interface */ |
| 736 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 737 | case SND_SOC_DAIFMT_CBM_CFM: |
| 738 | iface = ALC5632_DAI_SDP_MASTER_MODE; |
| 739 | break; |
| 740 | case SND_SOC_DAIFMT_CBS_CFS: |
| 741 | iface = ALC5632_DAI_SDP_SLAVE_MODE; |
| 742 | break; |
| 743 | default: |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | |
| 747 | /* interface format */ |
| 748 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 749 | case SND_SOC_DAIFMT_I2S: |
| 750 | iface |= ALC5632_DAI_I2S_DF_I2S; |
| 751 | break; |
| 752 | case SND_SOC_DAIFMT_LEFT_J: |
| 753 | iface |= ALC5632_DAI_I2S_DF_LEFT; |
| 754 | break; |
| 755 | case SND_SOC_DAIFMT_DSP_A: |
| 756 | iface |= ALC5632_DAI_I2S_DF_PCM_A; |
| 757 | break; |
| 758 | case SND_SOC_DAIFMT_DSP_B: |
| 759 | iface |= ALC5632_DAI_I2S_DF_PCM_B; |
| 760 | break; |
| 761 | default: |
| 762 | return -EINVAL; |
| 763 | } |
| 764 | |
| 765 | /* clock inversion */ |
| 766 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 767 | case SND_SOC_DAIFMT_NB_NF: |
| 768 | break; |
| 769 | case SND_SOC_DAIFMT_IB_IF: |
| 770 | iface |= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL; |
| 771 | break; |
| 772 | case SND_SOC_DAIFMT_IB_NF: |
| 773 | iface |= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL; |
| 774 | break; |
| 775 | case SND_SOC_DAIFMT_NB_IF: |
| 776 | break; |
| 777 | default: |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | return snd_soc_write(codec, ALC5632_DAI_CONTROL, iface); |
| 782 | } |
| 783 | |
| 784 | static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream, |
| 785 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
| 786 | { |
| 787 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 788 | struct snd_soc_codec *codec = rtd->codec; |
| 789 | int coeff, rate; |
| 790 | u16 iface; |
| 791 | |
| 792 | iface = snd_soc_read(codec, ALC5632_DAI_CONTROL); |
| 793 | iface &= ~ALC5632_DAI_I2S_DL_MASK; |
| 794 | |
| 795 | /* bit size */ |
| 796 | switch (params_format(params)) { |
| 797 | case SNDRV_PCM_FORMAT_S16_LE: |
| 798 | iface |= ALC5632_DAI_I2S_DL_16; |
| 799 | break; |
| 800 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 801 | iface |= ALC5632_DAI_I2S_DL_20; |
| 802 | break; |
| 803 | case SNDRV_PCM_FORMAT_S24_LE: |
| 804 | iface |= ALC5632_DAI_I2S_DL_24; |
| 805 | break; |
| 806 | default: |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | |
| 810 | /* set iface & srate */ |
| 811 | snd_soc_write(codec, ALC5632_DAI_CONTROL, iface); |
| 812 | rate = params_rate(params); |
| 813 | coeff = get_coeff(codec, rate); |
| 814 | if (coeff < 0) |
| 815 | return -EINVAL; |
| 816 | |
| 817 | coeff = coeff_div[coeff].regvalue; |
| 818 | snd_soc_write(codec, ALC5632_DAC_CLK_CTRL1, coeff); |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | static int alc5632_mute(struct snd_soc_dai *dai, int mute) |
| 824 | { |
| 825 | struct snd_soc_codec *codec = dai->codec; |
Leon Romanovsky | 88c494b | 2011-11-10 21:22:16 +0200 | [diff] [blame] | 826 | u16 hp_mute = ALC5632_MISC_HP_DEPOP_MUTE_L |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 827 | |ALC5632_MISC_HP_DEPOP_MUTE_R; |
| 828 | u16 mute_reg = snd_soc_read(codec, ALC5632_MISC_CTRL) & ~hp_mute; |
| 829 | |
| 830 | if (mute) |
| 831 | mute_reg |= hp_mute; |
| 832 | |
| 833 | return snd_soc_write(codec, ALC5632_MISC_CTRL, mute_reg); |
| 834 | } |
| 835 | |
| 836 | #define ALC5632_ADD2_POWER_EN (ALC5632_PWR_ADD2_VREF) |
| 837 | |
| 838 | #define ALC5632_ADD3_POWER_EN (ALC5632_PWR_ADD3_MIC1_BOOST_AD) |
| 839 | |
| 840 | #define ALC5632_ADD1_POWER_EN \ |
| 841 | (ALC5632_PWR_ADD1_DAC_REF \ |
| 842 | | ALC5632_PWR_ADD1_SOFTGEN_EN \ |
| 843 | | ALC5632_PWR_ADD1_HP_OUT_AMP \ |
| 844 | | ALC5632_PWR_ADD1_HP_OUT_ENH_AMP \ |
| 845 | | ALC5632_PWR_ADD1_MAIN_BIAS) |
| 846 | |
| 847 | static void enable_power_depop(struct snd_soc_codec *codec) |
| 848 | { |
| 849 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1, |
| 850 | ALC5632_PWR_ADD1_SOFTGEN_EN, |
| 851 | ALC5632_PWR_ADD1_SOFTGEN_EN); |
| 852 | |
| 853 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD3, |
| 854 | ALC5632_ADD3_POWER_EN, |
| 855 | ALC5632_ADD3_POWER_EN); |
| 856 | |
| 857 | snd_soc_update_bits(codec, ALC5632_MISC_CTRL, |
| 858 | ALC5632_MISC_HP_DEPOP_MODE2_EN, |
| 859 | ALC5632_MISC_HP_DEPOP_MODE2_EN); |
| 860 | |
| 861 | /* "normal" mode: 0 @ 26 */ |
| 862 | /* set all PR0-7 mixers to 0 */ |
| 863 | snd_soc_update_bits(codec, ALC5632_PWR_DOWN_CTRL_STATUS, |
| 864 | ALC5632_PWR_DOWN_CTRL_STATUS_MASK, |
| 865 | 0); |
| 866 | |
| 867 | msleep(500); |
| 868 | |
| 869 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 870 | ALC5632_ADD2_POWER_EN, |
| 871 | ALC5632_ADD2_POWER_EN); |
| 872 | |
| 873 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1, |
| 874 | ALC5632_ADD1_POWER_EN, |
| 875 | ALC5632_ADD1_POWER_EN); |
| 876 | |
| 877 | /* disable HP Depop2 */ |
| 878 | snd_soc_update_bits(codec, ALC5632_MISC_CTRL, |
| 879 | ALC5632_MISC_HP_DEPOP_MODE2_EN, |
| 880 | 0); |
| 881 | |
| 882 | } |
| 883 | |
| 884 | static int alc5632_set_bias_level(struct snd_soc_codec *codec, |
| 885 | enum snd_soc_bias_level level) |
| 886 | { |
| 887 | switch (level) { |
| 888 | case SND_SOC_BIAS_ON: |
| 889 | enable_power_depop(codec); |
| 890 | break; |
| 891 | case SND_SOC_BIAS_PREPARE: |
| 892 | break; |
| 893 | case SND_SOC_BIAS_STANDBY: |
| 894 | /* everything off except vref/vmid, */ |
| 895 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1, |
| 896 | ALC5632_PWR_MANAG_ADD1_MASK, |
| 897 | ALC5632_PWR_ADD1_MAIN_BIAS); |
| 898 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 899 | ALC5632_PWR_MANAG_ADD2_MASK, |
| 900 | ALC5632_PWR_ADD2_VREF); |
| 901 | /* "normal" mode: 0 @ 26 */ |
| 902 | snd_soc_update_bits(codec, ALC5632_PWR_DOWN_CTRL_STATUS, |
| 903 | ALC5632_PWR_DOWN_CTRL_STATUS_MASK, |
| 904 | 0xffff ^ (ALC5632_PWR_VREF_PR3 |
| 905 | | ALC5632_PWR_VREF_PR2)); |
| 906 | break; |
| 907 | case SND_SOC_BIAS_OFF: |
| 908 | /* everything off, dac mute, inactive */ |
| 909 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2, |
| 910 | ALC5632_PWR_MANAG_ADD2_MASK, 0); |
| 911 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD3, |
| 912 | ALC5632_PWR_MANAG_ADD3_MASK, 0); |
| 913 | snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1, |
| 914 | ALC5632_PWR_MANAG_ADD1_MASK, 0); |
| 915 | break; |
| 916 | } |
| 917 | codec->dapm.bias_level = level; |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | #define ALC5632_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \ |
| 922 | | SNDRV_PCM_FMTBIT_S24_LE \ |
| 923 | | SNDRV_PCM_FMTBIT_S32_LE) |
| 924 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 925 | static const struct snd_soc_dai_ops alc5632_dai_ops = { |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 926 | .hw_params = alc5632_pcm_hw_params, |
| 927 | .digital_mute = alc5632_mute, |
| 928 | .set_fmt = alc5632_set_dai_fmt, |
| 929 | .set_sysclk = alc5632_set_dai_sysclk, |
| 930 | .set_pll = alc5632_set_dai_pll, |
| 931 | }; |
| 932 | |
| 933 | static struct snd_soc_dai_driver alc5632_dai = { |
| 934 | .name = "alc5632-hifi", |
| 935 | .playback = { |
| 936 | .stream_name = "HiFi Playback", |
| 937 | .channels_min = 1, |
| 938 | .channels_max = 2, |
| 939 | .rate_min = 8000, |
| 940 | .rate_max = 48000, |
| 941 | .rates = SNDRV_PCM_RATE_8000_48000, |
| 942 | .formats = ALC5632_FORMATS,}, |
| 943 | .capture = { |
| 944 | .stream_name = "HiFi Capture", |
| 945 | .channels_min = 1, |
| 946 | .channels_max = 2, |
| 947 | .rate_min = 8000, |
| 948 | .rate_max = 48000, |
| 949 | .rates = SNDRV_PCM_RATE_8000_48000, |
| 950 | .formats = ALC5632_FORMATS,}, |
| 951 | |
| 952 | .ops = &alc5632_dai_ops, |
| 953 | .symmetric_rates = 1, |
| 954 | }; |
| 955 | |
Leon Romanovsky | c9be842 | 2011-11-16 12:07:00 +0200 | [diff] [blame] | 956 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 957 | static int alc5632_suspend(struct snd_soc_codec *codec) |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 958 | { |
| 959 | alc5632_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static int alc5632_resume(struct snd_soc_codec *codec) |
| 964 | { |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 965 | struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 966 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 967 | regcache_sync(alc5632->regmap); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 968 | |
| 969 | alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 970 | return 0; |
| 971 | } |
Leon Romanovsky | c9be842 | 2011-11-16 12:07:00 +0200 | [diff] [blame] | 972 | #else |
| 973 | #define alc5632_suspend NULL |
| 974 | #define alc5632_resume NULL |
| 975 | #endif |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 976 | |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 977 | static int alc5632_probe(struct snd_soc_codec *codec) |
| 978 | { |
| 979 | struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); |
| 980 | int ret; |
| 981 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 982 | codec->control_data = alc5632->regmap; |
| 983 | |
| 984 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); |
| 985 | if (ret != 0) { |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 986 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 987 | return ret; |
| 988 | } |
| 989 | |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 990 | /* power on device */ |
| 991 | alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 992 | |
| 993 | switch (alc5632->id) { |
| 994 | case 0x5c: |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 995 | snd_soc_add_codec_controls(codec, alc5632_vol_snd_controls, |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 996 | ARRAY_SIZE(alc5632_vol_snd_controls)); |
| 997 | break; |
| 998 | default: |
| 999 | return -EINVAL; |
| 1000 | } |
| 1001 | |
| 1002 | return ret; |
| 1003 | } |
| 1004 | |
| 1005 | /* power down chip */ |
| 1006 | static int alc5632_remove(struct snd_soc_codec *codec) |
| 1007 | { |
| 1008 | alc5632_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static struct snd_soc_codec_driver soc_codec_device_alc5632 = { |
| 1013 | .probe = alc5632_probe, |
| 1014 | .remove = alc5632_remove, |
| 1015 | .suspend = alc5632_suspend, |
| 1016 | .resume = alc5632_resume, |
| 1017 | .set_bias_level = alc5632_set_bias_level, |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1018 | .controls = alc5632_snd_controls, |
| 1019 | .num_controls = ARRAY_SIZE(alc5632_snd_controls), |
| 1020 | .dapm_widgets = alc5632_dapm_widgets, |
| 1021 | .num_dapm_widgets = ARRAY_SIZE(alc5632_dapm_widgets), |
| 1022 | .dapm_routes = alc5632_dapm_routes, |
| 1023 | .num_dapm_routes = ARRAY_SIZE(alc5632_dapm_routes), |
| 1024 | }; |
| 1025 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1026 | static struct regmap_config alc5632_regmap = { |
| 1027 | .reg_bits = 8, |
| 1028 | .val_bits = 16, |
| 1029 | |
| 1030 | .max_register = ALC5632_MAX_REGISTER, |
| 1031 | .reg_defaults = alc5632_reg_defaults, |
| 1032 | .num_reg_defaults = ARRAY_SIZE(alc5632_reg_defaults), |
| 1033 | .volatile_reg = alc5632_volatile_register, |
| 1034 | .cache_type = REGCACHE_RBTREE, |
| 1035 | }; |
| 1036 | |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1037 | /* |
| 1038 | * alc5632 2 wire address is determined by A1 pin |
| 1039 | * state during powerup. |
| 1040 | * low = 0x1a |
| 1041 | * high = 0x1b |
| 1042 | */ |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1043 | static __devinit int alc5632_i2c_probe(struct i2c_client *client, |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1044 | const struct i2c_device_id *id) |
| 1045 | { |
| 1046 | struct alc5632_priv *alc5632; |
Leon Romanovsky | 277c01b | 2011-11-17 12:01:30 +0200 | [diff] [blame] | 1047 | int ret, ret1, ret2; |
| 1048 | unsigned int vid1, vid2; |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1049 | |
| 1050 | alc5632 = devm_kzalloc(&client->dev, |
| 1051 | sizeof(struct alc5632_priv), GFP_KERNEL); |
| 1052 | if (alc5632 == NULL) |
| 1053 | return -ENOMEM; |
| 1054 | |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1055 | i2c_set_clientdata(client, alc5632); |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1056 | |
| 1057 | alc5632->regmap = regmap_init_i2c(client, &alc5632_regmap); |
| 1058 | if (IS_ERR(alc5632->regmap)) { |
| 1059 | ret = PTR_ERR(alc5632->regmap); |
| 1060 | dev_err(&client->dev, "regmap_init() failed: %d\n", ret); |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
Leon Romanovsky | 277c01b | 2011-11-17 12:01:30 +0200 | [diff] [blame] | 1064 | ret1 = regmap_read(alc5632->regmap, ALC5632_VENDOR_ID1, &vid1); |
| 1065 | ret2 = regmap_read(alc5632->regmap, ALC5632_VENDOR_ID2, &vid2); |
| 1066 | if (ret1 != 0 || ret2 != 0) { |
| 1067 | dev_err(&client->dev, |
| 1068 | "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2); |
| 1069 | regmap_exit(alc5632->regmap); |
| 1070 | return -EIO; |
| 1071 | } |
| 1072 | |
| 1073 | vid2 >>= 8; |
| 1074 | |
| 1075 | if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) { |
| 1076 | dev_err(&client->dev, |
| 1077 | "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2); |
| 1078 | regmap_exit(alc5632->regmap); |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1082 | ret = alc5632_reset(alc5632->regmap); |
| 1083 | if (ret < 0) { |
| 1084 | dev_err(&client->dev, "Failed to issue reset\n"); |
| 1085 | regmap_exit(alc5632->regmap); |
| 1086 | return ret; |
| 1087 | } |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1088 | |
Leon Romanovsky | 277c01b | 2011-11-17 12:01:30 +0200 | [diff] [blame] | 1089 | alc5632->id = vid2; |
| 1090 | switch (alc5632->id) { |
| 1091 | case 0x5c: |
| 1092 | alc5632_dai.name = "alc5632-hifi"; |
| 1093 | break; |
| 1094 | default: |
| 1095 | return -EINVAL; |
| 1096 | } |
| 1097 | |
| 1098 | ret = snd_soc_register_codec(&client->dev, |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1099 | &soc_codec_device_alc5632, &alc5632_dai, 1); |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1100 | |
| 1101 | if (ret < 0) { |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1102 | dev_err(&client->dev, "Failed to register codec: %d\n", ret); |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1103 | regmap_exit(alc5632->regmap); |
| 1104 | return ret; |
| 1105 | } |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1106 | |
| 1107 | return ret; |
| 1108 | } |
| 1109 | |
Axel Lin | 5091f5b | 2012-01-23 11:18:17 +0800 | [diff] [blame] | 1110 | static __devexit int alc5632_i2c_remove(struct i2c_client *client) |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1111 | { |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1112 | struct alc5632_priv *alc5632 = i2c_get_clientdata(client); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1113 | snd_soc_unregister_codec(&client->dev); |
Leon Romanovsky | bb39753 | 2011-11-16 12:06:58 +0200 | [diff] [blame] | 1114 | regmap_exit(alc5632->regmap); |
Leon Romanovsky | 94d5f7c | 2011-11-05 12:38:02 +0200 | [diff] [blame] | 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static const struct i2c_device_id alc5632_i2c_table[] = { |
| 1119 | {"alc5632", 0x5c}, |
| 1120 | {} |
| 1121 | }; |
| 1122 | MODULE_DEVICE_TABLE(i2c, alc5632_i2c_table); |
| 1123 | |
| 1124 | /* i2c codec control layer */ |
| 1125 | static struct i2c_driver alc5632_i2c_driver = { |
| 1126 | .driver = { |
| 1127 | .name = "alc5632", |
| 1128 | .owner = THIS_MODULE, |
| 1129 | }, |
| 1130 | .probe = alc5632_i2c_probe, |
| 1131 | .remove = __devexit_p(alc5632_i2c_remove), |
| 1132 | .id_table = alc5632_i2c_table, |
| 1133 | }; |
| 1134 | |
| 1135 | static int __init alc5632_modinit(void) |
| 1136 | { |
| 1137 | int ret; |
| 1138 | |
| 1139 | ret = i2c_add_driver(&alc5632_i2c_driver); |
| 1140 | if (ret != 0) { |
| 1141 | printk(KERN_ERR "%s: can't add i2c driver", __func__); |
| 1142 | return ret; |
| 1143 | } |
| 1144 | |
| 1145 | return ret; |
| 1146 | } |
| 1147 | module_init(alc5632_modinit); |
| 1148 | |
| 1149 | static void __exit alc5632_modexit(void) |
| 1150 | { |
| 1151 | i2c_del_driver(&alc5632_i2c_driver); |
| 1152 | } |
| 1153 | module_exit(alc5632_modexit); |
| 1154 | |
| 1155 | MODULE_DESCRIPTION("ASoC ALC5632 driver"); |
| 1156 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); |
| 1157 | MODULE_LICENSE("GPL"); |