Skip to contentSkip to conversation

dm: sound: Convert to driver model

PATCH New Simon Glass 2 participants 45 messages Dec 10, 2018 – Dec 14, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover dm: sound: Convert to driver model

The sound subsystem has never been converted to driver model. It is is a little bit complicated since it needs an audio codec, an i2s device and a sound device to bring them together.

Sound is the main subsystem holding back removal of CONFIG_DM_I2C_COMPAT.

This series takes a stab at doing the conversion. This is tested on snow, pit and pi. I do not have smdk5250/5420 or arndale to test with.

Changes in v2:
- Add fix for pit and pi also
- Fix up tabs in this commit instead of the later one
- Use Kconfig instead of defconfig to define DM_SOUND
- Update 'init' command to print the error code
- Correct conversion for pit
- Use void * for i2c and sound data
- Add new patch to move common code out of maxim98095
- Add new patch with support for max98090
- Correct conversion for pit and pi, updating commit message
- Add new patch to convert sandbox to use driver model
- Drop CONFIG_DM_SOUND from all defconfig files
- Fix up sandbox files to remove old code
- Update the rest of the samsung boards
- Remove unused sandbox code also
- Drop patches previously applied
- Add new patch to fix license headers
- Add new patch to tidy up error codes in max98095
- Add new patch to use the correct number of channels for sound

Simon Glass (22):
dm: sound: exynos: Correct codec bus addresses
dm: sound: Create an option to use driver model for sound
dm: sound: Rename samsung_i2s_priv to i2s_uc_priv
dm: sound: Create a uclass for audio codecs
dm: sound: Create a uclass for i2s
dm: sandbox: Update sound to use two buffers
dm: sound: Create a uclass for sound
dm: core: Add a function to read into a unsigned int
dm: sound: Start i2c IDs from 0
dm: sound: Add conversion to driver model
exynos: Add proid_is_exynos542x() for common 542x
exynos: Add support for exynos5420 i2s pinmux
dm: sound: Move common code out of maxim98095
dm: sound: exynos: Add support for max98090
dm: exynos: sound: Convert to use driver model
dm: sandbox: sound: Convert to use driver model
dm: exynos: Drop CONFIG_DM_I2C_COMPAT
dm: sound: Complete migration to driver model
dm: sound: Fix license headers
dm: sound: max98095: Tidy up error codes
dm: sandbox: Allow selection of sample rate and channels
dm: sound: Use the correct number of channels for sound

 arch/Kconfig                              |   1 +
 arch/arm/dts/exynos5250-smdk5250.dts      |  21 +-
 arch/arm/dts/exynos5250-snow.dts          |  23 +-
 arch/arm/dts/exynos5250-spring.dts        |  24 +-
 arch/arm/dts/exynos5250.dtsi              |  15 +-
 arch/arm/dts/exynos5420-peach-pit.dts     |  24 +-
 arch/arm/dts/exynos5420-smdk5420.dts      |  21 +-
 arch/arm/dts/exynos54xx.dtsi              |  14 +
 arch/arm/dts/exynos5800-peach-pi.dts      |  24 +-
 arch/arm/mach-exynos/clock.c              |  31 +-
 arch/arm/mach-exynos/clock_init_exynos5.c |   2 +-
 arch/arm/mach-exynos/common_setup.h       |   4 +-
 arch/arm/mach-exynos/include/mach/clock.h |   3 +
 arch/arm/mach-exynos/include/mach/cpu.h   |   4 +-
 arch/arm/mach-exynos/include/mach/gpio.h  |   4 +-
 arch/arm/mach-exynos/pinmux.c             |  19 +-
 arch/arm/mach-exynos/power.c              |   2 +-
 arch/sandbox/cpu/sdl.c                    | 123 ++--
 arch/sandbox/dts/sandbox.dts              |  21 +
 arch/sandbox/dts/test.dts                 |  23 +
 arch/sandbox/include/asm/sdl.h            |  19 +-
 arch/sandbox/include/asm/sound.h          |  13 -
 arch/sandbox/include/asm/test.h           |  40 ++
 cmd/sound.c                               |  15 +-
 configs/peach-pi_defconfig                |   3 +-
 configs/peach-pit_defconfig               |   3 +-
 configs/smdk5250_defconfig                |   1 -
 configs/smdk5420_defconfig                |   1 -
 configs/snow_defconfig                    |   1 -
 configs/spring_defconfig                  |   1 -
 drivers/core/read.c                       |  23 +
 drivers/sound/Kconfig                     |   8 +
 drivers/sound/Makefile                    |   8 +-
 drivers/sound/codec-uclass.c              |  26 +
 drivers/sound/i2s-uclass.c                |  25 +
 drivers/sound/max98090.c                  | 377 ++++++++++++
 drivers/sound/max98090.h                  | 663 ++++++++++++++++++++++
 drivers/sound/max98095.c                  | 313 ++++------
 drivers/sound/max98095.h                  |   9 +-
 drivers/sound/maxim_codec.c               |  87 +++
 drivers/sound/maxim_codec.h               |  67 +++
 drivers/sound/samsung-i2s.c               | 113 +++-
 drivers/sound/samsung_sound.c             | 104 ++++
 drivers/sound/sandbox.c                   | 177 +++++-
 drivers/sound/sound-i2s.c                 | 208 -------
 drivers/sound/sound-uclass.c              | 127 +++++
 drivers/sound/sound.c                     |  11 +-
 drivers/sound/wm8994.c                    | 114 ++--
 drivers/sound/wm8994.h                    |   2 +-
 include/audio_codec.h                     |  48 ++
 include/dm/read.h                         |  58 ++
 include/dm/uclass-id.h                    |   3 +
 include/i2s.h                             |  36 +-
 include/sound.h                           |  79 ++-
 test/dm/Makefile                          |   3 +
 test/dm/audio.c                           |  34 ++
 test/dm/i2s.c                             |  32 ++
 test/dm/sound.c                           |  34 ++
 test/dm/test-fdt.c                        |  35 ++
 59 files changed, 2660 insertions(+), 664 deletions(-)
 delete mode 100644 arch/sandbox/include/asm/sound.h
 create mode 100644 drivers/sound/codec-uclass.c
 create mode 100644 drivers/sound/i2s-uclass.c
 create mode 100644 drivers/sound/max98090.c
 create mode 100644 drivers/sound/max98090.h
 create mode 100644 drivers/sound/maxim_codec.c
 create mode 100644 drivers/sound/maxim_codec.h
 create mode 100644 drivers/sound/samsung_sound.c
 delete mode 100644 drivers/sound/sound-i2s.c
 create mode 100644 drivers/sound/sound-uclass.c
 create mode 100644 include/audio_codec.h
 create mode 100644 test/dm/audio.c
 create mode 100644 test/dm/i2s.c
 create mode 100644 test/dm/sound.c
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#1 lore raw

PATCH v2 1/22 dm: sound: exynos: Correct codec bus addresses

For snow the codec is at address 0x11 on the i2c bus, in 7-bit format. The device tree and code are in 8-bit format (i.e. shifted left one bit). Fix both. Fix pit in a similar way.

---

Changes in v2:
- Add fix for pit and pi also
- Fix up tabs in this commit instead of the later one

 arch/arm/dts/exynos5250-snow.dts      | 4 ++--
 arch/arm/dts/exynos5420-peach-pit.dts | 8 ++++----
 arch/arm/dts/exynos5800-peach-pi.dts  | 8 ++++----
 drivers/sound/max98095.c              | 3 +--
 4 files changed, 11 insertions(+), 12 deletions(-)
arch/arm/dts/exynos5250-snow.dts +2 -2
index e99f6e72bf6..cb5067b9669 100644
@@ -214,8 +214,8 @@
 			};
 		};
 
-		soundcodec at 22 {
-			reg = <0x22>;
+		soundcodec at 11 {
+			reg = <0x11>;
 			compatible = "maxim,max98095-codec";
 		};
 	};
