23 #include <linux/module.h>
24 #include <linux/device.h>
26 #include <linux/slab.h>
36 #define MC13783_AUDIO_RX0 36
37 #define MC13783_AUDIO_RX1 37
38 #define MC13783_AUDIO_TX 38
39 #define MC13783_SSI_NETWORK 39
40 #define MC13783_AUDIO_CODEC 40
41 #define MC13783_AUDIO_DAC 41
43 #define AUDIO_RX0_ALSPEN (1 << 5)
44 #define AUDIO_RX0_ALSPSEL (1 << 7)
45 #define AUDIO_RX0_ADDCDC (1 << 21)
46 #define AUDIO_RX0_ADDSTDC (1 << 22)
47 #define AUDIO_RX0_ADDRXIN (1 << 23)
49 #define AUDIO_RX1_PGARXEN (1 << 0);
50 #define AUDIO_RX1_PGASTEN (1 << 5)
51 #define AUDIO_RX1_ARXINEN (1 << 10)
53 #define AUDIO_TX_AMC1REN (1 << 5)
54 #define AUDIO_TX_AMC1LEN (1 << 7)
55 #define AUDIO_TX_AMC2EN (1 << 9)
56 #define AUDIO_TX_ATXINEN (1 << 11)
57 #define AUDIO_TX_RXINREC (1 << 13)
59 #define SSI_NETWORK_CDCTXRXSLOT(x) (((x) & 0x3) << 2)
60 #define SSI_NETWORK_CDCTXSECSLOT(x) (((x) & 0x3) << 4)
61 #define SSI_NETWORK_CDCRXSECSLOT(x) (((x) & 0x3) << 6)
62 #define SSI_NETWORK_CDCRXSECGAIN(x) (((x) & 0x3) << 8)
63 #define SSI_NETWORK_CDCSUMGAIN(x) (1 << 10)
64 #define SSI_NETWORK_CDCFSDLY(x) (1 << 11)
65 #define SSI_NETWORK_DAC_SLOTS_8 (1 << 12)
66 #define SSI_NETWORK_DAC_SLOTS_4 (2 << 12)
67 #define SSI_NETWORK_DAC_SLOTS_2 (3 << 12)
68 #define SSI_NETWORK_DAC_SLOT_MASK (3 << 12)
69 #define SSI_NETWORK_DAC_RXSLOT_0_1 (0 << 14)
70 #define SSI_NETWORK_DAC_RXSLOT_2_3 (1 << 14)
71 #define SSI_NETWORK_DAC_RXSLOT_4_5 (2 << 14)
72 #define SSI_NETWORK_DAC_RXSLOT_6_7 (3 << 14)
73 #define SSI_NETWORK_DAC_RXSLOT_MASK (3 << 14)
74 #define SSI_NETWORK_STDCRXSECSLOT(x) (((x) & 0x3) << 16)
75 #define SSI_NETWORK_STDCRXSECGAIN(x) (((x) & 0x3) << 18)
76 #define SSI_NETWORK_STDCSUMGAIN (1 << 20)
82 #define AUDIO_SSI_SEL (1 << 0)
83 #define AUDIO_CLK_SEL (1 << 1)
84 #define AUDIO_CSM (1 << 2)
85 #define AUDIO_BCL_INV (1 << 3)
86 #define AUDIO_CFS_INV (1 << 4)
87 #define AUDIO_CFS(x) (((x) & 0x3) << 5)
88 #define AUDIO_CLK(x) (((x) & 0x7) << 7)
89 #define AUDIO_C_EN (1 << 11)
90 #define AUDIO_C_CLK_EN (1 << 12)
91 #define AUDIO_C_RESET (1 << 15)
93 #define AUDIO_CODEC_CDCFS8K16K (1 << 10)
94 #define AUDIO_DAC_CFS_DLY_B (1 << 10)
108 unsigned int value = 0;
120 unsigned int reg,
unsigned int value)
135 static unsigned int mc13783_rates[] = {
136 8000, 11025, 12000, 16000,
137 22050, 24000, 32000, 44100,
150 for (i = 0; i <
ARRAY_SIZE(mc13783_rates); i++) {
151 if (rate == mc13783_rates[i]) {
192 return mc13783_pcm_hw_params_dac(substream, params, dai);
194 return mc13783_pcm_hw_params_codec(substream, params, dai);
197 static int mc13783_set_fmt(
struct snd_soc_dai *dai,
unsigned int fmt,
201 unsigned int val = 0;
253 static int mc13783_set_fmt_async(
struct snd_soc_dai *dai,
unsigned int fmt)
261 static int mc13783_set_fmt_sync(
struct snd_soc_dai *dai,
unsigned int fmt)
280 static int mc13783_sysclk[] = {
291 static int mc13783_set_sysclk(
struct snd_soc_dai *dai,
292 int clk_id,
unsigned int freq,
int dir,
297 unsigned int val = 0;
300 for (clk = 0; clk <
ARRAY_SIZE(mc13783_sysclk); clk++) {
301 if (mc13783_sysclk[clk] < 0)
303 if (mc13783_sysclk[clk] == freq)
320 static int mc13783_set_sysclk_dac(
struct snd_soc_dai *dai,
321 int clk_id,
unsigned int freq,
int dir)
326 static int mc13783_set_sysclk_codec(
struct snd_soc_dai *dai,
327 int clk_id,
unsigned int freq,
int dir)
332 static int mc13783_set_sysclk_sync(
struct snd_soc_dai *dai,
333 int clk_id,
unsigned int freq,
int dir)
344 static int mc13783_set_tdm_slot_dac(
struct snd_soc_dai *dai,
349 unsigned int val = 0;
389 static int mc13783_set_tdm_slot_codec(
struct snd_soc_dai *dai,
390 unsigned int tx_mask,
unsigned int rx_mask,
int slots,
394 unsigned int val = 0;
395 unsigned int mask = 0x3f;
400 if (tx_mask != 0xfffffffc)
411 static int mc13783_set_tdm_slot_sync(
struct snd_soc_dai *dai,
412 unsigned int tx_mask,
unsigned int rx_mask,
int slots,
417 ret = mc13783_set_tdm_slot_dac(dai, tx_mask, rx_mask, slots,
422 ret = mc13783_set_tdm_slot_codec(dai, tx_mask, rx_mask, slots,
443 static const char *
const adcl_enum_text[] = {
447 static const struct soc_enum adcl_enum =
453 static const char *
const adcr_enum_text[] = {
454 "MC1R",
"MC2",
"RXINR",
"TXIN",
457 static const struct soc_enum adcr_enum =
535 {
"MC1L Amp",
NULL,
"MC1LIN"},
536 {
"MC1R Amp",
NULL,
"MC1RIN" },
537 {
"MC2 Amp",
NULL,
"MC2IN" },
538 {
"TXIN Amp",
NULL,
"TXIN"},
540 {
"PGA Left Input Mux",
"MC1L",
"MC1L Amp" },
541 {
"PGA Left Input Mux",
"RXINL",
"RXINL"},
542 {
"PGA Right Input Mux",
"MC1R",
"MC1R Amp" },
543 {
"PGA Right Input Mux",
"MC2",
"MC2 Amp"},
544 {
"PGA Right Input Mux",
"TXIN",
"TXIN Amp"},
545 {
"PGA Right Input Mux",
"RXINR",
"RXINR"},
547 {
"PGA Left Input",
NULL,
"PGA Left Input Mux"},
548 {
"PGA Right Input",
NULL,
"PGA Right Input Mux"},
550 {
"ADC",
NULL,
"PGA Left Input"},
551 {
"ADC",
NULL,
"PGA Right Input"},
552 {
"ADC",
NULL,
"ADC_Reset"},
555 {
"HSL",
NULL,
"Headset Amp Left" },
556 {
"HSR",
NULL,
"Headset Amp Right"},
557 {
"RXOUTL",
NULL,
"Line out Amp Left"},
558 {
"RXOUTR",
NULL,
"Line out Amp Right"},
559 {
"SP",
NULL,
"Speaker Amp"},
560 {
"Speaker Amp",
NULL,
"DAC PGA"},
561 {
"LSP",
NULL,
"DAC PGA"},
562 {
"Headset Amp Left",
NULL,
"DAC PGA"},
563 {
"Headset Amp Right",
NULL,
"DAC PGA"},
564 {
"Line out Amp Left",
NULL,
"DAC PGA"},
565 {
"Line out Amp Right",
NULL,
"DAC PGA"},
566 {
"DAC PGA",
NULL,
"DAC"},
567 {
"DAC",
NULL,
"DAC_E"},
570 static const char *
const mc13783_3d_mixer[] = {
"Stereo",
"Phase Mix",
573 static const struct soc_enum mc13783_enum_3d_mixer =
581 SOC_ENUM(
"3D Control", mc13783_enum_3d_mixer),
619 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
631 #define MC13783_RATES_RECORD (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
633 #define MC13783_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
634 SNDRV_PCM_FMTBIT_S24_LE)
637 .hw_params = mc13783_pcm_hw_params_dac,
638 .set_fmt = mc13783_set_fmt_async,
639 .set_sysclk = mc13783_set_sysclk_dac,
640 .set_tdm_slot = mc13783_set_tdm_slot_dac,
644 .hw_params = mc13783_pcm_hw_params_codec,
645 .set_fmt = mc13783_set_fmt_async,
646 .set_sysclk = mc13783_set_sysclk_codec,
647 .set_tdm_slot = mc13783_set_tdm_slot_codec,
660 .name =
"mc13783-hifi-playback",
663 .stream_name =
"Playback",
669 .ops = &mc13783_ops_dac,
671 .name =
"mc13783-hifi-capture",
674 .stream_name =
"Capture",
680 .ops = &mc13783_ops_codec,
685 .hw_params = mc13783_pcm_hw_params_sync,
686 .set_fmt = mc13783_set_fmt_sync,
687 .set_sysclk = mc13783_set_sysclk_sync,
688 .set_tdm_slot = mc13783_set_tdm_slot_sync,
693 .name =
"mc13783-hifi",
696 .stream_name =
"Playback",
703 .stream_name =
"Capture",
709 .ops = &mc13783_ops_sync,
710 .symmetric_rates = 1,
715 .probe = mc13783_probe,
716 .remove = mc13783_remove,
717 .read = mc13783_read,
718 .write = mc13783_write,
719 .controls = mc13783_control_list,
720 .num_controls =
ARRAY_SIZE(mc13783_control_list),
721 .dapm_widgets = mc13783_dapm_widgets,
722 .num_dapm_widgets =
ARRAY_SIZE(mc13783_dapm_widgets),
723 .dapm_routes = mc13783_routes,
724 .num_dapm_routes =
ARRAY_SIZE(mc13783_routes),
753 mc13783_dai_sync,
ARRAY_SIZE(mc13783_dai_sync));
756 mc13783_dai_async,
ARRAY_SIZE(mc13783_dai_async));
759 goto err_register_codec;
764 dev_err(&pdev->
dev,
"register codec failed with %d\n", ret);
778 .name =
"mc13783-codec",
781 .probe = mc13783_codec_probe,