[alsa-devel] [PATCH v2 0/3] ASoC: topology: UAPI updates for TLV, ops and types
This series updates the topology UAPI to allow easier addition of new TLV object types, generic operations and added a private data type for the kernel topology core.
Changes since V1
* Split into several patches for UAPI changes. * Fixed {} usage in if statement. * Added __le32 data[SND_SOC_TPLG_TLV_SIZE] back to struct snd_soc_tplg_ctl_tlv
Liam Girdwood (1): ASoC: topology: Add private data type and bump ABI version to 3
Mengdong Lin (2): ASoC: topology: Update TLV support so we can support more TLV types ASoC: topology: Add ops support to byte controls UAPI
include/uapi/sound/asoc.h | 33 ++++++++++++++++++--------- sound/soc/soc-topology.c | 58 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 28 deletions(-)
From: Mengdong Lin mengdong.lin@intel.com
Currently the TLV topology structure is targeted at only supporting the DB scale data. This patch extends support for the other TLV types so they can be easily added at a later stage.
TLV structure is moved to common topology control header since it's a common field for controls and can be processed in a general way.
Users must set a proper access flag for a control since it's used to decide if the TLV field is valid and if a TLV callback is needed.
Removed the following fields from topology TLV struct: - size/count: type can decide the size. - numid: not needed to initialize TLV for kcontrol. - data: replaced by the type specific struct.
Added TLV structure to generic control header and removed TLV structure from mixer control.
Signed-off-by: Mengdong Lin mengdong.lin@intel.com Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- include/uapi/sound/asoc.h | 19 +++++++++++----- sound/soc/soc-topology.c | 58 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 2819fc1..aa3a79b 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -137,11 +137,19 @@ struct snd_soc_tplg_private { /* * Kcontrol TLV data. */ +struct snd_soc_tplg_tlv_dbscale { + __le32 min; + __le32 step; + __le32 mute; +} __attribute__((packed)); + struct snd_soc_tplg_ctl_tlv { - __le32 size; /* in bytes aligned to 4 */ - __le32 numid; /* control element numeric identification */ - __le32 count; /* number of elem in data array */ - __le32 data[SND_SOC_TPLG_TLV_SIZE]; + __le32 size; /* in bytes of this structure */ + __le32 type; /* SNDRV_CTL_TLVT_*, type of TLV */ + union { + __le32 data[SND_SOC_TPLG_TLV_SIZE]; + struct snd_soc_tplg_tlv_dbscale scale; + }; } __attribute__((packed));
/* @@ -172,7 +180,7 @@ struct snd_soc_tplg_ctl_hdr { char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; __le32 access; struct snd_soc_tplg_kcontrol_ops_id ops; - __le32 tlv_size; /* non zero means control has TLV data */ + struct snd_soc_tplg_ctl_tlv tlv; } __attribute__((packed));
/* @@ -260,7 +268,6 @@ struct snd_soc_tplg_mixer_control { __le32 invert; __le32 num_channels; struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; - struct snd_soc_tplg_ctl_tlv tlv; struct snd_soc_tplg_private priv; } __attribute__((packed));
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index df3ddf0..2799abe 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -33,6 +33,7 @@ #include <sound/soc.h> #include <sound/soc-dapm.h> #include <sound/soc-topology.h> +#include <sound/tlv.h>
/* * We make several passes over the data (since it wont necessarily be ordered) @@ -579,28 +580,51 @@ static int soc_tplg_init_kcontrol(struct soc_tplg *tplg, return 0; }
+ +static int soc_tplg_create_tlv_db_scale(struct soc_tplg *tplg, + struct snd_kcontrol_new *kc, struct snd_soc_tplg_tlv_dbscale *scale) +{ + unsigned int item_len = 2 * sizeof(unsigned int); + unsigned int *p; + + p = kzalloc(item_len + 2 * sizeof(unsigned int), GFP_KERNEL); + if (!p) + return -ENOMEM; + + p[0] = SNDRV_CTL_TLVT_DB_SCALE; + p[1] = item_len; + p[2] = scale->min; + p[3] = (scale->step & TLV_DB_SCALE_MASK) + | (scale->mute ? TLV_DB_SCALE_MUTE : 0); + + kc->tlv.p = (void *)p; + return 0; +} + static int soc_tplg_create_tlv(struct soc_tplg *tplg, - struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_tlv *tplg_tlv) + struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_hdr *tc) { - struct snd_ctl_tlv *tlv; - int size; + struct snd_soc_tplg_ctl_tlv *tplg_tlv;
- if (tplg_tlv->count == 0) + if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)) return 0;
- size = ((tplg_tlv->count + (sizeof(unsigned int) - 1)) & - ~(sizeof(unsigned int) - 1)); - tlv = kzalloc(sizeof(*tlv) + size, GFP_KERNEL); - if (tlv == NULL) - return -ENOMEM; - - dev_dbg(tplg->dev, " created TLV type %d size %d bytes\n", - tplg_tlv->numid, size); + if (tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { + kc->tlv.c = snd_soc_bytes_tlv_callback; + } else { + tplg_tlv = &tc->tlv; + switch (tplg_tlv->type) { + case SNDRV_CTL_TLVT_DB_SCALE: + return soc_tplg_create_tlv_db_scale(tplg, kc, + &tplg_tlv->scale);
- tlv->numid = tplg_tlv->numid; - tlv->length = size; - memcpy(&tlv->tlv[0], tplg_tlv->data, size); - kc->tlv.p = (void *)tlv; + /* TODO: add support for other TLV types */ + default: + dev_dbg(tplg->dev, "Unsupported TLV type %d\n", + tplg_tlv->type); + return -EINVAL; + } + }
return 0; } @@ -772,7 +796,7 @@ static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, }
/* create any TLV data */ - soc_tplg_create_tlv(tplg, &kc, &mc->tlv); + soc_tplg_create_tlv(tplg, &kc, &mc->hdr);
/* register control here */ err = soc_tplg_add_kcontrol(tplg, &kc,
From: Mengdong Lin mengdong.lin@intel.com
Add UAPI support for setting byte control ops. Rename the ops structure to be more generic so it can be sued by other objects too.
Signed-off-by: Mengdong Lin mengdong.lin@intel.com Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- include/uapi/sound/asoc.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index aa3a79b..d5281ac 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -163,9 +163,11 @@ struct snd_soc_tplg_channel { } __attribute__((packed));
/* - * Kcontrol Operations IDs + * Genericl Operations IDs, for binding Kcontrol or Bytes ext ops + * Kcontrol ops need get/put/info. + * Bytes ext ops need get/put. */ -struct snd_soc_tplg_kcontrol_ops_id { +struct snd_soc_tplg_io_ops { __le32 get; __le32 put; __le32 info; @@ -179,7 +181,7 @@ struct snd_soc_tplg_ctl_hdr { __le32 type; char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; __le32 access; - struct snd_soc_tplg_kcontrol_ops_id ops; + struct snd_soc_tplg_io_ops ops; struct snd_soc_tplg_ctl_tlv tlv; } __attribute__((packed));
@@ -311,6 +313,7 @@ struct snd_soc_tplg_bytes_control { __le32 mask; __le32 base; __le32 num_regs; + struct snd_soc_tplg_io_ops ext_ops; struct snd_soc_tplg_private priv; } __attribute__((packed));
Add ID for standalone private data object types and bump ABI version to 3 in order to userpsace features.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- include/uapi/sound/asoc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index d5281ac..51b8066 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -77,7 +77,7 @@ #define SND_SOC_TPLG_NUM_TEXTS 16
/* ABI version */ -#define SND_SOC_TPLG_ABI_VERSION 0x2 +#define SND_SOC_TPLG_ABI_VERSION 0x3
/* Max size of TLV data */ #define SND_SOC_TPLG_TLV_SIZE 32 @@ -97,7 +97,8 @@ #define SND_SOC_TPLG_TYPE_PCM 7 #define SND_SOC_TPLG_TYPE_MANIFEST 8 #define SND_SOC_TPLG_TYPE_CODEC_LINK 9 -#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_CODEC_LINK +#define SND_SOC_TPLG_TYPE_PDATA 10 +#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_PDATA
/* vendor block IDs - please add new vendor types to end */ #define SND_SOC_TPLG_TYPE_VENDOR_FW 1000
On Wed, Aug 05, 2015 at 02:41:12PM +0100, Liam Girdwood wrote:
This series updates the topology UAPI to allow easier addition of new TLV object types, generic operations and added a private data type for the kernel topology core.
Takashi, are you OK with these? We'll need to update both the library and kernel, and ideally get these into v4.2 so we don't have the old ABI in a release.
On Thu, 06 Aug 2015 12:16:31 +0200, Mark Brown wrote:
On Wed, Aug 05, 2015 at 02:41:12PM +0100, Liam Girdwood wrote:
This series updates the topology UAPI to allow easier addition of new TLV object types, generic operations and added a private data type for the kernel topology core.
Takashi, are you OK with these? We'll need to update both the library and kernel, and ideally get these into v4.2 so we don't have the old ABI in a release.
Yes, agreed that it's better to be put in 4.2. Since there is no consumer of topology API yet in the upstream, it must be relatively safe even at this late stage.
thanks,
Takashi
On Thu, 06 Aug 2015 12:20:52 +0200, Takashi Iwai wrote:
On Thu, 06 Aug 2015 12:16:31 +0200, Mark Brown wrote:
On Wed, Aug 05, 2015 at 02:41:12PM +0100, Liam Girdwood wrote:
This series updates the topology UAPI to allow easier addition of new TLV object types, generic operations and added a private data type for the kernel topology core.
Takashi, are you OK with these? We'll need to update both the library and kernel, and ideally get these into v4.2 so we don't have the old ABI in a release.
Yes, agreed that it's better to be put in 4.2. Since there is no consumer of topology API yet in the upstream, it must be relatively safe even at this late stage.
Oh BTW it'd be appreciated if I can get a pull request in tomorrow, so that this stuff gets merged in 4.2-rc6.
thanks,
Takashi
participants (3)
-
Liam Girdwood
-
Mark Brown
-
Takashi Iwai