arch/arm/dts/exynos5420-peach-pit.dts +4 -4
index c86f9d9035d..bd0a9c116d4 100644
@@ -69,10 +69,10 @@
 
 	i2c at 12CD0000 { /* i2c7 */
 		clock-frequency = <100000>;
-	       soundcodec at 20 {
-	              reg = <0x20>;
-	              compatible = "maxim,max98090-codec";
-	       };
+		soundcodec at 10 {
+			reg = <0x10>;
+			compatible = "maxim,max98090-codec";
+		};
 
 		edp-lvds-bridge at 48 {
 			compatible = "parade,ps8625";
arch/arm/dts/exynos5800-peach-pi.dts +4 -4
index 7498519d6c6..239781b34bb 100644
@@ -81,10 +81,10 @@
 
 	i2c at 12CD0000 { /* i2c7 */
 		clock-frequency = <100000>;
-	       soundcodec at 20 {
-	              reg = <0x20>;
-	              compatible = "maxim,max98090-codec";
-	       };
+		soundcodec at 10 {
+			reg = <0x10>;
+			compatible = "maxim,max98090-codec";
+		};
 	};
 
         sound at 3830000 {
drivers/sound/max98095.c +1 -2
index 6a98dac04bb..7a3dbd09840 100644
@@ -569,8 +569,7 @@ int max98095_init(const void *blob, enum en_max_audio_interface aif_id,
 
 	i2c_set_bus_num(pcodec_info.i2c_bus);
 
-	/* shift the device address by 1 for 7 bit addressing */
-	max98095_info.i2c_addr = pcodec_info.i2c_dev_addr >> 1;
+	max98095_info.i2c_addr = pcodec_info.i2c_dev_addr;
 	ret = max98095_device_init(&max98095_info);
 	if (ret < 0) {
 		debug("%s: max98095 codec chip init failed\n", __func__);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#2 lore raw

PATCH v2 1/22 dm: sound: exynos: Correct codec bus addresses

For snow the codec is at address 0x11 on the i2c bus, in 7-bit format. The device tree and code are in 8-bit format (i.e. shifted left one bit). Fix both. Fix pit in a similar way.

---

Changes in v2:
- Add fix for pit and pi also
- Fix up tabs in this commit instead of the later one

 arch/arm/dts/exynos5250-snow.dts      | 4 ++--
 arch/arm/dts/exynos5420-peach-pit.dts | 8 ++++----
 arch/arm/dts/exynos5800-peach-pi.dts  | 8 ++++----
 drivers/sound/max98095.c              | 3 +--
 4 files changed, 11 insertions(+), 12 deletions(-)

Applied to u-boot-dm/master

#3 lore raw

PATCH v2 2/22 dm: sound: Create an option to use driver model for sound

In reply to Simon Glass

The U-Boot sound system provides basic support for beeping. At present it does not use driver model, but it needs to be converted. Add an option to enable driver model for sound. For now it is not connected to anything. Future work will add drivers which use this option. It will then be removed once everything is converted.

---

Changes in v2:
- Use Kconfig instead of defconfig to define DM_SOUND

 arch/Kconfig          | 1 +
 drivers/sound/Kconfig | 6 ++++++
 2 files changed, 7 insertions(+)
arch/Kconfig +1 -0
index 947070fdd35..35e2712fce9 100644
@@ -116,6 +116,7 @@ config SANDBOX
 	imply VIRTIO_SANDBOX
 	imply VIRTIO_BLK
 	imply VIRTIO_NET
+	imply DM_SOUND
 
 config SH
 	bool "SuperH architecture"
drivers/sound/Kconfig +6 -0
index 5de86c05c60..93f6c36af32 100644
@@ -12,6 +12,12 @@ config SOUND
 	  audio codecs are called from the sound-i2s code. This could be
 	  converted to driver model.
 
+config DM_SOUND
+	bool "Use driver model for sound"
+	help
+	  Enable this option to use driver model for sound devices. This is a
+	  migration option and will be removed.
+
 config I2S
 	bool "Enable I2S support"
 	depends on SOUND
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#4 lore raw

PATCH v2 2/22 dm: sound: Create an option to use driver model for sound

The U-Boot sound system provides basic support for beeping. At present it does not use driver model, but it needs to be converted. Add an option to enable driver model for sound. For now it is not connected to anything. Future work will add drivers which use this option. It will then be removed once everything is converted.

---

Changes in v2:
- Use Kconfig instead of defconfig to define DM_SOUND

 arch/Kconfig          | 1 +
 drivers/sound/Kconfig | 6 ++++++
 2 files changed, 7 insertions(+)

Applied to u-boot-dm/master

#5 lore raw

PATCH v2 3/22 dm: sound: Rename samsung_i2s_priv to i2s_uc_priv

In reply to Simon Glass

This structure contains information that is likely needed by any i2s driver so it seems useful to attach it to the (forthcoming) i2c uclass. For now, just rename it.

---

Changes in v2: None

 drivers/sound/samsung-i2s.c |  4 ++--
 drivers/sound/sound-i2s.c   | 10 +++++-----
 include/i2s.h               |  6 +++---
 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/sound/samsung-i2s.c +2 -2
index c07d3cdb4c8..5cd585808ab 100644
@@ -255,7 +255,7 @@ static int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc)
 	return 0;
 }
 
-int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, unsigned int *data,
+int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data,
 			 unsigned long data_size)
 {
 	int i;
@@ -293,7 +293,7 @@ int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, unsigned int *data,
 	return 0;
 }
 
-int i2s_tx_init(struct samsung_i2s_priv *pi2s_tx)
+int i2s_tx_init(struct i2s_uc_priv *pi2s_tx)
 {
 	int ret;
 	struct i2s_reg *i2s_reg =
drivers/sound/sound-i2s.c +5 -5
index 106842a23db..ed130750b2e 100644
@@ -20,15 +20,15 @@
 #define SOUND_400_HZ 400
 #define SOUND_BITS_IN_BYTE 8
 
-static struct samsung_i2s_priv g_i2stx_pri;
+static struct i2s_uc_priv g_i2stx_pri;
 
 /*
  * get_sound_i2s_values gets values for i2s parameters
  *
- * @param samsung_i2s_priv	i2s transmitter transfer param structure
+ * @param i2s_uc_priv	i2s transmitter transfer param structure
  * @param blob		FDT blob if enabled else NULL
  */
-static int get_sound_i2s_values(struct samsung_i2s_priv *i2s, const void *blob)
+static int get_sound_i2s_values(struct i2s_uc_priv *i2s, const void *blob)
 {
 	int node;
 	int error = 0;
@@ -97,7 +97,7 @@ static int get_sound_i2s_values(struct samsung_i2s_priv *i2s, const void *blob)
  * @param pi2s_tx	i2s parameters required by codec
  * @return              int value, 0 for success
  */
-static int codec_init(const void *blob, struct samsung_i2s_priv *pi2s_tx)
+static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx)
 {
 	int ret;
 	const char *codectype;
@@ -145,7 +145,7 @@ static int codec_init(const void *blob, struct samsung_i2s_priv *pi2s_tx)
 int sound_init(const void *blob)
 {
 	int ret;
-	struct samsung_i2s_priv *pi2s_tx = &g_i2stx_pri;
+	struct i2s_uc_priv *pi2s_tx = &g_i2stx_pri;
 
 	/* Get the I2S Values */
 	if (get_sound_i2s_values(pi2s_tx, blob) < 0) {
include/i2s.h +3 -3
index 800473abd9c..f23862ca040 100644
@@ -76,7 +76,7 @@ struct i2s_reg {
 };
 
 /* This structure stores the i2s related information */
-struct samsung_i2s_priv {
+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 */
@@ -96,7 +96,7 @@ struct samsung_i2s_priv {
  *
  * @return		int value 0 for success, -1 in case of error
  */
-int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, uint *data,
+int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data,
 			 unsigned long data_size);
 
 /*
@@ -106,6 +106,6 @@ int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, uint *data,
  *
  * @return		int value 0 for success, -1 in case of error
  */
-int i2s_tx_init(struct samsung_i2s_priv *pi2s_tx);
+int i2s_tx_init(struct i2s_uc_priv *pi2s_tx);
 
 #endif /* __I2S_H__ */
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#6 lore raw

PATCH v2 3/22 dm: sound: Rename samsung_i2s_priv to i2s_uc_priv

This structure contains information that is likely needed by any i2s driver so it seems useful to attach it to the (forthcoming) i2c uclass. For now, just rename it.

---

Changes in v2: None

 drivers/sound/samsung-i2s.c |  4 ++--
 drivers/sound/sound-i2s.c   | 10 +++++-----
 include/i2s.h               |  6 +++---
 3 files changed, 10 insertions(+), 10 deletions(-)

Applied to u-boot-dm/master

#7 lore raw

PATCH v2 4/22 dm: sound: Create a uclass for audio codecs

In reply to Simon Glass

An audio codec provides a way to convert digital data to sound and vice versa. Add a simple uclass which just supports setting the parameters for the codec.

---

Changes in v2: None

 arch/sandbox/dts/test.dts       |  7 ++++-
 arch/sandbox/include/asm/test.h | 10 ++++++
 drivers/sound/Makefile          |  1 +
 drivers/sound/codec-uclass.c    | 26 ++++++++++++++++
 drivers/sound/sandbox.c         | 55 +++++++++++++++++++++++++++++++++
 include/audio_codec.h           | 48 ++++++++++++++++++++++++++++
 include/dm/uclass-id.h          |  1 +
 test/dm/Makefile                |  1 +
 test/dm/audio.c                 | 34 ++++++++++++++++++++
 9 files changed, 182 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/codec-uclass.c
 create mode 100644 include/audio_codec.h
 create mode 100644 test/dm/audio.c
arch/sandbox/dts/test.dts +6 -1
index 082fcec3f9e..73425b125a9 100644
@@ -42,7 +42,12 @@
 		osd0 = "/osd";
 	};
 
-	cros_ec: cros-ec {
+	audio: audio-codec {
+		compatible = "sandbox,audio-codec";
+		#sound-dai-cells = <1>;
+	};
+
+		cros_ec: cros-ec {
 		reg = <0 0>;
 		compatible = "google,cros-ec-sandbox";
 
arch/sandbox/include/asm/test.h +10 -0
index 5e818392959..f70e0d84177 100644
@@ -121,4 +121,14 @@ int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
  */
 void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask);
 
+/**
+ * sandbox_get_codec_params() - Read back codec parameters
+ *
+ * This reads back the parameters set by audio_codec_set_params() for the
+ * sandbox audio driver. Arguments are as for that function.
+ */
+void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
+			      int *mclk_freqp, int *bits_per_samplep,
+			      uint *channelsp);
+
 #endif
drivers/sound/Makefile +1 -0
index 696c5aecbe9..ae5fabed846 100644
@@ -4,6 +4,7 @@
 # R. Chandrasekar <[email protected]>
 
 obj-$(CONFIG_SOUND)	+= sound.o
+obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o
 obj-$(CONFIG_I2S)	+= sound-i2s.o
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o
 obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o
drivers/sound/codec-uclass.c new file +26 -0
new file mode 100644
index 00000000000..1ec77acfc1c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <audio_codec.h>
+
+int audio_codec_set_params(struct udevice *dev, int interface, int rate,
+			   int mclk_freq, int bits_per_sample, uint channels)
+{
+	struct audio_codec_ops *ops = audio_codec_get_ops(dev);
+
+	if (!ops->set_params)
+		return -ENOSYS;
+
+	return ops->set_params(dev, interface, rate, mclk_freq, bits_per_sample,
+			       channels);
+}
+
+UCLASS_DRIVER(audio_codec) = {
+	.id		= UCLASS_AUDIO_CODEC,
+	.name		= "audio-codec",
+};
drivers/sound/sandbox.c +55 -0

67 lines not on this page · raw message

include/audio_codec.h new file +48 -0

48 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 037af0460c6..50aa35ee246 100644
@@ -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 */
test/dm/Makefile +1 -0
index 2c9081e4dd6..ef450b7ed81 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
+obj-$(CONFIG_DM_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
 obj-$(CONFIG_CLK) += clk.o
test/dm/audio.c new file +34 -0
new file mode 100644
index 00000000000..77c3a3625bd
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <audio_codec.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the audio codec uclass */
+static int dm_test_audio(struct unit_test_state *uts)
+{
+	int interface, rate, mclk_freq, bits_per_sample;
+	struct udevice *dev;
+	uint channels;
+
+	/* check probe success */
+	ut_assertok(uclass_first_device_err(UCLASS_AUDIO_CODEC, &dev));
+	ut_assertok(audio_codec_set_params(dev, 1, 2, 3, 4, 5));
+	sandbox_get_codec_params(dev, &interface, &rate, &mclk_freq,
+				 &bits_per_sample, &channels);
+	ut_asserteq(1, interface);
+	ut_asserteq(2, rate);
+	ut_asserteq(3, mclk_freq);
+	ut_asserteq(4, bits_per_sample);
+	ut_asserteq(5, channels);
+
+	return 0;
+}
+DM_TEST(dm_test_audio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#8 lore raw

PATCH v2 4/22 dm: sound: Create a uclass for audio codecs

An audio codec provides a way to convert digital data to sound and vice versa. Add a simple uclass which just supports setting the parameters for the codec.

---

Changes in v2: None

 arch/sandbox/dts/test.dts       |  7 ++++-
 arch/sandbox/include/asm/test.h | 10 ++++++
 drivers/sound/Makefile          |  1 +
 drivers/sound/codec-uclass.c    | 26 ++++++++++++++++
 drivers/sound/sandbox.c         | 55 +++++++++++++++++++++++++++++++++
 include/audio_codec.h           | 48 ++++++++++++++++++++++++++++
 include/dm/uclass-id.h          |  1 +
 test/dm/Makefile                |  1 +
 test/dm/audio.c                 | 34 ++++++++++++++++++++
 9 files changed, 182 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/codec-uclass.c
 create mode 100644 include/audio_codec.h
 create mode 100644 test/dm/audio.c

Applied to u-boot-dm/master

#9 lore raw

PATCH v2 5/22 dm: sound: Create a uclass for i2s

In reply to Simon Glass

The i2s bus is commonly used with audio codecs. It provides a way to stream digital data sychronously in both directions. U-Boot only supports audio output, so this uclass is very simple, with a single tx_data() method.

Add a uclass and a test for i2s.

---

Changes in v2: None

 arch/sandbox/dts/test.dts       |  7 +++-
 arch/sandbox/include/asm/test.h | 10 ++++++
 drivers/sound/Makefile          |  1 +
 drivers/sound/i2s-uclass.c      | 25 ++++++++++++++
 drivers/sound/sandbox.c         | 60 ++++++++++++++++++++++++++++++++-
 include/dm/uclass-id.h          |  1 +
 include/i2s.h                   | 32 +++++++++++++++---
 test/dm/Makefile                |  1 +
 test/dm/i2s.c                   | 32 ++++++++++++++++++
 9 files changed, 163 insertions(+), 6 deletions(-)
 create mode 100644 drivers/sound/i2s-uclass.c
 create mode 100644 test/dm/i2s.c
arch/sandbox/dts/test.dts +6 -1
index 73425b125a9..28e2818ff37 100644
@@ -47,7 +47,7 @@
 		#sound-dai-cells = <1>;
 	};
 
-		cros_ec: cros-ec {
+	cros_ec: cros-ec {
 		reg = <0 0>;
 		compatible = "google,cros-ec-sandbox";
 
@@ -378,6 +378,11 @@
 		u-boot,dm-pre-reloc;
 	};
 
+	i2s: i2s {
+		compatible = "sandbox,i2s";
+		#sound-dai-cells = <1>;
+	};
+
 	misc-test {
 		compatible = "sandbox,misc_sandbox";
 	};
arch/sandbox/include/asm/test.h +10 -0
index f70e0d84177..71bd50bd5bc 100644
@@ -131,4 +131,14 @@ void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
 			      int *mclk_freqp, int *bits_per_samplep,
 			      uint *channelsp);
 
+/**
+ * sandbox_get_i2s_sum() - Read back the sum of the audio data so far
+ *
+ * This data is provided to the sandbox driver by the I2S tx_data() method.
+ *
+ * @dev: Device to check
+ * @return sum of audio data
+ */
+int sandbox_get_i2s_sum(struct udevice *dev);
+
 #endif
drivers/sound/Makefile +1 -0
index ae5fabed846..4aced9d22b9 100644
@@ -5,6 +5,7 @@
 
 obj-$(CONFIG_SOUND)	+= sound.o
 obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o
+obj-$(CONFIG_DM_SOUND)	+= i2s-uclass.o
 obj-$(CONFIG_I2S)	+= sound-i2s.o
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o
 obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o
drivers/sound/i2s-uclass.c new file +25 -0
new file mode 100644
index 00000000000..b741e3952d1
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2s.h>
+
+int i2s_tx_data(struct udevice *dev, void *data, uint data_size)
+{
+	struct i2s_ops *ops = i2s_get_ops(dev);
+
+	if (!ops->tx_data)
+		return -ENOSYS;
+
+	return ops->tx_data(dev, data, data_size);
+}
+
+UCLASS_DRIVER(i2s) = {
+	.id		= UCLASS_I2S,
+	.name		= "i2s",
+	.per_device_auto_alloc_size	= sizeof(struct i2s_uc_priv),
+};
drivers/sound/sandbox.c +59 -1

88 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 50aa35ee246..7ee5491e0b5 100644
@@ -48,6 +48,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 */
include/i2s.h +28 -4
index f23862ca040..28f6184811c 100644
@@ -87,17 +87,41 @@ struct i2s_uc_priv {
 	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 i2s_uc_priv *pi2s_tx, unsigned int *data,
-			 unsigned long data_size);
+int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, void *data,
+			 uint data_size);
 
 /*
  * Initialise i2s transmiter
test/dm/Makefile +1 -0
index ef450b7ed81..28ede9a6695 100644
@@ -22,6 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
+obj-$(CONFIG_DM_SOUND) += i2s.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
test/dm/i2s.c new file +32 -0
new file mode 100644
index 00000000000..49ebc3523c0
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2s.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the i2s codec uclass */
+static int dm_test_i2s(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	u8 data[3];
+
+	/* check probe success */
+	ut_assertok(uclass_first_device_err(UCLASS_I2S, &dev));
+	data[0] = 1;
+	data[1] = 4;
+	data[2] = 6;
+	ut_assertok(i2s_tx_data(dev, data, ARRAY_SIZE(data)));
+	ut_asserteq(11, sandbox_get_i2s_sum(dev));
+	ut_assertok(i2s_tx_data(dev, data, 1));
+	ut_asserteq(12, sandbox_get_i2s_sum(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_i2s, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#10 lore raw

PATCH v2 5/22 dm: sound: Create a uclass for i2s

The i2s bus is commonly used with audio codecs. It provides a way to stream digital data sychronously in both directions. U-Boot only supports audio output, so this uclass is very simple, with a single tx_data() method.

Add a uclass and a test for i2s.

---

Changes in v2: None

 arch/sandbox/dts/test.dts       |  7 +++-
 arch/sandbox/include/asm/test.h | 10 ++++++
 drivers/sound/Makefile          |  1 +
 drivers/sound/i2s-uclass.c      | 25 ++++++++++++++
 drivers/sound/sandbox.c         | 60 ++++++++++++++++++++++++++++++++-
 include/dm/uclass-id.h          |  1 +
 include/i2s.h                   | 32 +++++++++++++++---
 test/dm/Makefile                |  1 +
 test/dm/i2s.c                   | 32 ++++++++++++++++++
 9 files changed, 163 insertions(+), 6 deletions(-)
 create mode 100644 drivers/sound/i2s-uclass.c
 create mode 100644 test/dm/i2s.c

Applied to u-boot-dm/master

#11 lore raw

PATCH v2 6/22 dm: sandbox: Update sound to use two buffers

In reply to Simon Glass

At present we use a single buffer for sound which means we cannot be playing one sound while queueing up the next. This wouldn't matter except that a long sound (more than a second) has to be created as a single buffer, thus using a lot of memory. To better mimic what real sound drivers do, add support for double buffering in sandbox.

---

Changes in v2: None

 arch/sandbox/cpu/sdl.c | 88 ++++++++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 25 deletions(-)
arch/sandbox/cpu/sdl.c +63 -25
index c7a8d945492..4dacdbf993f 100644
@@ -13,6 +13,21 @@ enum {
 	SAMPLE_RATE	= 22050,
 };
 
+/**
+ * struct buf_info - a data buffer holding audio data
+ *
+ * @pos:	Current position playing in audio buffer
+ * @size:	Size of data in audio buffer (0=empty)
+ * @alloced:	Allocated size of audio buffer (max size it can hold)
+ * @data:	Audio data
+ */
+struct buf_info {
+	uint pos;
+	uint size;
+	uint alloced;
+	uint8_t *data;
+};
+
 static struct sdl_info {
 	SDL_Surface *screen;
 	int width;
@@ -20,12 +35,11 @@ static struct sdl_info {
 	int depth;
 	int pitch;
 	uint frequency;
-	uint audio_pos;
-	uint audio_size;
 	uint sample_rate;
-	uint8_t *audio_data;
 	bool audio_active;
 	bool inited;
+	int cur_buf;
+	struct buf_info buf[2];
 } sdl;
 
 static void sandbox_sdl_poll_events(void)
@@ -243,24 +257,37 @@ int sandbox_sdl_key_pressed(int keycode)
 
 void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
 {
+	struct buf_info *buf;
 	int avail;
+	int i;
 
-	avail = sdl.audio_size - sdl.audio_pos;
-	if (avail < len)
-		len = avail;
-
-	SDL_MixAudio(stream, sdl.audio_data + sdl.audio_pos, len,
-		     SDL_MIX_MAXVOLUME);
-	sdl.audio_pos += len;
-
-	/* Loop if we are@the end */
-	if (sdl.audio_pos == sdl.audio_size)
-		sdl.audio_pos = 0;
+	for (i = 0; i < 2; i++) {
+		buf = &sdl.buf[sdl.cur_buf];
+		avail = buf->size - buf->pos;
+		if (avail <= 0) {
+			sdl.cur_buf = 1 - sdl.cur_buf;
+			continue;
+		}
+		if (avail > len)
+			avail = len;
+
+		SDL_MixAudio(stream, buf->data + buf->pos, avail,
+			     SDL_MIX_MAXVOLUME);
+		buf->pos += avail;
+		len -= avail;
+
+		/* Move to next buffer if we are at the end */
+		if (buf->pos == buf->size)
+			buf->size = 0;
+		else
+			break;
+	}
 }
 
 int sandbox_sdl_sound_init(void)
 {
 	SDL_AudioSpec wanted;
+	int i;
 
 	if (sandbox_sdl_ensure_init())
 		return -1;
@@ -276,13 +303,20 @@ int sandbox_sdl_sound_init(void)
 	wanted.callback = sandbox_sdl_fill_audio;
 	wanted.userdata = NULL;
 
-	sdl.audio_size = sizeof(uint16_t) * wanted.freq;
-	sdl.audio_data = malloc(sdl.audio_size);
-	if (!sdl.audio_data) {
-		printf("%s: Out of memory\n", __func__);
-		return -1;
+	for (i = 0; i < 2; i++) {
+		struct buf_info *buf = &sdl.buf[i];
+
+		buf->alloced = sizeof(uint16_t) * wanted.freq * wanted.channels;
+		buf->data = malloc(buf->alloced);
+		if (!buf->data) {
+			printf("%s: Out of memory\n", __func__);
+			if (i == 1)
+				free(sdl.buf[0].data);
+			return -1;
+		}
+		buf->pos = 0;
+		buf->size = 0;
 	}
-	sdl.audio_pos = 0;
 
 	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
 		printf("Unable to initialize SDL audio: %s\n", SDL_GetError());
@@ -296,23 +330,27 @@ int sandbox_sdl_sound_init(void)
 	}
 	sdl.audio_active = true;
 	sdl.sample_rate = wanted.freq;
+	sdl.cur_buf = 0;
 
 	return 0;
 
 err:
-	free(sdl.audio_data);
+	for (i = 0; i < 2; i++)
+		free(sdl.buf[i].data);
 	return -1;
 }
 
 int sandbox_sdl_sound_start(uint frequency)
 {
+	struct buf_info *buf = &sdl.buf[0];
+
 	if (!sdl.audio_active)
 		return -1;
 	sdl.frequency = frequency;
-	sound_create_square_wave(sdl.sample_rate,
-				 (unsigned short *)sdl.audio_data,
-				 sdl.audio_size, frequency);
-	sdl.audio_pos = 0;
+	sound_create_square_wave(sdl.sample_rate, (unsigned short *)buf->data,
+				 buf->alloced, frequency);
+	buf->pos = 0;
+	buf->size = buf->alloced;
 	SDL_PauseAudio(0);
 
 	return 0;
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#12 lore raw

PATCH v2 6/22 dm: sandbox: Update sound to use two buffers

At present we use a single buffer for sound which means we cannot be playing one sound while queueing up the next. This wouldn't matter except that a long sound (more than a second) has to be created as a single buffer, thus using a lot of memory. To better mimic what real sound drivers do, add support for double buffering in sandbox.

---

Changes in v2: None

 arch/sandbox/cpu/sdl.c | 88 ++++++++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 25 deletions(-)

Applied to u-boot-dm/master

#13 lore raw

PATCH v2 7/22 dm: sound: Create a uclass for sound

In reply to Simon Glass

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.

---

Changes in v2:
- Update 'init' command to print the error code

 arch/sandbox/dts/test.dts       |  11 +++
 arch/sandbox/include/asm/test.h |  20 +++++
 cmd/sound.c                     |  23 +++++-
 drivers/sound/Makefile          |   1 +
 drivers/sound/sandbox.c         |  67 +++++++++++++++++
 drivers/sound/sound-uclass.c    | 127 ++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h          |   1 +
 include/sound.h                 |  70 +++++++++++++++++-
 test/dm/Makefile                |   1 +
 test/dm/sound.c                 |  34 +++++++++
 10 files changed, 351 insertions(+), 4 deletions(-)
 create mode 100644 drivers/sound/sound-uclass.c
 create mode 100644 test/dm/sound.c
arch/sandbox/dts/test.dts +11 -0
index 28e2818ff37..cedf514382f 100644
@@ -536,6 +536,17 @@
 		compatible = "sandbox,smem";
 	};
 
+	sound {
+		compatible = "sandbox,sound";
+		cpu {
+			sound-dai = <&i2s 0>;
+		};
+
+		codec {
+			sound-dai = <&audio 0>;
+		};
+	};
+
 	spi at 0 {
 		#address-cells = <1>;
 		#size-cells = <0>;
arch/sandbox/include/asm/test.h +20 -0
index 71bd50bd5bc..74f96188220 100644
@@ -141,4 +141,24 @@ void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
  */
 int sandbox_get_i2s_sum(struct udevice *dev);
 
+/**
+ * sandbox_get_setup_called() - Returns the number of times setup(*) was called
+ *
+ * This is used in the sound test
+ *
+ * @dev: Device to check
+ * @return call count for the setup() method
+ */
+int sandbox_get_setup_called(struct udevice *dev);
+
+/**
+ * sandbox_get_sound_sum() - Read back the sum of the sound data so far
+ *
+ * This data is provided to the sandbox driver by the sound play() method.
+ *
+ * @dev: Device to check
+ * @return sum of audio data
+ */
+int sandbox_get_sound_sum(struct udevice *dev);
+
 #endif
cmd/sound.c +21 -2
index d1cbc14f8df..77f51529259 100644
@@ -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;
 	}
 
drivers/sound/Makefile +1 -0
index 4aced9d22b9..70d32c6d6f6 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_SOUND)	+= sound.o
 obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o
 obj-$(CONFIG_DM_SOUND)	+= i2s-uclass.o
 obj-$(CONFIG_I2S)	+= sound-i2s.o
+obj-$(CONFIG_DM_SOUND)	+= sound-uclass.o
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o
 obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o
 obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
drivers/sound/sandbox.c +67 -0

103 lines not on this page · raw message

drivers/sound/sound-uclass.c new file +127 -0

127 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 7ee5491e0b5..ba6ed9b6c44 100644
@@ -83,6 +83,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 */
include/sound.h +68 -2

91 lines not on this page · raw message

test/dm/Makefile +1 -0
index 28ede9a6695..73f5dcf739e 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_MISC) += misc.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_CPU) += cpu.o
+obj-$(CONFIG_DM_SOUND) += sound.o
 obj-$(CONFIG_TEE) += tee.o
 obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
 obj-$(CONFIG_DMA) += dma.o
test/dm/sound.c new file +34 -0
new file mode 100644
index 00000000000..7d0b36e7a56
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sound.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the sound codec uclass */
+static int dm_test_sound(struct unit_test_state *uts)
+{
+	struct sound_uc_priv *uc_priv;
+	struct udevice *dev;
+
+	/* check probe success */
+	ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev));
+	uc_priv = dev_get_uclass_priv(dev);
+	ut_asserteq_str("audio-codec", uc_priv->codec->name);
+	ut_asserteq_str("i2s", uc_priv->i2s->name);
+	ut_asserteq(0, sandbox_get_setup_called(dev));
+
+	ut_assertok(sound_beep(dev, 1, 100));
+	ut_asserteq(4560, sandbox_get_sound_sum(dev));
+	ut_assertok(sound_beep(dev, 1, 100));
+	ut_asserteq(9120, sandbox_get_sound_sum(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_sound, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#14 lore raw

PATCH v2 7/22 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.

---

Changes in v2:
- Update 'init' command to print the error code

 arch/sandbox/dts/test.dts       |  11 +++
 arch/sandbox/include/asm/test.h |  20 +++++
 cmd/sound.c                     |  23 +++++-
 drivers/sound/Makefile          |   1 +
 drivers/sound/sandbox.c         |  67 +++++++++++++++++
 drivers/sound/sound-uclass.c    | 127 ++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h          |   1 +
 include/sound.h                 |  70 +++++++++++++++++-
 test/dm/Makefile                |   1 +
 test/dm/sound.c                 |  34 +++++++++
 10 files changed, 351 insertions(+), 4 deletions(-)
 create mode 100644 drivers/sound/sound-uclass.c
 create mode 100644 test/dm/sound.c

Applied to u-boot-dm/master

#15 lore raw

PATCH v2 8/22 dm: core: Add a function to read into a unsigned int

In reply to Simon Glass

The current dev_read...() functions use s32 and u32 which are convenient for device tree but not so useful for normal code, which often wants to use normal integers for values.

Add a helper which supports returning an unsigned int. Also add signed versions of the unsigned readers.

---

Changes in v2: None

 arch/sandbox/dts/test.dts |  2 ++
 drivers/core/read.c       | 23 ++++++++++++++++
 include/dm/read.h         | 58 +++++++++++++++++++++++++++++++++++++++
 test/dm/test-fdt.c        | 35 +++++++++++++++++++++++
 4 files changed, 118 insertions(+)
arch/sandbox/dts/test.dts +2 -0
index cedf514382f..e5c14fec5d8 100644
@@ -87,6 +87,8 @@
 		test2-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 6 1 3 2 1>,
 			<&gpio_b 7 2 3 2 1>, <&gpio_b 8 4 3 2 1>,
 			<&gpio_b 9 0xc 3 2 1>;
+		int-value = <1234>;
+		uint-value = <(-1234)>;
 	};
 
 	junk {
drivers/core/read.c +23 -0
index cdd78be03e2..3c46b3674ed 100644
@@ -21,6 +21,29 @@ int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
 	return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
 }
 
+int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp)
+{
+	return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp);
+}
+
+int dev_read_s32_default(struct udevice *dev, const char *propname, int def)
+{
+	return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
+}
+
+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;
+}
+
 const char *dev_read_string(struct udevice *dev, const char *propname)
 {
 	return ofnode_read_string(dev_ofnode(dev), propname);
include/dm/read.h +58 -0

70 lines not on this page · raw message

test/dm/test-fdt.c +35 -0
index 96d2528accb..984b80c02c8 100644
@@ -736,3 +736,38 @@ static int dm_test_first_child(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test integer functions in dm_read_...() */
+static int dm_test_read_int(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	u32 val32;
+	s32 sval;
+	uint val;
+
+	ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
+	ut_asserteq_str("a-test", dev->name);
+	ut_assertok(dev_read_u32(dev, "int-value", &val32));
+	ut_asserteq(1234, val32);
+
+	ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
+	ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
+
+	ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
+	ut_asserteq(1234, val32);
+
+	ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
+	ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
+
+	ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
+	ut_assertok(dev_read_s32(dev, "uint-value", &sval));
+	ut_asserteq(-1234, sval);
+
+	val = 0;
+	ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
+	ut_assertok(dev_read_u32u(dev, "uint-value", &val));
+	ut_asserteq(-1234, val);
+
+	return 0;
+}
+DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#16 lore raw

PATCH v2 8/22 dm: core: Add a function to read into a unsigned int

The current dev_read...() functions use s32 and u32 which are convenient for device tree but not so useful for normal code, which often wants to use normal integers for values.

Add a helper which supports returning an unsigned int. Also add signed versions of the unsigned readers.

---

Changes in v2: None

 arch/sandbox/dts/test.dts |  2 ++
 drivers/core/read.c       | 23 ++++++++++++++++
 include/dm/read.h         | 58 +++++++++++++++++++++++++++++++++++++++
 test/dm/test-fdt.c        | 35 +++++++++++++++++++++++
 4 files changed, 118 insertions(+)

Applied to u-boot-dm/master

#17 lore raw

PATCH v2 9/22 dm: sound: Start i2c IDs from 0

In reply to Simon Glass

The current ID enums start from 1 but there does not seem to be any reason that they cannot start with 0. Adjust the code to avoid the +1 in codec_init().

---

Changes in v2: None

 drivers/sound/max98095.h  | 2 +-
 drivers/sound/sound-i2s.c | 6 ++----
 drivers/sound/wm8994.h    | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)
drivers/sound/max98095.h +1 -1
index 44b1e3a97b4..13ae177a86b 100644
@@ -13,7 +13,7 @@
 
 /*  Available audio interface ports in wm8994 codec */
 enum en_max_audio_interface {
-	AIF1 = 1,
+	AIF1,
 	AIF2,
 };
 
drivers/sound/sound-i2s.c +2 -4
index ed130750b2e..a2fc78154f1 100644
@@ -120,13 +120,11 @@ static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx)
 	debug("device = %s\n", codectype);
 	if (!strcmp(codectype, "wm8994")) {
 		/* Check the codec type and initialise the same */
-		ret = wm8994_init(blob, pi2s_tx->id + 1,
-				  pi2s_tx->samplingrate,
+		ret = wm8994_init(blob, pi2s_tx->id, pi2s_tx->samplingrate,
 				  (pi2s_tx->samplingrate * (pi2s_tx->rfs)),
 				  pi2s_tx->bitspersample, pi2s_tx->channels);
 	} else if (!strcmp(codectype, "max98095")) {
-		ret = max98095_init(blob, pi2s_tx->id + 1,
-				    pi2s_tx->samplingrate,
+		ret = max98095_init(blob, pi2s_tx->id, pi2s_tx->samplingrate,
 				    (pi2s_tx->samplingrate * (pi2s_tx->rfs)),
 				    pi2s_tx->bitspersample);
 	} else {
drivers/sound/wm8994.h +1 -1
index ef2878f87ca..e36e6269f00 100644
@@ -15,7 +15,7 @@
 
 /*  Avilable audi interface ports in wm8994 codec */
 enum en_audio_interface {
-	 WM8994_AIF1 = 1,
+	 WM8994_AIF1,
 	 WM8994_AIF2,
 	 WM8994_AIF3
 };
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#18 lore raw

PATCH v2 9/22 dm: sound: Start i2c IDs from 0

The current ID enums start from 1 but there does not seem to be any reason that they cannot start with 0. Adjust the code to avoid the +1 in codec_init().

---

Changes in v2: None

 drivers/sound/max98095.h  | 2 +-
 drivers/sound/sound-i2s.c | 6 ++----
 drivers/sound/wm8994.h    | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)

Applied to u-boot-dm/master

#19 lore raw

PATCH v2 10/22 dm: sound: Add conversion to driver model

In reply to Simon Glass

Move the existing hardware drivers over to use driver model.

---

Changes in v2:
- Correct conversion for pit
- Use void * for i2c and sound data

 arch/arm/dts/exynos5250-smdk5250.dts |   1 +
 arch/arm/dts/exynos5420-smdk5420.dts |   1 +
 drivers/sound/Makefile               |   6 +-
 drivers/sound/max98095.c             |  59 +++++++++++++-
 drivers/sound/samsung-i2s.c          | 111 +++++++++++++++++++++++----
 drivers/sound/samsung_sound.c        | 101 ++++++++++++++++++++++++
 drivers/sound/wm8994.c               |  53 ++++++++++++-
 7 files changed, 316 insertions(+), 16 deletions(-)
 create mode 100644 drivers/sound/samsung_sound.c
arch/arm/dts/exynos5250-smdk5250.dts +1 -0
index 8b695442b1a..bf60b82d449 100644
@@ -62,6 +62,7 @@
 	i2c at 12C70000 {
 		soundcodec at 1a {
 			reg = <0x1a>;
+			u-boot,i2c-offset-len = <2>;
 			compatible = "wolfson,wm8994-codec";
 		};
 	};
arch/arm/dts/exynos5420-smdk5420.dts +1 -0
index cab5ddb61fa..daaa4666964 100644
@@ -84,6 +84,7 @@
 	i2c at 12C70000 {
 		soundcodec at 1a {
 			reg = <0x1a>;
+			u-boot,i2c-offset-len = <2>;
 			compatible = "wolfson,wm8994-codec";
 		};
 	};
drivers/sound/Makefile +5 -1
index 70d32c6d6f6..75fa31ec534 100644
@@ -6,9 +6,13 @@
 obj-$(CONFIG_SOUND)	+= sound.o
 obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o
 obj-$(CONFIG_DM_SOUND)	+= i2s-uclass.o
-obj-$(CONFIG_I2S)	+= sound-i2s.o
 obj-$(CONFIG_DM_SOUND)	+= sound-uclass.o
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o
 obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o
+ifdef CONFIG_DM_SOUND
+obj-$(CONFIG_I2S_SAMSUNG)	+= samsung_sound.o
+else
+obj-$(CONFIG_I2S)	+= sound-i2s.o
+endif
 obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o
drivers/sound/max98095.c +58 -1

100 lines not on this page · raw message

drivers/sound/samsung-i2s.c +98 -13

153 lines not on this page · raw message

drivers/sound/samsung_sound.c new file +101 -0

101 lines not on this page · raw message

drivers/sound/wm8994.c +52 -1

106 lines not on this page · raw message

Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#20 lore raw

PATCH v2 10/22 dm: sound: Add conversion to driver model

Move the existing hardware drivers over to use driver model.

---

Changes in v2:
- Correct conversion for pit
- Use void * for i2c and sound data

 arch/arm/dts/exynos5250-smdk5250.dts |   1 +
 arch/arm/dts/exynos5420-smdk5420.dts |   1 +
 drivers/sound/Makefile               |   6 +-
 drivers/sound/max98095.c             |  59 +++++++++++++-
 drivers/sound/samsung-i2s.c          | 111 +++++++++++++++++++++++----
 drivers/sound/samsung_sound.c        | 101 ++++++++++++++++++++++++
 drivers/sound/wm8994.c               |  53 ++++++++++++-
 7 files changed, 316 insertions(+), 16 deletions(-)
 create mode 100644 drivers/sound/samsung_sound.c

Applied to u-boot-dm/master

#21 lore raw

PATCH v2 11/22 exynos: Add proid_is_exynos542x() for common 542x

In reply to Simon Glass

Add a convenience function for any Exynos 542x chip.

---

Changes in v2: None

 arch/arm/mach-exynos/clock.c              | 10 +++++-----
 arch/arm/mach-exynos/clock_init_exynos5.c |  2 +-
 arch/arm/mach-exynos/common_setup.h       |  4 ++--
 arch/arm/mach-exynos/include/mach/cpu.h   |  4 +++-
 arch/arm/mach-exynos/include/mach/gpio.h  |  4 ++--
 arch/arm/mach-exynos/pinmux.c             |  2 +-
 arch/arm/mach-exynos/power.c              |  2 +-
 7 files changed, 15 insertions(+), 13 deletions(-)
arch/arm/mach-exynos/clock.c +5 -5
index 6a3cd44b5d3..2425a728669 100644
@@ -345,7 +345,7 @@ static struct clk_bit_info *get_clk_bit_info(int peripheral)
 	int i;
 	struct clk_bit_info *info;
 
-	if (proid_is_exynos5420() || proid_is_exynos5422())
+	if (proid_is_exynos542x())
 		info = exynos542x_bit_info;
 	else
 		info = exynos5_bit_info;
@@ -557,7 +557,7 @@ static unsigned long exynos542x_get_periph_rate(int peripheral)
 unsigned long clock_get_periph_rate(int peripheral)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return exynos542x_get_periph_rate(peripheral);
 		return exynos5_get_periph_rate(peripheral);
 	} else {
@@ -1575,7 +1575,7 @@ static unsigned long exynos4_get_i2c_clk(void)
 unsigned long get_pll_clk(int pllreg)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return exynos542x_get_pll_clk(pllreg);
 		return exynos5_get_pll_clk(pllreg);
 	} else if (cpu_is_exynos4()) {
@@ -1691,7 +1691,7 @@ void set_mmc_clk(int dev_index, unsigned int div)
 		div -= 1;
 
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			exynos5420_set_mmc_clk(dev_index, div);
 		else
 			exynos5_set_mmc_clk(dev_index, div);
@@ -1739,7 +1739,7 @@ void set_mipi_clk(void)
 int set_spi_clk(int periph_id, unsigned int rate)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return exynos5420_set_spi_clk(periph_id, rate);
 		return exynos5_set_spi_clk(periph_id, rate);
 	}
arch/arm/mach-exynos/clock_init_exynos5.c +1 -1
index e63ef645239..1cb8d391e7c 100644
@@ -968,7 +968,7 @@ static void exynos5420_system_clock_init(void)
 
 void system_clock_init(void)
 {
-	if (proid_is_exynos5420() || proid_is_exynos5422())
+	if (proid_is_exynos542x())
 		exynos5420_system_clock_init();
 	else
 		exynos5250_system_clock_init();
arch/arm/mach-exynos/common_setup.h +2 -2
index 2829fb269ed..4e3702b9285 100644
@@ -78,7 +78,7 @@ static inline void configure_l2_ctlr(void)
 		CACHE_TAG_RAM_LATENCY_2_CYCLES |
 		CACHE_DATA_RAM_LATENCY_2_CYCLES;
 
-	if (proid_is_exynos5420() || proid_is_exynos5422()) {
+	if (proid_is_exynos542x()) {
 		val |= CACHE_ECC_AND_PARITY |
 			CACHE_TAG_RAM_LATENCY_3_CYCLES |
 			CACHE_DATA_RAM_LATENCY_3_CYCLES;
@@ -97,7 +97,7 @@ static inline void configure_l2_actlr(void)
 {
 	uint32_t val;
 
-	if (proid_is_exynos5420() || proid_is_exynos5422()) {
+	if (proid_is_exynos542x()) {
 		mrc_l2_aux_ctlr(val);
 		val |= CACHE_ENABLE_FORCE_L2_LOGIC |
 			CACHE_DISABLE_CLEAN_EVICT;
arch/arm/mach-exynos/include/mach/cpu.h +3 -1
index aeb3755fe6b..766edeeb298 100644
@@ -268,6 +268,8 @@ IS_EXYNOS_TYPE(exynos5250, 0x5250)
 IS_EXYNOS_TYPE(exynos5420, 0x5420)
 IS_EXYNOS_TYPE(exynos5422, 0x5422)
 
+#define proid_is_exynos542x() (proid_is_exynos5420() || proid_is_exynos5422())
+
 #define SAMSUNG_BASE(device, base)				\
 static inline unsigned long __attribute__((no_instrument_function)) \
 	samsung_get_base_##device(void) \
@@ -277,7 +279,7 @@ static inline unsigned long __attribute__((no_instrument_function)) \
 			return EXYNOS4X12_##base;		\
 		return EXYNOS4_##base;				\
 	} else if (cpu_is_exynos5()) {				\
-		if (proid_is_exynos5420() || proid_is_exynos5422())	\
+		if (proid_is_exynos542x())			\
 			return EXYNOS5420_##base;		\
 		return EXYNOS5_##base;				\
 	}							\
arch/arm/mach-exynos/include/mach/gpio.h +2 -2
index 272e00bae8f..f9975d7919f 100644
@@ -1397,7 +1397,7 @@ static struct gpio_info exynos5420_gpio_data[EXYNOS5420_GPIO_NUM_PARTS] = {
 static inline struct gpio_info *get_gpio_data(void)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return exynos5420_gpio_data;
 		else
 			return exynos5_gpio_data;
@@ -1414,7 +1414,7 @@ static inline struct gpio_info *get_gpio_data(void)
 static inline unsigned int get_bank_num(void)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return EXYNOS5420_GPIO_NUM_PARTS;
 		else
 			return EXYNOS5_GPIO_NUM_PARTS;
arch/arm/mach-exynos/pinmux.c +1 -1
index f6743ca0f6e..5072f4f5691 100644
@@ -863,7 +863,7 @@ static int exynos4x12_pinmux_config(int peripheral, int flags)
 int exynos_pinmux_config(int peripheral, int flags)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			return exynos5420_pinmux_config(peripheral, flags);
 		else if (proid_is_exynos5250())
 			return exynos5_pinmux_config(peripheral, flags);
arch/arm/mach-exynos/power.c +1 -1
index 63c410aceff..f2a6c00dd62 100644
@@ -124,7 +124,7 @@ static void exynos5420_set_usbdev_phy_ctrl(unsigned int enable)
 void set_usbdrd_phy_ctrl(unsigned int enable)
 {
 	if (cpu_is_exynos5()) {
-		if (proid_is_exynos5420() || proid_is_exynos5422())
+		if (proid_is_exynos542x())
 			exynos5420_set_usbdev_phy_ctrl(enable);
 		else
 			exynos5_set_usbdrd_phy_ctrl(enable);
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#22 lore raw

PATCH v2 11/22 exynos: Add proid_is_exynos542x() for common 542x

Add a convenience function for any Exynos 542x chip.

---

Changes in v2: None

 arch/arm/mach-exynos/clock.c              | 10 +++++-----
 arch/arm/mach-exynos/clock_init_exynos5.c |  2 +-
 arch/arm/mach-exynos/common_setup.h       |  4 ++--
 arch/arm/mach-exynos/include/mach/cpu.h   |  4 +++-
 arch/arm/mach-exynos/include/mach/gpio.h  |  4 ++--
 arch/arm/mach-exynos/pinmux.c             |  2 +-
 arch/arm/mach-exynos/power.c              |  2 +-
 7 files changed, 15 insertions(+), 13 deletions(-)

Applied to u-boot-dm/master

#23 lore raw

PATCH v2 12/22 exynos: Add support for exynos5420 i2s pinmux

In reply to Simon Glass

Allow setting the i2s pinmux correctly on exyno5420 so that i2c can be used on that SoC. Also rename EXYNOS_AUDSS to something consistent with other naming.

---

Changes in v2: None

 arch/arm/mach-exynos/clock.c              | 21 +++++++++++++++++++--
 arch/arm/mach-exynos/include/mach/clock.h |  3 +++
 arch/arm/mach-exynos/pinmux.c             | 17 +++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)
arch/arm/mach-exynos/clock.c +19 -2
index 2425a728669..73aa4cdad32 100644
@@ -1317,6 +1317,19 @@ int exynos5_set_epll_clk(unsigned long rate)
 	return 0;
 }
 
+static int exynos5420_set_i2s_clk_source(void)
+{
+	struct exynos5420_clock *clk =
+		(struct exynos5420_clock *)samsung_get_base_clock();
+
+	setbits_le32(&clk->src_top6, EXYNOS5420_CLK_SRC_MOUT_EPLL);
+	clrsetbits_le32(&clk->src_mau, EXYNOS5420_AUDIO0_SEL_MASK,
+			(EXYNOS5420_CLK_SRC_SCLK_EPLL));
+	setbits_le32(EXYNOS5_AUDIOSS_BASE, 1 << 0);
+
+	return 0;
+}
+
 int exynos5_set_i2s_clk_source(unsigned int i2s_id)
 {
 	struct exynos5_clock *clk =
@@ -1758,8 +1771,12 @@ int set_i2s_clk_prescaler(unsigned int src_frq, unsigned int dst_frq,
 
 int set_i2s_clk_source(unsigned int i2s_id)
 {
-	if (cpu_is_exynos5())
-		return exynos5_set_i2s_clk_source(i2s_id);
+	if (cpu_is_exynos5()) {
+		if (proid_is_exynos542x())
+			return exynos5420_set_i2s_clk_source();
+		else
+			return exynos5_set_i2s_clk_source(i2s_id);
+	}
 
 	return 0;
 }
arch/arm/mach-exynos/include/mach/clock.h +3 -0
index edf62bdf853..e4c706adeac 100644
@@ -1370,10 +1370,13 @@ struct set_epll_con_val {
 #define AUDIO_1_RATIO_MASK		0x0f
 
 #define AUDIO0_SEL_MASK			0xf
+#define EXYNOS5420_AUDIO0_SEL_MASK	(0x3 << 28)
 #define AUDIO1_SEL_MASK			0xf
 
 #define CLK_SRC_SCLK_EPLL		0x7
+#define EXYNOS5420_CLK_SRC_SCLK_EPLL	(0x6 << 28)
 #define CLK_SRC_MOUT_EPLL		(1<<12)
+#define EXYNOS5420_CLK_SRC_MOUT_EPLL	BIT(20)
 #define AUDIO_CLKMUX_ASS		(1<<0)
 
 /* CON0 bit-fields */
arch/arm/mach-exynos/pinmux.c +17 -0
index 5072f4f5691..b24f1bb8f4f 100644
@@ -378,6 +378,20 @@ static void exynos5_i2s_config(int peripheral)
 	}
 }
 
+static void exynos5420_i2s_config(int peripheral)
+{
+	int i;
+
+	switch (peripheral) {
+	case PERIPH_ID_I2S0:
+		for (i = 0; i < 5; i++)
+			gpio_cfg_pin(EXYNOS5420_GPIO_Z0 + i,
+				     S5P_GPIO_FUNC(0x02));
+		break;
+	}
+}
+
+
 void exynos5_spi_config(int peripheral)
 {
 	int cfg = 0, pin = 0, i;
@@ -550,6 +564,9 @@ static int exynos5420_pinmux_config(int peripheral, int flags)
 	case PERIPH_ID_I2C10:
 		exynos5420_i2c_config(peripheral);
 		break;
+	case PERIPH_ID_I2S0:
+		exynos5420_i2s_config(peripheral);
+		break;
 	case PERIPH_ID_PWM0:
 		gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
 		break;
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#24 lore raw

PATCH v2 12/22 exynos: Add support for exynos5420 i2s pinmux

Allow setting the i2s pinmux correctly on exyno5420 so that i2c can be used on that SoC. Also rename EXYNOS_AUDSS to something consistent with other naming.

---

Changes in v2: None

 arch/arm/mach-exynos/clock.c              | 21 +++++++++++++++++++--
 arch/arm/mach-exynos/include/mach/clock.h |  3 +++
 arch/arm/mach-exynos/pinmux.c             | 17 +++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master

#25 lore raw

PATCH v2 13/22 dm: sound: Move common code out of maxim98095

In reply to Simon Glass

The register-access code is useful for any maxim codec. Move it out into its own file.

---

Changes in v2:
- Add new patch to move common code out of maxim98095

 drivers/sound/Makefile      |   2 +-
 drivers/sound/max98095.c    | 181 ++++++++++--------------------------
 drivers/sound/max98095.h    |   2 +
 drivers/sound/maxim_codec.c |  87 +++++++++++++++++
 drivers/sound/maxim_codec.h |  67 +++++++++++++
 5 files changed, 204 insertions(+), 135 deletions(-)
 create mode 100644 drivers/sound/maxim_codec.c
 create mode 100644 drivers/sound/maxim_codec.h
drivers/sound/Makefile +1 -1
index 75fa31ec534..b08845599f9 100644
@@ -15,4 +15,4 @@ else
 obj-$(CONFIG_I2S)	+= sound-i2s.o
 endif
 obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
-obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o
+obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
drivers/sound/max98095.c +47 -134

351 lines not on this page · raw message

drivers/sound/max98095.h +2 -0
index 13ae177a86b..f189db728d1 100644
@@ -11,6 +11,8 @@
 #ifndef _MAX98095_H
 #define _MAX98095_H
 
+#include "maxim_codec.h"
+
 /*  Available audio interface ports in wm8994 codec */
 enum en_max_audio_interface {
 	AIF1,
drivers/sound/maxim_codec.c new file +87 -0

87 lines not on this page · raw message

drivers/sound/maxim_codec.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#26 lore raw

PATCH v2 13/22 dm: sound: Move common code out of maxim98095

The register-access code is useful for any maxim codec. Move it out into its own file.

---

Changes in v2:
- Add new patch to move common code out of maxim98095

 drivers/sound/Makefile      |   2 +-
 drivers/sound/max98095.c    | 181 ++++++++++--------------------------
 drivers/sound/max98095.h    |   2 +
 drivers/sound/maxim_codec.c |  87 +++++++++++++++++
 drivers/sound/maxim_codec.h |  67 +++++++++++++
 5 files changed, 204 insertions(+), 135 deletions(-)
 create mode 100644 drivers/sound/maxim_codec.c
 create mode 100644 drivers/sound/maxim_codec.h

Applied to u-boot-dm/master

#27 lore raw

PATCH v2 14/22 dm: sound: exynos: Add support for max98090

In reply to Simon Glass

Add support for this new codec which is used by pit.

---

Changes in v2:
- Add new patch with support for max98090

 drivers/sound/Kconfig    |   8 +
 drivers/sound/Makefile   |   1 +
 drivers/sound/max98090.c | 377 ++++++++++++++++++++++
 drivers/sound/max98090.h | 663 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 1049 insertions(+)
 create mode 100644 drivers/sound/max98090.c
 create mode 100644 drivers/sound/max98090.h
drivers/sound/Kconfig +8 -0
index 93f6c36af32..18d7ca1dcb3 100644
@@ -37,6 +37,14 @@ config I2S_SAMSUNG
 	  option provides an implementation for sound_init() and
 	  sound_play().
 
+config SOUND_MAX98090
+	bool "Support Maxim max98090 audio codec"
+	depends on I2S_SAMSUNG
+	help
+	  Enable the max98090 audio codec. This is connected via I2S for
+	  audio data and I2C for codec control. At present it only works
+	  with the Samsung I2S driver.
+
 config SOUND_MAX98095
 	bool "Support Maxim max98095 audio codec"
 	depends on I2S_SAMSUNG
drivers/sound/Makefile +1 -0
index b08845599f9..937df152fe6 100644
@@ -15,4 +15,5 @@ else
 obj-$(CONFIG_I2S)	+= sound-i2s.o
 endif
 obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
+obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
drivers/sound/max98090.c new file +377 -0

377 lines not on this page · raw message

drivers/sound/max98090.h new file +663 -0

663 lines not on this page · raw message

Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#28 lore raw

PATCH v2 14/22 dm: sound: exynos: Add support for max98090

Add support for this new codec which is used by pit.

---

Changes in v2:
- Add new patch with support for max98090

 drivers/sound/Kconfig    |   8 +
 drivers/sound/Makefile   |   1 +
 drivers/sound/max98090.c | 377 ++++++++++++++++++++++
 drivers/sound/max98090.h | 663 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 1049 insertions(+)
 create mode 100644 drivers/sound/max98090.c
 create mode 100644 drivers/sound/max98090.h

Applied to u-boot-dm/master

#29 lore raw

PATCH v2 15/22 dm: exynos: sound: Convert to use driver model

In reply to Simon Glass

Update snow's device tree and config to use driver model for sound. Also update the others as best we can.

Spring does not appear to have audio support in the kernel. The smdk5250 and smdk5420 boards use a wolfson codec which I cannot test with. So the only boards that is tested and known to work are snow, pit and pi.

---

Changes in v2:
- Correct conversion for pit and pi, updating commit message

 arch/arm/dts/exynos5250-smdk5250.dts  | 20 ++++++++++++++++++--
 arch/arm/dts/exynos5250-snow.dts      | 21 ++++++++++++++++-----
 arch/arm/dts/exynos5250-spring.dts    | 24 ++++++++++++++++++++----
 arch/arm/dts/exynos5250.dtsi          | 15 ++++++++++-----
 arch/arm/dts/exynos5420-peach-pit.dts | 20 ++++++++++++++++++--
 arch/arm/dts/exynos5420-smdk5420.dts  | 20 ++++++++++++++++++--
 arch/arm/dts/exynos54xx.dtsi          | 14 ++++++++++++++
 arch/arm/dts/exynos5800-peach-pi.dts  | 20 ++++++++++++++++++--
 configs/arndale_defconfig             |  1 +
 configs/peach-pi_defconfig            |  3 +++
 configs/peach-pit_defconfig           |  3 +++
 configs/smdk5250_defconfig            |  1 +
 configs/snow_defconfig                |  1 +
 configs/spring_defconfig              |  1 +
 drivers/sound/samsung_sound.c         |  3 +++
 15 files changed, 145 insertions(+), 22 deletions(-)
arch/arm/dts/exynos5250-smdk5250.dts +18 -2
index bf60b82d449..e542a790761 100644
@@ -60,10 +60,26 @@
 	};
 
 	i2c at 12C70000 {
-		soundcodec at 1a {
+		wm8994: soundcodec at 1a {
 			reg = <0x1a>;
 			u-boot,i2c-offset-len = <2>;
-			compatible = "wolfson,wm8994-codec";
+			compatible = "wolfson,wm8994";
+			#sound-dai-cells = <1>;
+		};
+	};
+
+	sound {
+		compatible = "google,smdk5250-audio-wm8994";
+
+		samsung,model = "SMDK5250-I2S-WM8994";
+		samsung,audio-codec = <&wm8994>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&wm8994 0>;
 		};
 	};
 
arch/arm/dts/exynos5250-snow.dts +16 -5
index cb5067b9669..7587dc0ff24 100644
@@ -40,7 +40,6 @@
 		mmc3 = "/mmc at 12230000";
 		serial0 = "/serial at 12C30000";
 		console = "/serial at 12C30000";
-		i2s = "/sound at 3830000";
 	};
 
         memory {
@@ -214,9 +213,10 @@
 			};
 		};
 
-		soundcodec at 11 {
+		max98095: codec at 11 {
+			compatible = "maxim,max98095";
 			reg = <0x11>;
-			compatible = "maxim,max98095-codec";
+			#sound-dai-cells = <1>;
 		};
 	};
 
@@ -273,9 +273,20 @@
 		};
 	};
 
-	sound at 3830000 {
-		samsung,codec-type = "max98095";
+	sound {
+		compatible = "google,snow-audio-max98095";
+
+		samsung,model = "Snow-I2S-MAX98095";
+		samsung,audio-codec = <&max98095>;
 		codec-enable-gpio = <&gpx1 7 GPIO_ACTIVE_HIGH>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&max98095 0>;
+		};
 	};
 
 	sound at 12d60000 {
arch/arm/dts/exynos5250-spring.dts +20 -4
index 7633d36874f..191e12af6a1 100644
@@ -34,7 +34,6 @@
 		mmc0 = "/mmc at 12200000";
 		serial0 = "/serial at 12C30000";
 		console = "/serial at 12C30000";
-		i2s = "/sound at 3830000";
 	};
 
 	memory {
@@ -639,10 +638,27 @@
 		};
 	};
 
-	soundcodec at 20 {
-		reg = <0x20>;
-		compatible = "maxim,max98088-codec";
+	max98095: soundcodec at 10 {
+		reg = <0x10>;
+		compatible = "maxim,max98095";
+		#sound-dai-cells = <1>;
 	};
+
+	sound {
+		compatible = "google,spring-audio-max98095";
+
+		samsung,model = "Spring-I2S-MAX98095";
+		samsung,audio-codec = <&max98095>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&max98095 0>;
+		};
+	};
+
 };
 
 #include "cros-ec-keyboard.dtsi"
arch/arm/dts/exynos5250.dtsi +10 -5
index 502c687802e..66c5b6dca95 100644
@@ -78,9 +78,12 @@
 		#size-cells = <0>;
 	};
 
-	sound at 3830000 {
-		compatible = "samsung,exynos-sound";
-		reg = <0x3830000 0x50>;
+	i2s0: i2s at 3830000 {
+		compatible = "samsung,s5pv210-i2s";
+		reg = <0x03830000 0x100>;
+		samsung,idma-addr = <0x03000000>;
+		#clock-cells = <1>;
+		#sound-dai-cells = <1>;
 		samsung,i2s-epll-clock-frequency = <192000000>;
 		samsung,i2s-sampling-rate = <48000>;
 		samsung,i2s-bits-per-sample = <16>;
@@ -90,9 +93,11 @@
 		samsung,i2s-id = <0>;
 	};
 
-	sound at 12d60000 {
-		compatible = "samsung,exynos-sound";
+	i2s1: i2s at 12d60000 {
+		compatible = "samsung,s5pv210-i2s";
 		reg = <0x12d60000 0x20>;
+		#clock-cells = <1>;
+		#sound-dai-cells = <1>;
 		samsung,i2s-epll-clock-frequency = <192000000>;
 		samsung,i2s-sampling-rate = <48000>;
 		samsung,i2s-bits-per-sample = <16>;
arch/arm/dts/exynos5420-peach-pit.dts +18 -2
index bd0a9c116d4..4a96a18110a 100644
@@ -67,11 +67,27 @@
 		};
 	};
 
+	sound {
+		compatible = "google,peach-audio-max98090";
+
+		samsung,model = "PEACH-I2S-MAX98090";
+		samsung,audio-codec = <&max98090>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&max98090 0>;
+		};
+	};
+
 	i2c at 12CD0000 { /* i2c7 */
 		clock-frequency = <100000>;
-		soundcodec at 10 {
+		max98090: soundcodec at 10 {
 			reg = <0x10>;
-			compatible = "maxim,max98090-codec";
+			compatible = "maxim,max98090";
+			#sound-dai-cells = <1>;
 		};
 
 		edp-lvds-bridge at 48 {
arch/arm/dts/exynos5420-smdk5420.dts +18 -2
index daaa4666964..7a5da674fbe 100644
@@ -82,10 +82,26 @@
 	};
 
 	i2c at 12C70000 {
-		soundcodec at 1a {
+		wm8994: soundcodec at 1a {
 			reg = <0x1a>;
 			u-boot,i2c-offset-len = <2>;
-			compatible = "wolfson,wm8994-codec";
+			compatible = "wolfson,wm8994";
+			#sound-dai-cells = <1>;
+		};
+	};
+
+	sound {
+		compatible = "samsung,smdk5420-audio-wm8994";
+
+		samsung,model = "Snow-I2S-MAX98095";
+		samsung,audio-codec = <&wm8994>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&wm8994 0>;
 		};
 	};
 
arch/arm/dts/exynos54xx.dtsi +14 -0
index 09bef56e6c2..221da8b4850 100644
@@ -104,6 +104,20 @@
 		interrupts = <0 203 0>;
 	};
 
+	i2s0: i2s at 3830000 {
+		compatible = "samsung,s5pv210-i2s";
+		reg = <0x03830000 0x100>;
+		#sound-dai-cells = <1>;
+		samsung,idma-addr = <0x03000000>;
+		samsung,i2s-epll-clock-frequency = <192000000>;
+		samsung,i2s-sampling-rate = <48000>;
+		samsung,i2s-bits-per-sample = <16>;
+		samsung,i2s-channels = <2>;
+		samsung,i2s-lr-clk-framesize = <256>;
+		samsung,i2s-bit-clk-framesize = <32>;
+		samsung,i2s-id = <0>;
+	};
+
 	mmc at 12200000 {
 		samsung,bus-width = <8>;
 		samsung,timing = <1 3 3>;
arch/arm/dts/exynos5800-peach-pi.dts +18 -2
index 239781b34bb..63c0b186e42 100644
@@ -79,11 +79,27 @@
 		};
 	};
 
+	sound {
+		compatible = "google,peach-audio-max98090";
+
+		samsung,model = "PEACH-I2S-MAX98090";
+		samsung,audio-codec = <&max98090>;
+
+		cpu {
+			sound-dai = <&i2s0 0>;
+		};
+
+		codec {
+			sound-dai = <&max98090 0>;
+		};
+	};
+
 	i2c at 12CD0000 { /* i2c7 */
 		clock-frequency = <100000>;
-		soundcodec at 10 {
+		max98090: soundcodec at 10 {
 			reg = <0x10>;
-			compatible = "maxim,max98090-codec";
+			compatible = "maxim,max98090";
+			#sound-dai-cells = <1>;
 		};
 	};
 
configs/arndale_defconfig +1 -0
index 2b6af4b2215..22881c3a2c6 100644
@@ -31,6 +31,7 @@ CONFIG_MMC_SDHCI_S5P=y
 CONFIG_SMC911X=y
 CONFIG_SMC911X_BASE=0x5000000
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/peach-pi_defconfig +3 -0
index 338eae20b41..5ced3423160 100644
@@ -21,6 +21,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_TPM=y
@@ -50,8 +51,10 @@ CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
+CONFIG_SOUND_MAX98090=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_EXYNOS_SPI=y
configs/peach-pit_defconfig +3 -0
index 933c823ea86..b1fe3f73abb 100644
@@ -20,6 +20,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_TPM=y
@@ -49,8 +50,10 @@ CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
+CONFIG_SOUND_MAX98090=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_EXYNOS_SPI=y
configs/smdk5250_defconfig +1 -0
index 161454b33fd..90ee0ffbc9d 100644
@@ -44,6 +44,7 @@ CONFIG_DM_PMIC_MAX77686=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/snow_defconfig +1 -0
index 21080091a7d..4d1c53d4291 100644
@@ -61,6 +61,7 @@ CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/spring_defconfig +1 -0
index ca1799895e8..8f9436c74af 100644
@@ -61,6 +61,7 @@ CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_SOUND=y
+CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
drivers/sound/samsung_sound.c +3 -0
index 23b467c1de0..1d711c87322 100644
@@ -89,6 +89,9 @@ static const struct sound_ops samsung_sound_ops = {
 
 static const struct udevice_id samsung_sound_ids[] = {
 	{ .compatible = "google,snow-audio-max98095" },
+	{ .compatible = "google,spring-audio-max98095" },
+	{ .compatible = "samsung,smdk5420-audio-wm8994" },
+	{ .compatible = "google,peach-audio-max98090" },
 	{ }
 };
 
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#30 lore raw

PATCH v2 15/22 dm: exynos: sound: Convert to use driver model

Update snow's device tree and config to use driver model for sound. Also update the others as best we can.

Spring does not appear to have audio support in the kernel. The smdk5250 and smdk5420 boards use a wolfson codec which I cannot test with. So the only boards that is tested and known to work are snow, pit and pi.

---

Changes in v2:
- Correct conversion for pit and pi, updating commit message

 arch/arm/dts/exynos5250-smdk5250.dts  | 20 ++++++++++++++++++--
 arch/arm/dts/exynos5250-snow.dts      | 21 ++++++++++++++++-----
 arch/arm/dts/exynos5250-spring.dts    | 24 ++++++++++++++++++++----
 arch/arm/dts/exynos5250.dtsi          | 15 ++++++++++-----
 arch/arm/dts/exynos5420-peach-pit.dts | 20 ++++++++++++++++++--
 arch/arm/dts/exynos5420-smdk5420.dts  | 20 ++++++++++++++++++--
 arch/arm/dts/exynos54xx.dtsi          | 14 ++++++++++++++
 arch/arm/dts/exynos5800-peach-pi.dts  | 20 ++++++++++++++++++--
 configs/arndale_defconfig             |  1 +
 configs/peach-pi_defconfig            |  3 +++
 configs/peach-pit_defconfig           |  3 +++
 configs/smdk5250_defconfig            |  1 +
 configs/snow_defconfig                |  1 +
 configs/spring_defconfig              |  1 +
 drivers/sound/samsung_sound.c         |  3 +++
 15 files changed, 145 insertions(+), 22 deletions(-)

Applied to u-boot-dm/master

#31 lore raw

PATCH v2 16/22 dm: sandbox: sound: Convert to use driver model

In reply to Simon Glass

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.

---

Changes in v2:
- Add new patch to convert sandbox to use driver model

 arch/sandbox/cpu/sdl.c         | 36 ++++++++++++++++++++++------------
 arch/sandbox/dts/sandbox.dts   | 21 ++++++++++++++++++++
 arch/sandbox/include/asm/sdl.h |  8 ++++++++
 3 files changed, 53 insertions(+), 12 deletions(-)
arch/sandbox/cpu/sdl.c +24 -12
index 4dacdbf993f..8fc7c172e3a 100644
@@ -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,36 @@ 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);
+	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;
 }
arch/sandbox/dts/sandbox.dts +21 -0
index ce3c88c221d..ae3189ec8cf 100644
@@ -18,6 +18,11 @@
 		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;
@@ -127,6 +132,11 @@
 		};
 	};
 
+	i2s: i2s {
+		compatible = "sandbox,i2s";
+		#sound-dai-cells = <1>;
+	};
+
 	lcd {
 		u-boot,dm-pre-reloc;
 		compatible = "sandbox,lcd-sdl";
@@ -190,6 +200,17 @@
 		compatible = "sandbox,reset";
 	};
 
+	sound {
+		compatible = "sandbox,sound";
+		cpu {
+			sound-dai = <&i2s 0>;
+		};
+
+		codec {
+			sound-dai = <&audio 0>;
+		};
+	};
+
 	spi at 0 {
 		u-boot,dm-pre-reloc;
 		#address-cells = <1>;
arch/sandbox/include/asm/sdl.h +8 -0
index 1c4380c592a..0143ed9e621 100644
@@ -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
  *
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#32 lore raw

PATCH v2 16/22 dm: sandbox: sound: Convert to use driver model

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.

---

Changes in v2:
- Add new patch to convert sandbox to use driver model

 arch/sandbox/cpu/sdl.c         | 36 ++++++++++++++++++++++------------
 arch/sandbox/dts/sandbox.dts   | 21 ++++++++++++++++++++
 arch/sandbox/include/asm/sdl.h |  8 ++++++++
 3 files changed, 53 insertions(+), 12 deletions(-)

Applied to u-boot-dm/master

#33 lore raw

PATCH v2 17/22 dm: exynos: Drop CONFIG_DM_I2C_COMPAT

In reply to Simon Glass

This option is not needed anymore for all exynos boards except arndale. Update the config.

---

Changes in v2: None

 configs/peach-pi_defconfig  | 1 -
 configs/peach-pit_defconfig | 1 -
 configs/smdk5250_defconfig  | 1 -
 configs/smdk5420_defconfig  | 1 -
 configs/snow_defconfig      | 1 -
 configs/spring_defconfig    | 1 -
 6 files changed, 6 deletions(-)
configs/peach-pi_defconfig +0 -1
index 5ced3423160..32b32dd901c 100644
@@ -29,7 +29,6 @@ CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5800-peach-pi"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
configs/peach-pit_defconfig +0 -1
index b1fe3f73abb..7018737ab4f 100644
@@ -28,7 +28,6 @@ CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5420-peach-pit"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
configs/smdk5250_defconfig +0 -1
index 90ee0ffbc9d..1e058227e41 100644
@@ -30,7 +30,6 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5250-smdk5250"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_S5P=y
configs/smdk5420_defconfig +0 -1
index 433e9a8447f..4e4558944cc 100644
@@ -25,7 +25,6 @@ CONFIG_CMD_TIME=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5420-smdk5420"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_S5P=y
configs/snow_defconfig +0 -1
index 4d1c53d4291..10e11fbb337 100644
@@ -34,7 +34,6 @@ CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5250-snow"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
configs/spring_defconfig +0 -1
index 8f9436c74af..844a87734b8 100644
@@ -34,7 +34,6 @@ CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_DEFAULT_DEVICE_TREE="exynos5250-spring"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#34 lore raw

PATCH v2 17/22 dm: exynos: Drop CONFIG_DM_I2C_COMPAT

This option is not needed anymore for all exynos boards except arndale. Update the config.

---

Changes in v2: None

 configs/peach-pi_defconfig  | 1 -
 configs/peach-pit_defconfig | 1 -
 configs/smdk5250_defconfig  | 1 -
 configs/smdk5420_defconfig  | 1 -
 configs/snow_defconfig      | 1 -
 configs/spring_defconfig    | 1 -
 6 files changed, 6 deletions(-)

Applied to u-boot-dm/master

#35 lore raw

PATCH v2 18/22 dm: sound: Complete migration to driver model

In reply to Simon Glass

All users of sound are converted to use driver model. Drop the old code and the CONFIG_DM_SOUND option.

---

Changes in v2:
- Drop CONFIG_DM_SOUND from all defconfig files
- Fix up sandbox files to remove old code
- Update the rest of the samsung boards
- Remove unused sandbox code also
- Drop patches previously applied

 arch/sandbox/cpu/sdl.c           |   1 -
 arch/sandbox/include/asm/sdl.h   |  21 ++--
 arch/sandbox/include/asm/sound.h |  13 --
 cmd/sound.c                      |  12 --
 configs/arndale_defconfig        |   1 -
 configs/peach-pi_defconfig       |   1 -
 configs/peach-pit_defconfig      |   1 -
 configs/smdk5250_defconfig       |   1 -
 configs/snow_defconfig           |   1 -
 configs/spring_defconfig         |   1 -
 drivers/sound/Kconfig            |   6 -
 drivers/sound/Makefile           |  10 +-
 drivers/sound/max98095.c         |  78 ------------
 drivers/sound/sandbox.c          |  19 +--
 drivers/sound/sound-i2s.c        | 206 -------------------------------
 drivers/sound/wm8994.c           |  95 --------------
 include/sound.h                  |  18 ---
 test/dm/Makefile                 |   6 +-
 18 files changed, 16 insertions(+), 475 deletions(-)
 delete mode 100644 arch/sandbox/include/asm/sound.h
 delete mode 100644 drivers/sound/sound-i2s.c
arch/sandbox/cpu/sdl.c +0 -1
index 8fc7c172e3a..7eb2df7ddad 100644
@@ -7,7 +7,6 @@
 #include <unistd.h>
 #include <linux/input.h>
 #include <SDL/SDL.h>
-#include <sound.h>
 #include <asm/state.h>
 
 enum {
arch/sandbox/include/asm/sdl.h +9 -12
index 0143ed9e621..2799a8bee06 100644
@@ -54,12 +54,12 @@ int sandbox_sdl_scan_keys(int key[], int max_keys);
 int sandbox_sdl_key_pressed(int keycode);
 
 /**
- * sandbox_sdl_sound_start() - start playing a sound
+ * sandbox_sdl_sound_play() - Play a sound
  *
- * @frequency:	Frequency of sounds in Hertz
- * @return 0 if OK, -ENODEV if no sound is available
+ * @data:	Data to play (typically 16-bit)
+ * @count:	Number of bytes in data
  */
-int sandbox_sdl_sound_start(uint frequency);
+int sandbox_sdl_sound_play(const void *data, uint count);
 
 /**
  * sandbox_sdl_sound_stop() - stop playing a sound
@@ -68,14 +68,6 @@ 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
  *
@@ -110,6 +102,11 @@ static inline int sandbox_sdl_sound_start(uint frequency)
 	return -ENODEV;
 }
 
+int sandbox_sdl_sound_play(const void *data, uint count)
+{
+	return -ENODEV;
+}
+
 static inline int sandbox_sdl_sound_stop(void)
 {
 	return -ENODEV;
arch/sandbox/include/asm/sound.h deleted +0 -13
deleted file mode 100644
index a6015b0f60f..00000000000
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (c) 2013 Google, Inc
- */
-
-#ifndef __SANDBOX_SOUND_H
-#define __SANDBOX_SOUND_H
-
-int sound_play(unsigned int msec, unsigned int frequency);
-
-int sound_init(const void *blob);
-
-#endif
cmd/sound.c +0 -12
index 77f51529259..638f29df21d 100644
@@ -15,18 +15,12 @@ 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 (ret=%d)\n", ret);
 		return CMD_RET_FAILURE;
@@ -38,9 +32,7 @@ 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;
@@ -50,13 +42,9 @@ 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("Sound device failed to play (err=%d)\n", ret);
 		return CMD_RET_FAILURE;
configs/arndale_defconfig +0 -1
index 22881c3a2c6..2b6af4b2215 100644
@@ -31,7 +31,6 @@ CONFIG_MMC_SDHCI_S5P=y
 CONFIG_SMC911X=y
 CONFIG_SMC911X_BASE=0x5000000
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/peach-pi_defconfig +0 -1
index 32b32dd901c..14c835cad81 100644
@@ -50,7 +50,6 @@ CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98090=y
configs/peach-pit_defconfig +0 -1
index 7018737ab4f..9a3a11504de 100644
@@ -49,7 +49,6 @@ CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98090=y
configs/smdk5250_defconfig +0 -1
index 1e058227e41..21018d8b1b1 100644
@@ -43,7 +43,6 @@ CONFIG_DM_PMIC_MAX77686=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/snow_defconfig +0 -1
index 10e11fbb337..e0c1bf862c0 100644
@@ -60,7 +60,6 @@ CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
configs/spring_defconfig +0 -1
index 844a87734b8..c089517692e 100644
@@ -60,7 +60,6 @@ CONFIG_DM_PWM=y
 CONFIG_PWM_EXYNOS=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_SOUND=y
-CONFIG_DM_SOUND=y
 CONFIG_I2S=y
 CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
drivers/sound/Kconfig +0 -6
index 18d7ca1dcb3..c0d97cca338 100644
@@ -12,12 +12,6 @@ config SOUND
 	  audio codecs are called from the sound-i2s code. This could be
 	  converted to driver model.
 
-config DM_SOUND
-	bool "Use driver model for sound"
-	help
-	  Enable this option to use driver model for sound devices. This is a
-	  migration option and will be removed.
-
 config I2S
 	bool "Enable I2S support"
 	depends on SOUND
drivers/sound/Makefile +3 -7
index 937df152fe6..1de4346ec7a 100644
@@ -4,16 +4,12 @@
 # R. Chandrasekar <[email protected]>
 
 obj-$(CONFIG_SOUND)	+= sound.o
-obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o
-obj-$(CONFIG_DM_SOUND)	+= i2s-uclass.o
-obj-$(CONFIG_DM_SOUND)	+= sound-uclass.o
+obj-$(CONFIG_SOUND)	+= codec-uclass.o
+obj-$(CONFIG_SOUND)	+= i2s-uclass.o
+obj-$(CONFIG_SOUND)	+= sound-uclass.o
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o
 obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o
-ifdef CONFIG_DM_SOUND
 obj-$(CONFIG_I2S_SAMSUNG)	+= samsung_sound.o
-else
-obj-$(CONFIG_I2S)	+= sound-i2s.o
-endif
 obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
 obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
drivers/sound/max98095.c +0 -78

84 lines not on this page · raw message

drivers/sound/sandbox.c +1 -18
index ee2635f41d2..4a3b41dd002 100644
@@ -8,7 +8,6 @@
 #include <dm.h>
 #include <i2s.h>
 #include <sound.h>
-#include <asm/sound.h>
 #include <asm/sdl.h>
 
 struct sandbox_codec_priv {
@@ -28,22 +27,6 @@ struct sandbox_sound_priv {
 	int sum;	/* Use to sum the provided audio data */
 };
 
-#ifndef CONFIG_DM_SOUND
-int sound_play(uint32_t msec, uint32_t frequency)
-{
-	sandbox_sdl_sound_start(frequency);
-	mdelay(msec);
-	sandbox_sdl_sound_stop();
-
-	return 0;
-}
-#endif /* CONFIG_DM_SOUND */
-
-int sound_init(const void *blob)
-{
-	return sandbox_sdl_sound_init();
-}
-
 void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
 			      int *mclk_freqp, int *bits_per_samplep,
 			      uint *channelsp)
@@ -102,7 +85,7 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
 	for (i = 0; i < data_size; i++)
 		priv->sum += ((uint8_t *)data)[i];
 
-	return 0;
+	return sandbox_sdl_sound_play(data, data_size);
 }
 
 static int sandbox_i2s_probe(struct udevice *dev)
drivers/sound/sound-i2s.c deleted +0 -206

206 lines not on this page · raw message

drivers/sound/wm8994.c +0 -95

127 lines not on this page · raw message

include/sound.h +0 -18
index c94d2c37265..02acefd34f0 100644
@@ -45,14 +45,6 @@ struct sound_uc_priv {
 void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
 			      uint freq);
 
-/*
- * Initialises audio sub system
- * @param blob	Pointer of device tree node or NULL if none.
- * @return	int value 0 for success, -1 for error
- */
-int sound_init(const void *blob);
-
-#ifdef CONFIG_DM_SOUND
 /*
  * The sound uclass brings together a data transport (currently only I2C) and a
  * codec (currently connected over I2C).
@@ -101,14 +93,4 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz);
  */
 int sound_find_codec_i2s(struct udevice *dev);
 
-#else
-/*
- * plays the pcm data buffer in pcm_data.h through i2s1 to make the
- * sine wave sound
- *
- * @return	int 0 for success, -1 for error
- */
-int sound_play(uint32_t msec, uint32_t frequency);
-#endif /* CONFIG_DM_SOUND */
-
 #endif  /* __SOUND__H__ */
test/dm/Makefile +3 -3
index 73f5dcf739e..6b451060d8a 100644
@@ -13,7 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
-obj-$(CONFIG_DM_SOUND) += audio.o
+obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
 obj-$(CONFIG_CLK) += clk.o
@@ -22,7 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
-obj-$(CONFIG_DM_SOUND) += i2s.o
+obj-$(CONFIG_SOUND) += i2s.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
@@ -55,7 +55,7 @@ obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_MISC) += misc.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_CPU) += cpu.o
-obj-$(CONFIG_DM_SOUND) += sound.o
+obj-$(CONFIG_SOUND) += sound.o
 obj-$(CONFIG_TEE) += tee.o
 obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
 obj-$(CONFIG_DMA) += dma.o
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#36 lore raw

PATCH v2 18/22 dm: sound: Complete migration to driver model

All users of sound are converted to use driver model. Drop the old code and the CONFIG_DM_SOUND option.

---

Changes in v2:
- Drop CONFIG_DM_SOUND from all defconfig files
- Fix up sandbox files to remove old code
- Update the rest of the samsung boards
- Remove unused sandbox code also
- Drop patches previously applied

 arch/sandbox/cpu/sdl.c           |   1 -
 arch/sandbox/include/asm/sdl.h   |  21 ++--
 arch/sandbox/include/asm/sound.h |  13 --
 cmd/sound.c                      |  12 --
 configs/arndale_defconfig        |   1 -
 configs/peach-pi_defconfig       |   1 -
 configs/peach-pit_defconfig      |   1 -
 configs/smdk5250_defconfig       |   1 -
 configs/snow_defconfig           |   1 -
 configs/spring_defconfig         |   1 -
 drivers/sound/Kconfig            |   6 -
 drivers/sound/Makefile           |  10 +-
 drivers/sound/max98095.c         |  78 ------------
 drivers/sound/sandbox.c          |  19 +--
 drivers/sound/sound-i2s.c        | 206 -------------------------------
 drivers/sound/wm8994.c           |  95 --------------
 include/sound.h                  |  18 ---
 test/dm/Makefile                 |   6 +-
 18 files changed, 16 insertions(+), 475 deletions(-)
 delete mode 100644 arch/sandbox/include/asm/sound.h
 delete mode 100644 drivers/sound/sound-i2s.c

Applied to u-boot-dm/master

#37 lore raw

PATCH v2 19/22 dm: sound: Fix license headers

In reply to Simon Glass

Fix a few files whos license headers were not converted to SPDX.

---

Changes in v2:
- Add new patch to fix license headers

 drivers/sound/max98095.c | 7 ++-----
 drivers/sound/max98095.h | 5 +----
 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/sound/max98095.c +2 -5
index 93be50c34a2..624c5d24ef3 100644
@@ -1,13 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * max98095.c -- MAX98095 ALSA SoC Audio driver
  *
  * Copyright 2011 Maxim Integrated Products
  *
- * Modified for uboot by R. Chandrasekar (rcsekar at samsung.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * Modified for U-Boot by R. Chandrasekar (rcsekar at samsung.com)
  */
 
 #include <common.h>
drivers/sound/max98095.h +1 -4
index f189db728d1..1521f3f02f9 100644
@@ -1,11 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * max98095.h -- MAX98095 ALSA SoC Audio driver
  *
  * Copyright 2011 Maxim Integrated Products
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef _MAX98095_H
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#38 lore raw

PATCH v2 19/22 dm: sound: Fix license headers

Fix a few files whos license headers were not converted to SPDX.

---

Changes in v2:
- Add new patch to fix license headers

 drivers/sound/max98095.c | 7 ++-----
 drivers/sound/max98095.h | 5 +----
 2 files changed, 3 insertions(+), 9 deletions(-)

Applied to u-boot-dm/master

#39 lore raw

PATCH v2 20/22 dm: sound: max98095: Tidy up error codes

In reply to Simon Glass

Return a valid error code instead of -1.

---

Changes in v2:
- Add new patch to tidy up error codes in max98095

 drivers/sound/max98095.c | 47 ++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 24 deletions(-)
drivers/sound/max98095.c +23 -24
index 624c5d24ef3..99c0e996b4f 100644
@@ -46,7 +46,7 @@ static int rate_value(int rate, u8 *value)
 	}
 	*value = 1;
 
-	return -1;
+	return -EINVAL;
 }
 
 /*
@@ -56,7 +56,7 @@ static int rate_value(int rate, u8 *value)
  * @param rate		Sampling rate
  * @param bits_per_sample	Bits per sample
  *
- * @return -1 for error  and 0  Success.
+ * @return	0 for success or negative error code.
  */
 static int max98095_hw_params(struct maxim_priv *priv,
 			      enum en_max_audio_interface aif_id,
@@ -89,13 +89,13 @@ static int max98095_hw_params(struct maxim_priv *priv,
 	default:
 		debug("%s: Illegal bits per sample %d.\n",
 		      __func__, bits_per_sample);
-		return -1;
+		return -EINVAL;
 	}
 
 	if (rate_value(rate, &regval)) {
 		debug("%s: Failed to set sample rate to %d.\n",
 		      __func__, rate);
-		return -1;
+		return -EINVAL;
 	}
 	priv->rate = rate;
 
@@ -112,7 +112,7 @@ static int max98095_hw_params(struct maxim_priv *priv,
 
 	if (error < 0) {
 		debug("%s: Error setting hardware params.\n", __func__);
-		return -1;
+		return -EIO;
 	}
 
 	return 0;
@@ -124,7 +124,7 @@ static int max98095_hw_params(struct maxim_priv *priv,
  * @param priv		max98095 information
  * @param freq		Sampling frequency in Hz
  *
- * @return -1 for error and 0 success.
+ * @return	0 for success or negative error code.
  */
 static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq)
 {
@@ -147,13 +147,13 @@ static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq)
 		error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x30);
 	} else {
 		debug("%s: Invalid master clock frequency\n", __func__);
-		return -1;
+		return -EINVAL;
 	}
 
 	debug("%s: Clock@%uHz\n", __func__, freq);
 
 	if (error < 0)
-		return -1;
+		return -EIO;
 
 	priv->sysclk = freq;
 	return 0;
@@ -166,7 +166,7 @@ static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq)
  * @param fmt		i2S format - supports a subset of the options defined
  *			in i2s.h.
  *
- * @return -1 for error and 0  Success.
+ * @return	0 for success or negative error code.
  */
 static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
 			    enum en_max_audio_interface aif_id)
