Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * es8328.c  --  ES8328 ALSA SoC Audio driver
  4 *
  5 * Copyright 2014 Sutajio Ko-Usagi PTE LTD
  6 *
  7 * Author: Sean Cross <xobs@kosagi.com>
 
 
 
 
  8 */
  9
 10#include <linux/clk.h>
 11#include <linux/delay.h>
 
 12#include <linux/module.h>
 13#include <linux/pm.h>
 14#include <linux/regmap.h>
 15#include <linux/slab.h>
 16#include <linux/regulator/consumer.h>
 17#include <sound/core.h>
 18#include <sound/initval.h>
 19#include <sound/pcm.h>
 20#include <sound/pcm_params.h>
 21#include <sound/soc.h>
 22#include <sound/tlv.h>
 23#include "es8328.h"
 24
 25static const unsigned int rates_12288[] = {
 26	8000, 12000, 16000, 24000, 32000, 48000, 96000,
 27};
 28
 29static const int ratios_12288[] = {
 30	10, 7, 6, 4, 3, 2, 0,
 31};
 32
 33static const struct snd_pcm_hw_constraint_list constraints_12288 = {
 34	.count	= ARRAY_SIZE(rates_12288),
 35	.list	= rates_12288,
 36};
 37
 38static const unsigned int rates_11289[] = {
 39	8018, 11025, 22050, 44100, 88200,
 40};
 41
 42static const int ratios_11289[] = {
 43	9, 7, 4, 2, 0,
 44};
 45
 46static const struct snd_pcm_hw_constraint_list constraints_11289 = {
 47	.count	= ARRAY_SIZE(rates_11289),
 48	.list	= rates_11289,
 49};
 50
 51/* regulator supplies for sgtl5000, VDDD is an optional external supply */
 52enum sgtl5000_regulator_supplies {
 53	DVDD,
 54	AVDD,
 55	PVDD,
 56	HPVDD,
 57	ES8328_SUPPLY_NUM
 58};
 59
 60/* vddd is optional supply */
 61static const char * const supply_names[ES8328_SUPPLY_NUM] = {
 62	"DVDD",
 63	"AVDD",
 64	"PVDD",
 65	"HPVDD",
 66};
 67
 68#define ES8328_RATES (SNDRV_PCM_RATE_192000 | \
 69		SNDRV_PCM_RATE_96000 | \
 70		SNDRV_PCM_RATE_88200 | \
 71		SNDRV_PCM_RATE_8000_48000)
 72#define ES8328_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
 73		SNDRV_PCM_FMTBIT_S18_3LE | \
 74		SNDRV_PCM_FMTBIT_S20_3LE | \
 75		SNDRV_PCM_FMTBIT_S24_LE | \
 76		SNDRV_PCM_FMTBIT_S32_LE)
 77
 78struct es8328_priv {
 79	struct regmap *regmap;
 80	struct clk *clk;
 81	int playback_fs;
 82	bool deemph;
 83	int mclkdiv2;
 84	const struct snd_pcm_hw_constraint_list *sysclk_constraints;
 85	const int *mclk_ratios;
 86	bool provider;
 87	struct regulator_bulk_data supplies[ES8328_SUPPLY_NUM];
 88};
 89
 90/*
 91 * ES8328 Controls
 92 */
 93
 94static const char * const adcpol_txt[] = {"Normal", "L Invert", "R Invert",
 95					  "L + R Invert"};
 96static SOC_ENUM_SINGLE_DECL(adcpol,
 97			    ES8328_ADCCONTROL6, 6, adcpol_txt);
 98
 99static const DECLARE_TLV_DB_SCALE(play_tlv, -3000, 100, 0);
100static const DECLARE_TLV_DB_SCALE(dac_adc_tlv, -9600, 50, 0);
 
101static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
102static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 300, 0);
103
104static const struct {
105	int rate;
106	unsigned int val;
107} deemph_settings[] = {
108	{ 0,     ES8328_DACCONTROL6_DEEMPH_OFF },
109	{ 32000, ES8328_DACCONTROL6_DEEMPH_32k },
110	{ 44100, ES8328_DACCONTROL6_DEEMPH_44_1k },
111	{ 48000, ES8328_DACCONTROL6_DEEMPH_48k },
112};
113
114static int es8328_set_deemph(struct snd_soc_component *component)
115{
116	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
117	int val, i, best;
118
119	/*
120	 * If we're using deemphasis select the nearest available sample
121	 * rate.
122	 */
123	if (es8328->deemph) {
124		best = 0;
125		for (i = 1; i < ARRAY_SIZE(deemph_settings); i++) {
126			if (abs(deemph_settings[i].rate - es8328->playback_fs) <
127			    abs(deemph_settings[best].rate - es8328->playback_fs))
128				best = i;
129		}
130
131		val = deemph_settings[best].val;
132	} else {
133		val = ES8328_DACCONTROL6_DEEMPH_OFF;
134	}
135
136	dev_dbg(component->dev, "Set deemphasis %d\n", val);
137
138	return snd_soc_component_update_bits(component, ES8328_DACCONTROL6,
139			ES8328_DACCONTROL6_DEEMPH_MASK, val);
140}
141
142static int es8328_get_deemph(struct snd_kcontrol *kcontrol,
143			     struct snd_ctl_elem_value *ucontrol)
144{
145	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
146	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
147
148	ucontrol->value.integer.value[0] = es8328->deemph;
149	return 0;
150}
151
152static int es8328_put_deemph(struct snd_kcontrol *kcontrol,
153			     struct snd_ctl_elem_value *ucontrol)
154{
155	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
156	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
157	unsigned int deemph = ucontrol->value.integer.value[0];
158	int ret;
159
160	if (deemph > 1)
161		return -EINVAL;
162
163	if (es8328->deemph == deemph)
164		return 0;
165
166	ret = es8328_set_deemph(component);
167	if (ret < 0)
168		return ret;
169
170	es8328->deemph = deemph;
171
172	return 1;
173}
174
175
176
177static const struct snd_kcontrol_new es8328_snd_controls[] = {
178	SOC_DOUBLE_R_TLV("Capture Digital Volume",
179		ES8328_ADCCONTROL8, ES8328_ADCCONTROL9,
180		 0, 0xc0, 1, dac_adc_tlv),
181	SOC_SINGLE("Capture ZC Switch", ES8328_ADCCONTROL7, 6, 1, 0),
182
183	SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
184		    es8328_get_deemph, es8328_put_deemph),
185
186	SOC_ENUM("Capture Polarity", adcpol),
187
188	SOC_SINGLE_TLV("Left Mixer Left Bypass Volume",
189			ES8328_DACCONTROL17, 3, 7, 1, bypass_tlv),
190	SOC_SINGLE_TLV("Left Mixer Right Bypass Volume",
191			ES8328_DACCONTROL19, 3, 7, 1, bypass_tlv),
192	SOC_SINGLE_TLV("Right Mixer Left Bypass Volume",
193			ES8328_DACCONTROL18, 3, 7, 1, bypass_tlv),
194	SOC_SINGLE_TLV("Right Mixer Right Bypass Volume",
195			ES8328_DACCONTROL20, 3, 7, 1, bypass_tlv),
196
197	SOC_DOUBLE_R_TLV("PCM Volume",
198			ES8328_LDACVOL, ES8328_RDACVOL,
199			0, ES8328_DACVOL_MAX, 1, dac_adc_tlv),
200
201	SOC_DOUBLE_R_TLV("Output 1 Playback Volume",
202			ES8328_LOUT1VOL, ES8328_ROUT1VOL,
203			0, ES8328_OUT1VOL_MAX, 0, play_tlv),
204
205	SOC_DOUBLE_R_TLV("Output 2 Playback Volume",
206			ES8328_LOUT2VOL, ES8328_ROUT2VOL,
207			0, ES8328_OUT2VOL_MAX, 0, play_tlv),
208
209	SOC_DOUBLE_TLV("Mic PGA Volume", ES8328_ADCCONTROL1,
210			4, 0, 8, 0, mic_tlv),
211};
212
213/*
214 * DAPM Controls
215 */
216
217static const char * const es8328_line_texts[] = {
218	"Line 1", "Line 2", "PGA", "Differential"};
219
220static const struct soc_enum es8328_lline_enum =
221	SOC_ENUM_SINGLE(ES8328_DACCONTROL16, 3,
222			      ARRAY_SIZE(es8328_line_texts),
223			      es8328_line_texts);
224static const struct snd_kcontrol_new es8328_left_line_controls =
225	SOC_DAPM_ENUM("Route", es8328_lline_enum);
226
227static const struct soc_enum es8328_rline_enum =
228	SOC_ENUM_SINGLE(ES8328_DACCONTROL16, 0,
229			      ARRAY_SIZE(es8328_line_texts),
230			      es8328_line_texts);
231static const struct snd_kcontrol_new es8328_right_line_controls =
232	SOC_DAPM_ENUM("Route", es8328_rline_enum);
233
234/* Left Mixer */
235static const struct snd_kcontrol_new es8328_left_mixer_controls[] = {
 
236	SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL17, 6, 1, 0),
237	SOC_DAPM_SINGLE("Right Playback Switch", ES8328_DACCONTROL18, 7, 1, 0),
238	SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL18, 6, 1, 0),
239};
240
241/* Right Mixer */
242static const struct snd_kcontrol_new es8328_right_mixer_controls[] = {
243	SOC_DAPM_SINGLE("Left Playback Switch", ES8328_DACCONTROL19, 7, 1, 0),
244	SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL19, 6, 1, 0),
 
