blob: 4d3ba33eb6f928dc32146645b195d528592711c5 [file] [log] [blame]
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001/*
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 Romanovskybb397532011-11-16 12:06:58 +020025#include <linux/regmap.h>
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +020026#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 */
Axel Linc418a842015-07-05 17:48:29 +080038static const struct reg_default alc5632_reg_defaults[] = {
Leon Romanovsky43fa8e52011-11-17 12:01:28 +020039 { 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 Romanovsky43fa8e52011-11-17 12:01:28 +020054 { 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 Romanovsky43fa8e52011-11-17 12:01:28 +020071 { 86, 0x0000 }, /* R86 - Pin Sharing */
Leon Romanovsky43fa8e52011-11-17 12:01:28 +020072 { 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 Romanovsky94d5f7c2011-11-05 12:38:02 +020081};
82
83/* codec private data */
84struct alc5632_priv {
Leon Romanovskybb397532011-11-16 12:06:58 +020085 struct regmap *regmap;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +020086 u8 id;
87 unsigned int sysclk;
88};
89
Leon Romanovskybb397532011-11-16 12:06:58 +020090static bool alc5632_volatile_register(struct device *dev,
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +020091 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 Romanovsky9b4156c2011-11-17 12:01:29 +0200100 case ALC5632_VENDOR_ID1:
101 case ALC5632_VENDOR_ID2:
Leon Romanovskybb397532011-11-16 12:06:58 +0200102 return true;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200103
104 default:
105 break;
106 }
107
Leon Romanovskybb397532011-11-16 12:06:58 +0200108 return false;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200109}
110
Leon Romanovskybb397532011-11-16 12:06:58 +0200111static inline int alc5632_reset(struct regmap *map)
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200112{
Leon Romanovskybb397532011-11-16 12:06:58 +0200113 return regmap_write(map, ALC5632_RESET, 0x59B4);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200114}
115
116static int amp_mixer_event(struct snd_soc_dapm_widget *w,
117 struct snd_kcontrol *kcontrol, int event)
118{
Lars-Peter Clausen0bb043f2015-01-15 12:52:09 +0100119 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
120
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200121 /* to power-on/off class-d amp generators/speaker */
122 /* need to write to 'index-46h' register : */
123 /* so write index num (here 0x46) to reg 0x6a */
124 /* and then 0xffff/0 to reg 0x6c */
Lars-Peter Clausen0bb043f2015-01-15 12:52:09 +0100125 snd_soc_write(codec, ALC5632_HID_CTRL_INDEX, 0x46);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200126
127 switch (event) {
128 case SND_SOC_DAPM_PRE_PMU:
Lars-Peter Clausen0bb043f2015-01-15 12:52:09 +0100129 snd_soc_write(codec, ALC5632_HID_CTRL_DATA, 0xFFFF);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200130 break;
131 case SND_SOC_DAPM_POST_PMD:
Lars-Peter Clausen0bb043f2015-01-15 12:52:09 +0100132 snd_soc_write(codec, ALC5632_HID_CTRL_DATA, 0);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200133 break;
134 }
135
136 return 0;
137}
138
139/*
140 * ALC5632 Controls
141 */
142
143/* -34.5db min scale, 1.5db steps, no mute */
144static const DECLARE_TLV_DB_SCALE(vol_tlv, -3450, 150, 0);
145/* -46.5db min scale, 1.5db steps, no mute */
146static const DECLARE_TLV_DB_SCALE(hp_tlv, -4650, 150, 0);
147/* -16.5db min scale, 1.5db steps, no mute */
148static const DECLARE_TLV_DB_SCALE(adc_rec_tlv, -1650, 150, 0);
Lars-Peter Clausenec7e4dc2015-08-02 17:19:33 +0200149static const DECLARE_TLV_DB_RANGE(boost_tlv,
Paul Fertserabb015b2012-02-11 23:26:36 +0200150 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
Lars-Peter Clausenec7e4dc2015-08-02 17:19:33 +0200151 1, 3, TLV_DB_SCALE_ITEM(2000, 1000, 0)
152);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200153/* 0db min scale, 6 db steps, no mute */
154static const DECLARE_TLV_DB_SCALE(dig_tlv, 0, 600, 0);
155/* 0db min scalem 0.75db steps, no mute */
Andrey Danin39be1af2012-02-11 23:26:28 +0200156static const DECLARE_TLV_DB_SCALE(vdac_tlv, -3525, 75, 0);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200157
158static 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 Danin1a083252011-11-13 21:53:13 +0200161 SOC_DOUBLE_TLV("Speaker Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200162 ALC5632_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
163 /* bit 15 mutes left, bit 7 right */
Andrey Danin1a083252011-11-13 21:53:13 +0200164 SOC_DOUBLE("Speaker Playback Switch",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200165 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
172static 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),
Andrey Danin0a2c0562012-02-11 23:26:29 +0200179 SOC_SINGLE("Voice DAC Playback Switch",
180 ALC5632_VOICE_DAC_VOL, 12, 1, 1),
Paul Fertser5148aed2012-02-11 23:26:37 +0200181 SOC_SINGLE_TLV("Phone Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200182 ALC5632_PHONE_IN_VOL, 8, 31, 1, vol_tlv),
Paul Fertser5148aed2012-02-11 23:26:37 +0200183 SOC_DOUBLE_TLV("LineIn Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200184 ALC5632_LINE_IN_VOL, 8, 0, 31, 1, vol_tlv),
Andrey Danin1a083252011-11-13 21:53:13 +0200185 SOC_DOUBLE_TLV("Master Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200186 ALC5632_STEREO_DAC_IN_VOL, 8, 0, 63, 1, vdac_tlv),
Andrey Danin1a083252011-11-13 21:53:13 +0200187 SOC_DOUBLE("Master Playback Switch",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200188 ALC5632_STEREO_DAC_IN_VOL, 15, 7, 1, 1),
Paul Fertser5148aed2012-02-11 23:26:37 +0200189 SOC_SINGLE_TLV("Mic1 Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200190 ALC5632_MIC_VOL, 8, 31, 1, vol_tlv),
Paul Fertser5148aed2012-02-11 23:26:37 +0200191 SOC_SINGLE_TLV("Mic2 Playback Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200192 ALC5632_MIC_VOL, 0, 31, 1, vol_tlv),
193 SOC_DOUBLE_TLV("Rec Capture Volume",
194 ALC5632_ADC_REC_GAIN, 8, 0, 31, 0, adc_rec_tlv),
195 SOC_SINGLE_TLV("Mic 1 Boost Volume",
Paul Fertserabb015b2012-02-11 23:26:36 +0200196 ALC5632_MIC_CTRL, 10, 3, 0, boost_tlv),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200197 SOC_SINGLE_TLV("Mic 2 Boost Volume",
Paul Fertserabb015b2012-02-11 23:26:36 +0200198 ALC5632_MIC_CTRL, 8, 3, 0, boost_tlv),
Paul Fertser5148aed2012-02-11 23:26:37 +0200199 SOC_SINGLE_TLV("DMIC Boost Capture Volume",
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200200 ALC5632_DIGI_BOOST_CTRL, 0, 7, 0, dig_tlv),
Andrey Danin5e4e94a2012-02-11 23:26:33 +0200201 SOC_SINGLE("DMIC En Capture Switch",
202 ALC5632_DIGI_BOOST_CTRL, 15, 1, 0),
203 SOC_SINGLE("DMIC PreFilter Capture Switch",
204 ALC5632_DIGI_BOOST_CTRL, 12, 1, 0),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200205};
206
207/*
208 * DAPM Controls
209 */
210static const struct snd_kcontrol_new alc5632_hp_mixer_controls[] = {
211SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5632_LINE_IN_VOL, 15, 1, 1),
212SOC_DAPM_SINGLE("PHONE2HP Playback Switch", ALC5632_PHONE_IN_VOL, 15, 1, 1),
213SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 15, 1, 1),
214SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 11, 1, 1),
215SOC_DAPM_SINGLE("VOICE2HP Playback Switch", ALC5632_VOICE_DAC_VOL, 15, 1, 1),
216};
217
218static const struct snd_kcontrol_new alc5632_hpl_mixer_controls[] = {
219SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5632_ADC_REC_GAIN, 15, 1, 1),
220SOC_DAPM_SINGLE("DACL2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 3, 1, 1),
221};
222
223static const struct snd_kcontrol_new alc5632_hpr_mixer_controls[] = {
224SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5632_ADC_REC_GAIN, 7, 1, 1),
225SOC_DAPM_SINGLE("DACR2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL, 2, 1, 1),
226};
227
228static const struct snd_kcontrol_new alc5632_mono_mixer_controls[] = {
229SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5632_ADC_REC_GAIN, 14, 1, 1),
230SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5632_ADC_REC_GAIN, 6, 1, 1),
231SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5632_LINE_IN_VOL, 13, 1, 1),
232SOC_DAPM_SINGLE("MIC12MONO Playback Switch",
233 ALC5632_MIC_ROUTING_CTRL, 13, 1, 1),
234SOC_DAPM_SINGLE("MIC22MONO Playback Switch",
235 ALC5632_MIC_ROUTING_CTRL, 9, 1, 1),
236SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5632_MIC_ROUTING_CTRL, 0, 1, 1),
237SOC_DAPM_SINGLE("VOICE2MONO Playback Switch", ALC5632_VOICE_DAC_VOL, 13, 1, 1),
238};
239
240static const struct snd_kcontrol_new alc5632_speaker_mixer_controls[] = {
241SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5632_LINE_IN_VOL, 14, 1, 1),
242SOC_DAPM_SINGLE("PHONE2SPK Playback Switch", ALC5632_PHONE_IN_VOL, 14, 1, 1),
243SOC_DAPM_SINGLE("MIC12SPK Playback Switch",
244 ALC5632_MIC_ROUTING_CTRL, 14, 1, 1),
245SOC_DAPM_SINGLE("MIC22SPK Playback Switch",
246 ALC5632_MIC_ROUTING_CTRL, 10, 1, 1),
247SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5632_MIC_ROUTING_CTRL, 1, 1, 1),
248SOC_DAPM_SINGLE("VOICE2SPK Playback Switch", ALC5632_VOICE_DAC_VOL, 14, 1, 1),
249};
250
251/* Left Record Mixer */
252static const struct snd_kcontrol_new alc5632_captureL_mixer_controls[] = {
Andrey Danina15a9af2012-02-11 23:26:30 +0200253SOC_DAPM_SINGLE("MIC12REC_L Capture Switch", ALC5632_ADC_REC_MIXER, 14, 1, 1),
254SOC_DAPM_SINGLE("MIC22REC_L Capture Switch", ALC5632_ADC_REC_MIXER, 13, 1, 1),
255SOC_DAPM_SINGLE("LIL2REC Capture Switch", ALC5632_ADC_REC_MIXER, 12, 1, 1),
256SOC_DAPM_SINGLE("PH2REC_L Capture Switch", ALC5632_ADC_REC_MIXER, 11, 1, 1),
257SOC_DAPM_SINGLE("HPL2REC Capture Switch", ALC5632_ADC_REC_MIXER, 10, 1, 1),
258SOC_DAPM_SINGLE("SPK2REC_L Capture Switch", ALC5632_ADC_REC_MIXER, 9, 1, 1),
259SOC_DAPM_SINGLE("MONO2REC_L Capture Switch", ALC5632_ADC_REC_MIXER, 8, 1, 1),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200260};
261
262/* Right Record Mixer */
263static const struct snd_kcontrol_new alc5632_captureR_mixer_controls[] = {
Andrey Danina15a9af2012-02-11 23:26:30 +0200264SOC_DAPM_SINGLE("MIC12REC_R Capture Switch", ALC5632_ADC_REC_MIXER, 6, 1, 1),
265SOC_DAPM_SINGLE("MIC22REC_R Capture Switch", ALC5632_ADC_REC_MIXER, 5, 1, 1),
266SOC_DAPM_SINGLE("LIR2REC Capture Switch", ALC5632_ADC_REC_MIXER, 4, 1, 1),
267SOC_DAPM_SINGLE("PH2REC_R Capture Switch", ALC5632_ADC_REC_MIXER, 3, 1, 1),
268SOC_DAPM_SINGLE("HPR2REC Capture Switch", ALC5632_ADC_REC_MIXER, 2, 1, 1),
269SOC_DAPM_SINGLE("SPK2REC_R Capture Switch", ALC5632_ADC_REC_MIXER, 1, 1, 1),
270SOC_DAPM_SINGLE("MONO2REC_R Capture Switch", ALC5632_ADC_REC_MIXER, 0, 1, 1),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200271};
272
Andrey Danin5e4e94a2012-02-11 23:26:33 +0200273/* Dmic Mixer */
274static const struct snd_kcontrol_new alc5632_dmicl_mixer_controls[] = {
275SOC_DAPM_SINGLE("DMICL2ADC Capture Switch", ALC5632_DIGI_BOOST_CTRL, 7, 1, 1),
276};
277static const struct snd_kcontrol_new alc5632_dmicr_mixer_controls[] = {
278SOC_DAPM_SINGLE("DMICR2ADC Capture Switch", ALC5632_DIGI_BOOST_CTRL, 6, 1, 1),
279};
280
Andrey Danin75b35662012-02-11 23:26:32 +0200281static const char * const alc5632_spk_n_sour_sel[] = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200282 "RN/-R", "RP/+R", "LN/-R", "Mute"};
Andrey Danin75b35662012-02-11 23:26:32 +0200283static const char * const alc5632_hpl_out_input_sel[] = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200284 "Vmid", "HP Left Mix"};
Andrey Danin75b35662012-02-11 23:26:32 +0200285static const char * const alc5632_hpr_out_input_sel[] = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200286 "Vmid", "HP Right Mix"};
Andrey Danin75b35662012-02-11 23:26:32 +0200287static const char * const alc5632_spkout_input_sel[] = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200288 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
Andrey Danin75b35662012-02-11 23:26:32 +0200289static const char * const alc5632_aux_out_input_sel[] = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200290 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
Andrey Danin75b35662012-02-11 23:26:32 +0200291static const char * const alc5632_adcr_func_sel[] = {
292 "Stereo ADC", "Voice ADC"};
293static const char * const alc5632_i2s_out_sel[] = {
294 "ADC LR", "Voice Stereo Digital"};
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200295
296/* auxout output mux */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100297static SOC_ENUM_SINGLE_DECL(alc5632_aux_out_input_enum,
298 ALC5632_OUTPUT_MIXER_CTRL, 6,
299 alc5632_aux_out_input_sel);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200300static const struct snd_kcontrol_new alc5632_auxout_mux_controls =
301SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum);
302
303/* speaker output mux */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100304static SOC_ENUM_SINGLE_DECL(alc5632_spkout_input_enum,
305 ALC5632_OUTPUT_MIXER_CTRL, 10,
306 alc5632_spkout_input_sel);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200307static const struct snd_kcontrol_new alc5632_spkout_mux_controls =
308SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum);
309
310/* headphone left output mux */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100311static SOC_ENUM_SINGLE_DECL(alc5632_hpl_out_input_enum,
312 ALC5632_OUTPUT_MIXER_CTRL, 9,
313 alc5632_hpl_out_input_sel);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200314static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls =
315SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum);
316
317/* headphone right output mux */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100318static SOC_ENUM_SINGLE_DECL(alc5632_hpr_out_input_enum,
319 ALC5632_OUTPUT_MIXER_CTRL, 8,
320 alc5632_hpr_out_input_sel);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200321static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls =
322SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum);
323
324/* speaker output N select */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100325static SOC_ENUM_SINGLE_DECL(alc5632_spk_n_sour_enum,
326 ALC5632_OUTPUT_MIXER_CTRL, 14,
327 alc5632_spk_n_sour_sel);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200328static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls =
329SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum);
330
331/* speaker amplifier */
332static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"};
Takashi Iwaie84f2462014-02-18 10:44:32 +0100333static SOC_ENUM_SINGLE_DECL(alc5632_amp_enum,
334 ALC5632_OUTPUT_MIXER_CTRL, 13,
335 alc5632_amp_names);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200336static const struct snd_kcontrol_new alc5632_amp_mux_controls =
337 SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum);
338
Andrey Danin75b35662012-02-11 23:26:32 +0200339/* ADC output select */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100340static SOC_ENUM_SINGLE_DECL(alc5632_adcr_func_enum,
341 ALC5632_DAC_FUNC_SELECT, 5,
342 alc5632_adcr_func_sel);
Andrey Danin75b35662012-02-11 23:26:32 +0200343static const struct snd_kcontrol_new alc5632_adcr_func_controls =
344 SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum);
345
346/* I2S out select */
Takashi Iwaie84f2462014-02-18 10:44:32 +0100347static SOC_ENUM_SINGLE_DECL(alc5632_i2s_out_enum,
348 ALC5632_I2S_OUT_CTL, 5,
349 alc5632_i2s_out_sel);
Andrey Danin75b35662012-02-11 23:26:32 +0200350static const struct snd_kcontrol_new alc5632_i2s_out_controls =
351 SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200352
353static const struct snd_soc_dapm_widget alc5632_dapm_widgets[] = {
354/* Muxes */
355SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM, 0, 0,
356 &alc5632_auxout_mux_controls),
357SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM, 0, 0,
358 &alc5632_spkout_mux_controls),
359SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0,
360 &alc5632_hpl_out_mux_controls),
361SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0,
362 &alc5632_hpr_out_mux_controls),
363SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM, 0, 0,
364 &alc5632_spkoutn_mux_controls),
Andrey Danin75b35662012-02-11 23:26:32 +0200365SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0,
366 &alc5632_adcr_func_controls),
Andrey Danin9e751772012-02-11 23:26:34 +0200367SND_SOC_DAPM_MUX("I2SOut Mux", ALC5632_PWR_MANAG_ADD1, 11, 0,
Andrey Danin75b35662012-02-11 23:26:32 +0200368 &alc5632_i2s_out_controls),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200369
370/* output mixers */
371SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM, 0, 0,
372 &alc5632_hp_mixer_controls[0],
373 ARRAY_SIZE(alc5632_hp_mixer_controls)),
374SND_SOC_DAPM_MIXER("HPR Mix", ALC5632_PWR_MANAG_ADD2, 4, 0,
375 &alc5632_hpr_mixer_controls[0],
376 ARRAY_SIZE(alc5632_hpr_mixer_controls)),
377SND_SOC_DAPM_MIXER("HPL Mix", ALC5632_PWR_MANAG_ADD2, 5, 0,
378 &alc5632_hpl_mixer_controls[0],
379 ARRAY_SIZE(alc5632_hpl_mixer_controls)),
380SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
381SND_SOC_DAPM_MIXER("Mono Mix", ALC5632_PWR_MANAG_ADD2, 2, 0,
382 &alc5632_mono_mixer_controls[0],
383 ARRAY_SIZE(alc5632_mono_mixer_controls)),
384SND_SOC_DAPM_MIXER("Speaker Mix", ALC5632_PWR_MANAG_ADD2, 3, 0,
385 &alc5632_speaker_mixer_controls[0],
386 ARRAY_SIZE(alc5632_speaker_mixer_controls)),
Andrey Danin5e4e94a2012-02-11 23:26:33 +0200387SND_SOC_DAPM_MIXER("DMICL Mix", SND_SOC_NOPM, 0, 0,
388 &alc5632_dmicl_mixer_controls[0],
389 ARRAY_SIZE(alc5632_dmicl_mixer_controls)),
390SND_SOC_DAPM_MIXER("DMICR Mix", SND_SOC_NOPM, 0, 0,
391 &alc5632_dmicr_mixer_controls[0],
392 ARRAY_SIZE(alc5632_dmicr_mixer_controls)),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200393
394/* input mixers */
395SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5632_PWR_MANAG_ADD2, 1, 0,
396 &alc5632_captureL_mixer_controls[0],
397 ARRAY_SIZE(alc5632_captureL_mixer_controls)),
398SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5632_PWR_MANAG_ADD2, 0, 0,
399 &alc5632_captureR_mixer_controls[0],
400 ARRAY_SIZE(alc5632_captureR_mixer_controls)),
401
Andrey Danin75b35662012-02-11 23:26:32 +0200402SND_SOC_DAPM_AIF_IN("AIFRXL", "Left HiFi Playback", 0, SND_SOC_NOPM, 0, 0),
403SND_SOC_DAPM_AIF_IN("AIFRXR", "Right HiFi Playback", 0, SND_SOC_NOPM, 0, 0),
404SND_SOC_DAPM_AIF_OUT("AIFTXL", "Left HiFi Capture", 0, SND_SOC_NOPM, 0, 0),
405SND_SOC_DAPM_AIF_OUT("AIFTXR", "Right HiFi Capture", 0, SND_SOC_NOPM, 0, 0),
406SND_SOC_DAPM_AIF_IN("VAIFRX", "Voice Playback", 0, SND_SOC_NOPM, 0, 0),
407SND_SOC_DAPM_AIF_OUT("VAIFTX", "Voice Capture", 0, SND_SOC_NOPM, 0, 0),
408
409SND_SOC_DAPM_DAC("Voice DAC", NULL, ALC5632_PWR_MANAG_ADD2, 10, 0),
410SND_SOC_DAPM_DAC("Left DAC", NULL, ALC5632_PWR_MANAG_ADD2, 9, 0),
411SND_SOC_DAPM_DAC("Right DAC", NULL, ALC5632_PWR_MANAG_ADD2, 8, 0),
412SND_SOC_DAPM_ADC("Left ADC", NULL, ALC5632_PWR_MANAG_ADD2, 7, 0),
413SND_SOC_DAPM_ADC("Right ADC", NULL, ALC5632_PWR_MANAG_ADD2, 6, 0),
414
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200415SND_SOC_DAPM_MIXER("DAC Left Channel", ALC5632_PWR_MANAG_ADD1, 15, 0, NULL, 0),
416SND_SOC_DAPM_MIXER("DAC Right Channel",
417 ALC5632_PWR_MANAG_ADD1, 14, 0, NULL, 0),
418SND_SOC_DAPM_MIXER("I2S Mix", ALC5632_PWR_MANAG_ADD1, 11, 0, NULL, 0),
419SND_SOC_DAPM_MIXER("Phone Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
420SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
Andrey Danin75b35662012-02-11 23:26:32 +0200421SND_SOC_DAPM_MIXER("Voice Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
422SND_SOC_DAPM_MIXER("ADCLR", SND_SOC_NOPM, 0, 0, NULL, 0),
423
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200424SND_SOC_DAPM_PGA("Left Headphone", ALC5632_PWR_MANAG_ADD3, 11, 0, NULL, 0),
425SND_SOC_DAPM_PGA("Right Headphone", ALC5632_PWR_MANAG_ADD3, 10, 0, NULL, 0),
426SND_SOC_DAPM_PGA("Left Speaker", ALC5632_PWR_MANAG_ADD3, 13, 0, NULL, 0),
427SND_SOC_DAPM_PGA("Right Speaker", ALC5632_PWR_MANAG_ADD3, 12, 0, NULL, 0),
428SND_SOC_DAPM_PGA("Aux Out", ALC5632_PWR_MANAG_ADD3, 14, 0, NULL, 0),
429SND_SOC_DAPM_PGA("Left LineIn", ALC5632_PWR_MANAG_ADD3, 7, 0, NULL, 0),
430SND_SOC_DAPM_PGA("Right LineIn", ALC5632_PWR_MANAG_ADD3, 6, 0, NULL, 0),
431SND_SOC_DAPM_PGA("Phone", ALC5632_PWR_MANAG_ADD3, 5, 0, NULL, 0),
432SND_SOC_DAPM_PGA("Phone ADMix", ALC5632_PWR_MANAG_ADD3, 4, 0, NULL, 0),
433SND_SOC_DAPM_PGA("MIC1 PGA", ALC5632_PWR_MANAG_ADD3, 3, 0, NULL, 0),
434SND_SOC_DAPM_PGA("MIC2 PGA", ALC5632_PWR_MANAG_ADD3, 2, 0, NULL, 0),
435SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5632_PWR_MANAG_ADD3, 1, 0, NULL, 0),
436SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5632_PWR_MANAG_ADD3, 0, 0, NULL, 0),
Leon Romanovsky9215aa42011-12-12 21:43:45 +0200437SND_SOC_DAPM_SUPPLY("MICBIAS1", ALC5632_PWR_MANAG_ADD1, 3, 0, NULL, 0),
438SND_SOC_DAPM_SUPPLY("MICBIAS2", ALC5632_PWR_MANAG_ADD1, 2, 0, NULL, 0),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200439
440SND_SOC_DAPM_PGA_E("D Amp", ALC5632_PWR_MANAG_ADD2, 14, 0, NULL, 0,
441 amp_mixer_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
442SND_SOC_DAPM_PGA("AB Amp", ALC5632_PWR_MANAG_ADD2, 15, 0, NULL, 0),
443SND_SOC_DAPM_MUX("AB-D Amp Mux", ALC5632_PWR_MANAG_ADD1, 10, 0,
444 &alc5632_amp_mux_controls),
445
446SND_SOC_DAPM_OUTPUT("AUXOUT"),
447SND_SOC_DAPM_OUTPUT("HPL"),
448SND_SOC_DAPM_OUTPUT("HPR"),
449SND_SOC_DAPM_OUTPUT("SPKOUT"),
450SND_SOC_DAPM_OUTPUT("SPKOUTN"),
Andrey Danin75b35662012-02-11 23:26:32 +0200451
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200452SND_SOC_DAPM_INPUT("LINEINL"),
453SND_SOC_DAPM_INPUT("LINEINR"),
454SND_SOC_DAPM_INPUT("PHONEP"),
455SND_SOC_DAPM_INPUT("PHONEN"),
Andrey Danin75b35662012-02-11 23:26:32 +0200456SND_SOC_DAPM_INPUT("DMICDAT"),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200457SND_SOC_DAPM_INPUT("MIC1"),
458SND_SOC_DAPM_INPUT("MIC2"),
459SND_SOC_DAPM_VMID("Vmid"),
460};
461
462
463static const struct snd_soc_dapm_route alc5632_dapm_routes[] = {
Andrey Danin75b35662012-02-11 23:26:32 +0200464 /* Playback streams */
465 {"Left DAC", NULL, "AIFRXL"},
466 {"Right DAC", NULL, "AIFRXR"},
467
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200468 /* virtual mixer - mixes left & right channels */
469 {"I2S Mix", NULL, "Left DAC"},
470 {"I2S Mix", NULL, "Right DAC"},
471 {"Line Mix", NULL, "Right LineIn"},
472 {"Line Mix", NULL, "Left LineIn"},
473 {"Phone Mix", NULL, "Phone"},
474 {"Phone Mix", NULL, "Phone ADMix"},
475 {"AUXOUT", NULL, "Aux Out"},
476
477 /* DAC */
478 {"DAC Right Channel", NULL, "I2S Mix"},
479 {"DAC Left Channel", NULL, "I2S Mix"},
480
481 /* HP mixer */
482 {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"},
483 {"HPL Mix", NULL, "HP Mix"},
484 {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"},
485 {"HPR Mix", NULL, "HP Mix"},
486 {"HP Mix", "LI2HP Playback Switch", "Line Mix"},
487 {"HP Mix", "PHONE2HP Playback Switch", "Phone Mix"},
488 {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"},
489 {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"},
Andrey Danin75b35662012-02-11 23:26:32 +0200490 {"HP Mix", "VOICE2HP Playback Switch", "Voice Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200491 {"HPR Mix", "DACR2HP Playback Switch", "DAC Right Channel"},
492 {"HPL Mix", "DACL2HP Playback Switch", "DAC Left Channel"},
Marc Dietrich2435d462012-02-11 23:26:35 +0200493 {"HPOut Mix", NULL, "HP Mix"},
494 {"HPOut Mix", NULL, "HPR Mix"},
495 {"HPOut Mix", NULL, "HPL Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200496
497 /* speaker mixer */
498 {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"},
499 {"Speaker Mix", "PHONE2SPK Playback Switch", "Phone Mix"},
500 {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"},
501 {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"},
502 {"Speaker Mix", "DAC2SPK Playback Switch", "DAC Left Channel"},
Andrey Danin75b35662012-02-11 23:26:32 +0200503 {"Speaker Mix", "VOICE2SPK Playback Switch", "Voice Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200504
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200505 /* mono mixer */
506 {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"},
507 {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"},
508 {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200509 {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"},
510 {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"},
511 {"Mono Mix", "DAC2MONO Playback Switch", "DAC Left Channel"},
Andrey Danin75b35662012-02-11 23:26:32 +0200512 {"Mono Mix", "VOICE2MONO Playback Switch", "Voice Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200513
514 /* Left record mixer */
Andrey Danina15a9af2012-02-11 23:26:30 +0200515 {"Left Capture Mix", "LIL2REC Capture Switch", "LINEINL"},
516 {"Left Capture Mix", "PH2REC_L Capture Switch", "PHONEN"},
517 {"Left Capture Mix", "MIC12REC_L Capture Switch", "MIC1 Pre Amp"},
518 {"Left Capture Mix", "MIC22REC_L Capture Switch", "MIC2 Pre Amp"},
519 {"Left Capture Mix", "HPL2REC Capture Switch", "HPL Mix"},
520 {"Left Capture Mix", "SPK2REC_L Capture Switch", "Speaker Mix"},
521 {"Left Capture Mix", "MONO2REC_L Capture Switch", "Mono Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200522
523 /*Right record mixer */
Andrey Danina15a9af2012-02-11 23:26:30 +0200524 {"Right Capture Mix", "LIR2REC Capture Switch", "LINEINR"},
525 {"Right Capture Mix", "PH2REC_R Capture Switch", "PHONEP"},
526 {"Right Capture Mix", "MIC12REC_R Capture Switch", "MIC1 Pre Amp"},
527 {"Right Capture Mix", "MIC22REC_R Capture Switch", "MIC2 Pre Amp"},
528 {"Right Capture Mix", "HPR2REC Capture Switch", "HPR Mix"},
529 {"Right Capture Mix", "SPK2REC_R Capture Switch", "Speaker Mix"},
530 {"Right Capture Mix", "MONO2REC_R Capture Switch", "Mono Mix"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200531
532 /* headphone left mux */
533 {"Left Headphone Mux", "HP Left Mix", "HPL Mix"},
534 {"Left Headphone Mux", "Vmid", "Vmid"},
535
536 /* headphone right mux */
537 {"Right Headphone Mux", "HP Right Mix", "HPR Mix"},
538 {"Right Headphone Mux", "Vmid", "Vmid"},
539
540 /* speaker out mux */
541 {"SpeakerOut Mux", "Vmid", "Vmid"},
542 {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"},
543 {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"},
544 {"SpeakerOut Mux", "Mono Mix", "Mono Mix"},
545
546 /* Mono/Aux Out mux */
547 {"AuxOut Mux", "Vmid", "Vmid"},
548 {"AuxOut Mux", "HPOut Mix", "HPOut Mix"},
549 {"AuxOut Mux", "Speaker Mix", "Speaker Mix"},
550 {"AuxOut Mux", "Mono Mix", "Mono Mix"},
551
552 /* output pga */
553 {"HPL", NULL, "Left Headphone"},
554 {"Left Headphone", NULL, "Left Headphone Mux"},
555 {"HPR", NULL, "Right Headphone"},
556 {"Right Headphone", NULL, "Right Headphone Mux"},
557 {"Aux Out", NULL, "AuxOut Mux"},
558
559 /* input pga */
560 {"Left LineIn", NULL, "LINEINL"},
561 {"Right LineIn", NULL, "LINEINR"},
562 {"Phone", NULL, "PHONEP"},
563 {"MIC1 Pre Amp", NULL, "MIC1"},
564 {"MIC2 Pre Amp", NULL, "MIC2"},
565 {"MIC1 PGA", NULL, "MIC1 Pre Amp"},
566 {"MIC2 PGA", NULL, "MIC2 Pre Amp"},
567
568 /* left ADC */
569 {"Left ADC", NULL, "Left Capture Mix"},
Andrey Danin5e4e94a2012-02-11 23:26:33 +0200570 {"DMICL Mix", "DMICL2ADC Capture Switch", "DMICDAT"},
571 {"Left ADC", NULL, "DMICL Mix"},
Andrey Danin75b35662012-02-11 23:26:32 +0200572 {"ADCLR", NULL, "Left ADC"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200573
574 /* right ADC */
Andrey Danin75b35662012-02-11 23:26:32 +0200575 {"Right ADC", NULL, "Right Capture Mix"},
Andrey Danin5e4e94a2012-02-11 23:26:33 +0200576 {"DMICR Mix", "DMICR2ADC Capture Switch", "DMICDAT"},
577 {"Right ADC", NULL, "DMICR Mix"},
Andrey Danin75b35662012-02-11 23:26:32 +0200578 {"ADCR Mux", "Stereo ADC", "Right ADC"},
579 {"ADCR Mux", "Voice ADC", "Right ADC"},
580 {"ADCLR", NULL, "ADCR Mux"},
581 {"VAIFTX", NULL, "ADCR Mux"},
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200582
Andrey Danin75b35662012-02-11 23:26:32 +0200583 /* Digital I2S out */
584 {"I2SOut Mux", "ADC LR", "ADCLR"},
585 {"I2SOut Mux", "Voice Stereo Digital", "VAIFRX"},
586 {"AIFTXL", NULL, "I2SOut Mux"},
587 {"AIFTXR", NULL, "I2SOut Mux"},
588
589 /* Voice Mix */
590 {"Voice DAC", NULL, "VAIFRX"},
591 {"Voice Mix", NULL, "Voice DAC"},
592
593 /* Speaker Output */
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200594 {"SpeakerOut N Mux", "RN/-R", "Left Speaker"},
595 {"SpeakerOut N Mux", "RP/+R", "Left Speaker"},
596 {"SpeakerOut N Mux", "LN/-R", "Left Speaker"},
597 {"SpeakerOut N Mux", "Mute", "Vmid"},
598
599 {"SpeakerOut N Mux", "RN/-R", "Right Speaker"},
600 {"SpeakerOut N Mux", "RP/+R", "Right Speaker"},
601 {"SpeakerOut N Mux", "LN/-R", "Right Speaker"},
602 {"SpeakerOut N Mux", "Mute", "Vmid"},
603
604 {"AB Amp", NULL, "SpeakerOut Mux"},
605 {"D Amp", NULL, "SpeakerOut Mux"},
606 {"AB-D Amp Mux", "AB Amp", "AB Amp"},
607 {"AB-D Amp Mux", "D Amp", "D Amp"},
608 {"Left Speaker", NULL, "AB-D Amp Mux"},
609 {"Right Speaker", NULL, "AB-D Amp Mux"},
610
611 {"SPKOUT", NULL, "Left Speaker"},
612 {"SPKOUT", NULL, "Right Speaker"},
613
614 {"SPKOUTN", NULL, "SpeakerOut N Mux"},
615
616};
617
618/* PLL divisors */
619struct _pll_div {
620 u32 pll_in;
621 u32 pll_out;
622 u16 regvalue;
623};
624
625/* Note : pll code from original alc5632 driver. Not sure of how good it is */
Michael Opdenacker73678802013-09-18 06:04:48 +0200626/* useful only for master mode */
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200627static const struct _pll_div codec_master_pll_div[] = {
628
629 { 2048000, 8192000, 0x0ea0},
630 { 3686400, 8192000, 0x4e27},
631 { 12000000, 8192000, 0x456b},
632 { 13000000, 8192000, 0x495f},
633 { 13100000, 8192000, 0x0320},
634 { 2048000, 11289600, 0xf637},
635 { 3686400, 11289600, 0x2f22},
636 { 12000000, 11289600, 0x3e2f},
637 { 13000000, 11289600, 0x4d5b},
638 { 13100000, 11289600, 0x363b},
639 { 2048000, 16384000, 0x1ea0},
640 { 3686400, 16384000, 0x9e27},
641 { 12000000, 16384000, 0x452b},
642 { 13000000, 16384000, 0x542f},
643 { 13100000, 16384000, 0x03a0},
644 { 2048000, 16934400, 0xe625},
645 { 3686400, 16934400, 0x9126},
646 { 12000000, 16934400, 0x4d2c},
647 { 13000000, 16934400, 0x742f},
648 { 13100000, 16934400, 0x3c27},
649 { 2048000, 22579200, 0x2aa0},
650 { 3686400, 22579200, 0x2f20},
651 { 12000000, 22579200, 0x7e2f},
652 { 13000000, 22579200, 0x742f},
653 { 13100000, 22579200, 0x3c27},
654 { 2048000, 24576000, 0x2ea0},
655 { 3686400, 24576000, 0xee27},
656 { 12000000, 24576000, 0x2915},
657 { 13000000, 24576000, 0x772e},
658 { 13100000, 24576000, 0x0d20},
659};
660
661/* FOUT = MCLK*(N+2)/((M+2)*(K+2))
662 N: bit 15:8 (div 2 .. div 257)
663 K: bit 6:4 typical 2
664 M: bit 3:0 (div 2 .. div 17)
665
666 same as for 5623 - thanks!
667*/
668
669static const struct _pll_div codec_slave_pll_div[] = {
670
671 { 1024000, 16384000, 0x3ea0},
672 { 1411200, 22579200, 0x3ea0},
673 { 1536000, 24576000, 0x3ea0},
674 { 2048000, 16384000, 0x1ea0},
675 { 2822400, 22579200, 0x1ea0},
676 { 3072000, 24576000, 0x1ea0},
677
678};
679
680static int alc5632_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
681 int source, unsigned int freq_in, unsigned int freq_out)
682{
683 int i;
684 struct snd_soc_codec *codec = codec_dai->codec;
685 int gbl_clk = 0, pll_div = 0;
686 u16 reg;
687
688 if (pll_id < ALC5632_PLL_FR_MCLK || pll_id > ALC5632_PLL_FR_VBCLK)
689 return -EINVAL;
690
691 /* Disable PLL power */
692 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
693 ALC5632_PWR_ADD2_PLL1,
694 0);
695 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
696 ALC5632_PWR_ADD2_PLL2,
697 0);
698
699 /* pll is not used in slave mode */
700 reg = snd_soc_read(codec, ALC5632_DAI_CONTROL);
701 if (reg & ALC5632_DAI_SDP_SLAVE_MODE)
702 return 0;
703
704 if (!freq_in || !freq_out)
705 return 0;
706
707 switch (pll_id) {
708 case ALC5632_PLL_FR_MCLK:
709 for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) {
710 if (codec_master_pll_div[i].pll_in == freq_in
711 && codec_master_pll_div[i].pll_out == freq_out) {
712 /* PLL source from MCLK */
713 pll_div = codec_master_pll_div[i].regvalue;
714 break;
715 }
716 }
717 break;
718 case ALC5632_PLL_FR_BCLK:
719 for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {
720 if (codec_slave_pll_div[i].pll_in == freq_in
721 && codec_slave_pll_div[i].pll_out == freq_out) {
722 /* PLL source from Bitclk */
723 gbl_clk = ALC5632_PLL_FR_BCLK;
724 pll_div = codec_slave_pll_div[i].regvalue;
725 break;
726 }
727 }
728 break;
729 case ALC5632_PLL_FR_VBCLK:
730 for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {
731 if (codec_slave_pll_div[i].pll_in == freq_in
732 && codec_slave_pll_div[i].pll_out == freq_out) {
733 /* PLL source from voice clock */
734 gbl_clk = ALC5632_PLL_FR_VBCLK;
735 pll_div = codec_slave_pll_div[i].regvalue;
736 break;
737 }
738 }
739 break;
740 default:
741 return -EINVAL;
742 }
743
744 if (!pll_div)
745 return -EINVAL;
746
747 /* choose MCLK/BCLK/VBCLK */
748 snd_soc_write(codec, ALC5632_GPCR2, gbl_clk);
749 /* choose PLL1 clock rate */
750 snd_soc_write(codec, ALC5632_PLL1_CTRL, pll_div);
751 /* enable PLL1 */
752 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
753 ALC5632_PWR_ADD2_PLL1,
754 ALC5632_PWR_ADD2_PLL1);
755 /* enable PLL2 */
756 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
757 ALC5632_PWR_ADD2_PLL2,
758 ALC5632_PWR_ADD2_PLL2);
759 /* use PLL1 as main SYSCLK */
760 snd_soc_update_bits(codec, ALC5632_GPCR1,
761 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1,
762 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1);
763
764 return 0;
765}
766
767struct _coeff_div {
768 u16 fs;
769 u16 regvalue;
770};
771
772/* codec hifi mclk (after PLL) clock divider coefficients */
773/* values inspired from column BCLK=32Fs of Appendix A table */
774static const struct _coeff_div coeff_div[] = {
775 {512*1, 0x3075},
776};
777
778static int get_coeff(struct snd_soc_codec *codec, int rate)
779{
780 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
781 int i;
782
783 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
784 if (coeff_div[i].fs * rate == alc5632->sysclk)
785 return i;
786 }
787 return -EINVAL;
788}
789
790/*
791 * Clock after PLL and dividers
792 */
793static int alc5632_set_dai_sysclk(struct snd_soc_dai *codec_dai,
794 int clk_id, unsigned int freq, int dir)
795{
796 struct snd_soc_codec *codec = codec_dai->codec;
797 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
798
799 switch (freq) {
Andrey Danin0f613c22012-02-11 23:26:38 +0200800 case 4096000:
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200801 case 8192000:
802 case 11289600:
803 case 12288000:
804 case 16384000:
805 case 16934400:
806 case 18432000:
807 case 22579200:
808 case 24576000:
809 alc5632->sysclk = freq;
810 return 0;
811 }
812 return -EINVAL;
813}
814
815static int alc5632_set_dai_fmt(struct snd_soc_dai *codec_dai,
816 unsigned int fmt)
817{
818 struct snd_soc_codec *codec = codec_dai->codec;
819 u16 iface = 0;
820
821 /* set master/slave audio interface */
822 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
823 case SND_SOC_DAIFMT_CBM_CFM:
824 iface = ALC5632_DAI_SDP_MASTER_MODE;
825 break;
826 case SND_SOC_DAIFMT_CBS_CFS:
827 iface = ALC5632_DAI_SDP_SLAVE_MODE;
828 break;
829 default:
830 return -EINVAL;
831 }
832
833 /* interface format */
834 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
835 case SND_SOC_DAIFMT_I2S:
836 iface |= ALC5632_DAI_I2S_DF_I2S;
837 break;
838 case SND_SOC_DAIFMT_LEFT_J:
839 iface |= ALC5632_DAI_I2S_DF_LEFT;
840 break;
841 case SND_SOC_DAIFMT_DSP_A:
842 iface |= ALC5632_DAI_I2S_DF_PCM_A;
843 break;
844 case SND_SOC_DAIFMT_DSP_B:
845 iface |= ALC5632_DAI_I2S_DF_PCM_B;
846 break;
847 default:
848 return -EINVAL;
849 }
850
851 /* clock inversion */
852 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
853 case SND_SOC_DAIFMT_NB_NF:
854 break;
855 case SND_SOC_DAIFMT_IB_IF:
856 iface |= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL;
857 break;
858 case SND_SOC_DAIFMT_IB_NF:
859 iface |= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL;
860 break;
861 case SND_SOC_DAIFMT_NB_IF:
862 break;
863 default:
864 return -EINVAL;
865 }
866
867 return snd_soc_write(codec, ALC5632_DAI_CONTROL, iface);
868}
869
870static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream,
871 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
872{
Mark Browne6968a12012-04-04 15:58:16 +0100873 struct snd_soc_codec *codec = dai->codec;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200874 int coeff, rate;
875 u16 iface;
876
877 iface = snd_soc_read(codec, ALC5632_DAI_CONTROL);
878 iface &= ~ALC5632_DAI_I2S_DL_MASK;
879
880 /* bit size */
Mark Brown2dad2282014-01-08 19:28:27 +0000881 switch (params_width(params)) {
882 case 16:
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200883 iface |= ALC5632_DAI_I2S_DL_16;
884 break;
Mark Brown2dad2282014-01-08 19:28:27 +0000885 case 20:
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200886 iface |= ALC5632_DAI_I2S_DL_20;
887 break;
Mark Brown2dad2282014-01-08 19:28:27 +0000888 case 24:
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200889 iface |= ALC5632_DAI_I2S_DL_24;
890 break;
891 default:
892 return -EINVAL;
893 }
894
895 /* set iface & srate */
896 snd_soc_write(codec, ALC5632_DAI_CONTROL, iface);
897 rate = params_rate(params);
898 coeff = get_coeff(codec, rate);
899 if (coeff < 0)
900 return -EINVAL;
901
902 coeff = coeff_div[coeff].regvalue;
903 snd_soc_write(codec, ALC5632_DAC_CLK_CTRL1, coeff);
904
905 return 0;
906}
907
908static int alc5632_mute(struct snd_soc_dai *dai, int mute)
909{
910 struct snd_soc_codec *codec = dai->codec;
Leon Romanovsky88c494b2011-11-10 21:22:16 +0200911 u16 hp_mute = ALC5632_MISC_HP_DEPOP_MUTE_L
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +0200912 |ALC5632_MISC_HP_DEPOP_MUTE_R;
913 u16 mute_reg = snd_soc_read(codec, ALC5632_MISC_CTRL) & ~hp_mute;
914
915 if (mute)
916 mute_reg |= hp_mute;
917
918 return snd_soc_write(codec, ALC5632_MISC_CTRL, mute_reg);
919}
920
921#define ALC5632_ADD2_POWER_EN (ALC5632_PWR_ADD2_VREF)
922
923#define ALC5632_ADD3_POWER_EN (ALC5632_PWR_ADD3_MIC1_BOOST_AD)
924
925#define ALC5632_ADD1_POWER_EN \
926 (ALC5632_PWR_ADD1_DAC_REF \
927 | ALC5632_PWR_ADD1_SOFTGEN_EN \
928 | ALC5632_PWR_ADD1_HP_OUT_AMP \
929 | ALC5632_PWR_ADD1_HP_OUT_ENH_AMP \
930 | ALC5632_PWR_ADD1_MAIN_BIAS)
931
932static void enable_power_depop(struct snd_soc_codec *codec)
933{
934 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1,
935 ALC5632_PWR_ADD1_SOFTGEN_EN,
936 ALC5632_PWR_ADD1_SOFTGEN_EN);
937
938 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD3,
939 ALC5632_ADD3_POWER_EN,
940 ALC5632_ADD3_POWER_EN);
941
942 snd_soc_update_bits(codec, ALC5632_MISC_CTRL,
943 ALC5632_MISC_HP_DEPOP_MODE2_EN,
944 ALC5632_MISC_HP_DEPOP_MODE2_EN);
945
946 /* "normal" mode: 0 @ 26 */
947 /* set all PR0-7 mixers to 0 */
948 snd_soc_update_bits(codec, ALC5632_PWR_DOWN_CTRL_STATUS,
949 ALC5632_PWR_DOWN_CTRL_STATUS_MASK,
950 0);
951
952 msleep(500);
953
954 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
955 ALC5632_ADD2_POWER_EN,
956 ALC5632_ADD2_POWER_EN);
957
958 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1,
959 ALC5632_ADD1_POWER_EN,
960 ALC5632_ADD1_POWER_EN);
961
962 /* disable HP Depop2 */
963 snd_soc_update_bits(codec, ALC5632_MISC_CTRL,
964 ALC5632_MISC_HP_DEPOP_MODE2_EN,
965 0);
966
967}
968
969static int alc5632_set_bias_level(struct snd_soc_codec *codec,
970 enum snd_soc_bias_level level)
971{
972 switch (level) {
973 case SND_SOC_BIAS_ON:
974 enable_power_depop(codec);
975 break;
976 case SND_SOC_BIAS_PREPARE:
977 break;
978 case SND_SOC_BIAS_STANDBY:
979 /* everything off except vref/vmid, */
980 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1,
981 ALC5632_PWR_MANAG_ADD1_MASK,
982 ALC5632_PWR_ADD1_MAIN_BIAS);
983 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
984 ALC5632_PWR_MANAG_ADD2_MASK,
985 ALC5632_PWR_ADD2_VREF);
986 /* "normal" mode: 0 @ 26 */
987 snd_soc_update_bits(codec, ALC5632_PWR_DOWN_CTRL_STATUS,
988 ALC5632_PWR_DOWN_CTRL_STATUS_MASK,
989 0xffff ^ (ALC5632_PWR_VREF_PR3
990 | ALC5632_PWR_VREF_PR2));
991 break;
992 case SND_SOC_BIAS_OFF:
993 /* everything off, dac mute, inactive */
994 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD2,
995 ALC5632_PWR_MANAG_ADD2_MASK, 0);
996 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD3,
997 ALC5632_PWR_MANAG_ADD3_MASK, 0);
998 snd_soc_update_bits(codec, ALC5632_PWR_MANAG_ADD1,
999 ALC5632_PWR_MANAG_ADD1_MASK, 0);
1000 break;
1001 }
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001002 return 0;
1003}
1004
1005#define ALC5632_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
1006 | SNDRV_PCM_FMTBIT_S24_LE \
1007 | SNDRV_PCM_FMTBIT_S32_LE)
1008
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001009static const struct snd_soc_dai_ops alc5632_dai_ops = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001010 .hw_params = alc5632_pcm_hw_params,
1011 .digital_mute = alc5632_mute,
1012 .set_fmt = alc5632_set_dai_fmt,
1013 .set_sysclk = alc5632_set_dai_sysclk,
1014 .set_pll = alc5632_set_dai_pll,
1015};
1016
1017static struct snd_soc_dai_driver alc5632_dai = {
1018 .name = "alc5632-hifi",
1019 .playback = {
1020 .stream_name = "HiFi Playback",
1021 .channels_min = 1,
1022 .channels_max = 2,
1023 .rate_min = 8000,
1024 .rate_max = 48000,
1025 .rates = SNDRV_PCM_RATE_8000_48000,
1026 .formats = ALC5632_FORMATS,},
1027 .capture = {
1028 .stream_name = "HiFi Capture",
1029 .channels_min = 1,
1030 .channels_max = 2,
1031 .rate_min = 8000,
1032 .rate_max = 48000,
1033 .rates = SNDRV_PCM_RATE_8000_48000,
1034 .formats = ALC5632_FORMATS,},
1035
1036 .ops = &alc5632_dai_ops,
1037 .symmetric_rates = 1,
1038};
1039
Leon Romanovskyc9be8422011-11-16 12:07:00 +02001040#ifdef CONFIG_PM
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001041static int alc5632_resume(struct snd_soc_codec *codec)
1042{
Leon Romanovskybb397532011-11-16 12:06:58 +02001043 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001044
Leon Romanovskybb397532011-11-16 12:06:58 +02001045 regcache_sync(alc5632->regmap);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001046
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001047 return 0;
1048}
Leon Romanovskyc9be8422011-11-16 12:07:00 +02001049#else
Leon Romanovskyc9be8422011-11-16 12:07:00 +02001050#define alc5632_resume NULL
1051#endif
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001052
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001053static int alc5632_probe(struct snd_soc_codec *codec)
1054{
1055 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001056
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001057 switch (alc5632->id) {
1058 case 0x5c:
Liam Girdwood022658b2012-02-03 17:43:09 +00001059 snd_soc_add_codec_controls(codec, alc5632_vol_snd_controls,
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001060 ARRAY_SIZE(alc5632_vol_snd_controls));
1061 break;
1062 default:
1063 return -EINVAL;
1064 }
1065
Stephen Warrene3efe3b2014-03-31 12:25:24 -06001066 return 0;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001067}
1068
Krzysztof Kozlowski2b730cc2015-01-05 10:18:21 +01001069static const struct snd_soc_codec_driver soc_codec_device_alc5632 = {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001070 .probe = alc5632_probe,
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001071 .resume = alc5632_resume,
1072 .set_bias_level = alc5632_set_bias_level,
Lars-Peter Clausen5c9dc082014-11-23 13:47:51 +01001073 .suspend_bias_off = true,
1074
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001075 .controls = alc5632_snd_controls,
1076 .num_controls = ARRAY_SIZE(alc5632_snd_controls),
1077 .dapm_widgets = alc5632_dapm_widgets,
1078 .num_dapm_widgets = ARRAY_SIZE(alc5632_dapm_widgets),
1079 .dapm_routes = alc5632_dapm_routes,
1080 .num_dapm_routes = ARRAY_SIZE(alc5632_dapm_routes),
1081};
1082
Krzysztof Kozlowski2b730cc2015-01-05 10:18:21 +01001083static const struct regmap_config alc5632_regmap = {
Leon Romanovskybb397532011-11-16 12:06:58 +02001084 .reg_bits = 8,
1085 .val_bits = 16,
1086
1087 .max_register = ALC5632_MAX_REGISTER,
1088 .reg_defaults = alc5632_reg_defaults,
1089 .num_reg_defaults = ARRAY_SIZE(alc5632_reg_defaults),
1090 .volatile_reg = alc5632_volatile_register,
1091 .cache_type = REGCACHE_RBTREE,
1092};
1093
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001094/*
1095 * alc5632 2 wire address is determined by A1 pin
1096 * state during powerup.
1097 * low = 0x1a
1098 * high = 0x1b
1099 */
Bill Pemberton7a79e942012-12-07 09:26:37 -05001100static int alc5632_i2c_probe(struct i2c_client *client,
1101 const struct i2c_device_id *id)
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001102{
1103 struct alc5632_priv *alc5632;
Leon Romanovsky277c01b2011-11-17 12:01:30 +02001104 int ret, ret1, ret2;
1105 unsigned int vid1, vid2;
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001106
1107 alc5632 = devm_kzalloc(&client->dev,
1108 sizeof(struct alc5632_priv), GFP_KERNEL);
1109 if (alc5632 == NULL)
1110 return -ENOMEM;
1111
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001112 i2c_set_clientdata(client, alc5632);
Leon Romanovskybb397532011-11-16 12:06:58 +02001113
Axel Lin41a41ea2012-05-08 23:44:55 +08001114 alc5632->regmap = devm_regmap_init_i2c(client, &alc5632_regmap);
Leon Romanovskybb397532011-11-16 12:06:58 +02001115 if (IS_ERR(alc5632->regmap)) {
1116 ret = PTR_ERR(alc5632->regmap);
1117 dev_err(&client->dev, "regmap_init() failed: %d\n", ret);
1118 return ret;
1119 }
1120
Leon Romanovsky277c01b2011-11-17 12:01:30 +02001121 ret1 = regmap_read(alc5632->regmap, ALC5632_VENDOR_ID1, &vid1);
1122 ret2 = regmap_read(alc5632->regmap, ALC5632_VENDOR_ID2, &vid2);
1123 if (ret1 != 0 || ret2 != 0) {
1124 dev_err(&client->dev,
1125 "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2);
Leon Romanovsky277c01b2011-11-17 12:01:30 +02001126 return -EIO;
1127 }
1128
1129 vid2 >>= 8;
1130
1131 if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) {
1132 dev_err(&client->dev,
1133 "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2);
Leon Romanovsky277c01b2011-11-17 12:01:30 +02001134 return -EINVAL;
1135 }
1136
Leon Romanovskybb397532011-11-16 12:06:58 +02001137 ret = alc5632_reset(alc5632->regmap);
1138 if (ret < 0) {
1139 dev_err(&client->dev, "Failed to issue reset\n");
Leon Romanovskybb397532011-11-16 12:06:58 +02001140 return ret;
1141 }
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001142
Leon Romanovsky277c01b2011-11-17 12:01:30 +02001143 alc5632->id = vid2;
1144 switch (alc5632->id) {
1145 case 0x5c:
1146 alc5632_dai.name = "alc5632-hifi";
1147 break;
1148 default:
1149 return -EINVAL;
1150 }
1151
1152 ret = snd_soc_register_codec(&client->dev,
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001153 &soc_codec_device_alc5632, &alc5632_dai, 1);
Leon Romanovskybb397532011-11-16 12:06:58 +02001154
1155 if (ret < 0) {
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001156 dev_err(&client->dev, "Failed to register codec: %d\n", ret);
Leon Romanovskybb397532011-11-16 12:06:58 +02001157 return ret;
1158 }
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001159
1160 return ret;
1161}
1162
Bill Pemberton7a79e942012-12-07 09:26:37 -05001163static int alc5632_i2c_remove(struct i2c_client *client)
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001164{
1165 snd_soc_unregister_codec(&client->dev);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001166 return 0;
1167}
1168
1169static const struct i2c_device_id alc5632_i2c_table[] = {
1170 {"alc5632", 0x5c},
1171 {}
1172};
1173MODULE_DEVICE_TABLE(i2c, alc5632_i2c_table);
1174
Stephen Warrenc31b0cb2014-03-31 12:38:16 -06001175static const struct of_device_id alc5632_of_match[] = {
1176 { .compatible = "realtek,alc5632", },
1177 { }
1178};
1179MODULE_DEVICE_TABLE(of, alc5632_of_match);
1180
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001181/* i2c codec control layer */
1182static struct i2c_driver alc5632_i2c_driver = {
1183 .driver = {
1184 .name = "alc5632",
Stephen Warrenc31b0cb2014-03-31 12:38:16 -06001185 .of_match_table = of_match_ptr(alc5632_of_match),
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001186 },
1187 .probe = alc5632_i2c_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001188 .remove = alc5632_i2c_remove,
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001189 .id_table = alc5632_i2c_table,
1190};
1191
Axel Lin8d8c0b32012-05-08 23:43:33 +08001192module_i2c_driver(alc5632_i2c_driver);
Leon Romanovsky94d5f7c2011-11-05 12:38:02 +02001193
1194MODULE_DESCRIPTION("ASoC ALC5632 driver");
1195MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
1196MODULE_LICENSE("GPL");