@@ -209,7 +209,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
 	case SND_SOC_DAIFMT_CBM_CFS:
 	default:
 		debug("%s: Clock mode unsupported\n", __func__);
-		return -1;
+		return -EINVAL;
 	}
 
 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -220,7 +220,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
 		break;
 	default:
 		debug("%s: Unrecognized format.\n", __func__);
-		return -1;
+		return -EINVAL;
 	}
 
 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -237,7 +237,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
 		break;
 	default:
 		debug("%s: Unrecognized inversion settings.\n", __func__);
-		return -1;
+		return -EINVAL;
 	}
 
 	error |= maxim_bic_or(priv, M98095_DAI_FORMAT,
@@ -248,7 +248,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
 
 	if (error < 0) {
 		debug("%s: Error setting i2s format.\n", __func__);
-		return -1;
+		return -EIO;
 	}
 
 	return 0;
@@ -258,7 +258,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
  * resets the audio codec
  *
  * @param priv	Private data for driver
- * @return -1 for error and 0 success.
+ * @return	0 for success or negative error code.
  */
 static int max98095_reset(struct maxim_priv *priv)
 {
@@ -299,22 +299,21 @@ static int max98095_reset(struct maxim_priv *priv)
  * Intialise max98095 codec device
  *
  * @param priv		max98095 information
- *
- * @returns -1 for error  and 0 Success.
+ * @return	0 for success or negative error code.
  */
 static int max98095_device_init(struct maxim_priv *priv)
 {
 	unsigned char id;
-	int error = 0;
+	int ret;
 
 	/* Enable codec clock */
 	set_xclkout();
 
 	/* reset the codec, the DSP core, and disable all interrupts */
-	error = max98095_reset(priv);
-	if (error != 0) {
+	ret = max98095_reset(priv);
+	if (ret != 0) {
 		debug("Reset\n");
-		return error;
+		return ret;
 	}
 
 	/* initialize private data */
@@ -322,11 +321,11 @@ static int max98095_device_init(struct maxim_priv *priv)
 	priv->rate = -1U;
 	priv->fmt = -1U;
 
-	error = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id);
-	if (error < 0) {
+	ret = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id);
+	if (ret < 0) {
 		debug("%s: Failure reading hardware revision: %d\n",
 		      __func__, id);
-		return error;
+		return ret;
 	}
 	debug("%s: Hardware revision: %c\n", __func__, (id - 0x40) + 'A');
 
@@ -392,7 +391,7 @@ static int max98095_setup_interface(struct maxim_priv *priv,
 		error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07);
 
 	if (error < 0)
-		return -1;
+		return -EIO;
 
 	return 0;
 }
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#40 lore raw

PATCH v2 20/22 dm: sound: max98095: Tidy up error codes

Return a valid error code instead of -1.

---

Changes in v2:
- Add new patch to tidy up error codes in max98095

 drivers/sound/max98095.c | 47 ++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

Applied to u-boot-dm/master

#41 lore raw

PATCH v2 21/22 dm: sandbox: Allow selection of sample rate and channels

In reply to Simon Glass

At present these parameters are hard-coded in the sdl interface code. Allow them to be specified by the driver instead.

---

Changes in v2: None

 arch/sandbox/cpu/sdl.c         | 10 +++-------
 arch/sandbox/include/asm/sdl.h |  6 ++++--
 drivers/sound/sandbox.c        |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)
arch/sandbox/cpu/sdl.c +3 -7
index 7eb2df7ddad..66de4040fc8 100644
@@ -9,10 +9,6 @@
 #include <SDL/SDL.h>
 #include <asm/state.h>
 
-enum {
-	SAMPLE_RATE	= 22050,
-};
-
 /**
  * struct buf_info - a data buffer holding audio data
  *
@@ -285,7 +281,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
 	}
 }
 
-int sandbox_sdl_sound_init(void)
+int sandbox_sdl_sound_init(int rate, int channels)
 {
 	SDL_AudioSpec wanted;
 	int i;
@@ -297,9 +293,9 @@ int sandbox_sdl_sound_init(void)
 		return 0;
 
 	/* Set the audio format */
-	wanted.freq = SAMPLE_RATE;
+	wanted.freq = rate;
 	wanted.format = AUDIO_S16;
-	wanted.channels = 1;    /* 1 = mono, 2 = stereo */
+	wanted.channels = channels;
 	wanted.samples = 1024;  /* Good low-latency value for callback */
 	wanted.callback = sandbox_sdl_fill_audio;
 	wanted.userdata = NULL;
arch/sandbox/include/asm/sdl.h +4 -2
index 2799a8bee06..1027b59e732 100644
@@ -71,9 +71,11 @@ int sandbox_sdl_sound_stop(void);
 /**
  * sandbox_sdl_sound_init() - set up the sound system
  *
+ * @rate:	Sample rate to use
+ * @channels:	Number of channels to use (1=mono, 2=stereo)
  * @return 0 if OK, -ENODEV if no sound is available
  */
-int sandbox_sdl_sound_init(void);
+int sandbox_sdl_sound_init(int rate, int channels);
 
 #else
 static inline int sandbox_sdl_init_display(int width, int height,
@@ -112,7 +114,7 @@ static inline int sandbox_sdl_sound_stop(void)
 	return -ENODEV;
 }
 
-static inline int sandbox_sdl_sound_init(void)
+int sandbox_sdl_sound_init(int rate, int channels)
 {
 	return -ENODEV;
 }
drivers/sound/sandbox.c +1 -1
index 4a3b41dd002..a4f15088236 100644
@@ -101,7 +101,7 @@ static int sandbox_i2s_probe(struct udevice *dev)
 	uc_priv->channels = 2;
 	uc_priv->id = 1;
 
-	return sandbox_sdl_sound_init();
+	return sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
 }
 
 static int sandbox_sound_setup(struct udevice *dev)
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#42 lore raw

