blob: e4743684cc1d7065a9218f6c3cf772fd27ed0e4e [file] [log] [blame]
Vinod Koul4dc69be2011-01-04 20:16:07 +05301/*
2 * sn95031.c - TI sn95031 Codec driver
3 *
4 * Copyright (C) 2010 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 *
25 */
26#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
28#include <linux/platform_device.h>
Ingo Molnar438008a2008-11-13 11:51:57 +010029#include <linux/delay.h>
Vinod Koul4dc69be2011-01-04 20:16:07 +053030#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040031#include <linux/module.h>
Ingo Molnar438008a2008-11-13 11:51:57 +010032
Vinod Koul4dc69be2011-01-04 20:16:07 +053033#include <asm/intel_scu_ipc.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37#include <sound/soc-dapm.h>
38#include <sound/initval.h>
Harsha Priyafd94eee2011-01-28 22:26:53 +053039#include <sound/tlv.h>
Vinod Koul1e2f5932011-02-09 21:44:32 +053040#include <sound/jack.h>
Vinod Koul4dc69be2011-01-04 20:16:07 +053041#include "sn95031.h"
42
43#define SN95031_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100)
44#define SN95031_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
45
Vinod Koul36633232011-02-09 21:44:34 +053046/* adc helper functions */
47
48/* enables mic bias voltage */
49static void sn95031_enable_mic_bias(struct snd_soc_codec *codec)
50{
51 snd_soc_write(codec, SN95031_VAUD, BIT(2)|BIT(1)|BIT(0));
52 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(2), BIT(2));
53}
54
55/* Enable/Disable the ADC depending on the argument */
56static void configure_adc(struct snd_soc_codec *sn95031_codec, int val)
57{
58 int value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
59
60 if (val) {
61 /* Enable and start the ADC */
62 value |= (SN95031_ADC_ENBL | SN95031_ADC_START);
63 value &= (~SN95031_ADC_NO_LOOP);
64 } else {
65 /* Just stop the ADC */
66 value &= (~SN95031_ADC_START);
67 }
68 snd_soc_write(sn95031_codec, SN95031_ADC1CNTL1, value);
69}
70
Vinod Koul4dc69be2011-01-04 20:16:07 +053071/*
Vinod Koul36633232011-02-09 21:44:34 +053072 * finds an empty channel for conversion
73 * If the ADC is not enabled then start using 0th channel
74 * itself. Otherwise find an empty channel by looking for a
75 * channel in which the stopbit is set to 1. returns the index
76 * of the first free channel if succeeds or an error code.
77 *
78 * Context: can sleep
79 *
Vinod Koul4dc69be2011-01-04 20:16:07 +053080 */
Vinod Koul36633232011-02-09 21:44:34 +053081static int find_free_channel(struct snd_soc_codec *sn95031_codec)
82{
Axel Lin7b4615b2011-09-03 13:41:47 +080083 int i, value;
Vinod Koul36633232011-02-09 21:44:34 +053084
85 /* check whether ADC is enabled */
86 value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
87
88 if ((value & SN95031_ADC_ENBL) == 0)
89 return 0;
90
91 /* ADC is already enabled; Looking for an empty channel */
92 for (i = 0; i < SN95031_ADC_CHANLS_MAX; i++) {
93 value = snd_soc_read(sn95031_codec,
94 SN95031_ADC_CHNL_START_ADDR + i);
Axel Lin7b4615b2011-09-03 13:41:47 +080095 if (value & SN95031_STOPBIT_MASK)
Vinod Koul36633232011-02-09 21:44:34 +053096 break;
Vinod Koul36633232011-02-09 21:44:34 +053097 }
Axel Lin7b4615b2011-09-03 13:41:47 +080098 return (i == SN95031_ADC_CHANLS_MAX) ? (-EINVAL) : i;
Vinod Koul36633232011-02-09 21:44:34 +053099}
100
101/* Initialize the ADC for reading micbias values. Can sleep. */
102static int sn95031_initialize_adc(struct snd_soc_codec *sn95031_codec)
103{
104 int base_addr, chnl_addr;
105 int value;
Axel Linf34dafb2011-09-30 13:56:59 +0800106 int channel_index;
Vinod Koul36633232011-02-09 21:44:34 +0530107
108 /* Index of the first channel in which the stop bit is set */
109 channel_index = find_free_channel(sn95031_codec);
110 if (channel_index < 0) {
111 pr_err("No free ADC channels");
112 return channel_index;
113 }
114
115 base_addr = SN95031_ADC_CHNL_START_ADDR + channel_index;
116
117 if (!(channel_index == 0 || channel_index == SN95031_ADC_LOOP_MAX)) {
118 /* Reset stop bit for channels other than 0 and 12 */
119 value = snd_soc_read(sn95031_codec, base_addr);
120 /* Set the stop bit to zero */
121 snd_soc_write(sn95031_codec, base_addr, value & 0xEF);
122 /* Index of the first free channel */
123 base_addr++;
124 channel_index++;
125 }
126
127 /* Since this is the last channel, set the stop bit
128 to 1 by ORing the DIE_SENSOR_CODE with 0x10 */
129 snd_soc_write(sn95031_codec, base_addr,
130 SN95031_AUDIO_DETECT_CODE | 0x10);
131
132 chnl_addr = SN95031_ADC_DATA_START_ADDR + 2 * channel_index;
133 pr_debug("mid_initialize : %x", chnl_addr);
134 configure_adc(sn95031_codec, 1);
135 return chnl_addr;
136}
137
138
139/* reads the ADC registers and gets the mic bias value in mV. */
140static unsigned int sn95031_get_mic_bias(struct snd_soc_codec *codec)
141{
142 u16 adc_adr = sn95031_initialize_adc(codec);
143 u16 adc_val1, adc_val2;
144 unsigned int mic_bias;
145
146 sn95031_enable_mic_bias(codec);
147
148 /* Enable the sound card for conversion before reading */
149 snd_soc_write(codec, SN95031_ADC1CNTL3, 0x05);
150 /* Re-toggle the RRDATARD bit */
151 snd_soc_write(codec, SN95031_ADC1CNTL3, 0x04);
152
153 /* Read the higher bits of data */
154 msleep(1000);
155 adc_val1 = snd_soc_read(codec, adc_adr);
156 adc_adr++;
157 adc_val2 = snd_soc_read(codec, adc_adr);
158
159 /* Adding lower two bits to the higher bits */
160 mic_bias = (adc_val1 << 2) + (adc_val2 & 3);
161 mic_bias = (mic_bias * SN95031_ADC_ONE_LSB_MULTIPLIER) / 1000;
162 pr_debug("mic bias = %dmV\n", mic_bias);
163 return mic_bias;
164}
Vinod Koul36633232011-02-09 21:44:34 +0530165/*end - adc helper functions */
Vinod Koul4dc69be2011-01-04 20:16:07 +0530166
Mark Brown83cbe352013-09-25 19:22:54 +0100167static int sn95031_read(void *ctx, unsigned int reg, unsigned int *val)
Vinod Koul4dc69be2011-01-04 20:16:07 +0530168{
169 u8 value = 0;
170 int ret;
171
172 ret = intel_scu_ipc_ioread8(reg, &value);
Mark Brown83cbe352013-09-25 19:22:54 +0100173 if (ret == 0)
174 *val = value;
Vinod Koul4dc69be2011-01-04 20:16:07 +0530175
Vinod Koul4dc69be2011-01-04 20:16:07 +0530176 return ret;
177}
178
Mark Brown83cbe352013-09-25 19:22:54 +0100179static int sn95031_write(void *ctx, unsigned int reg, unsigned int value)
180{
181 return intel_scu_ipc_iowrite8(reg, value);
182}
183
184static const struct regmap_config sn95031_regmap = {
185 .reg_read = sn95031_read,
186 .reg_write = sn95031_write,
187};
188
Vinod Koul4dc69be2011-01-04 20:16:07 +0530189static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
190 enum snd_soc_bias_level level)
191{
192 switch (level) {
193 case SND_SOC_BIAS_ON:
194 break;
195
196 case SND_SOC_BIAS_PREPARE:
197 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
198 pr_debug("vaud_bias powering up pll\n");
199 /* power up the pll */
200 snd_soc_write(codec, SN95031_AUDPLLCTRL, BIT(5));
201 /* enable pcm 2 */
202 snd_soc_update_bits(codec, SN95031_PCM2C2,
203 BIT(0), BIT(0));
204 }
205 break;
206
207 case SND_SOC_BIAS_STANDBY:
208 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
209 pr_debug("vaud_bias power up rail\n");
210 /* power up the rail */
211 snd_soc_write(codec, SN95031_VAUD,
212 BIT(2)|BIT(1)|BIT(0));
213 msleep(1);
214 } else if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) {
215 /* turn off pcm */
216 pr_debug("vaud_bias power dn pcm\n");
217 snd_soc_update_bits(codec, SN95031_PCM2C2, BIT(0), 0);
218 snd_soc_write(codec, SN95031_AUDPLLCTRL, 0);
219 }
220 break;
221
222
223 case SND_SOC_BIAS_OFF:
224 pr_debug("vaud_bias _OFF doing rail shutdown\n");
225 snd_soc_write(codec, SN95031_VAUD, BIT(3));
226 break;
227 }
228
Vinod Koul4dc69be2011-01-04 20:16:07 +0530229 return 0;
230}
231
232static int sn95031_vhs_event(struct snd_soc_dapm_widget *w,
233 struct snd_kcontrol *kcontrol, int event)
234{
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100235 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
236
Vinod Koul4dc69be2011-01-04 20:16:07 +0530237 if (SND_SOC_DAPM_EVENT_ON(event)) {
238 pr_debug("VHS SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
239 /* power up the rail */
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100240 snd_soc_write(codec, SN95031_VHSP, 0x3D);
241 snd_soc_write(codec, SN95031_VHSN, 0x3F);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530242 msleep(1);
243 } else if (SND_SOC_DAPM_EVENT_OFF(event)) {
244 pr_debug("VHS SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100245 snd_soc_write(codec, SN95031_VHSP, 0xC4);
246 snd_soc_write(codec, SN95031_VHSN, 0x04);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530247 }
248 return 0;
249}
250
251static int sn95031_vihf_event(struct snd_soc_dapm_widget *w,
252 struct snd_kcontrol *kcontrol, int event)
253{
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100254 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
255
Vinod Koul4dc69be2011-01-04 20:16:07 +0530256 if (SND_SOC_DAPM_EVENT_ON(event)) {
257 pr_debug("VIHF SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
258 /* power up the rail */
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100259 snd_soc_write(codec, SN95031_VIHF, 0x27);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530260 msleep(1);
261 } else if (SND_SOC_DAPM_EVENT_OFF(event)) {
262 pr_debug("VIHF SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100263 snd_soc_write(codec, SN95031_VIHF, 0x24);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530264 }
265 return 0;
266}
267
Harsha Priyafd94eee2011-01-28 22:26:53 +0530268static int sn95031_dmic12_event(struct snd_soc_dapm_widget *w,
269 struct snd_kcontrol *k, int event)
270{
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100271 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530272 unsigned int ldo = 0, clk_dir = 0, data_dir = 0;
273
274 if (SND_SOC_DAPM_EVENT_ON(event)) {
275 ldo = BIT(5)|BIT(4);
276 clk_dir = BIT(0);
277 data_dir = BIT(7);
278 }
279 /* program DMIC LDO, clock and set clock */
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100280 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo);
281 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(0), clk_dir);
282 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(7), data_dir);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530283 return 0;
284}
285
286static int sn95031_dmic34_event(struct snd_soc_dapm_widget *w,
287 struct snd_kcontrol *k, int event)
288{
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100289 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530290 unsigned int ldo = 0, clk_dir = 0, data_dir = 0;
291
292 if (SND_SOC_DAPM_EVENT_ON(event)) {
293 ldo = BIT(5)|BIT(4);
294 clk_dir = BIT(2);
295 data_dir = BIT(1);
296 }
297 /* program DMIC LDO, clock and set clock */
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100298 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo);
299 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(2), clk_dir);
300 snd_soc_update_bits(codec, SN95031_DMICBUF45, BIT(1), data_dir);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530301 return 0;
302}
303
304static int sn95031_dmic56_event(struct snd_soc_dapm_widget *w,
305 struct snd_kcontrol *k, int event)
306{
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100307 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530308 unsigned int ldo = 0;
309
310 if (SND_SOC_DAPM_EVENT_ON(event))
311 ldo = BIT(7)|BIT(6);
312
313 /* program DMIC LDO */
Lars-Peter Clausen278a2022015-01-10 15:44:08 +0100314 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(7)|BIT(6), ldo);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530315 return 0;
316}
317
318/* mux controls */
319static const char *sn95031_mic_texts[] = { "AMIC", "LineIn" };
320
Takashi Iwaif3c11962014-02-18 10:17:24 +0100321static SOC_ENUM_SINGLE_DECL(sn95031_micl_enum,
322 SN95031_ADCCONFIG, 1, sn95031_mic_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530323
324static const struct snd_kcontrol_new sn95031_micl_mux_control =
325 SOC_DAPM_ENUM("Route", sn95031_micl_enum);
326
Takashi Iwaif3c11962014-02-18 10:17:24 +0100327static SOC_ENUM_SINGLE_DECL(sn95031_micr_enum,
328 SN95031_ADCCONFIG, 3, sn95031_mic_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530329
330static const struct snd_kcontrol_new sn95031_micr_mux_control =
331 SOC_DAPM_ENUM("Route", sn95031_micr_enum);
332
333static const char *sn95031_input_texts[] = { "DMIC1", "DMIC2", "DMIC3",
334 "DMIC4", "DMIC5", "DMIC6",
335 "ADC Left", "ADC Right" };
336
Takashi Iwaif3c11962014-02-18 10:17:24 +0100337static SOC_ENUM_SINGLE_DECL(sn95031_input1_enum,
338 SN95031_AUDIOMUX12, 0, sn95031_input_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530339
340static const struct snd_kcontrol_new sn95031_input1_mux_control =
341 SOC_DAPM_ENUM("Route", sn95031_input1_enum);
342
Takashi Iwaif3c11962014-02-18 10:17:24 +0100343static SOC_ENUM_SINGLE_DECL(sn95031_input2_enum,
344 SN95031_AUDIOMUX12, 4, sn95031_input_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530345
346static const struct snd_kcontrol_new sn95031_input2_mux_control =
347 SOC_DAPM_ENUM("Route", sn95031_input2_enum);
348
Takashi Iwaif3c11962014-02-18 10:17:24 +0100349static SOC_ENUM_SINGLE_DECL(sn95031_input3_enum,
350 SN95031_AUDIOMUX34, 0, sn95031_input_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530351
352static const struct snd_kcontrol_new sn95031_input3_mux_control =
353 SOC_DAPM_ENUM("Route", sn95031_input3_enum);
354
Takashi Iwaif3c11962014-02-18 10:17:24 +0100355static SOC_ENUM_SINGLE_DECL(sn95031_input4_enum,
356 SN95031_AUDIOMUX34, 4, sn95031_input_texts);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530357
358static const struct snd_kcontrol_new sn95031_input4_mux_control =
359 SOC_DAPM_ENUM("Route", sn95031_input4_enum);
360
361/* capture path controls */
362
363static const char *sn95031_micmode_text[] = {"Single Ended", "Differential"};
364
365/* 0dB to 30dB in 10dB steps */
Vinod Koul65e96252011-02-15 18:28:53 +0530366static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 10, 0);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530367
Takashi Iwaif3c11962014-02-18 10:17:24 +0100368static SOC_ENUM_SINGLE_DECL(sn95031_micmode1_enum,
369 SN95031_MICAMP1, 1, sn95031_micmode_text);
370static SOC_ENUM_SINGLE_DECL(sn95031_micmode2_enum,
371 SN95031_MICAMP2, 1, sn95031_micmode_text);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530372
373static const char *sn95031_dmic_cfg_text[] = {"GPO", "DMIC"};
374
Takashi Iwaif3c11962014-02-18 10:17:24 +0100375static SOC_ENUM_SINGLE_DECL(sn95031_dmic12_cfg_enum,
376 SN95031_DMICMUX, 0, sn95031_dmic_cfg_text);
377static SOC_ENUM_SINGLE_DECL(sn95031_dmic34_cfg_enum,
378 SN95031_DMICMUX, 1, sn95031_dmic_cfg_text);
379static SOC_ENUM_SINGLE_DECL(sn95031_dmic56_cfg_enum,
380 SN95031_DMICMUX, 2, sn95031_dmic_cfg_text);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530381
382static const struct snd_kcontrol_new sn95031_snd_controls[] = {
383 SOC_ENUM("Mic1Mode Capture Route", sn95031_micmode1_enum),
384 SOC_ENUM("Mic2Mode Capture Route", sn95031_micmode2_enum),
385 SOC_ENUM("DMIC12 Capture Route", sn95031_dmic12_cfg_enum),
386 SOC_ENUM("DMIC34 Capture Route", sn95031_dmic34_cfg_enum),
387 SOC_ENUM("DMIC56 Capture Route", sn95031_dmic56_cfg_enum),
388 SOC_SINGLE_TLV("Mic1 Capture Volume", SN95031_MICAMP1,
389 2, 4, 0, mic_tlv),
390 SOC_SINGLE_TLV("Mic2 Capture Volume", SN95031_MICAMP2,
391 2, 4, 0, mic_tlv),
392};
393
Vinod Koul4dc69be2011-01-04 20:16:07 +0530394/* DAPM widgets */
395static const struct snd_soc_dapm_widget sn95031_dapm_widgets[] = {
396
397 /* all end points mic, hs etc */
398 SND_SOC_DAPM_OUTPUT("HPOUTL"),
399 SND_SOC_DAPM_OUTPUT("HPOUTR"),
400 SND_SOC_DAPM_OUTPUT("EPOUT"),
401 SND_SOC_DAPM_OUTPUT("IHFOUTL"),
402 SND_SOC_DAPM_OUTPUT("IHFOUTR"),
403 SND_SOC_DAPM_OUTPUT("LINEOUTL"),
404 SND_SOC_DAPM_OUTPUT("LINEOUTR"),
405 SND_SOC_DAPM_OUTPUT("VIB1OUT"),
406 SND_SOC_DAPM_OUTPUT("VIB2OUT"),
407
Harsha Priyafd94eee2011-01-28 22:26:53 +0530408 SND_SOC_DAPM_INPUT("AMIC1"), /* headset mic */
409 SND_SOC_DAPM_INPUT("AMIC2"),
410 SND_SOC_DAPM_INPUT("DMIC1"),
411 SND_SOC_DAPM_INPUT("DMIC2"),
412 SND_SOC_DAPM_INPUT("DMIC3"),
413 SND_SOC_DAPM_INPUT("DMIC4"),
414 SND_SOC_DAPM_INPUT("DMIC5"),
415 SND_SOC_DAPM_INPUT("DMIC6"),
416 SND_SOC_DAPM_INPUT("LINEINL"),
417 SND_SOC_DAPM_INPUT("LINEINR"),
418
419 SND_SOC_DAPM_MICBIAS("AMIC1Bias", SN95031_MICBIAS, 2, 0),
420 SND_SOC_DAPM_MICBIAS("AMIC2Bias", SN95031_MICBIAS, 3, 0),
421 SND_SOC_DAPM_MICBIAS("DMIC12Bias", SN95031_DMICMUX, 3, 0),
422 SND_SOC_DAPM_MICBIAS("DMIC34Bias", SN95031_DMICMUX, 4, 0),
423 SND_SOC_DAPM_MICBIAS("DMIC56Bias", SN95031_DMICMUX, 5, 0),
424
425 SND_SOC_DAPM_SUPPLY("DMIC12supply", SN95031_DMICLK, 0, 0,
426 sn95031_dmic12_event,
427 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
428 SND_SOC_DAPM_SUPPLY("DMIC34supply", SN95031_DMICLK, 1, 0,
429 sn95031_dmic34_event,
430 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
431 SND_SOC_DAPM_SUPPLY("DMIC56supply", SN95031_DMICLK, 2, 0,
432 sn95031_dmic56_event,
433 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
434
435 SND_SOC_DAPM_AIF_OUT("PCM_Out", "Capture", 0,
436 SND_SOC_NOPM, 0, 0),
437
Vinod Koul4dc69be2011-01-04 20:16:07 +0530438 SND_SOC_DAPM_SUPPLY("Headset Rail", SND_SOC_NOPM, 0, 0,
439 sn95031_vhs_event,
440 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
441 SND_SOC_DAPM_SUPPLY("Speaker Rail", SND_SOC_NOPM, 0, 0,
442 sn95031_vihf_event,
443 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
444
445 /* playback path driver enables */
446 SND_SOC_DAPM_PGA("Headset Left Playback",
447 SN95031_DRIVEREN, 0, 0, NULL, 0),
448 SND_SOC_DAPM_PGA("Headset Right Playback",
449 SN95031_DRIVEREN, 1, 0, NULL, 0),
450 SND_SOC_DAPM_PGA("Speaker Left Playback",
451 SN95031_DRIVEREN, 2, 0, NULL, 0),
452 SND_SOC_DAPM_PGA("Speaker Right Playback",
453 SN95031_DRIVEREN, 3, 0, NULL, 0),
454 SND_SOC_DAPM_PGA("Vibra1 Playback",
455 SN95031_DRIVEREN, 4, 0, NULL, 0),
456 SND_SOC_DAPM_PGA("Vibra2 Playback",
457 SN95031_DRIVEREN, 5, 0, NULL, 0),
458 SND_SOC_DAPM_PGA("Earpiece Playback",
459 SN95031_DRIVEREN, 6, 0, NULL, 0),
460 SND_SOC_DAPM_PGA("Lineout Left Playback",
461 SN95031_LOCTL, 0, 0, NULL, 0),
462 SND_SOC_DAPM_PGA("Lineout Right Playback",
463 SN95031_LOCTL, 4, 0, NULL, 0),
464
465 /* playback path filter enable */
466 SND_SOC_DAPM_PGA("Headset Left Filter",
467 SN95031_HSEPRXCTRL, 4, 0, NULL, 0),
468 SND_SOC_DAPM_PGA("Headset Right Filter",
469 SN95031_HSEPRXCTRL, 5, 0, NULL, 0),
470 SND_SOC_DAPM_PGA("Speaker Left Filter",
471 SN95031_IHFRXCTRL, 0, 0, NULL, 0),
472 SND_SOC_DAPM_PGA("Speaker Right Filter",
473 SN95031_IHFRXCTRL, 1, 0, NULL, 0),
474
475 /* DACs */
476 SND_SOC_DAPM_DAC("HSDAC Left", "Headset",
477 SN95031_DACCONFIG, 0, 0),
478 SND_SOC_DAPM_DAC("HSDAC Right", "Headset",
479 SN95031_DACCONFIG, 1, 0),
480 SND_SOC_DAPM_DAC("IHFDAC Left", "Speaker",
481 SN95031_DACCONFIG, 2, 0),
482 SND_SOC_DAPM_DAC("IHFDAC Right", "Speaker",
483 SN95031_DACCONFIG, 3, 0),
484 SND_SOC_DAPM_DAC("Vibra1 DAC", "Vibra1",
485 SN95031_VIB1C5, 1, 0),
486 SND_SOC_DAPM_DAC("Vibra2 DAC", "Vibra2",
487 SN95031_VIB2C5, 1, 0),
Harsha Priyafd94eee2011-01-28 22:26:53 +0530488
489 /* capture widgets */
490 SND_SOC_DAPM_PGA("LineIn Enable Left", SN95031_MICAMP1,
491 7, 0, NULL, 0),
492 SND_SOC_DAPM_PGA("LineIn Enable Right", SN95031_MICAMP2,
493 7, 0, NULL, 0),
494
495 SND_SOC_DAPM_PGA("MIC1 Enable", SN95031_MICAMP1, 0, 0, NULL, 0),
496 SND_SOC_DAPM_PGA("MIC2 Enable", SN95031_MICAMP2, 0, 0, NULL, 0),
497 SND_SOC_DAPM_PGA("TX1 Enable", SN95031_AUDIOTXEN, 2, 0, NULL, 0),
498 SND_SOC_DAPM_PGA("TX2 Enable", SN95031_AUDIOTXEN, 3, 0, NULL, 0),
499 SND_SOC_DAPM_PGA("TX3 Enable", SN95031_AUDIOTXEN, 4, 0, NULL, 0),
500 SND_SOC_DAPM_PGA("TX4 Enable", SN95031_AUDIOTXEN, 5, 0, NULL, 0),
501
502 /* ADC have null stream as they will be turned ON by TX path */
503 SND_SOC_DAPM_ADC("ADC Left", NULL,
504 SN95031_ADCCONFIG, 0, 0),
505 SND_SOC_DAPM_ADC("ADC Right", NULL,
506 SN95031_ADCCONFIG, 2, 0),
507
508 SND_SOC_DAPM_MUX("Mic_InputL Capture Route",
509 SND_SOC_NOPM, 0, 0, &sn95031_micl_mux_control),
510 SND_SOC_DAPM_MUX("Mic_InputR Capture Route",
511 SND_SOC_NOPM, 0, 0, &sn95031_micr_mux_control),
512
513 SND_SOC_DAPM_MUX("Txpath1 Capture Route",
514 SND_SOC_NOPM, 0, 0, &sn95031_input1_mux_control),
515 SND_SOC_DAPM_MUX("Txpath2 Capture Route",
516 SND_SOC_NOPM, 0, 0, &sn95031_input2_mux_control),
517 SND_SOC_DAPM_MUX("Txpath3 Capture Route",
518 SND_SOC_NOPM, 0, 0, &sn95031_input3_mux_control),
519 SND_SOC_DAPM_MUX("Txpath4 Capture Route",
520 SND_SOC_NOPM, 0, 0, &sn95031_input4_mux_control),
521
Vinod Koul4dc69be2011-01-04 20:16:07 +0530522};
523
524static const struct snd_soc_dapm_route sn95031_audio_map[] = {
525 /* headset and earpiece map */
Vinod Koul1461d062011-02-15 18:28:51 +0530526 { "HPOUTL", NULL, "Headset Rail"},
527 { "HPOUTR", NULL, "Headset Rail"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530528 { "HPOUTL", NULL, "Headset Left Playback" },
529 { "HPOUTR", NULL, "Headset Right Playback" },
530 { "EPOUT", NULL, "Earpiece Playback" },
531 { "Headset Left Playback", NULL, "Headset Left Filter"},
532 { "Headset Right Playback", NULL, "Headset Right Filter"},
533 { "Earpiece Playback", NULL, "Headset Left Filter"},
534 { "Headset Left Filter", NULL, "HSDAC Left"},
535 { "Headset Right Filter", NULL, "HSDAC Right"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530536
537 /* speaker map */
Vinod Koul1461d062011-02-15 18:28:51 +0530538 { "IHFOUTL", NULL, "Speaker Rail"},
539 { "IHFOUTR", NULL, "Speaker Rail"},
Lars-Peter Clausencdd3d2a2015-02-27 14:13:04 +0100540 { "IHFOUTL", NULL, "Speaker Left Playback"},
541 { "IHFOUTR", NULL, "Speaker Right Playback"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530542 { "Speaker Left Playback", NULL, "Speaker Left Filter"},
543 { "Speaker Right Playback", NULL, "Speaker Right Filter"},
544 { "Speaker Left Filter", NULL, "IHFDAC Left"},
545 { "Speaker Right Filter", NULL, "IHFDAC Right"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530546
547 /* vibra map */
Vinod Koulb22dab82011-01-07 16:20:28 +0530548 { "VIB1OUT", NULL, "Vibra1 Playback"},
549 { "Vibra1 Playback", NULL, "Vibra1 DAC"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530550
Vinod Koulb22dab82011-01-07 16:20:28 +0530551 { "VIB2OUT", NULL, "Vibra2 Playback"},
552 { "Vibra2 Playback", NULL, "Vibra2 DAC"},
Vinod Koul4dc69be2011-01-04 20:16:07 +0530553
554 /* lineout */
Vinod Koulb22dab82011-01-07 16:20:28 +0530555 { "LINEOUTL", NULL, "Lineout Left Playback"},
556 { "LINEOUTR", NULL, "Lineout Right Playback"},
557 { "Lineout Left Playback", NULL, "Headset Left Filter"},
558 { "Lineout Left Playback", NULL, "Speaker Left Filter"},
559 { "Lineout Left Playback", NULL, "Vibra1 DAC"},
560 { "Lineout Right Playback", NULL, "Headset Right Filter"},
561 { "Lineout Right Playback", NULL, "Speaker Right Filter"},
562 { "Lineout Right Playback", NULL, "Vibra2 DAC"},
Harsha Priyafd94eee2011-01-28 22:26:53 +0530563
564 /* Headset (AMIC1) mic */
565 { "AMIC1Bias", NULL, "AMIC1"},
566 { "MIC1 Enable", NULL, "AMIC1Bias"},
567 { "Mic_InputL Capture Route", "AMIC", "MIC1 Enable"},
568
569 /* AMIC2 */
570 { "AMIC2Bias", NULL, "AMIC2"},
571 { "MIC2 Enable", NULL, "AMIC2Bias"},
572 { "Mic_InputR Capture Route", "AMIC", "MIC2 Enable"},
573
574
575 /* Linein */
576 { "LineIn Enable Left", NULL, "LINEINL"},
577 { "LineIn Enable Right", NULL, "LINEINR"},
578 { "Mic_InputL Capture Route", "LineIn", "LineIn Enable Left"},
579 { "Mic_InputR Capture Route", "LineIn", "LineIn Enable Right"},
580
581 /* ADC connection */
582 { "ADC Left", NULL, "Mic_InputL Capture Route"},
583 { "ADC Right", NULL, "Mic_InputR Capture Route"},
584
585 /*DMIC connections */
586 { "DMIC1", NULL, "DMIC12supply"},
587 { "DMIC2", NULL, "DMIC12supply"},
588 { "DMIC3", NULL, "DMIC34supply"},
589 { "DMIC4", NULL, "DMIC34supply"},
590 { "DMIC5", NULL, "DMIC56supply"},
591 { "DMIC6", NULL, "DMIC56supply"},
592
593 { "DMIC12Bias", NULL, "DMIC1"},
594 { "DMIC12Bias", NULL, "DMIC2"},
595 { "DMIC34Bias", NULL, "DMIC3"},
596 { "DMIC34Bias", NULL, "DMIC4"},
597 { "DMIC56Bias", NULL, "DMIC5"},
598 { "DMIC56Bias", NULL, "DMIC6"},
599
600 /*TX path inputs*/
601 { "Txpath1 Capture Route", "ADC Left", "ADC Left"},
602 { "Txpath2 Capture Route", "ADC Left", "ADC Left"},
603 { "Txpath3 Capture Route", "ADC Left", "ADC Left"},
604 { "Txpath4 Capture Route", "ADC Left", "ADC Left"},
605 { "Txpath1 Capture Route", "ADC Right", "ADC Right"},
606 { "Txpath2 Capture Route", "ADC Right", "ADC Right"},
607 { "Txpath3 Capture Route", "ADC Right", "ADC Right"},
608 { "Txpath4 Capture Route", "ADC Right", "ADC Right"},
Vinod Koula62ffc92011-02-15 18:28:52 +0530609 { "Txpath1 Capture Route", "DMIC1", "DMIC1"},
610 { "Txpath2 Capture Route", "DMIC1", "DMIC1"},
611 { "Txpath3 Capture Route", "DMIC1", "DMIC1"},
612 { "Txpath4 Capture Route", "DMIC1", "DMIC1"},
613 { "Txpath1 Capture Route", "DMIC2", "DMIC2"},
614 { "Txpath2 Capture Route", "DMIC2", "DMIC2"},
615 { "Txpath3 Capture Route", "DMIC2", "DMIC2"},
616 { "Txpath4 Capture Route", "DMIC2", "DMIC2"},
617 { "Txpath1 Capture Route", "DMIC3", "DMIC3"},
618 { "Txpath2 Capture Route", "DMIC3", "DMIC3"},
619 { "Txpath3 Capture Route", "DMIC3", "DMIC3"},
620 { "Txpath4 Capture Route", "DMIC3", "DMIC3"},
621 { "Txpath1 Capture Route", "DMIC4", "DMIC4"},
622 { "Txpath2 Capture Route", "DMIC4", "DMIC4"},
623 { "Txpath3 Capture Route", "DMIC4", "DMIC4"},
624 { "Txpath4 Capture Route", "DMIC4", "DMIC4"},
625 { "Txpath1 Capture Route", "DMIC5", "DMIC5"},
626 { "Txpath2 Capture Route", "DMIC5", "DMIC5"},
627 { "Txpath3 Capture Route", "DMIC5", "DMIC5"},
628 { "Txpath4 Capture Route", "DMIC5", "DMIC5"},
629 { "Txpath1 Capture Route", "DMIC6", "DMIC6"},
630 { "Txpath2 Capture Route", "DMIC6", "DMIC6"},
631 { "Txpath3 Capture Route", "DMIC6", "DMIC6"},
632 { "Txpath4 Capture Route", "DMIC6", "DMIC6"},
Harsha Priyafd94eee2011-01-28 22:26:53 +0530633
634 /* tx path */
635 { "TX1 Enable", NULL, "Txpath1 Capture Route"},
636 { "TX2 Enable", NULL, "Txpath2 Capture Route"},
637 { "TX3 Enable", NULL, "Txpath3 Capture Route"},
638 { "TX4 Enable", NULL, "Txpath4 Capture Route"},
639 { "PCM_Out", NULL, "TX1 Enable"},
640 { "PCM_Out", NULL, "TX2 Enable"},
641 { "PCM_Out", NULL, "TX3 Enable"},
642 { "PCM_Out", NULL, "TX4 Enable"},
643
Vinod Koul4dc69be2011-01-04 20:16:07 +0530644};
645
646/* speaker and headset mutes, for audio pops and clicks */
647static int sn95031_pcm_hs_mute(struct snd_soc_dai *dai, int mute)
648{
649 snd_soc_update_bits(dai->codec,
650 SN95031_HSLVOLCTRL, BIT(7), (!mute << 7));
651 snd_soc_update_bits(dai->codec,
652 SN95031_HSRVOLCTRL, BIT(7), (!mute << 7));
653 return 0;
654}
655
656static int sn95031_pcm_spkr_mute(struct snd_soc_dai *dai, int mute)
657{
658 snd_soc_update_bits(dai->codec,
659 SN95031_IHFLVOLCTRL, BIT(7), (!mute << 7));
660 snd_soc_update_bits(dai->codec,
661 SN95031_IHFRVOLCTRL, BIT(7), (!mute << 7));
662 return 0;
663}
664
Axel Lin5d429402011-09-19 16:34:28 +0800665static int sn95031_pcm_hw_params(struct snd_pcm_substream *substream,
Vinod Koul4dc69be2011-01-04 20:16:07 +0530666 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
667{
668 unsigned int format, rate;
669
Mark Brown9519dd42014-07-31 12:46:50 +0100670 switch (params_width(params)) {
671 case 16:
Vinod Koul4dc69be2011-01-04 20:16:07 +0530672 format = BIT(4)|BIT(5);
673 break;
674
Mark Brown9519dd42014-07-31 12:46:50 +0100675 case 24:
Vinod Koul4dc69be2011-01-04 20:16:07 +0530676 format = 0;
677 break;
678 default:
679 return -EINVAL;
680 }
681 snd_soc_update_bits(dai->codec, SN95031_PCM2C2,
682 BIT(4)|BIT(5), format);
683
684 switch (params_rate(params)) {
685 case 48000:
686 pr_debug("RATE_48000\n");
687 rate = 0;
688 break;
689
690 case 44100:
691 pr_debug("RATE_44100\n");
692 rate = BIT(7);
693 break;
694
695 default:
696 pr_err("ERR rate %d\n", params_rate(params));
697 return -EINVAL;
698 }
699 snd_soc_update_bits(dai->codec, SN95031_PCM1C1, BIT(7), rate);
700
701 return 0;
702}
703
704/* Codec DAI section */
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100705static const struct snd_soc_dai_ops sn95031_headset_dai_ops = {
Vinod Koul4dc69be2011-01-04 20:16:07 +0530706 .digital_mute = sn95031_pcm_hs_mute,
707 .hw_params = sn95031_pcm_hw_params,
708};
709
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100710static const struct snd_soc_dai_ops sn95031_speaker_dai_ops = {
Vinod Koul4dc69be2011-01-04 20:16:07 +0530711 .digital_mute = sn95031_pcm_spkr_mute,
712 .hw_params = sn95031_pcm_hw_params,
713};
714
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100715static const struct snd_soc_dai_ops sn95031_vib1_dai_ops = {
Vinod Koul4dc69be2011-01-04 20:16:07 +0530716 .hw_params = sn95031_pcm_hw_params,
717};
718
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100719static const struct snd_soc_dai_ops sn95031_vib2_dai_ops = {
Vinod Koul4dc69be2011-01-04 20:16:07 +0530720 .hw_params = sn95031_pcm_hw_params,
721};
722
Axel Lina4360892011-09-23 16:24:19 +0800723static struct snd_soc_dai_driver sn95031_dais[] = {
Vinod Koul4dc69be2011-01-04 20:16:07 +0530724{
725 .name = "SN95031 Headset",
726 .playback = {
727 .stream_name = "Headset",
728 .channels_min = 2,
729 .channels_max = 2,
730 .rates = SN95031_RATES,
731 .formats = SN95031_FORMATS,
732 },
Harsha Priyafd94eee2011-01-28 22:26:53 +0530733 .capture = {
734 .stream_name = "Capture",
735 .channels_min = 1,
736 .channels_max = 5,
737 .rates = SN95031_RATES,
738 .formats = SN95031_FORMATS,
739 },
Vinod Koul4dc69be2011-01-04 20:16:07 +0530740 .ops = &sn95031_headset_dai_ops,
741},
742{ .name = "SN95031 Speaker",
743 .playback = {
744 .stream_name = "Speaker",
745 .channels_min = 2,
746 .channels_max = 2,
747 .rates = SN95031_RATES,
748 .formats = SN95031_FORMATS,
749 },
750 .ops = &sn95031_speaker_dai_ops,
751},
752{ .name = "SN95031 Vibra1",
753 .playback = {
754 .stream_name = "Vibra1",
755 .channels_min = 1,
756 .channels_max = 1,
757 .rates = SN95031_RATES,
758 .formats = SN95031_FORMATS,
759 },
760 .ops = &sn95031_vib1_dai_ops,
761},
762{ .name = "SN95031 Vibra2",
763 .playback = {
764 .stream_name = "Vibra2",
765 .channels_min = 1,
766 .channels_max = 1,
767 .rates = SN95031_RATES,
768 .formats = SN95031_FORMATS,
769 },
770 .ops = &sn95031_vib2_dai_ops,
771},
772};
773
Vinod Koul1e2f5932011-02-09 21:44:32 +0530774static inline void sn95031_disable_jack_btn(struct snd_soc_codec *codec)
775{
776 snd_soc_write(codec, SN95031_BTNCTRL2, 0x00);
777}
778
779static inline void sn95031_enable_jack_btn(struct snd_soc_codec *codec)
780{
781 snd_soc_write(codec, SN95031_BTNCTRL1, 0x77);
782 snd_soc_write(codec, SN95031_BTNCTRL2, 0x01);
783}
784
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100785static int sn95031_get_headset_state(struct snd_soc_codec *codec,
786 struct snd_soc_jack *mfld_jack)
Vinod Koul1e2f5932011-02-09 21:44:32 +0530787{
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100788 int micbias = sn95031_get_mic_bias(codec);
Vinod Koul36633232011-02-09 21:44:34 +0530789
Vinod Koul7ae74342011-02-10 12:58:01 +0530790 int jack_type = snd_soc_jack_get_type(mfld_jack, micbias);
Vinod Koul1e2f5932011-02-09 21:44:32 +0530791
792 pr_debug("jack type detected = %d\n", jack_type);
793 if (jack_type == SND_JACK_HEADSET)
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100794 sn95031_enable_jack_btn(codec);
Vinod Koul1e2f5932011-02-09 21:44:32 +0530795 return jack_type;
796}
797
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100798void sn95031_jack_detection(struct snd_soc_codec *codec,
799 struct mfld_jack_data *jack_data)
Vinod Koul1e2f5932011-02-09 21:44:32 +0530800{
801 unsigned int status;
802 unsigned int mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_HEADSET;
803
804 pr_debug("interrupt id read in sram = 0x%x\n", jack_data->intr_id);
805 if (jack_data->intr_id & 0x1) {
806 pr_debug("short_push detected\n");
807 status = SND_JACK_HEADSET | SND_JACK_BTN_0;
808 } else if (jack_data->intr_id & 0x2) {
809 pr_debug("long_push detected\n");
810 status = SND_JACK_HEADSET | SND_JACK_BTN_1;
811 } else if (jack_data->intr_id & 0x4) {
812 pr_debug("headset or headphones inserted\n");
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100813 status = sn95031_get_headset_state(codec, jack_data->mfld_jack);
Vinod Koul1e2f5932011-02-09 21:44:32 +0530814 } else if (jack_data->intr_id & 0x8) {
815 pr_debug("headset or headphones removed\n");
816 status = 0;
Lars-Peter Clausenc472b932015-03-04 10:33:16 +0100817 sn95031_disable_jack_btn(codec);
Vinod Koul1e2f5932011-02-09 21:44:32 +0530818 } else {
819 pr_err("unidentified interrupt\n");
820 return;
821 }
822
823 snd_soc_jack_report(jack_data->mfld_jack, status, mask);
824 /*button pressed and released so we send explicit button release */
825 if ((status & SND_JACK_BTN_0) | (status & SND_JACK_BTN_1))
826 snd_soc_jack_report(jack_data->mfld_jack,
827 SND_JACK_HEADSET, mask);
828}
829EXPORT_SYMBOL_GPL(sn95031_jack_detection);
830
Vinod Koul4dc69be2011-01-04 20:16:07 +0530831/* codec registration */
832static int sn95031_codec_probe(struct snd_soc_codec *codec)
833{
Vinod Koul4dc69be2011-01-04 20:16:07 +0530834 pr_debug("codec_probe called\n");
835
Vinod Koul4dc69be2011-01-04 20:16:07 +0530836 /* PCM interface config
837 * This sets the pcm rx slot conguration to max 6 slots
838 * for max 4 dais (2 stereo and 2 mono)
839 */
840 snd_soc_write(codec, SN95031_PCM2RXSLOT01, 0x10);
841 snd_soc_write(codec, SN95031_PCM2RXSLOT23, 0x32);
842 snd_soc_write(codec, SN95031_PCM2RXSLOT45, 0x54);
Harsha Priyafd94eee2011-01-28 22:26:53 +0530843 snd_soc_write(codec, SN95031_PCM2TXSLOT01, 0x10);
844 snd_soc_write(codec, SN95031_PCM2TXSLOT23, 0x32);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530845 /* pcm port setting
846 * This sets the pcm port to slave and clock at 19.2Mhz which
847 * can support 6slots, sampling rate set per stream in hw-params
848 */
849 snd_soc_write(codec, SN95031_PCM1C1, 0x00);
850 snd_soc_write(codec, SN95031_PCM2C1, 0x01);
851 snd_soc_write(codec, SN95031_PCM2C2, 0x0A);
852 snd_soc_write(codec, SN95031_HSMIXER, BIT(0)|BIT(4));
853 /* vendor vibra workround, the vibras are muted by
854 * custom register so unmute them
855 */
856 snd_soc_write(codec, SN95031_SSR5, 0x80);
857 snd_soc_write(codec, SN95031_SSR6, 0x80);
858 snd_soc_write(codec, SN95031_VIB1C5, 0x00);
859 snd_soc_write(codec, SN95031_VIB2C5, 0x00);
860 /* configure vibras for pcm port */
861 snd_soc_write(codec, SN95031_VIB1C3, 0x00);
862 snd_soc_write(codec, SN95031_VIB2C3, 0x00);
863
864 /* soft mute ramp time */
865 snd_soc_write(codec, SN95031_SOFTMUTE, 0x3);
866 /* fix the initial volume at 1dB,
867 * default in +9dB,
868 * 1dB give optimal swing on DAC, amps
869 */
870 snd_soc_write(codec, SN95031_HSLVOLCTRL, 0x08);
871 snd_soc_write(codec, SN95031_HSRVOLCTRL, 0x08);
872 snd_soc_write(codec, SN95031_IHFLVOLCTRL, 0x08);
873 snd_soc_write(codec, SN95031_IHFRVOLCTRL, 0x08);
874 /* dac mode and lineout workaround */
875 snd_soc_write(codec, SN95031_SSR2, 0x10);
876 snd_soc_write(codec, SN95031_SSR3, 0x40);
877
Lu Guanqune27808d2011-03-30 21:53:17 +0800878 return 0;
Vinod Koul4dc69be2011-01-04 20:16:07 +0530879}
880
Lars-Peter Clausen3eb28d32013-05-14 22:19:56 +0200881static struct snd_soc_codec_driver sn95031_codec = {
Vinod Koulb22dab82011-01-07 16:20:28 +0530882 .probe = sn95031_codec_probe,
Vinod Koul4dc69be2011-01-04 20:16:07 +0530883 .set_bias_level = sn95031_set_vaud_bias,
Axel Lineb3032f2012-01-27 18:02:09 +0800884 .idle_bias_off = true,
Lars-Peter Clausen0c239fa2014-11-05 10:46:31 +0100885
886 .controls = sn95031_snd_controls,
887 .num_controls = ARRAY_SIZE(sn95031_snd_controls),
Lu Guanqune27808d2011-03-30 21:53:17 +0800888 .dapm_widgets = sn95031_dapm_widgets,
889 .num_dapm_widgets = ARRAY_SIZE(sn95031_dapm_widgets),
890 .dapm_routes = sn95031_audio_map,
891 .num_dapm_routes = ARRAY_SIZE(sn95031_audio_map),
Vinod Koul4dc69be2011-01-04 20:16:07 +0530892};
893
Bill Pemberton7a79e942012-12-07 09:26:37 -0500894static int sn95031_device_probe(struct platform_device *pdev)
Vinod Koul4dc69be2011-01-04 20:16:07 +0530895{
Mark Brown83cbe352013-09-25 19:22:54 +0100896 struct regmap *regmap;
897
Vinod Koul4dc69be2011-01-04 20:16:07 +0530898 pr_debug("codec device probe called for %s\n", dev_name(&pdev->dev));
Mark Brown83cbe352013-09-25 19:22:54 +0100899
900 regmap = devm_regmap_init(&pdev->dev, NULL, NULL, &sn95031_regmap);
901 if (IS_ERR(regmap))
902 return PTR_ERR(regmap);
903
Vinod Koul4dc69be2011-01-04 20:16:07 +0530904 return snd_soc_register_codec(&pdev->dev, &sn95031_codec,
905 sn95031_dais, ARRAY_SIZE(sn95031_dais));
906}
907
Bill Pemberton7a79e942012-12-07 09:26:37 -0500908static int sn95031_device_remove(struct platform_device *pdev)
Vinod Koul4dc69be2011-01-04 20:16:07 +0530909{
910 pr_debug("codec device remove called\n");
911 snd_soc_unregister_codec(&pdev->dev);
912 return 0;
913}
914
915static struct platform_driver sn95031_codec_driver = {
916 .driver = {
917 .name = "sn95031",
Vinod Koul4dc69be2011-01-04 20:16:07 +0530918 },
919 .probe = sn95031_device_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500920 .remove = sn95031_device_remove,
Vinod Koul4dc69be2011-01-04 20:16:07 +0530921};
922
Mark Brown5bbcc3c2011-11-23 22:52:08 +0000923module_platform_driver(sn95031_codec_driver);
Vinod Koul4dc69be2011-01-04 20:16:07 +0530924
Vinod Koulb22dab82011-01-07 16:20:28 +0530925MODULE_DESCRIPTION("ASoC TI SN95031 codec driver");
Vinod Koul4dc69be2011-01-04 20:16:07 +0530926MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
927MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
928MODULE_LICENSE("GPL v2");
929MODULE_ALIAS("platform:sn95031");