ALSA SoC: Add OpenFirmware helper for matching bus and codec drivers
Subsystems (3)
PATCH v3 1/3 ALSA SoC: Add OpenFirmware helper for matching bus and codec drivers
From: Grant Likely <[email protected]>
Simple utility layer for creating ASoC machine instances based on data in the OpenFirmware device tree. OF aware platform drivers and codec drivers register themselves with this framework and the framework automatically instantiates a machine driver. At the moment, the driver is not very capable and it is expected to be extended as more features are needed for specifying the configuration in the device tree.
This is most likely temporary glue code to work around limitations in the ASoC v1 framework. When v2 is merged, most of this driver will need to be reworked.
---
include/sound/soc-of-simple.h | 21 +++++ sound/soc/fsl/Kconfig | 3 + sound/soc/fsl/Makefile | 3 + sound/soc/fsl/soc-of-simple.c | 171 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 0 deletions(-)
include/sound/soc-of-simple.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* OF helpers for ALSA SoC +* +* Copyright (C) 2008, Secret Lab Technologies Ltd. +*/ + +#ifndef _INCLUDE_SOC_OF_H_ +#define _INCLUDE_SOC_OF_H_ + +#include <linux/of.h> +#include <sound/soc.h> + +int of_snd_soc_register_codec (struct snd_soc_codec_device *codec_dev, +void *codec_data,struct snd_soc_dai *dai, +struct device_node *node); + +int of_snd_soc_register_platform (struct snd_soc_platform *platform, +struct device_node *node, +struct snd_soc_dai *cpu_dai); + +#endif /* _INCLUDE_SOC_OF_H_ */
sound/soc/fsl/Kconfig +3 -0
@@ -1,3 +1,6 @@ +config SND_SOC_OF_SIMPLE + tristate + config SND_SOC_MPC8610 bool "ALSA SoC support for the MPC8610 SOC" depends on MPC8610_HPCD
sound/soc/fsl/Makefile +3 -0
@@ -1,3 +1,6 @@ +# Simple machine driver that extracts configuration from the OF device tree +obj-$(CONFIG_SND_SOC_OF_SIMPLE) += soc-of-simple.o + # MPC8610 HPCD Machine Support obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.o
sound/soc/fsl/soc-of-simple.c new file +171 -0
171 lines not on this page · raw message
PATCH v3 2/3 ALSA SoC: Add mpc5200-psc I2S driver
From: Grant Likely <[email protected]>
This is an I2S bus driver for the MPC5200 PSC device. It depends on the soc-of helper functions to match a PSC device with a codec based on data in the device tree.
---
sound/soc/fsl/Kconfig | 7 sound/soc/fsl/Makefile | 2 sound/soc/fsl/mpc5200_psc_i2s.c | 884 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 893 insertions(+), 0 deletions(-)
sound/soc/fsl/Kconfig +7 -0
@@ -17,3 +17,10 @@ config SND_SOC_MPC8610_HPCD default y if MPC8610_HPCD help Say Y if you want to enable audio on the Freescale MPC8610 HPCD. + +config SND_SOC_MPC5200_I2S + tristate "Freescale MPC5200 PSC in I2S mode driver" + select SND_SOC_OF_SIMPLE + depends on SND_SOC && PPC_MPC52xx + help + Say Y here to support the MPC5200 PSCs in I2S mode.
sound/soc/fsl/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.o # MPC8610 Platform Support obj-$(CONFIG_SND_SOC_MPC8610) += fsl_ssi.o fsl_dma.o +obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o +
sound/soc/fsl/mpc5200_psc_i2s.c new file +884 -0
884 lines not on this page · raw message
PATCH v3 3/3 ALSA SoC: Add Texas Instruments TLV320AIC26 codec driver
In reply to Grant LikelyFrom: Grant Likely <[email protected]>
ASoC Codec driver for the TLV320AIC26 device. As it stands, this driver doesn't support all the modes and clocking options of the AIC16, but it is a start.
---
sound/soc/codecs/Kconfig | 4 sound/soc/codecs/Makefile | 2 sound/soc/codecs/tlv320aic26.c | 519 ++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/tlv320aic26.h | 93 +++++++ 4 files changed, 618 insertions(+), 0 deletions(-)
sound/soc/codecs/Kconfig +4 -0
@@ -47,6 +47,10 @@ config SND_SOC_CS4270_VD33_ERRATA bool depends on SND_SOC_CS4270 +config SND_SOC_TLV320AIC26 + tristate "TI TLB320AIC26 Codec support" + depends on SND_SOC && SPI + config SND_SOC_TLV320AIC3X tristate depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -9,6 +9,7 @@ snd-soc-wm8990-objs := wm8990.o snd-soc-wm9712-objs := wm9712.o snd-soc-wm9713-objs := wm9713.o snd-soc-cs4270-objs := cs4270.o +snd-soc-tlv320aic26-objs := tlv320aic26.o snd-soc-tlv320aic3x-objs := tlv320aic3x.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
@@ -22,4 +23,5 @@ obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o +obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
sound/soc/codecs/tlv320aic26.c new file +519 -0
519 lines not on this page · raw message
sound/soc/codecs/tlv320aic26.h new file +93 -0
93 lines not on this page · raw message
Quoted 3 lines · Grant Likely
This is most likely temporary glue code to work around limitations in the ASoC v1 framework. When v2 is merged, most of this driver will need to be reworked.
Whatever is needed in v2 can probably have the client registration functions integrated into the core registration functions.
Quoted 1 line
Signed-off-by Grant Likely <[email protected]>
Re: [PATCH v3 2/3] ALSA SoC: Add mpc5200-psc I2S driver
In reply to Grant LikelyQuoted 1 line · Grant Likely
Signed-off-by Grant Likely <[email protected]>
There's a few issues that were raised on the previous review cycle that still need to be addressed but they should be fixable in incremental patches (and easier to review that way):
sound/soc/fsl/mpc5200_psc_i2s.c line 331
Quoted 9 lines
sound/soc/fsl/mpc5200_psc_i2s.c new file +8
-0+static int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd) + spin_lock_irqsave(&psc_i2s->lock, flags); +/* first make sure it is low */ +while ((in_8 (®s->ipcr_acr.ipcr) &0x80 ) !=0 ) + ; +/* then wait for the transition to high */ +while ((in_8 (®s->ipcr_acr.ipcr) &0x80 ) ==0 ) + ;
These loops should really have some sort of time limit on them, otherwise they'll lock hard if the expected events don't happen. Given that in slave mode they're synchronising with an externally generated clock this is something that might happen in practice and should produce better diagnostics.
sound/soc/fsl/mpc5200_psc_i2s.c line 368
Quoted 4 lines
sound/soc/fsl/mpc5200_psc_i2s.c new file +4
-0+default : +dev_dbg (psc_i2s->dev,"invalid command\n" ); +return -EINVAL ; + }
I'd really expect to see the other possible triggers handled, even if the appropriate action is to silently ignore them, rather than having them generate an error message.
Re: [PATCH v3 3/3] ALSA SoC: Add Texas Instruments TLV320AIC26 codec driver
In reply to Grant LikelyQuoted 1 line · Grant Likely
Signed-off-by Grant Likely <[email protected]>
with the same comments about outstanding issues as applied to the CPU side.
sound/soc/codecs/tlv320aic26.c line 169
Quoted 11 lines
sound/soc/codecs/tlv320aic26.c new file +9
-0+static int aic26_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +switch (params_rate (params)) { +case 8000 : fsref =48000 ; divisor =AIC26_DIV_6 ;break ; +/* Configure PLL */ + pval =1 ; + jval = (fsref ==44100 ) ?7 :8 ; + dval = (fsref ==44100 ) ?5264 :1920 ;
Without having looked at the chip datasheet these parameters probably all need to depend on the input clock rate and the PLL configuration should be done in a set_pll() rather than here.
sound/soc/codecs/tlv320aic26.c line 485
Quoted 5 lines
sound/soc/codecs/tlv320aic26.c new file +5
-0+#if defined(CONFIG_SND_SOC_OF_SIMPLE ) +/* Tell the of_soc helper about this codec */ +of_snd_soc_register_codec (&aic26_soc_codec_dev, aic26, &aic26_dai, + spi->dev.archdata.of_node); +#endif
This won't work if the OF_SIMPLE stuff is a module. There's also a checkpatch issue which I'll fix up.
Quoted 40 lines · Grant Likely
From: Grant Likely <[email protected]>
Simple utility layer for creating ASoC machine instances based on data in the OpenFirmware device tree. OF aware platform drivers and codec drivers register themselves with this framework and the framework automatically instantiates a machine driver. At the moment, the driver is not very capable and it is expected to be extended as more features are needed for specifying the configuration in the device tree.
This is most likely temporary glue code to work around limitations in the ASoC v1 framework. When v2 is merged, most of this driver will need to be reworked.
Signed-off-by Grant Likely <[email protected]>---
include/sound/soc-of-simple.h | 21 +++++ sound/soc/fsl/Kconfig | 3 + sound/soc/fsl/Makefile | 3 + sound/soc/fsl/soc-of-simple.c | 171 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 0 deletions(-)diff --git
a/include/sound/soc-of-simple.hb/include/sound/soc-of-simple.hnew file mode 100644
index 0000000..696fc51
---/dev/null
+++b/include/sound/soc-of-simple.h
@@ -0,0 +1,21 @@
+/*
+ * OF helpers for ALSA SoC
+ *
+ * Copyright (C) 2008, Secret Lab Technologies Ltd.
+ */
+
+#ifndef _INCLUDE_SOC_OF_H_
+#define _INCLUDE_SOC_OF_H_
+
+#include <linux/of.h>
+#include <sound/soc.h>
+
Quoted 8 lines
+int of_snd_soc_register_codec(struct
snd_soc_codec_device*codec_dev,
+ void*codec_data, structsnd_soc_dai*dai,
+ structdevice_node*node);
+
+int of_snd_soc_register_platform(structsnd_soc_platform*platform,
+ structdevice_node*node,
+ structsnd_soc_dai*cpu_dai);
+
This doesn't compile for me. Where is struct snd_soc_dai being defined?
It used to be....
+int of_snd_soc_register_codec(struct snd_soc_codec_device *codec_dev,
+ void *codec_data, struct snd_soc_codec_dai *dai,
+ struct device_node *node);
+
+int of_snd_soc_register_platform(struct snd_soc_platform *platform,
+ struct device_node *node,
+ struct snd_soc_cpu_dai *cpu_dai);
Quoted 202 lines
+#endif /* _INCLUDE_SOC_OF_H_ */
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 3368ace..398f002 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -1,3 +1,6 @@
+configSND_SOC_OF_SIMPLE
+ tristate
+
configSND_SOC_MPC8610
bool "ALSA SoC support for the MPC8610 SOC"
depends onMPC8610_HPCD
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile index 62f680a..aa2100b 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -1,3 +1,6 @@
+# Simple machine driver that extracts configuration from the OF device tree +obj-$(CONFIG_SND_SOC_OF_SIMPLE) += soc-of-simple.o
+
# MPC8610 HPCD Machine Support obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.odiff --git
a/sound/soc/fsl/soc-of-simple.cb/sound/soc/fsl/soc-of-simple.cnew file mode 100644
index 0000000..0382fda
---/dev/null
+++b/sound/soc/fsl/soc-of-simple.c
@@ -0,0 +1,171 @@
+/*
+ * OF helpers for ALSA SoC Layer
+ *
+ * Copyright (C) 2008, Secret Lab Technologies Ltd.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/bitops.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-of-simple.h>
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Grant Likely <[email protected]>"); +MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("ALSA SoC OpenFirmware bindings");
+
+staticDEFINE_MUTEX(of_snd_soc_mutex);
+staticLIST_HEAD(of_snd_soc_device_list);
+static intof_snd_soc_next_index;
+
+structof_snd_soc_device{+ int id; + struct list_head list; + struct snd_soc_device device; + struct snd_soc_machine machine; + struct snd_soc_dai_link dai_link; + struct platform_device *pdev; + struct device_node *platform_node; + struct device_node *codec_node; +}; + +static struct snd_soc_ops of_snd_soc_ops = { +}; + +static struct of_snd_soc_device * +of_snd_soc_get_device(struct device_node *codec_node) +{ + struct of_snd_soc_device *of_soc; + + list_for_each_entry(of_soc, &of_snd_soc_device_list, list) { + if (of_soc->codec_node == codec_node) + return of_soc; + } + + of_soc = kzalloc(sizeof(struct of_snd_soc_device), GFP_KERNEL); + if (!of_soc) + return NULL; + + /* Initialize the structure and add it to the global list */ + of_soc->codec_node = codec_node; + of_soc->id = of_snd_soc_next_index++; + of_soc->machine.dai_link = &of_soc->dai_link; + of_soc->machine.num_links = 1; + of_soc->device.machine = &of_soc->machine; + of_soc->dai_link.ops = &of_snd_soc_ops; + list_add(&of_soc->list, &of_snd_soc_device_list); + + return of_soc; +} + +static void of_snd_soc_register_device(struct of_snd_soc_device *of_soc) +{ + struct platform_device *pdev; + int rc; + + /* Only register the device if both the codec and platform have + * been registered */ + if ((!of_soc->device.codec_data) || (!of_soc->platform_node)) + return; + + pr_info("platform<-->codec match achieved; registering machine\n"); + + pdev = platform_device_alloc("soc-audio", of_soc->id); + if (!pdev) { + pr_err("of_soc: platform_device_alloc() failed\n"); + return; + } + + pdev->dev.platform_data = of_soc; + platform_set_drvdata(pdev, &of_soc->device); + of_soc->device.dev = &pdev->dev; + + /* The ASoC device is complete; register it */ + rc = platform_device_add(pdev); + if (rc) { + pr_err("of_soc: platform_device_add() failed\n"); + return; + } + +} + +int of_snd_soc_register_codec(struct snd_soc_codec_device *codec_dev, + void *codec_data, struct snd_soc_dai *dai, + struct device_node *node) +{ + struct of_snd_soc_device *of_soc; + int rc = 0; + + pr_info("registering ASoC codec driver: %s\n", node->full_name); + + mutex_lock(&of_snd_soc_mutex); + of_soc = of_snd_soc_get_device(node); + if (!of_soc) { + rc = -ENOMEM; + goto out; + } + + /* Store the codec data */ + of_soc->device.codec_data = codec_data; + of_soc->device.codec_dev = codec_dev; + of_soc->dai_link.name = (char *)node->name; + of_soc->dai_link.stream_name = (char *)node->name; + of_soc->dai_link.codec_dai = dai; + + /* Now try to register the SoC device */ + of_snd_soc_register_device(of_soc); + + out: + mutex_unlock(&of_snd_soc_mutex); + return rc; +} +EXPORT_SYMBOL_GPL(of_snd_soc_register_codec); + +int of_snd_soc_register_platform(struct snd_soc_platform *platform, + struct device_node *node, + struct snd_soc_dai *cpu_dai) +{ + struct of_snd_soc_device *of_soc; + struct device_node *codec_node; + const phandle *handle; + int len, rc = 0; + + pr_info("registering ASoC platform driver: %s\n", node->full_name); + + handle = of_get_property(node, "codec-handle", &len); + if (!handle || len < sizeof(handle)) + return -ENODEV; + codec_node = of_find_node_by_phandle(*handle); + if (!codec_node) + return -ENODEV; + pr_info("looking for codec: %s\n", codec_node->full_name); + + mutex_lock(&of_snd_soc_mutex); + of_soc = of_snd_soc_get_device(codec_node); + if (!of_soc) { + rc = -ENOMEM; + goto out; + } + + of_soc->platform_node = node; + of_soc->dai_link.cpu_dai = cpu_dai; + of_soc->device.platform = platform; + of_soc->machine.name = of_soc->dai_link.cpu_dai->name;+
+ /* Now try to register the SoC device */
+of_snd_soc_register_device(of_soc);
+
+ out:
+mutex_unlock(&of_snd_soc_mutex);
+ return rc;
+} +EXPORT_SYMBOL_GPL(of_snd_soc_register_platform);
Signature · 2 lines
Jon Smirl [email protected]
Quoted 10 lines · Jon Smirl
Quoted 4 lines · Grant Likely
+int of_snd_soc_register_platform(struct
snd_soc_platform*platform,
+ structdevice_node*node,
+ structsnd_soc_dai*cpu_dai);
+This doesn't compile for me. Where is struct
snd_soc_daibeing defined?It used to be....
In ALSA and ASoC git struct snd_soc_{cpu,codec}_dai have been replaced by a shared snd_soc_dai defined in soc.h as the previous two were.
Re: [PATCH v3 2/3] ALSA SoC: Add mpc5200-psc I2S driver
In reply to Grant LikelyWhat about the mpc5200b?
+/* Match table for of_platform binding */
+static struct of_device_id psc_i2s_match[] __devinitdata = {
+ { .compatible = "fsl,mpc5200-psc-i2s", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, psc_i2s_match);
+
I'm just being grumpy because updating to linus/master made me fix over a hundred merge conflicts, now I have to test everything again.
Signature · 2 lines
Jon Smirl [email protected]
Quoted 15 lines · Jon Smirl
Quoted 8 lines · Grant Likely
+int of_snd_soc_register_codec(struct
snd_soc_codec_device*codec_dev,
+ void*codec_data, structsnd_soc_dai*dai,
+ structdevice_node*node);
+
+int of_snd_soc_register_platform(structsnd_soc_platform*platform,
+ structdevice_node*node,
+ structsnd_soc_dai*cpu_dai);
+This doesn't compile for me. Where is struct
snd_soc_daibeing defined?It used to be....
include/sound/soc-of-simple.h
Quoted 7 lines
include/sound/soc-of-simple.h new file +7
-0+int of_snd_soc_register_codec (struct snd_soc_codec_device *codec_dev, +void *codec_data,struct snd_soc_codec_dai *dai, +struct device_node *node); + +int of_snd_soc_register_platform (struct snd_soc_platform *platform, +struct device_node *node, +struct snd_soc_cpu_dai *cpu_dai);
I had to change it to match what is in Linus' current top of tree. The snd_soc_cpu_dai and snd_soc_codec_dai structures have been merged.
g.
Re: [PATCH v3 2/3] ALSA SoC: Add mpc5200-psc I2S driver
In reply to Mark BrownQuoted 12 lines · Mark Brown
Quoted 1 line · Grant Likely
Signed-off-by Grant Likely <[email protected]>Signed-off-by Mark Brown <[email protected]>There's a few issues that were raised on the previous review cycle that still need to be addressed but they should be fixable in incremental patches (and easier to review that way):
Quoted 1 line
+static int
psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
Quoted 13 lines
sound/soc/fsl/mpc5200_psc_i2s.c line 331
Quoted 7 lines
sound/soc/fsl/mpc5200_psc_i2s.c new file +7
-0+spin_lock_irqsave (&psc_i2s->lock, flags); +/* first make sure it is low */ +while ((in_8 (®s->ipcr_acr.ipcr) &0x80 ) !=0 ) + ; +/* then wait for the transition to high */ +while ((in_8 (®s->ipcr_acr.ipcr) &0x80 ) ==0 ) + ;These loops should really have some sort of time limit on them, otherwise they'll lock hard if the expected events don't happen. Given that in slave mode they're synchronising with an externally generated clock this is something that might happen in practice and should produce better diagnostics.
Yes, I hope to rework these two lines entirely. I'm not happy with the current implementation either.
Quoted 8 lines
sound/soc/fsl/mpc5200_psc_i2s.c line 368
Quoted 4 lines
sound/soc/fsl/mpc5200_psc_i2s.c new file +4
-0+default : +dev_dbg (psc_i2s->dev,"invalid command\n" ); +return -EINVAL ; + }I'd really expect to see the other possible triggers handled, even if the appropriate action is to silently ignore them, rather than having them generate an error message.
Okay, I'll do that.
g.