245	SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL20, 6, 1, 0),
246};
247
248static const char * const es8328_pga_sel[] = {
249	"Line 1", "Line 2", "Line 3", "Differential"};
250
251/* Left PGA Mux */
252static const struct soc_enum es8328_lpga_enum =
253	SOC_ENUM_SINGLE(ES8328_ADCCONTROL2, 6,
254			      ARRAY_SIZE(es8328_pga_sel),
255			      es8328_pga_sel);
256static const struct snd_kcontrol_new es8328_left_pga_controls =
257	SOC_DAPM_ENUM("Route", es8328_lpga_enum);
258
259/* Right PGA Mux */
260static const struct soc_enum es8328_rpga_enum =
261	SOC_ENUM_SINGLE(ES8328_ADCCONTROL2, 4,
262			      ARRAY_SIZE(es8328_pga_sel),
263			      es8328_pga_sel);
264static const struct snd_kcontrol_new es8328_right_pga_controls =
265	SOC_DAPM_ENUM("Route", es8328_rpga_enum);
266
267/* Differential Mux */
268static const char * const es8328_diff_sel[] = {"Line 1", "Line 2"};
269static SOC_ENUM_SINGLE_DECL(diffmux,
270			    ES8328_ADCCONTROL3, 7, es8328_diff_sel);
271static const struct snd_kcontrol_new es8328_diffmux_controls =
272	SOC_DAPM_ENUM("Route", diffmux);
273
274/* Mono ADC Mux */
275static const char * const es8328_mono_mux[] = {"Stereo", "Mono (Left)",
276	"Mono (Right)", "Digital Mono"};
277static SOC_ENUM_SINGLE_DECL(monomux,
278			    ES8328_ADCCONTROL3, 3, es8328_mono_mux);
279static const struct snd_kcontrol_new es8328_monomux_controls =
280	SOC_DAPM_ENUM("Route", monomux);
281
282static const struct snd_soc_dapm_widget es8328_dapm_widgets[] = {
283	SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0,
284		&es8328_diffmux_controls),
285	SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0,
286		&es8328_monomux_controls),
287	SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0,
288		&es8328_monomux_controls),
289
290	SND_SOC_DAPM_MUX("Left PGA Mux", ES8328_ADCPOWER,
291			ES8328_ADCPOWER_AINL_OFF, 1,
292			&es8328_left_pga_controls),
293	SND_SOC_DAPM_MUX("Right PGA Mux", ES8328_ADCPOWER,
294			ES8328_ADCPOWER_AINR_OFF, 1,
295			&es8328_right_pga_controls),
296
297	SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM, 0, 0,
298		&es8328_left_line_controls),
299	SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM, 0, 0,
300		&es8328_right_line_controls),
301
302	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", ES8328_ADCPOWER,
303			ES8328_ADCPOWER_ADCR_OFF, 1),
304	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", ES8328_ADCPOWER,
305			ES8328_ADCPOWER_ADCL_OFF, 1),
306
307	SND_SOC_DAPM_SUPPLY("Mic Bias", ES8328_ADCPOWER,
308			ES8328_ADCPOWER_MIC_BIAS_OFF, 1, NULL, 0),
309	SND_SOC_DAPM_SUPPLY("Mic Bias Gen", ES8328_ADCPOWER,
310			ES8328_ADCPOWER_ADC_BIAS_GEN_OFF, 1, NULL, 0),
311
312	SND_SOC_DAPM_SUPPLY("DAC STM", ES8328_CHIPPOWER,
313			ES8328_CHIPPOWER_DACSTM_RESET, 1, NULL, 0),
314	SND_SOC_DAPM_SUPPLY("ADC STM", ES8328_CHIPPOWER,
315			ES8328_CHIPPOWER_ADCSTM_RESET, 1, NULL, 0),
316
317	SND_SOC_DAPM_SUPPLY("DAC DIG", ES8328_CHIPPOWER,
318			ES8328_CHIPPOWER_DACDIG_OFF, 1, NULL, 0),
319	SND_SOC_DAPM_SUPPLY("ADC DIG", ES8328_CHIPPOWER,
320			ES8328_CHIPPOWER_ADCDIG_OFF, 1, NULL, 0),
321
322	SND_SOC_DAPM_SUPPLY("DAC DLL", ES8328_CHIPPOWER,
323			ES8328_CHIPPOWER_DACDLL_OFF, 1, NULL, 0),
324	SND_SOC_DAPM_SUPPLY("ADC DLL", ES8328_CHIPPOWER,
325			ES8328_CHIPPOWER_ADCDLL_OFF, 1, NULL, 0),
326
327	SND_SOC_DAPM_SUPPLY("ADC Vref", ES8328_CHIPPOWER,
328			ES8328_CHIPPOWER_ADCVREF_OFF, 1, NULL, 0),
329	SND_SOC_DAPM_SUPPLY("DAC Vref", ES8328_CHIPPOWER,
330			ES8328_CHIPPOWER_DACVREF_OFF, 1, NULL, 0),
331
332	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", ES8328_DACPOWER,
333			ES8328_DACPOWER_RDAC_OFF, 1),
334	SND_SOC_DAPM_DAC("Left DAC", "Left Playback", ES8328_DACPOWER,
335			ES8328_DACPOWER_LDAC_OFF, 1),
336
337	SND_SOC_DAPM_MIXER("Left Mixer", ES8328_DACCONTROL17, 7, 0,
338		&es8328_left_mixer_controls[0],
339		ARRAY_SIZE(es8328_left_mixer_controls)),
340	SND_SOC_DAPM_MIXER("Right Mixer", ES8328_DACCONTROL20, 7, 0,
341		&es8328_right_mixer_controls[0],
342		ARRAY_SIZE(es8328_right_mixer_controls)),
343
344	SND_SOC_DAPM_PGA("Right Out 2", ES8328_DACPOWER,
345			ES8328_DACPOWER_ROUT2_ON, 0, NULL, 0),
346	SND_SOC_DAPM_PGA("Left Out 2", ES8328_DACPOWER,
347			ES8328_DACPOWER_LOUT2_ON, 0, NULL, 0),
348	SND_SOC_DAPM_PGA("Right Out 1", ES8328_DACPOWER,
349			ES8328_DACPOWER_ROUT1_ON, 0, NULL, 0),
350	SND_SOC_DAPM_PGA("Left Out 1", ES8328_DACPOWER,
351			ES8328_DACPOWER_LOUT1_ON, 0, NULL, 0),
352
353	SND_SOC_DAPM_OUTPUT("LOUT1"),
354	SND_SOC_DAPM_OUTPUT("ROUT1"),
355	SND_SOC_DAPM_OUTPUT("LOUT2"),
356	SND_SOC_DAPM_OUTPUT("ROUT2"),
357
358	SND_SOC_DAPM_INPUT("LINPUT1"),
359	SND_SOC_DAPM_INPUT("LINPUT2"),
360	SND_SOC_DAPM_INPUT("RINPUT1"),
361	SND_SOC_DAPM_INPUT("RINPUT2"),
362};
363
364static const struct snd_soc_dapm_route es8328_dapm_routes[] = {
365
366	{ "Left Line Mux", "Line 1", "LINPUT1" },
367	{ "Left Line Mux", "Line 2", "LINPUT2" },
368	{ "Left Line Mux", "PGA", "Left PGA Mux" },
369	{ "Left Line Mux", "Differential", "Differential Mux" },
370
371	{ "Right Line Mux", "Line 1", "RINPUT1" },
372	{ "Right Line Mux", "Line 2", "RINPUT2" },
373	{ "Right Line Mux", "PGA", "Right PGA Mux" },
374	{ "Right Line Mux", "Differential", "Differential Mux" },
375
376	{ "Left PGA Mux", "Line 1", "LINPUT1" },
377	{ "Left PGA Mux", "Line 2", "LINPUT2" },
378	{ "Left PGA Mux", "Differential", "Differential Mux" },
379
380	{ "Right PGA Mux", "Line 1", "RINPUT1" },
381	{ "Right PGA Mux", "Line 2", "RINPUT2" },
382	{ "Right PGA Mux", "Differential", "Differential Mux" },
383
384	{ "Differential Mux", "Line 1", "LINPUT1" },
385	{ "Differential Mux", "Line 1", "RINPUT1" },
386	{ "Differential Mux", "Line 2", "LINPUT2" },
387	{ "Differential Mux", "Line 2", "RINPUT2" },
388
389	{ "Left ADC Mux", "Stereo", "Left PGA Mux" },
390	{ "Left ADC Mux", "Mono (Left)", "Left PGA Mux" },
391	{ "Left ADC Mux", "Digital Mono", "Left PGA Mux" },
392
393	{ "Right ADC Mux", "Stereo", "Right PGA Mux" },
394	{ "Right ADC Mux", "Mono (Right)", "Right PGA Mux" },
395	{ "Right ADC Mux", "Digital Mono", "Right PGA Mux" },
396
397	{ "Left ADC", NULL, "Left ADC Mux" },
398	{ "Right ADC", NULL, "Right ADC Mux" },
399
400	{ "ADC DIG", NULL, "ADC STM" },
401	{ "ADC DIG", NULL, "ADC Vref" },
402	{ "ADC DIG", NULL, "ADC DLL" },
403
404	{ "Left ADC", NULL, "ADC DIG" },
405	{ "Right ADC", NULL, "ADC DIG" },
406
407	{ "Mic Bias", NULL, "Mic Bias Gen" },
408
409	{ "Left Line Mux", "Line 1", "LINPUT1" },
410	{ "Left Line Mux", "Line 2", "LINPUT2" },
411	{ "Left Line Mux", "PGA", "Left PGA Mux" },
412	{ "Left Line Mux", "Differential", "Differential Mux" },
413
414	{ "Right Line Mux", "Line 1", "RINPUT1" },
415	{ "Right Line Mux", "Line 2", "RINPUT2" },
416	{ "Right Line Mux", "PGA", "Right PGA Mux" },
417	{ "Right Line Mux", "Differential", "Differential Mux" },
418
419	{ "Left Mixer", NULL, "Left DAC" },
 
 
 
 
 
420	{ "Left Mixer", "Left Bypass Switch", "Left Line Mux" },
421	{ "Left Mixer", "Right Playback Switch", "Right DAC" },
422	{ "Left Mixer", "Right Bypass Switch", "Right Line Mux" },
423
424	{ "Right Mixer", "Left Playback Switch", "Left DAC" },
425	{ "Right Mixer", "Left Bypass Switch", "Left Line Mux" },
426	{ "Right Mixer", NULL, "Right DAC" },
427	{ "Right Mixer", "Right Bypass Switch", "Right Line Mux" },
428
429	{ "DAC DIG", NULL, "DAC STM" },
430	{ "DAC DIG", NULL, "DAC Vref" },
431	{ "DAC DIG", NULL, "DAC DLL" },
432
433	{ "Left DAC", NULL, "DAC DIG" },
434	{ "Right DAC", NULL, "DAC DIG" },
435
436	{ "Left Out 1", NULL, "Left Mixer" },
437	{ "LOUT1", NULL, "Left Out 1" },
438	{ "Right Out 1", NULL, "Right Mixer" },
439	{ "ROUT1", NULL, "Right Out 1" },
440
441	{ "Left Out 2", NULL, "Left Mixer" },
442	{ "LOUT2", NULL, "Left Out 2" },
443	{ "Right Out 2", NULL, "Right Mixer" },
444	{ "ROUT2", NULL, "Right Out 2" },
445};
446
447static int es8328_mute(struct snd_soc_dai *dai, int mute, int direction)
448{
449	return snd_soc_component_update_bits(dai->component, ES8328_DACCONTROL3,
450			ES8328_DACCONTROL3_DACMUTE,
451			mute ? ES8328_DACCONTROL3_DACMUTE : 0);
452}
453
454static int es8328_startup(struct snd_pcm_substream *substream,
455			  struct snd_soc_dai *dai)
456{
457	struct snd_soc_component *component = dai->component;
458	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
459
460	if (es8328->provider && es8328->sysclk_constraints)
461		snd_pcm_hw_constraint_list(substream->runtime, 0,
462				SNDRV_PCM_HW_PARAM_RATE,
463				es8328->sysclk_constraints);
464
465	return 0;
466}
467
468static int es8328_hw_params(struct snd_pcm_substream *substream,
469	struct snd_pcm_hw_params *params,
470	struct snd_soc_dai *dai)
471{
472	struct snd_soc_component *component = dai->component;
473	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
474	int i;
475	int reg;
476	int wl;
477	int ratio;
478
479	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
480		reg = ES8328_DACCONTROL2;
481	else
482		reg = ES8328_ADCCONTROL5;
483
484	if (es8328->provider) {
485		if (!es8328->sysclk_constraints) {
486			dev_err(component->dev, "No MCLK configured\n");
487			return -EINVAL;
488		}
489
490		for (i = 0; i < es8328->sysclk_constraints->count; i++)
491			if (es8328->sysclk_constraints->list[i] ==
492			    params_rate(params))
493				break;
494
495		if (i == es8328->sysclk_constraints->count) {
496			dev_err(component->dev,
497				"LRCLK %d unsupported with current clock\n",
498				params_rate(params));
499			return -EINVAL;
500		}
501		ratio = es8328->mclk_ratios[i];
502	} else {
503		ratio = 0;
504		es8328->mclkdiv2 = 0;
505	}
506
507	snd_soc_component_update_bits(component, ES8328_MASTERMODE,
508			ES8328_MASTERMODE_MCLKDIV2,
509			es8328->mclkdiv2 ? ES8328_MASTERMODE_MCLKDIV2 : 0);
510
511	switch (params_width(params)) {
512	case 16:
513		wl = 3;
514		break;
515	case 18:
516		wl = 2;
517		break;
518	case 20:
519		wl = 1;
520		break;
521	case 24:
522		wl = 0;
523		break;
524	case 32:
525		wl = 4;
526		break;
527	default:
528		return -EINVAL;
529	}
530
531	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
532		snd_soc_component_update_bits(component, ES8328_DACCONTROL1,
533				ES8328_DACCONTROL1_DACWL_MASK,
534				wl << ES8328_DACCONTROL1_DACWL_SHIFT);
535
536		es8328->playback_fs = params_rate(params);
537		es8328_set_deemph(component);
538	} else
539		snd_soc_component_update_bits(component, ES8328_ADCCONTROL4,
540				ES8328_ADCCONTROL4_ADCWL_MASK,
541				wl << ES8328_ADCCONTROL4_ADCWL_SHIFT);
542
543	return snd_soc_component_update_bits(component, reg, ES8328_RATEMASK, ratio);
544}
545
546static int es8328_set_sysclk(struct snd_soc_dai *codec_dai,
547		int clk_id, unsigned int freq, int dir)
548{
549	struct snd_soc_component *component = codec_dai->component;
550	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
551	int mclkdiv2 = 0;
552	unsigned int round_freq;
553
554	/*
555	 * Allow a small tolerance for frequencies within 100hz. Note
556	 * this value is chosen arbitrarily.
557	 */
558	round_freq = DIV_ROUND_CLOSEST(freq, 100) * 100;
559
560	switch (round_freq) {
561	case 0:
562		es8328->sysclk_constraints = NULL;
563		es8328->mclk_ratios = NULL;
564		break;
565	case 22579200:
566		mclkdiv2 = 1;
567		fallthrough;
568	case 11289600:
569		es8328->sysclk_constraints = &constraints_11289;
570		es8328->mclk_ratios = ratios_11289;
571		break;
572	case 24576000:
573		mclkdiv2 = 1;
574		fallthrough;
575	case 12288000:
576		es8328->sysclk_constraints = &constraints_12288;
577		es8328->mclk_ratios = ratios_12288;
578		break;
579	default:
580		return -EINVAL;
581	}
582
583	es8328->mclkdiv2 = mclkdiv2;
584	return 0;
585}
586
587static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai,
588		unsigned int fmt)
589{
590	struct snd_soc_component *component = codec_dai->component;
591	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
592	u8 dac_mode = 0;
593	u8 adc_mode = 0;
594
595	switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
596	case SND_SOC_DAIFMT_CBP_CFP:
597		/* Master serial port mode, with BCLK generated automatically */
598		snd_soc_component_update_bits(component, ES8328_MASTERMODE,
599				    ES8328_MASTERMODE_MSC,
600				    ES8328_MASTERMODE_MSC);
601		es8328->provider = true;
602		break;
603	case SND_SOC_DAIFMT_CBC_CFC:
604		/* Slave serial port mode */
605		snd_soc_component_update_bits(component, ES8328_MASTERMODE,
606				    ES8328_MASTERMODE_MSC, 0);
607		es8328->provider = false;
608		break;
609	default:
610		return -EINVAL;
611	}
612
613	/* interface format */
614	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
615	case SND_SOC_DAIFMT_I2S:
616		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_I2S;
617		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_I2S;
618		break;
619	case SND_SOC_DAIFMT_RIGHT_J:
620		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_RJUST;
621		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_RJUST;
622		break;
623	case SND_SOC_DAIFMT_LEFT_J:
624		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_LJUST;
625		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_LJUST;
626		break;
627	default:
628		return -EINVAL;
629	}
630
631	/* clock inversion */
632	if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF)
633		return -EINVAL;
634
635	snd_soc_component_update_bits(component, ES8328_DACCONTROL1,
636			ES8328_DACCONTROL1_DACFORMAT_MASK, dac_mode);
637	snd_soc_component_update_bits(component, ES8328_ADCCONTROL4,
638			ES8328_ADCCONTROL4_ADCFORMAT_MASK, adc_mode);
639
640	return 0;
641}
642
643static int es8328_set_bias_level(struct snd_soc_component *component,
644				 enum snd_soc_bias_level level)
645{
646	switch (level) {
647	case SND_SOC_BIAS_ON:
648		break;
649
650	case SND_SOC_BIAS_PREPARE:
651		/* VREF, VMID=2x50k, digital enabled */
652		snd_soc_component_write(component, ES8328_CHIPPOWER, 0);
653		snd_soc_component_update_bits(component, ES8328_CONTROL1,
654				ES8328_CONTROL1_VMIDSEL_MASK |
655				ES8328_CONTROL1_ENREF,
656				ES8328_CONTROL1_VMIDSEL_50k |
657				ES8328_CONTROL1_ENREF);
658		break;
659
660	case SND_SOC_BIAS_STANDBY:
661		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
662			snd_soc_component_update_bits(component, ES8328_CONTROL1,
663					ES8328_CONTROL1_VMIDSEL_MASK |
664					ES8328_CONTROL1_ENREF,
665					ES8328_CONTROL1_VMIDSEL_5k |
666					ES8328_CONTROL1_ENREF);
667
668			/* Charge caps */
669			msleep(100);
670		}
671
672		snd_soc_component_write(component, ES8328_CONTROL2,
673				ES8328_CONTROL2_OVERCURRENT_ON |
674				ES8328_CONTROL2_THERMAL_SHUTDOWN_ON);
675
676		/* VREF, VMID=2*500k, digital stopped */
677		snd_soc_component_update_bits(component, ES8328_CONTROL1,
678				ES8328_CONTROL1_VMIDSEL_MASK |
679				ES8328_CONTROL1_ENREF,
680				ES8328_CONTROL1_VMIDSEL_500k |
681				ES8328_CONTROL1_ENREF);
682		break;
683
684	case SND_SOC_BIAS_OFF:
685		snd_soc_component_update_bits(component, ES8328_CONTROL1,
686				ES8328_CONTROL1_VMIDSEL_MASK |
687				ES8328_CONTROL1_ENREF,
688				0);
689		break;
690	}
691	return 0;
692}
693
694static const struct snd_soc_dai_ops es8328_dai_ops = {
695	.startup	= es8328_startup,
696	.hw_params	= es8328_hw_params,
697	.mute_stream	= es8328_mute,
698	.set_sysclk	= es8328_set_sysclk,
699	.set_fmt	= es8328_set_dai_fmt,
700	.no_capture_mute = 1,
701};
702
703static struct snd_soc_dai_driver es8328_dai = {
704	.name = "es8328-hifi-analog",
705	.playback = {
706		.stream_name = "Playback",
707		.channels_min = 2,
708		.channels_max = 2,
709		.rates = ES8328_RATES,
710		.formats = ES8328_FORMATS,
711	},
712	.capture = {
713		.stream_name = "Capture",
714		.channels_min = 2,
715		.channels_max = 2,
716		.rates = ES8328_RATES,
717		.formats = ES8328_FORMATS,
718	},
719	.ops = &es8328_dai_ops,
720	.symmetric_rate = 1,
721};
722
723static int es8328_suspend(struct snd_soc_component *component)
724{
725	struct es8328_priv *es8328;
726	int ret;
727
728	es8328 = snd_soc_component_get_drvdata(component);
729
730	clk_disable_unprepare(es8328->clk);
731
732	ret = regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
733			es8328->supplies);
734	if (ret) {
735		dev_err(component->dev, "unable to disable regulators\n");
736		return ret;
737	}
738	return 0;
739}
740
741static int es8328_resume(struct snd_soc_component *component)
742{
743	struct regmap *regmap = dev_get_regmap(component->dev, NULL);
744	struct es8328_priv *es8328;
745	int ret;
746
747	es8328 = snd_soc_component_get_drvdata(component);
748
749	ret = clk_prepare_enable(es8328->clk);
750	if (ret) {
751		dev_err(component->dev, "unable to enable clock\n");
752		return ret;
753	}
754
755	ret = regulator_bulk_enable(ARRAY_SIZE(es8328->supplies),
756					es8328->supplies);
757	if (ret) {
758		dev_err(component->dev, "unable to enable regulators\n");
759		return ret;
760	}
761
762	regcache_mark_dirty(regmap);
763	ret = regcache_sync(regmap);
764	if (ret) {
765		dev_err(component->dev, "unable to sync regcache\n");
766		return ret;
767	}
768
769	return 0;
770}
771
772static int es8328_component_probe(struct snd_soc_component *component)
773{
774	struct es8328_priv *es8328;
775	int ret;
776
777	es8328 = snd_soc_component_get_drvdata(component);
778
779	ret = regulator_bulk_enable(ARRAY_SIZE(es8328->supplies),
780					es8328->supplies);
781	if (ret) {
782		dev_err(component->dev, "unable to enable regulators\n");
783		return ret;
784	}
785
786	/* Setup clocks */
787	es8328->clk = devm_clk_get(component->dev, NULL);
788	if (IS_ERR(es8328->clk)) {
789		dev_err(component->dev, "codec clock missing or invalid\n");
790		ret = PTR_ERR(es8328->clk);
791		goto clk_fail;
792	}
793
794	ret = clk_prepare_enable(es8328->clk);
795	if (ret) {
796		dev_err(component->dev, "unable to prepare codec clk\n");
797		goto clk_fail;
798	}
799
800	return 0;
801
802clk_fail:
803	regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
804			       es8328->supplies);
805	return ret;
806}
807
808static void es8328_remove(struct snd_soc_component *component)
809{
810	struct es8328_priv *es8328;
811
812	es8328 = snd_soc_component_get_drvdata(component);
813
814	clk_disable_unprepare(es8328->clk);
 
815
816	regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
817			       es8328->supplies);
818}
819
820const struct regmap_config es8328_regmap_config = {
821	.reg_bits	= 8,
822	.val_bits	= 8,
823	.max_register	= ES8328_REG_MAX,
824	.cache_type	= REGCACHE_MAPLE,
825	.use_single_read = true,
826	.use_single_write = true,
827};
828EXPORT_SYMBOL_GPL(es8328_regmap_config);
829
830static const struct snd_soc_component_driver es8328_component_driver = {
831	.probe			= es8328_component_probe,
832	.remove			= es8328_remove,
833	.suspend		= es8328_suspend,
834	.resume			= es8328_resume,
835	.set_bias_level		= es8328_set_bias_level,
836	.controls		= es8328_snd_controls,
837	.num_controls		= ARRAY_SIZE(es8328_snd_controls),
838	.dapm_widgets		= es8328_dapm_widgets,
839	.num_dapm_widgets	= ARRAY_SIZE(es8328_dapm_widgets),
840	.dapm_routes		= es8328_dapm_routes,
841	.num_dapm_routes	= ARRAY_SIZE(es8328_dapm_routes),
842	.suspend_bias_off	= 1,
843	.idle_bias_on		= 1,
844	.use_pmdown_time	= 1,
845	.endianness		= 1,
 
846};
847
848int es8328_probe(struct device *dev, struct regmap *regmap)
849{
850	struct es8328_priv *es8328;
851	int ret;
852	int i;
853
854	if (IS_ERR(regmap))
855		return PTR_ERR(regmap);
856
857	es8328 = devm_kzalloc(dev, sizeof(*es8328), GFP_KERNEL);
858	if (es8328 == NULL)
859		return -ENOMEM;
860
861	es8328->regmap = regmap;
862
863	for (i = 0; i < ARRAY_SIZE(es8328->supplies); i++)
864		es8328->supplies[i].supply = supply_names[i];
865
866	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(es8328->supplies),
867				es8328->supplies);
868	if (ret) {
869		dev_err(dev, "unable to get regulators\n");
870		return ret;
871	}
872
873	dev_set_drvdata(dev, es8328);
874
875	return devm_snd_soc_register_component(dev,
876			&es8328_component_driver, &es8328_dai, 1);
877}
878EXPORT_SYMBOL_GPL(es8328_probe);
879
880MODULE_DESCRIPTION("ASoC ES8328 driver");
881MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
882MODULE_LICENSE("GPL");
v4.17
 
  1/*
  2 * es8328.c  --  ES8328 ALSA SoC Audio driver
  3 *
  4 * Copyright 2014 Sutajio Ko-Usagi PTE LTD
  5 *
  6 * Author: Sean Cross <xobs@kosagi.com>
  7 *
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License version 2 as
 10 * published by the Free Software Foundation.
 11 */
 12
 13#include <linux/clk.h>
 14#include <linux/delay.h>
 15#include <linux/of_device.h>
 16#include <linux/module.h>
 17#include <linux/pm.h>
 18#include <linux/regmap.h>
 19#include <linux/slab.h>
 20#include <linux/regulator/consumer.h>
 21#include <sound/core.h>
 22#include <sound/initval.h>
 23#include <sound/pcm.h>
 24#include <sound/pcm_params.h>
 25#include <sound/soc.h>
 26#include <sound/tlv.h>
 27#include "es8328.h"
 28
 29static const unsigned int rates_12288[] = {
 30	8000, 12000, 16000, 24000, 32000, 48000, 96000,
 31};
 32
 33static const int ratios_12288[] = {
 34	10, 7, 6, 4, 3, 2, 0,
 35};
 36
 37static const struct snd_pcm_hw_constraint_list constraints_12288 = {
 38	.count	= ARRAY_SIZE(rates_12288),
 39	.list	= rates_12288,
 40};
 41
 42static const unsigned int rates_11289[] = {
 43	8018, 11025, 22050, 44100, 88200,
 44};
 45
 46static const int ratios_11289[] = {
 47	9, 7, 4, 2, 0,
 48};
 49
 50static const struct snd_pcm_hw_constraint_list constraints_11289 = {
 51	.count	= ARRAY_SIZE(rates_11289),
 52	.list	= rates_11289,
 53};
 54
 55/* regulator supplies for sgtl5000, VDDD is an optional external supply */
 56enum sgtl5000_regulator_supplies {
 57	DVDD,
 58	AVDD,
 59	PVDD,
 60	HPVDD,
 61	ES8328_SUPPLY_NUM
 62};
 63
 64/* vddd is optional supply */
 65static const char * const supply_names[ES8328_SUPPLY_NUM] = {
 66	"DVDD",
 67	"AVDD",
 68	"PVDD",
 69	"HPVDD",
 70};
 71
 72#define ES8328_RATES (SNDRV_PCM_RATE_192000 | \
 73		SNDRV_PCM_RATE_96000 | \
 74		SNDRV_PCM_RATE_88200 | \
 75		SNDRV_PCM_RATE_8000_48000)
 76#define ES8328_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
 77		SNDRV_PCM_FMTBIT_S18_3LE | \
 78		SNDRV_PCM_FMTBIT_S20_3LE | \
 79		SNDRV_PCM_FMTBIT_S24_LE | \
 80		SNDRV_PCM_FMTBIT_S32_LE)
 81
 82struct es8328_priv {
 83	struct regmap *regmap;
 84	struct clk *clk;
 85	int playback_fs;
 86	bool deemph;
 87	int mclkdiv2;
 88	const struct snd_pcm_hw_constraint_list *sysclk_constraints;
 89	const int *mclk_ratios;
 90	bool master;
 91	struct regulator_bulk_data supplies[ES8328_SUPPLY_NUM];
 92};
 93
 94/*
 95 * ES8328 Controls
 96 */
 97
 98static const char * const adcpol_txt[] = {"Normal", "L Invert", "R Invert",
 99					  "L + R Invert"};
