[U-Boot] [PATCH 0/7 V2] EXYNOS5: FDT support for Sound

This patch adds FDT support for Sound driver.
This patch is based on following patchset. "EXYNOS5: FDT Support for I2C"
Changes in V2: - Add documentation for sound node. - Decoding codec FDT values moved to codec. - fd_dec_lookup function added to header file. - Single sound init funtion to handle both fdt and non fdt support. - Removed SPI compatible string.
Rajeshwari Shinde (7): FDT: Declare API in header file. EXYNOS5: FDT: Add sound device node data EXYNOS5: FDT: Add sound and codec device node EXYNOS5: FDT: Add compatible strings for sound Sound: Add FDT support to driver Sound: WM8994: Add FDT support to codec Sound: Add FDT support to CMD.
arch/arm/dts/exynos5250.dtsi | 5 + board/samsung/dts/exynos5250-smdk5250.dts | 17 +++ common/cmd_sound.c | 6 +- doc/device-tree-bindings/exynos/sound.txt | 27 +++++ drivers/sound/sound.c | 180 +++++++++++++++++----------- drivers/sound/wm8994.c | 83 +++++++++++++- drivers/sound/wm8994.h | 6 +- include/fdtdec.h | 15 +++ include/sound.h | 9 ++ lib/fdtdec.c | 2 + 10 files changed, 272 insertions(+), 78 deletions(-) create mode 100644 doc/device-tree-bindings/exynos/sound.txt

Added fd_dec_lookup function to header file.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - New patch. include/fdtdec.h | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h index f9aac31..89030aa 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -389,4 +389,17 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, */ const u8 *fdtdec_locate_byte_array(const void *blob, int node, const char *prop_name, int count); + +/** + * Find the compatible ID for a given node. + * + * Generally each node has at least one compatible string attached to it. + * This function looks through our list of known compatible strings and + * returns the corresponding ID which matches the compatible string. + * + * @param blob FDT blob to use + * @param node Node containing compatible string to find + * @return compatible ID, or COMPAT_UNKNOWN if we cannot find a match + */ +enum fdt_compat_id fd_dec_lookup(const void *blob, int node); #endif

Hi Rajeshwari,
On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
Added fd_dec_lookup function to header file.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Actually I think my patch to fix the name and export this function has already landed in mainline, so you should be able to drop this patch. It is now called fdtdec_lookup().
Regards, Simon
Changes in V2: - New patch. include/fdtdec.h | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h index f9aac31..89030aa 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -389,4 +389,17 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, */ const u8 *fdtdec_locate_byte_array(const void *blob, int node, const char *prop_name, int count);
+/**
- Find the compatible ID for a given node.
- Generally each node has at least one compatible string attached to it.
- This function looks through our list of known compatible strings and
- returns the corresponding ID which matches the compatible string.
- @param blob FDT blob to use
- @param node Node containing compatible string to find
- @return compatible ID, or COMPAT_UNKNOWN if we cannot find a match
- */
+enum fdt_compat_id fd_dec_lookup(const void *blob, int node);
#endif
1.7.4.4

Add sound device node data for exynos
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - Added documentation to sound node. arch/arm/dts/exynos5250.dtsi | 5 +++++ doc/device-tree-bindings/exynos/sound.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) create mode 100644 doc/device-tree-bindings/exynos/sound.txt
diff --git a/arch/arm/dts/exynos5250.dtsi b/arch/arm/dts/exynos5250.dtsi index e877e6c..3f750f0 100644 --- a/arch/arm/dts/exynos5250.dtsi +++ b/arch/arm/dts/exynos5250.dtsi @@ -97,4 +97,9 @@ reg = <0x12CD0000 0x100>; interrupts = <0 63 0>; }; + + sound@12d60000 { + compatible = "samsung,exynos-sound"; + reg = <0x12d60000 0x20>; + }; }; diff --git a/doc/device-tree-bindings/exynos/sound.txt b/doc/device-tree-bindings/exynos/sound.txt new file mode 100644 index 0000000..98d1798 --- /dev/null +++ b/doc/device-tree-bindings/exynos/sound.txt @@ -0,0 +1,27 @@ +Exynos Sound Subsystem + +The device node for sound subsytem which contains codec and i2s block +that is a part of Exynos5250 + +Required properties : + - compatible : Should be "samsung,exynos-sound" for sound + - samsung,i2s-epll-clock-frequency : epll clock output frequency in Hz + - samsung,i2s-sampling-rate : sampling rate, default is 48000 + - samsung,i2s-bits-per-sample : sample width, defalut is 16 bit + - samsung,i2s-channels : nummber of channels, default is 2 + - samsung,i2s-lr-clk-framesize : lr clock frame size + - samsung,i2s-bit-clk-framesize : bit clock frame size + - samsung,codec-type : sound codec type + +Example: + +sound@12d60000 { + compatible = "samsung,exynos-sound" + 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,codec-type = "wm8994"; +};

