[U-Boot] [PATCH v2 33/34] x86: sound: Add sound support for samus (broadwell)

Simon Glass sjg at chromium.org
Sun Feb 17 03:25:06 UTC 2019


Add a sound driver for samus which ties together the audio codec and
I2S controller.

For now broadwell_sound is commented out in the makefile since we cannot
compile it without sound support enabled. The next commit fixes this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 drivers/sound/Makefile          |  2 +-
 drivers/sound/broadwell_sound.c | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/broadwell_sound.c

diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile
index fe3ccd6e5c6..452a5a17616 100644
--- a/drivers/sound/Makefile
+++ b/drivers/sound/Makefile
@@ -18,5 +18,5 @@ obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)	+= rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o
+obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o #broadwell_sound.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
diff --git a/drivers/sound/broadwell_sound.c b/drivers/sound/broadwell_sound.c
new file mode 100644
index 00000000000..6e083fe1f69
--- /dev/null
+++ b/drivers/sound/broadwell_sound.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sound for broadwell
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_SOUND
+
+#include <common.h>
+#include <audio_codec.h>
+#include <dm.h>
+#include <i2s.h>
+#include <sound.h>
+
+static int broadwell_sound_probe(struct udevice *dev)
+{
+	return sound_find_codec_i2s(dev);
+}
+
+static int broadwell_sound_setup(struct udevice *dev)
+{
+	struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
+	int ret;
+
+	if (uc_priv->setup_done)
+		return -EALREADY;
+	ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
+				     i2c_priv->samplingrate,
+				     i2c_priv->samplingrate * i2c_priv->rfs,
+				     i2c_priv->bitspersample,
+				     i2c_priv->channels);
+	if (ret)
+		return ret;
+	uc_priv->setup_done = true;
+
+	return 0;
+}
+
+static int broadwell_sound_play(struct udevice *dev, void *data, uint data_size)
+{
+	struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	return i2s_tx_data(uc_priv->i2s, data, data_size);
+}
+
+static const struct sound_ops broadwell_sound_ops = {
+	.setup		= broadwell_sound_setup,
+	.play		= broadwell_sound_play,
+};
+
+static const struct udevice_id broadwell_sound_ids[] = {
+	{ .compatible = "google,samus-sound" },
+	{ }
+};
+
+U_BOOT_DRIVER(broadwell_sound_drv) = {
+	.name		= "broadwell_sound",
+	.id		= UCLASS_SOUND,
+	.of_match	= broadwell_sound_ids,
+	.probe		= broadwell_sound_probe,
+	.ops		= &broadwell_sound_ops,
+};
-- 
2.21.0.rc0.258.g878e2cd30e-goog



More information about the U-Boot mailing list