Lines Matching +full:bt +full:- +full:pcm +full:- +full:int +full:- +full:params
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/mfd/wl1273-core.h>
13 #include <sound/pcm.h>
26 unsigned int channels;
29 static int snd_wl1273_fm_set_i2s_mode(struct wl1273_core *core, in snd_wl1273_fm_set_i2s_mode()
30 int rate, int width) in snd_wl1273_fm_set_i2s_mode()
32 struct device *dev = &core->client->dev; in snd_wl1273_fm_set_i2s_mode()
33 int r = 0; in snd_wl1273_fm_set_i2s_mode()
39 mutex_lock(&core->lock); in snd_wl1273_fm_set_i2s_mode()
41 mode = core->i2s_mode & ~WL1273_IS2_WIDTH & ~WL1273_IS2_RATE; in snd_wl1273_fm_set_i2s_mode()
70 r = -EINVAL; in snd_wl1273_fm_set_i2s_mode()
104 r = -EINVAL; in snd_wl1273_fm_set_i2s_mode()
109 dev_dbg(dev, "core->i2s_mode: 0x%04x\n", core->i2s_mode); in snd_wl1273_fm_set_i2s_mode()
112 if (core->i2s_mode != mode) { in snd_wl1273_fm_set_i2s_mode()
113 r = core->write(core, WL1273_I2S_MODE_CONFIG_SET, mode); in snd_wl1273_fm_set_i2s_mode()
117 core->i2s_mode = mode; in snd_wl1273_fm_set_i2s_mode()
118 r = core->write(core, WL1273_AUDIO_ENABLE, in snd_wl1273_fm_set_i2s_mode()
124 mutex_unlock(&core->lock); in snd_wl1273_fm_set_i2s_mode()
129 static int snd_wl1273_fm_set_channel_number(struct wl1273_core *core, in snd_wl1273_fm_set_channel_number()
130 int channel_number) in snd_wl1273_fm_set_channel_number()
132 struct device *dev = &core->client->dev; in snd_wl1273_fm_set_channel_number()
133 int r = 0; in snd_wl1273_fm_set_channel_number()
137 mutex_lock(&core->lock); in snd_wl1273_fm_set_channel_number()
139 if (core->channel_number == channel_number) in snd_wl1273_fm_set_channel_number()
142 if (channel_number == 1 && core->mode == WL1273_MODE_RX) in snd_wl1273_fm_set_channel_number()
143 r = core->write(core, WL1273_MOST_MODE_SET, WL1273_RX_MONO); in snd_wl1273_fm_set_channel_number()
144 else if (channel_number == 1 && core->mode == WL1273_MODE_TX) in snd_wl1273_fm_set_channel_number()
145 r = core->write(core, WL1273_MONO_SET, WL1273_TX_MONO); in snd_wl1273_fm_set_channel_number()
146 else if (channel_number == 2 && core->mode == WL1273_MODE_RX) in snd_wl1273_fm_set_channel_number()
147 r = core->write(core, WL1273_MOST_MODE_SET, WL1273_RX_STEREO); in snd_wl1273_fm_set_channel_number()
148 else if (channel_number == 2 && core->mode == WL1273_MODE_TX) in snd_wl1273_fm_set_channel_number()
149 r = core->write(core, WL1273_MONO_SET, WL1273_TX_STEREO); in snd_wl1273_fm_set_channel_number()
151 r = -EINVAL; in snd_wl1273_fm_set_channel_number()
153 mutex_unlock(&core->lock); in snd_wl1273_fm_set_channel_number()
158 static int snd_wl1273_get_audio_route(struct snd_kcontrol *kcontrol, in snd_wl1273_get_audio_route()
164 ucontrol->value.enumerated.item[0] = wl1273->mode; in snd_wl1273_get_audio_route()
174 static const char * const wl1273_audio_route[] = { "Bt", "FmRx", "FmTx" };
176 static int snd_wl1273_set_audio_route(struct snd_kcontrol *kcontrol, in snd_wl1273_set_audio_route()
182 if (wl1273->mode == ucontrol->value.enumerated.item[0]) in snd_wl1273_set_audio_route()
187 return -EPERM; in snd_wl1273_set_audio_route()
189 if (ucontrol->value.enumerated.item[0] >= ARRAY_SIZE(wl1273_audio_route)) in snd_wl1273_set_audio_route()
190 return -EINVAL; in snd_wl1273_set_audio_route()
192 wl1273->mode = ucontrol->value.enumerated.item[0]; in snd_wl1273_set_audio_route()
199 static int snd_wl1273_fm_audio_get(struct snd_kcontrol *kcontrol, in snd_wl1273_fm_audio_get()
205 dev_dbg(component->dev, "%s: enter.\n", __func__); in snd_wl1273_fm_audio_get()
207 ucontrol->value.enumerated.item[0] = wl1273->core->audio_mode; in snd_wl1273_fm_audio_get()
212 static int snd_wl1273_fm_audio_put(struct snd_kcontrol *kcontrol, in snd_wl1273_fm_audio_put()
217 int val, r = 0; in snd_wl1273_fm_audio_put()
219 dev_dbg(component->dev, "%s: enter.\n", __func__); in snd_wl1273_fm_audio_put()
221 val = ucontrol->value.enumerated.item[0]; in snd_wl1273_fm_audio_put()
222 if (wl1273->core->audio_mode == val) in snd_wl1273_fm_audio_put()
225 r = wl1273->core->set_audio(wl1273->core, val); in snd_wl1273_fm_audio_put()
236 static int snd_wl1273_fm_volume_get(struct snd_kcontrol *kcontrol, in snd_wl1273_fm_volume_get()
242 dev_dbg(component->dev, "%s: enter.\n", __func__); in snd_wl1273_fm_volume_get()
244 ucontrol->value.integer.value[0] = wl1273->core->volume; in snd_wl1273_fm_volume_get()
249 static int snd_wl1273_fm_volume_put(struct snd_kcontrol *kcontrol, in snd_wl1273_fm_volume_put()
254 int r; in snd_wl1273_fm_volume_put()
256 dev_dbg(component->dev, "%s: enter.\n", __func__); in snd_wl1273_fm_volume_put()
258 r = wl1273->core->set_volume(wl1273->core, in snd_wl1273_fm_volume_put()
259 ucontrol->value.integer.value[0]); in snd_wl1273_fm_volume_put()
287 static int wl1273_startup(struct snd_pcm_substream *substream, in wl1273_startup()
290 struct snd_soc_component *component = dai->component; in wl1273_startup()
293 switch (wl1273->mode) { in wl1273_startup()
295 snd_pcm_hw_constraint_single(substream->runtime, in wl1273_startup()
297 snd_pcm_hw_constraint_single(substream->runtime, in wl1273_startup()
301 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in wl1273_startup()
303 return -EINVAL; in wl1273_startup()
307 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in wl1273_startup()
309 return -EINVAL; in wl1273_startup()
313 return -EINVAL; in wl1273_startup()
319 static int wl1273_hw_params(struct snd_pcm_substream *substream, in wl1273_hw_params()
320 struct snd_pcm_hw_params *params, in wl1273_hw_params() argument
323 struct wl1273_priv *wl1273 = snd_soc_component_get_drvdata(dai->component); in wl1273_hw_params()
324 struct wl1273_core *core = wl1273->core; in wl1273_hw_params()
325 unsigned int rate, width, r; in wl1273_hw_params()
327 if (params_width(params) != 16) { in wl1273_hw_params()
328 dev_err(dai->dev, "%d bits/sample not supported\n", in wl1273_hw_params()
329 params_width(params)); in wl1273_hw_params()
330 return -EINVAL; in wl1273_hw_params()
333 rate = params_rate(params); in wl1273_hw_params()
334 width = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; in wl1273_hw_params()
336 if (wl1273->mode == WL1273_MODE_BT) { in wl1273_hw_params()
338 pr_err("Rate %d not supported.\n", params_rate(params)); in wl1273_hw_params()
339 return -EINVAL; in wl1273_hw_params()
342 if (params_channels(params) != 1) { in wl1273_hw_params()
344 return -EINVAL; in wl1273_hw_params()
350 if (wl1273->mode == WL1273_MODE_FM_TX && in wl1273_hw_params()
351 substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in wl1273_hw_params()
353 return -EINVAL; in wl1273_hw_params()
356 if (wl1273->mode == WL1273_MODE_FM_RX && in wl1273_hw_params()
357 substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in wl1273_hw_params()
359 return -EINVAL; in wl1273_hw_params()
362 if (wl1273->mode != WL1273_MODE_FM_RX && in wl1273_hw_params()
363 wl1273->mode != WL1273_MODE_FM_TX) { in wl1273_hw_params()
364 pr_err("Unexpected mode: %d.\n", wl1273->mode); in wl1273_hw_params()
365 return -EINVAL; in wl1273_hw_params()
372 wl1273->channels = params_channels(params); in wl1273_hw_params()
373 r = snd_wl1273_fm_set_channel_number(core, wl1273->channels); in wl1273_hw_params()
386 .name = "wl1273-fm",
403 int wl1273_get_format(struct snd_soc_component *component, unsigned int *fmt) in wl1273_get_format()
408 return -EINVAL; in wl1273_get_format()
412 switch (wl1273->mode) { in wl1273_get_format()
427 return -EINVAL; in wl1273_get_format()
434 static int wl1273_probe(struct snd_soc_component *component) in wl1273_probe()
436 struct wl1273_core **core = component->dev->platform_data; in wl1273_probe()
439 dev_dbg(component->dev, "%s.\n", __func__); in wl1273_probe()
442 dev_err(component->dev, "Platform data is missing.\n"); in wl1273_probe()
443 return -EINVAL; in wl1273_probe()
448 return -ENOMEM; in wl1273_probe()
450 wl1273->mode = WL1273_MODE_BT; in wl1273_probe()
451 wl1273->core = *core; in wl1273_probe()
462 dev_dbg(component->dev, "%s\n", __func__); in wl1273_remove()
480 static int wl1273_platform_probe(struct platform_device *pdev) in wl1273_platform_probe()
482 return devm_snd_soc_register_component(&pdev->dev, in wl1273_platform_probe()
487 MODULE_ALIAS("platform:wl1273-codec");
491 .name = "wl1273-codec",