On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
Add sound device node data for exynos
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Acked-by: Simon Glass sjg@chromium.org
(see comment below)
Changes in V2: - Added documentation to sound node. arch/arm/dts/exynos5250.dtsi | 5 +++++ doc/device-tree-bindings/exynos/sound.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) create mode 100644 doc/device-tree-bindings/exynos/sound.txt
diff --git a/arch/arm/dts/exynos5250.dtsi b/arch/arm/dts/exynos5250.dtsi index e877e6c..3f750f0 100644 --- a/arch/arm/dts/exynos5250.dtsi +++ b/arch/arm/dts/exynos5250.dtsi @@ -97,4 +97,9 @@ reg = <0x12CD0000 0x100>; interrupts = <0 63 0>; };
sound@12d60000 {
compatible = "samsung,exynos-sound";
reg = <0x12d60000 0x20>;
};
}; diff --git a/doc/device-tree-bindings/exynos/sound.txt b/doc/device-tree-bindings/exynos/sound.txt new file mode 100644 index 0000000..98d1798 --- /dev/null +++ b/doc/device-tree-bindings/exynos/sound.txt @@ -0,0 +1,27 @@ +Exynos Sound Subsystem
+The device node for sound subsytem which contains codec and i2s block +that is a part of Exynos5250
+Required properties :
- compatible : Should be "samsung,exynos-sound" for sound
- samsung,i2s-epll-clock-frequency : epll clock output frequency in Hz
- samsung,i2s-sampling-rate : sampling rate, default is 48000
- samsung,i2s-bits-per-sample : sample width, defalut is 16 bit
- samsung,i2s-channels : nummber of channels, default is 2
- samsung,i2s-lr-clk-framesize : lr clock frame size
- samsung,i2s-bit-clk-framesize : bit clock frame size
- samsung,codec-type : sound codec type
+Example:
+sound@12d60000 {
compatible = "samsung,exynos-sound"
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,codec-type = "wm8994";
Strictly speaking this should not be needed, but you use it as a way to call your driver, which is reasonable until we have device model, so this is fine I think.
+};
1.7.4.4
Regards, Simon

Adds sound and codec device node parameters
Signed-off-by: R. Chandrasekar rcsekar@samsung.com Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - codec type moved single sound node. board/samsung/dts/exynos5250-smdk5250.dts | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/board/samsung/dts/exynos5250-smdk5250.dts b/board/samsung/dts/exynos5250-smdk5250.dts index 8722b36..1562721 100644 --- a/board/samsung/dts/exynos5250-smdk5250.dts +++ b/board/samsung/dts/exynos5250-smdk5250.dts @@ -50,4 +50,21 @@ samsung,slope = <268470274>; samsung,dc-value = <25>; }; + + sound@12d60000 { + 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,codec-type = "wm8994"; + }; + + i2c@12c70000 { + soundcodec@1a { + reg = <0x1a>; + compatible = "wolfson,wm8994-codec"; + }; + }; };

On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
Adds sound and codec device node parameters
Signed-off-by: R. Chandrasekar rcsekar@samsung.com Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Acked-by: Simon Glass sjg@chromium.org
Changes in V2: - codec type moved single sound node. board/samsung/dts/exynos5250-smdk5250.dts | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/board/samsung/dts/exynos5250-smdk5250.dts b/board/samsung/dts/exynos5250-smdk5250.dts index 8722b36..1562721 100644 --- a/board/samsung/dts/exynos5250-smdk5250.dts +++ b/board/samsung/dts/exynos5250-smdk5250.dts @@ -50,4 +50,21 @@ samsung,slope = <268470274>; samsung,dc-value = <25>; };
sound@12d60000 {
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,codec-type = "wm8994";
};
i2c@12c70000 {
soundcodec@1a {
reg = <0x1a>;
compatible = "wolfson,wm8994-codec";
};
};
};
1.7.4.4

Add required compatible information for sound driver.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - Removed SPI string. include/fdtdec.h | 2 ++ lib/fdtdec.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h index 89030aa..8efb89f 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -70,6 +70,8 @@ enum fdt_compat_id { COMPAT_SAMSUNG_EXYNOS5_SROMC, /* Exynos5 SROMC */ COMPAT_SAMSUNG_EXYNOS_TMU, /* Exynos TMU */ COMPAT_SAMSUNG_S3C2440_I2C, /* Exynos I2C Controller */ + COMPAT_SAMSUNG_EXYNOS5_SOUND, /* Exynos Sound */ + COMPAT_WOLFSON_WM8994_CODEC, /* Wolfson WM8994 Sound Codec */
COMPAT_COUNT, }; diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 6e8c24c..87dc32f 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -47,6 +47,8 @@ static const char * const compat_names[COMPAT_COUNT] = { COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"), COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"), COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"), + COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"), + COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"), };
const char *fdtdec_get_compatible(enum fdt_compat_id id)

