aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/sh
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2014-08-01 06:10:47 -0400
committerMark Brown <broonie@linaro.org>2014-08-01 13:46:25 -0400
commit486b09c750e58777976ad74a37de7b4252630332 (patch)
treec57309d9570a03816fbcb511c54cb682fa379e34 /sound/soc/sh
parent1a7889ca8aba333d7c74fad543d692c31bc7f280 (diff)
ASoC: rsnd: tidyup DVC control method
DVC can use Volume and Mute control, and these control methods doesn't have much difference. This patch cleanup current method, and it will be used for Mute control. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/sh')
-rw-r--r--sound/soc/sh/rcar/dvc.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index 9096fb03d001..12a0a2068d34 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -20,7 +20,7 @@ struct rsnd_dvc {
20 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */ 20 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */
21 struct rsnd_mod mod; 21 struct rsnd_mod mod;
22 struct clk *clk; 22 struct clk *clk;
23 long volume[RSND_DVC_VOLUME_NUM]; 23 u8 volume[RSND_DVC_VOLUME_NUM];
24}; 24};
25 25
26#define rsnd_mod_to_dvc(_mod) \ 26#define rsnd_mod_to_dvc(_mod) \
@@ -151,12 +151,11 @@ static int rsnd_dvc_volume_info(struct snd_kcontrol *kctrl,
151static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl, 151static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl,
152 struct snd_ctl_elem_value *ucontrol) 152 struct snd_ctl_elem_value *ucontrol)
153{ 153{
154 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl); 154 u8 *val = (u8 *)kctrl->private_value;
155 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
156 int i; 155 int i;
157 156
158 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) 157 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++)
159 ucontrol->value.integer.value[i] = dvc->volume[i]; 158 ucontrol->value.integer.value[i] = val[i];
160 159
161 return 0; 160 return 0;
162} 161}
@@ -165,47 +164,38 @@ static int rsnd_dvc_volume_put(struct snd_kcontrol *kctrl,
165 struct snd_ctl_elem_value *ucontrol) 164 struct snd_ctl_elem_value *ucontrol)
166{ 165{
167 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl); 166 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
168 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); 167 u8 *val = (u8 *)kctrl->private_value;
169 int i, change = 0; 168 int i, change = 0;
170 169
171 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) { 170 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) {
172 if (ucontrol->value.integer.value[i] < 0 || 171 change |= (ucontrol->value.integer.value[i] != val[i]);
173 ucontrol->value.integer.value[i] > RSND_DVC_VOLUME_MAX) 172 val[i] = ucontrol->value.integer.value[i];
174 return -EINVAL;
175
176 change |= (ucontrol->value.integer.value[i] != dvc->volume[i]);
177 } 173 }
178 174
179 if (change) { 175 if (change)
180 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++)
181 dvc->volume[i] = ucontrol->value.integer.value[i];
182
183 rsnd_dvc_volume_update(mod); 176 rsnd_dvc_volume_update(mod);
184 }
185 177
186 return change; 178 return change;
187} 179}
188 180
189static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, 181static int __rsnd_dvc_pcm_new(struct rsnd_mod *mod,
190 struct rsnd_dai *rdai, 182 struct rsnd_dai *rdai,
191 struct snd_soc_pcm_runtime *rtd) 183 struct snd_soc_pcm_runtime *rtd,
184 const unsigned char *name,
185 u8 *private)
192{ 186{
193 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
194 struct snd_card *card = rtd->card->snd_card; 187 struct snd_card *card = rtd->card->snd_card;
195 struct snd_kcontrol *kctrl; 188 struct snd_kcontrol *kctrl;
196 static struct snd_kcontrol_new knew = { 189 struct snd_kcontrol_new knew = {
197 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
191 .name = name,
198 .info = rsnd_dvc_volume_info, 192 .info = rsnd_dvc_volume_info,
199 .get = rsnd_dvc_volume_get, 193 .get = rsnd_dvc_volume_get,
200 .put = rsnd_dvc_volume_put, 194 .put = rsnd_dvc_volume_put,
195 .private_value = (unsigned long)private,
201 }; 196 };
202 int ret; 197 int ret;
203 198
204 if (rsnd_dai_is_play(rdai, io))
205 knew.name = "Playback Volume";
206 else
207 knew.name = "Capture Volume";
208
209 kctrl = snd_ctl_new1(&knew, mod); 199 kctrl = snd_ctl_new1(&knew, mod);
210 if (!kctrl) 200 if (!kctrl)
211 return -ENOMEM; 201 return -ENOMEM;
@@ -217,6 +207,25 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
217 return 0; 207 return 0;
218} 208}
219 209
210static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
211 struct rsnd_dai *rdai,
212 struct snd_soc_pcm_runtime *rtd)
213{
214 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
215 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
216 int ret;
217
218 /* Volume */
219 ret = __rsnd_dvc_pcm_new(mod, rdai, rtd,
220 rsnd_dai_is_play(rdai, io) ?
221 "DVC Out Playback Volume" : "DVC In Capture Volume",
222 dvc->volume);
223 if (ret < 0)
224 return ret;
225
226 return 0;
227}
228
220static struct rsnd_mod_ops rsnd_dvc_ops = { 229static struct rsnd_mod_ops rsnd_dvc_ops = {
221 .name = DVC_NAME, 230 .name = DVC_NAME,
222 .probe = rsnd_dvc_probe_gen2, 231 .probe = rsnd_dvc_probe_gen2,