xref: /linux/sound/soc/codecs/wm8974.c (revision 3e32a3ff800b71c84796a89479a6ea89eee0803e)
10a1bf553SMark Brown /*
20a1bf553SMark Brown  * wm8974.c  --  WM8974 ALSA Soc Audio driver
30a1bf553SMark Brown  *
48b83a193SMark Brown  * Copyright 2006-2009 Wolfson Microelectronics PLC.
50a1bf553SMark Brown  *
69a185b9aSMark Brown  * Author: Liam Girdwood <Liam.Girdwood@wolfsonmicro.com>
70a1bf553SMark Brown  *
80a1bf553SMark Brown  * This program is free software; you can redistribute it and/or modify
90a1bf553SMark Brown  * it under the terms of the GNU General Public License version 2 as
100a1bf553SMark Brown  * published by the Free Software Foundation.
110a1bf553SMark Brown  */
120a1bf553SMark Brown 
130a1bf553SMark Brown #include <linux/module.h>
140a1bf553SMark Brown #include <linux/moduleparam.h>
150a1bf553SMark Brown #include <linux/kernel.h>
160a1bf553SMark Brown #include <linux/init.h>
170a1bf553SMark Brown #include <linux/delay.h>
180a1bf553SMark Brown #include <linux/pm.h>
190a1bf553SMark Brown #include <linux/i2c.h>
20e40e0b5dSMark Brown #include <linux/regmap.h>
215a0e3ad6STejun Heo #include <linux/slab.h>
220a1bf553SMark Brown #include <sound/core.h>
230a1bf553SMark Brown #include <sound/pcm.h>
240a1bf553SMark Brown #include <sound/pcm_params.h>
250a1bf553SMark Brown #include <sound/soc.h>
260a1bf553SMark Brown #include <sound/initval.h>
27a5f8d2f1SMark Brown #include <sound/tlv.h>
280a1bf553SMark Brown 
290a1bf553SMark Brown #include "wm8974.h"
300a1bf553SMark Brown 
3151b2bb3fSMans Rullgard struct wm8974_priv {
3251b2bb3fSMans Rullgard 	unsigned int mclk;
3351b2bb3fSMans Rullgard 	unsigned int fs;
3451b2bb3fSMans Rullgard };
3551b2bb3fSMans Rullgard 
36e40e0b5dSMark Brown static const struct reg_default wm8974_reg_defaults[] = {
37e40e0b5dSMark Brown 	{  0, 0x0000 }, {  1, 0x0000 }, {  2, 0x0000 }, {  3, 0x0000 },
38e40e0b5dSMark Brown 	{  4, 0x0050 }, {  5, 0x0000 }, {  6, 0x0140 }, {  7, 0x0000 },
39e40e0b5dSMark Brown 	{  8, 0x0000 }, {  9, 0x0000 }, { 10, 0x0000 }, { 11, 0x00ff },
40e40e0b5dSMark Brown 	{ 12, 0x0000 }, { 13, 0x0000 }, { 14, 0x0100 }, { 15, 0x00ff },
41e40e0b5dSMark Brown 	{ 16, 0x0000 }, { 17, 0x0000 }, { 18, 0x012c }, { 19, 0x002c },
42e40e0b5dSMark Brown 	{ 20, 0x002c }, { 21, 0x002c }, { 22, 0x002c }, { 23, 0x0000 },
43e40e0b5dSMark Brown 	{ 24, 0x0032 }, { 25, 0x0000 }, { 26, 0x0000 }, { 27, 0x0000 },
44e40e0b5dSMark Brown 	{ 28, 0x0000 }, { 29, 0x0000 }, { 30, 0x0000 }, { 31, 0x0000 },
45e40e0b5dSMark Brown 	{ 32, 0x0038 }, { 33, 0x000b }, { 34, 0x0032 }, { 35, 0x0000 },
46e40e0b5dSMark Brown 	{ 36, 0x0008 }, { 37, 0x000c }, { 38, 0x0093 }, { 39, 0x00e9 },
47e40e0b5dSMark Brown 	{ 40, 0x0000 }, { 41, 0x0000 }, { 42, 0x0000 }, { 43, 0x0000 },
48e40e0b5dSMark Brown 	{ 44, 0x0003 }, { 45, 0x0010 }, { 46, 0x0000 }, { 47, 0x0000 },
49e40e0b5dSMark Brown 	{ 48, 0x0000 }, { 49, 0x0002 }, { 50, 0x0000 }, { 51, 0x0000 },
50e40e0b5dSMark Brown 	{ 52, 0x0000 }, { 53, 0x0000 }, { 54, 0x0039 }, { 55, 0x0000 },
51e40e0b5dSMark Brown 	{ 56, 0x0000 },
520a1bf553SMark Brown };
530a1bf553SMark Brown 
54df1ef7a3SMark Brown #define WM8974_POWER1_BIASEN  0x08
5548c03ce7SGuennadi Liakhovetski #define WM8974_POWER1_BUFIOEN 0x04
56df1ef7a3SMark Brown 
57*3e32a3ffSKuninori Morimoto #define wm8974_reset(c)	snd_soc_component_write(c, WM8974_RESET, 0)
580a1bf553SMark Brown 
590a1bf553SMark Brown static const char *wm8974_companding[] = {"Off", "NC", "u-law", "A-law" };
600a1bf553SMark Brown static const char *wm8974_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz" };
610a1bf553SMark Brown static const char *wm8974_eqmode[] = {"Capture", "Playback" };
620a1bf553SMark Brown static const char *wm8974_bw[] = {"Narrow", "Wide" };
630a1bf553SMark Brown static const char *wm8974_eq1[] = {"80Hz", "105Hz", "135Hz", "175Hz" };
640a1bf553SMark Brown static const char *wm8974_eq2[] = {"230Hz", "300Hz", "385Hz", "500Hz" };
650a1bf553SMark Brown static const char *wm8974_eq3[] = {"650Hz", "850Hz", "1.1kHz", "1.4kHz" };
660a1bf553SMark Brown static const char *wm8974_eq4[] = {"1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz" };
670a1bf553SMark Brown static const char *wm8974_eq5[] = {"5.3kHz", "6.9kHz", "9kHz", "11.7kHz" };
680a1bf553SMark Brown static const char *wm8974_alc[] = {"ALC", "Limiter" };
690a1bf553SMark Brown 
700a1bf553SMark Brown static const struct soc_enum wm8974_enum[] = {
710a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_COMP, 1, 4, wm8974_companding), /* adc */
720a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_COMP, 3, 4, wm8974_companding), /* dac */
730a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_DAC,  4, 4, wm8974_deemp),
740a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ1,  8, 2, wm8974_eqmode),
750a1bf553SMark Brown 
760a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ1,  5, 4, wm8974_eq1),
770a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ2,  8, 2, wm8974_bw),
780a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ2,  5, 4, wm8974_eq2),
790a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ3,  8, 2, wm8974_bw),
800a1bf553SMark Brown 
810a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ3,  5, 4, wm8974_eq3),
820a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ4,  8, 2, wm8974_bw),
830a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ4,  5, 4, wm8974_eq4),
840a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ5,  8, 2, wm8974_bw),
850a1bf553SMark Brown 
860a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_EQ5,  5, 4, wm8974_eq5),
870a1bf553SMark Brown 	SOC_ENUM_SINGLE(WM8974_ALC3,  8, 2, wm8974_alc),
880a1bf553SMark Brown };
890a1bf553SMark Brown 
908a123ee2SMark Brown static const char *wm8974_auxmode_text[] = { "Buffer", "Mixer" };
918a123ee2SMark Brown 
92de461bd2STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8974_auxmode,
93de461bd2STakashi Iwai 			    WM8974_INPUT,  3, wm8974_auxmode_text);
948a123ee2SMark Brown 
95a5f8d2f1SMark Brown static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1);
96a5f8d2f1SMark Brown static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
97a5f8d2f1SMark Brown static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1200, 75, 0);
98a5f8d2f1SMark Brown static const DECLARE_TLV_DB_SCALE(spk_tlv, -5700, 100, 0);
99a5f8d2f1SMark Brown 
1000a1bf553SMark Brown static const struct snd_kcontrol_new wm8974_snd_controls[] = {
1010a1bf553SMark Brown 
1020a1bf553SMark Brown SOC_SINGLE("Digital Loopback Switch", WM8974_COMP, 0, 1, 0),
1030a1bf553SMark Brown 
1040a1bf553SMark Brown SOC_ENUM("DAC Companding", wm8974_enum[1]),
1050a1bf553SMark Brown SOC_ENUM("ADC Companding", wm8974_enum[0]),
1060a1bf553SMark Brown 
1070a1bf553SMark Brown SOC_ENUM("Playback De-emphasis", wm8974_enum[2]),
1080a1bf553SMark Brown SOC_SINGLE("DAC Inversion Switch", WM8974_DAC, 0, 1, 0),
1090a1bf553SMark Brown 
110a5f8d2f1SMark Brown SOC_SINGLE_TLV("PCM Volume", WM8974_DACVOL, 0, 255, 0, digital_tlv),
1110a1bf553SMark Brown 
1120a1bf553SMark Brown SOC_SINGLE("High Pass Filter Switch", WM8974_ADC, 8, 1, 0),
1130a1bf553SMark Brown SOC_SINGLE("High Pass Cut Off", WM8974_ADC, 4, 7, 0),
11425cbf465Sjavier Martin SOC_SINGLE("ADC Inversion Switch", WM8974_ADC, 0, 1, 0),
1150a1bf553SMark Brown 
116a5f8d2f1SMark Brown SOC_SINGLE_TLV("Capture Volume", WM8974_ADCVOL,  0, 255, 0, digital_tlv),
1170a1bf553SMark Brown 
1180a1bf553SMark Brown SOC_ENUM("Equaliser Function", wm8974_enum[3]),
1190a1bf553SMark Brown SOC_ENUM("EQ1 Cut Off", wm8974_enum[4]),
120a5f8d2f1SMark Brown SOC_SINGLE_TLV("EQ1 Volume", WM8974_EQ1,  0, 24, 1, eq_tlv),
1210a1bf553SMark Brown 
122c46d5c04SMasanari Iida SOC_ENUM("Equaliser EQ2 Bandwidth", wm8974_enum[5]),
1230a1bf553SMark Brown SOC_ENUM("EQ2 Cut Off", wm8974_enum[6]),
124a5f8d2f1SMark Brown SOC_SINGLE_TLV("EQ2 Volume", WM8974_EQ2,  0, 24, 1, eq_tlv),
1250a1bf553SMark Brown 
126c46d5c04SMasanari Iida SOC_ENUM("Equaliser EQ3 Bandwidth", wm8974_enum[7]),
1270a1bf553SMark Brown SOC_ENUM("EQ3 Cut Off", wm8974_enum[8]),
128a5f8d2f1SMark Brown SOC_SINGLE_TLV("EQ3 Volume", WM8974_EQ3,  0, 24, 1, eq_tlv),
1290a1bf553SMark Brown 
130c46d5c04SMasanari Iida SOC_ENUM("Equaliser EQ4 Bandwidth", wm8974_enum[9]),
1310a1bf553SMark Brown SOC_ENUM("EQ4 Cut Off", wm8974_enum[10]),
132a5f8d2f1SMark Brown SOC_SINGLE_TLV("EQ4 Volume", WM8974_EQ4,  0, 24, 1, eq_tlv),
1330a1bf553SMark Brown 
134a895d57dSMasanari Iida SOC_ENUM("Equaliser EQ5 Bandwidth", wm8974_enum[11]),
1350a1bf553SMark Brown SOC_ENUM("EQ5 Cut Off", wm8974_enum[12]),
136a5f8d2f1SMark Brown SOC_SINGLE_TLV("EQ5 Volume", WM8974_EQ5,  0, 24, 1, eq_tlv),
1370a1bf553SMark Brown 
1380a1bf553SMark Brown SOC_SINGLE("DAC Playback Limiter Switch", WM8974_DACLIM1,  8, 1, 0),
1390a1bf553SMark Brown SOC_SINGLE("DAC Playback Limiter Decay", WM8974_DACLIM1,  4, 15, 0),
1400a1bf553SMark Brown SOC_SINGLE("DAC Playback Limiter Attack", WM8974_DACLIM1,  0, 15, 0),
1410a1bf553SMark Brown 
1420a1bf553SMark Brown SOC_SINGLE("DAC Playback Limiter Threshold", WM8974_DACLIM2,  4, 7, 0),
1430a1bf553SMark Brown SOC_SINGLE("DAC Playback Limiter Boost", WM8974_DACLIM2,  0, 15, 0),
1440a1bf553SMark Brown 
1450a1bf553SMark Brown SOC_SINGLE("ALC Enable Switch", WM8974_ALC1,  8, 1, 0),
1460a1bf553SMark Brown SOC_SINGLE("ALC Capture Max Gain", WM8974_ALC1,  3, 7, 0),
1470a1bf553SMark Brown SOC_SINGLE("ALC Capture Min Gain", WM8974_ALC1,  0, 7, 0),
1480a1bf553SMark Brown 
1490a1bf553SMark Brown SOC_SINGLE("ALC Capture ZC Switch", WM8974_ALC2,  8, 1, 0),
1500a1bf553SMark Brown SOC_SINGLE("ALC Capture Hold", WM8974_ALC2,  4, 7, 0),
1510a1bf553SMark Brown SOC_SINGLE("ALC Capture Target", WM8974_ALC2,  0, 15, 0),
1520a1bf553SMark Brown 
1530a1bf553SMark Brown SOC_ENUM("ALC Capture Mode", wm8974_enum[13]),
1540a1bf553SMark Brown SOC_SINGLE("ALC Capture Decay", WM8974_ALC3,  4, 15, 0),
1550a1bf553SMark Brown SOC_SINGLE("ALC Capture Attack", WM8974_ALC3,  0, 15, 0),
1560a1bf553SMark Brown 
1570a1bf553SMark Brown SOC_SINGLE("ALC Capture Noise Gate Switch", WM8974_NGATE,  3, 1, 0),
1580a1bf553SMark Brown SOC_SINGLE("ALC Capture Noise Gate Threshold", WM8974_NGATE,  0, 7, 0),
1590a1bf553SMark Brown 
1600a1bf553SMark Brown SOC_SINGLE("Capture PGA ZC Switch", WM8974_INPPGA,  7, 1, 0),
161a5f8d2f1SMark Brown SOC_SINGLE_TLV("Capture PGA Volume", WM8974_INPPGA,  0, 63, 0, inpga_tlv),
1620a1bf553SMark Brown 
1630a1bf553SMark Brown SOC_SINGLE("Speaker Playback ZC Switch", WM8974_SPKVOL,  7, 1, 0),
1640a1bf553SMark Brown SOC_SINGLE("Speaker Playback Switch", WM8974_SPKVOL,  6, 1, 1),
1658a123ee2SMark Brown SOC_SINGLE_TLV("Speaker Playback Volume", WM8974_SPKVOL,  0, 63, 0, spk_tlv),
1668a123ee2SMark Brown 
1678a123ee2SMark Brown SOC_ENUM("Aux Mode", wm8974_auxmode),
1680a1bf553SMark Brown 
1690a1bf553SMark Brown SOC_SINGLE("Capture Boost(+20dB)", WM8974_ADCBOOST,  8, 1, 0),
1708a123ee2SMark Brown SOC_SINGLE("Mono Playback Switch", WM8974_MONOMIX, 6, 1, 1),
171b2c3e923SGuennadi Liakhovetski 
172b2c3e923SGuennadi Liakhovetski /* DAC / ADC oversampling */
173b2c3e923SGuennadi Liakhovetski SOC_SINGLE("DAC 128x Oversampling Switch", WM8974_DAC, 8, 1, 0),
174b2c3e923SGuennadi Liakhovetski SOC_SINGLE("ADC 128x Oversampling Switch", WM8974_ADC, 8, 1, 0),
1750a1bf553SMark Brown };
1760a1bf553SMark Brown 
1770a1bf553SMark Brown /* Speaker Output Mixer */
1780a1bf553SMark Brown static const struct snd_kcontrol_new wm8974_speaker_mixer_controls[] = {
1790a1bf553SMark Brown SOC_DAPM_SINGLE("Line Bypass Switch", WM8974_SPKMIX, 1, 1, 0),
1800a1bf553SMark Brown SOC_DAPM_SINGLE("Aux Playback Switch", WM8974_SPKMIX, 5, 1, 0),
181759512fbSMark Brown SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_SPKMIX, 0, 1, 0),
1820a1bf553SMark Brown };
1830a1bf553SMark Brown 
1840a1bf553SMark Brown /* Mono Output Mixer */
1850a1bf553SMark Brown static const struct snd_kcontrol_new wm8974_mono_mixer_controls[] = {
1860a1bf553SMark Brown SOC_DAPM_SINGLE("Line Bypass Switch", WM8974_MONOMIX, 1, 1, 0),
1870a1bf553SMark Brown SOC_DAPM_SINGLE("Aux Playback Switch", WM8974_MONOMIX, 2, 1, 0),
1888a123ee2SMark Brown SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_MONOMIX, 0, 1, 0),
1898a123ee2SMark Brown };
1908a123ee2SMark Brown 
1918a123ee2SMark Brown /* Boost mixer */
1928a123ee2SMark Brown static const struct snd_kcontrol_new wm8974_boost_mixer[] = {
1938a123ee2SMark Brown SOC_DAPM_SINGLE("Aux Switch", WM8974_INPPGA, 6, 1, 0),
1948a123ee2SMark Brown };
1958a123ee2SMark Brown 
1968a123ee2SMark Brown /* Input PGA */
1978a123ee2SMark Brown static const struct snd_kcontrol_new wm8974_inpga[] = {
1988a123ee2SMark Brown SOC_DAPM_SINGLE("Aux Switch", WM8974_INPUT, 2, 1, 0),
1998a123ee2SMark Brown SOC_DAPM_SINGLE("MicN Switch", WM8974_INPUT, 1, 1, 0),
2008a123ee2SMark Brown SOC_DAPM_SINGLE("MicP Switch", WM8974_INPUT, 0, 1, 0),
2010a1bf553SMark Brown };
2020a1bf553SMark Brown 
2030a1bf553SMark Brown /* AUX Input boost vol */
2040a1bf553SMark Brown static const struct snd_kcontrol_new wm8974_aux_boost_controls =
2050a1bf553SMark Brown SOC_DAPM_SINGLE("Aux Volume", WM8974_ADCBOOST, 0, 7, 0);
2060a1bf553SMark Brown 
2070a1bf553SMark Brown /* Mic Input boost vol */
2080a1bf553SMark Brown static const struct snd_kcontrol_new wm8974_mic_boost_controls =
2090a1bf553SMark Brown SOC_DAPM_SINGLE("Mic Volume", WM8974_ADCBOOST, 4, 7, 0);
2100a1bf553SMark Brown 
2110a1bf553SMark Brown static const struct snd_soc_dapm_widget wm8974_dapm_widgets[] = {
2120a1bf553SMark Brown SND_SOC_DAPM_MIXER("Speaker Mixer", WM8974_POWER3, 2, 0,
2130a1bf553SMark Brown 	&wm8974_speaker_mixer_controls[0],
2140a1bf553SMark Brown 	ARRAY_SIZE(wm8974_speaker_mixer_controls)),
2150a1bf553SMark Brown SND_SOC_DAPM_MIXER("Mono Mixer", WM8974_POWER3, 3, 0,
2160a1bf553SMark Brown 	&wm8974_mono_mixer_controls[0],
2170a1bf553SMark Brown 	ARRAY_SIZE(wm8974_mono_mixer_controls)),
2180a1bf553SMark Brown SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8974_POWER3, 0, 0),
2198a123ee2SMark Brown SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8974_POWER2, 0, 0),
2200a1bf553SMark Brown SND_SOC_DAPM_PGA("Aux Input", WM8974_POWER1, 6, 0, NULL, 0),
2210a1bf553SMark Brown SND_SOC_DAPM_PGA("SpkN Out", WM8974_POWER3, 5, 0, NULL, 0),
2220a1bf553SMark Brown SND_SOC_DAPM_PGA("SpkP Out", WM8974_POWER3, 6, 0, NULL, 0),
2230a1bf553SMark Brown SND_SOC_DAPM_PGA("Mono Out", WM8974_POWER3, 7, 0, NULL, 0),
2240a1bf553SMark Brown 
2258a123ee2SMark Brown SND_SOC_DAPM_MIXER("Input PGA", WM8974_POWER2, 2, 0, wm8974_inpga,
2268a123ee2SMark Brown 		   ARRAY_SIZE(wm8974_inpga)),
2278a123ee2SMark Brown SND_SOC_DAPM_MIXER("Boost Mixer", WM8974_POWER2, 4, 0,
2288a123ee2SMark Brown 		   wm8974_boost_mixer, ARRAY_SIZE(wm8974_boost_mixer)),
2290a1bf553SMark Brown 
23048dd231bSMark Brown SND_SOC_DAPM_SUPPLY("Mic Bias", WM8974_POWER1, 4, 0, NULL, 0),
2310a1bf553SMark Brown 
2320a1bf553SMark Brown SND_SOC_DAPM_INPUT("MICN"),
2330a1bf553SMark Brown SND_SOC_DAPM_INPUT("MICP"),
2340a1bf553SMark Brown SND_SOC_DAPM_INPUT("AUX"),
2350a1bf553SMark Brown SND_SOC_DAPM_OUTPUT("MONOOUT"),
2360a1bf553SMark Brown SND_SOC_DAPM_OUTPUT("SPKOUTP"),
2370a1bf553SMark Brown SND_SOC_DAPM_OUTPUT("SPKOUTN"),
2380a1bf553SMark Brown };
2390a1bf553SMark Brown 
240a2bd691cSMark Brown static const struct snd_soc_dapm_route wm8974_dapm_routes[] = {
2410a1bf553SMark Brown 	/* Mono output mixer */
2420a1bf553SMark Brown 	{"Mono Mixer", "PCM Playback Switch", "DAC"},
2430a1bf553SMark Brown 	{"Mono Mixer", "Aux Playback Switch", "Aux Input"},
2440a1bf553SMark Brown 	{"Mono Mixer", "Line Bypass Switch", "Boost Mixer"},
2450a1bf553SMark Brown 
2460a1bf553SMark Brown 	/* Speaker output mixer */
2470a1bf553SMark Brown 	{"Speaker Mixer", "PCM Playback Switch", "DAC"},
2480a1bf553SMark Brown 	{"Speaker Mixer", "Aux Playback Switch", "Aux Input"},
2490a1bf553SMark Brown 	{"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"},
2500a1bf553SMark Brown 
2510a1bf553SMark Brown 	/* Outputs */
2520a1bf553SMark Brown 	{"Mono Out", NULL, "Mono Mixer"},
2530a1bf553SMark Brown 	{"MONOOUT", NULL, "Mono Out"},
2540a1bf553SMark Brown 	{"SpkN Out", NULL, "Speaker Mixer"},
2550a1bf553SMark Brown 	{"SpkP Out", NULL, "Speaker Mixer"},
2560a1bf553SMark Brown 	{"SPKOUTN", NULL, "SpkN Out"},
2570a1bf553SMark Brown 	{"SPKOUTP", NULL, "SpkP Out"},
2580a1bf553SMark Brown 
2590a1bf553SMark Brown 	/* Boost Mixer */
2608a123ee2SMark Brown 	{"ADC", NULL, "Boost Mixer"},
2618a123ee2SMark Brown 	{"Boost Mixer", "Aux Switch", "Aux Input"},
2628a123ee2SMark Brown 	{"Boost Mixer", NULL, "Input PGA"},
2638a123ee2SMark Brown 	{"Boost Mixer", NULL, "MICP"},
2648a123ee2SMark Brown 
2658a123ee2SMark Brown 	/* Input PGA */
2668a123ee2SMark Brown 	{"Input PGA", "Aux Switch", "Aux Input"},
2678a123ee2SMark Brown 	{"Input PGA", "MicN Switch", "MICN"},
2688a123ee2SMark Brown 	{"Input PGA", "MicP Switch", "MICP"},
2690a1bf553SMark Brown 
2700a1bf553SMark Brown 	/* Inputs */
2718a123ee2SMark Brown 	{"Aux Input", NULL, "AUX"},
2720a1bf553SMark Brown };
2730a1bf553SMark Brown 
2740a1bf553SMark Brown struct pll_ {
275c36b2fc7SMark Brown 	unsigned int pre_div:1;
2760a1bf553SMark Brown 	unsigned int n:4;
2770a1bf553SMark Brown 	unsigned int k;
2780a1bf553SMark Brown };
2790a1bf553SMark Brown 
28091d0c3ecSMark Brown /* The size in bits of the pll divide multiplied by 10
28191d0c3ecSMark Brown  * to allow rounding later */
28291d0c3ecSMark Brown #define FIXED_PLL_SIZE ((1 << 24) * 10)
28391d0c3ecSMark Brown 
284c36b2fc7SMark Brown static void pll_factors(struct pll_ *pll_div,
285c36b2fc7SMark Brown 			unsigned int target, unsigned int source)
28691d0c3ecSMark Brown {
28791d0c3ecSMark Brown 	unsigned long long Kpart;
28891d0c3ecSMark Brown 	unsigned int K, Ndiv, Nmod;
28991d0c3ecSMark Brown 
290c36b2fc7SMark Brown 	/* There is a fixed divide by 4 in the output path */
291c36b2fc7SMark Brown 	target *= 4;
292c36b2fc7SMark Brown 
29391d0c3ecSMark Brown 	Ndiv = target / source;
29491d0c3ecSMark Brown 	if (Ndiv < 6) {
295c36b2fc7SMark Brown 		source /= 2;
296c36b2fc7SMark Brown 		pll_div->pre_div = 1;
29791d0c3ecSMark Brown 		Ndiv = target / source;
29891d0c3ecSMark Brown 	} else
299c36b2fc7SMark Brown 		pll_div->pre_div = 0;
30091d0c3ecSMark Brown 
30191d0c3ecSMark Brown 	if ((Ndiv < 6) || (Ndiv > 12))
30291d0c3ecSMark Brown 		printk(KERN_WARNING
3038b83a193SMark Brown 			"WM8974 N value %u outwith recommended range!\n",
30491d0c3ecSMark Brown 			Ndiv);
30591d0c3ecSMark Brown 
306c36b2fc7SMark Brown 	pll_div->n = Ndiv;
30791d0c3ecSMark Brown 	Nmod = target % source;
30891d0c3ecSMark Brown 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
30991d0c3ecSMark Brown 
31091d0c3ecSMark Brown 	do_div(Kpart, source);
31191d0c3ecSMark Brown 
31291d0c3ecSMark Brown 	K = Kpart & 0xFFFFFFFF;
31391d0c3ecSMark Brown 
31491d0c3ecSMark Brown 	/* Check if we need to round */
31591d0c3ecSMark Brown 	if ((K % 10) >= 5)
31691d0c3ecSMark Brown 		K += 5;
31791d0c3ecSMark Brown 
31891d0c3ecSMark Brown 	/* Move down to proper range now rounding is done */
31991d0c3ecSMark Brown 	K /= 10;
32091d0c3ecSMark Brown 
321c36b2fc7SMark Brown 	pll_div->k = K;
32291d0c3ecSMark Brown }
3230a1bf553SMark Brown 
32485488037SMark Brown static int wm8974_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
32585488037SMark Brown 		int source, unsigned int freq_in, unsigned int freq_out)
3260a1bf553SMark Brown {
327*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
328c36b2fc7SMark Brown 	struct pll_ pll_div;
3290a1bf553SMark Brown 	u16 reg;
3300a1bf553SMark Brown 
3310a1bf553SMark Brown 	if (freq_in == 0 || freq_out == 0) {
33291d0c3ecSMark Brown 		/* Clock CODEC directly from MCLK */
333*3e32a3ffSKuninori Morimoto 		reg = snd_soc_component_read32(component, WM8974_CLOCK);
334*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_CLOCK, reg & 0x0ff);
33591d0c3ecSMark Brown 
33691d0c3ecSMark Brown 		/* Turn off PLL */
337*3e32a3ffSKuninori Morimoto 		reg = snd_soc_component_read32(component, WM8974_POWER1);
338*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER1, reg & 0x1df);
3390a1bf553SMark Brown 		return 0;
3400a1bf553SMark Brown 	}
3410a1bf553SMark Brown 
342c36b2fc7SMark Brown 	pll_factors(&pll_div, freq_out, freq_in);
34391d0c3ecSMark Brown 
344*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_PLLN, (pll_div.pre_div << 4) | pll_div.n);
345*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_PLLK1, pll_div.k >> 18);
346*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_PLLK2, (pll_div.k >> 9) & 0x1ff);
347*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_PLLK3, pll_div.k & 0x1ff);
348*3e32a3ffSKuninori Morimoto 	reg = snd_soc_component_read32(component, WM8974_POWER1);
349*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_POWER1, reg | 0x020);
3501a55b3f6SMark Brown 
35191d0c3ecSMark Brown 	/* Run CODEC from PLL instead of MCLK */
352*3e32a3ffSKuninori Morimoto 	reg = snd_soc_component_read32(component, WM8974_CLOCK);
353*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_CLOCK, reg | 0x100);
35491d0c3ecSMark Brown 
35591d0c3ecSMark Brown 	return 0;
3560a1bf553SMark Brown }
3570a1bf553SMark Brown 
3580a1bf553SMark Brown /*
3590a1bf553SMark Brown  * Configure WM8974 clock dividers.
3600a1bf553SMark Brown  */
3610a1bf553SMark Brown static int wm8974_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
3620a1bf553SMark Brown 		int div_id, int div)
3630a1bf553SMark Brown {
364*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
3650a1bf553SMark Brown 	u16 reg;
3660a1bf553SMark Brown 
3670a1bf553SMark Brown 	switch (div_id) {
3680a1bf553SMark Brown 	case WM8974_OPCLKDIV:
369*3e32a3ffSKuninori Morimoto 		reg = snd_soc_component_read32(component, WM8974_GPIO) & 0x1cf;
370*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_GPIO, reg | div);
3710a1bf553SMark Brown 		break;
3720a1bf553SMark Brown 	case WM8974_MCLKDIV:
373*3e32a3ffSKuninori Morimoto 		reg = snd_soc_component_read32(component, WM8974_CLOCK) & 0x11f;
374*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_CLOCK, reg | div);
3750a1bf553SMark Brown 		break;
3760a1bf553SMark Brown 	case WM8974_BCLKDIV:
377*3e32a3ffSKuninori Morimoto 		reg = snd_soc_component_read32(component, WM8974_CLOCK) & 0x1e3;
378*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_CLOCK, reg | div);
3790a1bf553SMark Brown 		break;
3800a1bf553SMark Brown 	default:
3810a1bf553SMark Brown 		return -EINVAL;
3820a1bf553SMark Brown 	}
3830a1bf553SMark Brown 
3840a1bf553SMark Brown 	return 0;
3850a1bf553SMark Brown }
3860a1bf553SMark Brown 
38751b2bb3fSMans Rullgard static unsigned int wm8974_get_mclkdiv(unsigned int f_in, unsigned int f_out,
38851b2bb3fSMans Rullgard 				       int *mclkdiv)
38951b2bb3fSMans Rullgard {
39051b2bb3fSMans Rullgard 	unsigned int ratio = 2 * f_in / f_out;
39151b2bb3fSMans Rullgard 
39251b2bb3fSMans Rullgard 	if (ratio <= 2) {
39351b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_1;
39451b2bb3fSMans Rullgard 		ratio = 2;
39551b2bb3fSMans Rullgard 	} else if (ratio == 3) {
39651b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_1_5;
39751b2bb3fSMans Rullgard 	} else if (ratio == 4) {
39851b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_2;
39951b2bb3fSMans Rullgard 	} else if (ratio <= 6) {
40051b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_3;
40151b2bb3fSMans Rullgard 		ratio = 6;
40251b2bb3fSMans Rullgard 	} else if (ratio <= 8) {
40351b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_4;
40451b2bb3fSMans Rullgard 		ratio = 8;
40551b2bb3fSMans Rullgard 	} else if (ratio <= 12) {
40651b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_6;
40751b2bb3fSMans Rullgard 		ratio = 12;
40851b2bb3fSMans Rullgard 	} else if (ratio <= 16) {
40951b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_8;
41051b2bb3fSMans Rullgard 		ratio = 16;
41151b2bb3fSMans Rullgard 	} else {
41251b2bb3fSMans Rullgard 		*mclkdiv = WM8974_MCLKDIV_12;
41351b2bb3fSMans Rullgard 		ratio = 24;
41451b2bb3fSMans Rullgard 	}
41551b2bb3fSMans Rullgard 
41651b2bb3fSMans Rullgard 	return f_out * ratio / 2;
41751b2bb3fSMans Rullgard }
41851b2bb3fSMans Rullgard 
41951b2bb3fSMans Rullgard static int wm8974_update_clocks(struct snd_soc_dai *dai)
42051b2bb3fSMans Rullgard {
421*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
422*3e32a3ffSKuninori Morimoto 	struct wm8974_priv *priv = snd_soc_component_get_drvdata(component);
42351b2bb3fSMans Rullgard 	unsigned int fs256;
42451b2bb3fSMans Rullgard 	unsigned int fpll = 0;
42551b2bb3fSMans Rullgard 	unsigned int f;
42651b2bb3fSMans Rullgard 	int mclkdiv;
42751b2bb3fSMans Rullgard 
42851b2bb3fSMans Rullgard 	if (!priv->mclk || !priv->fs)
42951b2bb3fSMans Rullgard 		return 0;
43051b2bb3fSMans Rullgard 
43151b2bb3fSMans Rullgard 	fs256 = 256 * priv->fs;
43251b2bb3fSMans Rullgard 
43351b2bb3fSMans Rullgard 	f = wm8974_get_mclkdiv(priv->mclk, fs256, &mclkdiv);
43451b2bb3fSMans Rullgard 
43551b2bb3fSMans Rullgard 	if (f != priv->mclk) {
43651b2bb3fSMans Rullgard 		/* The PLL performs best around 90MHz */
43751b2bb3fSMans Rullgard 		fpll = wm8974_get_mclkdiv(22500000, fs256, &mclkdiv);
43851b2bb3fSMans Rullgard 	}
43951b2bb3fSMans Rullgard 
44051b2bb3fSMans Rullgard 	wm8974_set_dai_pll(dai, 0, 0, priv->mclk, fpll);
44151b2bb3fSMans Rullgard 	wm8974_set_dai_clkdiv(dai, WM8974_MCLKDIV, mclkdiv);
44251b2bb3fSMans Rullgard 
44351b2bb3fSMans Rullgard 	return 0;
44451b2bb3fSMans Rullgard }
44551b2bb3fSMans Rullgard 
44651b2bb3fSMans Rullgard static int wm8974_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
44751b2bb3fSMans Rullgard 				 unsigned int freq, int dir)
44851b2bb3fSMans Rullgard {
449*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
450*3e32a3ffSKuninori Morimoto 	struct wm8974_priv *priv = snd_soc_component_get_drvdata(component);
45151b2bb3fSMans Rullgard 
45251b2bb3fSMans Rullgard 	if (dir != SND_SOC_CLOCK_IN)
45351b2bb3fSMans Rullgard 		return -EINVAL;
45451b2bb3fSMans Rullgard 
45551b2bb3fSMans Rullgard 	priv->mclk = freq;
45651b2bb3fSMans Rullgard 
45751b2bb3fSMans Rullgard 	return wm8974_update_clocks(dai);
45851b2bb3fSMans Rullgard }
45951b2bb3fSMans Rullgard 
4600a1bf553SMark Brown static int wm8974_set_dai_fmt(struct snd_soc_dai *codec_dai,
4610a1bf553SMark Brown 		unsigned int fmt)
4620a1bf553SMark Brown {
463*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
4640a1bf553SMark Brown 	u16 iface = 0;
465*3e32a3ffSKuninori Morimoto 	u16 clk = snd_soc_component_read32(component, WM8974_CLOCK) & 0x1fe;
4660a1bf553SMark Brown 
4670a1bf553SMark Brown 	/* set master/slave audio interface */
4680a1bf553SMark Brown 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4690a1bf553SMark Brown 	case SND_SOC_DAIFMT_CBM_CFM:
4700a1bf553SMark Brown 		clk |= 0x0001;
4710a1bf553SMark Brown 		break;
4720a1bf553SMark Brown 	case SND_SOC_DAIFMT_CBS_CFS:
4730a1bf553SMark Brown 		break;
4740a1bf553SMark Brown 	default:
4750a1bf553SMark Brown 		return -EINVAL;
4760a1bf553SMark Brown 	}
4770a1bf553SMark Brown 
4780a1bf553SMark Brown 	/* interface format */
4790a1bf553SMark Brown 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
4800a1bf553SMark Brown 	case SND_SOC_DAIFMT_I2S:
4810a1bf553SMark Brown 		iface |= 0x0010;
4820a1bf553SMark Brown 		break;
4830a1bf553SMark Brown 	case SND_SOC_DAIFMT_RIGHT_J:
4840a1bf553SMark Brown 		break;
4850a1bf553SMark Brown 	case SND_SOC_DAIFMT_LEFT_J:
4860a1bf553SMark Brown 		iface |= 0x0008;
4870a1bf553SMark Brown 		break;
4880a1bf553SMark Brown 	case SND_SOC_DAIFMT_DSP_A:
4890a1bf553SMark Brown 		iface |= 0x00018;
4900a1bf553SMark Brown 		break;
4910a1bf553SMark Brown 	default:
4920a1bf553SMark Brown 		return -EINVAL;
4930a1bf553SMark Brown 	}
4940a1bf553SMark Brown 
4950a1bf553SMark Brown 	/* clock inversion */
4960a1bf553SMark Brown 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
4970a1bf553SMark Brown 	case SND_SOC_DAIFMT_NB_NF:
4980a1bf553SMark Brown 		break;
4990a1bf553SMark Brown 	case SND_SOC_DAIFMT_IB_IF:
5000a1bf553SMark Brown 		iface |= 0x0180;
5010a1bf553SMark Brown 		break;
5020a1bf553SMark Brown 	case SND_SOC_DAIFMT_IB_NF:
5030a1bf553SMark Brown 		iface |= 0x0100;
5040a1bf553SMark Brown 		break;
5050a1bf553SMark Brown 	case SND_SOC_DAIFMT_NB_IF:
5060a1bf553SMark Brown 		iface |= 0x0080;
5070a1bf553SMark Brown 		break;
5080a1bf553SMark Brown 	default:
5090a1bf553SMark Brown 		return -EINVAL;
5100a1bf553SMark Brown 	}
5110a1bf553SMark Brown 
512*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_IFACE, iface);
513*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_CLOCK, clk);
5140a1bf553SMark Brown 	return 0;
5150a1bf553SMark Brown }
5160a1bf553SMark Brown 
5170a1bf553SMark Brown static int wm8974_pcm_hw_params(struct snd_pcm_substream *substream,
5180a1bf553SMark Brown 				struct snd_pcm_hw_params *params,
5190a1bf553SMark Brown 				struct snd_soc_dai *dai)
5200a1bf553SMark Brown {
521*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
522*3e32a3ffSKuninori Morimoto 	struct wm8974_priv *priv = snd_soc_component_get_drvdata(component);
523*3e32a3ffSKuninori Morimoto 	u16 iface = snd_soc_component_read32(component, WM8974_IFACE) & 0x19f;
524*3e32a3ffSKuninori Morimoto 	u16 adn = snd_soc_component_read32(component, WM8974_ADD) & 0x1f1;
52551b2bb3fSMans Rullgard 	int err;
52651b2bb3fSMans Rullgard 
52751b2bb3fSMans Rullgard 	priv->fs = params_rate(params);
52851b2bb3fSMans Rullgard 	err = wm8974_update_clocks(dai);
52951b2bb3fSMans Rullgard 	if (err)
53051b2bb3fSMans Rullgard 		return err;
5310a1bf553SMark Brown 
5320a1bf553SMark Brown 	/* bit size */
5336afdc9a0SMark Brown 	switch (params_width(params)) {
5346afdc9a0SMark Brown 	case 16:
5350a1bf553SMark Brown 		break;
5366afdc9a0SMark Brown 	case 20:
5370a1bf553SMark Brown 		iface |= 0x0020;
5380a1bf553SMark Brown 		break;
5396afdc9a0SMark Brown 	case 24:
5400a1bf553SMark Brown 		iface |= 0x0040;
5410a1bf553SMark Brown 		break;
5426afdc9a0SMark Brown 	case 32:
5430a1bf553SMark Brown 		iface |= 0x0060;
5440a1bf553SMark Brown 		break;
5450a1bf553SMark Brown 	}
5460a1bf553SMark Brown 
5470a1bf553SMark Brown 	/* filter coefficient */
5480a1bf553SMark Brown 	switch (params_rate(params)) {
549b3172f22SGuennadi Liakhovetski 	case 8000:
5500a1bf553SMark Brown 		adn |= 0x5 << 1;
5510a1bf553SMark Brown 		break;
552b3172f22SGuennadi Liakhovetski 	case 11025:
5530a1bf553SMark Brown 		adn |= 0x4 << 1;
5540a1bf553SMark Brown 		break;
555b3172f22SGuennadi Liakhovetski 	case 16000:
5560a1bf553SMark Brown 		adn |= 0x3 << 1;
5570a1bf553SMark Brown 		break;
558b3172f22SGuennadi Liakhovetski 	case 22050:
5590a1bf553SMark Brown 		adn |= 0x2 << 1;
5600a1bf553SMark Brown 		break;
561b3172f22SGuennadi Liakhovetski 	case 32000:
5620a1bf553SMark Brown 		adn |= 0x1 << 1;
5630a1bf553SMark Brown 		break;
564b3172f22SGuennadi Liakhovetski 	case 44100:
565b3172f22SGuennadi Liakhovetski 	case 48000:
5660a1bf553SMark Brown 		break;
5670a1bf553SMark Brown 	}
5680a1bf553SMark Brown 
569*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_IFACE, iface);
570*3e32a3ffSKuninori Morimoto 	snd_soc_component_write(component, WM8974_ADD, adn);
5710a1bf553SMark Brown 	return 0;
5720a1bf553SMark Brown }
5730a1bf553SMark Brown 
5740a1bf553SMark Brown static int wm8974_mute(struct snd_soc_dai *dai, int mute)
5750a1bf553SMark Brown {
576*3e32a3ffSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
577*3e32a3ffSKuninori Morimoto 	u16 mute_reg = snd_soc_component_read32(component, WM8974_DAC) & 0xffbf;
5780a1bf553SMark Brown 
5790a1bf553SMark Brown 	if (mute)
580*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_DAC, mute_reg | 0x40);
5810a1bf553SMark Brown 	else
582*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_DAC, mute_reg);
5830a1bf553SMark Brown 	return 0;
5840a1bf553SMark Brown }
5850a1bf553SMark Brown 
5860a1bf553SMark Brown /* liam need to make this lower power with dapm */
587*3e32a3ffSKuninori Morimoto static int wm8974_set_bias_level(struct snd_soc_component *component,
5880a1bf553SMark Brown 	enum snd_soc_bias_level level)
5890a1bf553SMark Brown {
590*3e32a3ffSKuninori Morimoto 	u16 power1 = snd_soc_component_read32(component, WM8974_POWER1) & ~0x3;
591df1ef7a3SMark Brown 
5920a1bf553SMark Brown 	switch (level) {
5930a1bf553SMark Brown 	case SND_SOC_BIAS_ON:
5940a1bf553SMark Brown 	case SND_SOC_BIAS_PREPARE:
595df1ef7a3SMark Brown 		power1 |= 0x1;  /* VMID 50k */
596*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER1, power1);
5970a1bf553SMark Brown 		break;
598df1ef7a3SMark Brown 
5990a1bf553SMark Brown 	case SND_SOC_BIAS_STANDBY:
600df1ef7a3SMark Brown 		power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN;
601df1ef7a3SMark Brown 
602*3e32a3ffSKuninori Morimoto 		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
603*3e32a3ffSKuninori Morimoto 			regcache_sync(dev_get_regmap(component->dev, NULL));
6040bad3d84SAxel Lin 
605df1ef7a3SMark Brown 			/* Initial cap charge at VMID 5k */
606*3e32a3ffSKuninori Morimoto 			snd_soc_component_write(component, WM8974_POWER1, power1 | 0x3);
607df1ef7a3SMark Brown 			mdelay(100);
608df1ef7a3SMark Brown 		}
609df1ef7a3SMark Brown 
610df1ef7a3SMark Brown 		power1 |= 0x2;  /* VMID 500k */
611*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER1, power1);
6120a1bf553SMark Brown 		break;
613df1ef7a3SMark Brown 
6140a1bf553SMark Brown 	case SND_SOC_BIAS_OFF:
615*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER1, 0);
616*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER2, 0);
617*3e32a3ffSKuninori Morimoto 		snd_soc_component_write(component, WM8974_POWER3, 0);
6180a1bf553SMark Brown 		break;
6190a1bf553SMark Brown 	}
620df1ef7a3SMark Brown 
6210a1bf553SMark Brown 	return 0;
6220a1bf553SMark Brown }
6230a1bf553SMark Brown 
6241a55b3f6SMark Brown #define WM8974_RATES (SNDRV_PCM_RATE_8000_48000)
6250a1bf553SMark Brown 
6260a1bf553SMark Brown #define WM8974_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
6270a1bf553SMark Brown 	SNDRV_PCM_FMTBIT_S24_LE)
6280a1bf553SMark Brown 
62985e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm8974_ops = {
6300a1bf553SMark Brown 	.hw_params = wm8974_pcm_hw_params,
6310a1bf553SMark Brown 	.digital_mute = wm8974_mute,
6320a1bf553SMark Brown 	.set_fmt = wm8974_set_dai_fmt,
6330a1bf553SMark Brown 	.set_clkdiv = wm8974_set_dai_clkdiv,
6340a1bf553SMark Brown 	.set_pll = wm8974_set_dai_pll,
63551b2bb3fSMans Rullgard 	.set_sysclk = wm8974_set_dai_sysclk,
6360a1bf553SMark Brown };
6370a1bf553SMark Brown 
638f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm8974_dai = {
639f0fba2adSLiam Girdwood 	.name = "wm8974-hifi",
6400a1bf553SMark Brown 	.playback = {
6410a1bf553SMark Brown 		.stream_name = "Playback",
6420a1bf553SMark Brown 		.channels_min = 1,
64333d81af4SMark Brown 		.channels_max = 2,   /* Only 1 channel of data */
6440a1bf553SMark Brown 		.rates = WM8974_RATES,
6450a1bf553SMark Brown 		.formats = WM8974_FORMATS,},
6460a1bf553SMark Brown 	.capture = {
6470a1bf553SMark Brown 		.stream_name = "Capture",
6480a1bf553SMark Brown 		.channels_min = 1,
64933d81af4SMark Brown 		.channels_max = 2,   /* Only 1 channel of data */
6500a1bf553SMark Brown 		.rates = WM8974_RATES,
6510a1bf553SMark Brown 		.formats = WM8974_FORMATS,},
6520a1bf553SMark Brown 	.ops = &wm8974_ops,
653cb11d39eSMark Brown 	.symmetric_rates = 1,
6540a1bf553SMark Brown };
6550a1bf553SMark Brown 
656e40e0b5dSMark Brown static const struct regmap_config wm8974_regmap = {
657e40e0b5dSMark Brown 	.reg_bits = 7,
658e40e0b5dSMark Brown 	.val_bits = 9,
659e40e0b5dSMark Brown 
660e40e0b5dSMark Brown 	.max_register = WM8974_MONOMIX,
661e40e0b5dSMark Brown 	.reg_defaults = wm8974_reg_defaults,
662e40e0b5dSMark Brown 	.num_reg_defaults = ARRAY_SIZE(wm8974_reg_defaults),
6631ea5998aSMans Rullgard 	.cache_type = REGCACHE_FLAT,
664e40e0b5dSMark Brown };
665e40e0b5dSMark Brown 
666*3e32a3ffSKuninori Morimoto static int wm8974_probe(struct snd_soc_component *component)
6670a1bf553SMark Brown {
6680a1bf553SMark Brown 	int ret = 0;
6690a1bf553SMark Brown 
670*3e32a3ffSKuninori Morimoto 	ret = wm8974_reset(component);
671f0fba2adSLiam Girdwood 	if (ret < 0) {
672*3e32a3ffSKuninori Morimoto 		dev_err(component->dev, "Failed to issue reset\n");
673f0fba2adSLiam Girdwood 		return ret;
674f0fba2adSLiam Girdwood 	}
675f0fba2adSLiam Girdwood 
6760a1bf553SMark Brown 	return 0;
6770a1bf553SMark Brown }
6780a1bf553SMark Brown 
679*3e32a3ffSKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm8974 = {
6800a1bf553SMark Brown 	.probe			= wm8974_probe,
681f0fba2adSLiam Girdwood 	.set_bias_level		= wm8974_set_bias_level,
682a2bd691cSMark Brown 	.controls		= wm8974_snd_controls,
683a2bd691cSMark Brown 	.num_controls		= ARRAY_SIZE(wm8974_snd_controls),
684a2bd691cSMark Brown 	.dapm_widgets		= wm8974_dapm_widgets,
685a2bd691cSMark Brown 	.num_dapm_widgets	= ARRAY_SIZE(wm8974_dapm_widgets),
686a2bd691cSMark Brown 	.dapm_routes		= wm8974_dapm_routes,
687a2bd691cSMark Brown 	.num_dapm_routes	= ARRAY_SIZE(wm8974_dapm_routes),
688*3e32a3ffSKuninori Morimoto 	.suspend_bias_off	= 1,
689*3e32a3ffSKuninori Morimoto 	.idle_bias_on		= 1,
690*3e32a3ffSKuninori Morimoto 	.use_pmdown_time	= 1,
691*3e32a3ffSKuninori Morimoto 	.endianness		= 1,
692*3e32a3ffSKuninori Morimoto 	.non_legacy_dai_naming	= 1,
6930a1bf553SMark Brown };
6940a1bf553SMark Brown 
6957a79e94eSBill Pemberton static int wm8974_i2c_probe(struct i2c_client *i2c,
6964fcbbb67SMark Brown 			    const struct i2c_device_id *id)
6974fcbbb67SMark Brown {
69851b2bb3fSMans Rullgard 	struct wm8974_priv *priv;
699e40e0b5dSMark Brown 	struct regmap *regmap;
700f0fba2adSLiam Girdwood 	int ret;
7014fcbbb67SMark Brown 
70251b2bb3fSMans Rullgard 	priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL);
70351b2bb3fSMans Rullgard 	if (!priv)
70451b2bb3fSMans Rullgard 		return -ENOMEM;
70551b2bb3fSMans Rullgard 
70651b2bb3fSMans Rullgard 	i2c_set_clientdata(i2c, priv);
70751b2bb3fSMans Rullgard 
708e40e0b5dSMark Brown 	regmap = devm_regmap_init_i2c(i2c, &wm8974_regmap);
709e40e0b5dSMark Brown 	if (IS_ERR(regmap))
710e40e0b5dSMark Brown 		return PTR_ERR(regmap);
711e40e0b5dSMark Brown 
712*3e32a3ffSKuninori Morimoto 	ret = devm_snd_soc_register_component(&i2c->dev,
713*3e32a3ffSKuninori Morimoto 			&soc_component_dev_wm8974, &wm8974_dai, 1);
714c2562a8eSMark Brown 
715f0fba2adSLiam Girdwood 	return ret;
7164fcbbb67SMark Brown }
7174fcbbb67SMark Brown 
7184fcbbb67SMark Brown static const struct i2c_device_id wm8974_i2c_id[] = {
7194fcbbb67SMark Brown 	{ "wm8974", 0 },
7204fcbbb67SMark Brown 	{ }
7214fcbbb67SMark Brown };
7224fcbbb67SMark Brown MODULE_DEVICE_TABLE(i2c, wm8974_i2c_id);
7234fcbbb67SMark Brown 
7242005bd88SMans Rullgard static const struct of_device_id wm8974_of_match[] = {
7252005bd88SMans Rullgard        { .compatible = "wlf,wm8974", },
7262005bd88SMans Rullgard        { }
7272005bd88SMans Rullgard };
7282005bd88SMans Rullgard MODULE_DEVICE_TABLE(of, wm8974_of_match);
7292005bd88SMans Rullgard 
7304fcbbb67SMark Brown static struct i2c_driver wm8974_i2c_driver = {
7314fcbbb67SMark Brown 	.driver = {
732091edccfSMark Brown 		.name = "wm8974",
7332005bd88SMans Rullgard 		.of_match_table = wm8974_of_match,
7344fcbbb67SMark Brown 	},
7354fcbbb67SMark Brown 	.probe =    wm8974_i2c_probe,
7364fcbbb67SMark Brown 	.id_table = wm8974_i2c_id,
7374fcbbb67SMark Brown };
7384fcbbb67SMark Brown 
7392be59418SSachin Kamat module_i2c_driver(wm8974_i2c_driver);
7400a1bf553SMark Brown 
7410a1bf553SMark Brown MODULE_DESCRIPTION("ASoC WM8974 driver");
7420a1bf553SMark Brown MODULE_AUTHOR("Liam Girdwood");
7430a1bf553SMark Brown MODULE_LICENSE("GPL");
744