summaryrefslogtreecommitdiffstats
path: root/cmd/sound.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-12-10 10:37:36 -0700
committerSimon Glass <sjg@chromium.org>2018-12-13 16:32:49 -0700
commitd4901898654b664c41d8a03afc0e0fbf531b5812 (patch)
treee757add0074c0f4c193a97157abaa70e7e56ec2e /cmd/sound.c
parente625b68b04a400ba377ec0a5b958bde0bc6244ff (diff)
downloadu-boot-d4901898654b664c41d8a03afc0e0fbf531b5812.tar.gz
u-boot-d4901898654b664c41d8a03afc0e0fbf531b5812.tar.xz
u-boot-d4901898654b664c41d8a03afc0e0fbf531b5812.zip
dm: sound: Create a uclass for sound
The sound driver pulls together the audio codec and i2s drivers in order to actually make sounds. It supports setup() and play() methods. The sound_find_codec_i2s() function allows locating the linked codec and i2s devices. They can be referred to from uclass-private data. Add a uclass and a test for sound. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd/sound.c')
-rw-r--r--cmd/sound.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/cmd/sound.c b/cmd/sound.c
index d1cbc14f8d..77f5152925 100644
--- a/cmd/sound.c
+++ b/cmd/sound.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <command.h>
+#include <dm.h>
#include <fdtdec.h>
#include <sound.h>
@@ -14,11 +15,20 @@ DECLARE_GLOBAL_DATA_PTR;
/* Initilaise sound subsystem */
static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
+#ifdef CONFIG_DM_SOUND
+ struct udevice *dev;
+#endif
int ret;
+#ifdef CONFIG_DM_SOUND
+ ret = uclass_first_device_err(UCLASS_SOUND, &dev);
+ if (!ret)
+ ret = sound_setup(dev);
+#else
ret = sound_init(gd->fdt_blob);
+#endif
if (ret) {
- printf("Initialise Audio driver failed\n");
+ printf("Initialise Audio driver failed (ret=%d)\n", ret);
return CMD_RET_FAILURE;
}
@@ -28,6 +38,9 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
/* play sound from buffer */
static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
+#ifdef CONFIG_DM_SOUND
+ struct udevice *dev;
+#endif
int ret = 0;
int msec = 1000;
int freq = 400;
@@ -37,9 +50,15 @@ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
if (argc > 2)
freq = simple_strtoul(argv[2], NULL, 10);
+#ifdef CONFIG_DM_SOUND
+ ret = uclass_first_device_err(UCLASS_SOUND, &dev);
+ if (!ret)
+ ret = sound_beep(dev, msec, freq);
+#else
ret = sound_play(msec, freq);
+#endif
if (ret) {
- printf("play failed");
+ printf("Sound device failed to play (err=%d)\n", ret);
return CMD_RET_FAILURE;
}