Enable using multiple different type kcontrols for widgets
Subsystems (3)
v3 cover Enable using multiple different type kcontrols for widgets
Hi,
This is a patch v3 for enabling multiple different types of kcontrols for a dapm widget.
Currently asoc allows to define and parse multiple same type kcontrols for single widget. So you can have for example two volume controls in a widget but not one byte and one enum control. Lately we've seen couple of cases where different types of controls would be useful and alsa topology actually allows you to create these.
This patch refactors the dapm kcontrol parsing by lifting the creation loop and memory allocation up one level and making the type variable to hold multiple type values. Sof driver is modified to use this type information in the same patch as it is quite cumbersome to split the changes nicely.
changes since v2:
- only 1 patch for not breaking bisect
- sof internal reviews -> minor changes + reviewed by tags
- no upstream comments after v2 -> assuming I'm on the right track here
Jaska Uimonen (1):
ASoC: dapm: Add support for multiple kcontrol types to a widget
include/sound/soc-topology.h | 2 +- sound/soc/soc-topology.c | 466 +++++++++++++++++------------------ sound/soc/sof/topology.c | 15 +- 3 files changed, 233 insertions(+), 250 deletions(-)
Signature · 1 line
2.24.1
PATCH v3 1/1 ASoC: dapm: Add support for multiple kcontrol types to a widget
Current dapm widget has a single variable to describe its kcontrol's type. As there can be many kcontrols in one widget it is inherently presumed that the types are the same.
Lately there has been use cases where different types of kcontrols would be needed for a single widget. Thus add pointer to dapm widget to hold an array for different kcontrol types and modify the kcontrol creation to operate in a loop based on individual kcontrol type.
Change control creation and deletion to use individual kcontrol types in SOF driver. This is done in the same patch for not breaking bisect. SOF driver is also currently the only one using the dapm widget kcontrol_type.
--- include/sound/soc-topology.h | 2 +- sound/soc/soc-topology.c | 466 +++++++++++++++++------------------ sound/soc/sof/topology.c | 15 +- 3 files changed, 233 insertions(+), 250 deletions(-)
include/sound/soc-topology.h +1 -1
@@ -54,7 +54,7 @@ struct snd_soc_dobj_control {/* dynamic widget object */ struct snd_soc_dobj_widget { -unsigned int kcontrol_type;/* kcontrol type: mixer, enum, bytes */ +unsigned int *kcontrol_type;/* kcontrol type: mixer, enum, bytes */ };/* generic dynamic object - all dynamic objects belong to this struct */
sound/soc/soc-topology.c +223 -243
550 lines not on this page · raw message
sound/soc/sof/topology.c +9 -6
@@ -1063,6 +1063,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp, scontrol->min_volume_step =le32_to_cpu (mc->min); scontrol->max_volume_step =le32_to_cpu (mc->max); scontrol->num_channels =le32_to_cpu (mc->num_channels); + scontrol->control_data->index = kc->index;/* set cmd for mixer control */ if (le32_to_cpu (mc->max) ==1 ) {
@@ -1140,7 +1141,7 @@ static int sof_control_load_enum(struct snd_soc_component *scomp, scontrol->comp_id = sdev->next_comp_id; scontrol->num_channels =le32_to_cpu (ec->num_channels); - + scontrol->control_data->index = kc->index; scontrol->cmd =SOF_CTRL_CMD_ENUM ; dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d comp_id %d\n",
@@ -1188,6 +1189,7 @@ static int sof_control_load_bytes(struct snd_soc_component *scomp, scontrol->comp_id = sdev->next_comp_id; scontrol->cmd =SOF_CTRL_CMD_BINARY ; + scontrol->control_data->index = kc->index;dev_dbg (scomp->dev,"tplg: load kcontrol index %d chans %d\n" , scontrol->comp_id, scontrol->num_channels);
@@ -2133,7 +2135,7 @@ static int sof_get_control_data(struct snd_soc_component *scomp,for (i =0 ; i < widget->num_kcontrols; i++) { kc = &widget->kcontrol_news[i]; -switch (widget->dobj.widget.kcontrol_type) { +switch (widget->dobj.widget.kcontrol_type[i]) {case SND_SOC_TPLG_TYPE_MIXER : sm = (struct soc_mixer_control *)kc->private_value; wdata[i].control = sm->dobj.private;
@@ -2147,8 +2149,8 @@ static int sof_get_control_data(struct snd_soc_component *scomp, wdata[i].control = se->dobj.private;break ;default : -dev_err (scomp->dev,"error: unknown kcontrol type %d in widget %s\n" , - widget->dobj.widget.kcontrol_type, +dev_err (scomp->dev,"error: unknown kcontrol type %u in widget %s\n" , + widget->dobj.widget.kcontrol_type[i], widget->name);return -EINVAL ; }
@@ -2164,7 +2166,8 @@ static int sof_get_control_data(struct snd_soc_component *scomp,return -EINVAL ;/* make sure data is valid - data can be updated at runtime */ -if (wdata[i].pdata->magic !=SOF_ABI_MAGIC ) +if (widget->dobj.widget.kcontrol_type[i] ==SND_SOC_TPLG_TYPE_BYTES && + wdata[i].pdata->magic !=SOF_ABI_MAGIC )return -EINVAL ; *size += wdata[i].pdata->size;
@@ -2605,7 +2608,7 @@ static int sof_widget_unload(struct snd_soc_component *scomp, }for (i =0 ; i < widget->num_kcontrols; i++) { kc = &widget->kcontrol_news[i]; -switch (dobj->widget.kcontrol_type) { +switch (widget->dobj.widget.kcontrol_type[i]) {case SND_SOC_TPLG_TYPE_MIXER : sm = (struct soc_mixer_control *)kc->private_value; scontrol = sm->dobj.private;
Signature · 1 line
2.24.1
kernel test robot
build botRe: [PATCH v3 1/1] ASoC: dapm: Add support for multiple kcontrol types to a widget
Thank you for the patch! Perhaps something to improve:
Hi Jaska,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on asoc/for-next]
[also build test WARNING on v5.12 next-20210504]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jaska-Uimonen/Enable-using-multiple-different-type-kcontrols-for-widgets/20210504-182856 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next config: h8300-randconfig-s031-20210504 (attached as .config) compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-341-g8af24329-dirty
# https://github.com/0day-ci/linux/commit/c3ae3eefaed49ea413b773616ed3fc309a8ade99
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jaska-Uimonen/Enable-using-multiple-different-type-kcontrols-for-widgets/20210504-182856 git checkout c3ae3eefaed49ea413b773616ed3fc309a8ade99
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=h8300
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> sound/soc/soc-topology.c:1483:39: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned long [usertype] n @@ got restricted __le32 [usertype] num_kcontrols @@
sound/soc/soc-topology.c:1483:39: sparse: expected unsigned long [usertype] n
sound/soc/soc-topology.c:1483:39: sparse: got restricted __le32 [usertype] num_kcontrols
sound/soc/soc-topology.c:1487:50: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned long [usertype] n @@ got restricted __le32 [usertype] num_kcontrols @@
sound/soc/soc-topology.c:1487:50: sparse: expected unsigned long [usertype] n
sound/soc/soc-topology.c:1487:50: sparse: got restricted __le32 [usertype] num_kcontrols
sound/soc/soc-topology.c:1491:26: sparse: sparse: restricted __le32 degrades to integer
vim +1483 sound/soc/soc-topology.c
1417
1418 static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
1419 struct snd_soc_tplg_dapm_widget *w)
1420 {
1421 struct snd_soc_dapm_context *dapm = &tplg->comp->dapm;
1422 struct snd_soc_dapm_widget template, *widget;
1423 struct snd_soc_tplg_ctl_hdr *control_hdr;
1424 struct snd_soc_card *card = tplg->comp->card;
1425 unsigned int *kcontrol_type;
1426 struct snd_kcontrol_new *kc;
1427 int mixer_count = 0;
1428 int bytes_count = 0;
1429 int enum_count = 0;
1430 int ret = 0;
1431 int i;
1432
1433 if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1434 SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1435 return -EINVAL;
1436 if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1437 SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1438 return -EINVAL;
1439
1440 dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n",
1441 w->name, w->id);
1442
1443 memset(&template, 0, sizeof(template));
1444
1445 /* map user to kernel widget ID */
1446 template.id = get_widget_id(le32_to_cpu(w->id));
1447 if ((int)template.id < 0)
1448 return template.id;
1449
1450 /* strings are allocated here, but used and freed by the widget */
1451 template.name = kstrdup(w->name, GFP_KERNEL);
1452 if (!template.name)
1453 return -ENOMEM;
1454 template.sname = kstrdup(w->sname, GFP_KERNEL);
1455 if (!template.sname) {
1456 ret = -ENOMEM;
1457 goto err;
1458 }
1459 template.reg = le32_to_cpu(w->reg);
1460 template.shift = le32_to_cpu(w->shift);
1461 template.mask = le32_to_cpu(w->mask);
1462 template.subseq = le32_to_cpu(w->subseq);
1463 template.on_val = w->invert ? 0 : 1;
1464 template.off_val = w->invert ? 1 : 0;
1465 template.ignore_suspend = le32_to_cpu(w->ignore_suspend);
1466 template.event_flags = le16_to_cpu(w->event_flags);
1467 template.dobj.index = tplg->index;
1468
1469 tplg->pos +=
1470 (sizeof(struct snd_soc_tplg_dapm_widget) +
1471 le32_to_cpu(w->priv.size));
1472
1473 if (w->num_kcontrols == 0) {
1474 template.num_kcontrols = 0;
1475 goto widget;
1476 }
1477
1478 control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
1479 dev_dbg(tplg->dev, "ASoC: template %s has %d controls of type %x\n",
1480 w->name, w->num_kcontrols, control_hdr->type);
1481
1482 template.num_kcontrols = le32_to_cpu(w->num_kcontrols);
> 1483 kc = devm_kcalloc(tplg->dev, w->num_kcontrols, sizeof(*kc), GFP_KERNEL);
1484 if (!kc)
1485 goto err;
1486
1487 kcontrol_type = devm_kcalloc(tplg->dev, w->num_kcontrols, sizeof(unsigned int), GFP_KERNEL);
1488 if (!kcontrol_type)
1489 goto err;
1490
1491 for (i = 0; i < w->num_kcontrols; i++) {
1492 control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
1493 switch (le32_to_cpu(control_hdr->ops.info)) {
1494 case SND_SOC_TPLG_CTL_VOLSW:
1495 case SND_SOC_TPLG_CTL_STROBE:
1496 case SND_SOC_TPLG_CTL_VOLSW_SX:
1497 case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
1498 case SND_SOC_TPLG_CTL_RANGE:
1499 case SND_SOC_TPLG_DAPM_CTL_VOLSW:
1500 /* volume mixer */
1501 kc[i].index = mixer_count;
1502 kcontrol_type[i] = SND_SOC_TPLG_TYPE_MIXER;
1503 mixer_count++;
1504 ret = soc_tplg_dapm_widget_dmixer_create(tplg, &kc[i]);
1505 if (ret < 0)
1506 goto hdr_err;
1507 break;
1508 case SND_SOC_TPLG_CTL_ENUM:
1509 case SND_SOC_TPLG_CTL_ENUM_VALUE:
1510 case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
1511 case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
1512 case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
1513 /* enumerated mixer */
1514 kc[i].index = enum_count;
1515 kcontrol_type[i] = SND_SOC_TPLG_TYPE_ENUM;
1516 enum_count++;
1517 ret = soc_tplg_dapm_widget_denum_create(tplg, &kc[i]);
1518 if (ret < 0)
1519 goto hdr_err;
1520 break;
1521 case SND_SOC_TPLG_CTL_BYTES:
1522 /* bytes control */
1523 kc[i].index = bytes_count;
1524 kcontrol_type[i] = SND_SOC_TPLG_TYPE_BYTES;
1525 bytes_count++;
1526 ret = soc_tplg_dapm_widget_dbytes_create(tplg, &kc[i]);
1527 if (ret < 0)
1528 goto hdr_err;
1529 break;
1530 default:
1531 dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n",
1532 control_hdr->ops.get, control_hdr->ops.put,
1533 le32_to_cpu(control_hdr->ops.info));
1534 ret = -EINVAL;
1535 goto hdr_err;
1536 }
1537 }
1538
1539 template.kcontrol_news = kc;
1540
1541 widget:
1542 ret = soc_tplg_widget_load(tplg, &template, w);
1543 if (ret < 0)
1544 goto hdr_err;
1545
1546 /* card dapm mutex is held by the core if we are loading topology
1547 * data during sound card init. */
1548 if (card->instantiated)
1549 widget = snd_soc_dapm_new_control(dapm, &template);
1550 else
1551 widget = snd_soc_dapm_new_control_unlocked(dapm, &template);
1552 if (IS_ERR(widget)) {
1553 ret = PTR_ERR(widget);
1554 goto hdr_err;
1555 }
1556
1557 widget->dobj.type = SND_SOC_DOBJ_WIDGET;
1558 widget->dobj.widget.kcontrol_type = kcontrol_type;
1559 widget->dobj.ops = tplg->ops;
1560 widget->dobj.index = tplg->index;
1561 list_add(&widget->dobj.list, &tplg->comp->dobj_list);
1562
1563 ret = soc_tplg_widget_ready(tplg, widget, w);
1564 if (ret < 0)
1565 goto ready_err;
1566
1567 kfree(template.sname);
1568 kfree(template.name);
1569
1570 return 0;
1571
1572 ready_err:
1573 remove_widget(widget->dapm->component, &widget->dobj, SOC_TPLG_PASS_WIDGET);
1574 snd_soc_dapm_free_widget(widget);
1575 hdr_err:
1576 kfree(template.sname);
1577 kfree(kc);
1578 err:
1579 kfree(template.name);
1580 return ret;
1581 }
1582
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org