PATCH v2 21/22 dm: sandbox: Allow selection of sample rate and channels

At present these parameters are hard-coded in the sdl interface code. Allow them to be specified by the driver instead.

---

Changes in v2: None

 arch/sandbox/cpu/sdl.c         | 10 +++-------
 arch/sandbox/include/asm/sdl.h |  6 ++++--
 drivers/sound/sandbox.c        |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)

Applied to u-boot-dm/master

#43 lore raw

PATCH v2 22/22 dm: sound: Use the correct number of channels for sound

In reply to Simon Glass

At present the 'beep' sound generates a waveform for only one channel even if two are being used. This means that the beep is twice the frequency it should be. Correct this by making it a parameter.

The fix in a previous commit was correct for sandbox but not for other boards.

Fixes 03f11e87a8 ("sound: Correct data output in sound_create_square_wave()")

---

Changes in v2:
- Add new patch to use the correct number of channels for sound

 drivers/sound/sound-uclass.c |  2 +-
 drivers/sound/sound.c        | 11 +++++++----
 include/sound.h              | 11 ++++++-----
 3 files changed, 14 insertions(+), 10 deletions(-)
drivers/sound/sound-uclass.c +1 -1
index 71e753cb993..2b836268896 100644
@@ -53,7 +53,7 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz)
 	}
 
 	sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size,
