Re: [PATCH v8] ASoC: dapm: add code to configure dai link parameters

2015-01-16 Thread Charles Keepax
On Thu, Jan 15, 2015 at 02:07:11PM +, Nikesh Oswal wrote:
> dai-link params for codec-codec links were fixed. The fixed
> link between codec and another chip which may be another codec,
> baseband, bluetooth codec etc may require run time configuaration
> changes. This change provides an optional alsa control to select
> one of the params from a list of params.
> 
> Signed-off-by: Nikesh Oswal 
> ---
>  include/sound/soc-dapm.h |3 +
>  include/sound/soc.h  |1 +
>  sound/soc/soc-core.c |6 +-
>  sound/soc/soc-dapm.c |  155 
> --
>  4 files changed, 157 insertions(+), 8 deletions(-)
> 
> diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
> index 5c0a798..a2098e4 100644
> @@ -3299,14 +3363,52 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
>   struct snd_soc_dapm_widget *w;
>   size_t len;
>   char *link_name;
> - int ret;
> + int ret, count;
> + unsigned long private_value;
> + const char **w_param_text;
> + struct soc_enum w_param_enum[] = {
> + SOC_ENUM_SINGLE(0, 0, 0, NULL),
> + };
> + struct snd_kcontrol_new kcontrol_dai_link[] = {
> + SOC_ENUM_EXT(NULL, w_param_enum[0],
> +  snd_soc_dapm_dai_link_get,
> +  snd_soc_dapm_dai_link_put),
> + };
> + const struct snd_soc_pcm_stream *config = params;
> +
> + w_param_text = devm_kcalloc(card->dev, num_params,
> + sizeof(char *), GFP_KERNEL);
> + if (!w_param_text)
> + return -ENOMEM;
>  
>   len = strlen(source->name) + strlen(sink->name) + 2;
>   link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
> - if (!link_name)
> - return -ENOMEM;
> + if (!link_name) {
> + ret = -ENOMEM;
> + goto outfree_w_param;
> + }
>   snprintf(link_name, len, "%s-%s", source->name, sink->name);
>  
> + for (count = 0 ; count < num_params; count++) {
> + if (!config->stream_name) {
> + dev_warn(card->dapm.dev,
> + "ASoC: anonymous config %d for dai link %s\n",
> + count, link_name);

The ALSA core doesn't like one of the string in the enum text
links being a NULL pointer so you will want to add some sort of
default text or something in this case.

> + } else {
> + w_param_text[count] = devm_kmemdup(card->dev,
> + config->stream_name,
> + strlen(config->stream_name) + 1,
> + GFP_KERNEL);
> + if (!w_param_text[count]) {
> + ret = -ENOMEM;
> + goto outfree_link_name;
> + }
> + }
> + config++;
> + }
> + w_param_enum[0].items = num_params;
> + w_param_enum[0].texts = w_param_text;
> +
>   memset(, 0, sizeof(template));
>   template.reg = SND_SOC_NOPM;
>   template.id = snd_soc_dapm_dai_link;

Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v8] ASoC: dapm: add code to configure dai link parameters

2015-01-16 Thread Charles Keepax
On Thu, Jan 15, 2015 at 02:07:11PM +, Nikesh Oswal wrote:
 dai-link params for codec-codec links were fixed. The fixed
 link between codec and another chip which may be another codec,
 baseband, bluetooth codec etc may require run time configuaration
 changes. This change provides an optional alsa control to select
 one of the params from a list of params.
 
 Signed-off-by: Nikesh Oswal nik...@opensource.wolfsonmicro.com
 ---
  include/sound/soc-dapm.h |3 +
  include/sound/soc.h  |1 +
  sound/soc/soc-core.c |6 +-
  sound/soc/soc-dapm.c |  155 
 --
  4 files changed, 157 insertions(+), 8 deletions(-)
 
 diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
 index 5c0a798..a2098e4 100644
 @@ -3299,14 +3363,52 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
   struct snd_soc_dapm_widget *w;
   size_t len;
   char *link_name;
 - int ret;
 + int ret, count;
 + unsigned long private_value;
 + const char **w_param_text;
 + struct soc_enum w_param_enum[] = {
 + SOC_ENUM_SINGLE(0, 0, 0, NULL),
 + };
 + struct snd_kcontrol_new kcontrol_dai_link[] = {
 + SOC_ENUM_EXT(NULL, w_param_enum[0],
 +  snd_soc_dapm_dai_link_get,
 +  snd_soc_dapm_dai_link_put),
 + };
 + const struct snd_soc_pcm_stream *config = params;
 +
 + w_param_text = devm_kcalloc(card-dev, num_params,
 + sizeof(char *), GFP_KERNEL);
 + if (!w_param_text)
 + return -ENOMEM;
  
   len = strlen(source-name) + strlen(sink-name) + 2;
   link_name = devm_kzalloc(card-dev, len, GFP_KERNEL);
 - if (!link_name)
 - return -ENOMEM;
 + if (!link_name) {
 + ret = -ENOMEM;
 + goto outfree_w_param;
 + }
   snprintf(link_name, len, %s-%s, source-name, sink-name);
  
 + for (count = 0 ; count  num_params; count++) {
 + if (!config-stream_name) {
 + dev_warn(card-dapm.dev,
 + ASoC: anonymous config %d for dai link %s\n,
 + count, link_name);

The ALSA core doesn't like one of the string in the enum text
links being a NULL pointer so you will want to add some sort of
default text or something in this case.

 + } else {
 + w_param_text[count] = devm_kmemdup(card-dev,
 + config-stream_name,
 + strlen(config-stream_name) + 1,
 + GFP_KERNEL);
 + if (!w_param_text[count]) {
 + ret = -ENOMEM;
 + goto outfree_link_name;
 + }
 + }
 + config++;
 + }
 + w_param_enum[0].items = num_params;
 + w_param_enum[0].texts = w_param_text;
 +
   memset(template, 0, sizeof(template));
   template.reg = SND_SOC_NOPM;
   template.id = snd_soc_dapm_dai_link;

