summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/audio_codec.h48
-rw-r--r--include/dm/read.h58
-rw-r--r--include/dm/uclass-id.h3
-rw-r--r--include/i2s.h36
-rw-r--r--include/sound.h88
5 files changed, 203 insertions, 30 deletions
diff --git a/include/audio_codec.h b/include/audio_codec.h
new file mode 100644
index 0000000000..2587099546
--- /dev/null
+++ b/include/audio_codec.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#ifndef __AUDIO_CODEC_H__
+#define __AUDIO_CODEC_H__
+
+/*
+ * An audio codec turns digital data into sound with various parameters to
+ * control its operation.
+ */
+
+/* Operations for sound */
+struct audio_codec_ops {
+ /**
+ * set_params() - Set audio codec parameters
+ *
+ * @dev: Sound device
+ * @inteface: Interface number to use on codec
+ * @rate: Sampling rate in Hz
+ * @mclk_freq: Codec clock frequency in Hz
+ * @bits_per_sample: Must be 16 or 24
+ * @channels: Number of channels to use (1=mono, 2=stereo)
+ * @return 0 if OK, -ve on error
+ */
+ int (*set_params)(struct udevice *dev, int interface, int rate,
+ int mclk_freq, int bits_per_sample, uint channels);
+};
+
+#define audio_codec_get_ops(dev) ((struct audio_codec_ops *)(dev)->driver->ops)
+
+/**
+ * audio_codec_set_params() - Set audio codec parameters
+ *
+ * @dev: Sound device
+ * @inteface: Interface number to use on codec
+ * @rate: Sampling rate in Hz
+ * @mclk_freq: Codec clock frequency in Hz
+ * @bits_per_sample: Must be 16 or 24
+ * @channels: Number of channels to use (1=mono, 2=stereo)
+ * @return 0 if OK, -ve on error
+ */
+int audio_codec_set_params(struct udevice *dev, int interface, int rate,
+ int mclk_freq, int bits_per_sample, uint channels);
+
+#endif /* __AUDIO_CODEC_H__ */
diff --git a/include/dm/read.h b/include/dm/read.h
index efcbee15ec..389e30e7fb 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -65,6 +65,38 @@ int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
/**
+ * dev_read_s32() - read a signed 32-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * @return 0 if OK, -ve on error
+ */
+int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp);
+
+/**
+ * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * @return property value, or @def if not found
+ */
+int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
+
+/**
+ * dev_read_u32u() - read a 32-bit integer from a device's DT property
+ *
+ * This version uses a standard uint type.
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * @return 0 if OK, -ve on error
+ */
+int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp);
+
+/**
* dev_read_string() - Read a string from a device's DT property
*
* @dev: device to read DT property from
@@ -492,6 +524,32 @@ static inline int dev_read_u32_default(struct udevice *dev,
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
+static inline int dev_read_s32(struct udevice *dev,
+ const char *propname, s32 *outp)
+{
+ return ofnode_read_s32(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_s32_default(struct udevice *dev,
+ const char *propname, int def)
+{
+ return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
+}
+
+static inline int dev_read_u32u(struct udevice *dev,
+ const char *propname, uint *outp)
+{
+ u32 val;
+ int ret;
+
+ ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
+ if (ret)
+ return ret;
+ *outp = val;
+
+ return 0;
+}
+
static inline const char *dev_read_string(struct udevice *dev,
const char *propname)
{
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index e960e48b85..f3bafb3c63 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -29,6 +29,7 @@ enum uclass_id {
/* U-Boot uclasses start here - in alphabetical order */
UCLASS_ADC, /* Analog-to-digital converter */
UCLASS_AHCI, /* SATA disk controller */
+ UCLASS_AUDIO_CODEC, /* Audio codec with control and data path */
UCLASS_AXI, /* AXI bus */
UCLASS_BLK, /* Block device */
UCLASS_BOARD, /* Device information from hardware */
@@ -48,6 +49,7 @@ enum uclass_id {
UCLASS_I2C_EEPROM, /* I2C EEPROM device */
UCLASS_I2C_GENERIC, /* Generic I2C device */
UCLASS_I2C_MUX, /* I2C multiplexer */
+ UCLASS_I2S, /* I2S bus */
UCLASS_IDE, /* IDE device */
UCLASS_IRQ, /* Interrupt controller */
UCLASS_KEYBOARD, /* Keyboard input device */
@@ -82,6 +84,7 @@ enum uclass_id {
UCLASS_SERIAL, /* Serial UART */
UCLASS_SIMPLE_BUS, /* Bus with child devices */
UCLASS_SMEM, /* Shared memory interface */
+ UCLASS_SOUND, /* Playing simple sounds */
UCLASS_SPI, /* SPI bus */
UCLASS_SPI_FLASH, /* SPI flash */
UCLASS_SPI_GENERIC, /* Generic SPI flash target */
diff --git a/include/i2s.h b/include/i2s.h
index e6d45ec26d..28f6184811 100644
--- a/include/i2s.h
+++ b/include/i2s.h
@@ -76,7 +76,7 @@ struct i2s_reg {
};
/* This structure stores the i2s related information */
-struct i2stx_info {
+struct i2s_uc_priv {
unsigned int rfs; /* LR clock frame size */
unsigned int bfs; /* Bit slock frame size */
unsigned int audio_pll_clk; /* Audio pll frequency in Hz */
@@ -87,17 +87,41 @@ struct i2stx_info {
unsigned int id; /* I2S controller id */
};
+/* Operations for i2s devices */
+struct i2s_ops {
+ /**
+ * tx_data() - Transmit audio data
+ *
+ * @dev: I2C device
+ * @data: Data buffer to play
+ * @data_size: Size of data buffer in bytes
+ * @return 0 if OK, -ve on error
+ */
+ int (*tx_data)(struct udevice *dev, void *data, uint data_size);
+};
+
+#define i2s_get_ops(dev) ((struct i2s_ops *)(dev)->driver->ops)
+
+/**
+ * i2s_tx_data() - Transmit audio data
+ *
+ * @dev: I2C device
+ * @data: Data buffer to play
+ * @data_size: Size of data buffer in bytes
+ * @return 0 if OK, -ve on error
+ */
+int i2s_tx_data(struct udevice *dev, void *data, uint data_size);
+
/*
* Sends the given data through i2s tx
*
* @param pi2s_tx pointer of i2s transmitter parameter structure.
* @param data address of the data buffer
- * @param data_size array size of the int buffer (total size / size of int)
- *
+ * @param data_size size of the data (in bytes)
* @return int value 0 for success, -1 in case of error
*/
-int i2s_transfer_tx_data(struct i2stx_info *pi2s_tx, unsigned *data,
- unsigned long data_size);
+int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, void *data,
+ uint data_size);
/*
* Initialise i2s transmiter
@@ -106,6 +130,6 @@ int i2s_transfer_tx_data(struct i2stx_info *pi2s_tx, unsigned *data,
*
* @return int value 0 for success, -1 in case of error
*/
-int i2s_tx_init(struct i2stx_info *pi2s_tx);
+int i2s_tx_init(struct i2s_uc_priv *pi2s_tx);
#endif /* __I2S_H__ */
diff --git a/include/sound.h b/include/sound.h
index 77bfe6a93b..b7959cc260 100644
--- a/include/sound.h
+++ b/include/sound.h
@@ -8,14 +8,6 @@
#define __SOUND_H__
/* sound codec enum */
-enum en_sound_codec {
- CODEC_WM_8994,
- CODEC_WM_8995,
- CODEC_MAX_98095,
- CODEC_MAX
-};
-
-/* sound codec enum */
enum sound_compat {
AUDIO_COMPAT_SPI,
AUDIO_COMPAT_I2C,
@@ -25,33 +17,81 @@ enum sound_compat {
struct sound_codec_info {
int i2c_bus;
int i2c_dev_addr;
- enum en_sound_codec codec_type;
};
-/*
+/**
+ * struct sound_uc_priv - private uclass information about each sound device
+ *
+ * This is used to line the codec and i2s together
+ *
+ * @codec: Codec that is used for this sound device
+ * @i2s: I2S bus that is used for this sound device
+ * @setup_done: true if setup() has been called
+ */
+struct sound_uc_priv {
+ struct udevice *codec;
+ struct udevice *i2s;
+ int setup_done;
+};
+
+/**
* Generates square wave sound data for 1 second
*
- * @param sample_rate Sample rate in Hz
- * @param data data buffer pointer
- * @param size size of the buffer
- * @param freq frequency of the wave
+ * @sample_rate: Sample rate in Hz
+ * @data: data buffer pointer
+ * @size: size of the buffer in bytes
+ * @freq: frequency of the wave
+ * @channels: Number of channels to use
*/
void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
- uint freq);
+ uint freq, uint channels);
/*
- * Initialises audio sub system
- * @param blob Pointer of device tree node or NULL if none.
- * @return int value 0 for success, -1 for error
+ * The sound uclass brings together a data transport (currently only I2C) and a
+ * codec (currently connected over I2C).
*/
-int sound_init(const void *blob);
-/*
- * plays the pcm data buffer in pcm_data.h through i2s1 to make the
- * sine wave sound
+/* Operations for sound */
+struct sound_ops {
+ /**
+ * setup() - Set up to play a sound
+ */
+ int (*setup)(struct udevice *dev);
+
+ /**
+ * play() - Play a beep
+ *
+ * @dev: Sound device
+ * @data: Data buffer to play
+ * @data_size: Size of data buffer in bytes
+ * @return 0 if OK, -ve on error
+ */
+ int (*play)(struct udevice *dev, void *data, uint data_size);
+};
+
+#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops)
+
+/**
+ * setup() - Set up to play a sound
+ */
+int sound_setup(struct udevice *dev);
+
+/**
+ * play() - Play a beep
+ *
+ * @dev: Sound device
+ * @msecs: Duration of beep in milliseconds
+ * @frequency_hz: Frequency of the beep in Hertz
+ * @return 0 if OK, -ve on error
+ */
+int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
+
+/**
+ * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s
*
- * @return int 0 for success, -1 for error
+ * This finds the audio codec and i2s devices and puts them in the uclass's
+ * private data for this device.
*/
-int sound_play(uint32_t msec, uint32_t frequency);
+int sound_find_codec_i2s(struct udevice *dev);
#endif /* __SOUND__H__ */