2014-02-26 05:07:56

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 00/10] Simplify the code of TDM slot setting


Xiubo Li (10):
ASoC: core: Add snd_soc_dai_set_tdm_slot_xlate().
ASoC: fsl-utils: Add fsl_asoc_of_xlate_tdm_slot_mask() support.
ASoC: fsl-esai: Add .of_xlate_tdm_slot_mask() support.
ASoC: fsl-ssi: Add .of_xlate_tdm_slot_mask() support.
ASoC: imx-ssi: Add .of_xlate_tdm_slot_mask() support.
ASoC: simple-card: Use snd_soc_dai_set_tdm_slot_xlate()
ASoC: blackfin: bf5xx-ad1836: Use snd_soc_dai_set_tdm_slot_xlate()
ASoC: blackfin: bf5xx-ad193x: Use snd_soc_dai_set_tdm_slot_xlate()
ASoC: fsl: eukrea-tlv320: Use snd_soc_dai_set_tdm_slot_xlate()
ASoC: fsl: wm1133-ev1: Use snd_soc_dai_set_tdm_slot_xlate()

include/sound/soc-dai.h | 3 +++
sound/soc/blackfin/bf5xx-ad1836.c | 2 +-
sound/soc/blackfin/bf5xx-ad193x.c | 4 ++--
sound/soc/fsl/Kconfig | 3 +++
sound/soc/fsl/eukrea-tlv320.c | 2 +-
sound/soc/fsl/fsl_esai.c | 2 ++
sound/soc/fsl/fsl_ssi.c | 2 ++
sound/soc/fsl/fsl_utils.c | 27 +++++++++++++++++++++++++++
sound/soc/fsl/fsl_utils.h | 4 +++-
sound/soc/fsl/imx-ssi.c | 2 ++
sound/soc/fsl/wm1133-ev1.c | 11 +----------
sound/soc/generic/simple-card.c | 7 +++----
sound/soc/soc-core.c | 33 ++++++++++++++++++++++++++++-----
13 files changed, 78 insertions(+), 24 deletions(-)

--
1.8.4


2014-02-26 05:08:32

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 01/10] ASoC: core: Add snd_soc_dai_set_tdm_slot_xlate().

For most cases the rx_mask and tx_mask params have no use for
snd_soc_dai_set_tdm_slot(), because they could be generated by
{XXX_ .}of_xlate_tdm_slot_mask().

This patch add snd_soc_dai_set_tdm_slot_xlate() which will replace
the snd_soc_dai_set_tdm_slot() in some use cases to simplify the
code. And for some CODECs or CPU DAI devices there needed much more
work to support the .of_xlate_tdm_slot_mask feature.

This patch can be applied to most use case of the current DAI drivers.

Signed-off-by: Xiubo Li <[email protected]>
---
include/sound/soc-dai.h | 3 +++
sound/soc/soc-core.c | 33 ++++++++++++++++++++++++++++-----
2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index d86e0fc..68569ee 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -110,6 +110,9 @@ int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
/* Digital Audio interface formatting */
int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);

+int snd_soc_dai_set_tdm_slot_xlate(struct snd_soc_dai *dai,
+ unsigned int slots,
+ unsigned int slot_width);
int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 0911856..e5a535b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3687,19 +3687,20 @@ static int snd_soc_of_xlate_tdm_slot_mask(unsigned int slots,
}

/**
- * snd_soc_dai_set_tdm_slot - configure DAI TDM.
+ * snd_soc_dai_set_tdm_slot_xlate - configure DAI TDM with of xlate.
* @dai: DAI
- * @tx_mask: bitmask representing active TX slots.
- * @rx_mask: bitmask representing active RX slots.
* @slots: Number of slots in use.
* @slot_width: Width in bits for each slot.
*
* Configures a DAI for TDM operation. Both mask and slots are codec and DAI
* specific.
*/
-int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
- unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
+int snd_soc_dai_set_tdm_slot_xlate(struct snd_soc_dai *dai,
+ unsigned int slots,
+ unsigned int slot_width)
{
+ unsigned int tx_mask, rx_mask;
+
if (dai->driver && dai->driver->ops->of_xlate_tdm_slot_mask)
dai->driver->ops->of_xlate_tdm_slot_mask(slots,
&tx_mask, &rx_mask);
@@ -3712,6 +3713,28 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
else
return -ENOTSUPP;
}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot_xlate);
+
+/**
+ * snd_soc_dai_set_tdm_slot - configure DAI TDM.
+ * @dai: DAI
+ * @tx_mask: bitmask representing active TX slots.
+ * @rx_mask: bitmask representing active RX slots.
+ * @slots: Number of slots in use.
+ * @slot_width: Width in bits for each slot.
+ *
+ * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
+ * specific.
+ */
+int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
+ unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
+{
+ if (dai->driver && dai->driver->ops->set_tdm_slot)
+ return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
+ slots, slot_width);
+ else
+ return -ENOTSUPP;
+}
EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);

