Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4483872rwd; Tue, 23 May 2023 08:16:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FHJuKYRXW3hXWaGFQfHlsLjylnp+szfR3M6eWlETqdD4+DP311i73ZRyO3pSADNmsUpFO X-Received: by 2002:a17:902:7009:b0:1ac:5717:fd5 with SMTP id y9-20020a170902700900b001ac57170fd5mr12759685plk.60.1684854993446; Tue, 23 May 2023 08:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854993; cv=none; d=google.com; s=arc-20160816; b=bIM8H3V1uZYUv5HtWZZ/rrfLmixo2YJEbW3jp8tTlv+wYi04Kynzdi4j6la7ljAyC1 Sbll+NeQqUZ37UZ5CNTw6sccu6LoMmpYI4LGvPVXk8R4l3i8JQRPVYR6hKm+ECLiCgJy f8e5VoGdNrnjCZAqKkekLAwkVF9HUmx4MWtOGz+/u7fee2Ac0oFEH/olJ9CRXhHnVd6B jY+k1YjK0havBJsnRcPvmSjyoWmGMspAyT7jtjH3vc+Ph/0aTuvOCChdjlqGZWSmp3jF nx3ZybukSBAxZ+evmwImFwCoGR3Tk8USLjjCB93azO8r908AxAyCBXPO6Ep3Ykj5pjU1 7umA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DrMZ95BLnGjcDr2P+qmpgq0WbufG1vHwF/RueaYJS28=; b=IKHVcC5OZld3YDWmRU4Hc7ODxXXrlqyjiRtP5d4hvJTP+cXUi1Fshd+b9vqp6JGpEM SSzjOc/HsO0MT74epu8Fcgfh+Z71GBqda8f3/ac5t2vdt31iff755VVCewIyRhKFADmi XsNWUY0Ceber+BfrJURp2Lfjd9comyc2ZUi4m5Ca65F2dNjxu41gR9NQroXsR01DovlS hDDlxxYcTKjzf38ID63GZpEzmo9YiMQRy1ydmKu7RQI6etNf8vwc82ppYHNpEuEqFJG7 ZsOnEluza8Lm9NOf9Ipl9aIvHoZwDv63N7f51BrcX4k/J33JGFdUXZNOSKrJnsqQaaTI ++9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OJWTwCnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a170902ce8300b001ac6a6f2dd3si4979661plg.555.2023.05.23.08.16.20; Tue, 23 May 2023 08:16:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OJWTwCnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237497AbjEWPNP (ORCPT + 99 others); Tue, 23 May 2023 11:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjEWPNE (ORCPT ); Tue, 23 May 2023 11:13:04 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1981B1; Tue, 23 May 2023 08:12:51 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 3D8ECC0008; Tue, 23 May 2023 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DrMZ95BLnGjcDr2P+qmpgq0WbufG1vHwF/RueaYJS28=; b=OJWTwCnlWn+Xthk0Xfek+s2r5juF2h7SNMSfs+CDSVW51lOc8n36dXjfmK4BGPJBYbTAPt 86JjRd4Mcrd49qLXHvDbArKC/E8hki2QuxdslB+MaEZqxwzDROqTu3G8Z0Oz5C6eQX+enW 1FEIgs2cKR0VhE8GLUYxb3DvhzjllrjjdzEjgxzsfnZWENwkRrwuSFZJ1V6owA63QJX4at E+lI4csyxxNOldCH4gEdjII1NaSjAe/tFPmI74ueGDSpFa0nTIg+UIMmKFywgHxEA6Z5du 0P+mF8ZkTdK3AP4vyWzvlgggQVXF+c6HB2D3ptw9OPIUQUqHT2gaJZ7N9lx2tQ== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 6/9] ASoC: soc-dapm.h: Add a helper to build a DAPM widget dynamically Date: Tue, 23 May 2023 17:12:20 +0200 Message-Id: <20230523151223.109551-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SND_SOC_DAPM_* helpers family are used to build widgets array in a static way. Introduce SND_SOC_DAPM_WIDGET() in order to use the SND_SOC_DAPM_* helpers family in a dynamic way. The different SND_SOC_DAPM_* parameters can be computed by the code and the widget can be built based on this parameter computation. For instance: static int create_widget(char *input_name) { struct snd_soc_dapm_widget widget; char name*; ... name = input_name; if (!name) name = "default"; widget = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_INPUT(name)); ... } Signed-off-by: Herve Codina --- include/sound/soc-dapm.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 87f8e1793af1..6b62fe5c779c 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -276,7 +276,17 @@ struct soc_enum; .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD } - +/* + * Helper to create a widget 'dynamically' + * This can be used with any of the SND_SOC_DAPM_* widget helper. + * For instance: + * struct snd_soc_dapm_widget widget; + * ... + * widget = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_INPUT(input_name)); + */ +#define SND_SOC_DAPM_WIDGET(_widget)({ \ + struct snd_soc_dapm_widget _w[1] = { _widget }; \ + _w[0]; }) /* dapm kcontrol types */ #define SOC_DAPM_DOUBLE(xname, reg, lshift, rshift, max, invert) \ -- 2.40.1