-				 frequency_hz);
+				 frequency_hz, i2s_uc_priv->channels);
 
 	while (msecs >= 1000) {
 		ret = sound_play(dev, data, data_size);
drivers/sound/sound.c +7 -4
index 4f0ad0d8f0d..dd3f9db4f75 100644
@@ -8,7 +8,7 @@
 #include <sound.h>
 
 void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
-			      uint freq)
+			      uint freq, uint channels)
 {
 	const unsigned short amplitude = 16000; /* between 1 and 32767 */
 	const int period = freq ? sample_rate / freq : 0;
@@ -21,14 +21,17 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
 		size--;
 
 	while (size) {
-		int i;
+		int i, j;
+
 		for (i = 0; size && i < half; i++) {
 			size -= 2;
-			*data++ = amplitude;
+			for (j = 0; j < channels; j++)
+				*data++ = amplitude;
 		}
 		for (i = 0; size && i < period - half; i++) {
 			size -= 2;
-			*data++ = -amplitude;
+			for (j = 0; j < channels; j++)
+				*data++ = -amplitude;
 		}
 	}
 }
include/sound.h +6 -5
index 02acefd34f0..b7959cc2607 100644
@@ -37,13 +37,14 @@ struct sound_uc_priv {
 /**
  * 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 in bytes
- * @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);
 
 /*
  * The sound uclass brings together a data transport (currently only I2C) and a
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
#44 lore raw

PATCH v2 22/22 dm: sound: Use the correct number of channels for sound

At present the 'beep' sound generates a waveform for only one channel even if two are being used. This means that the beep is twice the frequency it should be. Correct this by making it a parameter.

The fix in a previous commit was correct for sandbox but not for other boards.

Fixes 03f11e87a8 ("sound: Correct data output in sound_create_square_wave()")

---

Changes in v2:
- Add new patch to use the correct number of channels for sound

 drivers/sound/sound-uclass.c |  2 +-
 drivers/sound/sound.c        | 11 +++++++----
 include/sound.h              | 11 ++++++-----
 3 files changed, 14 insertions(+), 10 deletions(-)

Applied to u-boot-dm/master