1 // SPDX-License-Identifier: GPL-2.0+
5 // Copyright 2011 Vista Silicon S.L.
7 // Author: Javier Martin <javier.martin@vista-silicon.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/device.h>
12 #include <linux/i2c.h>
13 #include <linux/gpio.h>
14 #include <linux/platform_data/asoc-mx27vis.h>
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/soc.h>
18 #include <sound/soc-dapm.h>
19 #include <sound/tlv.h>
20 #include <asm/mach-types.h>
22 #include "../codecs/tlv320aic32x4.h"
24 #include "imx-audmux.h"
26 #define MX27VIS_AMP_GAIN 0
27 #define MX27VIS_AMP_MUTE 1
29 static int mx27vis_amp_gain
;
30 static int mx27vis_amp_mute
;
31 static int mx27vis_amp_gain0_gpio
;
32 static int mx27vis_amp_gain1_gpio
;
33 static int mx27vis_amp_mutel_gpio
;
34 static int mx27vis_amp_muter_gpio
;
36 static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream
*substream
,
37 struct snd_pcm_hw_params
*params
)
39 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
40 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
41 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
44 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0,
45 25000000, SND_SOC_CLOCK_OUT
);
47 pr_err("%s: failed setting codec sysclk\n", __func__
);
51 ret
= snd_soc_dai_set_sysclk(cpu_dai
, IMX_SSP_SYS_CLK
, 0,
54 pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
61 static const struct snd_soc_ops mx27vis_aic32x4_snd_ops
= {
62 .hw_params
= mx27vis_aic32x4_hw_params
,
65 static int mx27vis_amp_set(struct snd_kcontrol
*kcontrol
,
66 struct snd_ctl_elem_value
*ucontrol
)
68 struct soc_mixer_control
*mc
=
69 (struct soc_mixer_control
*)kcontrol
->private_value
;
70 int value
= ucontrol
->value
.integer
.value
[0];
71 unsigned int reg
= mc
->reg
;
78 case MX27VIS_AMP_GAIN
:
79 gpio_set_value(mx27vis_amp_gain0_gpio
, value
& 1);
80 gpio_set_value(mx27vis_amp_gain1_gpio
, value
>> 1);
81 mx27vis_amp_gain
= value
;
83 case MX27VIS_AMP_MUTE
:
84 gpio_set_value(mx27vis_amp_mutel_gpio
, value
& 1);
85 gpio_set_value(mx27vis_amp_muter_gpio
, value
>> 1);
86 mx27vis_amp_mute
= value
;
92 static int mx27vis_amp_get(struct snd_kcontrol
*kcontrol
,
93 struct snd_ctl_elem_value
*ucontrol
)
95 struct soc_mixer_control
*mc
=
96 (struct soc_mixer_control
*)kcontrol
->private_value
;
97 unsigned int reg
= mc
->reg
;
100 case MX27VIS_AMP_GAIN
:
101 ucontrol
->value
.integer
.value
[0] = mx27vis_amp_gain
;
103 case MX27VIS_AMP_MUTE
:
104 ucontrol
->value
.integer
.value
[0] = mx27vis_amp_mute
;
110 /* From 6dB to 24dB in steps of 6dB */
111 static const DECLARE_TLV_DB_SCALE(mx27vis_amp_tlv
, 600, 600, 0);
113 static const struct snd_kcontrol_new mx27vis_aic32x4_controls
[] = {
114 SOC_DAPM_PIN_SWITCH("External Mic"),
115 SOC_SINGLE_EXT_TLV("LO Ext Boost", MX27VIS_AMP_GAIN
, 0, 3, 0,
116 mx27vis_amp_get
, mx27vis_amp_set
, mx27vis_amp_tlv
),
117 SOC_DOUBLE_EXT("LO Ext Mute Switch", MX27VIS_AMP_MUTE
, 0, 1, 1, 0,
118 mx27vis_amp_get
, mx27vis_amp_set
),
121 static const struct snd_soc_dapm_widget aic32x4_dapm_widgets
[] = {
122 SND_SOC_DAPM_MIC("External Mic", NULL
),
125 static const struct snd_soc_dapm_route aic32x4_dapm_routes
[] = {
126 {"Mic Bias", NULL
, "External Mic"},
127 {"IN1_R", NULL
, "Mic Bias"},
128 {"IN2_R", NULL
, "Mic Bias"},
129 {"IN3_R", NULL
, "Mic Bias"},
130 {"IN1_L", NULL
, "Mic Bias"},
131 {"IN2_L", NULL
, "Mic Bias"},
132 {"IN3_L", NULL
, "Mic Bias"},
135 SND_SOC_DAILINK_DEFS(hifi
,
136 DAILINK_COMP_ARRAY(COMP_CPU("imx-ssi.0")),
137 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.0-0018",
138 "tlv320aic32x4-hifi")),
139 DAILINK_COMP_ARRAY(COMP_PLATFORM("imx-ssi.0")));
141 static struct snd_soc_dai_link mx27vis_aic32x4_dai
= {
142 .name
= "tlv320aic32x4",
143 .stream_name
= "TLV320AIC32X4",
144 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_NB_NF
|
145 SND_SOC_DAIFMT_CBM_CFM
,
146 .ops
= &mx27vis_aic32x4_snd_ops
,
147 SND_SOC_DAILINK_REG(hifi
),
150 static struct snd_soc_card mx27vis_aic32x4
= {
151 .name
= "visstrim_m10-audio",
152 .owner
= THIS_MODULE
,
153 .dai_link
= &mx27vis_aic32x4_dai
,
155 .controls
= mx27vis_aic32x4_controls
,
156 .num_controls
= ARRAY_SIZE(mx27vis_aic32x4_controls
),
157 .dapm_widgets
= aic32x4_dapm_widgets
,
158 .num_dapm_widgets
= ARRAY_SIZE(aic32x4_dapm_widgets
),
159 .dapm_routes
= aic32x4_dapm_routes
,
160 .num_dapm_routes
= ARRAY_SIZE(aic32x4_dapm_routes
),
163 static int mx27vis_aic32x4_probe(struct platform_device
*pdev
)
165 struct snd_mx27vis_platform_data
*pdata
= pdev
->dev
.platform_data
;
169 dev_err(&pdev
->dev
, "No platform data supplied\n");
173 mx27vis_amp_gain0_gpio
= pdata
->amp_gain0_gpio
;
174 mx27vis_amp_gain1_gpio
= pdata
->amp_gain1_gpio
;
175 mx27vis_amp_mutel_gpio
= pdata
->amp_mutel_gpio
;
176 mx27vis_amp_muter_gpio
= pdata
->amp_muter_gpio
;
178 mx27vis_aic32x4
.dev
= &pdev
->dev
;
179 ret
= snd_soc_register_card(&mx27vis_aic32x4
);
181 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n",
186 /* Connect SSI0 as clock slave to SSI1 external pins */
187 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0
,
188 IMX_AUDMUX_V1_PCR_SYN
|
189 IMX_AUDMUX_V1_PCR_TFSDIR
|
190 IMX_AUDMUX_V1_PCR_TCLKDIR
|
191 IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1
) |
192 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1
)
194 imx_audmux_v1_configure_port(MX27_AUDMUX_PPCR1_SSI_PINS_1
,
195 IMX_AUDMUX_V1_PCR_SYN
|
196 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0
)
202 static int mx27vis_aic32x4_remove(struct platform_device
*pdev
)
204 snd_soc_unregister_card(&mx27vis_aic32x4
);
209 static struct platform_driver mx27vis_aic32x4_audio_driver
= {
213 .probe
= mx27vis_aic32x4_probe
,
214 .remove
= mx27vis_aic32x4_remove
,
217 module_platform_driver(mx27vis_aic32x4_audio_driver
);
219 MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
220 MODULE_DESCRIPTION("ALSA SoC AIC32X4 mx27 visstrim");
221 MODULE_LICENSE("GPL");
222 MODULE_ALIAS("platform:mx27vis");