From: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
To: alsa-devel@alsa-project.org
Cc: cezary.rojewski@intel.com, andriy.shevchenko@intel.com,
tiwai@suse.com, jee.heng.sia@intel.com,
pierre-louis.bossart@linux.intel.com,
liam.r.girdwood@linux.intel.com, broonie@kernel.org
Subject: [PATCH 3/4] ASoC: Intel: KMB: Enable TDM audio capture
Date: Thu, 30 Jul 2020 13:53:18 +0800 [thread overview]
Message-ID: <20200730055319.1522-4-michael.wei.hong.sit@intel.com> (raw)
In-Reply-To: <20200730055319.1522-1-michael.wei.hong.sit@intel.com>
Enable I2S TDM audio capture for Intel Keem Bay platform.
The I2S TDM will support 4 channel and 8 channel audio capture only.
4 channel and 8 channel audio capture operates only in slave mode.
Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
Reviewed-by: Sia Jee Heng <jee.heng.sia@intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
sound/soc/intel/keembay/kmb_platform.c | 105 +++++++++++++++++++------
1 file changed, 80 insertions(+), 25 deletions(-)
diff --git a/sound/soc/intel/keembay/kmb_platform.c b/sound/soc/intel/keembay/kmb_platform.c
index eaa4fd391171..8cb097ecf4bc 100644
--- a/sound/soc/intel/keembay/kmb_platform.c
+++ b/sound/soc/intel/keembay/kmb_platform.c
@@ -17,7 +17,7 @@
#define PERIODS_MAX 48
#define PERIOD_BYTES_MIN 4096
#define BUFFER_BYTES_MAX (PERIODS_MAX * PERIOD_BYTES_MIN)
-#define TDM_OPERATION 1
+#define TDM_OPERATION 5
#define I2S_OPERATION 0
#define DATA_WIDTH_CONFIG_BIT 6
#define TDM_CHANNEL_CONFIG_BIT 3
@@ -37,7 +37,7 @@ static const struct snd_pcm_hardware kmb_pcm_hardware = {
SNDRV_PCM_FMTBIT_S24_LE |
SNDRV_PCM_FMTBIT_S32_LE,
.channels_min = 2,
- .channels_max = 2,
+ /* channels_max removed to allow configurable max channels */
.buffer_bytes_max = BUFFER_BYTES_MAX,
.period_bytes_min = PERIOD_BYTES_MIN,
.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN,
@@ -82,19 +82,25 @@ static unsigned int kmb_pcm_rx_fn(struct kmb_i2s_info *kmb_i2s,
{
unsigned int period_pos = rx_ptr % runtime->period_size;
void __iomem *i2s_base = kmb_i2s->i2s_base;
+ int chan = kmb_i2s->config.chan_nr;
void *buf = runtime->dma_area;
- int i;
+ int i, j;
/* KMB i2s uses two separate L/R FIFO */
for (i = 0; i < kmb_i2s->fifo_th; i++) {
- if (kmb_i2s->config.data_width == 16) {
- ((u16(*)[2])buf)[rx_ptr][0] = readl(i2s_base + LRBR_LTHR(0));
- ((u16(*)[2])buf)[rx_ptr][1] = readl(i2s_base + RRBR_RTHR(0));
- } else {
- ((u32(*)[2])buf)[rx_ptr][0] = readl(i2s_base + LRBR_LTHR(0));
- ((u32(*)[2])buf)[rx_ptr][1] = readl(i2s_base + RRBR_RTHR(0));
+ for (j = 0; j < chan / 2; j++) {
+ if (kmb_i2s->config.data_width == 16) {
+ ((u16 *)buf)[rx_ptr * chan + (j * 2)] =
+ readl(i2s_base + LRBR_LTHR(j));
+ ((u16 *)buf)[rx_ptr * chan + ((j * 2) + 1)] =
+ readl(i2s_base + RRBR_RTHR(j));
+ } else {
+ ((u32 *)buf)[rx_ptr * chan + (j * 2)] =
+ readl(i2s_base + LRBR_LTHR(j));
+ ((u32 *)buf)[rx_ptr * chan + ((j * 2) + 1)] =
+ readl(i2s_base + RRBR_RTHR(j));
+ }
}
-
period_pos++;
if (++rx_ptr >= runtime->buffer_size)
@@ -238,6 +244,7 @@ static irqreturn_t kmb_i2s_irq_handler(int irq, void *dev_id)
struct kmb_i2s_info *kmb_i2s = dev_id;
struct i2s_clk_config_data *config = &kmb_i2s->config;
irqreturn_t ret = IRQ_NONE;
+ u32 tx_enabled = 0;
u32 isr[4];
int i;
@@ -246,22 +253,45 @@ static irqreturn_t kmb_i2s_irq_handler(int irq, void *dev_id)
kmb_i2s_clear_irqs(kmb_i2s, SNDRV_PCM_STREAM_PLAYBACK);
kmb_i2s_clear_irqs(kmb_i2s, SNDRV_PCM_STREAM_CAPTURE);
+ /* Only check TX interrupt if TX is active */
+ tx_enabled = readl(kmb_i2s->i2s_base + ITER);
+
+ /*
+ * Data available. Retrieve samples from FIFO
+ */
+
+ /*
+ * 8 channel audio will have isr[0..2] triggered,
+ * reading the specific isr based on the audio configuration,
+ * to avoid reading the buffers too early.
+ */
+ switch (config->chan_nr) {
+ case 2:
+ if (isr[0] & ISR_RXDA)
+ kmb_pcm_operation(kmb_i2s, false);
+ ret = IRQ_HANDLED;
+ break;
+ case 4:
+ if (isr[1] & ISR_RXDA)
+ kmb_pcm_operation(kmb_i2s, false);
+ ret = IRQ_HANDLED;
+ break;
+ case 8:
+ if (isr[3] & ISR_RXDA)
+ kmb_pcm_operation(kmb_i2s, false);
+ ret = IRQ_HANDLED;
+ break;
+ }
for (i = 0; i < config->chan_nr / 2; i++) {
/*
* Check if TX fifo is empty. If empty fill FIFO with samples
*/
- if ((isr[i] & ISR_TXFE)) {
+ if ((isr[i] & ISR_TXFE) && tx_enabled) {
kmb_pcm_operation(kmb_i2s, true);
ret = IRQ_HANDLED;
}
- /*
- * Data available. Retrieve samples from FIFO
- */
- if ((isr[i] & ISR_RXDA)) {
- kmb_pcm_operation(kmb_i2s, false);
- ret = IRQ_HANDLED;
- }
+
/* Error Handling: TX */
if (isr[i] & ISR_TXFO) {
dev_dbg(kmb_i2s->dev, "TX overrun (ch_id=%d)\n", i);
@@ -445,7 +475,7 @@ static int kmb_dai_hw_params(struct snd_pcm_substream *substream,
{
struct kmb_i2s_info *kmb_i2s = snd_soc_dai_get_drvdata(cpu_dai);
struct i2s_clk_config_data *config = &kmb_i2s->config;
- u32 register_val, write_val;
+ u32 write_val;
int ret;
switch (params_format(hw_params)) {
@@ -472,16 +502,34 @@ static int kmb_dai_hw_params(struct snd_pcm_substream *substream,
config->chan_nr = params_channels(hw_params);
switch (config->chan_nr) {
- /* TODO: This switch case will handle up to TDM8 in the near future */
- case TWO_CHANNEL_SUPPORT:
+ case 8:
+ case 4:
+ /*
+ * Platform is not capable of providing clocks for
+ * multi channel audio
+ */
+ if (kmb_i2s->master)
+ return -EINVAL;
+
write_val = ((config->chan_nr / 2) << TDM_CHANNEL_CONFIG_BIT) |
(config->data_width << DATA_WIDTH_CONFIG_BIT) |
- MASTER_MODE | I2S_OPERATION;
+ !MASTER_MODE | TDM_OPERATION;
writel(write_val, kmb_i2s->pss_base + I2S_GEN_CFG_0);
+ break;
+ case 2:
+ /*
+ * Platform is only capable of providing clocks need for
+ * 2 channel master mode
+ */
+ if (!(kmb_i2s->master))
+ return -EINVAL;
+
+ write_val = ((config->chan_nr / 2) << TDM_CHANNEL_CONFIG_BIT) |
+ (config->data_width << DATA_WIDTH_CONFIG_BIT) |
+ MASTER_MODE | I2S_OPERATION;
- register_val = readl(kmb_i2s->pss_base + I2S_GEN_CFG_0);
- dev_dbg(kmb_i2s->dev, "pss register = 0x%X", register_val);
+ writel(write_val, kmb_i2s->pss_base + I2S_GEN_CFG_0);
break;
default:
dev_dbg(kmb_i2s->dev, "channel not supported\n");
@@ -531,7 +579,7 @@ static struct snd_soc_dai_ops kmb_dai_ops = {
static struct snd_soc_dai_driver intel_kmb_platform_dai[] = {
{
- .name = "kmb-plat-dai",
+ /* .name is provided by Device Tree */
.playback = {
.channels_min = 2,
.channels_max = 2,
@@ -571,6 +619,7 @@ static int kmb_plat_dai_probe(struct platform_device *pdev)
struct kmb_i2s_info *kmb_i2s;
int ret, irq;
u32 comp1_reg;
+ u32 channel_max;
kmb_i2s = devm_kzalloc(dev, sizeof(*kmb_i2s), GFP_KERNEL);
if (!kmb_i2s)
@@ -629,6 +678,12 @@ static int kmb_plat_dai_probe(struct platform_device *pdev)
kmb_i2s->fifo_th = (1 << COMP1_FIFO_DEPTH(comp1_reg)) / 2;
+ ret = of_property_read_u32(dev->of_node, "channel-max", &channel_max);
+ if (ret < 0)
+ dev_err(dev, "Couldn't find channel-max\n");
+ else if (intel_kmb_platform_dai->capture.channels_max < channel_max)
+ intel_kmb_platform_dai->capture.channels_max = channel_max;
+
ret = devm_snd_soc_register_component(dev, &kmb_component,
intel_kmb_platform_dai,
ARRAY_SIZE(intel_kmb_platform_dai));
--
2.17.1
next prev parent reply other threads:[~2020-07-30 6:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-30 5:53 [PATCH 0/4] ASoC: Intel: KMB: TDM Enablement patches Michael Sit Wei Hong
2020-07-30 5:53 ` [PATCH 1/4] ASoC: Intel: KMB: Add 8kHz audio support Michael Sit Wei Hong
2020-07-30 5:53 ` [PATCH 2/4] ASoC: Intel: KMB: Rework disable channel function Michael Sit Wei Hong
2020-07-30 5:53 ` Michael Sit Wei Hong [this message]
2020-07-30 5:53 ` [PATCH 4/4] dt-bindings: sound: intel, keembay-i2s: Add channel-max property Michael Sit Wei Hong
2020-07-30 11:29 ` [PATCH 4/4] dt-bindings: sound: intel,keembay-i2s: " Mark Brown
2020-08-03 1:59 ` Sit, Michael Wei Hong
2020-08-03 10:49 ` Mark Brown
2020-08-04 1:57 ` Sit, Michael Wei Hong
2020-08-04 11:50 ` Mark Brown
2020-08-05 6:21 ` Sit, Michael Wei Hong
2020-08-07 14:31 ` Mark Brown
2020-08-10 9:47 ` Sit, Michael Wei Hong
2020-08-10 12:26 ` Mark Brown
2020-07-30 22:28 ` [PATCH 0/4] ASoC: Intel: KMB: TDM Enablement patches Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200730055319.1522-4-michael.wei.hong.sit@intel.com \
--to=michael.wei.hong.sit@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=andriy.shevchenko@intel.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=jee.heng.sia@intel.com \
--cc=liam.r.girdwood@linux.intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox