Merge tag 'char-misc-5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[linux-2.6-block.git] / sound / soc / fsl / mx27vis-aic32x4.c
CommitLineData
1021ec41
AD
1// SPDX-License-Identifier: GPL-2.0+
2//
3// mx27vis-aic32x4.c
4//
5// Copyright 2011 Vista Silicon S.L.
6//
7// Author: Javier Martin <javier.martin@vista-silicon.com>
841a451f
JM
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <linux/device.h>
12#include <linux/i2c.h>
78adaeb2 13#include <linux/gpio.h>
d41789b2 14#include <linux/platform_data/asoc-mx27vis.h>
841a451f
JM
15#include <sound/core.h>
16#include <sound/pcm.h>
17#include <sound/soc.h>
18#include <sound/soc-dapm.h>
78adaeb2 19#include <sound/tlv.h>
841a451f 20#include <asm/mach-types.h>
841a451f
JM
21
22#include "../codecs/tlv320aic32x4.h"
23#include "imx-ssi.h"
3c77c29c 24#include "imx-audmux.h"
841a451f 25
78adaeb2
JM
26#define MX27VIS_AMP_GAIN 0
27#define MX27VIS_AMP_MUTE 1
28
78adaeb2
JM
29static int mx27vis_amp_gain;
30static int mx27vis_amp_mute;
d41789b2
SG
31static int mx27vis_amp_gain0_gpio;
32static int mx27vis_amp_gain1_gpio;
33static int mx27vis_amp_mutel_gpio;
34static int mx27vis_amp_muter_gpio;
78adaeb2 35
841a451f
JM
36static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
38{
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;
42 int ret;
841a451f
JM
43
44 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
45 25000000, SND_SOC_CLOCK_OUT);
46 if (ret) {
47 pr_err("%s: failed setting codec sysclk\n", __func__);
48 return ret;
49 }
50
51 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
52 SND_SOC_CLOCK_IN);
53 if (ret) {
54 pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
55 return ret;
56 }
57
58 return 0;
59}
60
5ace37bd 61static const struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
841a451f
JM
62 .hw_params = mx27vis_aic32x4_hw_params,
63};
64
78adaeb2
JM
65static int mx27vis_amp_set(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
67{
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;
72 int max = mc->max;
73
74 if (value > max)
75 return -EINVAL;
76
77 switch (reg) {
78 case MX27VIS_AMP_GAIN:
d41789b2
SG
79 gpio_set_value(mx27vis_amp_gain0_gpio, value & 1);
80 gpio_set_value(mx27vis_amp_gain1_gpio, value >> 1);
78adaeb2
JM
81 mx27vis_amp_gain = value;
82 break;
83 case MX27VIS_AMP_MUTE:
d41789b2
SG
84 gpio_set_value(mx27vis_amp_mutel_gpio, value & 1);
85 gpio_set_value(mx27vis_amp_muter_gpio, value >> 1);
78adaeb2
JM
86 mx27vis_amp_mute = value;
87 break;
88 }
89 return 0;
90}
91
92static int mx27vis_amp_get(struct snd_kcontrol *kcontrol,
93 struct snd_ctl_elem_value *ucontrol)
94{
95 struct soc_mixer_control *mc =
96 (struct soc_mixer_control *)kcontrol->private_value;
97 unsigned int reg = mc->reg;
98
99 switch (reg) {
100 case MX27VIS_AMP_GAIN:
101 ucontrol->value.integer.value[0] = mx27vis_amp_gain;
102 break;
103 case MX27VIS_AMP_MUTE:
104 ucontrol->value.integer.value[0] = mx27vis_amp_mute;
105 break;
106 }
107 return 0;
108}
109
110/* From 6dB to 24dB in steps of 6dB */
111static const DECLARE_TLV_DB_SCALE(mx27vis_amp_tlv, 600, 600, 0);
112
a6b44f16
JM
113static const struct snd_kcontrol_new mx27vis_aic32x4_controls[] = {
114 SOC_DAPM_PIN_SWITCH("External Mic"),
78adaeb2
JM
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),
a6b44f16
JM
119};
120
121static const struct snd_soc_dapm_widget aic32x4_dapm_widgets[] = {
122 SND_SOC_DAPM_MIC("External Mic", NULL),
123};
124
125static 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"},
133};
134
841a451f
JM
135static struct snd_soc_dai_link mx27vis_aic32x4_dai = {
136 .name = "tlv320aic32x4",
137 .stream_name = "TLV320AIC32X4",
138 .codec_dai_name = "tlv320aic32x4-hifi",
3b7d4638 139 .platform_name = "imx-ssi.0",
841a451f
JM
140 .codec_name = "tlv320aic32x4.0-0018",
141 .cpu_dai_name = "imx-ssi.0",
dea53bd3
LPC
142 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
143 SND_SOC_DAIFMT_CBM_CFM,
841a451f
JM
144 .ops = &mx27vis_aic32x4_snd_ops,
145};
146
147static struct snd_soc_card mx27vis_aic32x4 = {
148 .name = "visstrim_m10-audio",
6aff8ccb 149 .owner = THIS_MODULE,
841a451f
JM
150 .dai_link = &mx27vis_aic32x4_dai,
151 .num_links = 1,
a6b44f16
JM
152 .controls = mx27vis_aic32x4_controls,
153 .num_controls = ARRAY_SIZE(mx27vis_aic32x4_controls),
154 .dapm_widgets = aic32x4_dapm_widgets,
155 .num_dapm_widgets = ARRAY_SIZE(aic32x4_dapm_widgets),
156 .dapm_routes = aic32x4_dapm_routes,
157 .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
841a451f
JM
158};
159
a0a3d518 160static int mx27vis_aic32x4_probe(struct platform_device *pdev)
841a451f 161{
d41789b2 162 struct snd_mx27vis_platform_data *pdata = pdev->dev.platform_data;
841a451f
JM
163 int ret;
164
d41789b2
SG
165 if (!pdata) {
166 dev_err(&pdev->dev, "No platform data supplied\n");
167 return -EINVAL;
168 }
169
170 mx27vis_amp_gain0_gpio = pdata->amp_gain0_gpio;
171 mx27vis_amp_gain1_gpio = pdata->amp_gain1_gpio;
172 mx27vis_amp_mutel_gpio = pdata->amp_mutel_gpio;
173 mx27vis_amp_muter_gpio = pdata->amp_muter_gpio;
174
5ec65ee5
FE
175 mx27vis_aic32x4.dev = &pdev->dev;
176 ret = snd_soc_register_card(&mx27vis_aic32x4);
841a451f 177 if (ret) {
5ec65ee5
FE
178 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
179 ret);
180 return ret;
841a451f
JM
181 }
182
183 /* Connect SSI0 as clock slave to SSI1 external pins */
af4872fb
SG
184 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
185 IMX_AUDMUX_V1_PCR_SYN |
186 IMX_AUDMUX_V1_PCR_TFSDIR |
187 IMX_AUDMUX_V1_PCR_TCLKDIR |
188 IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1) |
189 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1)
841a451f 190 );
af4872fb
SG
191 imx_audmux_v1_configure_port(MX27_AUDMUX_PPCR1_SSI_PINS_1,
192 IMX_AUDMUX_V1_PCR_SYN |
193 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
841a451f
JM
194 );
195
196 return ret;
197}
198
a0a3d518 199static int mx27vis_aic32x4_remove(struct platform_device *pdev)
841a451f 200{
5ec65ee5
FE
201 snd_soc_unregister_card(&mx27vis_aic32x4);
202
203 return 0;
841a451f
JM
204}
205
5ec65ee5
FE
206static struct platform_driver mx27vis_aic32x4_audio_driver = {
207 .driver = {
208 .name = "mx27vis",
5ec65ee5
FE
209 },
210 .probe = mx27vis_aic32x4_probe,
a0a3d518 211 .remove = mx27vis_aic32x4_remove,
5ec65ee5
FE
212};
213
214module_platform_driver(mx27vis_aic32x4_audio_driver);
841a451f
JM
215
216MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
217MODULE_DESCRIPTION("ALSA SoC AIC32X4 mx27 visstrim");
218MODULE_LICENSE("GPL");
5ec65ee5 219MODULE_ALIAS("platform:mx27vis");