/**
--
1.8.4

2014-02-26 05:09:14

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 03/10] ASoC: fsl-esai: Add .of_xlate_tdm_slot_mask() support.

This patch add .of_xlate_tdm_slot_mask support for ESAI, and this will
generate the TDM slot TX and RX masks.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/Kconfig | 1 +
sound/soc/fsl/fsl_esai.c | 2 ++
2 files changed, 3 insertions(+)

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index f397144..6abb68e 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -13,6 +13,7 @@ config SND_SOC_FSL_SPDIF
config SND_SOC_FSL_ESAI
tristate "ALSA SoC support for the Freescale ESAI device"
select REGMAP_MMIO
+ select SND_SOC_FSL_UTILS

config SND_SOC_FSL_UTILS
tristate
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index 0ba3700..912104f 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -18,6 +18,7 @@

#include "fsl_esai.h"
#include "imx-pcm.h"
+#include "fsl_utils.h"

#define FSL_ESAI_RATES SNDRV_PCM_RATE_8000_192000
#define FSL_ESAI_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
@@ -581,6 +582,7 @@ static struct snd_soc_dai_ops fsl_esai_dai_ops = {
.hw_params = fsl_esai_hw_params,
.set_sysclk = fsl_esai_set_dai_sysclk,
.set_fmt = fsl_esai_set_dai_fmt,
+ .of_xlate_tdm_slot_mask = fsl_asoc_of_xlate_tdm_slot_mask,
.set_tdm_slot = fsl_esai_set_dai_tdm_slot,
};

--
1.8.4

2014-02-26 05:09:31

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 02/10] ASoC: fsl-utils: Add fsl_asoc_of_xlate_tdm_slot_mask() support.

This patch add fsl_asoc_of_xlate_tdm_slot_mask() support for utils.
For the some spcified DAI driver, this will be used to generate the
TDM slot TX/RX mask. And the TX/RX mask will use a 0 bit for an active
slot as default, and the default active bits are at the LSB of
the masks.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/fsl_utils.c | 27 +++++++++++++++++++++++++++
sound/soc/fsl/fsl_utils.h | 4 +++-
2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c
index b9e42b5..b536eb1 100644
--- a/sound/soc/fsl/fsl_utils.c
+++ b/sound/soc/fsl/fsl_utils.c
@@ -86,6 +86,33 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
}
EXPORT_SYMBOL(fsl_asoc_get_dma_channel);

+/**
+ * fsl_asoc_of_xlate_tdm_slot_mask - generate TDM slot TX/RX mask.
+ *
+ * @slots: Number of slots in use.
+ * @tx_mask: bitmask representing active TX slots.
+ * @rx_mask: bitmask representing active RX slots.
+ *
+ * This function used to generate the TDM slot TX/RX mask. And the TX/RX
+ * mask will use a 0 bit for an active slot as default, and the default
+ * active bits are at the LSB of the mask value.
+ */
+int fsl_asoc_of_xlate_tdm_slot_mask(unsigned int slots,
+ unsigned int *tx_mask,
+ unsigned int *rx_mask)
+{
+ if (!slots)
+ return -EINVAL;
+
+ if (tx_mask)
+ *tx_mask = ~((1 << slots) - 1);
+ if (rx_mask)
+ *rx_mask = ~((1 << slots) - 1);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(fsl_asoc_of_xlate_tdm_slot_mask);
+
MODULE_AUTHOR("Timur Tabi <[email protected]>");
MODULE_DESCRIPTION("Freescale ASoC utility code");
MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/fsl/fsl_utils.h b/sound/soc/fsl/fsl_utils.h
index b295112..01b01f9 100644
--- a/sound/soc/fsl/fsl_utils.h
+++ b/sound/soc/fsl/fsl_utils.h
@@ -22,5 +22,7 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np, const char *name,
struct snd_soc_dai_link *dai,
unsigned int *dma_channel_id,
unsigned int *dma_id);
-
+int fsl_asoc_of_xlate_tdm_slot_mask(unsigned int slots,
+ unsigned int *tx_mask,
+ unsigned int *rx_mask);
#endif /* _FSL_UTILS_H */
--
1.8.4