Thanks,
Charles
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v8] ASoC: dapm: add code to configure dai link parameters

2015-01-15 Thread Nikesh Oswal
dai-link params for codec-codec links were fixed. The fixed
link between codec and another chip which may be another codec,
baseband, bluetooth codec etc may require run time configuaration
changes. This change provides an optional alsa control to select
one of the params from a list of params.

Signed-off-by: Nikesh Oswal 
---
 include/sound/soc-dapm.h |3 +
 include/sound/soc.h  |1 +
 sound/soc/soc-core.c |6 +-
 sound/soc/soc-dapm.c |  155 --
 4 files changed, 157 insertions(+), 8 deletions(-)

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 5c0a798..a2098e4 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -378,6 +378,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card 
*card);
 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
 const struct snd_soc_pcm_stream *params,
+unsigned int num_params,
 struct snd_soc_dapm_widget *source,
 struct snd_soc_dapm_widget *sink);
 
@@ -531,6 +532,8 @@ struct snd_soc_dapm_widget {
void *priv; /* widget specific data */
struct regulator *regulator;/* attached regulator */
const struct snd_soc_pcm_stream *params; /* params for dai links */
+   unsigned int num_params; /* number of params for dai links */
+   unsigned int params_select; /* currently selected param for dai link */
 
/* dapm control */
int reg;/* negative reg = no direct 
dapm */
diff --git a/include/sound/soc.h b/include/sound/soc.h
index edd4a0a..7556885 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -940,6 +940,7 @@ struct snd_soc_dai_link {
int be_id;  /* optional ID for machine driver BE identification */
 
const struct snd_soc_pcm_stream *params;
+   unsigned int num_params;
 
unsigned int dai_fmt;   /* format to set on init */
 
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index ededb97..893a6e5 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1230,7 +1230,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
capture_w = cpu_dai->capture_widget;
if (play_w && capture_w) {
ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-  capture_w, play_w);
+  dai_link->num_params, capture_w,
+  play_w);
if (ret != 0) {
dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
play_w->name, capture_w->name, ret);
@@ -1242,7 +1243,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
capture_w = codec_dai->capture_widget;
if (play_w && capture_w) {
ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-  capture_w, play_w);
+  dai_link->num_params, capture_w,
+  play_w);
if (ret != 0) {
dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
play_w->name, capture_w->name, ret);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index bc2d7a0..286413b 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -853,6 +853,36 @@ static int dapm_new_pga(struct snd_soc_dapm_widget *w)
return 0;
 }
 
