summaryrefslogtreecommitdiff
path: root/drivers/sound
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-12-10 20:37:33 +0300
committerSimon Glass <sjg@chromium.org>2018-12-14 02:32:49 +0300
commitce6d99a056ebc9ad329521ca3660f6cb298a7666 (patch)
treee297e74248dba6d54656e7899a4bd0e134c1dd9d /drivers/sound
parent45863db5a97360b6843a0488621342819e9a6e62 (diff)
downloadu-boot-ce6d99a056ebc9ad329521ca3660f6cb298a7666.tar.xz
dm: sound: Create a uclass for audio codecs
An audio codec provides a way to convert digital data to sound and vice versa. Add a simple uclass which just supports setting the parameters for the codec. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/sound')
-rw-r--r--drivers/sound/Makefile1
-rw-r--r--drivers/sound/codec-uclass.c26
-rw-r--r--drivers/sound/sandbox.c55
3 files changed, 82 insertions, 0 deletions
diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile
index 696c5aecbe..ae5fabed84 100644
--- a/drivers/sound/Makefile
+++ b/drivers/sound/Makefile
@@ -4,6 +4,7 @@
# R. Chandrasekar <rcsekar@samsung.com>
obj-$(CONFIG_SOUND) += sound.o
+obj-$(CONFIG_DM_SOUND) += codec-uclass.o
obj-$(CONFIG_I2S) += sound-i2s.o
obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o
obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o
diff --git a/drivers/sound/codec-uclass.c b/drivers/sound/codec-uclass.c
new file mode 100644
index 0000000000..1ec77acfc1
--- /dev/null
+++ b/drivers/sound/codec-uclass.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <audio_codec.h>
+
+int audio_codec_set_params(struct udevice *dev, int interface, int rate,
+ int mclk_freq, int bits_per_sample, uint channels)
+{
+ struct audio_codec_ops *ops = audio_codec_get_ops(dev);
+
+ if (!ops->set_params)
+ return -ENOSYS;
+
+ return ops->set_params(dev, interface, rate, mclk_freq, bits_per_sample,
+ channels);
+}
+
+UCLASS_DRIVER(audio_codec) = {
+ .id = UCLASS_AUDIO_CODEC,
+ .name = "audio-codec",
+};
diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c
index 94eff54282..d24eb9ae9c 100644
--- a/drivers/sound/sandbox.c
+++ b/drivers/sound/sandbox.c
@@ -4,9 +4,19 @@
*/
#include <common.h>
+#include <dm.h>
+#include <audio_codec.h>
#include <asm/sound.h>
#include <asm/sdl.h>
+struct sandbox_codec_priv {
+ int interface;
+ int rate;
+ int mclk_freq;
+ int bits_per_sample;
+ uint channels;
+};
+
int sound_play(uint32_t msec, uint32_t frequency)
{
sandbox_sdl_sound_start(frequency);
@@ -20,3 +30,48 @@ int sound_init(const void *blob)
{
return sandbox_sdl_sound_init();
}
+
+void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
+ int *mclk_freqp, int *bits_per_samplep,
+ uint *channelsp)
+{
+ struct sandbox_codec_priv *priv = dev_get_priv(dev);
+
+ *interfacep = priv->interface;
+ *ratep = priv->rate;
+ *mclk_freqp = priv->mclk_freq;
+ *bits_per_samplep = priv->bits_per_sample;
+ *channelsp = priv->channels;
+}
+
+static int sandbox_codec_set_params(struct udevice *dev, int interface,
+ int rate, int mclk_freq,
+ int bits_per_sample, uint channels)
+{
+ struct sandbox_codec_priv *priv = dev_get_priv(dev);
+
+ priv->interface = interface;
+ priv->rate = rate;
+ priv->mclk_freq = mclk_freq;
+ priv->bits_per_sample = bits_per_sample;
+ priv->channels = channels;
+
+ return 0;
+}
+
+static const struct audio_codec_ops sandbox_codec_ops = {
+ .set_params = sandbox_codec_set_params,
+};
+
+static const struct udevice_id sandbox_codec_ids[] = {
+ { .compatible = "sandbox,audio-codec" },
+ { }
+};
+
+U_BOOT_DRIVER(sandbox_codec) = {
+ .name = "sandbox_codec",
+ .id = UCLASS_AUDIO_CODEC,
+ .of_match = sandbox_codec_ids,
+ .ops = &sandbox_codec_ops,
+ .priv_auto_alloc_size = sizeof(struct sandbox_codec_priv),
+};