[alsa-devel] [PATCH v3 00/15] ASoC: fsl-ssi: ac97-slave support
Hi,
This series adds DT support for phycore-ac97. It is now based on the pcm dma cleanups from Lars. Beside ac97 support, the series adds fsl-ssi imx-pcm-fiq and generic DMA binding handling.
@Lars: There are 4 new patches at the beginning of the series that fix some problems of your cleanups. I think they were in the changes you posted. If not, could you please add them to your branch?
Regards,
Markus
Changes in v3: - Rebased onto pcm dma cleanup patches - A lot of cleanups for the fsl-ssi ac97 integration - Some small changes which are listed in the notes of the patches.
Markus Pargmann (15): ASoC: imx-ssi: Fix includes ASoC: dmaengine-pcm: Replace of specific helper function ASoC: dmaengine-pcm: Fix function name ASoC: dmaengine-pcm: Fix pcm_request_chan function name ASoC: phycore-ac97: Add DT support ASoC: imx-pcm-dma: DT support ASoC: imx-pcm-fiq: Introduce pcm-fiq-params ASoC: fsl-ssi: Add SACNT definitions ASoC: fsl-ssi: Add support for imx-pcm-fiq ASoC: fsl-ssi: Use generic DMA bindings if possible ARM: imx: Export ac97 reset functions ASoC: fsl-ssi: imx ac97 support ASoC: fsl: Kconfig: Use fsl-ssi for phycore-ac97 ASoC: fsl: Move fsl-ssi binding doc to sound/ ASoC: fsl: Update fsl-ssi binding doc
Documentation/devicetree/bindings/{powerpc/fsl/ssi.txt => sound/fsl,ssi.txt} | 7 + Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt | 12 ++ arch/arm/mach-imx/mach-pca100.c | 7 +- arch/arm/mach-imx/mach-pcm043.c | 7 +- include/sound/dmaengine_pcm.h | 2 +- sound/soc/fsl/Kconfig | 2 +- sound/soc/fsl/fsl_ssi.c | 484 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- sound/soc/fsl/fsl_ssi.h | 8 ++ sound/soc/fsl/imx-pcm-dma.c | 4 +- sound/soc/fsl/imx-pcm-fiq.c | 16 ++- sound/soc/fsl/imx-pcm.h | 9 ++ sound/soc/fsl/imx-ssi.c | 7 +- sound/soc/fsl/imx-ssi.h | 2 + sound/soc/fsl/phycore-ac97.c | 184 +++++++++++++++++++++++---- sound/soc/soc-generic-dmaengine-pcm.c | 9 +- sound/soc/spear/spear_pcm.c | 2 +- 16 files changed, 634 insertions(+), 128 deletions(-) rename Documentation/devicetree/bindings/{powerpc/fsl/ssi.txt => sound/fsl,ssi.txt} (92%) create mode 100644 Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt
From: Markus Pargmann mpa@pengutrnoix.de
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/fsl/imx-ssi.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/sound/soc/fsl/imx-ssi.h b/sound/soc/fsl/imx-ssi.h index d8063c2..bb6b3db 100644 --- a/sound/soc/fsl/imx-ssi.h +++ b/sound/soc/fsl/imx-ssi.h @@ -187,6 +187,7 @@
#include <linux/dmaengine.h> #include <linux/platform_data/dma-imx.h> +#include <sound/dmaengine_pcm.h> #include "imx-pcm.h"
struct imx_ssi {
From: Markus Pargmann mpa@pengutrnoix.de
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/soc-generic-dmaengine-pcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index d5467ff..2e25402 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -221,9 +221,9 @@ int snd_dmaengine_pcm_register(struct device *dev, if (flags & SND_DMAENGINE_PCM_FLAG_COMPAT) pcm->compat = true;
- if (!(flags & SND_DMAENGINE_PCM_FLAG_NO_DT) && dev->of_node) { + if (!(flags & SND_DMAENGINE_PCM_FLAG_NO_DT)) { for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) { - pcm->chan[i] = of_dma_request_slave_channel(dev->of_node, + pcm->chan[i] = dma_request_slave_channel(dev, dmaengine_pcm_dma_channel_names[i]); } }
From: Markus Pargmann mpa@pengutrnoix.de
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/soc-generic-dmaengine-pcm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index 2e25402..f752577 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -50,7 +50,8 @@ int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream, if (ret) return ret;
- snd_dmaengine_set_config_from_dai_data(substream, dma_data, slave_config); + snd_dmaengine_pcm_set_config_from_dai_data(substream, dma_data, + slave_config);
return 0; }
From: Markus Pargmann mpa@pengutrnoix.de
dmaengine_pcm.c implements snd_dmaengine_pcm_request_channel. This function fixes all function calls to the shorter snd_dmaengine_pcm_request_chan.
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- include/sound/dmaengine_pcm.h | 2 +- sound/soc/soc-generic-dmaengine-pcm.c | 2 +- sound/soc/spear/spear_pcm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h index b346098..b7dbec0 100644 --- a/include/sound/dmaengine_pcm.h +++ b/include/sound/dmaengine_pcm.h @@ -47,7 +47,7 @@ int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, dma_filter_fn filter_fn, void *filter_data); int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream);
-struct dma_chan *snd_dmaengine_pcm_request_chan(dma_filter_fn filter_fn, +struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn, void *filter_data); struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream);
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index f752577..9480087 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -117,7 +117,7 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel( if (pcm->config->compat_request_channel) return pcm->config->compat_request_channel(rtd, substream);
- return snd_dmaengine_pcm_request_chan(pcm->config->compat_filter_fn, + return snd_dmaengine_pcm_request_channel(pcm->config->compat_filter_fn, snd_soc_dai_get_dma_data(rtd->cpu_dai, substream)); }
diff --git a/sound/soc/spear/spear_pcm.c b/sound/soc/spear/spear_pcm.c index a8222ae..10fc7c9 100644 --- a/sound/soc/spear/spear_pcm.c +++ b/sound/soc/spear/spear_pcm.c @@ -38,7 +38,7 @@ static struct dma_chan *spear_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
- return snd_dmaengine_pcm_request_chan(dma_data->filter, dma_data); + return snd_dmaengine_pcm_request_channel(dma_data->filter, dma_data); }
static const struct snd_dmaengine_pcm_config spear_dmaengine_pcm_config = {
Add devicetree support for this audio soc fabric driver.
DT initialized drivers do not have real device ids, so imx-pcm-fiq-audio.0 is used without '.0'.
This patch also simplifies the way audmux ports are configured. Before there was knowledge about the used board. As the audmux driver knows the used board, we know use the returned errorcodes to correctly set the audmux port. So this driver does not have to know which board it is running on.
Signed-off-by: Markus Pargmann mpa@pengutronix.de ---
Notes: Changes in v3: - Add some more information in the commit message.
Changes in v2: - Simplify the driver, by combining audmux port configurations. The audmux driver actually knows on which platform he is running and will return the appropriate error code if we use functions for another platform. So we don't need to have the knowledge about it in phycore-ac97 and can try both functions. This removes the need of different compatibilities and renames it to phycore-ac97. - Use a phandle for the cpu_dai link. - Add devicetree binding documentation. - Rename binding to phytec,phycore-ac97 and fsl,ssi to phytec,ssi
Changes in v2: - Simplify the driver, by combining audmux port configurations. The audmux driver actually knows on which platform he is running and will return the appropriate error code if we use functions for another platform. So we don't need to have the knowledge about it in phycore-ac97 and can try both functions. This removes the need of different compatibilities and renames it to imx27-ac97. - Use a phandle for the cpu_dai link. - Add devicetree binding documentation. - Rename binding to phytec,phycore-ac97 and fsl,ssi to phytec,ssi
.../bindings/sound/phytec,phycore-ac97.txt | 12 ++ sound/soc/fsl/phycore-ac97.c | 184 ++++++++++++++++++--- 2 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt
diff --git a/Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt b/Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt new file mode 100644 index 0000000..e04221d --- /dev/null +++ b/Documentation/devicetree/bindings/sound/phytec,phycore-ac97.txt @@ -0,0 +1,12 @@ +Phytec phycore AC97 + +Required properties: +- compatible: "phytec,phycore-ac97" +- phytec,ssi: A phandle to the ssi device that is connected to ac97. + +Example: + +sound { + compatible = "phytec,phycore-ac97"; + phytec,ssi = <&ssi1>; +}; diff --git a/sound/soc/fsl/phycore-ac97.c b/sound/soc/fsl/phycore-ac97.c index f8da6dd..cebd93f 100644 --- a/sound/soc/fsl/phycore-ac97.c +++ b/sound/soc/fsl/phycore-ac97.c @@ -21,7 +21,10 @@
#include "imx-audmux.h"
+#define DRV_NAME "phycore-audio-fabric" + static struct snd_soc_card imx_phycore; +static struct device_node *phycore_dai_cpu_node;
static struct snd_soc_ops imx_phycore_hifi_ops = { }; @@ -32,8 +35,12 @@ static struct snd_soc_dai_link imx_phycore_dai_ac97[] = { .stream_name = "HiFi", .codec_dai_name = "wm9712-hifi", .codec_name = "wm9712-codec", +#ifdef CONFIG_MACH_IMX27_DT + .platform_name = "imx-fiq-pcm-audio", +#else .cpu_dai_name = "imx-ssi.0", .platform_name = "imx-fiq-pcm-audio.0", +#endif .ops = &imx_phycore_hifi_ops, }, }; @@ -45,35 +52,78 @@ static struct snd_soc_card imx_phycore = { .num_links = ARRAY_SIZE(imx_phycore_dai_ac97), };
-static struct platform_device *imx_phycore_snd_ac97_device; +static int phycore_ac97_pca100_audmux(void) +{ + int ret; + + ret = imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, + IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */ + IMX_AUDMUX_V1_PCR_TFCSEL(3) | + IMX_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */ + IMX_AUDMUX_V1_PCR_RXDSEL(3)); + if (ret) + return ret; + + ret = imx_audmux_v1_configure_port(3, + IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */ + IMX_AUDMUX_V1_PCR_TFCSEL(0) | + IMX_AUDMUX_V1_PCR_TFSDIR | + IMX_AUDMUX_V1_PCR_RXDSEL(0)); + return ret; +} + +static int phycore_ac97_pcm043_audmux(void) +{ + int ret; + + ret = imx_audmux_v2_configure_port(3, + IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */ + IMX_AUDMUX_V2_PTCR_TFSEL(0) | + IMX_AUDMUX_V2_PTCR_TFSDIR, + IMX_AUDMUX_V2_PDCR_RXDSEL(0)); + if (ret) + return ret; + + ret = imx_audmux_v2_configure_port(0, + IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */ + IMX_AUDMUX_V2_PTCR_TCSEL(3) | + IMX_AUDMUX_V2_PTCR_TCLKDIR, /* clock is output */ + IMX_AUDMUX_V2_PDCR_RXDSEL(3)); + return ret; +} + +static __maybe_unused int phycore_ac97_init_audmux(void) +{ + int ret; + + /* + * This driver doesn't need to know which actual hardware is used. + * The audmux driver has knowledge about it's type, and returns + * an error if executed on the wrong type of hardware. + */ + ret = phycore_ac97_pca100_audmux(); + if (!ret) + return 0; + + ret = phycore_ac97_pcm043_audmux(); + + return ret; +} + static struct platform_device *imx_phycore_snd_device;
+#ifndef CONFIG_MACH_IMX27_DT + +static struct platform_device *imx_phycore_snd_ac97_device; + static int __init imx_phycore_init(void) { int ret;
if (machine_is_pca100()) { - imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, - IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */ - IMX_AUDMUX_V1_PCR_TFCSEL(3) | - IMX_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */ - IMX_AUDMUX_V1_PCR_RXDSEL(3)); - imx_audmux_v1_configure_port(3, - IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */ - IMX_AUDMUX_V1_PCR_TFCSEL(0) | - IMX_AUDMUX_V1_PCR_TFSDIR | - IMX_AUDMUX_V1_PCR_RXDSEL(0)); + phycore_ac97_pca100_audmux(); } else if (machine_is_pcm043()) { - imx_audmux_v2_configure_port(3, - IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */ - IMX_AUDMUX_V2_PTCR_TFSEL(0) | - IMX_AUDMUX_V2_PTCR_TFSDIR, - IMX_AUDMUX_V2_PDCR_RXDSEL(0)); - imx_audmux_v2_configure_port(0, - IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */ - IMX_AUDMUX_V2_PTCR_TCSEL(3) | - IMX_AUDMUX_V2_PTCR_TCLKDIR, /* clock is output */ - IMX_AUDMUX_V2_PDCR_RXDSEL(3)); + phycore_ac97_pcm043_audmux(); } else { /* return happy. We might run on a totally different machine */ return 0; @@ -120,6 +170,96 @@ static void __exit imx_phycore_exit(void) late_initcall(imx_phycore_init); module_exit(imx_phycore_exit);
+#else /* !CONFIG_MACH_IMX27_DT */ + +static const struct of_device_id imx_phycore_ac97_of_dev_id[] = { + { + .compatible = "phytec,phycore-ac97", + }, { + /* sentinel */ + } +}; +MODULE_DEVICE_TABLE(of, imx_phycore_ac97_of_dev_id); + +static int phycore_ac97_setup_devices(struct platform_device *pdev) +{ + int ret; + + imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1); + if (!imx_phycore_snd_device) + return -ENOMEM; + + ret = platform_device_add(imx_phycore_snd_device); + if (ret) { + dev_err(&pdev->dev, "ASoC: Platform device allocation failed\n"); + goto fail1; + } + + ret = snd_soc_register_card(&imx_phycore); + if (ret) { + dev_err(&pdev->dev, "ASoC: soc card registration failed\n"); + goto fail2; + } + return 0; + +fail2: + platform_device_del(imx_phycore_snd_device); +fail1: + platform_device_put(imx_phycore_snd_device); + return ret; +} + +static int imx_phycore_ac97_probe(struct platform_device *pdev) +{ + int ret; + struct device_node *ssi_np; + + imx_phycore.dev = &pdev->dev; + + ret = phycore_ac97_init_audmux(); + if (ret) { + dev_err(&pdev->dev, "Failed to initialize audmux\n"); + return ret; + } + + ssi_np = of_parse_phandle(pdev->dev.of_node, "phytec,ssi", 0); + if (!ssi_np) { + dev_err(&pdev->dev, "No valid ssi phandle found\n"); + return -EINVAL; + } + + imx_phycore_dai_ac97[0].cpu_of_node = ssi_np; + phycore_dai_cpu_node = ssi_np; + + + ret = phycore_ac97_setup_devices(pdev); + if (ret) + of_node_put(phycore_dai_cpu_node); + + return ret; +} + +static int imx_phycore_ac97_remove(struct platform_device *pdev) +{ + of_node_put(phycore_dai_cpu_node); + platform_device_unregister(imx_phycore_snd_device); + return 0; +} + +static struct platform_driver imx_phycore_ac97_driver = { + .probe = imx_phycore_ac97_probe, + .remove = imx_phycore_ac97_remove, + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + .of_match_table = imx_phycore_ac97_of_dev_id, + }, +}; + +module_platform_driver(imx_phycore_ac97_driver); + +#endif /* CONFIG_MACH_IMX27_DT */ + MODULE_AUTHOR("Sascha Hauer s.hauer@pengutronix.de"); -MODULE_DESCRIPTION("PhyCORE ALSA SoC driver"); +MODULE_DESCRIPTION(DRV_NAME ": PhyCORE ALSA SoC fabric driver"); MODULE_LICENSE("GPL");
On Sun, Apr 14, 2013 at 01:42:49PM +0200, Markus Pargmann wrote:
- /*
* This driver doesn't need to know which actual hardware is used.
* The audmux driver has knowledge about it's type, and returns
* an error if executed on the wrong type of hardware.
*/
- ret = phycore_ac97_pca100_audmux();
- if (!ret)
return 0;
- ret = phycore_ac97_pcm043_audmux();
The DT really ought to be able to give enough information to figure out the audmux configuration. If we can't do that it rather defeats the point of moving to DT...
On Tue, Apr 16, 2013 at 12:59:43PM +0100, Mark Brown wrote:
On Sun, Apr 14, 2013 at 01:42:49PM +0200, Markus Pargmann wrote:
- /*
* This driver doesn't need to know which actual hardware is used.
* The audmux driver has knowledge about it's type, and returns
* an error if executed on the wrong type of hardware.
*/
- ret = phycore_ac97_pca100_audmux();
- if (!ret)
return 0;
- ret = phycore_ac97_pcm043_audmux();
The DT really ought to be able to give enough information to figure out the audmux configuration. If we can't do that it rather defeats the point of moving to DT...
Yes you are right, I added a phandle "phytec,audmux" to check which audmux setup function we have to use.
Regards,
Markus
From: Markus Pargmann mpa@pengutrnoix.de
This patch adds the possibility to pass a of_node as platform_data which is used by generic-pcm-dma to request a DMA slave channel.
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/fsl/imx-pcm-dma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c index 9eb0021..a6cdae7 100644 --- a/sound/soc/fsl/imx-pcm-dma.c +++ b/sound/soc/fsl/imx-pcm-dma.c @@ -62,9 +62,11 @@ static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = {
int imx_pcm_dma_init(struct platform_device *pdev) { + if (pdev->dev.platform_data) + pdev->dev.of_node = pdev->dev.platform_data; + return snd_dmaengine_pcm_register(&pdev->dev, &imx_dmaengine_pcm_config, SND_DMAENGINE_PCM_FLAG_NO_RESIDUE | - SND_DMAENGINE_PCM_FLAG_NO_DT | SND_DMAENGINE_PCM_FLAG_COMPAT); }
Cleaner parameter passing for imx-pcm-fiq. Create a seperated fiq-params struct to pass all arguments.
Signed-off-by: Markus Pargmann mpa@pengutronix.de ---
Notes: Changes in v3: - Using snd_dmaengine_dai_dma_data for dma_params after rebasing onto dmaengine cleanups.
sound/soc/fsl/imx-pcm-fiq.c | 16 +++++++++------- sound/soc/fsl/imx-pcm.h | 9 +++++++++ sound/soc/fsl/imx-ssi.c | 7 ++++++- sound/soc/fsl/imx-ssi.h | 1 + 4 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/sound/soc/fsl/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c index 670b96b..c3fdb2f 100644 --- a/sound/soc/fsl/imx-pcm-fiq.c +++ b/sound/soc/fsl/imx-pcm-fiq.c @@ -22,6 +22,7 @@ #include <linux/slab.h>
#include <sound/core.h> +#include <sound/dmaengine_pcm.h> #include <sound/initval.h> #include <sound/pcm.h> #include <sound/pcm_params.h> @@ -32,6 +33,7 @@ #include <linux/platform_data/asoc-imx-ssi.h>
#include "imx-ssi.h" +#include "imx-pcm.h"
struct imx_pcm_runtime_data { unsigned int period; @@ -283,7 +285,7 @@ static struct snd_soc_platform_driver imx_soc_platform_fiq = {
int imx_pcm_fiq_init(struct platform_device *pdev) { - struct imx_ssi *ssi = platform_get_drvdata(pdev); + struct imx_pcm_fiq_params *params = platform_get_drvdata(pdev); int ret;
ret = claim_fiq(&fh); @@ -292,15 +294,15 @@ int imx_pcm_fiq_init(struct platform_device *pdev) return ret; }
- mxc_set_irq_fiq(ssi->irq, 1); - ssi_irq = ssi->irq; + mxc_set_irq_fiq(params->irq, 1); + ssi_irq = params->irq;
- imx_pcm_fiq = ssi->irq; + imx_pcm_fiq = params->irq;
- imx_ssi_fiq_base = (unsigned long)ssi->base; + imx_ssi_fiq_base = (unsigned long)params->base;
- ssi->dma_params_tx.maxburst = 4; - ssi->dma_params_rx.maxburst = 6; + params->dma_params_tx->maxburst = 4; + params->dma_params_rx->maxburst = 6;
ret = snd_soc_register_platform(&pdev->dev, &imx_soc_platform_fiq); if (ret) diff --git a/sound/soc/fsl/imx-pcm.h b/sound/soc/fsl/imx-pcm.h index 3661b13..cde849b 100644 --- a/sound/soc/fsl/imx-pcm.h +++ b/sound/soc/fsl/imx-pcm.h @@ -32,6 +32,15 @@ imx_pcm_dma_params_init_data(struct imx_dma_data *dma_data, dma_data->peripheral_type = IMX_DMATYPE_SSI; }
+struct imx_pcm_fiq_params { + int irq; + void __iomem *base; + + /* Pointer to original ssi driver to setup tx rx sizes */ + struct snd_dmaengine_dai_dma_data *dma_params_rx; + struct snd_dmaengine_dai_dma_data *dma_params_tx; +}; + int snd_imx_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma); int imx_pcm_new(struct snd_soc_pcm_runtime *rtd); diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c index 902fab0..f80f4c7 100644 --- a/sound/soc/fsl/imx-ssi.c +++ b/sound/soc/fsl/imx-ssi.c @@ -601,7 +601,12 @@ static int imx_ssi_probe(struct platform_device *pdev) goto failed_pdev_fiq_alloc; }
- platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi); + ssi->fiq_params.irq = ssi->irq; + ssi->fiq_params.base = ssi->base; + ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx; + ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx; + + platform_set_drvdata(ssi->soc_platform_pdev_fiq, &ssi->fiq_params); ret = platform_device_add(ssi->soc_platform_pdev_fiq); if (ret) { dev_err(&pdev->dev, "failed to add platform device\n"); diff --git a/sound/soc/fsl/imx-ssi.h b/sound/soc/fsl/imx-ssi.h index bb6b3db..20ce7ca 100644 --- a/sound/soc/fsl/imx-ssi.h +++ b/sound/soc/fsl/imx-ssi.h @@ -209,6 +209,7 @@ struct imx_ssi { struct snd_dmaengine_dai_dma_data dma_params_tx; struct imx_dma_data filter_data_tx; struct imx_dma_data filter_data_rx; + struct imx_pcm_fiq_params fiq_params;
int enabled;
Add definitions for AC97 control register.
Signed-off-by: Markus Pargmann mpa@pengutronix.de Acked-by: Timur Tabi timur@tabi.org --- sound/soc/fsl/fsl_ssi.h | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/sound/soc/fsl/fsl_ssi.h b/sound/soc/fsl/fsl_ssi.h index 2173000..e6b9a69 100644 --- a/sound/soc/fsl/fsl_ssi.h +++ b/sound/soc/fsl/fsl_ssi.h @@ -196,5 +196,13 @@ struct ccsr_ssi { #define CCSR_SSI_SOR_WAIT(x) (((x) & 3) << CCSR_SSI_SOR_WAIT_SHIFT) #define CCSR_SSI_SOR_SYNRST 0x00000001
+#define CCSR_SSI_SACNT_FRDIV(x) (((x) & 0x3f) << 5) +#define CCSR_SSI_SACNT_WR 0x00000010 +#define CCSR_SSI_SACNT_RD 0x00000008 +#define CCSR_SSI_SACNT_RDWR_MASK 0x00000018 +#define CCSR_SSI_SACNT_TIF 0x00000004 +#define CCSR_SSI_SACNT_FV 0x00000002 +#define CCSR_SSI_SACNT_AC97EN 0x00000001 + #endif
Add support for non-dma pcm for imx platforms with imx-pcm-fiq support. Instead of imx-pcm-audio, in this case imx-pcm-fiq-audio device is added and the SIER flags are set differently.
Signed-off-by: Markus Pargmann mpa@pengutronix.de ---
Notes: Changes in v3: - Rename bool "dma" to "use_dma"
sound/soc/fsl/fsl_ssi.c | 66 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 14 deletions(-)
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 0f0bed6..6a9be9c 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -121,12 +121,14 @@ struct fsl_ssi_private {
bool new_binding; bool ssi_on_imx; + bool use_dma; struct clk *clk; struct platform_device *imx_pcm_pdev; struct snd_dmaengine_dai_dma_data dma_params_tx; struct snd_dmaengine_dai_dma_data dma_params_rx; struct imx_dma_data filter_data_tx; struct imx_dma_data filter_data_rx; + struct imx_pcm_fiq_params fiq_params;
struct { unsigned int rfrc; @@ -356,7 +358,12 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, */
/* Enable the interrupts and DMA requests */ - write_ssi(SIER_FLAGS, &ssi->sier); + if (ssi_private->use_dma) + write_ssi(SIER_FLAGS, &ssi->sier); + else + write_ssi(CCSR_SSI_SIER_TIE | CCSR_SSI_SIER_TFE0_EN | + CCSR_SSI_SIER_RIE | + CCSR_SSI_SIER_RFF0_EN, &ssi->sier);
/* * Set the watermark for transmit FIFI 0 and receive FIFO 0. We @@ -550,7 +557,7 @@ static int fsl_ssi_dai_probe(struct snd_soc_dai *dai) { struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(dai);
- if (ssi_private->ssi_on_imx) { + if (ssi_private->ssi_on_imx && ssi_private->use_dma) { dai->playback_dma_data = &ssi_private->dma_params_tx; dai->capture_dma_data = &ssi_private->dma_params_rx; } @@ -695,6 +702,8 @@ static int fsl_ssi_probe(struct platform_device *pdev) sizeof(fsl_ssi_dai_template)); ssi_private->cpu_dai_drv.name = ssi_private->name;
+ ssi_private->use_dma = !of_property_read_bool(np, "fsl,imx-fiq"); + /* Get the addresses and IRQ */ ret = of_address_to_resource(np, 0, &res); if (ret) { @@ -716,12 +725,15 @@ static int fsl_ssi_probe(struct platform_device *pdev) goto error_iomap; }
- /* The 'name' should not have any slashes in it. */ - ret = request_irq(ssi_private->irq, fsl_ssi_isr, 0, ssi_private->name, - ssi_private); - if (ret < 0) { - dev_err(&pdev->dev, "could not claim irq %u\n", ssi_private->irq); - goto error_irqmap; + if (ssi_private->use_dma) { + /* The 'name' should not have any slashes in it. */ + ret = request_irq(ssi_private->irq, fsl_ssi_isr, 0, + ssi_private->name, ssi_private); + if (ret < 0) { + dev_err(&pdev->dev, "could not claim irq %u\n", + ssi_private->irq); + goto error_irqmap; + } }
/* Are the RX and the TX clocks locked? */ @@ -770,7 +782,7 @@ static int fsl_ssi_probe(struct platform_device *pdev) */ ret = of_property_read_u32_array(pdev->dev.of_node, "fsl,ssi-dma-events", dma_events, 2); - if (ret) { + if (ret && !ssi_private->use_dma) { dev_err(&pdev->dev, "could not get dma events\n"); goto error_clk; } @@ -809,12 +821,38 @@ static int fsl_ssi_probe(struct platform_device *pdev) }
if (ssi_private->ssi_on_imx) { - ssi_private->imx_pcm_pdev = - platform_device_register_simple("imx-pcm-audio", + if (!ssi_private->use_dma) { + ssi_private->imx_pcm_pdev = platform_device_alloc( + "imx-fiq-pcm-audio", + pdev->id); + if (!ssi_private->imx_pcm_pdev) { + ret = -ENOMEM; + goto error_dev; + } + + ssi_private->fiq_params.irq = ssi_private->irq; + ssi_private->fiq_params.base = ssi_private->ssi; + ssi_private->fiq_params.dma_params_rx = + &ssi_private->dma_params_rx; + ssi_private->fiq_params.dma_params_tx = + &ssi_private->dma_params_tx; + + platform_set_drvdata(ssi_private->imx_pcm_pdev, + &ssi_private->fiq_params); + ret = platform_device_add(ssi_private->imx_pcm_pdev); + if (ret) { + dev_err(&pdev->dev, "Failed to add imx-fiq-pcm-audio device\n"); + platform_device_put(ssi_private->imx_pcm_pdev); + goto error_dev; + } + } else { + ssi_private->imx_pcm_pdev = + platform_device_register_simple("imx-pcm-audio", -1, NULL, 0); - if (IS_ERR(ssi_private->imx_pcm_pdev)) { - ret = PTR_ERR(ssi_private->imx_pcm_pdev); - goto error_dev; + if (IS_ERR(ssi_private->imx_pcm_pdev)) { + ret = PTR_ERR(ssi_private->imx_pcm_pdev); + goto error_dev; + } } }
From: Markus Pargmann mpa@pengutrnoix.de
There may be some platforms using fsl-ssi that do not have a DMA driver with generic DMA bindings. So this patch adds support for the generic DMA bindings, while still using the old "fsl,dma-events" property if "dmas" is not found.
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/fsl/fsl_ssi.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 6a9be9c..1ab66f8 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -776,15 +776,19 @@ static int fsl_ssi_probe(struct platform_device *pdev) &ssi_private->filter_data_tx; ssi_private->dma_params_rx.filter_data = &ssi_private->filter_data_rx; - /* - * TODO: This is a temporary solution and should be changed - * to use generic DMA binding later when the helplers get in. - */ - ret = of_property_read_u32_array(pdev->dev.of_node, + if (!of_property_read_bool(pdev->dev.of_node, "dmas") && + ssi_private->use_dma) { + /* + * TODO: This is a temporary solution and should be + * changed to use generic DMA binding later when the + * helplers get in. + */ + ret = of_property_read_u32_array(pdev->dev.of_node, "fsl,ssi-dma-events", dma_events, 2); - if (ret && !ssi_private->use_dma) { - dev_err(&pdev->dev, "could not get dma events\n"); - goto error_clk; + if (ret && ssi_private->use_dma) { + dev_err(&pdev->dev, "could not get dma events but fsl-ssi is configured to use DMA\n"); + goto error_clk; + } }
shared = of_device_is_compatible(of_get_parent(np), @@ -847,8 +851,10 @@ static int fsl_ssi_probe(struct platform_device *pdev) } } else { ssi_private->imx_pcm_pdev = - platform_device_register_simple("imx-pcm-audio", - -1, NULL, 0); + platform_device_register_data(&pdev->dev, + "imx-pcm-audio", -1, + pdev->dev.of_node, + sizeof(*pdev->dev.of_node)); if (IS_ERR(ssi_private->imx_pcm_pdev)) { ret = PTR_ERR(ssi_private->imx_pcm_pdev); goto error_dev;
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- arch/arm/mach-imx/mach-pca100.c | 7 +++++-- arch/arm/mach-imx/mach-pcm043.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/arch/arm/mach-imx/mach-pca100.c b/arch/arm/mach-imx/mach-pca100.c index b8b15bb..68badf8 100644 --- a/arch/arm/mach-imx/mach-pca100.c +++ b/arch/arm/mach-imx/mach-pca100.c @@ -22,6 +22,7 @@ #include <linux/i2c.h> #include <linux/i2c/at24.h> #include <linux/dma-mapping.h> +#include <linux/export.h> #include <linux/spi/spi.h> #include <linux/spi/eeprom.h> #include <linux/irq.h> @@ -208,7 +209,7 @@ static const struct spi_imx_master pca100_spi0_data __initconst = { .num_chipselect = ARRAY_SIZE(pca100_spi_cs), };
-static void pca100_ac97_warm_reset(struct snd_ac97 *ac97) +void pca100_ac97_warm_reset(struct snd_ac97 *ac97) { mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); gpio_set_value(GPIO_PORTC + 20, 1); @@ -217,8 +218,9 @@ static void pca100_ac97_warm_reset(struct snd_ac97 *ac97) mxc_gpio_mode(PC20_PF_SSI1_FS); msleep(2); } +EXPORT_SYMBOL(pca100_ac97_warm_reset);
-static void pca100_ac97_cold_reset(struct snd_ac97 *ac97) +void pca100_ac97_cold_reset(struct snd_ac97 *ac97) { mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); /* FS */ gpio_set_value(GPIO_PORTC + 20, 0); @@ -232,6 +234,7 @@ static void pca100_ac97_cold_reset(struct snd_ac97 *ac97) mxc_gpio_mode(PC22_PF_SSI1_TXD); msleep(2); } +EXPORT_SYMBOL(pca100_ac97_cold_reset);
static const struct imx_ssi_platform_data pca100_ssi_pdata __initconst = { .ac97_reset = pca100_ac97_cold_reset, diff --git a/arch/arm/mach-imx/mach-pcm043.c b/arch/arm/mach-imx/mach-pcm043.c index 8ed533f..4f318ca 100644 --- a/arch/arm/mach-imx/mach-pcm043.c +++ b/arch/arm/mach-imx/mach-pcm043.c @@ -27,6 +27,7 @@ #include <linux/i2c/at24.h> #include <linux/usb/otg.h> #include <linux/usb/ulpi.h> +#include <linux/export.h>
#include <asm/mach-types.h> #include <asm/mach/arch.h> @@ -217,7 +218,7 @@ static iomux_v3_cfg_t pcm043_pads[] = { #define SD1_GPIO_WP IMX_GPIO_NR(2, 23) #define SD1_GPIO_CD IMX_GPIO_NR(2, 24)
-static void pcm043_ac97_warm_reset(struct snd_ac97 *ac97) +void pcm043_ac97_warm_reset(struct snd_ac97 *ac97) { iomux_v3_cfg_t txfs_gpio = MX35_PAD_STXFS4__GPIO2_31; iomux_v3_cfg_t txfs = MX35_PAD_STXFS4__AUDMUX_AUD4_TXFS; @@ -239,8 +240,9 @@ static void pcm043_ac97_warm_reset(struct snd_ac97 *ac97) gpio_free(AC97_GPIO_TXFS); mxc_iomux_v3_setup_pad(txfs); } +EXPORT_SYMBOL(pcm043_ac97_warm_reset);
-static void pcm043_ac97_cold_reset(struct snd_ac97 *ac97) +void pcm043_ac97_cold_reset(struct snd_ac97 *ac97) { iomux_v3_cfg_t txfs_gpio = MX35_PAD_STXFS4__GPIO2_31; iomux_v3_cfg_t txfs = MX35_PAD_STXFS4__AUDMUX_AUD4_TXFS; @@ -286,6 +288,7 @@ err1: printk("%s failed with %d\n", __func__, ret); mdelay(1); } +EXPORT_SYMBOL(pcm043_ac97_cold_reset);
static const struct imx_ssi_platform_data pcm043_ssi_pdata __initconst = { .ac97_reset = pcm043_ac97_cold_reset,
This patch copies some parts from imx-ssi to support AC97 on imx27-pca100 and imx27-pcm043. This is a implementation of the ac97-slave mode.
For ac97, the registers have to be setup earlier than for other ssi modes because there is some communication with the external device before actual streaming. So this patch introduces a fsl_ssi_setup function to setup the registers at different times.
This patch was tested with imx27-pca100.
Signed-off-by: Markus Pargmann mpa@pengutronix.de ---
Notes: Changes in v3: - Cleanup ac97 code by adding a fsl_ssi_setup function for initial register setup. For ac97 the registers have to be setup earlier than in normal mode.
sound/soc/fsl/fsl_ssi.c | 412 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 340 insertions(+), 72 deletions(-)
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 1ab66f8..0ffb898 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -121,6 +121,7 @@ struct fsl_ssi_private {
bool new_binding; bool ssi_on_imx; + bool imx_ac97; bool use_dma; struct clk *clk; struct platform_device *imx_pcm_pdev; @@ -130,6 +131,9 @@ struct fsl_ssi_private { struct imx_dma_data filter_data_rx; struct imx_pcm_fiq_params fiq_params;
+ void (*ac97_reset) (struct snd_ac97 *ac97); + void (*ac97_warm_reset)(struct snd_ac97 *ac97); + struct { unsigned int rfrc; unsigned int tfrc; @@ -301,6 +305,124 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) return ret; }
+static int fsl_ssi_setup(struct fsl_ssi_private *ssi_private) +{ + struct ccsr_ssi __iomem *ssi = ssi_private->ssi; + u8 i2s_mode; + u8 wm; + int synchronous = ssi_private->cpu_dai_drv.symmetric_rates; + + if (ssi_private->imx_ac97) + i2s_mode = CCSR_SSI_SCR_I2S_MODE_NORMAL | CCSR_SSI_SCR_NET; + else + i2s_mode = CCSR_SSI_SCR_I2S_MODE_SLAVE; + + /* + * Section 16.5 of the MPC8610 reference manual says that the SSI needs + * to be disabled before updating the registers we set here. + */ + write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0); + + /* + * Program the SSI into I2S Slave Non-Network Synchronous mode. Also + * enable the transmit and receive FIFO. + * + * FIXME: Little-endian samples require a different shift dir + */ + write_ssi_mask(&ssi->scr, + CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN, + CCSR_SSI_SCR_TFR_CLK_DIS | + i2s_mode | + (synchronous ? CCSR_SSI_SCR_SYN : 0)); + + write_ssi(CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 | + CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS | + CCSR_SSI_STCR_TSCKP, &ssi->stcr); + + write_ssi(CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 | + CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS | + CCSR_SSI_SRCR_RSCKP, &ssi->srcr); + /* + * The DC and PM bits are only used if the SSI is the clock master. + */ + + /* + * Set the watermark for transmit FIFI 0 and receive FIFO 0. We don't + * use FIFO 1. We program the transmit water to signal a DMA transfer + * if there are only two (or fewer) elements left in the FIFO. Two + * elements equals one frame (left channel, right channel). This value, + * however, depends on the depth of the transmit buffer. + * + * We set the watermark on the same level as the DMA burstsize. For + * fiq it is probably better to use the biggest possible watermark + * size. + */ + if (ssi_private->use_dma) + wm = ssi_private->fifo_depth - 2; + else + wm = ssi_private->fifo_depth; + + write_ssi(CCSR_SSI_SFCSR_TFWM0(wm) | CCSR_SSI_SFCSR_RFWM0(wm) | + CCSR_SSI_SFCSR_TFWM1(wm) | CCSR_SSI_SFCSR_RFWM1(wm), + &ssi->sfcsr); + + /* + * For non-ac97 setups, we keep the SSI disabled because if we enable + * it, then the DMA controller will start. It's not supposed to start + * until the SCR.TE (or SCR.RE) bit is set, but it does anyway. The DMA + * controller will transfer one "BWC" of data (i.e. the amount of data + * that the MR.BWC bits are set to). The reason this is bad is because + * at this point, the PCM driver has not finished initializing the DMA + * controller. + */ + + + /* + * For ac97 interrupts are enabled with the startup of the substream + * because it is also running without an active substream. Normally SSI + * is only enabled when there is a substream. + */ + if (!ssi_private->imx_ac97) { + /* Enable the interrupts and DMA requests */ + if (ssi_private->use_dma) + write_ssi(SIER_FLAGS, &ssi->sier); + else + write_ssi(CCSR_SSI_SIER_TIE | CCSR_SSI_SIER_TFE0_EN | + CCSR_SSI_SIER_RIE | + CCSR_SSI_SIER_RFF0_EN, &ssi->sier); + } else { + /* + * Setup the clock control register + */ + write_ssi(CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13), + &ssi->stccr); + write_ssi(CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13), + &ssi->srccr); + + /* + * Enable AC97 mode and startup the SSI + */ + write_ssi(CCSR_SSI_SACNT_AC97EN | CCSR_SSI_SACNT_FV, + &ssi->sacnt); + write_ssi(0xff, &ssi->saccdis); + write_ssi(0x300, &ssi->saccen); + + /* + * Enable SSI + */ + write_ssi_mask(&ssi->scr, 0, CCSR_SSI_SCR_SSIEN); + write_ssi(CCSR_SSI_SOR_WAIT(3), &ssi->sor); + + /* + * Enable Transmit and Receive + */ + write_ssi_mask(&ssi->scr, 0, CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE); + } + + return 0; +} + + /** * fsl_ssi_startup: create a new substream * @@ -322,75 +444,14 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, * and initialize the SSI registers. */ if (!ssi_private->first_stream) { - struct ccsr_ssi __iomem *ssi = ssi_private->ssi; - ssi_private->first_stream = substream;
/* - * Section 16.5 of the MPC8610 reference manual says that the - * SSI needs to be disabled before updating the registers we set - * here. - */ - write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0); - - /* - * Program the SSI into I2S Slave Non-Network Synchronous mode. - * Also enable the transmit and receive FIFO. - * - * FIXME: Little-endian samples require a different shift dir - */ - write_ssi_mask(&ssi->scr, - CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN, - CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE - | (synchronous ? CCSR_SSI_SCR_SYN : 0)); - - write_ssi(CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 | - CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS | - CCSR_SSI_STCR_TSCKP, &ssi->stcr); - - write_ssi(CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 | - CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS | - CCSR_SSI_SRCR_RSCKP, &ssi->srcr); - - /* - * The DC and PM bits are only used if the SSI is the clock - * master. - */ - - /* Enable the interrupts and DMA requests */ - if (ssi_private->use_dma) - write_ssi(SIER_FLAGS, &ssi->sier); - else - write_ssi(CCSR_SSI_SIER_TIE | CCSR_SSI_SIER_TFE0_EN | - CCSR_SSI_SIER_RIE | - CCSR_SSI_SIER_RFF0_EN, &ssi->sier); - - /* - * Set the watermark for transmit FIFI 0 and receive FIFO 0. We - * don't use FIFO 1. We program the transmit water to signal a - * DMA transfer if there are only two (or fewer) elements left - * in the FIFO. Two elements equals one frame (left channel, - * right channel). This value, however, depends on the depth of - * the transmit buffer. - * - * We program the receive FIFO to notify us if at least two - * elements (one frame) have been written to the FIFO. We could - * make this value larger (and maybe we should), but this way - * data will be written to memory as soon as it's available. - */ - write_ssi(CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) | - CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2), - &ssi->sfcsr); - - /* - * We keep the SSI disabled because if we enable it, then the - * DMA controller will start. It's not supposed to start until - * the SCR.TE (or SCR.RE) bit is set, but it does anyway. The - * DMA controller will transfer one "BWC" of data (i.e. the - * amount of data that the MR.BWC bits are set to). The reason - * this is bad is because at this point, the PCM driver has not - * finished initializing the DMA controller. + * fsl_ssi_setup was already called by ac97_init earlier if + * the driver is in ac97 mode. */ + if (!ssi_private->imx_ac97) + fsl_ssi_setup(ssi_private); } else { if (synchronous) { struct snd_pcm_runtime *first_runtime = @@ -545,8 +606,9 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
/* * If this is the last active substream, disable the SSI. + * If AC97 is active, we don't want to disable SSI. */ - if (!ssi_private->first_stream) { + if (!ssi_private->first_stream && !ssi_private->imx_ac97) { struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0); @@ -595,6 +657,176 @@ static const struct snd_soc_component_driver fsl_ssi_component = { .name = "fsl-ssi", };
+/** + * fsl_ssi_ac97_trigger: start and stop the AC97 receive/transmit. + * + * This function is called by ALSA to start, stop, pause, and resume the + * transfer of data. + */ +static int fsl_ssi_ac97_trigger(struct snd_pcm_substream *substream, int cmd, + struct snd_soc_dai *dai) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai); + struct ccsr_ssi __iomem *ssi = ssi_private->ssi; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + write_ssi_mask(&ssi->sier, 0, CCSR_SSI_SIER_TIE | + CCSR_SSI_SIER_TFE0_EN); + else + write_ssi_mask(&ssi->sier, 0, CCSR_SSI_SIER_RIE | + CCSR_SSI_SIER_RFF0_EN); + break; + + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + write_ssi_mask(&ssi->sier, CCSR_SSI_SIER_TIE | + CCSR_SSI_SIER_TFE0_EN, 0); + else + write_ssi_mask(&ssi->sier, CCSR_SSI_SIER_RIE | + CCSR_SSI_SIER_RFF0_EN, 0); + break; + + default: + return -EINVAL; + } + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + write_ssi(CCSR_SSI_SOR_TX_CLR, &ssi->sor); + else + write_ssi(CCSR_SSI_SOR_RX_CLR, &ssi->sor); + + return 0; +} + +static const struct snd_soc_dai_ops fsl_ssi_ac97_dai_ops = { + .startup = fsl_ssi_startup, + .shutdown = fsl_ssi_shutdown, + .trigger = fsl_ssi_ac97_trigger, +}; + +static struct snd_soc_dai_driver fsl_ssi_ac97_dai = { + .ac97_control = 1, + .playback = { + .stream_name = "AC97 Playback", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_8000_48000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .capture = { + .stream_name = "AC97 Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_48000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .ops = &fsl_ssi_ac97_dai_ops, +}; + + +static struct fsl_ssi_private *fsl_ac97_data; + +static void fsl_ssi_ac97_init(void) +{ + fsl_ssi_setup(fsl_ac97_data); +} + +static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, + unsigned short val) +{ + struct ccsr_ssi *ssi = fsl_ac97_data->ssi; + unsigned int lreg; + unsigned int lval; + + if (reg > 0x7f) + return; + + + lreg = reg << 12; + write_ssi(lreg, &ssi->sacadd); + + lval = val << 4; + write_ssi(lval , &ssi->sacdat); + + write_ssi_mask(&ssi->sacnt, CCSR_SSI_SACNT_RDWR_MASK, + CCSR_SSI_SACNT_WR); + udelay(100); +} + +static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97, + unsigned short reg) +{ + struct ccsr_ssi *ssi = fsl_ac97_data->ssi; + + unsigned short val = -1; + unsigned int lreg; + + lreg = (reg & 0x7f) << 12 ; + write_ssi(lreg, &ssi->sacadd); + write_ssi_mask(&ssi->sacnt, CCSR_SSI_SACNT_RDWR_MASK, + CCSR_SSI_SACNT_RD); + + udelay(100); + + val = (read_ssi(&ssi->sacdat) >> 4) & 0xffff; + + return val; +} + +static void fsl_ssi_ac97_reset(struct snd_ac97 *ac97) +{ + struct fsl_ssi_private *ssi_private = fsl_ac97_data; + + if (ssi_private->ac97_reset) + ssi_private->ac97_reset(ac97); + /* First read sometimes fails, do a dummy read */ + fsl_ssi_ac97_read(ac97, 0); +} + +static void fsl_ssi_ac97_warm_reset(struct snd_ac97 *ac97) +{ + struct fsl_ssi_private *ssi_private = fsl_ac97_data; + + if (ssi_private->ac97_warm_reset) + ssi_private->ac97_warm_reset(ac97); + + /* First read sometimes fails, do a dummy read */ + fsl_ssi_ac97_read(ac97, 0); +} + +struct snd_ac97_bus_ops soc_ac97_ops = { + .read = fsl_ssi_ac97_read, + .write = fsl_ssi_ac97_write, + .reset = fsl_ssi_ac97_reset, + .warm_reset = fsl_ssi_ac97_warm_reset +}; +EXPORT_SYMBOL_GPL(soc_ac97_ops); + +/* + * Pointer to AC97 reset functions for specific boards + */ +#if IS_ENABLED(CONFIG_MACH_PCA100) +extern void pca100_ac97_cold_reset(struct snd_ac97 *ac97); +extern void pca100_ac97_warm_reset(struct snd_ac97 *ac97); +#else +void pca100_ac97_cold_reset(struct snd_ac97 *ac97) { } +void pca100_ac97_warm_reset(struct snd_ac97 *ac97) { } +#endif + +#if IS_ENABLED(CONFIG_MACH_PCM043) +extern void pcm043_ac97_cold_reset(struct snd_ac97 *ac97); +extern void pcm043_ac97_warm_reset(struct snd_ac97 *ac97); +#else +void pcm043_ac97_cold_reset(struct snd_ac97 *ac97) { } +void pcm043_ac97_warm_reset(struct snd_ac97 *ac97) { } +#endif + + /* Show the statistics of a flag only if its interrupt is enabled. The * compiler will optimze this code to a no-op if the interrupt is not * enabled. @@ -671,6 +903,7 @@ static int fsl_ssi_probe(struct platform_device *pdev) struct resource res; char name[64]; bool shared; + bool ac97 = false;
/* SSIs that are not connected on the board should have a * status = "disabled" @@ -681,7 +914,13 @@ static int fsl_ssi_probe(struct platform_device *pdev)
/* We only support the SSI in "I2S Slave" mode */ sprop = of_get_property(np, "fsl,mode", NULL); - if (!sprop || strcmp(sprop, "i2s-slave")) { + if (!sprop) { + dev_err(&pdev->dev, "fsl,mode property is necessary\n"); + return -EINVAL; + } + if (!strcmp(sprop, "ac97-slave")) { + ac97 = true; + } else if (strcmp(sprop, "i2s-slave")) { dev_notice(&pdev->dev, "mode %s is unsupported\n", sprop); return -ENODEV; } @@ -697,13 +936,39 @@ static int fsl_ssi_probe(struct platform_device *pdev)
strcpy(ssi_private->name, p);
- /* Initialize this copy of the CPU DAI driver structure */ - memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template, - sizeof(fsl_ssi_dai_template)); - ssi_private->cpu_dai_drv.name = ssi_private->name; - ssi_private->use_dma = !of_property_read_bool(np, "fsl,imx-fiq");
+ if (ac97) { + sprop = of_get_property(of_find_node_by_path("/"), "compatible", + NULL); + p = strrchr(sprop, ','); + if (p) + sprop = p + 1; + + if (!strcmp(sprop, "imx27-pca100")) { + ssi_private->ac97_reset = pca100_ac97_cold_reset; + ssi_private->ac97_warm_reset = pca100_ac97_warm_reset; + } else if (!strcmp(sprop, "imx27-pcm043")) { + ssi_private->ac97_reset = pcm043_ac97_cold_reset; + ssi_private->ac97_warm_reset = pcm043_ac97_warm_reset; + } else { + dev_err(&pdev->dev, "Failed to enable ssi AC97 mode, unknown board.\n"); + ret = -EINVAL; + goto error_kmalloc; + } + + memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_ac97_dai, + sizeof(fsl_ssi_ac97_dai)); + + fsl_ac97_data = ssi_private; + ssi_private->imx_ac97 = true; + } else { + /* Initialize this copy of the CPU DAI driver structure */ + memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template, + sizeof(fsl_ssi_dai_template)); + } + ssi_private->cpu_dai_drv.name = ssi_private->name; + /* Get the addresses and IRQ */ ret = of_address_to_resource(np, 0, &res); if (ret) { @@ -894,6 +1159,9 @@ static int fsl_ssi_probe(struct platform_device *pdev) }
done: + if (ssi_private->imx_ac97) + fsl_ssi_ac97_init(); + return 0;
error_dai:
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- sound/soc/fsl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index 3843a18..28af843 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig @@ -153,7 +153,7 @@ config SND_SOC_PHYCORE_AC97 select SND_SOC_WM9712 select SND_SOC_IMX_PCM_FIQ select SND_SOC_IMX_AUDMUX - select SND_SOC_IMX_SSI + select SND_SOC_FSL_SSI help Say Y if you want to add support for SoC audio on Phytec phyCORE and phyCARD boards in AC97 mode
fsl-ssi was located in powerpc/fsl/ssi.txt. This is no powerpc specific device, so it should be moved to sound/ as it connects to differen audio codecs.
Signed-off-by: Markus Pargmann mpa@pengutronix.de --- .../devicetree/bindings/powerpc/fsl/ssi.txt | 73 ---------------------- .../devicetree/bindings/sound/fsl,ssi.txt | 73 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 Documentation/devicetree/bindings/powerpc/fsl/ssi.txt create mode 100644 Documentation/devicetree/bindings/sound/fsl,ssi.txt
diff --git a/Documentation/devicetree/bindings/powerpc/fsl/ssi.txt b/Documentation/devicetree/bindings/powerpc/fsl/ssi.txt deleted file mode 100644 index 5ff76c9..0000000 --- a/Documentation/devicetree/bindings/powerpc/fsl/ssi.txt +++ /dev/null @@ -1,73 +0,0 @@ -Freescale Synchronous Serial Interface - -The SSI is a serial device that communicates with audio codecs. It can -be programmed in AC97, I2S, left-justified, or right-justified modes. - -Required properties: -- compatible: Compatible list, contains "fsl,ssi". -- cell-index: The SSI, <0> = SSI1, <1> = SSI2, and so on. -- reg: Offset and length of the register set for the device. -- interrupts: <a b> where a is the interrupt number and b is a - field that represents an encoding of the sense and - level information for the interrupt. This should be - encoded based on the information in section 2) - depending on the type of interrupt controller you - have. -- interrupt-parent: The phandle for the interrupt controller that - services interrupts for this device. -- fsl,mode: The operating mode for the SSI interface. - "i2s-slave" - I2S mode, SSI is clock slave - "i2s-master" - I2S mode, SSI is clock master - "lj-slave" - left-justified mode, SSI is clock slave - "lj-master" - l.j. mode, SSI is clock master - "rj-slave" - right-justified mode, SSI is clock slave - "rj-master" - r.j., SSI is clock master - "ac97-slave" - AC97 mode, SSI is clock slave - "ac97-master" - AC97 mode, SSI is clock master -- fsl,playback-dma: Phandle to a node for the DMA channel to use for - playback of audio. This is typically dictated by SOC - design. See the notes below. -- fsl,capture-dma: Phandle to a node for the DMA channel to use for - capture (recording) of audio. This is typically dictated - by SOC design. See the notes below. -- fsl,fifo-depth: The number of elements in the transmit and receive FIFOs. - This number is the maximum allowed value for SFCSR[TFWM0]. -- fsl,ssi-asynchronous: - If specified, the SSI is to be programmed in asynchronous - mode. In this mode, pins SRCK, STCK, SRFS, and STFS must - all be connected to valid signals. In synchronous mode, - SRCK and SRFS are ignored. Asynchronous mode allows - playback and capture to use different sample sizes and - sample rates. Some drivers may require that SRCK and STCK - be connected together, and SRFS and STFS be connected - together. This would still allow different sample sizes, - but not different sample rates. - -Optional properties: -- codec-handle: Phandle to a 'codec' node that defines an audio - codec connected to this SSI. This node is typically - a child of an I2C or other control node. - -Child 'codec' node required properties: -- compatible: Compatible list, contains the name of the codec - -Child 'codec' node optional properties: -- clock-frequency: The frequency of the input clock, which typically comes - from an on-board dedicated oscillator. - -Notes on fsl,playback-dma and fsl,capture-dma: - -On SOCs that have an SSI, specific DMA channels are hard-wired for playback -and capture. On the MPC8610, for example, SSI1 must use DMA channel 0 for -playback and DMA channel 1 for capture. SSI2 must use DMA channel 2 for -playback and DMA channel 3 for capture. The developer can choose which -DMA controller to use, but the channels themselves are hard-wired. The -purpose of these two properties is to represent this hardware design. - -The device tree nodes for the DMA channels that are referenced by -"fsl,playback-dma" and "fsl,capture-dma" must be marked as compatible with -"fsl,ssi-dma-channel". The SOC-specific compatible string (e.g. -"fsl,mpc8610-dma-channel") can remain. If these nodes are left as -"fsl,elo-dma-channel" or "fsl,eloplus-dma-channel", then the generic Elo DMA -drivers (fsldma) will attempt to use them, and it will conflict with the -sound drivers. diff --git a/Documentation/devicetree/bindings/sound/fsl,ssi.txt b/Documentation/devicetree/bindings/sound/fsl,ssi.txt new file mode 100644 index 0000000..5ff76c9 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/fsl,ssi.txt @@ -0,0 +1,73 @@ +Freescale Synchronous Serial Interface + +The SSI is a serial device that communicates with audio codecs. It can +be programmed in AC97, I2S, left-justified, or right-justified modes. + +Required properties: +- compatible: Compatible list, contains "fsl,ssi". +- cell-index: The SSI, <0> = SSI1, <1> = SSI2, and so on. +- reg: Offset and length of the register set for the device. +- interrupts: <a b> where a is the interrupt number and b is a + field that represents an encoding of the sense and + level information for the interrupt. This should be + encoded based on the information in section 2) + depending on the type of interrupt controller you + have. +- interrupt-parent: The phandle for the interrupt controller that + services interrupts for this device. +- fsl,mode: The operating mode for the SSI interface. + "i2s-slave" - I2S mode, SSI is clock slave + "i2s-master" - I2S mode, SSI is clock master + "lj-slave" - left-justified mode, SSI is clock slave + "lj-master" - l.j. mode, SSI is clock master + "rj-slave" - right-justified mode, SSI is clock slave + "rj-master" - r.j., SSI is clock master + "ac97-slave" - AC97 mode, SSI is clock slave + "ac97-master" - AC97 mode, SSI is clock master +- fsl,playback-dma: Phandle to a node for the DMA channel to use for + playback of audio. This is typically dictated by SOC + design. See the notes below. +- fsl,capture-dma: Phandle to a node for the DMA channel to use for + capture (recording) of audio. This is typically dictated + by SOC design. See the notes below. +- fsl,fifo-depth: The number of elements in the transmit and receive FIFOs. + This number is the maximum allowed value for SFCSR[TFWM0]. +- fsl,ssi-asynchronous: + If specified, the SSI is to be programmed in asynchronous + mode. In this mode, pins SRCK, STCK, SRFS, and STFS must + all be connected to valid signals. In synchronous mode, + SRCK and SRFS are ignored. Asynchronous mode allows + playback and capture to use different sample sizes and + sample rates. Some drivers may require that SRCK and STCK + be connected together, and SRFS and STFS be connected + together. This would still allow different sample sizes, + but not different sample rates. + +Optional properties: +- codec-handle: Phandle to a 'codec' node that defines an audio + codec connected to this SSI. This node is typically + a child of an I2C or other control node. + +Child 'codec' node required properties: +- compatible: Compatible list, contains the name of the codec + +Child 'codec' node optional properties: +- clock-frequency: The frequency of the input clock, which typically comes + from an on-board dedicated oscillator. + +Notes on fsl,playback-dma and fsl,capture-dma: + +On SOCs that have an SSI, specific DMA channels are hard-wired for playback +and capture. On the MPC8610, for example, SSI1 must use DMA channel 0 for +playback and DMA channel 1 for capture. SSI2 must use DMA channel 2 for +playback and DMA channel 3 for capture. The developer can choose which +DMA controller to use, but the channels themselves are hard-wired. The +purpose of these two properties is to represent this hardware design. + +The device tree nodes for the DMA channels that are referenced by +"fsl,playback-dma" and "fsl,capture-dma" must be marked as compatible with +"fsl,ssi-dma-channel". The SOC-specific compatible string (e.g. +"fsl,mpc8610-dma-channel") can remain. If these nodes are left as +"fsl,elo-dma-channel" or "fsl,eloplus-dma-channel", then the generic Elo DMA +drivers (fsldma) will attempt to use them, and it will conflict with the +sound drivers.
Update the fsl-ssi bindings. DMA is no required property anymore and uses the generic DMA bindings. imx-fiq is a new alternative to DMA
Signed-off-by: Markus Pargmann mpa@pengutronix.de ---
Notes: Changes in v3: - In previous versions, I removed fsl,playback-dma and capture-dma. But they are still in use by fsl_dma.c, so I added them again.
Documentation/devicetree/bindings/sound/fsl,ssi.txt | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/fsl,ssi.txt b/Documentation/devicetree/bindings/sound/fsl,ssi.txt index 5ff76c9..6ea2ff2 100644 --- a/Documentation/devicetree/bindings/sound/fsl,ssi.txt +++ b/Documentation/devicetree/bindings/sound/fsl,ssi.txt @@ -43,10 +43,17 @@ Required properties: together. This would still allow different sample sizes, but not different sample rates.
+Note that either dmas, dma-names or fsl,imx-fiq are required. + Optional properties: - codec-handle: Phandle to a 'codec' node that defines an audio codec connected to this SSI. This node is typically a child of an I2C or other control node. +- dmas: Generic dma devicetree binding as described in + Documentation/devicetree/bindings/dma/dma.txt. +- dma-names: Two dmas have to be defined, "tx" and "rx", if fsl,imx-fiq + is not defined. +- fsl,imx-fiq: Bool property. Use imx-pcm-fiq instead of imx-pcm-dma.
Child 'codec' node required properties: - compatible: Compatible list, contains the name of the codec
On 04/14/2013 01:42 PM, Markus Pargmann wrote:
Hi,
This series adds DT support for phycore-ac97. It is now based on the pcm dma cleanups from Lars. Beside ac97 support, the series adds fsl-ssi imx-pcm-fiq and generic DMA binding handling.
@Lars: There are 4 new patches at the beginning of the series that fix some problems of your cleanups. I think they were in the changes you posted. If not, could you please add them to your branch?
Hi,
I had already fixed them localy. I'm in the process of polishing the last bits and pieces of my generic dmaengine PCM driver series right now and will submit it later today.
- Lars
Lars-Peter Clausen wrote:
@Lars: There are 4 new patches at the beginning of the series that fix some problems of your cleanups. I think they were in the changes you posted. If not, could you please add them to your branch?
Hi,
I had already fixed them localy. I'm in the process of polishing the last bits and pieces of my generic dmaengine PCM driver series right now and will submit it later today.
So which repository should I apply these patches to? I want to make sure they don't break PowerPC.
On 04/16/2013 02:25 AM, Timur Tabi wrote:
Lars-Peter Clausen wrote:
@Lars: There are 4 new patches at the beginning of the series that fix some
problems
of your cleanups. I think they were in the changes you posted. If not,
could you
please add them to your branch?
Hi,
I had already fixed them localy. I'm in the process of polishing the last bits and pieces of my generic dmaengine PCM driver series right now and will submit it later today.
So which repository should I apply these patches to? I want to make sure they don't break PowerPC.
You can use https://github.com/lclausen-adi/linux-2.6/tree/asoc-dmaengine-cleanups, but make sure to skip the first 4 patches from this series.
- Lars
On Sun, Apr 14, 2013 at 01:42:44PM +0200, Markus Pargmann wrote:
This series adds DT support for phycore-ac97. It is now based on the pcm dma cleanups from Lars. Beside ac97 support, the series adds fsl-ssi imx-pcm-fiq and generic DMA binding handling.
I've now merged the core and i.MX bits of that into topic/dma so if you could check what actually went in and then respin?
participants (4)
-
Lars-Peter Clausen
-
Mark Brown
-
Markus Pargmann
-
Timur Tabi