]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: Add C API support for BE and CC Links.
authorVedang Patel <vedang.patel@intel.com>
Thu, 5 Nov 2015 12:49:23 +0000 (20:49 +0800)
committerJaroslav Kysela <perex@perex.cz>
Thu, 5 Nov 2015 13:53:24 +0000 (14:53 +0100)
Adding BE and CC Link support for C API reference. This will be used
to populate the .hw_params element for BE and .params for CC, enabling
us to update already existing DAI Links created by the kernel.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/topology.h
src/topology/builder.c
src/topology/parser.c
src/topology/pcm.c

index 9b84bd9331dc4663dc7d209763536dc9f5c390fc..ccd69d7ae2d5115f05d9d5b88a7716c461120e79 100644 (file)
@@ -648,6 +648,28 @@ struct snd_tplg_widget_template {
        struct snd_tplg_ctl_template *ctl[0];   /*!< array of widget controls */
 };
 
+/** \struct snd_tplg_stream_template
+ * \brief Stream configurations.
+ */
+struct snd_tplg_stream_template {
+       const char *name;       /*!< name of the stream config */
+       int format;             /*!< SNDRV_PCM_FMTBIT_* */
+       int rate;               /*!< SNDRV_PCM_RATE_* */
+       int period_bytes;       /*!< size of period in bytes */
+       int buffer_bytes;       /*!< size of buffer in bytes. */
+       int channels;           /*!< number of channels */
+};
+
+/** \struct snd_tplg_link_template
+ * \brief Template type for BE and CC DAI Links.
+ */
+struct snd_tplg_link_template {
+       const char *name;       /*!< link name */
+       int id; /*!< unique ID - used to match with existing BE and CC links */
+       int num_streams;        /*!< number of configs */
+       struct snd_tplg_stream_template stream[0]; /*!< supported configs */
+};
+
 /** \struct snd_tplg_obj_template
  * \brief Generic Template Object
  */
@@ -662,6 +684,7 @@ typedef struct snd_tplg_obj_template {
                struct snd_tplg_bytes_template *bytes_ctl;      /*!< Bytes control */
                struct snd_tplg_enum_template *enum_ctl;        /*!< Enum control */
                struct snd_tplg_graph_template *graph;          /*!< Graph elements */
+               struct snd_tplg_link_template *link;            /*!< BE and CC Links */
        };
 } snd_tplg_obj_template_t;
 
index 8d57a8b719f7a37d803c0fb26869997869ef716e..154bd6302fe630dce89497126b6fdaf32f9d3f42 100644 (file)
@@ -221,10 +221,10 @@ static int write_block(snd_tplg_t *tplg, struct list_head *base,
                        SND_SOC_TPLG_TYPE_PCM, "pcm");
        case SND_TPLG_TYPE_BE:
                return write_elem_block(tplg, base, size,
-                       SND_SOC_TPLG_TYPE_DAI_LINK, "be");
+                       SND_SOC_TPLG_TYPE_BACKEND_LINK, "be");
        case SND_TPLG_TYPE_CC:
                return write_elem_block(tplg, base, size,
-                       SND_SOC_TPLG_TYPE_DAI_LINK, "cc");
+                       SND_SOC_TPLG_TYPE_CODEC_LINK, "cc");
        case SND_TPLG_TYPE_DATA:
                return write_elem_block(tplg, base, size,
                        SND_SOC_TPLG_TYPE_PDATA, "data");
index ab5ca1bc3780927c44742113251da7122690a25b..1851459f44b6b2dd76d32fa4e272ee77b1550d19 100644 (file)
@@ -311,6 +311,9 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
                return tplg_add_widget_object(tplg, t);
        case SND_TPLG_TYPE_DAPM_GRAPH:
                return tplg_add_graph_object(tplg, t);
+       case SND_TPLG_TYPE_BE:
+       case SND_TPLG_TYPE_CC:
+               return tplg_add_link_object(tplg, t);
        default:
                SNDERR("error: invalid object type %d\n", t->type);
                return -EINVAL;
index ec26f9c5a061ba97073a141baa628061431c884c..c2b2b9818ce097c696efbec15937dab98ae653d5 100644 (file)
@@ -480,3 +480,49 @@ int tplg_parse_cc(snd_tplg_t *tplg,
 
        return 0;
 }
+
+/* copy stream object */
+static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
+                               struct snd_tplg_stream_template *strm_tpl)
+{
+       elem_copy_text(strm->name, strm_tpl->name,
+               SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
+       strm->format = strm_tpl->format;
+       strm->rate = strm_tpl->rate;
+       strm->period_bytes = strm_tpl->period_bytes;
+       strm->buffer_bytes = strm_tpl->buffer_bytes;
+       strm->channels = strm_tpl->channels;
+}
+
+int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
+{
+       struct snd_tplg_link_template *link = t->link;
+       struct snd_soc_tplg_link_config *lk;
+       struct tplg_elem *elem;
+       int i;
+
+       if (t->type != SND_TPLG_TYPE_BE && t->type != SND_TPLG_TYPE_CC)
+               return -EINVAL;
+
+       /* here type can be either BE or CC. */
+       elem = tplg_elem_new_common(tplg, NULL, link->name, t->type);
+       if (!elem)
+               return -ENOMEM;
+
+       if (t->type == SND_TPLG_TYPE_BE) {
+               tplg_dbg("BE Link: %s", link->name);
+               lk = elem->be;
+       } else {
+               tplg_dbg("CC Link: %s", link->name);
+               lk = elem->cc;
+       }
+
+       lk->size = elem->size;
+       lk->id = link->id;
+       lk->num_streams = link->num_streams;
+
+       for (i = 0; i < lk->num_streams; i++)
+               tplg_add_stream_object(&lk->stream[i], &link->stream[i]);
+
+       return 0;
+}