100static SOC_ENUM_SINGLE_DECL(adcpol,
101			    ES8328_ADCCONTROL6, 6, adcpol_txt);
102
103static const DECLARE_TLV_DB_SCALE(play_tlv, -3000, 100, 0);
104static const DECLARE_TLV_DB_SCALE(dac_adc_tlv, -9600, 50, 0);
105static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
106static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
107static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 300, 0);
108
109static const struct {
110	int rate;
111	unsigned int val;
112} deemph_settings[] = {
113	{ 0,     ES8328_DACCONTROL6_DEEMPH_OFF },
114	{ 32000, ES8328_DACCONTROL6_DEEMPH_32k },
115	{ 44100, ES8328_DACCONTROL6_DEEMPH_44_1k },
116	{ 48000, ES8328_DACCONTROL6_DEEMPH_48k },
117};
118
119static int es8328_set_deemph(struct snd_soc_component *component)
120{
121	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
122	int val, i, best;
123
124	/*
125	 * If we're using deemphasis select the nearest available sample
126	 * rate.
127	 */
128	if (es8328->deemph) {
129		best = 0;
130		for (i = 1; i < ARRAY_SIZE(deemph_settings); i++) {
131			if (abs(deemph_settings[i].rate - es8328->playback_fs) <
132			    abs(deemph_settings[best].rate - es8328->playback_fs))
133				best = i;
134		}
135
136		val = deemph_settings[best].val;
137	} else {
138		val = ES8328_DACCONTROL6_DEEMPH_OFF;
139	}
140
141	dev_dbg(component->dev, "Set deemphasis %d\n", val);
142
143	return snd_soc_component_update_bits(component, ES8328_DACCONTROL6,
144			ES8328_DACCONTROL6_DEEMPH_MASK, val);
145}
146
147static int es8328_get_deemph(struct snd_kcontrol *kcontrol,
148			     struct snd_ctl_elem_value *ucontrol)
149{
150	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
151	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
152
153	ucontrol->value.integer.value[0] = es8328->deemph;
154	return 0;
155}
156
157static int es8328_put_deemph(struct snd_kcontrol *kcontrol,
158			     struct snd_ctl_elem_value *ucontrol)
159{
160	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
161	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
162	unsigned int deemph = ucontrol->value.integer.value[0];
163	int ret;
164
165	if (deemph > 1)
166		return -EINVAL;
167
 
 
 
168	ret = es8328_set_deemph(component);
169	if (ret < 0)
170		return ret;
171
172	es8328->deemph = deemph;
173
174	return 0;
175}
176
177
178
179static const struct snd_kcontrol_new es8328_snd_controls[] = {
180	SOC_DOUBLE_R_TLV("Capture Digital Volume",
181		ES8328_ADCCONTROL8, ES8328_ADCCONTROL9,
182		 0, 0xc0, 1, dac_adc_tlv),
183	SOC_SINGLE("Capture ZC Switch", ES8328_ADCCONTROL7, 6, 1, 0),
184
185	SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
186		    es8328_get_deemph, es8328_put_deemph),
187
188	SOC_ENUM("Capture Polarity", adcpol),
189
190	SOC_SINGLE_TLV("Left Mixer Left Bypass Volume",
191			ES8328_DACCONTROL17, 3, 7, 1, bypass_tlv),
192	SOC_SINGLE_TLV("Left Mixer Right Bypass Volume",
193			ES8328_DACCONTROL19, 3, 7, 1, bypass_tlv),
194	SOC_SINGLE_TLV("Right Mixer Left Bypass Volume",
195			ES8328_DACCONTROL18, 3, 7, 1, bypass_tlv),
196	SOC_SINGLE_TLV("Right Mixer Right Bypass Volume",
197			ES8328_DACCONTROL20, 3, 7, 1, bypass_tlv),
198
199	SOC_DOUBLE_R_TLV("PCM Volume",
200			ES8328_LDACVOL, ES8328_RDACVOL,
201			0, ES8328_DACVOL_MAX, 1, dac_adc_tlv),
202
203	SOC_DOUBLE_R_TLV("Output 1 Playback Volume",
204			ES8328_LOUT1VOL, ES8328_ROUT1VOL,
205			0, ES8328_OUT1VOL_MAX, 0, play_tlv),
206
207	SOC_DOUBLE_R_TLV("Output 2 Playback Volume",
208			ES8328_LOUT2VOL, ES8328_ROUT2VOL,
209			0, ES8328_OUT2VOL_MAX, 0, play_tlv),
210
211	SOC_DOUBLE_TLV("Mic PGA Volume", ES8328_ADCCONTROL1,
212			4, 0, 8, 0, mic_tlv),
213};
214
215/*
216 * DAPM Controls
217 */
218
219static const char * const es8328_line_texts[] = {
220	"Line 1", "Line 2", "PGA", "Differential"};
221
222static const struct soc_enum es8328_lline_enum =
223	SOC_ENUM_SINGLE(ES8328_DACCONTROL16, 3,
224			      ARRAY_SIZE(es8328_line_texts),
225			      es8328_line_texts);
226static const struct snd_kcontrol_new es8328_left_line_controls =
227	SOC_DAPM_ENUM("Route", es8328_lline_enum);
228
229static const struct soc_enum es8328_rline_enum =
230	SOC_ENUM_SINGLE(ES8328_DACCONTROL16, 0,
231			      ARRAY_SIZE(es8328_line_texts),
232			      es8328_line_texts);
233static const struct snd_kcontrol_new es8328_right_line_controls =
234	SOC_DAPM_ENUM("Route", es8328_lline_enum);
235
236/* Left Mixer */
237static const struct snd_kcontrol_new es8328_left_mixer_controls[] = {
238	SOC_DAPM_SINGLE("Playback Switch", ES8328_DACCONTROL17, 7, 1, 0),
239	SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL17, 6, 1, 0),
240	SOC_DAPM_SINGLE("Right Playback Switch", ES8328_DACCONTROL18, 7, 1, 0),
241	SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL18, 6, 1, 0),
242};
243
244/* Right Mixer */
245static const struct snd_kcontrol_new es8328_right_mixer_controls[] = {
246	SOC_DAPM_SINGLE("Left Playback Switch", ES8328_DACCONTROL19, 7, 1, 0),
247	SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL19, 6, 1, 0),
248	SOC_DAPM_SINGLE("Playback Switch", ES8328_DACCONTROL20, 7, 1, 0),
249	SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL20, 6, 1, 0),
250};
251
252static const char * const es8328_pga_sel[] = {
253	"Line 1", "Line 2", "Line 3", "Differential"};
254
255/* Left PGA Mux */
256static const struct soc_enum es8328_lpga_enum =
257	SOC_ENUM_SINGLE(ES8328_ADCCONTROL2, 6,
258			      ARRAY_SIZE(es8328_pga_sel),
259			      es8328_pga_sel);
260static const struct snd_kcontrol_new es8328_left_pga_controls =
261	SOC_DAPM_ENUM("Route", es8328_lpga_enum);
262
263/* Right PGA Mux */
264static const struct soc_enum es8328_rpga_enum =
265	SOC_ENUM_SINGLE(ES8328_ADCCONTROL2, 4,
266			      ARRAY_SIZE(es8328_pga_sel),
267			      es8328_pga_sel);
268static const struct snd_kcontrol_new es8328_right_pga_controls =
269	SOC_DAPM_ENUM("Route", es8328_rpga_enum);
270
271/* Differential Mux */
272static const char * const es8328_diff_sel[] = {"Line 1", "Line 2"};
273static SOC_ENUM_SINGLE_DECL(diffmux,
274			    ES8328_ADCCONTROL3, 7, es8328_diff_sel);
275static const struct snd_kcontrol_new es8328_diffmux_controls =
276	SOC_DAPM_ENUM("Route", diffmux);
277
278/* Mono ADC Mux */
279static const char * const es8328_mono_mux[] = {"Stereo", "Mono (Left)",
280	"Mono (Right)", "Digital Mono"};
281static SOC_ENUM_SINGLE_DECL(monomux,
282			    ES8328_ADCCONTROL3, 3, es8328_mono_mux);
283static const struct snd_kcontrol_new es8328_monomux_controls =
284	SOC_DAPM_ENUM("Route", monomux);
285
286static const struct snd_soc_dapm_widget es8328_dapm_widgets[] = {
287	SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0,
288		&es8328_diffmux_controls),
289	SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0,
290		&es8328_monomux_controls),
291	SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0,
292		&es8328_monomux_controls),
293
294	SND_SOC_DAPM_MUX("Left PGA Mux", ES8328_ADCPOWER,
295			ES8328_ADCPOWER_AINL_OFF, 1,
296			&es8328_left_pga_controls),
297	SND_SOC_DAPM_MUX("Right PGA Mux", ES8328_ADCPOWER,
298			ES8328_ADCPOWER_AINR_OFF, 1,
299			&es8328_right_pga_controls),
300
301	SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM, 0, 0,
302		&es8328_left_line_controls),
303	SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM, 0, 0,
304		&es8328_right_line_controls),
305
306	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", ES8328_ADCPOWER,
307			ES8328_ADCPOWER_ADCR_OFF, 1),
308	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", ES8328_ADCPOWER,
309			ES8328_ADCPOWER_ADCL_OFF, 1),
310
311	SND_SOC_DAPM_SUPPLY("Mic Bias", ES8328_ADCPOWER,
312			ES8328_ADCPOWER_MIC_BIAS_OFF, 1, NULL, 0),
313	SND_SOC_DAPM_SUPPLY("Mic Bias Gen", ES8328_ADCPOWER,
314			ES8328_ADCPOWER_ADC_BIAS_GEN_OFF, 1, NULL, 0),
315
316	SND_SOC_DAPM_SUPPLY("DAC STM", ES8328_CHIPPOWER,
317			ES8328_CHIPPOWER_DACSTM_RESET, 1, NULL, 0),
318	SND_SOC_DAPM_SUPPLY("ADC STM", ES8328_CHIPPOWER,
319			ES8328_CHIPPOWER_ADCSTM_RESET, 1, NULL, 0),
320
321	SND_SOC_DAPM_SUPPLY("DAC DIG", ES8328_CHIPPOWER,
322			ES8328_CHIPPOWER_DACDIG_OFF, 1, NULL, 0),
323	SND_SOC_DAPM_SUPPLY("ADC DIG", ES8328_CHIPPOWER,
324			ES8328_CHIPPOWER_ADCDIG_OFF, 1, NULL, 0),
325
326	SND_SOC_DAPM_SUPPLY("DAC DLL", ES8328_CHIPPOWER,
327			ES8328_CHIPPOWER_DACDLL_OFF, 1, NULL, 0),
328	SND_SOC_DAPM_SUPPLY("ADC DLL", ES8328_CHIPPOWER,
329			ES8328_CHIPPOWER_ADCDLL_OFF, 1, NULL, 0),
330
331	SND_SOC_DAPM_SUPPLY("ADC Vref", ES8328_CHIPPOWER,
332			ES8328_CHIPPOWER_ADCVREF_OFF, 1, NULL, 0),
333	SND_SOC_DAPM_SUPPLY("DAC Vref", ES8328_CHIPPOWER,
334			ES8328_CHIPPOWER_DACVREF_OFF, 1, NULL, 0),
335
336	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", ES8328_DACPOWER,
337			ES8328_DACPOWER_RDAC_OFF, 1),
338	SND_SOC_DAPM_DAC("Left DAC", "Left Playback", ES8328_DACPOWER,
339			ES8328_DACPOWER_LDAC_OFF, 1),
340
341	SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0,
342		&es8328_left_mixer_controls[0],
343		ARRAY_SIZE(es8328_left_mixer_controls)),
344	SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0,
345		&es8328_right_mixer_controls[0],
346		ARRAY_SIZE(es8328_right_mixer_controls)),
347
348	SND_SOC_DAPM_PGA("Right Out 2", ES8328_DACPOWER,
349			ES8328_DACPOWER_ROUT2_ON, 0, NULL, 0),
350	SND_SOC_DAPM_PGA("Left Out 2", ES8328_DACPOWER,
351			ES8328_DACPOWER_LOUT2_ON, 0, NULL, 0),
352	SND_SOC_DAPM_PGA("Right Out 1", ES8328_DACPOWER,
353			ES8328_DACPOWER_ROUT1_ON, 0, NULL, 0),
354	SND_SOC_DAPM_PGA("Left Out 1", ES8328_DACPOWER,
355			ES8328_DACPOWER_LOUT1_ON, 0, NULL, 0),
356
357	SND_SOC_DAPM_OUTPUT("LOUT1"),
358	SND_SOC_DAPM_OUTPUT("ROUT1"),
359	SND_SOC_DAPM_OUTPUT("LOUT2"),
360	SND_SOC_DAPM_OUTPUT("ROUT2"),
361
362	SND_SOC_DAPM_INPUT("LINPUT1"),
363	SND_SOC_DAPM_INPUT("LINPUT2"),
364	SND_SOC_DAPM_INPUT("RINPUT1"),
365	SND_SOC_DAPM_INPUT("RINPUT2"),
366};
367
368static const struct snd_soc_dapm_route es8328_dapm_routes[] = {
369
370	{ "Left Line Mux", "Line 1", "LINPUT1" },
371	{ "Left Line Mux", "Line 2", "LINPUT2" },
372	{ "Left Line Mux", "PGA", "Left PGA Mux" },
373	{ "Left Line Mux", "Differential", "Differential Mux" },
374
375	{ "Right Line Mux", "Line 1", "RINPUT1" },
376	{ "Right Line Mux", "Line 2", "RINPUT2" },
377	{ "Right Line Mux", "PGA", "Right PGA Mux" },
378	{ "Right Line Mux", "Differential", "Differential Mux" },
379
380	{ "Left PGA Mux", "Line 1", "LINPUT1" },
381	{ "Left PGA Mux", "Line 2", "LINPUT2" },
382	{ "Left PGA Mux", "Differential", "Differential Mux" },
383
384	{ "Right PGA Mux", "Line 1", "RINPUT1" },
385	{ "Right PGA Mux", "Line 2", "RINPUT2" },
386	{ "Right PGA Mux", "Differential", "Differential Mux" },
387
388	{ "Differential Mux", "Line 1", "LINPUT1" },
389	{ "Differential Mux", "Line 1", "RINPUT1" },
390	{ "Differential Mux", "Line 2", "LINPUT2" },
391	{ "Differential Mux", "Line 2", "RINPUT2" },
392
393	{ "Left ADC Mux", "Stereo", "Left PGA Mux" },
394	{ "Left ADC Mux", "Mono (Left)", "Left PGA Mux" },
395	{ "Left ADC Mux", "Digital Mono", "Left PGA Mux" },
396
397	{ "Right ADC Mux", "Stereo", "Right PGA Mux" },
398	{ "Right ADC Mux", "Mono (Right)", "Right PGA Mux" },
399	{ "Right ADC Mux", "Digital Mono", "Right PGA Mux" },
400
401	{ "Left ADC", NULL, "Left ADC Mux" },
402	{ "Right ADC", NULL, "Right ADC Mux" },
403
404	{ "ADC DIG", NULL, "ADC STM" },
405	{ "ADC DIG", NULL, "ADC Vref" },
406	{ "ADC DIG", NULL, "ADC DLL" },
407
408	{ "Left ADC", NULL, "ADC DIG" },
409	{ "Right ADC", NULL, "ADC DIG" },
410
411	{ "Mic Bias", NULL, "Mic Bias Gen" },
412
413	{ "Left Line Mux", "Line 1", "LINPUT1" },
414	{ "Left Line Mux", "Line 2", "LINPUT2" },
415	{ "Left Line Mux", "PGA", "Left PGA Mux" },
416	{ "Left Line Mux", "Differential", "Differential Mux" },
417
418	{ "Right Line Mux", "Line 1", "RINPUT1" },
419	{ "Right Line Mux", "Line 2", "RINPUT2" },
420	{ "Right Line Mux", "PGA", "Right PGA Mux" },
421	{ "Right Line Mux", "Differential", "Differential Mux" },
422
423	{ "Left Out 1", NULL, "Left DAC" },
424	{ "Right Out 1", NULL, "Right DAC" },
425	{ "Left Out 2", NULL, "Left DAC" },
426	{ "Right Out 2", NULL, "Right DAC" },
427
428	{ "Left Mixer", "Playback Switch", "Left DAC" },
429	{ "Left Mixer", "Left Bypass Switch", "Left Line Mux" },
430	{ "Left Mixer", "Right Playback Switch", "Right DAC" },
431	{ "Left Mixer", "Right Bypass Switch", "Right Line Mux" },
432
433	{ "Right Mixer", "Left Playback Switch", "Left DAC" },
434	{ "Right Mixer", "Left Bypass Switch", "Left Line Mux" },
435	{ "Right Mixer", "Playback Switch", "Right DAC" },
436	{ "Right Mixer", "Right Bypass Switch", "Right Line Mux" },
437
438	{ "DAC DIG", NULL, "DAC STM" },
439	{ "DAC DIG", NULL, "DAC Vref" },
440	{ "DAC DIG", NULL, "DAC DLL" },
441
442	{ "Left DAC", NULL, "DAC DIG" },
443	{ "Right DAC", NULL, "DAC DIG" },
444
445	{ "Left Out 1", NULL, "Left Mixer" },
446	{ "LOUT1", NULL, "Left Out 1" },
447	{ "Right Out 1", NULL, "Right Mixer" },
448	{ "ROUT1", NULL, "Right Out 1" },
449
450	{ "Left Out 2", NULL, "Left Mixer" },
451	{ "LOUT2", NULL, "Left Out 2" },
452	{ "Right Out 2", NULL, "Right Mixer" },
453	{ "ROUT2", NULL, "Right Out 2" },
454};
455
456static int es8328_mute(struct snd_soc_dai *dai, int mute)
457{
458	return snd_soc_component_update_bits(dai->component, ES8328_DACCONTROL3,
459			ES8328_DACCONTROL3_DACMUTE,
460			mute ? ES8328_DACCONTROL3_DACMUTE : 0);
461}
462
463static int es8328_startup(struct snd_pcm_substream *substream,
464			  struct snd_soc_dai *dai)
465{
466	struct snd_soc_component *component = dai->component;
467	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
468
469	if (es8328->master && es8328->sysclk_constraints)
470		snd_pcm_hw_constraint_list(substream->runtime, 0,
471				SNDRV_PCM_HW_PARAM_RATE,
472				es8328->sysclk_constraints);
473
474	return 0;
475}
476
477static int es8328_hw_params(struct snd_pcm_substream *substream,
478	struct snd_pcm_hw_params *params,
479	struct snd_soc_dai *dai)
480{
481	struct snd_soc_component *component = dai->component;
482	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
483	int i;
484	int reg;
485	int wl;
486	int ratio;
487
488	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
489		reg = ES8328_DACCONTROL2;
490	else
491		reg = ES8328_ADCCONTROL5;
492
493	if (es8328->master) {
494		if (!es8328->sysclk_constraints) {
495			dev_err(component->dev, "No MCLK configured\n");
496			return -EINVAL;
497		}
498
499		for (i = 0; i < es8328->sysclk_constraints->count; i++)
500			if (es8328->sysclk_constraints->list[i] ==
501			    params_rate(params))
502				break;
503
504		if (i == es8328->sysclk_constraints->count) {
505			dev_err(component->dev,
506				"LRCLK %d unsupported with current clock\n",
507				params_rate(params));
508			return -EINVAL;
509		}
510		ratio = es8328->mclk_ratios[i];
511	} else {
512		ratio = 0;
513		es8328->mclkdiv2 = 0;
514	}
515
516	snd_soc_component_update_bits(component, ES8328_MASTERMODE,
517			ES8328_MASTERMODE_MCLKDIV2,
518			es8328->mclkdiv2 ? ES8328_MASTERMODE_MCLKDIV2 : 0);
519
520	switch (params_width(params)) {
521	case 16:
522		wl = 3;
523		break;
524	case 18:
525		wl = 2;
526		break;
527	case 20:
528		wl = 1;
529		break;
530	case 24:
531		wl = 0;
532		break;
533	case 32:
534		wl = 4;
535		break;
536	default:
537		return -EINVAL;
538	}
539
540	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
541		snd_soc_component_update_bits(component, ES8328_DACCONTROL1,
542				ES8328_DACCONTROL1_DACWL_MASK,
543				wl << ES8328_DACCONTROL1_DACWL_SHIFT);
544
545		es8328->playback_fs = params_rate(params);
546		es8328_set_deemph(component);
547	} else
548		snd_soc_component_update_bits(component, ES8328_ADCCONTROL4,
549				ES8328_ADCCONTROL4_ADCWL_MASK,
550				wl << ES8328_ADCCONTROL4_ADCWL_SHIFT);
551
552	return snd_soc_component_update_bits(component, reg, ES8328_RATEMASK, ratio);
553}
554
555static int es8328_set_sysclk(struct snd_soc_dai *codec_dai,
556		int clk_id, unsigned int freq, int dir)
557{
558	struct snd_soc_component *component = codec_dai->component;
559	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
560	int mclkdiv2 = 0;
 
561
562	switch (freq) {
 
 
 
 
 
 
563	case 0:
564		es8328->sysclk_constraints = NULL;
565		es8328->mclk_ratios = NULL;
566		break;
567	case 22579200:
568		mclkdiv2 = 1;
569		/* fallthru */
570	case 11289600:
571		es8328->sysclk_constraints = &constraints_11289;
572		es8328->mclk_ratios = ratios_11289;
573		break;
574	case 24576000:
575		mclkdiv2 = 1;
576		/* fallthru */
577	case 12288000:
578		es8328->sysclk_constraints = &constraints_12288;
579		es8328->mclk_ratios = ratios_12288;
580		break;
581	default:
582		return -EINVAL;
583	}
584
585	es8328->mclkdiv2 = mclkdiv2;
586	return 0;
587}
588
589static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai,
590		unsigned int fmt)
591{
592	struct snd_soc_component *component = codec_dai->component;
593	struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
594	u8 dac_mode = 0;
595	u8 adc_mode = 0;
596
597	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
598	case SND_SOC_DAIFMT_CBM_CFM:
599		/* Master serial port mode, with BCLK generated automatically */
600		snd_soc_component_update_bits(component, ES8328_MASTERMODE,
601				    ES8328_MASTERMODE_MSC,
602				    ES8328_MASTERMODE_MSC);
603		es8328->master = true;
604		break;
605	case SND_SOC_DAIFMT_CBS_CFS:
606		/* Slave serial port mode */
607		snd_soc_component_update_bits(component, ES8328_MASTERMODE,
608				    ES8328_MASTERMODE_MSC, 0);
609		es8328->master = false;
610		break;
611	default:
612		return -EINVAL;
613	}
614
615	/* interface format */
616	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
617	case SND_SOC_DAIFMT_I2S:
618		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_I2S;
619		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_I2S;
620		break;
621	case SND_SOC_DAIFMT_RIGHT_J:
622		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_RJUST;
623		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_RJUST;
624		break;
625	case SND_SOC_DAIFMT_LEFT_J:
626		dac_mode |= ES8328_DACCONTROL1_DACFORMAT_LJUST;
627		adc_mode |= ES8328_ADCCONTROL4_ADCFORMAT_LJUST;
628		break;
629	default:
630		return -EINVAL;
631	}
632
633	/* clock inversion */
634	if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF)
635		return -EINVAL;
636
637	snd_soc_component_update_bits(component, ES8328_DACCONTROL1,
638			ES8328_DACCONTROL1_DACFORMAT_MASK, dac_mode);
639	snd_soc_component_update_bits(component, ES8328_ADCCONTROL4,
640			ES8328_ADCCONTROL4_ADCFORMAT_MASK, adc_mode);
641
642	return 0;
643}
644
645static int es8328_set_bias_level(struct snd_soc_component *component,
646				 enum snd_soc_bias_level level)
647{
648	switch (level) {
649	case SND_SOC_BIAS_ON:
650		break;
651
652	case SND_SOC_BIAS_PREPARE:
653		/* VREF, VMID=2x50k, digital enabled */
654		snd_soc_component_write(component, ES8328_CHIPPOWER, 0);
655		snd_soc_component_update_bits(component, ES8328_CONTROL1,
656				ES8328_CONTROL1_VMIDSEL_MASK |
657				ES8328_CONTROL1_ENREF,
658				ES8328_CONTROL1_VMIDSEL_50k |
659				ES8328_CONTROL1_ENREF);
660		break;
661
662	case SND_SOC_BIAS_STANDBY:
663		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
664			snd_soc_component_update_bits(component, ES8328_CONTROL1,
665					ES8328_CONTROL1_VMIDSEL_MASK |
666					ES8328_CONTROL1_ENREF,
667					ES8328_CONTROL1_VMIDSEL_5k |
668					ES8328_CONTROL1_ENREF);
669
670			/* Charge caps */
671			msleep(100);
672		}
673
674		snd_soc_component_write(component, ES8328_CONTROL2,
675				ES8328_CONTROL2_OVERCURRENT_ON |
676				ES8328_CONTROL2_THERMAL_SHUTDOWN_ON);
677
678		/* VREF, VMID=2*500k, digital stopped */
679		snd_soc_component_update_bits(component, ES8328_CONTROL1,
680				ES8328_CONTROL1_VMIDSEL_MASK |
681				ES8328_CONTROL1_ENREF,
682				ES8328_CONTROL1_VMIDSEL_500k |
683				ES8328_CONTROL1_ENREF);
684		break;
685
686	case SND_SOC_BIAS_OFF:
687		snd_soc_component_update_bits(component, ES8328_CONTROL1,
688				ES8328_CONTROL1_VMIDSEL_MASK |
689				ES8328_CONTROL1_ENREF,
690				0);
691		break;
692	}
693	return 0;
694}
695
696static const struct snd_soc_dai_ops es8328_dai_ops = {
697	.startup	= es8328_startup,
698	.hw_params	= es8328_hw_params,
699	.digital_mute	= es8328_mute,
700	.set_sysclk	= es8328_set_sysclk,
701	.set_fmt	= es8328_set_dai_fmt,
 
702};
703
704static struct snd_soc_dai_driver es8328_dai = {
705	.name = "es8328-hifi-analog",
706	.playback = {
707		.stream_name = "Playback",
708		.channels_min = 2,
709		.channels_max = 2,
710		.rates = ES8328_RATES,
711		.formats = ES8328_FORMATS,
712	},
713	.capture = {
714		.stream_name = "Capture",
715		.channels_min = 2,
716		.channels_max = 2,
717		.rates = ES8328_RATES,
718		.formats = ES8328_FORMATS,
719	},
720	.ops = &es8328_dai_ops,
721	.symmetric_rates = 1,
722};
723
724static int es8328_suspend(struct snd_soc_component *component)
725{
726	struct es8328_priv *es8328;
727	int ret;
728
729	es8328 = snd_soc_component_get_drvdata(component);
730
731	clk_disable_unprepare(es8328->clk);
732
733	ret = regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
734			es8328->supplies);
735	if (ret) {
736		dev_err(component->dev, "unable to disable regulators\n");
737		return ret;
738	}
739	return 0;
740}
741
742static int es8328_resume(struct snd_soc_component *component)
743{
744	struct regmap *regmap = dev_get_regmap(component->dev, NULL);
745	struct es8328_priv *es8328;
746	int ret;
747
748	es8328 = snd_soc_component_get_drvdata(component);
749
750	ret = clk_prepare_enable(es8328->clk);
751	if (ret) {
752		dev_err(component->dev, "unable to enable clock\n");
753		return ret;
754	}
755
756	ret = regulator_bulk_enable(ARRAY_SIZE(es8328->supplies),
757					es8328->supplies);
758	if (ret) {
759		dev_err(component->dev, "unable to enable regulators\n");
760		return ret;
761	}
762
763	regcache_mark_dirty(regmap);
764	ret = regcache_sync(regmap);
765	if (ret) {
766		dev_err(component->dev, "unable to sync regcache\n");
767		return ret;
768	}
769
770	return 0;
771}
772
773static int es8328_component_probe(struct snd_soc_component *component)
774{
775	struct es8328_priv *es8328;
776	int ret;
777
778	es8328 = snd_soc_component_get_drvdata(component);
779
780	ret = regulator_bulk_enable(ARRAY_SIZE(es8328->supplies),
781					es8328->supplies);
782	if (ret) {
783		dev_err(component->dev, "unable to enable regulators\n");
784		return ret;
785	}
786
787	/* Setup clocks */
788	es8328->clk = devm_clk_get(component->dev, NULL);
789	if (IS_ERR(es8328->clk)) {
790		dev_err(component->dev, "codec clock missing or invalid\n");
791		ret = PTR_ERR(es8328->clk);
792		goto clk_fail;
793	}
794
795	ret = clk_prepare_enable(es8328->clk);
796	if (ret) {
797		dev_err(component->dev, "unable to prepare codec clk\n");
798		goto clk_fail;
799	}
800
801	return 0;
802
803clk_fail:
804	regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
805			       es8328->supplies);
806	return ret;
807}
808
809static void es8328_remove(struct snd_soc_component *component)
810{
811	struct es8328_priv *es8328;
812
813	es8328 = snd_soc_component_get_drvdata(component);
814
815	if (es8328->clk)
816		clk_disable_unprepare(es8328->clk);
817
818	regulator_bulk_disable(ARRAY_SIZE(es8328->supplies),
819			       es8328->supplies);
820}
821
822const struct regmap_config es8328_regmap_config = {
823	.reg_bits	= 8,
824	.val_bits	= 8,
825	.max_register	= ES8328_REG_MAX,
826	.cache_type	= REGCACHE_RBTREE,
827	.use_single_rw	= true,
 
828};
829EXPORT_SYMBOL_GPL(es8328_regmap_config);
830
831static const struct snd_soc_component_driver es8328_component_driver = {
832	.probe			= es8328_component_probe,
833	.remove			= es8328_remove,
834	.suspend		= es8328_suspend,
835	.resume			= es8328_resume,
836	.set_bias_level		= es8328_set_bias_level,
837	.controls		= es8328_snd_controls,
838	.num_controls		= ARRAY_SIZE(es8328_snd_controls),
839	.dapm_widgets		= es8328_dapm_widgets,
840	.num_dapm_widgets	= ARRAY_SIZE(es8328_dapm_widgets),
841	.dapm_routes		= es8328_dapm_routes,
842	.num_dapm_routes	= ARRAY_SIZE(es8328_dapm_routes),
843	.suspend_bias_off	= 1,
844	.idle_bias_on		= 1,
845	.use_pmdown_time	= 1,
846	.endianness		= 1,
847	.non_legacy_dai_naming	= 1,
848};
849
850int es8328_probe(struct device *dev, struct regmap *regmap)
851{
852	struct es8328_priv *es8328;
853	int ret;
854	int i;
855
856	if (IS_ERR(regmap))
857		return PTR_ERR(regmap);
858
859	es8328 = devm_kzalloc(dev, sizeof(*es8328), GFP_KERNEL);
860	if (es8328 == NULL)
861		return -ENOMEM;
862
863	es8328->regmap = regmap;
864
865	for (i = 0; i < ARRAY_SIZE(es8328->supplies); i++)
866		es8328->supplies[i].supply = supply_names[i];
867
868	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(es8328->supplies),
869				es8328->supplies);
870	if (ret) {
871		dev_err(dev, "unable to get regulators\n");
872		return ret;
873	}
874
875	dev_set_drvdata(dev, es8328);
876
877	return devm_snd_soc_register_component(dev,
878			&es8328_component_driver, &es8328_dai, 1);
879}
880EXPORT_SYMBOL_GPL(es8328_probe);
881
882MODULE_DESCRIPTION("ASoC ES8328 driver");
883MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
884MODULE_LICENSE("GPL");