From 4ca7deb1e15e0030d04051cf4285e88249ebe252 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 5 Aug 2015 22:34:22 +0800 Subject: ASoC: topology: Use kcalloc instead of kzalloc for array allocation Also remove unnecessary memset. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index d0960683c409..f038c6ef8005 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1070,7 +1070,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create( struct snd_soc_tplg_mixer_control *mc; int i, err; - kc = kzalloc(sizeof(*kc) * num_kcontrols, GFP_KERNEL); + kc = kcalloc(num_kcontrols, sizeof(*kc), GFP_KERNEL); if (kc == NULL) return NULL; @@ -1251,7 +1251,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create( struct snd_kcontrol_new *kc; int i, err; - kc = kzalloc(sizeof(*kc) * count, GFP_KERNEL); + kc = kcalloc(count, sizeof(*kc), GFP_KERNEL); if (!kc) return NULL; @@ -1274,7 +1274,6 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create( "ASoC: adding bytes kcontrol %s with access 0x%x\n", be->hdr.name, be->hdr.access); - memset(kc, 0, sizeof(*kc)); kc[i].name = be->hdr.name; kc[i].private_value = (long)sbe; kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; -- cgit v1.2.1 From 376c0afe2f0047d091956a95e382e1edd104ea72 Mon Sep 17 00:00:00 2001 From: Andrzej Hajda Date: Fri, 7 Aug 2015 09:59:37 +0200 Subject: ASoC: topology: use kmemdup rather than duplicating its implementation The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1]. [1]: http://permalink.gmane.org/gmane.linux.kernel/2014320 Signed-off-by: Andrzej Hajda Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index f038c6ef8005..8620dbf410c6 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -832,12 +832,12 @@ static int soc_tplg_denum_create_values(struct soc_enum *se, if (ec->items > sizeof(*ec->values)) return -EINVAL; - se->dobj.control.dvalues = - kmalloc(ec->items * sizeof(u32), GFP_KERNEL); + se->dobj.control.dvalues = kmemdup(ec->values, + ec->items * sizeof(u32), + GFP_KERNEL); if (!se->dobj.control.dvalues) return -ENOMEM; - memcpy(se->dobj.control.dvalues, ec->values, ec->items * sizeof(u32)); return 0; } -- cgit v1.2.1 From 1a8e7fab70c8d7cad2e606e7b21d46e42e51c2fd Mon Sep 17 00:00:00 2001 From: Mengdong Lin Date: Mon, 10 Aug 2015 22:48:30 +0800 Subject: ASoC: topology: Change pass number of DAI smaller than graph The PCM DAIs need to be loaded and added to ASoC core ealier than the graph (route). Otherwise, adding routes will fail for missing DAIs. Signed-off-by: Mengdong Lin Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 8620dbf410c6..942c1acd79d4 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -44,12 +44,12 @@ #define SOC_TPLG_PASS_VENDOR 1 #define SOC_TPLG_PASS_MIXER 2 #define SOC_TPLG_PASS_WIDGET 3 -#define SOC_TPLG_PASS_GRAPH 4 -#define SOC_TPLG_PASS_PINS 5 -#define SOC_TPLG_PASS_PCM_DAI 6 +#define SOC_TPLG_PASS_PCM_DAI 4 +#define SOC_TPLG_PASS_GRAPH 5 +#define SOC_TPLG_PASS_PINS 6 #define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST -#define SOC_TPLG_PASS_END SOC_TPLG_PASS_PCM_DAI +#define SOC_TPLG_PASS_END SOC_TPLG_PASS_PINS struct soc_tplg { const struct firmware *fw; -- cgit v1.2.1 From 88a17d8fb7c4a156ec13e6668b46dbbedf670ff7 Mon Sep 17 00:00:00 2001 From: Mengdong Lin Date: Tue, 18 Aug 2015 18:11:51 +0800 Subject: ASoC: topology: Bind vendor specific kcontrol handlers before standard ones Vendor specific handlers should override standard handlers. So we can handle things in the order from specific to generic. Signed-off-by: Mengdong Lin Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 73e959c105f0..ca551b9fd100 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -66,7 +66,7 @@ struct soc_tplg { u32 index; /* current block index */ u32 req_index; /* required index, only loaded/free matching blocks */ - /* kcontrol operations */ + /* vendor specific kcontrol operations */ const struct snd_soc_tplg_kcontrol_ops *io_ops; int io_ops_count; @@ -513,22 +513,7 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, { int i; - /* try and map standard kcontrols handler first */ - for (i = 0; i < num_ops; i++) { - - if (ops[i].id == hdr->ops.put) - k->put = ops[i].put; - if (ops[i].id == hdr->ops.get) - k->get = ops[i].get; - if (ops[i].id == hdr->ops.info) - k->info = ops[i].info; - } - - /* standard handlers found ? */ - if (k->put && k->get && k->info) - return 0; - - /* none found so try bespoke handlers */ + /* try and map vendor specific kcontrol handlers first */ for (i = 0; i < num_bops; i++) { if (k->put == NULL && bops[i].id == hdr->ops.put) @@ -539,7 +524,22 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, k->info = bops[i].info; } - /* bespoke handlers found ? */ + /* vendor specific handlers found ? */ + if (k->put && k->get && k->info) + return 0; + + /* none found so try standard kcontrol handlers */ + for (i = 0; i < num_ops; i++) { + + if (k->put == NULL && ops[i].id == hdr->ops.put) + k->put = ops[i].put; + if (k->get == NULL && ops[i].id == hdr->ops.get) + k->get = ops[i].get; + if (k->info == NULL && ops[i].id == hdr->ops.info) + k->info = ops[i].info; + } + + /* standard handlers found ? */ if (k->put && k->get && k->info) return 0; -- cgit v1.2.1 From 2b5cdb9156f76162d5302e2847f84a79de8a3ad1 Mon Sep 17 00:00:00 2001 From: Mengdong Lin Date: Tue, 18 Aug 2015 18:12:01 +0800 Subject: ASoC: topology: Reduce arguments of soc_tplg_kcontrol_bind_io() Add the pointer of struct soc_tplg as one argument, so no need to pass standard/vendor specific kcontrol handlers and their count. Signed-off-by: Mengdong Lin Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index ca551b9fd100..c4a58d7337b5 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -508,20 +508,22 @@ static void remove_pcm_dai(struct snd_soc_component *comp, /* bind a kcontrol to it's IO handlers */ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, struct snd_kcontrol_new *k, - const struct snd_soc_tplg_kcontrol_ops *ops, int num_ops, - const struct snd_soc_tplg_kcontrol_ops *bops, int num_bops) + const struct soc_tplg *tplg) { - int i; + const struct snd_soc_tplg_kcontrol_ops *ops; + int num_ops, i; /* try and map vendor specific kcontrol handlers first */ - for (i = 0; i < num_bops; i++) { - - if (k->put == NULL && bops[i].id == hdr->ops.put) - k->put = bops[i].put; - if (k->get == NULL && bops[i].id == hdr->ops.get) - k->get = bops[i].get; - if (k->info == NULL && bops[i].id == hdr->ops.info) - k->info = bops[i].info; + ops = tplg->io_ops; + num_ops = tplg->io_ops_count; + for (i = 0; i < num_ops; i++) { + + if (k->put == NULL && ops[i].id == hdr->ops.put) + k->put = ops[i].put; + if (k->get == NULL && ops[i].id == hdr->ops.get) + k->get = ops[i].get; + if (k->info == NULL && ops[i].id == hdr->ops.info) + k->info = ops[i].info; } /* vendor specific handlers found ? */ @@ -529,6 +531,8 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, return 0; /* none found so try standard kcontrol handlers */ + ops = io_ops; + num_ops = ARRAY_SIZE(io_ops); for (i = 0; i < num_ops; i++) { if (k->put == NULL && ops[i].id == hdr->ops.put) @@ -682,8 +686,7 @@ static int soc_tplg_dbytes_create(struct soc_tplg *tplg, unsigned int count, INIT_LIST_HEAD(&sbe->dobj.list); /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, tplg); if (err) { soc_control_err(tplg, &be->hdr, be->hdr.name); kfree(sbe); @@ -777,8 +780,7 @@ static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, INIT_LIST_HEAD(&sm->dobj.list); /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, tplg); if (err) { soc_control_err(tplg, &mc->hdr, mc->hdr.name); kfree(sm); @@ -950,8 +952,7 @@ static int soc_tplg_denum_create(struct soc_tplg *tplg, unsigned int count, } /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, tplg); if (err) { soc_control_err(tplg, &ec->hdr, ec->hdr.name); kfree(se); @@ -1137,8 +1138,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create( INIT_LIST_HEAD(&sm->dobj.list); /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc[i], io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc[i], tplg); if (err) { soc_control_err(tplg, &mc->hdr, mc->hdr.name); kfree(sm); @@ -1235,8 +1235,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create( } /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, tplg); if (err) { soc_control_err(tplg, &ec->hdr, ec->hdr.name); goto err_se; @@ -1306,9 +1305,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create( INIT_LIST_HEAD(&sbe->dobj.list); /* map standard io handlers and check for external handlers */ - err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc[i], io_ops, - ARRAY_SIZE(io_ops), tplg->io_ops, - tplg->io_ops_count); + err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc[i], tplg); if (err) { soc_control_err(tplg, &be->hdr, be->hdr.name); kfree(sbe); -- cgit v1.2.1 From 1a3232d2f61d2853a848464b7bde2d54960c58bb Mon Sep 17 00:00:00 2001 From: Mengdong Lin Date: Tue, 18 Aug 2015 18:12:20 +0800 Subject: ASoC: topology: Add support for TLV bytes controls Allow vendor drivers to define bespoke bytes ext handlers and IDs for TLV bytes controls. And the topology core will bind these handlers by matching IDs defined by the vendor driver and user space topology data file. And TLV callback binding is moved to soc_tplg_kcontrol_bind_io(). This function process all handler binding now. Signed-off-by: Mengdong Lin Signed-off-by: Mark Brown --- sound/soc/soc-topology.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'sound/soc/soc-topology.c') diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index c4a58d7337b5..5690b7e7172e 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -70,6 +70,10 @@ struct soc_tplg { const struct snd_soc_tplg_kcontrol_ops *io_ops; int io_ops_count; + /* vendor specific bytes ext handlers, for TLV bytes controls */ + const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops; + int bytes_ext_ops_count; + /* optional fw loading callbacks to component drivers */ struct snd_soc_tplg_ops *ops; }; @@ -511,8 +515,40 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, const struct soc_tplg *tplg) { const struct snd_soc_tplg_kcontrol_ops *ops; + const struct snd_soc_tplg_bytes_ext_ops *ext_ops; int num_ops, i; + if (hdr->ops.info == SND_SOC_TPLG_CTL_BYTES + && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER + && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE + && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { + struct soc_bytes_ext *sbe; + struct snd_soc_tplg_bytes_control *be; + + sbe = (struct soc_bytes_ext *)k->private_value; + be = container_of(hdr, struct snd_soc_tplg_bytes_control, hdr); + + /* TLV bytes controls need standard kcontrol info handler, + * TLV callback and extended put/get handlers. + */ + k->info = snd_soc_bytes_info; + k->tlv.c = snd_soc_bytes_tlv_callback; + + ext_ops = tplg->bytes_ext_ops; + num_ops = tplg->bytes_ext_ops_count; + for (i = 0; i < num_ops; i++) { + if (!sbe->put && ext_ops[i].id == be->ext_ops.put) + sbe->put = ext_ops[i].put; + if (!sbe->get && ext_ops[i].id == be->ext_ops.get) + sbe->get = ext_ops[i].get; + } + + if (sbe->put && sbe->get) + return 0; + else + return -EINVAL; + } + /* try and map vendor specific kcontrol handlers first */ ops = tplg->io_ops; num_ops = tplg->io_ops_count; @@ -613,9 +649,7 @@ static int soc_tplg_create_tlv(struct soc_tplg *tplg, if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)) return 0; - if (tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { - kc->tlv.c = snd_soc_bytes_tlv_callback; - } else { + if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)) { tplg_tlv = &tc->tlv; switch (tplg_tlv->type) { case SNDRV_CTL_TLVT_DB_SCALE: @@ -1733,6 +1767,8 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp, tplg.req_index = id; tplg.io_ops = ops->io_ops; tplg.io_ops_count = ops->io_ops_count; + tplg.bytes_ext_ops = ops->bytes_ext_ops; + tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count; return soc_tplg_load(&tplg); } -- cgit v1.2.1