summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2021-01-31 21:18:41 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-02-08 10:57:05 +0100
commit78dd61b47e5d93240b3d112c51fa3b1896c4f6e6 (patch)
treedd5c0335559bf6099d57c44816fc7ad327928c87 /include
parent12ad41f91f1824eb141e368294d97860644ab777 (diff)
downloadbarebox-78dd61b47e5d93240b3d112c51fa3b1896c4f6e6.tar.gz
barebox-78dd61b47e5d93240b3d112c51fa3b1896c4f6e6.tar.xz
drivers: add sound card driver support
Add driver core boilerplate for sound support in barebox. Using the provided API in <sound.h>, consumers can play beeps for a fixed duration of time. Playing beeps is not blocking and new beeps can be enqueued while one is already playing. They will be played in succession by a poller, which will also turn off the sound card when the beep tune is over. API is also available for blocking until all beeps are played and for cancelling an underway beep tune. The API could be later extended for arbitrary PCM audio, should the need arise. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/poller.h4
-rw-r--r--include/sound.h45
2 files changed, 49 insertions, 0 deletions
diff --git a/include/poller.h b/include/poller.h
index 886557252b..db773265b2 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -34,6 +34,10 @@ int poller_async_unregister(struct poller_async *pa);
int poller_call_async(struct poller_async *pa, uint64_t delay_ns,
void (*fn)(void *), void *ctx);
int poller_async_cancel(struct poller_async *pa);
+static inline bool poller_async_active(struct poller_async *pa)
+{
+ return pa->active;
+}
#ifdef CONFIG_POLLER
void poller_call(void);
diff --git a/include/sound.h b/include/sound.h
new file mode 100644
index 0000000000..f5124aebbd
--- /dev/null
+++ b/include/sound.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: © 2021 Ahmad Fatoum */
+
+#ifndef __SOUND_H_
+#define __SOUND_H_
+
+#include <linux/list.h>
+#include <poller.h>
+
+#define BELL_DEFAULT_FREQUENCY -1
+
+struct sound_card {
+ const char *name;
+ int bell_frequency;
+ int (*beep)(struct sound_card *, unsigned freq, unsigned us);
+
+ /* private */
+ struct list_head list;
+ struct list_head tune;
+ struct poller_async poller;
+};
+
+int sound_card_register(struct sound_card *card);
+int sound_card_beep_wait(struct sound_card *card, unsigned timeout_us);
+int sound_card_beep(struct sound_card *card, int freq, unsigned int us);
+int sound_card_beep_cancel(struct sound_card *card);
+
+struct sound_card *sound_card_get_default(void);
+
+static inline int beep(int freq, unsigned us)
+{
+ return sound_card_beep(sound_card_get_default(), freq, us);
+}
+
+static inline int beep_wait(unsigned timeout_us)
+{
+ return sound_card_beep_wait(sound_card_get_default(), timeout_us);
+}
+
+static inline int beep_cancel(void)
+{
+ return sound_card_beep_cancel(sound_card_get_default());
+}
+
+#endif