+/* create new dapm dai link control */
+static int dapm_new_dai_link(struct snd_soc_dapm_widget *w)
+{
+   int i, ret;
+   struct snd_kcontrol *kcontrol;
+   struct snd_soc_dapm_context *dapm = w->dapm;
+   struct snd_card *card = dapm->card->snd_card;
+
+   /* create control for links with > 1 config */
+   if (w->num_params <= 1)
+   return 0;
+
+   /* add kcontrol */
+   for (i = 0; i < w->num_kcontrols; i++) {
+   kcontrol = snd_soc_cnew(>kcontrol_news[i], w,
+   w->name, NULL);
+   ret = snd_ctl_add(card, kcontrol);
+   if (ret < 0) {
+   dev_err(dapm->dev,
+   "ASoC: failed to add widget %s dapm kcontrol 
%s: %d\n",
+   w->name, w->kcontrol_news[i].name, ret);
+   return ret;
+   }
+   kcontrol->private_data = w;
+   w->kcontrols[i] = kcontrol;
+   }
+
+   return 0;
+}
+
 /* We implement power down on suspend by checking the power state of
  * the ALSA card - when we are suspending the ALSA state for the card
  * is set to D3.
@@ -2724,6 +2754,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
  

[PATCH v8] ASoC: dapm: add code to configure dai link parameters

2015-01-15 Thread Nikesh Oswal
dai-link params for codec-codec links were fixed. The fixed
link between codec and another chip which may be another codec,
baseband, bluetooth codec etc may require run time configuaration
changes. This change provides an optional alsa control to select
one of the params from a list of params.

Signed-off-by: Nikesh Oswal nik...@opensource.wolfsonmicro.com
---
 include/sound/soc-dapm.h |3 +
 include/sound/soc.h  |1 +
 sound/soc/soc-core.c |6 +-
 sound/soc/soc-dapm.c |  155 --
 4 files changed, 157 insertions(+), 8 deletions(-)

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 5c0a798..a2098e4 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -378,6 +378,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card 
*card);
 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
 const struct snd_soc_pcm_stream *params,
+unsigned int num_params,
 struct snd_soc_dapm_widget *source,
 struct snd_soc_dapm_widget *sink);
 
@@ -531,6 +532,8 @@ struct snd_soc_dapm_widget {
void *priv; /* widget specific data */
struct regulator *regulator;/* attached regulator */
const struct snd_soc_pcm_stream *params; /* params for dai links */
+   unsigned int num_params; /* number of params for dai links */
+   unsigned int params_select; /* currently selected param for dai link */
 
/* dapm control */
int reg;/* negative reg = no direct 
dapm */
diff --git a/include/sound/soc.h b/include/sound/soc.h
index edd4a0a..7556885 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -940,6 +940,7 @@ struct snd_soc_dai_link {
int be_id;  /* optional ID for machine driver BE identification */
 
const struct snd_soc_pcm_stream *params;
+   unsigned int num_params;
 
unsigned int dai_fmt;   /* format to set on init */
 
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index ededb97..893a6e5 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1230,7 +1230,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
capture_w = cpu_dai-capture_widget;
if (play_w  capture_w) {
ret = snd_soc_dapm_new_pcm(card, dai_link-params,
-  capture_w, play_w);
+  dai_link-num_params, capture_w,
+  play_w);
if (ret != 0) {
dev_err(card-dev, ASoC: Can't link %s to %s: %d\n,
play_w-name, capture_w-name, ret);
@@ -1242,7 +1243,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
capture_w = codec_dai-capture_widget;
if (play_w  capture_w) {
ret = snd_soc_dapm_new_pcm(card, dai_link-params,
-  capture_w, play_w);
+  dai_link-num_params, capture_w,
+  play_w);
if (ret != 0) {
dev_err(card-dev, ASoC: Can't link %s to %s: %d\n,
play_w-name, capture_w-name, ret);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index bc2d7a0..286413b 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -853,6 +853,36 @@ static int dapm_new_pga(struct snd_soc_dapm_widget *w)
return 0;
 }
 
+/* create new dapm dai link control */
+static int dapm_new_dai_link(struct snd_soc_dapm_widget *w)
+{
+   int i, ret;
+   struct snd_kcontrol *kcontrol;
+   struct snd_soc_dapm_context *dapm = w-dapm;
+   struct snd_card *card = dapm-card-snd_card;
+
+   /* create control for links with  1 config */
+   if (w-num_params = 1)
+   return 0;
+
+   /* add kcontrol */
+   for (i = 0; i  w-num_kcontrols; i++) {
+   kcontrol = snd_soc_cnew(w-kcontrol_news[i], w,
+   w-name, NULL);
+   ret = snd_ctl_add(card, kcontrol);
+   if (ret  0) {
+   dev_err(dapm-dev,
+   ASoC: failed to add widget %s dapm kcontrol 
%s: %d\n,
+   w-name, w-kcontrol_news[i].name, ret);
+   return ret;
+   }
+   kcontrol-private_data = w;
+   w-kcontrols[i] = kcontrol;
+   }
+
+   return 0;
+}
+
 /* We implement power down on suspend by checking the power state of
  * the ALSA card - when we are suspending the ALSA state for the card
  * is set to D3.
@@ -2724,6 +2754,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)