14 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/slab.h>
42 0x00, 0x80, 0x00, 0x80,
43 0x02, 0x00, 0x11, 0x05,
44 0x00, 0x00, 0x36, 0x10,
45 0x00, 0x00, 0x57, 0x00,
46 0x88, 0x88, 0x08, 0x08
49 static const int deemph_settings[] = {44100, 0, 48000, 32000};
53 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
56 for (i = 0 ; i <
ARRAY_SIZE(deemph_settings); i++) {
58 if (ak4641->
deemph && deemph_settings[i] != 0 &&
63 if (!ak4641->
deemph && deemph_settings[i] == 0)
67 dev_dbg(codec->
dev,
"Set deemphasis %d\n", best);
72 static int ak4641_put_deemph(
struct snd_kcontrol *kcontrol,
76 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
84 return ak4641_set_deemph(codec);
87 static int ak4641_get_deemph(
struct snd_kcontrol *kcontrol,
91 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
93 ucontrol->
value.enumerated.item[0] = ak4641->
deemph;
97 static const char *ak4641_mono_out[] = {
"(L + R)/2",
"Hi-Z"};
98 static const char *ak4641_hp_out[] = {
"Stereo",
"Mono"};
99 static const char *ak4641_mic_select[] = {
"Internal",
"External"};
100 static const char *ak4641_mic_or_dac[] = {
"Microphone",
"Voice DAC"};
114 static const struct soc_enum ak4641_mono_out_enum =
116 static const struct soc_enum ak4641_hp_out_enum =
118 static const struct soc_enum ak4641_mic_select_enum =
120 static const struct soc_enum ak4641_mic_or_dac_enum =
124 SOC_ENUM(
"Mono 1 Output", ak4641_mono_out_enum),
127 SOC_ENUM(
"Headphone Output", ak4641_hp_out_enum),
129 ak4641_get_deemph, ak4641_put_deemph),
161 mic_mono_sidetone_tlv),
169 mic_stereo_sidetone_tlv),
196 &ak4641_stereo_mixer_controls[0],
199 &ak4641_mono1_mixer_controls[0],
202 &ak4641_input_mixer_controls[0],
205 &ak4641_mic_mux_control),
207 &ak4641_input_mux_control),
209 &ak4641_mono2_control),
240 {
"Stereo Mixer",
"Playback Switch",
"DAC"},
241 {
"Stereo Mixer",
"Mic Sidetone Switch",
"Input Mux"},
242 {
"Stereo Mixer",
"Aux Bypass Switch",
"AUX In"},
245 {
"Mono1 Mixer",
"Mic Mono Sidetone Switch",
"Input Mux"},
246 {
"Mono1 Mixer",
"Mono Playback Switch",
"DAC"},
249 {
"Mic",
NULL,
"AIN"},
250 {
"Mic Mux",
"Internal",
"Mic Int Bias"},
251 {
"Mic Mux",
"External",
"Mic Ext Bias"},
252 {
"Mic Int Bias",
NULL,
"MICIN"},
253 {
"Mic Ext Bias",
NULL,
"MICEXT"},
254 {
"MICOUT",
NULL,
"Mic Mux"},
257 {
"Input Mux",
"Microphone",
"Mic"},
258 {
"Input Mux",
"Voice DAC",
"Voice DAC"},
261 {
"LOUT",
NULL,
"Line Out"},
262 {
"ROUT",
NULL,
"Line Out"},
263 {
"Line Out",
NULL,
"Stereo Mixer"},
266 {
"MOUT1",
NULL,
"Mono Out"},
267 {
"Mono Out",
NULL,
"Mono1 Mixer"},
270 {
"MOUT2",
NULL,
"Mono 2 Enable"},
271 {
"Mono 2 Enable",
"Switch",
"Mono Out 2"},
272 {
"Mono Out 2",
NULL,
"Stereo Mixer"},
274 {
"Voice ADC",
NULL,
"Mono 2 Enable"},
277 {
"AUX In",
NULL,
"AUX"},
280 {
"ADC",
NULL,
"Input Mixer"},
281 {
"Input Mixer",
"Mic Capture Switch",
"Mic"},
282 {
"Input Mixer",
"Aux Capture Switch",
"AUX In"},
285 static int ak4641_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
286 int clk_id,
unsigned int freq,
int dir)
289 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
300 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
330 ak4641_set_deemph(codec);
336 static int ak4641_pcm_set_dai_fmt(
struct snd_soc_dai *codec_dai,
368 static int ak4641_i2s_set_dai_fmt(
struct snd_soc_dai *codec_dai,
375 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
396 static int ak4641_set_bias_level(
struct snd_soc_codec *codec,
413 if (pdata && gpio_is_valid(pdata->
gpio_power))
416 if (pdata && gpio_is_valid(pdata->
gpio_npdn))
423 "Failed to sync cache: %d\n", ret);
432 if (pdata && gpio_is_valid(pdata->
gpio_npdn))
434 if (pdata && gpio_is_valid(pdata->
gpio_power))
443 #define AK4641_RATES (SNDRV_PCM_RATE_8000_48000)
444 #define AK4641_RATES_BT (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
445 SNDRV_PCM_RATE_16000)
446 #define AK4641_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
449 .hw_params = ak4641_i2s_hw_params,
450 .set_fmt = ak4641_i2s_set_dai_fmt,
451 .digital_mute = ak4641_mute,
452 .set_sysclk = ak4641_set_dai_sysclk,
457 .set_fmt = ak4641_pcm_set_dai_fmt,
458 .digital_mute = ak4641_mute,
459 .set_sysclk = ak4641_set_dai_sysclk,
464 .name =
"ak4641-hifi",
467 .stream_name =
"HiFi Playback",
474 .stream_name =
"HiFi Capture",
480 .ops = &ak4641_i2s_dai_ops,
481 .symmetric_rates = 1,
484 .name =
"ak4641-voice",
487 .stream_name =
"Voice Playback",
494 .stream_name =
"Voice Capture",
500 .ops = &ak4641_pcm_dai_ops,
501 .symmetric_rates = 1,
523 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
542 .probe = ak4641_probe,
543 .remove = ak4641_remove,
544 .suspend = ak4641_suspend,
545 .resume = ak4641_resume,
546 .controls = ak4641_snd_controls,
547 .num_controls =
ARRAY_SIZE(ak4641_snd_controls),
548 .dapm_widgets = ak4641_dapm_widgets,
549 .num_dapm_widgets =
ARRAY_SIZE(ak4641_dapm_widgets),
550 .dapm_routes = ak4641_audio_map,
551 .num_dapm_routes =
ARRAY_SIZE(ak4641_audio_map),
552 .set_bias_level = ak4641_set_bias_level,
554 .reg_word_size =
sizeof(
u8),
590 i2c_set_clientdata(i2c, ak4641);
607 if (pdata && gpio_is_valid(pdata->
gpio_power))
637 static struct i2c_driver ak4641_i2c_driver = {
642 .probe = ak4641_i2c_probe,
644 .id_table = ak4641_i2c_id,