linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] Make sound work on DT-based MMP2 machines
@ 2020-05-11 21:01 Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
                   ` (10 more replies)
  0 siblings, 11 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media

Hi,

this patch set reworks the mmp-sspa driver to work on a device
tree based MMP2 machines. My motivation is to make sound work on
a MMP2-based OLPC XO-1.75 laptop.

Note that currently the driver is pretty much orphaned -- it is not used by
any boards and nothing in tree provides the necessary clocks. This means
that risks of regressions are effectively zero; even though my test
configuration is not exhaustive and do not possess the datasheet.

I'm actually not convinced it would've worked too well if it was hooked
on (due to what patches 01/11, 02/11 and perhaps 09/11).

I've tested this on a XO-1.75 along with clk-audio driver that was
submitted separately ("MMP2 Audio clock controller driver" [1]),
mmp_tdma driver (with changes queued in linux-next), the rt5631 codec
and audio-graph-card.

[1] https://lore.kernel.org/lkml/20200511195534.1207927-1-lkundrak@v3.sk/

Thank you,
Lubo



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-12 16:45   ` Mark Brown
  2020-05-19 19:52   ` Mark Brown
  2020-05-11 21:01 ` [PATCH 02/11] ASoC: mmp-sspa: Drop S20_3LE case Lubomir Rintel
                   ` (9 subsequent siblings)
  10 siblings, 2 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

The hw_params() callback handles the 3-byte format, not
SNDRV_PCM_FMTBIT_S24_LE.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 3548a2634a63..1ca6afe464c4 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -362,7 +362,7 @@ static int mmp_sspa_probe(struct snd_soc_dai *dai)
 #define MMP_SSPA_RATES SNDRV_PCM_RATE_8000_192000
 #define MMP_SSPA_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
 		SNDRV_PCM_FMTBIT_S16_LE | \
-		SNDRV_PCM_FMTBIT_S24_LE | \
+		SNDRV_PCM_FMTBIT_S24_3LE | \
 		SNDRV_PCM_FMTBIT_S32_LE)
 
 static const struct snd_soc_dai_ops mmp_sspa_dai_ops = {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 02/11] ASoC: mmp-sspa: Drop S20_3LE case
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 03/11] ASoC: mmp-sspa: A trivial typo fix Lubomir Rintel
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

It does nothing, because the corresponding bit s not flipped on in .formats
and the audio SRAM DMA engine is not able to handle 20-bit transfers
anyway.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 1ca6afe464c4..90a9bc81be80 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -275,9 +275,6 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 	case SNDRV_PCM_FORMAT_S16_LE:
 		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_16_BITS);
 		break;
-	case SNDRV_PCM_FORMAT_S20_3LE:
-		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_20_BITS);
-		break;
 	case SNDRV_PCM_FORMAT_S24_3LE:
 		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_24_BITS);
 		break;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 03/11] ASoC: mmp-sspa: A trivial typo fix
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 02/11] ASoC: mmp-sspa: Drop S20_3LE case Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 04/11] ASoC: mmp-sspa: Get rid of dma_params and phys_base Lubomir Rintel
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

"Transmit", not "Tansmit".

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h
index 7d1b7c7325df..611063a7af68 100644
--- a/sound/soc/pxa/mmp-sspa.h
+++ b/sound/soc/pxa/mmp-sspa.h
@@ -38,7 +38,7 @@
 #define	SSPA_CTL_XFRLEN2(x)	((x) << 24)	/* Transmit Frame Length in Phase 2 */
 #define	SSPA_CTL_XWDLEN2_MASK	(7 << 21)
 #define	SSPA_CTL_XWDLEN2(x)	((x) << 21)	/* Transmit Word Length in Phase 2 */
-#define	SSPA_CTL_XDATDLY(x)	((x) << 19)	/* Tansmit Data Delay */
+#define	SSPA_CTL_XDATDLY(x)	((x) << 19)	/* Transmit Data Delay */
 #define	SSPA_CTL_XSSZ2_MASK	(7 << 16)
 #define	SSPA_CTL_XSSZ2(x)	((x) << 16)	/* Transmit Sample Audio Size */
 #define	SSPA_CTL_XFRLEN1_MASK	(7 << 8)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 04/11] ASoC: mmp-sspa: Get rid of dma_params and phys_base
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (2 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 03/11] ASoC: mmp-sspa: A trivial typo fix Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 05/11] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm Lubomir Rintel
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

This makes things simpler. There's no reason not to just embed the struct
snd_dmaengine_dai_dma_data in struct sspa_priv and do away with an
unnecessary kmalloc(). While at that, we can initialize the
snd_dmaengine_dai_dma_data structures earlier.

Let's also stop offsetting the source/destination of the DMA transfer by
phys_base. Firstly, it's never set and is always zero. Secondly, the
hardware actually ignores it, at least on a MMP2 and MMP3.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 90a9bc81be80..421ffa9fa7b1 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -29,7 +29,8 @@
  */
 struct sspa_priv {
 	struct ssp_device *sspa;
-	struct snd_dmaengine_dai_dma_data *dma_params;
+	struct snd_dmaengine_dai_dma_data playback_dma_data;
+	struct snd_dmaengine_dai_dma_data capture_dma_data;
 	struct clk *audio_clk;
 	struct clk *sysclk;
 	int dai_fmt;
@@ -250,11 +251,8 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 			       struct snd_pcm_hw_params *params,
 			       struct snd_soc_dai *dai)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai);
 	struct ssp_device *sspa = sspa_priv->sspa;
-	struct snd_dmaengine_dai_dma_data *dma_params;
 	u32 sspa_ctrl;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -293,11 +291,6 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 		mmp_sspa_write_reg(sspa, SSPA_RXFIFO_UL, 0x0);
 	}
 
-	dma_params = &sspa_priv->dma_params[substream->stream];
-	dma_params->addr = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
-				(sspa->phys_base + SSPA_TXD) :
-				(sspa->phys_base + SSPA_RXD);
-	snd_soc_dai_set_dma_data(cpu_dai, substream, dma_params);
 	return 0;
 }
 
@@ -351,6 +344,10 @@ static int mmp_sspa_probe(struct snd_soc_dai *dai)
 {
 	struct sspa_priv *priv = dev_get_drvdata(dai->dev);
 
+	snd_soc_dai_init_dma_data(dai,
+				&priv->playback_dma_data,
+				&priv->capture_dma_data);
+
 	snd_soc_dai_set_drvdata(dai, priv);
 	return 0;
 
@@ -407,12 +404,6 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 	if (priv->sspa == NULL)
 		return -ENOMEM;
 
-	priv->dma_params = devm_kcalloc(&pdev->dev,
-			2, sizeof(struct snd_dmaengine_dai_dma_data),
-			GFP_KERNEL);
-	if (priv->dma_params == NULL)
-		return -ENOMEM;
-
 	priv->sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->sspa->mmio_base))
 		return PTR_ERR(priv->sspa->mmio_base);
@@ -434,6 +425,10 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 	priv->dai_fmt = (unsigned int) -1;
 	platform_set_drvdata(pdev, priv);
 
+	/* You know, these addresses are actually ignored. */
+	priv->playback_dma_data.addr = SSPA_TXD;
+	priv->capture_dma_data.addr = SSPA_RXD;
+
 	return devm_snd_soc_register_component(&pdev->dev, &mmp_sspa_component,
 					       &mmp_sspa_dai, 1);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 05/11] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (3 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 04/11] ASoC: mmp-sspa: Get rid of dma_params and phys_base Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 06/11] ASoC: mmp-sspa: Remove the embedded struct ssp_device Lubomir Rintel
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

This makes the driver usable with the mmp_tdma drier via
soc-generic-dmaengine-pcm. This is conditionalized on DT node (support
for DT is added by a later patch).

A custom mmap callback that creates a NC mapping is used instead of the
default WC one, because with write-combining some bytes don't seem to
make it through for reasons unknown to me.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 57 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 421ffa9fa7b1..6e4b63d0c589 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -386,8 +386,54 @@ static struct snd_soc_dai_driver mmp_sspa_dai = {
 	.ops = &mmp_sspa_dai_ops,
 };
 
+#define MMP_PCM_INFO (SNDRV_PCM_INFO_MMAP |	\
+		SNDRV_PCM_INFO_MMAP_VALID |	\
+		SNDRV_PCM_INFO_INTERLEAVED |	\
+		SNDRV_PCM_INFO_PAUSE |		\
+		SNDRV_PCM_INFO_RESUME |		\
+		SNDRV_PCM_INFO_NO_PERIOD_WAKEUP)
+
+static const struct snd_pcm_hardware mmp_pcm_hardware[] = {
+	{
+		.info			= MMP_PCM_INFO,
+		.period_bytes_min	= 1024,
+		.period_bytes_max	= 2048,
+		.periods_min		= 2,
+		.periods_max		= 32,
+		.buffer_bytes_max	= 4096,
+		.fifo_size		= 32,
+	},
+	{
+		.info			= MMP_PCM_INFO,
+		.period_bytes_min	= 1024,
+		.period_bytes_max	= 2048,
+		.periods_min		= 2,
+		.periods_max		= 32,
+		.buffer_bytes_max	= 4096,
+		.fifo_size		= 32,
+	},
+};
+
+static const struct snd_dmaengine_pcm_config mmp_pcm_config = {
+	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
+	.pcm_hardware = mmp_pcm_hardware,
+	.prealloc_buffer_size = 4096,
+};
+
+static int mmp_pcm_mmap(struct snd_soc_component *component,
+			struct snd_pcm_substream *substream,
+			struct vm_area_struct *vma)
+{
+	vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+	return remap_pfn_range(vma, vma->vm_start,
+		substream->dma_buffer.addr >> PAGE_SHIFT,
+		vma->vm_end - vma->vm_start, vma->vm_page_prot);
+}
+
 static const struct snd_soc_component_driver mmp_sspa_component = {
 	.name		= "mmp-sspa",
+	.mmap		= mmp_pcm_mmap,
 };
 
 static int asoc_mmp_sspa_probe(struct platform_device *pdev)
@@ -425,10 +471,21 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 	priv->dai_fmt = (unsigned int) -1;
 	platform_set_drvdata(pdev, priv);
 
+	priv->playback_dma_data.maxburst = 4;
+	priv->capture_dma_data.maxburst = 4;
 	/* You know, these addresses are actually ignored. */
 	priv->playback_dma_data.addr = SSPA_TXD;
 	priv->capture_dma_data.addr = SSPA_RXD;
 
+	if (pdev->dev.of_node) {
+		int ret;
+
+		ret = devm_snd_dmaengine_pcm_register(&pdev->dev,
+						      &mmp_pcm_config, 0);
+		if (ret)
+			return ret;
+	}
+
 	return devm_snd_soc_register_component(&pdev->dev, &mmp_sspa_component,
 					       &mmp_sspa_dai, 1);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 06/11] ASoC: mmp-sspa: Remove the embedded struct ssp_device
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (4 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 05/11] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks Lubomir Rintel
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

The "serial port" it represents is actually a SPI controller -- it's not
clear why would the audio serial interface embed it. We're only using
the mmio_base and clk fields.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 129 ++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 69 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 6e4b63d0c589..7a706b1d2588 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -11,7 +11,6 @@
 #include <linux/delay.h>
 #include <linux/clk.h>
 #include <linux/slab.h>
-#include <linux/pxa2xx_ssp.h>
 #include <linux/io.h>
 #include <linux/dmaengine.h>
 
@@ -28,26 +27,27 @@
  * SSPA audio private data
  */
 struct sspa_priv {
-	struct ssp_device *sspa;
+	void __iomem *mmio_base;
 	struct snd_dmaengine_dai_dma_data playback_dma_data;
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
+	struct clk *clk;
 	struct clk *audio_clk;
 	struct clk *sysclk;
 	int dai_fmt;
 	int running_cnt;
 };
 
-static void mmp_sspa_write_reg(struct ssp_device *sspa, u32 reg, u32 val)
+static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val)
 {
 	__raw_writel(val, sspa->mmio_base + reg);
 }
 
-static u32 mmp_sspa_read_reg(struct ssp_device *sspa, u32 reg)
+static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg)
 {
 	return __raw_readl(sspa->mmio_base + reg);
 }
 
-static void mmp_sspa_tx_enable(struct ssp_device *sspa)
+static void mmp_sspa_tx_enable(struct sspa_priv *sspa)
 {
 	unsigned int sspa_sp;
 
@@ -57,7 +57,7 @@ static void mmp_sspa_tx_enable(struct ssp_device *sspa)
 	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
 }
 
-static void mmp_sspa_tx_disable(struct ssp_device *sspa)
+static void mmp_sspa_tx_disable(struct sspa_priv *sspa)
 {
 	unsigned int sspa_sp;
 
@@ -67,7 +67,7 @@ static void mmp_sspa_tx_disable(struct ssp_device *sspa)
 	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
 }
 
-static void mmp_sspa_rx_enable(struct ssp_device *sspa)
+static void mmp_sspa_rx_enable(struct sspa_priv *sspa)
 {
 	unsigned int sspa_sp;
 
@@ -77,7 +77,7 @@ static void mmp_sspa_rx_enable(struct ssp_device *sspa)
 	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
 }
 
-static void mmp_sspa_rx_disable(struct ssp_device *sspa)
+static void mmp_sspa_rx_disable(struct sspa_priv *sspa)
 {
 	unsigned int sspa_sp;
 
@@ -90,10 +90,10 @@ static void mmp_sspa_rx_disable(struct ssp_device *sspa)
 static int mmp_sspa_startup(struct snd_pcm_substream *substream,
 	struct snd_soc_dai *dai)
 {
-	struct sspa_priv *priv = snd_soc_dai_get_drvdata(dai);
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 
-	clk_enable(priv->sysclk);
-	clk_enable(priv->sspa->clk);
+	clk_enable(sspa->sysclk);
+	clk_enable(sspa->clk);
 
 	return 0;
 }
@@ -101,10 +101,10 @@ static int mmp_sspa_startup(struct snd_pcm_substream *substream,
 static void mmp_sspa_shutdown(struct snd_pcm_substream *substream,
 	struct snd_soc_dai *dai)
 {
-	struct sspa_priv *priv = snd_soc_dai_get_drvdata(dai);
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 
-	clk_disable(priv->sspa->clk);
-	clk_disable(priv->sysclk);
+	clk_disable(sspa->clk);
+	clk_disable(sspa->sysclk);
 
 }
 
@@ -114,12 +114,12 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream,
 static int mmp_sspa_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
 				    int clk_id, unsigned int freq, int dir)
 {
-	struct sspa_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
 	int ret = 0;
 
 	switch (clk_id) {
 	case MMP_SSPA_CLK_AUDIO:
-		ret = clk_set_rate(priv->audio_clk, freq);
+		ret = clk_set_rate(sspa->audio_clk, freq);
 		if (ret)
 			return ret;
 		break;
@@ -138,17 +138,17 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
 				 int source, unsigned int freq_in,
 				 unsigned int freq_out)
 {
-	struct sspa_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
 	int ret = 0;
 
 	switch (pll_id) {
 	case MMP_SYSCLK:
-		ret = clk_set_rate(priv->sysclk, freq_out);
+		ret = clk_set_rate(sspa->sysclk, freq_out);
 		if (ret)
 			return ret;
 		break;
 	case MMP_SSPA_CLK:
-		ret = clk_set_rate(priv->sspa->clk, freq_out);
+		ret = clk_set_rate(sspa->clk, freq_out);
 		if (ret)
 			return ret;
 		break;
@@ -167,18 +167,17 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
 static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 				 unsigned int fmt)
 {
-	struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(cpu_dai);
-	struct ssp_device *sspa = sspa_priv->sspa;
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
 	u32 sspa_sp, sspa_ctrl;
 
 	/* check if we need to change anything at all */
-	if (sspa_priv->dai_fmt == fmt)
+	if (sspa->dai_fmt == fmt)
 		return 0;
 
 	/* we can only change the settings if the port is not in use */
 	if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) ||
 	    (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) {
-		dev_err(sspa->dev,
+		dev_err(cpu_dai->dev,
 			"can't change hardware dai format: stream is in use\n");
 		return -EINVAL;
 	}
@@ -239,7 +238,7 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 	 * we have to defer some things until hw_params() where we
 	 * know parameters like the sample size.
 	 */
-	sspa_priv->dai_fmt = fmt;
+	sspa->dai_fmt = fmt;
 	return 0;
 }
 
@@ -251,8 +250,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 			       struct snd_pcm_hw_params *params,
 			       struct snd_soc_dai *dai)
 {
-	struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai);
-	struct ssp_device *sspa = sspa_priv->sspa;
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 	u32 sspa_ctrl;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -297,8 +295,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd,
 			     struct snd_soc_dai *dai)
 {
-	struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai);
-	struct ssp_device *sspa = sspa_priv->sspa;
+	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 	int ret = 0;
 
 	switch (cmd) {
@@ -311,25 +308,25 @@ static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd,
 		 * enabled or not; if has been enabled by another
 		 * stream, do not enable again.
 		 */
-		if (!sspa_priv->running_cnt)
+		if (!sspa->running_cnt)
 			mmp_sspa_rx_enable(sspa);
 
 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 			mmp_sspa_tx_enable(sspa);
 
-		sspa_priv->running_cnt++;
+		sspa->running_cnt++;
 		break;
 
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		sspa_priv->running_cnt--;
+		sspa->running_cnt--;
 
 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 			mmp_sspa_tx_disable(sspa);
 
 		/* have no capture stream, disable rx port */
-		if (!sspa_priv->running_cnt)
+		if (!sspa->running_cnt)
 			mmp_sspa_rx_disable(sspa);
 		break;
 
@@ -342,15 +339,14 @@ static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd,
 
 static int mmp_sspa_probe(struct snd_soc_dai *dai)
 {
-	struct sspa_priv *priv = dev_get_drvdata(dai->dev);
+	struct sspa_priv *sspa = dev_get_drvdata(dai->dev);
 
 	snd_soc_dai_init_dma_data(dai,
-				&priv->playback_dma_data,
-				&priv->capture_dma_data);
+				&sspa->playback_dma_data,
+				&sspa->capture_dma_data);
 
-	snd_soc_dai_set_drvdata(dai, priv);
+	snd_soc_dai_set_drvdata(dai, sspa);
 	return 0;
-
 }
 
 #define MMP_SSPA_RATES SNDRV_PCM_RATE_8000_192000
@@ -438,44 +434,39 @@ static const struct snd_soc_component_driver mmp_sspa_component = {
 
 static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 {
-	struct sspa_priv *priv;
+	struct sspa_priv *sspa;
 
-	priv = devm_kzalloc(&pdev->dev,
+	sspa = devm_kzalloc(&pdev->dev,
 				sizeof(struct sspa_priv), GFP_KERNEL);
-	if (!priv)
+	if (!sspa)
 		return -ENOMEM;
 
-	priv->sspa = devm_kzalloc(&pdev->dev,
-				sizeof(struct ssp_device), GFP_KERNEL);
-	if (priv->sspa == NULL)
-		return -ENOMEM;
+	sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(sspa->mmio_base))
+		return PTR_ERR(sspa->mmio_base);
 
-	priv->sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(priv->sspa->mmio_base))
-		return PTR_ERR(priv->sspa->mmio_base);
+	sspa->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(sspa->clk))
+		return PTR_ERR(sspa->clk);
 
-	priv->sspa->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(priv->sspa->clk))
-		return PTR_ERR(priv->sspa->clk);
+	sspa->audio_clk = clk_get(NULL, "mmp-audio");
+	if (IS_ERR(sspa->audio_clk))
+		return PTR_ERR(sspa->audio_clk);
 
-	priv->audio_clk = clk_get(NULL, "mmp-audio");
-	if (IS_ERR(priv->audio_clk))
-		return PTR_ERR(priv->audio_clk);
-
-	priv->sysclk = clk_get(NULL, "mmp-sysclk");
-	if (IS_ERR(priv->sysclk)) {
-		clk_put(priv->audio_clk);
-		return PTR_ERR(priv->sysclk);
+	sspa->sysclk = clk_get(NULL, "mmp-sysclk");
+	if (IS_ERR(sspa->sysclk)) {
+		clk_put(sspa->audio_clk);
+		return PTR_ERR(sspa->sysclk);
 	}
-	clk_enable(priv->audio_clk);
-	priv->dai_fmt = (unsigned int) -1;
-	platform_set_drvdata(pdev, priv);
+	clk_enable(sspa->audio_clk);
+	sspa->dai_fmt = (unsigned int) -1;
+	platform_set_drvdata(pdev, sspa);
 
-	priv->playback_dma_data.maxburst = 4;
-	priv->capture_dma_data.maxburst = 4;
+	sspa->playback_dma_data.maxburst = 4;
+	sspa->capture_dma_data.maxburst = 4;
 	/* You know, these addresses are actually ignored. */
-	priv->playback_dma_data.addr = SSPA_TXD;
-	priv->capture_dma_data.addr = SSPA_RXD;
+	sspa->playback_dma_data.addr = SSPA_TXD;
+	sspa->capture_dma_data.addr = SSPA_RXD;
 
 	if (pdev->dev.of_node) {
 		int ret;
@@ -492,11 +483,11 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 
 static int asoc_mmp_sspa_remove(struct platform_device *pdev)
 {
-	struct sspa_priv *priv = platform_get_drvdata(pdev);
+	struct sspa_priv *sspa = platform_get_drvdata(pdev);
 
-	clk_disable(priv->audio_clk);
-	clk_put(priv->audio_clk);
-	clk_put(priv->sysclk);
+	clk_disable(sspa->audio_clk);
+	clk_put(sspa->audio_clk);
+	clk_put(sspa->sysclk);
 	return 0;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (5 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 06/11] ASoC: mmp-sspa: Remove the embedded struct ssp_device Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-12 12:45   ` Mark Brown
  2020-05-11 21:01 ` [PATCH 08/11] ASoC: mmp-sspa: Add support for the runtime power management Lubomir Rintel
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

The driver enables the clocks without preparing them and disables
without unpreparing afterwards. Fix that.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 7a706b1d2588..a66e594b1072 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -92,8 +92,8 @@ static int mmp_sspa_startup(struct snd_pcm_substream *substream,
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 
-	clk_enable(sspa->sysclk);
-	clk_enable(sspa->clk);
+	clk_prepare_enable(sspa->sysclk);
+	clk_prepare_enable(sspa->clk);
 
 	return 0;
 }
@@ -103,8 +103,8 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream,
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 
-	clk_disable(sspa->clk);
-	clk_disable(sspa->sysclk);
+	clk_disable_unprepare(sspa->clk);
+	clk_disable_unprepare(sspa->sysclk);
 
 }
 
@@ -458,7 +458,7 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 		clk_put(sspa->audio_clk);
 		return PTR_ERR(sspa->sysclk);
 	}
-	clk_enable(sspa->audio_clk);
+	clk_prepare_enable(sspa->audio_clk);
 	sspa->dai_fmt = (unsigned int) -1;
 	platform_set_drvdata(pdev, sspa);
 
@@ -485,7 +485,7 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev)
 {
 	struct sspa_priv *sspa = platform_get_drvdata(pdev);
 
-	clk_disable(sspa->audio_clk);
+	clk_disable_unprepare(sspa->audio_clk);
 	clk_put(sspa->audio_clk);
 	clk_put(sspa->sysclk);
 	return 0;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 08/11] ASoC: mmp-sspa: Add support for the runtime power management
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (6 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 09/11] ASoC: mmp-sspa: Set appropriate bus format for given bit width Lubomir Rintel
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

Only turn on the Audio island when it's in use.

This requires keeping track of control register contents instead of
reloading them back from hardware, because they're lost when the power is
off.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 126 ++++++++++++++++++++-------------------
 1 file changed, 66 insertions(+), 60 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index a66e594b1072..9cb17c4fb0c8 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -13,6 +13,7 @@
 #include <linux/slab.h>
 #include <linux/io.h>
 #include <linux/dmaengine.h>
+#include <linux/pm_runtime.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -33,8 +34,9 @@ struct sspa_priv {
 	struct clk *clk;
 	struct clk *audio_clk;
 	struct clk *sysclk;
-	int dai_fmt;
 	int running_cnt;
+	u32 sp;
+	u32 ctrl;
 };
 
 static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val)
@@ -49,9 +51,9 @@ static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg)
 
 static void mmp_sspa_tx_enable(struct sspa_priv *sspa)
 {
-	unsigned int sspa_sp;
+	unsigned int sspa_sp = sspa->sp;
 
-	sspa_sp = mmp_sspa_read_reg(sspa, SSPA_TXSP);
+	sspa_sp &= ~SSPA_SP_MSL;
 	sspa_sp |= SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
 	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
@@ -59,9 +61,9 @@ static void mmp_sspa_tx_enable(struct sspa_priv *sspa)
 
 static void mmp_sspa_tx_disable(struct sspa_priv *sspa)
 {
-	unsigned int sspa_sp;
+	unsigned int sspa_sp = sspa->sp;
 
-	sspa_sp = mmp_sspa_read_reg(sspa, SSPA_TXSP);
+	sspa_sp &= ~SSPA_SP_MSL;
 	sspa_sp &= ~SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
 	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
@@ -69,9 +71,8 @@ static void mmp_sspa_tx_disable(struct sspa_priv *sspa)
 
 static void mmp_sspa_rx_enable(struct sspa_priv *sspa)
 {
-	unsigned int sspa_sp;
+	unsigned int sspa_sp = sspa->sp;
 
-	sspa_sp = mmp_sspa_read_reg(sspa, SSPA_RXSP);
 	sspa_sp |= SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
 	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
@@ -79,9 +80,8 @@ static void mmp_sspa_rx_enable(struct sspa_priv *sspa)
 
 static void mmp_sspa_rx_disable(struct sspa_priv *sspa)
 {
-	unsigned int sspa_sp;
+	unsigned int sspa_sp = sspa->sp;
 
-	sspa_sp = mmp_sspa_read_reg(sspa, SSPA_RXSP);
 	sspa_sp &= ~SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
 	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
@@ -160,35 +160,20 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
 }
 
 /*
- * Set up the sspa dai format. The sspa port must be inactive
- * before calling this function as the physical
- * interface format is changed.
+ * Set up the sspa dai format.
  */
 static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 				 unsigned int fmt)
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
-	u32 sspa_sp, sspa_ctrl;
-
-	/* check if we need to change anything at all */
-	if (sspa->dai_fmt == fmt)
-		return 0;
-
-	/* we can only change the settings if the port is not in use */
-	if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) ||
-	    (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) {
-		dev_err(cpu_dai->dev,
-			"can't change hardware dai format: stream is in use\n");
-		return -EINVAL;
-	}
 
 	/* reset port settings */
-	sspa_sp   = SSPA_SP_WEN | SSPA_SP_S_RST | SSPA_SP_FFLUSH;
-	sspa_ctrl = 0;
+	sspa->sp   = SSPA_SP_WEN | SSPA_SP_S_RST | SSPA_SP_FFLUSH;
+	sspa->ctrl = 0;
 
 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
 	case SND_SOC_DAIFMT_CBS_CFS:
-		sspa_sp |= SSPA_SP_MSL;
+		sspa->sp |= SSPA_SP_MSL;
 		break;
 	case SND_SOC_DAIFMT_CBM_CFM:
 		break;
@@ -198,7 +183,7 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 
 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
 	case SND_SOC_DAIFMT_NB_NF:
-		sspa_sp |= SSPA_SP_FSP;
+		sspa->sp |= SSPA_SP_FSP;
 		break;
 	default:
 		return -EINVAL;
@@ -206,39 +191,18 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 
 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
-		sspa_sp |= SSPA_TXSP_FPER(63);
-		sspa_sp |= SSPA_SP_FWID(31);
-		sspa_ctrl |= SSPA_CTL_XDATDLY(1);
+		sspa->sp |= SSPA_TXSP_FPER(63);
+		sspa->sp |= SSPA_SP_FWID(31);
+		sspa->ctrl |= SSPA_CTL_XDATDLY(1);
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
-
-	sspa_sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH);
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
-
-	/*
-	 * FIXME: hw issue, for the tx serial port,
-	 * can not config the master/slave mode;
-	 * so must clean this bit.
-	 * The master/slave mode has been set in the
-	 * rx port.
-	 */
-	sspa_sp &= ~SSPA_SP_MSL;
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
-
-	mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl);
-	mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa_ctrl);
-
 	/* Since we are configuring the timings for the format by hand
 	 * we have to defer some things until hw_params() where we
 	 * know parameters like the sample size.
 	 */
-	sspa->dai_fmt = fmt;
 	return 0;
 }
 
@@ -251,12 +215,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 			       struct snd_soc_dai *dai)
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
-	u32 sspa_ctrl;
-
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		sspa_ctrl = mmp_sspa_read_reg(sspa, SSPA_TXCTL);
-	else
-		sspa_ctrl = mmp_sspa_read_reg(sspa, SSPA_RXCTL);
+	u32 sspa_ctrl = sspa->ctrl;
 
 	sspa_ctrl &= ~SSPA_CTL_XFRLEN1_MASK;
 	sspa_ctrl |= SSPA_CTL_XFRLEN1(params_channels(params) - 1);
@@ -427,9 +386,55 @@ static int mmp_pcm_mmap(struct snd_soc_component *component,
 		vma->vm_end - vma->vm_start, vma->vm_page_prot);
 }
 
+static int mmp_sspa_open(struct snd_soc_component *component,
+			 struct snd_pcm_substream *substream)
+{
+	struct sspa_priv *sspa = snd_soc_component_get_drvdata(component);
+
+	pm_runtime_get_sync(component->dev);
+
+	/* we can only change the settings if the port is not in use */
+	if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) ||
+	    (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) {
+		dev_err(component->dev,
+			"can't change hardware dai format: stream is in use\n");
+		return -EBUSY;
+	}
+
+	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp);
+	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp);
+
+	sspa->sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH);
+	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp);
+	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp);
+
+	/*
+	 * FIXME: hw issue, for the tx serial port,
+	 * can not config the master/slave mode;
+	 * so must clean this bit.
+	 * The master/slave mode has been set in the
+	 * rx port.
+	 */
+	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp & ~SSPA_SP_MSL);
+
+	mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa->ctrl);
+	mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa->ctrl);
+
+	return 0;
+}
+
+static int mmp_sspa_close(struct snd_soc_component *component,
+			  struct snd_pcm_substream *substream)
+{
+	pm_runtime_put_sync(component->dev);
+	return 0;
+}
+
 static const struct snd_soc_component_driver mmp_sspa_component = {
 	.name		= "mmp-sspa",
 	.mmap		= mmp_pcm_mmap,
+	.open		= mmp_sspa_open,
+	.close		= mmp_sspa_close,
 };
 
 static int asoc_mmp_sspa_probe(struct platform_device *pdev)
@@ -458,8 +463,8 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 		clk_put(sspa->audio_clk);
 		return PTR_ERR(sspa->sysclk);
 	}
+	pm_runtime_enable(&pdev->dev);
 	clk_prepare_enable(sspa->audio_clk);
-	sspa->dai_fmt = (unsigned int) -1;
 	platform_set_drvdata(pdev, sspa);
 
 	sspa->playback_dma_data.maxburst = 4;
@@ -486,6 +491,7 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev)
 	struct sspa_priv *sspa = platform_get_drvdata(pdev);
 
 	clk_disable_unprepare(sspa->audio_clk);
+	pm_runtime_disable(&pdev->dev);
 	clk_put(sspa->audio_clk);
 	clk_put(sspa->sysclk);
 	return 0;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 09/11] ASoC: mmp-sspa: Set appropriate bus format for given bit width
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (7 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 08/11] ASoC: mmp-sspa: Add support for the runtime power management Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding Lubomir Rintel
  2020-05-11 21:01 ` [PATCH 11/11] ASoC: mmp-sspa: Add Device Tree support Lubomir Rintel
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