2014-02-26 05:09:59

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 06/10] ASoC: simple-card: Use snd_soc_dai_set_tdm_slot_xlate()

Use snd_soc_dai_set_tdm_slot_xlate instead of snd_soc_dai_set_tdm_slot.

This will use the DAI driver specified .of_xlate_tdm_slot_mask to generate
the TDM slot TX/RX mask, or the default snd_soc_of_xlate_tdm_slot_mask will
be used instead if it's absent.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/generic/simple-card.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index bdd176d..22efa83 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -48,11 +48,10 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
}

if (set->slots) {
- ret = snd_soc_dai_set_tdm_slot(dai, 0, 0,
- set->slots,
- set->slot_width);
+ ret = snd_soc_dai_set_tdm_slot_xlate(dai, set->slots,
+ set->slot_width);
if (ret && ret != -ENOTSUPP) {
- dev_err(dai->dev, "simple-card: set_tdm_slot error\n");
+ dev_err(dai->dev, "simple-card: set_tdm_slot_xlate error\n");
goto err;
}
}
--
1.8.4

2014-02-26 05:10:11

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 04/10] ASoC: fsl-ssi: Add .of_xlate_tdm_slot_mask() support.

This patch add .of_xlate_tdm_slot_mask support for SSI, and this will
generate the TDM slot TX and RX masks.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/Kconfig | 1 +
sound/soc/fsl/fsl_ssi.c | 2 ++
2 files changed, 3 insertions(+)

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 6abb68e..7472308 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -5,6 +5,7 @@ config SND_SOC_FSL_SAI

config SND_SOC_FSL_SSI
tristate
+ select SND_SOC_FSL_UTILS

config SND_SOC_FSL_SPDIF
tristate "ALSA SoC support for the Freescale SPDIF device"
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 5428a1f..80ca76c 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -53,6 +53,7 @@

#include "fsl_ssi.h"
#include "imx-pcm.h"
+#include "fsl_utils.h"

#ifdef PPC
#define read_ssi(addr) in_be32(addr)
@@ -1136,6 +1137,7 @@ static const struct snd_soc_dai_ops fsl_ssi_dai_ops = {
.hw_params = fsl_ssi_hw_params,
.set_fmt = fsl_ssi_set_dai_fmt,
.set_sysclk = fsl_ssi_set_dai_sysclk,
+ .of_xlate_tdm_slot_mask = fsl_asoc_of_xlate_tdm_slot_mask,
.set_tdm_slot = fsl_ssi_set_dai_tdm_slot,
.trigger = fsl_ssi_trigger,
};
--
1.8.4

2014-02-26 05:10:32

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 05/10] ASoC: imx-ssi: Add .of_xlate_tdm_slot_mask() support.

This patch add .of_xlate_tdm_slot_mask support for IMX SSI, and this
will generate the TDM slot TX and RX masks.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/Kconfig | 1 +
sound/soc/fsl/imx-ssi.c | 2 ++
2 files changed, 3 insertions(+)

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 7472308..67833dd 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -122,6 +122,7 @@ if SND_IMX_SOC

config SND_SOC_IMX_SSI
tristate
+ select SND_SOC_FSL_UTILS

config SND_SOC_IMX_PCM_FIQ
tristate
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index df552fa..52d4b7a 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -50,6 +50,7 @@
#include <linux/platform_data/asoc-imx-ssi.h>

#include "imx-ssi.h"
+#include "fsl_utils.h"

#define SSI_SACNT_DEFAULT (SSI_SACNT_AC97EN | SSI_SACNT_FV)

@@ -339,6 +340,7 @@ static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = {
.set_fmt = imx_ssi_set_dai_fmt,
.set_clkdiv = imx_ssi_set_dai_clkdiv,
.set_sysclk = imx_ssi_set_dai_sysclk,
+ .of_xlate_tdm_slot_mask = fsl_asoc_of_xlate_tdm_slot_mask,
.set_tdm_slot = imx_ssi_set_dai_tdm_slot,
.trigger = imx_ssi_trigger,
};
--
1.8.4

2014-02-26 05:10:29

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 08/10] ASoC: blackfin: bf5xx-ad193x: Use snd_soc_dai_set_tdm_slot_xlate()

Use snd_soc_dai_set_tdm_slot_xlate instead of snd_soc_dai_set_tdm_slot.
This will use the default snd_soc_of_xlate_tdm_slot_mask to generate
the TDM slot TX/RX mask using the slot parameter.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/blackfin/bf5xx-ad193x.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/blackfin/bf5xx-ad193x.c b/sound/soc/blackfin/bf5xx-ad193x.c
index 603ad1f..f622faa 100644
--- a/sound/soc/blackfin/bf5xx-ad193x.c
+++ b/sound/soc/blackfin/bf5xx-ad193x.c
@@ -53,11 +53,11 @@ static int bf5xx_ad193x_link_init(struct snd_soc_pcm_runtime *rtd)
return ret;

/* set codec DAI slots, 8 channels, all channels are enabled */
- ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xFF, 0xFF, 8, 32);
+ ret = snd_soc_dai_set_tdm_slot_xlate(codec_dai, 8, 32);
if (ret < 0)
return ret;

- ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xFF, 0xFF, 8, 32);
+ ret = snd_soc_dai_set_tdm_slot_xlate(cpu_dai, 8, 32);
if (ret < 0)
return ret;

--
1.8.4

2014-02-26 05:11:00

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 10/10] ASoC: fsl: wm1133-ev1: Use snd_soc_dai_set_tdm_slot_xlate()

Use snd_soc_dai_set_tdm_slot_xlate instead of snd_soc_dai_set_tdm_slot.
This will use the default snd_soc_of_xlate_tdm_slot_mask to generate
the TDM slot TX/RX mask using the slot parameter.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/wm1133-ev1.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/sound/soc/fsl/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c
index fce6325..4519b08 100644
--- a/sound/soc/fsl/wm1133-ev1.c
+++ b/sound/soc/fsl/wm1133-ev1.c
@@ -114,16 +114,7 @@ static int wm1133_ev1_hw_params(struct snd_pcm_substream *substream,
snd_soc_dai_set_fmt(cpu_dai, dai_format);

/* TODO: The SSI driver should figure this out for us */
- switch (channels) {
- case 2:
- snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
- break;
- case 1:
- snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffe, 0xffffffe, 1, 0);
- break;
- default:
- return -EINVAL;
- }
+ snd_soc_dai_set_tdm_slot_xlate(cpu_dai, channels, 0);

/* set MCLK as the codec system clock for DAC and ADC */
snd_soc_dai_set_sysclk(codec_dai, WM8350_MCLK_SEL_PLL_MCLK,
--
1.8.4

2014-02-26 05:11:27

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 09/10] ASoC: fsl: eukrea-tlv320: Use snd_soc_dai_set_tdm_slot_xlate()

Use snd_soc_dai_set_tdm_slot_xlate instead of snd_soc_dai_set_tdm_slot.
This will use the default snd_soc_of_xlate_tdm_slot_mask to generate
the TDM slot TX/RX mask using the slot parameter.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/fsl/eukrea-tlv320.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 5983740..3965023 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -63,7 +63,7 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
"Failed to set the codec sysclk.\n");
return ret;
}
- snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
+ snd_soc_dai_set_tdm_slot_xlate(cpu_dai, 2, 0);

ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
SND_SOC_CLOCK_IN);
--
1.8.4

2014-02-26 05:13:48

by Xiubo Li

[permalink] [raw]
Subject: [PATCH 07/10] ASoC: blackfin: bf5xx-ad1836: Use snd_soc_dai_set_tdm_slot_xlate()

Use snd_soc_dai_set_tdm_slot_xlate instead of snd_soc_dai_set_tdm_slot.
This will use the default snd_soc_of_xlate_tdm_slot_mask to generate
the TDM slot TX/RX mask using the slot parameter.

Signed-off-by: Xiubo Li <[email protected]>
---
sound/soc/blackfin/bf5xx-ad1836.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/blackfin/bf5xx-ad1836.c b/sound/soc/blackfin/bf5xx-ad1836.c
index 8fcfc4e..b1908ce 100644
--- a/sound/soc/blackfin/bf5xx-ad1836.c
+++ b/sound/soc/blackfin/bf5xx-ad1836.c
@@ -44,7 +44,7 @@ static int bf5xx_ad1836_init(struct snd_soc_pcm_runtime *rtd)
if (ret < 0)
return ret;

- ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xFF, 0xFF, 8, 32);
+ ret = snd_soc_dai_set_tdm_slot_xlate(cpu_dai, 8, 32);
if (ret < 0)
return ret;

--
1.8.4