18 #include <linux/module.h>
19 #include <linux/kernel.h>
23 #include <linux/i2c.h>
24 #include <linux/slab.h>
35 static int caps_charge = 2000;
56 for (i = 0 ; i < codec->
driver->reg_cache_size ; i +=
step)
94 static const unsigned int boost_tlv[] = {
219 static const char *alc5623_spk_n_sour_sel[] = {
220 "RN/-R",
"RP/+R",
"LN/-R",
"Vmid" };
221 static const char *alc5623_hpl_out_input_sel[] = {
222 "Vmid",
"HP Left Mix"};
223 static const char *alc5623_hpr_out_input_sel[] = {
224 "Vmid",
"HP Right Mix"};
225 static const char *alc5623_spkout_input_sel[] = {
226 "Vmid",
"HPOut Mix",
"Speaker Mix",
"Mono Mix"};
227 static const char *alc5623_aux_out_input_sel[] = {
228 "Vmid",
"HPOut Mix",
"Speaker Mix",
"Mono Mix"};
231 static const struct soc_enum alc5623_aux_out_input_enum =
237 static const struct soc_enum alc5623_spkout_input_enum =
243 static const struct soc_enum alc5623_hpl_out_input_enum =
249 static const struct soc_enum alc5623_hpr_out_input_enum =
255 static const struct soc_enum alc5623_spk_n_sour_enum =
263 &alc5623_auxout_mux_controls),
265 &alc5623_spkout_mux_controls),
267 &alc5623_hpl_out_mux_controls),
269 &alc5623_hpr_out_mux_controls),
271 &alc5623_spkoutn_mux_controls),
275 &alc5623_hp_mixer_controls[0],
278 &alc5623_hpr_mixer_controls[0],
281 &alc5623_hpl_mixer_controls[0],
285 &alc5623_mono_mixer_controls[0],
288 &alc5623_speaker_mixer_controls[0],
293 &alc5623_captureL_mixer_controls[0],
296 &alc5623_captureR_mixer_controls[0],
340 static const char *alc5623_amp_names[] = {
"AB Amp",
"D Amp"};
341 static const struct soc_enum alc5623_amp_enum =
351 &alc5623_amp_mux_controls),
356 {
"I2S Mix",
NULL,
"Left DAC"},
357 {
"I2S Mix",
NULL,
"Right DAC"},
358 {
"Line Mix",
NULL,
"Right LineIn"},
359 {
"Line Mix",
NULL,
"Left LineIn"},
360 {
"AuxI Mix",
NULL,
"Left AuxI"},
361 {
"AuxI Mix",
NULL,
"Right AuxI"},
362 {
"AUXOUTL",
NULL,
"Left AuxOut"},
363 {
"AUXOUTR",
NULL,
"Right AuxOut"},
366 {
"HPL Mix",
"ADC2HP_L Playback Switch",
"Left Capture Mix"},
367 {
"HPL Mix",
NULL,
"HP Mix"},
368 {
"HPR Mix",
"ADC2HP_R Playback Switch",
"Right Capture Mix"},
369 {
"HPR Mix",
NULL,
"HP Mix"},
370 {
"HP Mix",
"LI2HP Playback Switch",
"Line Mix"},
371 {
"HP Mix",
"AUXI2HP Playback Switch",
"AuxI Mix"},
372 {
"HP Mix",
"MIC12HP Playback Switch",
"MIC1 PGA"},
373 {
"HP Mix",
"MIC22HP Playback Switch",
"MIC2 PGA"},
374 {
"HP Mix",
"DAC2HP Playback Switch",
"I2S Mix"},
377 {
"Speaker Mix",
"LI2SPK Playback Switch",
"Line Mix"},
378 {
"Speaker Mix",
"AUXI2SPK Playback Switch",
"AuxI Mix"},
379 {
"Speaker Mix",
"MIC12SPK Playback Switch",
"MIC1 PGA"},
380 {
"Speaker Mix",
"MIC22SPK Playback Switch",
"MIC2 PGA"},
381 {
"Speaker Mix",
"DAC2SPK Playback Switch",
"I2S Mix"},
384 {
"Mono Mix",
"ADC2MONO_L Playback Switch",
"Left Capture Mix"},
385 {
"Mono Mix",
"ADC2MONO_R Playback Switch",
"Right Capture Mix"},
386 {
"Mono Mix",
"LI2MONO Playback Switch",
"Line Mix"},
387 {
"Mono Mix",
"AUXI2MONO Playback Switch",
"AuxI Mix"},
388 {
"Mono Mix",
"MIC12MONO Playback Switch",
"MIC1 PGA"},
389 {
"Mono Mix",
"MIC22MONO Playback Switch",
"MIC2 PGA"},
390 {
"Mono Mix",
"DAC2MONO Playback Switch",
"I2S Mix"},
393 {
"Left Capture Mix",
"LineInL Capture Switch",
"LINEINL"},
394 {
"Left Capture Mix",
"Left AuxI Capture Switch",
"AUXINL"},
395 {
"Left Capture Mix",
"Mic1 Capture Switch",
"MIC1 Pre Amp"},
396 {
"Left Capture Mix",
"Mic2 Capture Switch",
"MIC2 Pre Amp"},
397 {
"Left Capture Mix",
"HPMixerL Capture Switch",
"HPL Mix"},
398 {
"Left Capture Mix",
"SPKMixer Capture Switch",
"Speaker Mix"},
399 {
"Left Capture Mix",
"MonoMixer Capture Switch",
"Mono Mix"},
402 {
"Right Capture Mix",
"LineInR Capture Switch",
"LINEINR"},
403 {
"Right Capture Mix",
"Right AuxI Capture Switch",
"AUXINR"},
404 {
"Right Capture Mix",
"Mic1 Capture Switch",
"MIC1 Pre Amp"},
405 {
"Right Capture Mix",
"Mic2 Capture Switch",
"MIC2 Pre Amp"},
406 {
"Right Capture Mix",
"HPMixerR Capture Switch",
"HPR Mix"},
407 {
"Right Capture Mix",
"SPKMixer Capture Switch",
"Speaker Mix"},
408 {
"Right Capture Mix",
"MonoMixer Capture Switch",
"Mono Mix"},
411 {
"Left Headphone Mux",
"HP Left Mix",
"HPL Mix"},
412 {
"Left Headphone Mux",
"Vmid",
"Vmid"},
415 {
"Right Headphone Mux",
"HP Right Mix",
"HPR Mix"},
416 {
"Right Headphone Mux",
"Vmid",
"Vmid"},
419 {
"SpeakerOut Mux",
"Vmid",
"Vmid"},
420 {
"SpeakerOut Mux",
"HPOut Mix",
"HPOut Mix"},
421 {
"SpeakerOut Mux",
"Speaker Mix",
"Speaker Mix"},
422 {
"SpeakerOut Mux",
"Mono Mix",
"Mono Mix"},
425 {
"AuxOut Mux",
"Vmid",
"Vmid"},
426 {
"AuxOut Mux",
"HPOut Mix",
"HPOut Mix"},
427 {
"AuxOut Mux",
"Speaker Mix",
"Speaker Mix"},
428 {
"AuxOut Mux",
"Mono Mix",
"Mono Mix"},
431 {
"HPL",
NULL,
"Left Headphone"},
432 {
"Left Headphone",
NULL,
"Left Headphone Mux"},
433 {
"HPR",
NULL,
"Right Headphone"},
434 {
"Right Headphone",
NULL,
"Right Headphone Mux"},
435 {
"Left AuxOut",
NULL,
"AuxOut Mux"},
436 {
"Right AuxOut",
NULL,
"AuxOut Mux"},
439 {
"Left LineIn",
NULL,
"LINEINL"},
440 {
"Right LineIn",
NULL,
"LINEINR"},
441 {
"Left AuxI",
NULL,
"AUXINL"},
442 {
"Right AuxI",
NULL,
"AUXINR"},
443 {
"MIC1 Pre Amp",
NULL,
"MIC1"},
444 {
"MIC2 Pre Amp",
NULL,
"MIC2"},
445 {
"MIC1 PGA",
NULL,
"MIC1 Pre Amp"},
446 {
"MIC2 PGA",
NULL,
"MIC2 Pre Amp"},
449 {
"Left ADC",
NULL,
"Left Capture Mix"},
452 {
"Right ADC",
NULL,
"Right Capture Mix"},
454 {
"SpeakerOut N Mux",
"RN/-R",
"SpeakerOut"},
455 {
"SpeakerOut N Mux",
"RP/+R",
"SpeakerOut"},
456 {
"SpeakerOut N Mux",
"LN/-R",
"SpeakerOut"},
457 {
"SpeakerOut N Mux",
"Vmid",
"Vmid"},
459 {
"SPKOUT",
NULL,
"SpeakerOut"},
460 {
"SPKOUTN",
NULL,
"SpeakerOut N Mux"},
464 {
"SpeakerOut",
NULL,
"SpeakerOut Mux"},
468 {
"AB Amp",
NULL,
"SpeakerOut Mux"},
469 {
"D Amp",
NULL,
"SpeakerOut Mux"},
470 {
"AB-D Amp Mux",
"AB Amp",
"AB Amp"},
471 {
"AB-D Amp Mux",
"D Amp",
"D Amp"},
472 {
"SpeakerOut",
NULL,
"AB-D Amp Mux"},
484 static const struct _pll_div codec_master_pll_div[] = {
486 { 2048000, 8192000, 0x0ea0},
487 { 3686400, 8192000, 0x4e27},
488 { 12000000, 8192000, 0x456b},
489 { 13000000, 8192000, 0x495f},
490 { 13100000, 8192000, 0x0320},
491 { 2048000, 11289600, 0xf637},
492 { 3686400, 11289600, 0x2f22},
493 { 12000000, 11289600, 0x3e2f},
494 { 13000000, 11289600, 0x4d5b},
495 { 13100000, 11289600, 0x363b},
496 { 2048000, 16384000, 0x1ea0},
497 { 3686400, 16384000, 0x9e27},
498 { 12000000, 16384000, 0x452b},
499 { 13000000, 16384000, 0x542f},
500 { 13100000, 16384000, 0x03a0},
501 { 2048000, 16934400, 0xe625},
502 { 3686400, 16934400, 0x9126},
503 { 12000000, 16934400, 0x4d2c},
504 { 13000000, 16934400, 0x742f},
505 { 13100000, 16934400, 0x3c27},
506 { 2048000, 22579200, 0x2aa0},
507 { 3686400, 22579200, 0x2f20},
508 { 12000000, 22579200, 0x7e2f},
509 { 13000000, 22579200, 0x742f},
510 { 13100000, 22579200, 0x3c27},
511 { 2048000, 24576000, 0x2ea0},
512 { 3686400, 24576000, 0xee27},
513 { 12000000, 24576000, 0x2915},
514 { 13000000, 24576000, 0x772e},
515 { 13100000, 24576000, 0x0d20},
518 static const struct _pll_div codec_slave_pll_div[] = {
520 { 1024000, 16384000, 0x3ea0},
521 { 1411200, 22579200, 0x3ea0},
522 { 1536000, 24576000, 0x3ea0},
523 { 2048000, 16384000, 0x1ea0},
524 { 2822400, 22579200, 0x1ea0},
525 { 3072000, 24576000, 0x1ea0},
529 static int alc5623_set_dai_pll(
struct snd_soc_dai *codec_dai,
int pll_id,
530 int source,
unsigned int freq_in,
unsigned int freq_out)
550 if (!freq_in || !freq_out)
555 for (i = 0; i <
ARRAY_SIZE(codec_master_pll_div); i++) {
556 if (codec_master_pll_div[i].pll_in == freq_in
557 && codec_master_pll_div[i].pll_out == freq_out) {
564 case ALC5623_PLL_FR_BCK:
565 for (i = 0; i <
ARRAY_SIZE(codec_slave_pll_div); i++) {
566 if (codec_slave_pll_div[i].pll_in == freq_in
567 && codec_slave_pll_div[i].pll_out == freq_out) {
600 static const struct _coeff_div coeff_div[] = {
613 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
617 if (coeff_div[i].
fs * rate == alc5623->
sysclk)
626 static int alc5623_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
627 int clk_id,
unsigned int freq,
int dir)
630 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
647 static int alc5623_set_dai_fmt(
struct snd_soc_dai *codec_dai,
709 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
737 coeff = get_coeff(codec, rate);
742 dev_dbg(codec->
dev,
"%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
743 __func__, alc5623->
sysclk, rate, coeff);
761 #define ALC5623_ADD2_POWER_EN (ALC5623_PWR_ADD2_VREF \
762 | ALC5623_PWR_ADD2_DAC_REF_CIR)
764 #define ALC5623_ADD3_POWER_EN (ALC5623_PWR_ADD3_MAIN_BIAS \
765 | ALC5623_PWR_ADD3_MIC1_BOOST_AD)
767 #define ALC5623_ADD1_POWER_EN \
768 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN | ALC5623_PWR_ADD1_SOFTGEN_EN \
769 | ALC5623_PWR_ADD1_DEPOP_BUF_HP | ALC5623_PWR_ADD1_HP_OUT_AMP \
770 | ALC5623_PWR_ADD1_HP_OUT_ENH_AMP)
772 #define ALC5623_ADD1_POWER_EN_5622 \
773 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN \
774 | ALC5623_PWR_ADD1_HP_OUT_AMP)
778 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
795 if (alc5623->
id == 0x22)
809 static int alc5623_set_bias_level(
struct snd_soc_codec *codec,
814 enable_power_depop(codec);
836 #define ALC5623_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
837 | SNDRV_PCM_FMTBIT_S24_LE \
838 | SNDRV_PCM_FMTBIT_S32_LE)
841 .hw_params = alc5623_pcm_hw_params,
842 .digital_mute = alc5623_mute,
843 .set_fmt = alc5623_set_dai_fmt,
844 .set_sysclk = alc5623_set_dai_sysclk,
845 .set_pll = alc5623_set_dai_pll,
849 .name =
"alc5623-hifi",
851 .stream_name =
"Playback",
859 .stream_name =
"Capture",
867 .ops = &alc5623_dai_ops,
882 for (i = 2 ; i < codec->
driver->reg_cache_size ; i +=
step)
891 alc5623_set_bias_level(codec, codec->
dapm.bias_level);
899 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
905 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
909 alc5623_reset(codec);
910 alc5623_fill_cache(codec);
925 switch (alc5623->
id) {
951 switch (alc5623->
id) {
978 .probe = alc5623_probe,
979 .remove = alc5623_remove,
980 .suspend = alc5623_suspend,
981 .resume = alc5623_resume,
982 .set_bias_level = alc5623_set_bias_level,
984 .reg_word_size =
sizeof(
u16),
1003 dev_err(&client->
dev,
"failed to read I2C\n");
1006 vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8);
1010 dev_err(&client->
dev,
"failed to read I2C\n");
1014 if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) {
1015 dev_err(&client->
dev,
"unknown or wrong codec\n");
1016 dev_err(&client->
dev,
"Expected %x:%lx, got %x:%x\n",
1017 0x10ec, id->driver_data,
1022 dev_dbg(&client->
dev,
"Found codec id : alc56%02x\n", vid2);
1026 if (alc5623 ==
NULL)
1029 pdata = client->
dev.platform_data;
1036 switch (alc5623->
id) {
1038 alc5623_dai.
name =
"alc5621-hifi";
1041 alc5623_dai.
name =
"alc5622-hifi";
1044 alc5623_dai.
name =
"alc5623-hifi";
1050 i2c_set_clientdata(client, alc5623);
1054 &soc_codec_device_alc5623, &alc5623_dai, 1);
1056 dev_err(&client->
dev,
"Failed to register codec: %d\n", ret);
1076 static struct i2c_driver alc5623_i2c_driver = {
1078 .name =
"alc562x-codec",
1081 .probe = alc5623_i2c_probe,
1083 .id_table = alc5623_i2c_table,