The values set by set_dai_fmt() and hw_params() seem to be tailored only
for 32-bit formats. Negotiate the correct ones in hw_params() callback
instead.

This was essentially copied from the OLPC kernel driver and tested to
fix wrong audio output for non-32bit formats. The documentation is not
available.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/mmp-sspa.c | 40 ++++++++++++++++++++++++++++------------
 sound/soc/pxa/mmp-sspa.h |  2 ++
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 9cb17c4fb0c8..86277471974a 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -191,8 +191,6 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 
 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
-		sspa->sp |= SSPA_TXSP_FPER(63);
-		sspa->sp |= SSPA_SP_FWID(31);
 		sspa->ctrl |= SSPA_CTL_XDATDLY(1);
 		break;
 	default:
@@ -216,30 +214,48 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
 	u32 sspa_ctrl = sspa->ctrl;
-
-	sspa_ctrl &= ~SSPA_CTL_XFRLEN1_MASK;
-	sspa_ctrl |= SSPA_CTL_XFRLEN1(params_channels(params) - 1);
-	sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK;
-	sspa_ctrl |= SSPA_CTL_XWDLEN1(SSPA_CTL_32_BITS);
-	sspa_ctrl &= ~SSPA_CTL_XSSZ1_MASK;
+	int bits;
+	int bitval;
 
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S8:
-		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_8_BITS);
+		bits = 8;
+		bitval = SSPA_CTL_8_BITS;
 		break;
 	case SNDRV_PCM_FORMAT_S16_LE:
-		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_16_BITS);
+		bits = 16;
+		bitval = SSPA_CTL_16_BITS;
 		break;
 	case SNDRV_PCM_FORMAT_S24_3LE:
-		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_24_BITS);
+		bits = 24;
+		bitval = SSPA_CTL_24_BITS;
 		break;
 	case SNDRV_PCM_FORMAT_S32_LE:
-		sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_32_BITS);
+		bits = 32;
+		bitval = SSPA_CTL_32_BITS;
 		break;
 	default:
 		return -EINVAL;
 	}
 
+	if (params_channels(params) == 2)
+		sspa_ctrl |= SSPA_CTL_XPH;
+
+	sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK;
+	sspa_ctrl |= SSPA_CTL_XWDLEN1(bitval);
+
+	sspa_ctrl &= ~SSPA_CTL_XSSZ1_MASK;
+	sspa_ctrl |= SSPA_CTL_XSSZ1(bitval);
+
+	sspa_ctrl &= ~SSPA_CTL_XSSZ2_MASK;
+	sspa_ctrl |= SSPA_CTL_XSSZ2(bitval);
+
+	sspa->sp &= ~SSPA_SP_FWID_MASK;
+	sspa->sp |= SSPA_SP_FWID(bits - 1);
+
+	sspa->sp &= ~SSPA_TXSP_FPER_MASK;
+	sspa->sp |= SSPA_TXSP_FPER(bits * 2 - 1);
+
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl);
 		mmp_sspa_write_reg(sspa, SSPA_TXFIFO_LL, 0x1);
diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h
index 611063a7af68..328969b57ad1 100644
--- a/sound/soc/pxa/mmp-sspa.h
+++ b/sound/soc/pxa/mmp-sspa.h
@@ -63,7 +63,9 @@
 #define	SSPA_SP_FFLUSH		(1 << 2)	/* FIFO Flush */
 #define	SSPA_SP_S_RST		(1 << 1)	/* Active High Reset Signal */
 #define	SSPA_SP_S_EN		(1 << 0)	/* Serial Clock Domain Enable */
+#define	SSPA_SP_FWID_MASK	(0x3f << 20)
 #define	SSPA_SP_FWID(x)		((x) << 20)	/* Frame-Sync Width */
+#define	SSPA_TXSP_FPER_MASK	(0x3f << 4)
 #define	SSPA_TXSP_FPER(x)	((x) << 4)	/* Frame-Sync Active */
 
 /* sspa clock sources */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (8 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 09/11] ASoC: mmp-sspa: Set appropriate bus format for given bit width Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  2020-05-19 18:37   ` Rob Herring
  2020-05-11 21:01 ` [PATCH 11/11] ASoC: mmp-sspa: Add Device Tree support Lubomir Rintel
  10 siblings, 1 reply; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

Add binding documentation for the audio serial port interface (I2S) on
Marvell MMP SoCs.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 .../bindings/sound/marvell,mmp-sspa.yaml      | 122 ++++++++++++++++++
 1 file changed, 122 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml

diff --git a/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml b/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml
new file mode 100644
index 000000000000..6d20a24a2ae9
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml
@@ -0,0 +1,122 @@
+# SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/marvell,mmp-sspa.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvel SSPA Digital Audio Interface Bindings
+
+maintainers:
+  - Lubomir Rintel <lkundrak@v3.sk>
+
+properties:
+  $nodename:
+    pattern: "^audio-controller(@.*)?$"
+
+  compatible:
+    const: marvell,mmp-sspa
+
+  reg:
+    items:
+      - description: RX block
+      - description: TX block
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Clock for the Audio block
+      - description: I2S bit clock
+
+  clock-names:
+    items:
+      - const: audio
+      - const: bitclk
+
+  power-domains:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    const: 0
+
+  dmas:
+    items:
+      - description: TX DMA Channel
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  port:
+    type: object
+
+    properties:
+      endpoint:
+        type: object
+
+        properties:
+          remote-endpoint: true
+
+          frame-master:
+            type: boolean
+            description: SoC generates the frame clock
+
+          bitclock-master:
+            type: boolean
+            description: SoC generates the bit clock
+
+          dai-format:
+            $ref: /schemas/types.yaml#/definitions/string
+            description: The digital audio format
+            const: i2s
+
+        required:
+          - remote-endpoint
+
+    required:
+      - endpoint
+
+    additionalProperties: false
+
+required:
+  - "#sound-dai-cells"
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - dmas
+  - dma-names
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/marvell,mmp2.h>
+
+    audio-controller@d42a0c00 {
+      compatible = "marvell,mmp-sspa";
+      reg = <0xd42a0c00 0x30>,
+            <0xd42a0c80 0x30>;
+      interrupts = <2>;
+      clock-names = "audio", "bitclk";
+      clocks = <&soc_clocks 127>,
+               <&audio_clk 1>;
+      #sound-dai-cells = <0>;
+      dmas = <&adma0 0>, <&adma0 1>;
+      dma-names = "tx", "rx";
+      port {
+        endpoint {
+          remote-endpoint = <&rt5631_0>;
+          frame-master;
+          bitclock-master;
+          dai-format = "i2s";
+        };
+      };
+    };
+
+...
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 11/11] ASoC: mmp-sspa: Add Device Tree support
  2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
                   ` (9 preceding siblings ...)
  2020-05-11 21:01 ` [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding Lubomir Rintel
@ 2020-05-11 21:01 ` Lubomir Rintel
  10 siblings, 0 replies; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-11 21:01 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media, Lubomir Rintel

This makes it possible to select CONFIG_SND_MMP_SOC_SSPA directly, as
opposed to via CONFIG_SND_MMP_SOC, and for the driver to bind to a device
tree node. That makes the driver useful on Device Tree based systems,
with audio-graph-card or simple-card.

The aforementioned card drivers control the master clock themselves and
don't call the set_dai_sysclk() or set_dai_pll(), thus the respective
handlers don't serve any purpose anymore. Instead, they return early and
the hw_params() handler sets the appropriate bitclk itself.

The register range is split into two -- for the RX block and for the TX
block. On a MMP2 there are two pairs of them; the first one has the
clock controller in the middle, while the second just has a hole:

  0xd42a0c00 - 0xd42a0c30 RX1
  0xd42a0c30 - 0xd42a0c40 Clocks
  0xd42a0c80 - 0xd42a0cb0 TX1
  0xd42a0d00 - 0xd42a0d30 RX2
  0xd42a0d80 - 0xd42a0cb0 TX2

For this reason, mmp_sspa_write_reg() and mmp_sspa_read_reg() are
replaced with direct calls to I/O routines.

Tested on a MMP2-based OLPC XO-1.75 laptop with rt5631 coded, mmp_tdma DMA
engine and MMP2 clock controller glued together with audio-graph-card.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 sound/soc/pxa/Kconfig    |  20 +++---
 sound/soc/pxa/mmp-sspa.c | 139 ++++++++++++++++++++++++++-------------
 sound/soc/pxa/mmp-sspa.h |  28 +++-----
 3 files changed, 113 insertions(+), 74 deletions(-)

diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index d4c0f580a565..7ad2fd7e653b 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -9,14 +9,8 @@ config SND_PXA2XX_SOC
 	  to select the audio interfaces to support below.
 
 config SND_MMP_SOC
-	bool "Soc Audio for Marvell MMP chips"
-	depends on ARCH_MMP
+	bool
 	select MMP_SRAM
-	select SND_SOC_GENERIC_DMAENGINE_PCM
-	select SND_ARM
-	help
-	  Say Y if you want to add support for codecs attached to
-	  the MMP SSPA interface.
 
 config SND_PXA2XX_AC97
 	tristate
@@ -39,7 +33,13 @@ config SND_PXA_SOC_SSP
 	select SND_PXA2XX_LIB
 
 config SND_MMP_SOC_SSPA
-	tristate
+	tristate "SoC Audio via MMP SSPA ports"
+	depends on ARCH_MMP
+	select SND_SOC_GENERIC_DMAENGINE_PCM
+	select SND_ARM
+	help
+	  Say Y if you want to add support for codecs attached to
+	  the MMP SSPA interface.
 
 config SND_PXA2XX_SOC_CORGI
 	tristate "SoC Audio support for Sharp Zaurus SL-C7x0"
@@ -232,8 +232,8 @@ config SND_PXA2XX_SOC_IMOTE2
 
 config SND_MMP_SOC_BROWNSTONE
 	tristate "SoC Audio support for Marvell Brownstone"
-	depends on SND_MMP_SOC && MACH_BROWNSTONE && I2C
-	select SND_MMP_SOC_SSPA
+	depends on SND_MMP_SOC_SSPA && MACH_BROWNSTONE && I2C
+	select SND_MMP_SOC
 	select MFD_WM8994
 	select SND_SOC_WM8994
 	help
diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 86277471974a..b0accd49c89d 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -28,27 +28,20 @@
  * SSPA audio private data
  */
 struct sspa_priv {
-	void __iomem *mmio_base;
+	void __iomem *tx_base;
+	void __iomem *rx_base;
+
 	struct snd_dmaengine_dai_dma_data playback_dma_data;
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
 	struct clk *clk;
 	struct clk *audio_clk;
 	struct clk *sysclk;
+
 	int running_cnt;
 	u32 sp;
 	u32 ctrl;
 };
 
-static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val)
-{
-	__raw_writel(val, sspa->mmio_base + reg);
-}
-
-static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg)
-{
-	return __raw_readl(sspa->mmio_base + reg);
-}
-
 static void mmp_sspa_tx_enable(struct sspa_priv *sspa)
 {
 	unsigned int sspa_sp = sspa->sp;
@@ -56,7 +49,7 @@ static void mmp_sspa_tx_enable(struct sspa_priv *sspa)
 	sspa_sp &= ~SSPA_SP_MSL;
 	sspa_sp |= SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
+	__raw_writel(sspa_sp, sspa->tx_base + SSPA_SP);
 }
 
 static void mmp_sspa_tx_disable(struct sspa_priv *sspa)
@@ -66,7 +59,7 @@ static void mmp_sspa_tx_disable(struct sspa_priv *sspa)
 	sspa_sp &= ~SSPA_SP_MSL;
 	sspa_sp &= ~SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp);
+	__raw_writel(sspa_sp, sspa->tx_base + SSPA_SP);
 }
 
 static void mmp_sspa_rx_enable(struct sspa_priv *sspa)
@@ -75,7 +68,7 @@ static void mmp_sspa_rx_enable(struct sspa_priv *sspa)
 
 	sspa_sp |= SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
+	__raw_writel(sspa_sp, sspa->rx_base + SSPA_SP);
 }
 
 static void mmp_sspa_rx_disable(struct sspa_priv *sspa)
@@ -84,7 +77,7 @@ static void mmp_sspa_rx_disable(struct sspa_priv *sspa)
 
 	sspa_sp &= ~SSPA_SP_S_EN;
 	sspa_sp |= SSPA_SP_WEN;
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp);
+	__raw_writel(sspa_sp, sspa->rx_base + SSPA_SP);
 }
 
 static int mmp_sspa_startup(struct snd_pcm_substream *substream,
@@ -105,7 +98,6 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream,
 
 	clk_disable_unprepare(sspa->clk);
 	clk_disable_unprepare(sspa->sysclk);
-
 }
 
 /*
@@ -115,8 +107,12 @@ static int mmp_sspa_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
 				    int clk_id, unsigned int freq, int dir)
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
+	struct device *dev = cpu_dai->component->dev;
 	int ret = 0;
 
+	if (dev->of_node)
+		return -ENOTSUPP;
+
 	switch (clk_id) {
 	case MMP_SSPA_CLK_AUDIO:
 		ret = clk_set_rate(sspa->audio_clk, freq);
@@ -139,8 +135,12 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
 				 unsigned int freq_out)
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai);
+	struct device *dev = cpu_dai->component->dev;
 	int ret = 0;
 
+	if (dev->of_node)
+		return -ENOTSUPP;
+
 	switch (pll_id) {
 	case MMP_SYSCLK:
 		ret = clk_set_rate(sspa->sysclk, freq_out);
@@ -213,6 +213,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 			       struct snd_soc_dai *dai)
 {
 	struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai);
+	struct device *dev = dai->component->dev;
 	u32 sspa_ctrl = sspa->ctrl;
 	int bits;
 	int bitval;
@@ -238,7 +239,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
-	if (params_channels(params) == 2)
+	if (dev->of_node || params_channels(params) == 2)
 		sspa_ctrl |= SSPA_CTL_XPH;
 
 	sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK;
@@ -256,12 +257,17 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream,
 	sspa->sp &= ~SSPA_TXSP_FPER_MASK;
 	sspa->sp |= SSPA_TXSP_FPER(bits * 2 - 1);
 
+	if (dev->of_node) {
+		clk_set_rate(sspa->clk, params_rate(params) *
+					params_channels(params) * bits);
+	}
+
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl);
-		mmp_sspa_write_reg(sspa, SSPA_TXFIFO_LL, 0x1);
+		__raw_writel(sspa_ctrl, sspa->tx_base + SSPA_CTL);
+		__raw_writel(0x1, sspa->tx_base + SSPA_FIFO_UL);
 	} else {
-		mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa_ctrl);
-		mmp_sspa_write_reg(sspa, SSPA_RXFIFO_UL, 0x0);
+		__raw_writel(sspa_ctrl, sspa->rx_base + SSPA_CTL);
+		__raw_writel(0x0, sspa->rx_base + SSPA_FIFO_UL);
 	}
 
 	return 0;
@@ -410,19 +416,19 @@ static int mmp_sspa_open(struct snd_soc_component *component,
 	pm_runtime_get_sync(component->dev);
 
 	/* we can only change the settings if the port is not in use */
-	if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) ||
-	    (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) {
+	if ((__raw_readl(sspa->tx_base + SSPA_SP) & SSPA_SP_S_EN) ||
+	    (__raw_readl(sspa->rx_base + SSPA_SP) & SSPA_SP_S_EN)) {
 		dev_err(component->dev,
 			"can't change hardware dai format: stream is in use\n");
 		return -EBUSY;
 	}
 
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp);
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp);
+	__raw_writel(sspa->sp, sspa->tx_base + SSPA_SP);
+	__raw_writel(sspa->sp, sspa->rx_base + SSPA_SP);
 
 	sspa->sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH);
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp);
-	mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp);
+	__raw_writel(sspa->sp, sspa->tx_base + SSPA_SP);
+	__raw_writel(sspa->sp, sspa->rx_base + SSPA_SP);
 
 	/*
 	 * FIXME: hw issue, for the tx serial port,
@@ -431,10 +437,10 @@ static int mmp_sspa_open(struct snd_soc_component *component,
 	 * The master/slave mode has been set in the
 	 * rx port.
 	 */
-	mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp & ~SSPA_SP_MSL);
+	__raw_writel(sspa->sp & ~SSPA_SP_MSL, sspa->tx_base + SSPA_SP);
 
-	mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa->ctrl);
-	mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa->ctrl);
+	__raw_writel(sspa->ctrl, sspa->tx_base + SSPA_CTL);
+	__raw_writel(sspa->ctrl, sspa->rx_base + SSPA_CTL);
 
 	return 0;
 }
@@ -462,22 +468,51 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 	if (!sspa)
 		return -ENOMEM;
 
-	sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(sspa->mmio_base))
-		return PTR_ERR(sspa->mmio_base);
+	if (pdev->dev.of_node) {
+		sspa->rx_base = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(sspa->rx_base))
+			return PTR_ERR(sspa->rx_base);
 
-	sspa->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(sspa->clk))
-		return PTR_ERR(sspa->clk);
+		sspa->tx_base = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(sspa->tx_base))
+			return PTR_ERR(sspa->tx_base);
 
-	sspa->audio_clk = clk_get(NULL, "mmp-audio");
-	if (IS_ERR(sspa->audio_clk))
-		return PTR_ERR(sspa->audio_clk);
+		sspa->clk = devm_clk_get(&pdev->dev, "bitclk");
+		if (IS_ERR(sspa->clk))
+			return PTR_ERR(sspa->clk);
 
-	sspa->sysclk = clk_get(NULL, "mmp-sysclk");
-	if (IS_ERR(sspa->sysclk)) {
-		clk_put(sspa->audio_clk);
-		return PTR_ERR(sspa->sysclk);
+		sspa->audio_clk = devm_clk_get(&pdev->dev, "audio");
+		if (IS_ERR(sspa->audio_clk))
+			return PTR_ERR(sspa->audio_clk);
+	} else {
+		struct resource *res;
+
+		res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+		if (res == NULL)
+			return -ENODEV;
+
+		sspa->rx_base = devm_ioremap(&pdev->dev, res->start, 0x30);
+		if (IS_ERR(sspa->rx_base))
+			return PTR_ERR(sspa->rx_base);
+
+		sspa->tx_base = devm_ioremap(&pdev->dev,
+					     res->start + 0x80, 0x30);
+		if (IS_ERR(sspa->tx_base))
+			return PTR_ERR(sspa->tx_base);
+
+		sspa->clk = devm_clk_get(&pdev->dev, NULL);
+		if (IS_ERR(sspa->clk))
+			return PTR_ERR(sspa->clk);
+
+		sspa->audio_clk = clk_get(NULL, "mmp-audio");
+		if (IS_ERR(sspa->audio_clk))
+			return PTR_ERR(sspa->audio_clk);
+
+		sspa->sysclk = clk_get(NULL, "mmp-sysclk");
+		if (IS_ERR(sspa->sysclk)) {
+			clk_put(sspa->audio_clk);
+			return PTR_ERR(sspa->sysclk);
+		}
 	}
 	pm_runtime_enable(&pdev->dev);
 	clk_prepare_enable(sspa->audio_clk);
@@ -486,8 +521,8 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
 	sspa->playback_dma_data.maxburst = 4;
 	sspa->capture_dma_data.maxburst = 4;
 	/* You know, these addresses are actually ignored. */
-	sspa->playback_dma_data.addr = SSPA_TXD;
-	sspa->capture_dma_data.addr = SSPA_RXD;
+	sspa->capture_dma_data.addr = SSPA_D;
+	sspa->playback_dma_data.addr = 0x80 + SSPA_D;
 
 	if (pdev->dev.of_node) {
 		int ret;
@@ -508,14 +543,28 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(sspa->audio_clk);
 	pm_runtime_disable(&pdev->dev);
+
+	if (pdev->dev.of_node)
+		return 0;
+
 	clk_put(sspa->audio_clk);
 	clk_put(sspa->sysclk);
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id mmp_sspa_of_match[] = {
+	{ .compatible = "marvell,mmp-sspa" },
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, mmp_sspa_of_match);
+#endif
+
 static struct platform_driver asoc_mmp_sspa_driver = {
 	.driver = {
 		.name = "mmp-sspa-dai",
+		.of_match_table = of_match_ptr(mmp_sspa_of_match),
 	},
 	.probe = asoc_mmp_sspa_probe,
 	.remove = asoc_mmp_sspa_remove,
diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h
index 328969b57ad1..938ef2f667e3 100644
--- a/sound/soc/pxa/mmp-sspa.h
+++ b/sound/soc/pxa/mmp-sspa.h
@@ -10,25 +10,15 @@
 /*
  * SSPA Registers
  */
-#define SSPA_RXD		(0x00)
-#define SSPA_RXID		(0x04)
-#define SSPA_RXCTL		(0x08)
-#define SSPA_RXSP		(0x0c)
-#define SSPA_RXFIFO_UL		(0x10)
-#define SSPA_RXINT_MASK		(0x14)
-#define SSPA_RXC		(0x18)
-#define SSPA_RXFIFO_NOFS	(0x1c)
-#define SSPA_RXFIFO_SIZE	(0x20)
-
-#define SSPA_TXD		(0x80)
-#define SSPA_TXID		(0x84)
-#define SSPA_TXCTL		(0x88)
-#define SSPA_TXSP		(0x8c)
-#define SSPA_TXFIFO_LL		(0x90)
-#define SSPA_TXINT_MASK		(0x94)
-#define SSPA_TXC		(0x98)
-#define SSPA_TXFIFO_NOFS	(0x9c)
-#define SSPA_TXFIFO_SIZE	(0xa0)
+#define SSPA_D			(0x00)
+#define SSPA_ID			(0x04)
+#define SSPA_CTL		(0x08)
+#define SSPA_SP			(0x0c)
+#define SSPA_FIFO_UL		(0x10)
+#define SSPA_INT_MASK		(0x14)
+#define SSPA_C			(0x18)
+#define SSPA_FIFO_NOFS		(0x1c)
+#define SSPA_FIFO_SIZE		(0x20)
 
 /* SSPA Control Register */
 #define	SSPA_CTL_XPH		(1 << 31)	/* Read Phase */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks
  2020-05-11 21:01 ` [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks Lubomir Rintel
@ 2020-05-12 12:45   ` Mark Brown
  2020-05-12 15:36     ` Lubomir Rintel
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2020-05-12 12:45 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: Liam Girdwood, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

On Mon, May 11, 2020 at 11:01:30PM +0200, Lubomir Rintel wrote:
> The driver enables the clocks without preparing them and disables
> without unpreparing afterwards. Fix that.

This fix should've been earlier in the series so it could be sent as a
fix.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks
  2020-05-12 12:45   ` Mark Brown
@ 2020-05-12 15:36     ` Lubomir Rintel
  2020-05-12 16:29       ` Mark Brown
  0 siblings, 1 reply; 18+ messages in thread
From: Lubomir Rintel @ 2020-05-12 15:36 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media

On Tue, May 12, 2020 at 01:45:20PM +0100, Mark Brown wrote:
> On Mon, May 11, 2020 at 11:01:30PM +0200, Lubomir Rintel wrote:
> > The driver enables the clocks without preparing them and disables
> > without unpreparing afterwards. Fix that.
> 
> This fix should've been earlier in the series so it could be sent as a
> fix.

I'll order it earlier on v2.

However, there's not much of a point in picking this patch alone,
because the driver is certainly not used anywhere and very likely
doesn't even work to any sensible extent without the rest of the
series.

Lubo

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks
  2020-05-12 15:36     ` Lubomir Rintel
@ 2020-05-12 16:29       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2020-05-12 16:29 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: Liam Girdwood, Michael Turquette, Stephen Boyd, Rob Herring,
	linux-clk, devicetree, linux-kernel, linux-media

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

On Tue, May 12, 2020 at 05:36:54PM +0200, Lubomir Rintel wrote:
> On Tue, May 12, 2020 at 01:45:20PM +0100, Mark Brown wrote:

> > This fix should've been earlier in the series so it could be sent as a
> > fix.

> I'll order it earlier on v2.

> However, there's not much of a point in picking this patch alone,
> because the driver is certainly not used anywhere and very likely
> doesn't even work to any sensible extent without the rest of the
> series.

Well, I've already applied everything except the DT patches for that
reason - it's just worth pointing out for future reference.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on
  2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
@ 2020-05-12 16:45   ` Mark Brown
  2020-05-19 19:52   ` Mark Brown
  1 sibling, 0 replies; 18+ messages in thread
From: Mark Brown @ 2020-05-12 16:45 UTC (permalink / raw)
  To: Liam Girdwood, Lubomir Rintel
  Cc: Rob Herring, Michael Turquette, devicetree, Stephen Boyd,
	linux-kernel, linux-media, linux-clk

On Mon, 11 May 2020 23:01:24 +0200, Lubomir Rintel wrote:
> The hw_params() callback handles the 3-byte format, not
> SNDRV_PCM_FMTBIT_S24_LE.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.8

Thanks!

[1/7] ASoC: mmp-sspa: A trivial typo fix
      commit: e0b9024d2c8851b18b953823204278602bf73086
[2/7] ASoC: mmp-sspa: Get rid of dma_params and phys_base
      commit: c9aeda1c94973f835b3d1b6c785a414caaf935c3
[3/7] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm
      commit: 724da05378ba7af6e273451a2c3f565a3315a9db
[4/7] ASoC: mmp-sspa: Remove the embedded struct ssp_device
      commit: 3c4e89df3b45348dc0ee01a2ef1be710f7424ff7
[5/7] ASoC: mmp-sspa: Prepare/unprepare the clocks
      commit: 8ecdcac8792b6787ecb2341d25cb82165cf0129d
[6/7] ASoC: mmp-sspa: Add support for the runtime power management
      commit: 7d98cc648253c362ebfc582b11095a0e3f001896
[7/7] ASoC: mmp-sspa: Set appropriate bus format for given bit width
      commit: 39ec7e9b699910792468cf41a179d9930052e8ff

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding
  2020-05-11 21:01 ` [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding Lubomir Rintel
@ 2020-05-19 18:37   ` Rob Herring
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2020-05-19 18:37 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: Liam Girdwood, Mark Brown, devicetree, Michael Turquette,
	Rob Herring, linux-media, linux-clk, linux-kernel, Stephen Boyd

On Mon, 11 May 2020 23:01:33 +0200, Lubomir Rintel wrote:
> Add binding documentation for the audio serial port interface (I2S) on
> Marvell MMP SoCs.
> 
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> ---
>  .../bindings/sound/marvell,mmp-sspa.yaml      | 122 ++++++++++++++++++
>  1 file changed, 122 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on
  2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
  2020-05-12 16:45   ` Mark Brown
@ 2020-05-19 19:52   ` Mark Brown
  1 sibling, 0 replies; 18+ messages in thread
From: Mark Brown @ 2020-05-19 19:52 UTC (permalink / raw)
  To: Liam Girdwood, Lubomir Rintel
  Cc: Michael Turquette, linux-kernel, linux-clk, Stephen Boyd,
	Rob Herring, linux-media, devicetree

On Mon, 11 May 2020 23:01:24 +0200, Lubomir Rintel wrote:
> The hw_params() callback handles the 3-byte format, not
> SNDRV_PCM_FMTBIT_S24_LE.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.8

Thanks!

[1/2] ASoC: Add Marvell MMP SSPA binding
      commit: d81bb8726c247c3e7719d21bf213c5400de29e03
[2/2] ASoC: mmp-sspa: Add Device Tree support
      commit: a97e384ba78fd8bf7ba8c32718424d8a7536416e

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-05-19 19:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 21:01 [PATCH 00/11] Make sound work on DT-based MMP2 machines Lubomir Rintel
2020-05-11 21:01 ` [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Lubomir Rintel
2020-05-12 16:45   ` Mark Brown
2020-05-19 19:52   ` Mark Brown
2020-05-11 21:01 ` [PATCH 02/11] ASoC: mmp-sspa: Drop S20_3LE case Lubomir Rintel
2020-05-11 21:01 ` [PATCH 03/11] ASoC: mmp-sspa: A trivial typo fix Lubomir Rintel
2020-05-11 21:01 ` [PATCH 04/11] ASoC: mmp-sspa: Get rid of dma_params and phys_base Lubomir Rintel
2020-05-11 21:01 ` [PATCH 05/11] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm Lubomir Rintel
2020-05-11 21:01 ` [PATCH 06/11] ASoC: mmp-sspa: Remove the embedded struct ssp_device Lubomir Rintel
2020-05-11 21:01 ` [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks Lubomir Rintel
2020-05-12 12:45   ` Mark Brown
2020-05-12 15:36     ` Lubomir Rintel
2020-05-12 16:29       ` Mark Brown
2020-05-11 21:01 ` [PATCH 08/11] ASoC: mmp-sspa: Add support for the runtime power management Lubomir Rintel
2020-05-11 21:01 ` [PATCH 09/11] ASoC: mmp-sspa: Set appropriate bus format for given bit width Lubomir Rintel
2020-05-11 21:01 ` [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding Lubomir Rintel
2020-05-19 18:37   ` Rob Herring
2020-05-11 21:01 ` [PATCH 11/11] ASoC: mmp-sspa: Add Device Tree support Lubomir Rintel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).