]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: sandbox: sound: Convert to use driver model
authorSimon Glass <sjg@chromium.org>
Mon, 10 Dec 2018 17:37:45 +0000 (10:37 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 13 Dec 2018 23:36:30 +0000 (16:36 -0700)
Update sandbox's device tree and config to use driver model for sound. Use
the double buffer for sound output so that we don't need to wait for the
sound to complete before returning.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/sdl.c
arch/sandbox/dts/sandbox.dts
arch/sandbox/include/asm/sdl.h

index 4dacdbf993f7eaf96924d76681141302f65e167f..32fa1fffc9b78b72ca59a6effcb4d2dc085a73c3 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <errno.h>
+#include <unistd.h>
 #include <linux/input.h>
 #include <SDL/SDL.h>
 #include <sound.h>
@@ -40,6 +41,7 @@ static struct sdl_info {
        bool inited;
        int cur_buf;
        struct buf_info buf[2];
+       bool running;
 } sdl;
 
 static void sandbox_sdl_poll_events(void)
@@ -331,6 +333,7 @@ int sandbox_sdl_sound_init(void)
        sdl.audio_active = true;
        sdl.sample_rate = wanted.freq;
        sdl.cur_buf = 0;
+       sdl.running = 0;
 
        return 0;
 
@@ -340,27 +343,39 @@ err:
        return -1;
 }
 
-int sandbox_sdl_sound_start(uint frequency)
+int sandbox_sdl_sound_play(const void *data, uint size)
 {
-       struct buf_info *buf = &sdl.buf[0];
+       struct buf_info *buf;
 
        if (!sdl.audio_active)
-               return -1;
-       sdl.frequency = frequency;
-       sound_create_square_wave(sdl.sample_rate, (unsigned short *)buf->data,
-                                buf->alloced, frequency);
+               return 0;
+
+       buf = &sdl.buf[0];
+       if (buf->size)
+               buf = &sdl.buf[1];
+       while (buf->size)
+               usleep(1000);
+
+       if (size > buf->alloced)
+               return -E2BIG;
+
+       memcpy(buf->data, data, size);
+       buf->size = size;
        buf->pos = 0;
-       buf->size = buf->alloced;
-       SDL_PauseAudio(0);
+       if (!sdl.running) {
+               SDL_PauseAudio(0);
+               sdl.running = 1;
+       }
 
        return 0;
 }
 
 int sandbox_sdl_sound_stop(void)
 {
-       if (!sdl.audio_active)
-               return -1;
-       SDL_PauseAudio(1);
+       if (sdl.running) {
+               SDL_PauseAudio(1);
+               sdl.running = 0;
+       }
 
        return 0;
 }
index ce3c88c221d233149f738c51c43f554db1360c38..ae3189ec8cfad3d5d1b35fa150d4706613b26c44 100644 (file)
                stdout-path = "/serial";
        };
 
+       audio: audio-codec {
+               compatible = "sandbox,audio-codec";
+               #sound-dai-cells = <1>;
+       };
+
        cros_ec: cros-ec {
                reg = <0 0>;
                u-boot,dm-pre-reloc;
                };
        };
 
+       i2s: i2s {
+               compatible = "sandbox,i2s";
+               #sound-dai-cells = <1>;
+       };
+
        lcd {
                u-boot,dm-pre-reloc;
                compatible = "sandbox,lcd-sdl";
                compatible = "sandbox,reset";
        };
 
+       sound {
+               compatible = "sandbox,sound";
+               cpu {
+                       sound-dai = <&i2s 0>;
+               };
+
+               codec {
+                       sound-dai = <&audio 0>;
+               };
+       };
+
        spi@0 {
                u-boot,dm-pre-reloc;
                #address-cells = <1>;
index 1c4380c592a7ddd6d2c8c23660a7065f714f7a43..0143ed9e621cce64aca411e790816573301fb69a 100644 (file)
@@ -68,6 +68,14 @@ int sandbox_sdl_sound_start(uint frequency);
  */
 int sandbox_sdl_sound_stop(void);
 
+/**
+ * sandbox_sdl_sound_play() - Play a sound
+ *
+ * @data:      Data to play (typically 16-bit)
+ * @count:     Number of bytes in data
+ */
+int sandbox_sdl_sound_play(const void *data, uint count);
+
 /**
  * sandbox_sdl_sound_init() - set up the sound system
  *