On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
Add required compatible information for sound driver.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Acked-by: Simon Glass sjg@chromium.org
Changes in V2: - Removed SPI string. include/fdtdec.h | 2 ++ lib/fdtdec.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h index 89030aa..8efb89f 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -70,6 +70,8 @@ enum fdt_compat_id { COMPAT_SAMSUNG_EXYNOS5_SROMC, /* Exynos5 SROMC */ COMPAT_SAMSUNG_EXYNOS_TMU, /* Exynos TMU */ COMPAT_SAMSUNG_S3C2440_I2C, /* Exynos I2C Controller */
COMPAT_SAMSUNG_EXYNOS5_SOUND, /* Exynos Sound */
COMPAT_WOLFSON_WM8994_CODEC, /* Wolfson WM8994 Sound Codec */ COMPAT_COUNT,
}; diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 6e8c24c..87dc32f 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -47,6 +47,8 @@ static const char * const compat_names[COMPAT_COUNT] = { COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"), COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"), COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"),
COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"),
COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"),
};
const char *fdtdec_get_compatible(enum fdt_compat_id id)
1.7.4.4

This patch adds FDT support to the sound driver.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - Made single function to get i2s values,codec init and sount init in both FDT and non FDT support case. drivers/sound/sound.c | 179 +++++++++++++++++++++++++++++------------------- include/sound.h | 4 +- 2 files changed, 110 insertions(+), 73 deletions(-)
diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4c74534..bc87a9b 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -28,108 +28,160 @@ #include <i2s.h> #include <sound.h> #include "wm8994.h" +#ifdef CONFIG_OF_CONTROL +#include <libfdt.h> +#include <fdtdec.h> +#else #include <asm/arch/sound.h> +#endif
/* defines */ #define SOUND_400_HZ 400 #define SOUND_BITS_IN_BYTE 8
static struct i2stx_info g_i2stx_pri; -static struct sound_codec_info g_codec_info;
/* - * get_sound_fdt_values gets fdt values for i2s parameters + * get_sound_i2s_values gets values for i2s parameters * * @param i2stx_info i2s transmitter transfer param structure - * @param blob FDT blob + * @param blob FDT blob if enabled else NULL */ -static void get_sound_i2s_values(struct i2stx_info *i2s) -{ - i2s->base_address = samsung_get_base_i2s(); - i2s->audio_pll_clk = I2S_PLL_CLK; - i2s->samplingrate = I2S_SAMPLING_RATE; - i2s->bitspersample = I2S_BITS_PER_SAMPLE; - i2s->channels = I2S_CHANNELS; - i2s->rfs = I2S_RFS; - i2s->bfs = I2S_BFS; -} - -/* - * Gets fdt values for wm8994 config parameters - * - * @param pcodec_info codec information structure - * @param blob FDT blob - * @return int value, 0 for success - */ -static int get_sound_wm8994_values(struct sound_codec_info *pcodec_info) +static int get_sound_i2s_values(struct i2stx_info *i2s, const void *blob) { +#ifdef CONFIG_OF_CONTROL + int node; int error = 0; + int base;
- switch (AUDIO_COMPAT) { - case AUDIO_COMPAT_SPI: - debug("%s: Support not added for SPI interface\n", __func__); + node = fdtdec_next_compatible(blob, 0, + COMPAT_SAMSUNG_EXYNOS5_SOUND); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for sound in device tree\n"); return -1; - break; - case AUDIO_COMPAT_I2C: - pcodec_info->i2c_bus = AUDIO_I2C_BUS; - pcodec_info->i2c_dev_addr = AUDIO_I2C_REG; - debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); - break; - default: - debug("%s: Unknown compat id %d\n", __func__, AUDIO_COMPAT); + } + + /* + * Get the pre-defined sound specific values from FDT. + * All of these are expected to be correct otherwise + * wrong register values in i2s setup parameters + * may result in no sound play. + */ + base = fdtdec_get_addr(blob, node, "reg"); + if (base == FDT_ADDR_T_NONE) { + debug("%s: Missing i2s base\n", __func__); return -1; } + i2s->base_address = base;
+ i2s->audio_pll_clk = fdtdec_get_int(blob, + node, "samsung,i2s-epll-clock-frequency", -1); + error |= i2s->audio_pll_clk; + debug("audio_pll_clk = %d\n", i2s->audio_pll_clk); + i2s->samplingrate = fdtdec_get_int(blob, + node, "samsung,i2s-sampling-rate", -1); + error |= i2s->samplingrate; + debug("samplingrate = %d\n", i2s->samplingrate); + i2s->bitspersample = fdtdec_get_int(blob, + node, "samsung,i2s-bits-per-sample", -1); + error |= i2s->bitspersample; + debug("bitspersample = %d\n", i2s->bitspersample); + i2s->channels = fdtdec_get_int(blob, + node, "samsung,i2s-channels", -1); + error |= i2s->channels; + debug("channels = %d\n", i2s->channels); + i2s->rfs = fdtdec_get_int(blob, + node, "samsung,i2s-lr-clk-framesize", -1); + error |= i2s->rfs; + debug("rfs = %d\n", i2s->rfs); + i2s->bfs = fdtdec_get_int(blob, + node, "samsung,i2s-bit-clk-framesize", -1); + error |= i2s->bfs; + debug("bfs = %d\n", i2s->bfs); if (error == -1) { - debug("fail to get wm8994 codec node properties\n"); + debug("fail to get sound i2s node properties\n"); return -1; } - +#else + i2s->base_address = samsung_get_base_i2s(); + i2s->audio_pll_clk = I2S_PLL_CLK; + i2s->samplingrate = I2S_SAMPLING_RATE; + i2s->bitspersample = I2S_BITS_PER_SAMPLE; + i2s->channels = I2S_CHANNELS; + i2s->rfs = I2S_RFS; + i2s->bfs = I2S_BFS; +#endif return 0; }
/* - * Gets fdt values for codec config parameters + * Init codec * - * @param pcodec_info codec information structure - * @param blob FDT blob - * @return int value, 0 for success + * @param blob FDT blob + * @param pi2s_tx i2s parameters required by codec + * @return int value, 0 for success */ -static int get_sound_codec_values(struct sound_codec_info *pcodec_info) +static int codec_init(const void *blob, struct i2stx_info *pi2s_tx) { - int error = 0; + int ret; const char *codectype; +#ifdef CONFIG_OF_CONTROL + int node;
- codectype = AUDIO_CODEC; + /* Get the node from FDT for sound */ + node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SOUND); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for sound in device tree\n"); + debug("node = %d\n", node); + return -1; + }
+ /* + * Get the pre-defined sound codec specific values from FDT. + * All of these are expected to be correct otherwise sound + * can not be played + */ + codectype = fdt_getprop(blob, node, "samsung,codec-type", NULL); + debug("device = %s\n", codectype); +#else + codectype = AUDIO_CODEC; +#endif if (!strcmp(codectype, "wm8994")) { - pcodec_info->codec_type = CODEC_WM_8994; - error = get_sound_wm8994_values(pcodec_info); + /* Check the codec type and initialise the same */ + ret = wm8994_init(blob, WM8994_AIF2, + pi2s_tx->samplingrate, + (pi2s_tx->samplingrate * (pi2s_tx->rfs)), + pi2s_tx->bitspersample, pi2s_tx->channels); } else { - error = -1; + debug("%s: Unknown code type %s\n", __func__, + codectype); + return -1; } - - if (error == -1) { - debug("fail to get sound codec node properties\n"); + if (ret) { + debug("%s: Codec init failed\n", __func__); return -1; }
return 0; }
-int sound_init(void) +int sound_init(const void *blob) { int ret; struct i2stx_info *pi2s_tx = &g_i2stx_pri; - struct sound_codec_info *pcodec_info = &g_codec_info;
+#ifdef CONFIG_OF_CONTROL /* Get the I2S Values */ - get_sound_i2s_values(pi2s_tx); - - /* Get the codec Values */ - if (get_sound_codec_values(pcodec_info) < 0) + if (get_sound_i2s_values(pi2s_tx, blob) < 0) { + debug(" FDT I2S values failed\n"); return -1; - + } + codec_init(blob, pi2s_tx); +#else + /* Get the I2S Values */ + get_sound_i2s_values(pi2s_tx, NULL); + codec_init(NULL, pi2s_tx); +#endif ret = i2s_tx_init(pi2s_tx); if (ret) { debug("%s: Failed to init i2c transmit: ret=%d\n", __func__, @@ -137,21 +189,6 @@ int sound_init(void) return ret; }
- /* Check the codec type and initialise the same */ - if (pcodec_info->codec_type == CODEC_WM_8994) { - ret = wm8994_init(pcodec_info, WM8994_AIF2, - pi2s_tx->samplingrate, - (pi2s_tx->samplingrate * (pi2s_tx->rfs)), - pi2s_tx->bitspersample, pi2s_tx->channels); - } else { - debug("%s: Unknown code type %d\n", __func__, - pcodec_info->codec_type); - return -1; - } - if (ret) { - debug("%s: Codec init failed\n", __func__); - return -1; - }
return ret; } diff --git a/include/sound.h b/include/sound.h index ea0b115..a9cbeed 100644 --- a/include/sound.h +++ b/include/sound.h @@ -46,10 +46,10 @@ struct sound_codec_info {
/* * Initialises audio sub system - * + * @param blob Pointer of device tree node. * @return int value 0 for success, -1 for error */ -int sound_init(void); +int sound_init(const void *blob);
/* * plays the pcm data buffer in pcm_data.h through i2s1 to make the

Hi Rajeshwari,
On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
This patch adds FDT support to the sound driver.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Changes in V2: - Made single function to get i2s values,codec init and sount init in both FDT and non FDT support case. drivers/sound/sound.c | 179 +++++++++++++++++++++++++++++------------------- include/sound.h | 4 +- 2 files changed, 110 insertions(+), 73 deletions(-)
diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4c74534..bc87a9b 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -28,108 +28,160 @@ #include <i2s.h> #include <sound.h> #include "wm8994.h" +#ifdef CONFIG_OF_CONTROL +#include <libfdt.h> +#include <fdtdec.h> +#else #include <asm/arch/sound.h> +#endif
Can we just include all 3 files?
/* defines */ #define SOUND_400_HZ 400 #define SOUND_BITS_IN_BYTE 8
static struct i2stx_info g_i2stx_pri; -static struct sound_codec_info g_codec_info;
/*
- get_sound_fdt_values gets fdt values for i2s parameters
- get_sound_i2s_values gets values for i2s parameters
- @param i2stx_info i2s transmitter transfer param structure
- @param blob FDT blob
*/
- @param blob FDT blob if enabled else NULL
-static void get_sound_i2s_values(struct i2stx_info *i2s) -{
i2s->base_address = samsung_get_base_i2s();
i2s->audio_pll_clk = I2S_PLL_CLK;
i2s->samplingrate = I2S_SAMPLING_RATE;
i2s->bitspersample = I2S_BITS_PER_SAMPLE;
i2s->channels = I2S_CHANNELS;
i2s->rfs = I2S_RFS;
i2s->bfs = I2S_BFS;
-}
-/*
- Gets fdt values for wm8994 config parameters
- @param pcodec_info codec information structure
- @param blob FDT blob
- @return int value, 0 for success
- */
-static int get_sound_wm8994_values(struct sound_codec_info *pcodec_info) +static int get_sound_i2s_values(struct i2stx_info *i2s, const void *blob) { +#ifdef CONFIG_OF_CONTROL
int node; int error = 0;
int base;
switch (AUDIO_COMPAT) {
case AUDIO_COMPAT_SPI:
debug("%s: Support not added for SPI interface\n", __func__);
node = fdtdec_next_compatible(blob, 0,
COMPAT_SAMSUNG_EXYNOS5_SOUND);
if (node <= 0) {
debug("EXYNOS_SOUND: No node for sound in device tree\n"); return -1;
break;
case AUDIO_COMPAT_I2C:
pcodec_info->i2c_bus = AUDIO_I2C_BUS;
pcodec_info->i2c_dev_addr = AUDIO_I2C_REG;
debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr);
break;
default:
debug("%s: Unknown compat id %d\n", __func__, AUDIO_COMPAT);
}
/*
* Get the pre-defined sound specific values from FDT.
* All of these are expected to be correct otherwise
* wrong register values in i2s setup parameters
* may result in no sound play.
*/
base = fdtdec_get_addr(blob, node, "reg");
if (base == FDT_ADDR_T_NONE) {
debug("%s: Missing i2s base\n", __func__); return -1; }
i2s->base_address = base;
i2s->audio_pll_clk = fdtdec_get_int(blob,
node, "samsung,i2s-epll-clock-frequency", -1);
error |= i2s->audio_pll_clk;
debug("audio_pll_clk = %d\n", i2s->audio_pll_clk);
i2s->samplingrate = fdtdec_get_int(blob,
node, "samsung,i2s-sampling-rate", -1);
error |= i2s->samplingrate;
debug("samplingrate = %d\n", i2s->samplingrate);
i2s->bitspersample = fdtdec_get_int(blob,
node, "samsung,i2s-bits-per-sample", -1);
error |= i2s->bitspersample;
debug("bitspersample = %d\n", i2s->bitspersample);
i2s->channels = fdtdec_get_int(blob,
node, "samsung,i2s-channels", -1);
error |= i2s->channels;
debug("channels = %d\n", i2s->channels);
i2s->rfs = fdtdec_get_int(blob,
node, "samsung,i2s-lr-clk-framesize", -1);
error |= i2s->rfs;
debug("rfs = %d\n", i2s->rfs);
i2s->bfs = fdtdec_get_int(blob,
node, "samsung,i2s-bit-clk-framesize", -1);
error |= i2s->bfs;
debug("bfs = %d\n", i2s->bfs); if (error == -1) {
debug("fail to get wm8994 codec node properties\n");
debug("fail to get sound i2s node properties\n"); return -1; }
+#else
i2s->base_address = samsung_get_base_i2s();
i2s->audio_pll_clk = I2S_PLL_CLK;
i2s->samplingrate = I2S_SAMPLING_RATE;
i2s->bitspersample = I2S_BITS_PER_SAMPLE;
i2s->channels = I2S_CHANNELS;
i2s->rfs = I2S_RFS;
i2s->bfs = I2S_BFS;
+#endif return 0; }
/*
- Gets fdt values for codec config parameters
- Init codec
- @param pcodec_info codec information structure
- @param blob FDT blob
- @return int value, 0 for success
- @param blob FDT blob
- @param pi2s_tx i2s parameters required by codec
*/
- @return int value, 0 for success
-static int get_sound_codec_values(struct sound_codec_info *pcodec_info) +static int codec_init(const void *blob, struct i2stx_info *pi2s_tx) {
int error = 0;
int ret; const char *codectype;
+#ifdef CONFIG_OF_CONTROL
int node;
codectype = AUDIO_CODEC;
/* Get the node from FDT for sound */
node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SOUND);
if (node <= 0) {
debug("EXYNOS_SOUND: No node for sound in device tree\n");
debug("node = %d\n", node);
return -1;
}
/*
* Get the pre-defined sound codec specific values from FDT.
* All of these are expected to be correct otherwise sound
* can not be played
*/
codectype = fdt_getprop(blob, node, "samsung,codec-type", NULL);
debug("device = %s\n", codectype);
+#else
codectype = AUDIO_CODEC;
+#endif if (!strcmp(codectype, "wm8994")) {
pcodec_info->codec_type = CODEC_WM_8994;
error = get_sound_wm8994_values(pcodec_info);
/* Check the codec type and initialise the same */
ret = wm8994_init(blob, WM8994_AIF2,
pi2s_tx->samplingrate,
(pi2s_tx->samplingrate * (pi2s_tx->rfs)),
pi2s_tx->bitspersample, pi2s_tx->channels); } else {
error = -1;
debug("%s: Unknown code type %s\n", __func__,
codectype);
return -1; }
if (error == -1) {
debug("fail to get sound codec node properties\n");
if (ret) {
debug("%s: Codec init failed\n", __func__); return -1; } return 0;
}
-int sound_init(void) +int sound_init(const void *blob) { int ret; struct i2stx_info *pi2s_tx = &g_i2stx_pri;
struct sound_codec_info *pcodec_info = &g_codec_info;
+#ifdef CONFIG_OF_CONTROL /* Get the I2S Values */
get_sound_i2s_values(pi2s_tx);
/* Get the codec Values */
if (get_sound_codec_values(pcodec_info) < 0)
if (get_sound_i2s_values(pi2s_tx, blob) < 0) {
debug(" FDT I2S values failed\n"); return -1;
}
codec_init(blob, pi2s_tx);
I think you should check for failure - debug() and return -1.
+#else
/* Get the I2S Values */
get_sound_i2s_values(pi2s_tx, NULL);
I think you can pass blob to the function safely always (since it is NULL if !defined CONFIG_OF_CONTROL). and just make this code comment with the code above. I hope that means that this #else can disappear.
codec_init(NULL, pi2s_tx);
+#endif ret = i2s_tx_init(pi2s_tx); if (ret) { debug("%s: Failed to init i2c transmit: ret=%d\n", __func__, @@ -137,21 +189,6 @@ int sound_init(void) return ret; }
/* Check the codec type and initialise the same */
if (pcodec_info->codec_type == CODEC_WM_8994) {
ret = wm8994_init(pcodec_info, WM8994_AIF2,
pi2s_tx->samplingrate,
(pi2s_tx->samplingrate * (pi2s_tx->rfs)),
pi2s_tx->bitspersample, pi2s_tx->channels);
} else {
debug("%s: Unknown code type %d\n", __func__,
pcodec_info->codec_type);
return -1;
}
if (ret) {
debug("%s: Codec init failed\n", __func__);
return -1;
} return ret;
} diff --git a/include/sound.h b/include/sound.h index ea0b115..a9cbeed 100644 --- a/include/sound.h +++ b/include/sound.h @@ -46,10 +46,10 @@ struct sound_codec_info {
/*
- 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(void); +int sound_init(const void *blob);
/*
- plays the pcm data buffer in pcm_data.h through i2s1 to make the
-- 1.7.4.4
Regards, Simon

This patch adds FDT support to the codec.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - New patch. drivers/sound/wm8994.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/sound/wm8994.h | 6 +-- 2 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/drivers/sound/wm8994.c b/drivers/sound/wm8994.c index 293903a..4352b21 100644 --- a/drivers/sound/wm8994.c +++ b/drivers/sound/wm8994.c @@ -31,6 +31,11 @@ #include <sound.h> #include "wm8994.h" #include "wm8994_registers.h" +#ifdef CONFIG_OF_CONTROL +#include <fdtdec.h> +#else +#include <asm/arch/sound.h> +#endif
/* defines for wm8994 system clock selection */ #define SEL_MCLK1 0x00 @@ -77,6 +82,7 @@ static int bclk_divs[] = {
static struct wm8994_priv g_wm8994_info; static unsigned char g_wm8994_i2c_dev_addr; +static struct sound_codec_info g_codec_info;
/* * Initialise I2C for wm 8994 @@ -747,13 +753,86 @@ err: return -1; }
+/* + * Gets fdt values for wm8994 config parameters + * + * @param pcodec_info codec information structure + * @param blob FDT blob + * @return int value, 0 for success + */ +static int get_codec_values(struct sound_codec_info *pcodec_info, + const void *blob) +{ + int error = 0; +#ifdef CONFIG_OF_CONTROL + enum fdt_compat_id compat; + int node; + int parent; + + /* Get the node from FDT for codec */ + node = fdtdec_next_compatible(blob, 0, COMPAT_WOLFSON_WM8994_CODEC); + if (node <= 0) { + debug("EXYNOS_SOUND: No node for codec in device tree\n"); + debug("node = %d\n", node); + return -1; + } + + parent = fdt_parent_offset(blob, node); + if (parent < 0) { + debug("%s: Cannot find node parent\n", __func__); + return -1; + } + + compat = fd_dec_lookup(blob, parent); + switch (compat) { + case COMPAT_SAMSUNG_S3C2440_I2C: + pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent); + error |= pcodec_info->i2c_bus; + debug("i2c bus = %d\n", pcodec_info->i2c_bus); + pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, + "reg", 0); + error |= pcodec_info->i2c_dev_addr; + debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); + break; + default: + debug("%s: Unknown compat id %d\n", __func__, compat); + return -1; + } +#else + pcodec_info->i2c_bus = AUDIO_I2C_BUS; + pcodec_info->i2c_dev_addr = AUDIO_I2C_REG; + debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); +#endif + + pcodec_info->codec_type = CODEC_WM_8994; + + if (error == -1) { + debug("fail to get wm8994 codec node properties\n"); + return -1; + } + + return 0; + +} + + /*wm8994 Device Initialisation */ -int wm8994_init(struct sound_codec_info *pcodec_info, - enum en_audio_interface aif_id, +int wm8994_init(const void *blob, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, unsigned int channels) { int ret = 0; + struct sound_codec_info *pcodec_info = &g_codec_info; + + /* Get the codec Values */ +#ifdef CONFIG_OF_CONTROL + if (get_codec_values(pcodec_info, blob) < 0) { +#else + if (get_codec_values(pcodec_info, NULL) < 0) { +#endif + debug("FDT Codec values failed\n"); + return -1; + }
/* shift the device address by 1 for 7 bit addressing */ g_wm8994_i2c_dev_addr = pcodec_info->i2c_dev_addr; diff --git a/drivers/sound/wm8994.h b/drivers/sound/wm8994.h index a8f0de1..a1e8335 100644 --- a/drivers/sound/wm8994.h +++ b/drivers/sound/wm8994.h @@ -69,8 +69,7 @@ enum wm8994_type { /* * intialise wm8994 sound codec device for the given configuration * - * @param pcodec_info pointer value of the sound codec info structure - * parsed from device tree + * @param blob FDT node for codec values * @param aif_id enum value of codec interface port in which * soc i2s is connected * @param sampling_rate Sampling rate ranges between from 8khz to 96khz @@ -80,8 +79,7 @@ enum wm8994_type { * * @returns -1 for error and 0 Success. */ -int wm8994_init(struct sound_codec_info *pcodec_info, - enum en_audio_interface aif_id, +int wm8994_init(const void *blob, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, unsigned int channels); #endif /*__WM8994_H__ */

Hi Rajeshwari,
On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
This patch adds FDT support to the codec.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Changes in V2: - New patch. drivers/sound/wm8994.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/sound/wm8994.h | 6 +-- 2 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/drivers/sound/wm8994.c b/drivers/sound/wm8994.c index 293903a..4352b21 100644 --- a/drivers/sound/wm8994.c +++ b/drivers/sound/wm8994.c @@ -31,6 +31,11 @@ #include <sound.h> #include "wm8994.h" #include "wm8994_registers.h" +#ifdef CONFIG_OF_CONTROL +#include <fdtdec.h> +#else +#include <asm/arch/sound.h> +#endif
Can you remove these #ifdefs?
/* defines for wm8994 system clock selection */ #define SEL_MCLK1 0x00 @@ -77,6 +82,7 @@ static int bclk_divs[] = {
static struct wm8994_priv g_wm8994_info; static unsigned char g_wm8994_i2c_dev_addr; +static struct sound_codec_info g_codec_info;
/*
- Initialise I2C for wm 8994
@@ -747,13 +753,86 @@ err: return -1; }
+/*
- Gets fdt values for wm8994 config parameters
- @param pcodec_info codec information structure
- @param blob FDT blob
- @return int value, 0 for success
- */
+static int get_codec_values(struct sound_codec_info *pcodec_info,
const void *blob)
+{
int error = 0;
+#ifdef CONFIG_OF_CONTROL
enum fdt_compat_id compat;
int node;
int parent;
/* Get the node from FDT for codec */
node = fdtdec_next_compatible(blob, 0, COMPAT_WOLFSON_WM8994_CODEC);
if (node <= 0) {
debug("EXYNOS_SOUND: No node for codec in device tree\n");
debug("node = %d\n", node);
return -1;
}
parent = fdt_parent_offset(blob, node);
if (parent < 0) {
debug("%s: Cannot find node parent\n", __func__);
return -1;
}
compat = fd_dec_lookup(blob, parent);
switch (compat) {
case COMPAT_SAMSUNG_S3C2440_I2C:
pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent);
error |= pcodec_info->i2c_bus;
debug("i2c bus = %d\n", pcodec_info->i2c_bus);
pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node,
"reg", 0);
error |= pcodec_info->i2c_dev_addr;
debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr);
break;
default:
debug("%s: Unknown compat id %d\n", __func__, compat);
return -1;
}
+#else
pcodec_info->i2c_bus = AUDIO_I2C_BUS;
pcodec_info->i2c_dev_addr = AUDIO_I2C_REG;
debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr);
+#endif
pcodec_info->codec_type = CODEC_WM_8994;
if (error == -1) {
debug("fail to get wm8994 codec node properties\n");
return -1;
}
return 0;
+}
/*wm8994 Device Initialisation */ -int wm8994_init(struct sound_codec_info *pcodec_info,
enum en_audio_interface aif_id,
+int wm8994_init(const void *blob, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, unsigned int channels) { int ret = 0;
struct sound_codec_info *pcodec_info = &g_codec_info;
/* Get the codec Values */
+#ifdef CONFIG_OF_CONTROL
if (get_codec_values(pcodec_info, blob) < 0) {
+#else
if (get_codec_values(pcodec_info, NULL) < 0) {
+#endif
Since blob should be NULL if !defined CONFIG_OF_CONTROL. you should be able to remove the #ifdef.
debug("FDT Codec values failed\n");
return -1;
Remove one indent here.
} /* shift the device address by 1 for 7 bit addressing */ g_wm8994_i2c_dev_addr = pcodec_info->i2c_dev_addr;
diff --git a/drivers/sound/wm8994.h b/drivers/sound/wm8994.h index a8f0de1..a1e8335 100644 --- a/drivers/sound/wm8994.h +++ b/drivers/sound/wm8994.h @@ -69,8 +69,7 @@ enum wm8994_type { /*
- intialise wm8994 sound codec device for the given configuration
- @param pcodec_info pointer value of the sound codec info structure
parsed from device tree
- @param blob FDT node for codec values
- @param aif_id enum value of codec interface port in which
soc i2s is connected
- @param sampling_rate Sampling rate ranges between from 8khz to 96khz
@@ -80,8 +79,7 @@ enum wm8994_type {
- @returns -1 for error and 0 Success.
*/ -int wm8994_init(struct sound_codec_info *pcodec_info,
enum en_audio_interface aif_id,
+int wm8994_init(const void *blob, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, unsigned int channels);
#endif /*__WM8994_H__ */
1.7.4.4
Regards, Simon

This patch adds FDT support to sound init in CMD.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com --- Changes in V2: - Same function call for sound init in case of FDT or non FDT support. common/cmd_sound.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/common/cmd_sound.c b/common/cmd_sound.c index 459d1eb..e06b1db 100644 --- a/common/cmd_sound.c +++ b/common/cmd_sound.c @@ -33,7 +33,11 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { int ret;
- ret = sound_init(); +#ifdef CONFIG_OF_CONTROL + ret = sound_init(gd->fdt_blob); +#else + ret = sound_init(NULL); +#endif if (ret) { printf("Initialise Audio driver failed\n"); return CMD_RET_FAILURE;

Hi Rajeshwari,
On Tue, Nov 27, 2012 at 10:10 PM, Rajeshwari Shinde rajeshwari.s@samsung.com wrote:
This patch adds FDT support to sound init in CMD.
Signed-off-by: Rajeshwari Shinde rajeshwari.s@samsung.com
Changes in V2: - Same function call for sound init in case of FDT or non FDT support. common/cmd_sound.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/common/cmd_sound.c b/common/cmd_sound.c index 459d1eb..e06b1db 100644 --- a/common/cmd_sound.c +++ b/common/cmd_sound.c @@ -33,7 +33,11 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { int ret;
ret = sound_init();
+#ifdef CONFIG_OF_CONTROL
ret = sound_init(gd->fdt_blob);
+#else
ret = sound_init(NULL);
+#endif
Can you remove this #ifdef and just always pass gd->fdt_blob?
if (ret) { printf("Initialise Audio driver failed\n"); return CMD_RET_FAILURE;
-- 1.7.4.4
Regards, Simon
participants (2)
-
Rajeshwari Shinde
-
Simon Glass