From patchwork Fri Apr 21 12:41:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 86292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1040932vqo; Fri, 21 Apr 2023 05:51:17 -0700 (PDT) X-Google-Smtp-Source: AKy350asetiFSUHsA7Dw7/L51t7OKHBXoImwI5wr5lfYltjp+Qp/IbZSYKX+s2qRGLKx3NVX/lE5 X-Received: by 2002:a17:903:2447:b0:1a6:fe25:4129 with SMTP id l7-20020a170903244700b001a6fe254129mr5431800pls.0.1682081476948; Fri, 21 Apr 2023 05:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682081476; cv=none; d=google.com; s=arc-20160816; b=QZbF7Ldd5pJGpuej0cLFtfA2MHULYeiM075IV4T9NxsiuXQtKJuYWzds0Ce7EI7LRg NmiWo1toZqGJhAmIKW8qgAaGWruUxkpb56IO9dAZyOXH7XCzhBeqL13xBDPVY2kWXvKS Snaj58sQz7IWO8ceaE+x03ikL6aOAdo5WdzsaVu0JnEig6UConH/21VL15U0hojcbBRO /ymnHCDpkCxp+65npDEXHP09FsU6C7R8fpSm8aljOkiC8Zc4f7s+JdpjdI4tiRAGe+yE Ym5pO9zLgglDt4fRTBQ0d8Psl7PmDnq6dABd6aNz2jK6+mKbY4cKNITo1uGiNM8N1bow 4zcg== 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=ReUlzkjE4Wu5oxkDFDACc0QGLsw/liPYYYIVObV0csA=; b=tFoXOY8IskYecWfUo+6XPTEJDbUlGIAABNZeCm1SD58ug6iyiu6F7PERFJODy88kAE C0JLiynlmYlt8yWxxp13gk0zMKmuM8PqOPGvl4O++jMoA1e6oy9qvJ7AowDv78juI5QQ vndoeVUlRM+Igukk9FMpV9p5moDApk2Wq0VPI0truTL3ERbG/6MpuSxhWho6p7TP3us8 zK9Gv0bQ47eHjNky7rer/D/Rb8tAT8oG18JbSCNb0z5kZun48t1PSzkwJMsxXHcsaOme zqqJ++cOuXp+WESpAmyNX1CW4W6t/tI8MuBFtvdiPCFnhBg1dXrQZhPwn5RXdKQR49cr KcWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EBy4SLN3; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a170902d58200b001a69cb5f7besi4375095plh.525.2023.04.21.05.51.04; Fri, 21 Apr 2023 05:51:16 -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=EBy4SLN3; 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 S232268AbjDUMmo (ORCPT + 99 others); Fri, 21 Apr 2023 08:42:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232109AbjDUMmj (ORCPT ); Fri, 21 Apr 2023 08:42:39 -0400 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17F8902A; Fri, 21 Apr 2023 05:42:12 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id AFC324000A; Fri, 21 Apr 2023 12:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1682080921; 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=ReUlzkjE4Wu5oxkDFDACc0QGLsw/liPYYYIVObV0csA=; b=EBy4SLN3K1xBNjJvOdgJT6PUfEQL9bFvtJnkKZY46KL21NgKdoRGRLuXY2Ng5RVJCaQUsK GUAjgQdTVTG41iA642TMsVC4zRI8weITdr7eKSHZvuCV1Q5xCkm8Jbl77IjpdbpUulDUiX AsR9HA/raMQtAMUCJOFuJPfaI0RECjhMyOz7Albr5ZYlsRCx1iz32soaxO3gFjAiprgSuv cIxyMyYohgaG33z6C43NJ8liKsqhp27aY2E8che4fAx5gExva8v9hS1l3cwoZzOoA0YZ43 4sasYv521gJLU5JtIUz/jn78fj2GCk6QXZiocudJcA47ux7IaLWyQXpxTA88AQ== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai 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 3/4] ASoC: soc-dapm.h: Add a helper to build a DAPM widget dynamically Date: Fri, 21 Apr 2023 14:41:21 +0200 Message-Id: <20230421124122.324820-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230421124122.324820-1-herve.codina@bootlin.com> References: <20230421124122.324820-1-herve.codina@bootlin.com> MIME-Version: 1.0 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_H3,RCVD_IN_MSPIKE_WL,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763790266860529636?= X-GMAIL-MSGID: =?utf-8?q?1763790266860529636?= 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 64915ebd641e..d6bb97fba8c9 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) \