[alsa-devel] [PATCH v2 0/4] omap-abe-twl6040: Device tree support
Hello,
Changes since v1: - Binding docukentation updated with available pins and connectors - dts section for abe-twl6040 sound configuration has been changed
Instead of dai link pairs only the nodes probed via DT have phandle: ti,mcpdm; ti,dmic, ti,twl6040. The driver in turn is responsible to handle the provided information. To provide dai link pairs (cpu dai - codec) we would need Linux (ASoC) specific nodes in DT for the dmic codec and twl6040 ASoC codec driver.
If the DT section have ti,dmic phandle the ASoC machine driver will register the device to load the ASoC dmic-codec runtime.
Example dts section for audio support (SDP4430): sound { compatible = "ti,abe-twl6040"; ti,model = "SDP4430";
ti,jack-detection = <1>; ti,mclk-freq = <38400000>;
ti,mcpdm = <&mcpdm>; ti,dmic = <&dmic>;
ti,twl6040 = <&twl6040>;
/* Audio routing */ ti,audio-routing = "Headset Stereophone", "HSOL", "Headset Stereophone", "HSOR", "Earphone Spk", "EP", "Ext Spk", "HFL", "Ext Spk", "HFR", "Line Out", "AUXL", "Line Out", "AUXR", "Vibrator", "VIBRAL", "Vibrator", "VIBRAR", "HSMIC", "Headset Mic", "Headset Mic", "Headset Mic Bias", "MAINMIC", "Main Handset Mic", "Main Handset Mic", "Main Mic Bias", "SUBMIC", "Sub Handset Mic", "Sub Handset Mic", "Main Mic Bias", "AFML", "Line In", "AFMR", "Line In", "DMic", "Digital Mic", "Digital Mic", "Digital Mic1 Bias"; };
Regards, Peter --- Peter Ujfalusi (4): ASoC: omap-abe-twl6040: Keep only one snd_soc_dai_link structure ASoC: omap-abe-twl6040: Move Digital Mic widget into dapm table ASoC: omap-abe-twl6040: Introduce driver data for runtime parameters ASoC: omap-abe-twl6040: Add device tree support
.../devicetree/bindings/sound/omap-abe-twl6040.txt | 91 +++++++++ sound/soc/omap/omap-abe-twl6040.c | 195 ++++++++++++++------ 2 files changed, 230 insertions(+), 56 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt
There is no need to have two snd_soc_dai_link structure for the two setup the machine driver supports. We can just tell core to register only the first link if the DMIC link is not in use on the device.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com Acked-by: Mark Brown broonie@opensource.wolfsonmicro.com --- sound/soc/omap/omap-abe-twl6040.c | 30 +++++++++--------------------- 1 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c index 93bb8ee..31ab6fe 100644 --- a/sound/soc/omap/omap-abe-twl6040.c +++ b/sound/soc/omap/omap-abe-twl6040.c @@ -235,7 +235,7 @@ static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd) }
/* Digital audio interface glue - connects codec <--> CPU */ -static struct snd_soc_dai_link twl6040_dmic_dai[] = { +static struct snd_soc_dai_link abe_twl6040_dai_links[] = { { .name = "TWL6040", .stream_name = "TWL6040", @@ -258,19 +258,6 @@ static struct snd_soc_dai_link twl6040_dmic_dai[] = { }, };
-static struct snd_soc_dai_link twl6040_only_dai[] = { - { - .name = "TWL6040", - .stream_name = "TWL6040", - .cpu_dai_name = "omap-mcpdm", - .codec_dai_name = "twl6040-legacy", - .platform_name = "omap-pcm-audio", - .codec_name = "twl6040-codec", - .init = omap_abe_twl6040_init, - .ops = &omap_abe_ops, - }, -}; - /* Audio machine driver */ static struct snd_soc_card omap_abe_card = { .owner = THIS_MODULE, @@ -285,6 +272,7 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) { struct omap_abe_twl6040_data *pdata = dev_get_platdata(&pdev->dev); struct snd_soc_card *card = &omap_abe_card; + int num_links = 0; int ret;
card->dev = &pdev->dev; @@ -306,13 +294,13 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) return -ENODEV; }
- if (pdata->has_dmic) { - card->dai_link = twl6040_dmic_dai; - card->num_links = ARRAY_SIZE(twl6040_dmic_dai); - } else { - card->dai_link = twl6040_only_dai; - card->num_links = ARRAY_SIZE(twl6040_only_dai); - } + if (pdata->has_dmic) + num_links = 2; + else + num_links = 1; + + card->dai_link = abe_twl6040_dai_links; + card->num_links = num_links;
ret = snd_soc_register_card(card); if (ret)
The needed change in routing will be done runtime for the non twl6040 connected widgets, like the Digital microphone.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com Acked-by: Mark Brown broonie@opensource.wolfsonmicro.com --- sound/soc/omap/omap-abe-twl6040.c | 13 +++---------- 1 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c index 31ab6fe..4388de9 100644 --- a/sound/soc/omap/omap-abe-twl6040.c +++ b/sound/soc/omap/omap-abe-twl6040.c @@ -128,6 +128,9 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { SND_SOC_DAPM_MIC("Main Handset Mic", NULL), SND_SOC_DAPM_MIC("Sub Handset Mic", NULL), SND_SOC_DAPM_LINE("Line In", NULL), + + /* Digital microphones */ + SND_SOC_DAPM_MIC("Digital Mic", NULL), };
static const struct snd_soc_dapm_route audio_map[] = { @@ -210,10 +213,6 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) return ret; }
-static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = { - SND_SOC_DAPM_MIC("Digital Mic", NULL), -}; - static const struct snd_soc_dapm_route dmic_audio_map[] = { {"DMic", NULL, "Digital Mic"}, {"Digital Mic", NULL, "Digital Mic1 Bias"}, @@ -223,12 +222,6 @@ static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_codec *codec = rtd->codec; struct snd_soc_dapm_context *dapm = &codec->dapm; - int ret; - - ret = snd_soc_dapm_new_controls(dapm, dmic_dapm_widgets, - ARRAY_SIZE(dmic_dapm_widgets)); - if (ret) - return ret;
return snd_soc_dapm_add_routes(dapm, dmic_audio_map, ARRAY_SIZE(dmic_audio_map));
In preparation to Device Tree support. With DT booted kernel we can not rely on pdata which used to hold information needed for the driver at runtime. Use the card's driver data to hold these informations from now on.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com Acked-by: Mark Brown broonie@opensource.wolfsonmicro.com --- sound/soc/omap/omap-abe-twl6040.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c index 4388de9..9d93793 100644 --- a/sound/soc/omap/omap-abe-twl6040.c +++ b/sound/soc/omap/omap-abe-twl6040.c @@ -40,6 +40,11 @@ #include "omap-pcm.h" #include "../codecs/twl6040.h"
+struct abe_twl6040 { + int jack_detection; /* board can detect jack events */ + int mclk_freq; /* MCLK frequency speed for twl6040 */ +}; + static int omap_abe_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { @@ -47,13 +52,13 @@ static int omap_abe_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_codec *codec = rtd->codec; struct snd_soc_card *card = codec->card; - struct omap_abe_twl6040_data *pdata = dev_get_platdata(card->dev); + struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card); int clk_id, freq; int ret;
clk_id = twl6040_get_clk_id(rtd->codec); if (clk_id == TWL6040_SYSCLK_SEL_HPPLL) - freq = pdata->mclk_freq; + freq = priv->mclk_freq; else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL) freq = 32768; else @@ -176,6 +181,7 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_card *card = codec->card; struct snd_soc_dapm_context *dapm = &codec->dapm; struct omap_abe_twl6040_data *pdata = dev_get_platdata(card->dev); + struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card); int hs_trim; int ret = 0;
@@ -199,7 +205,7 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) TWL6040_HSF_TRIM_RIGHT(hs_trim));
/* Headset jack detection only if it is supported */ - if (pdata->jack_detection) { + if (priv->jack_detection) { ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, &hs_jack); if (ret) @@ -265,6 +271,7 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) { struct omap_abe_twl6040_data *pdata = dev_get_platdata(&pdev->dev); struct snd_soc_card *card = &omap_abe_card; + struct abe_twl6040 *priv; int num_links = 0; int ret;
@@ -275,6 +282,10 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) return -ENODEV; }
+ priv = devm_kzalloc(&pdev->dev, sizeof(struct abe_twl6040), GFP_KERNEL); + if (priv == NULL) + return -ENOMEM; + if (pdata->card_name) { card->name = pdata->card_name; } else { @@ -282,7 +293,11 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) return -ENODEV; }
- if (!pdata->mclk_freq) { + priv->jack_detection = pdata->jack_detection; + priv->mclk_freq = pdata->mclk_freq; + + + if (!priv->mclk_freq) { dev_err(&pdev->dev, "MCLK frequency missing\n"); return -ENODEV; } @@ -295,6 +310,8 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) card->dai_link = abe_twl6040_dai_links; card->num_links = num_links;
+ snd_soc_card_set_drvdata(card, priv); + ret = snd_soc_register_card(card); if (ret) dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
When the board boots with device tree the driver will receive the name of the card, DAPM routing map, phandle for the audio components described in the dts file, mclk speed, and the possibility of detecting the jack detection.
The card will be set up based on this information. Since the routing is provided via DT we can mark the card fully routed so core can take care of disconnecting the unused pins.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- .../devicetree/bindings/sound/omap-abe-twl6040.txt | 91 ++++++++++++ sound/soc/omap/omap-abe-twl6040.c | 145 ++++++++++++++++---- 2 files changed, 206 insertions(+), 30 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt
diff --git a/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt b/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt new file mode 100644 index 0000000..65dec87 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt @@ -0,0 +1,91 @@ +* Texas Instruments OMAP4+ and twl6040 based audio setups + +Required properties: +- compatible: "ti,abe-twl6040" +- ti,model: Name of the sound card ( for example "SDP4430") +- ti,mclk-freq: MCLK frequency for HPPLL operation +- ti,mcpdm: phandle for the McPDM node +- ti,twl6040: phandle for the twl6040 core node +- ti,audio-routing: List of connections between audio components. + Each entry is a pair of strings, the first being the connection's sink, + the second being the connection's source. + +Optional properties: +- ti,dmic: phandle for the OMAP dmic node if the machine have it connected +- ti,jack_detection: Need to be set to <1> if the board capable to detect jack + insertion, removal. + +Available audio endpoints for the audio-routing table: + +Board connectors: + * Headset Stereophone + * Earphone Spk + * Ext Spk + * Line Out + * Vibrator + * Headset Mic + * Main Handset Mic + * Sub Handset Mic + * Line In + * Digital Mic + +twl6040 pins: + * HSOL + * HSOR + * EP + * HFL + * HFR + * AUXL + * AUXR + * VIBRAL + * VIBRAR + * HSMIC + * MAINMIC + * SUBMIC + * AFML + * AFMR + + * Headset Mic Bias + * Main Mic Bias + * Digital Mic1 Bias + * Digital Mic2 Bias + +Digital mic pins: + * DMic + +Example: + +sound { + compatible = "ti,abe-twl6040"; + ti,model = "SDP4430"; + + ti,jack-detection = <1>; + ti,mclk-freq = <38400000>; + + ti,mcpdm = <&mcpdm>; + ti,dmic = <&dmic>; + + ti,twl6040 = <&twl6040>; + + /* Audio routing */ + ti,audio-routing = + "Headset Stereophone", "HSOL", + "Headset Stereophone", "HSOR", + "Earphone Spk", "EP", + "Ext Spk", "HFL", + "Ext Spk", "HFR", + "Line Out", "AUXL", + "Line Out", "AUXR", + "Vibrator", "VIBRAL", + "Vibrator", "VIBRAR", + "HSMIC", "Headset Mic", + "Headset Mic", "Headset Mic Bias", + "MAINMIC", "Main Handset Mic", + "Main Handset Mic", "Main Mic Bias", + "SUBMIC", "Sub Handset Mic", + "Sub Handset Mic", "Main Mic Bias", + "AFML", "Line In", + "AFMR", "Line In", + "DMic", "Digital Mic", + "Digital Mic", "Digital Mic1 Bias"; +}; diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c index 9d93793..1995a7f 100644 --- a/sound/soc/omap/omap-abe-twl6040.c +++ b/sound/soc/omap/omap-abe-twl6040.c @@ -25,6 +25,7 @@ #include <linux/mfd/twl6040.h> #include <linux/platform_data/omap-abe-twl6040.h> #include <linux/module.h> +#include <linux/of.h>
#include <sound/core.h> #include <sound/pcm.h> @@ -43,6 +44,8 @@ struct abe_twl6040 { int jack_detection; /* board can detect jack events */ int mclk_freq; /* MCLK frequency speed for twl6040 */ + + struct platform_device *dmic_codec_dev; };
static int omap_abe_hw_params(struct snd_pcm_substream *substream, @@ -185,17 +188,6 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) int hs_trim; int ret = 0;
- /* Disable not connected paths if not used */ - twl6040_disconnect_pin(dapm, pdata->has_hs, "Headset Stereophone"); - twl6040_disconnect_pin(dapm, pdata->has_hf, "Ext Spk"); - twl6040_disconnect_pin(dapm, pdata->has_ep, "Earphone Spk"); - twl6040_disconnect_pin(dapm, pdata->has_aux, "Line Out"); - twl6040_disconnect_pin(dapm, pdata->has_vibra, "Vinrator"); - twl6040_disconnect_pin(dapm, pdata->has_hsmic, "Headset Mic"); - twl6040_disconnect_pin(dapm, pdata->has_mainmic, "Main Handset Mic"); - twl6040_disconnect_pin(dapm, pdata->has_submic, "Sub Handset Mic"); - twl6040_disconnect_pin(dapm, pdata->has_afm, "Line In"); - /* * Configure McPDM offset cancellation based on the HSOTRIM value from * twl6040. @@ -216,6 +208,24 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); }
+ /* + * NULL pdata means we booted with DT. In this case the routing is + * provided and the card is fully routed, no need to mark pins. + */ + if (!pdata) + return ret; + + /* Disable not connected paths if not used */ + twl6040_disconnect_pin(dapm, pdata->has_hs, "Headset Stereophone"); + twl6040_disconnect_pin(dapm, pdata->has_hf, "Ext Spk"); + twl6040_disconnect_pin(dapm, pdata->has_ep, "Earphone Spk"); + twl6040_disconnect_pin(dapm, pdata->has_aux, "Line Out"); + twl6040_disconnect_pin(dapm, pdata->has_vibra, "Vinrator"); + twl6040_disconnect_pin(dapm, pdata->has_hsmic, "Headset Mic"); + twl6040_disconnect_pin(dapm, pdata->has_mainmic, "Main Handset Mic"); + twl6040_disconnect_pin(dapm, pdata->has_submic, "Sub Handset Mic"); + twl6040_disconnect_pin(dapm, pdata->has_afm, "Line In"); + return ret; }
@@ -270,52 +280,116 @@ static struct snd_soc_card omap_abe_card = { static __devinit int omap_abe_probe(struct platform_device *pdev) { struct omap_abe_twl6040_data *pdata = dev_get_platdata(&pdev->dev); + struct device_node *node = pdev->dev.of_node; struct snd_soc_card *card = &omap_abe_card; struct abe_twl6040 *priv; int num_links = 0; - int ret; + int ret = 0;
card->dev = &pdev->dev;
- if (!pdata) { - dev_err(&pdev->dev, "Missing pdata\n"); - return -ENODEV; - } - priv = devm_kzalloc(&pdev->dev, sizeof(struct abe_twl6040), GFP_KERNEL); if (priv == NULL) return -ENOMEM;
- if (pdata->card_name) { - card->name = pdata->card_name; + priv->dmic_codec_dev = ERR_PTR(-EINVAL); + + if (node) { + struct device_node *dai_node; + + if (snd_soc_of_parse_card_name(card, "ti,model")) { + dev_err(&pdev->dev, "Card name is not provided\n"); + return -ENODEV; + } + + ret = snd_soc_of_parse_audio_routing(card, + "ti,audio-routing"); + if (ret) { + dev_err(&pdev->dev, + "Error while parsing DAPM routing\n"); + return -EINVAL; + } + + dai_node = of_parse_phandle(node, "ti,mcpdm", 0); + if (!dai_node) { + dev_err(&pdev->dev, "McPDM node is not provided\n"); + return -EINVAL; + } + abe_twl6040_dai_links[0].cpu_dai_name = NULL; + abe_twl6040_dai_links[0].cpu_dai_of_node = dai_node; + + dai_node = of_parse_phandle(node, "ti,dmic", 0); + if (dai_node) { + num_links = 2; + abe_twl6040_dai_links[1].cpu_dai_name = NULL; + abe_twl6040_dai_links[1].cpu_dai_of_node = dai_node; + + priv->dmic_codec_dev = platform_device_register_simple( + "dmic-codec", -1, NULL, 0); + if (IS_ERR(priv->dmic_codec_dev)) { + dev_err(&pdev->dev, + "Can't instantiate dmic-codec\n"); + return PTR_ERR(priv->dmic_codec_dev); + } + } else { + num_links = 1; + } + + of_property_read_u32(node, "ti,jack-detection", + &priv->jack_detection); + of_property_read_u32(node, "ti,mclk-freq", + &priv->mclk_freq); + if (!priv->mclk_freq) { + dev_err(&pdev->dev, "MCLK frequency not provided\n"); + ret = -EINVAL; + goto err_unregister; + } + + omap_abe_card.fully_routed = 1; + } else if (pdata) { + if (pdata->card_name) { + card->name = pdata->card_name; + } else { + dev_err(&pdev->dev, "Card name is not provided\n"); + return -ENODEV; + } + + if (pdata->has_dmic) + num_links = 2; + else + num_links = 1; + + priv->jack_detection = pdata->jack_detection; + priv->mclk_freq = pdata->mclk_freq; } else { - dev_err(&pdev->dev, "Card name is not provided\n"); + dev_err(&pdev->dev, "Missing pdata\n"); return -ENODEV; }
- priv->jack_detection = pdata->jack_detection; - priv->mclk_freq = pdata->mclk_freq; -
if (!priv->mclk_freq) { dev_err(&pdev->dev, "MCLK frequency missing\n"); - return -ENODEV; + ret = -ENODEV; + goto err_unregister; }
- if (pdata->has_dmic) - num_links = 2; - else - num_links = 1; - card->dai_link = abe_twl6040_dai_links; card->num_links = num_links;
snd_soc_card_set_drvdata(card, priv);
ret = snd_soc_register_card(card); - if (ret) + if (ret) { dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); + goto err_unregister; + } + + return 0; + +err_unregister: + if (!IS_ERR(priv->dmic_codec_dev)) + platform_device_unregister(priv->dmic_codec_dev);
return ret; } @@ -323,17 +397,28 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) static int __devexit omap_abe_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); + struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card);
snd_soc_unregister_card(card);
+ if (!IS_ERR(priv->dmic_codec_dev)) + platform_device_unregister(priv->dmic_codec_dev); + return 0; }
+static const struct of_device_id omap_abe_of_match[] = { + {.compatible = "ti,abe-twl6040", }, + { }, +}; +MODULE_DEVICE_TABLE(of, omap_abe_of_match); + static struct platform_driver omap_abe_driver = { .driver = { .name = "omap-abe-twl6040", .owner = THIS_MODULE, .pm = &snd_soc_pm_ops, + .of_match_table = omap_abe_of_match, }, .probe = omap_abe_probe, .remove = __devexit_p(omap_abe_remove),
Hi Mark, Liam,
On 05/16/2012 02:57 PM, Peter Ujfalusi wrote:
When the board boots with device tree the driver will receive the name of the card, DAPM routing map, phandle for the audio components described in the dts file, mclk speed, and the possibility of detecting the jack detection.
The card will be set up based on this information. Since the routing is provided via DT we can mark the card fully routed so core can take care of disconnecting the unused pins.
Would you be able to take a look at this patch? The rest of the series has been already applied for 3.5 but this somehow missed the review.
Thank you, Péter
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com
.../devicetree/bindings/sound/omap-abe-twl6040.txt | 91 ++++++++++++ sound/soc/omap/omap-abe-twl6040.c | 145 ++++++++++++++++---- 2 files changed, 206 insertions(+), 30 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt
diff --git a/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt b/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt new file mode 100644 index 0000000..65dec87 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt @@ -0,0 +1,91 @@ +* Texas Instruments OMAP4+ and twl6040 based audio setups
+Required properties: +- compatible: "ti,abe-twl6040" +- ti,model: Name of the sound card ( for example "SDP4430") +- ti,mclk-freq: MCLK frequency for HPPLL operation +- ti,mcpdm: phandle for the McPDM node +- ti,twl6040: phandle for the twl6040 core node +- ti,audio-routing: List of connections between audio components.
- Each entry is a pair of strings, the first being the connection's sink,
- the second being the connection's source.
+Optional properties: +- ti,dmic: phandle for the OMAP dmic node if the machine have it connected +- ti,jack_detection: Need to be set to <1> if the board capable to detect jack
- insertion, removal.
+Available audio endpoints for the audio-routing table:
+Board connectors:
- Headset Stereophone
- Earphone Spk
- Ext Spk
- Line Out
- Vibrator
- Headset Mic
- Main Handset Mic
- Sub Handset Mic
- Line In
- Digital Mic
+twl6040 pins:
- HSOL
- HSOR
- EP
- HFL
- HFR
- AUXL
- AUXR
- VIBRAL
- VIBRAR
- HSMIC
- MAINMIC
- SUBMIC
- AFML
- AFMR
- Headset Mic Bias
- Main Mic Bias
- Digital Mic1 Bias
- Digital Mic2 Bias
+Digital mic pins:
- DMic
+Example:
+sound {
- compatible = "ti,abe-twl6040";
- ti,model = "SDP4430";
- ti,jack-detection = <1>;
- ti,mclk-freq = <38400000>;
- ti,mcpdm = <&mcpdm>;
- ti,dmic = <&dmic>;
- ti,twl6040 = <&twl6040>;
- /* Audio routing */
- ti,audio-routing =
"Headset Stereophone", "HSOL",
"Headset Stereophone", "HSOR",
"Earphone Spk", "EP",
"Ext Spk", "HFL",
"Ext Spk", "HFR",
"Line Out", "AUXL",
"Line Out", "AUXR",
"Vibrator", "VIBRAL",
"Vibrator", "VIBRAR",
"HSMIC", "Headset Mic",
"Headset Mic", "Headset Mic Bias",
"MAINMIC", "Main Handset Mic",
"Main Handset Mic", "Main Mic Bias",
"SUBMIC", "Sub Handset Mic",
"Sub Handset Mic", "Main Mic Bias",
"AFML", "Line In",
"AFMR", "Line In",
"DMic", "Digital Mic",
"Digital Mic", "Digital Mic1 Bias";
+}; diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c index 9d93793..1995a7f 100644 --- a/sound/soc/omap/omap-abe-twl6040.c +++ b/sound/soc/omap/omap-abe-twl6040.c @@ -25,6 +25,7 @@ #include <linux/mfd/twl6040.h> #include <linux/platform_data/omap-abe-twl6040.h> #include <linux/module.h> +#include <linux/of.h>
#include <sound/core.h> #include <sound/pcm.h> @@ -43,6 +44,8 @@ struct abe_twl6040 { int jack_detection; /* board can detect jack events */ int mclk_freq; /* MCLK frequency speed for twl6040 */
- struct platform_device *dmic_codec_dev;
};
static int omap_abe_hw_params(struct snd_pcm_substream *substream, @@ -185,17 +188,6 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) int hs_trim; int ret = 0;
- /* Disable not connected paths if not used */
- twl6040_disconnect_pin(dapm, pdata->has_hs, "Headset Stereophone");
- twl6040_disconnect_pin(dapm, pdata->has_hf, "Ext Spk");
- twl6040_disconnect_pin(dapm, pdata->has_ep, "Earphone Spk");
- twl6040_disconnect_pin(dapm, pdata->has_aux, "Line Out");
- twl6040_disconnect_pin(dapm, pdata->has_vibra, "Vinrator");
- twl6040_disconnect_pin(dapm, pdata->has_hsmic, "Headset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_mainmic, "Main Handset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_submic, "Sub Handset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_afm, "Line In");
- /*
- Configure McPDM offset cancellation based on the HSOTRIM value from
- twl6040.
@@ -216,6 +208,24 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); }
- /*
* NULL pdata means we booted with DT. In this case the routing is
* provided and the card is fully routed, no need to mark pins.
*/
- if (!pdata)
return ret;
- /* Disable not connected paths if not used */
- twl6040_disconnect_pin(dapm, pdata->has_hs, "Headset Stereophone");
- twl6040_disconnect_pin(dapm, pdata->has_hf, "Ext Spk");
- twl6040_disconnect_pin(dapm, pdata->has_ep, "Earphone Spk");
- twl6040_disconnect_pin(dapm, pdata->has_aux, "Line Out");
- twl6040_disconnect_pin(dapm, pdata->has_vibra, "Vinrator");
- twl6040_disconnect_pin(dapm, pdata->has_hsmic, "Headset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_mainmic, "Main Handset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_submic, "Sub Handset Mic");
- twl6040_disconnect_pin(dapm, pdata->has_afm, "Line In");
- return ret;
}
@@ -270,52 +280,116 @@ static struct snd_soc_card omap_abe_card = { static __devinit int omap_abe_probe(struct platform_device *pdev) { struct omap_abe_twl6040_data *pdata = dev_get_platdata(&pdev->dev);
- struct device_node *node = pdev->dev.of_node; struct snd_soc_card *card = &omap_abe_card; struct abe_twl6040 *priv; int num_links = 0;
- int ret;
int ret = 0;
card->dev = &pdev->dev;
if (!pdata) {
dev_err(&pdev->dev, "Missing pdata\n");
return -ENODEV;
}
priv = devm_kzalloc(&pdev->dev, sizeof(struct abe_twl6040), GFP_KERNEL); if (priv == NULL) return -ENOMEM;
if (pdata->card_name) {
card->name = pdata->card_name;
- priv->dmic_codec_dev = ERR_PTR(-EINVAL);
- if (node) {
struct device_node *dai_node;
if (snd_soc_of_parse_card_name(card, "ti,model")) {
dev_err(&pdev->dev, "Card name is not provided\n");
return -ENODEV;
}
ret = snd_soc_of_parse_audio_routing(card,
"ti,audio-routing");
if (ret) {
dev_err(&pdev->dev,
"Error while parsing DAPM routing\n");
return -EINVAL;
}
dai_node = of_parse_phandle(node, "ti,mcpdm", 0);
if (!dai_node) {
dev_err(&pdev->dev, "McPDM node is not provided\n");
return -EINVAL;
}
abe_twl6040_dai_links[0].cpu_dai_name = NULL;
abe_twl6040_dai_links[0].cpu_dai_of_node = dai_node;
dai_node = of_parse_phandle(node, "ti,dmic", 0);
if (dai_node) {
num_links = 2;
abe_twl6040_dai_links[1].cpu_dai_name = NULL;
abe_twl6040_dai_links[1].cpu_dai_of_node = dai_node;
priv->dmic_codec_dev = platform_device_register_simple(
"dmic-codec", -1, NULL, 0);
if (IS_ERR(priv->dmic_codec_dev)) {
dev_err(&pdev->dev,
"Can't instantiate dmic-codec\n");
return PTR_ERR(priv->dmic_codec_dev);
}
} else {
num_links = 1;
}
of_property_read_u32(node, "ti,jack-detection",
&priv->jack_detection);
of_property_read_u32(node, "ti,mclk-freq",
&priv->mclk_freq);
if (!priv->mclk_freq) {
dev_err(&pdev->dev, "MCLK frequency not provided\n");
ret = -EINVAL;
goto err_unregister;
}
omap_abe_card.fully_routed = 1;
- } else if (pdata) {
if (pdata->card_name) {
card->name = pdata->card_name;
} else {
dev_err(&pdev->dev, "Card name is not provided\n");
return -ENODEV;
}
if (pdata->has_dmic)
num_links = 2;
else
num_links = 1;
priv->jack_detection = pdata->jack_detection;
} else {priv->mclk_freq = pdata->mclk_freq;
dev_err(&pdev->dev, "Card name is not provided\n");
return -ENODEV; }dev_err(&pdev->dev, "Missing pdata\n");
priv->jack_detection = pdata->jack_detection;
priv->mclk_freq = pdata->mclk_freq;
if (!priv->mclk_freq) { dev_err(&pdev->dev, "MCLK frequency missing\n");
return -ENODEV;
ret = -ENODEV;
}goto err_unregister;
if (pdata->has_dmic)
num_links = 2;
else
num_links = 1;
card->dai_link = abe_twl6040_dai_links; card->num_links = num_links;
snd_soc_card_set_drvdata(card, priv);
ret = snd_soc_register_card(card);
if (ret)
- if (ret) { dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
goto err_unregister;
- }
- return 0;
+err_unregister:
if (!IS_ERR(priv->dmic_codec_dev))
platform_device_unregister(priv->dmic_codec_dev);
return ret;
} @@ -323,17 +397,28 @@ static __devinit int omap_abe_probe(struct platform_device *pdev) static int __devexit omap_abe_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev);
struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card);
snd_soc_unregister_card(card);
if (!IS_ERR(priv->dmic_codec_dev))
platform_device_unregister(priv->dmic_codec_dev);
return 0;
}
+static const struct of_device_id omap_abe_of_match[] = {
- {.compatible = "ti,abe-twl6040", },
- { },
+}; +MODULE_DEVICE_TABLE(of, omap_abe_of_match);
static struct platform_driver omap_abe_driver = { .driver = { .name = "omap-abe-twl6040", .owner = THIS_MODULE, .pm = &snd_soc_pm_ops,
}, .probe = omap_abe_probe, .remove = __devexit_p(omap_abe_remove),.of_match_table = omap_abe_of_match,
On Tue, Jun 05, 2012 at 04:06:01PM +0300, Peter Ujfalusi wrote:
Would you be able to take a look at this patch? The rest of the series has been already applied for 3.5 but this somehow missed the review.
Please resend this and the other patch you mentioned.
Hi Mark, Liam,
On 05/16/2012 02:57 PM, Peter Ujfalusi wrote:
Hello,
Changes since v1:
- Binding docukentation updated with available pins and connectors
- dts section for abe-twl6040 sound configuration has been changed
Can you take a look at patch 4 in this series? The rest of the series has been already applied for 3.5 but the 4th one has been missed.
Thank you, Péter
Instead of dai link pairs only the nodes probed via DT have phandle: ti,mcpdm; ti,dmic, ti,twl6040. The driver in turn is responsible to handle the provided information. To provide dai link pairs (cpu dai - codec) we would need Linux (ASoC) specific nodes in DT for the dmic codec and twl6040 ASoC codec driver.
If the DT section have ti,dmic phandle the ASoC machine driver will register the device to load the ASoC dmic-codec runtime.
Example dts section for audio support (SDP4430): sound { compatible = "ti,abe-twl6040"; ti,model = "SDP4430";
ti,jack-detection = <1>; ti,mclk-freq = <38400000>;
ti,mcpdm = <&mcpdm>; ti,dmic = <&dmic>;
ti,twl6040 = <&twl6040>;
/* Audio routing */ ti,audio-routing = "Headset Stereophone", "HSOL", "Headset Stereophone", "HSOR", "Earphone Spk", "EP", "Ext Spk", "HFL", "Ext Spk", "HFR", "Line Out", "AUXL", "Line Out", "AUXR", "Vibrator", "VIBRAL", "Vibrator", "VIBRAR", "HSMIC", "Headset Mic", "Headset Mic", "Headset Mic Bias", "MAINMIC", "Main Handset Mic", "Main Handset Mic", "Main Mic Bias", "SUBMIC", "Sub Handset Mic", "Sub Handset Mic", "Main Mic Bias", "AFML", "Line In", "AFMR", "Line In", "DMic", "Digital Mic", "Digital Mic", "Digital Mic1 Bias"; };
Regards, Peter
Peter Ujfalusi (4): ASoC: omap-abe-twl6040: Keep only one snd_soc_dai_link structure ASoC: omap-abe-twl6040: Move Digital Mic widget into dapm table ASoC: omap-abe-twl6040: Introduce driver data for runtime parameters ASoC: omap-abe-twl6040: Add device tree support
.../devicetree/bindings/sound/omap-abe-twl6040.txt | 91 +++++++++ sound/soc/omap/omap-abe-twl6040.c | 195 ++++++++++++++------ 2 files changed, 230 insertions(+), 56 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/omap-abe-twl6040.txt
On Tue, Jun 05, 2012 at 03:46:26PM +0300, Peter Ujfalusi wrote:
Can you take a look at patch 4 in this series? The rest of the series has been already applied for 3.5 but the 4th one has been missed.
If this happens you should resend the patch, there's a good chance people don't have a copy of it.
participants (2)
-
Mark Brown
-
Peter Ujfalusi