From patchwork Fri Jun 23 08:58:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629368vqr; Fri, 23 Jun 2023 02:00:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rY9Rk6oTm0s9KsuvXAAzEOMhjBOEBHnRa+rnvCLX3ZT00KYmQ41NrujWYA4D6tQz2nF/W X-Received: by 2002:a05:6358:6a49:b0:12f:91cd:2d07 with SMTP id c9-20020a0563586a4900b0012f91cd2d07mr13435419rwh.28.1687510830973; Fri, 23 Jun 2023 02:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510830; cv=none; d=google.com; s=arc-20160816; b=ZdCNm8qppDYA8twBNL9v8jBfVap3eoVh8R2DhP2AHW3IQiyKXY1o5mU1hhjcfX/Wz6 VJLk/uBgRX9YPtaAtEpzSJUCcW0cT3UscKIDCzR00xmwg7yjTSMwC23Iy72hKg0246M5 iP1XzN2QhGtm9VaqYX3UYOhJOsPVwurYu6BpANVhH1BSsXg1GBrWZ9EBo96mylY137II CfBiESkTy5fCvFXQBKbM+ISyoOGqWNUNQ1mNMSD1rnnNVc0VxuvuyN9QzsMbgMI5QMXA QOxJmvDtd1hqkTIiJPuoY/bXogLAeZOyph9VbIB/dMEEtOAJ3OPk0/iga2tR4NVM/LcD E1ow== 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=EEEy793cjGF4C1unCyddxor7imGVvD+ZiP6bKckvbw4=; b=tF1qeNN+MCwfH2QkE8uTGULJSAWF5/PZIIsojABqF/FNA9Hj55s6Vjmoue5+m+0NwT ELZoxpc7Sya7I3P3Tzup2oHNviOeI3cZWKuP3/VQnFlNT/AzUZetna08TgMd6rgDiTbW b+u4hIkglkt7WVhUQvQkc1j09GXBpijP7qmFTKELbtREp/i07zP4erv63Ole6JBlisDW 7hMRKbCZndFe0Gp2HPel0G7GEAHfkvuSB50NsldyxJjlzjBv94Ay7OCdWo6gC5QaQNVW GJznFRifXjZN4ku3CepODTD+Y6xTzDITeoEyuLYpP5PXr5W1vGB2Zb8nsOMYngDa6EUX AgPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UotQHbaA; 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 w4-20020a656944000000b005538fca55f5si8344511pgq.874.2023.06.23.02.00.18; Fri, 23 Jun 2023 02:00:30 -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=UotQHbaA; 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 S231591AbjFWI6t (ORCPT + 99 others); Fri, 23 Jun 2023 04:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbjFWI6o (ORCPT ); Fri, 23 Jun 2023 04:58:44 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C2942136; Fri, 23 Jun 2023 01:58:41 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510720; 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=EEEy793cjGF4C1unCyddxor7imGVvD+ZiP6bKckvbw4=; b=UotQHbaAJeNXasLN9mk7ePmGKLlGqSP5Pk+4e4/5oGOhcBkWTqdISJTeO8zYXONumIYwR3 Od7Qd/WgRSMRq1o45te8iI48HzGRLT3mSf6jYm6zPkG4p27aPt4paAiWNd0i5xUJq42pb0 5Ig4LySjXqz/dZF2avcsX4oFRD/8Fp5XbV/S+GP1Mi86Jvo96Vd3Ler343LhhDOcUGyCes Mbyd0W6rRpuFVbLHZrkiUtHfrSl7TL/0jBeIvKdf0a5SuEzFhYXwvXKyQZ3sKQviNgVvm5 c5lHEslDQAjzYHT95A7JsL+v/jRe40vpqTWvd/r2I9ADxZAWcfhF6xFCtWwP7A== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id A0B9CE000C; Fri, 23 Jun 2023 08:58:38 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron , Rob Herring Subject: [PATCH v6 01/13] ASoC: dt-bindings: Add audio-iio-aux Date: Fri, 23 Jun 2023 10:58:18 +0200 Message-Id: <20230623085830.749991-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483357225439485?= X-GMAIL-MSGID: =?utf-8?q?1769483357225439485?= Industrial I/O devices can be present in the audio path. These devices needs to be viewed as audio components in order to be fully integrated in the audio path. audio-iio-aux allows to consider these Industrial I/O devices as auxliary audio devices. Signed-off-by: Herve Codina Reviewed-by: Jonathan Cameron Reviewed-by: Rob Herring Reviewed-by: Christophe Leroy Reviewed-by: Christophe Leroy --- .../bindings/sound/audio-iio-aux.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/audio-iio-aux.yaml diff --git a/Documentation/devicetree/bindings/sound/audio-iio-aux.yaml b/Documentation/devicetree/bindings/sound/audio-iio-aux.yaml new file mode 100644 index 000000000000..d3cc1ea4a175 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/audio-iio-aux.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/audio-iio-aux.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Audio IIO auxiliary + +maintainers: + - Herve Codina + +description: + Auxiliary device based on Industrial I/O device channels + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + const: audio-iio-aux + + io-channels: + description: + Industrial I/O device channels used + + io-channel-names: + description: + Industrial I/O channel names related to io-channels. + These names are used to provides sound controls, widgets and routes names. + + snd-control-invert-range: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + A list of 0/1 flags defining whether or not the related channel is + inverted + items: + enum: [0, 1] + default: 0 + description: | + Invert the sound control value compared to the IIO channel raw value. + - 1: The related sound control value is inverted meaning that the + minimum sound control value correspond to the maximum IIO channel + raw value and the maximum sound control value correspond to the + minimum IIO channel raw value. + - 0: The related sound control value is not inverted meaning that the + minimum (resp maximum) sound control value correspond to the + minimum (resp maximum) IIO channel raw value. + +required: + - compatible + - io-channels + - io-channel-names + +unevaluatedProperties: false + +examples: + - | + iio-aux { + compatible = "audio-iio-aux"; + io-channels = <&iio 0>, <&iio 1>, <&iio 2>, <&iio 3>; + io-channel-names = "CH0", "CH1", "CH2", "CH3"; + /* Invert CH1 and CH2 */ + snd-control-invert-range = <0 1 1 0>; + }; From patchwork Fri Jun 23 08:58:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629387vqr; Fri, 23 Jun 2023 02:00:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KrzwDIEPWBioYfQNSDFWAcYqw5kSV9cuTKMOe1EXwbJLRmFLCA/YXYecSyXhd1m9Z3Chr X-Received: by 2002:a05:6830:189:b0:6b7:1d93:72e0 with SMTP id q9-20020a056830018900b006b71d9372e0mr2734973ota.32.1687510832745; Fri, 23 Jun 2023 02:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510832; cv=none; d=google.com; s=arc-20160816; b=o2+18eXxFz/0zIL6Ue8oSymi93PkhM7O+i2oE1QnZKCmyb+ZASupFdQpxhibERD7kK /IHaAdtlc91y1wL1+UaD2lXFUBcmHS2YT7nI4O5HggkNSIUOxsg6t34ArOI1t0dVhf9A zseTeWZyYHCPyzl7YYG2bU16PvMc9SYXTEq8UjatwoE++eYr8fJ8gyp7lPRhL7BuH8KC tWV0cqnwOtPrIAtmTIcxgrjFEKMbBFtLSTDpc2qSKBy/Bo/cmfRBG0fCSyaVhs/LGD0b m1JsLIn9h/qwiMUiLt1lu2l/GGHmSlw+Frb6zpU/1JNPN7ZXhSEIBHuMb4Qo6IQucOmk diWA== 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=bOjUEUa+0v4gjRsjixC0ZUKxZ+b4tghUzi1tXKl/N6c=; b=MhlWsD0ThvPtYCvnvM+46ulrGlzU/4NkU/28QTifwY0Du93RlBGkyc1VrzcwGQIch6 lUNMAoBrHb8PZ194F+B3fExhkW/gIFmdOA0oet72b53QiSYEVyJRCtAzB9QbKpvvaMIm FoynEOt0JsrERE2p/logVPzHfH9GyIbvp5AExKY+jocCu9b0m7sy8Gx/oiBqKYEdmcjU DLNp0l1zGRUcgscwql/KTIMzBw4fY7NUWZ8yWL1jr/wONqNpsL5a8hH45dQSEzbowK9M Kukv8Zh0eXQdXr3GQxupqRPZ68EEcEzzwxx+RwGdtFLBzeox9F4pMxE3ptcRnnw8laH4 ymbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=poXQb6l0; 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 e30-20020a63371e000000b005539ec6a3adsi8529019pga.703.2023.06.23.02.00.18; Fri, 23 Jun 2023 02:00:32 -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=poXQb6l0; 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 S231948AbjFWI6w (ORCPT + 99 others); Fri, 23 Jun 2023 04:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjFWI6q (ORCPT ); Fri, 23 Jun 2023 04:58:46 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 859E710C1; Fri, 23 Jun 2023 01:58:44 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510723; 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=bOjUEUa+0v4gjRsjixC0ZUKxZ+b4tghUzi1tXKl/N6c=; b=poXQb6l0cEHC73knVIo0+10AHqgF/mUekvirOylTeNnSx+PaqoPQVZlRF+dyI2+0/lI9cl UzFiXUl+Zg9ygv6MARKwCWo9tctVTVbubnks2+aRy9bXLlV7KZZSpQWBUmxs73pQBb9NPJ aSAJ/gD8Y9jkg552ubQj4k38KHLEf1mqY0GOixpcnUF7ELGlDLl7ezenwSEby0s0hJl9Ig f/Fa3cp3110QCbyLbAP+wunwNpfrKsui/ijn5hA+a8XzvOpYaSsYaHTxGyZjYgqTkux4B4 aP2W1AG1QrjUHW7kgtCz/HEwBFe2Xsx96lajdmYtJf5/XTsufUJ6Umx+C+PFyg== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id D3C40E0002; Fri, 23 Jun 2023 08:58:40 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 02/13] ASoC: dt-bindings: simple-card: Add additional-devs subnode Date: Fri, 23 Jun 2023 10:58:19 +0200 Message-Id: <20230623085830.749991-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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_PASS,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?1769483359074868303?= X-GMAIL-MSGID: =?utf-8?q?1769483359074868303?= The additional-devs subnode allows to declared some virtual devices as sound card children. These virtual devices can then be used by the sound card and so be present in the audio path. The first virtual device supported is the audio IIO auxiliary device in order to support an IIO device as an audio auxiliary device. Signed-off-by: Herve Codina Reviewed-by: Jonathan Cameron Reviewed-by: Christophe Leroy Reviewed-by: Christophe Leroy --- .../bindings/sound/simple-card.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/simple-card.yaml b/Documentation/devicetree/bindings/sound/simple-card.yaml index b05e05c81cc4..59ac2d1d1ccf 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.yaml +++ b/Documentation/devicetree/bindings/sound/simple-card.yaml @@ -148,6 +148,15 @@ definitions: required: - sound-dai + additional-devs: + type: object + description: + Additional devices used by the simple audio card. + patternProperties: + '^iio-aux(-.+)?$': + type: object + $ref: audio-iio-aux.yaml# + properties: compatible: contains: @@ -187,6 +196,8 @@ properties: $ref: "#/definitions/mclk-fs" simple-audio-card,aux-devs: $ref: "#/definitions/aux-devs" + simple-audio-card,additional-devs: + $ref: "#/definitions/additional-devs" simple-audio-card,convert-rate: $ref: "#/definitions/convert-rate" simple-audio-card,convert-channels: @@ -359,6 +370,48 @@ examples: }; }; +# -------------------- +# route audio to/from a codec through an amplifier +# designed with a potentiometer driven by IIO: +# -------------------- + - | + sound { + compatible = "simple-audio-card"; + + simple-audio-card,aux-devs = <&_in>, <&_out>; + simple-audio-card,routing = + "CODEC LEFTIN", "AMP_IN LEFT OUT", + "CODEC RIGHTIN", "AMP_IN RIGHT OUT", + "AMP_OUT LEFT IN", "CODEC LEFTOUT", + "AMP_OUT RIGHT IN", "CODEC RIGHTOUT"; + + simple-audio-card,additional-devs { + amp_out: iio-aux-out { + compatible = "audio-iio-aux"; + io-channels = <&pot_out 0>, <&pot_out 1>; + io-channel-names = "LEFT", "RIGHT"; + snd-control-invert-range = <1 1>; + sound-name-prefix = "AMP_OUT"; + }; + + amp_in: iio_aux-in { + compatible = "audio-iio-aux"; + io-channels = <&pot_in 0>, <&pot_in 1>; + io-channel-names = "LEFT", "RIGHT"; + sound-name-prefix = "AMP_IN"; + }; + }; + + simple-audio-card,cpu { + sound-dai = <&cpu>; + }; + + simple-audio-card,codec { + sound-dai = <&codec>; + clocks = <&clocks>; + }; + }; + # -------------------- # Sampling Rate Conversion # -------------------- From patchwork Fri Jun 23 08:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5637111vqr; Fri, 23 Jun 2023 02:16:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5KxAvbqsYcJCUwMYegM0GRRaYKb1/oiZmdgSfyNmOskQ7YzuQYUiVHwIx2VWg1gsexFWSX X-Received: by 2002:a05:6a21:9983:b0:121:bf66:a715 with SMTP id ve3-20020a056a21998300b00121bf66a715mr11736939pzb.45.1687511819292; Fri, 23 Jun 2023 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687511819; cv=none; d=google.com; s=arc-20160816; b=iPqBDvEhbb5ZBKuMjy/VCi+qoaNJBfSbGOov119UXbi9mPknldOlfTNCY+UtEUbwlk PLc8WxqiGDsf6lUQ6v9VV9tU5LoGESItWFBDXjALJoqcD2Z+IrJykJ4mAVNemojdcOyM ZXih0qosKIB95HYcg8ihMgC3eYg5L0wzabdQv6QdCwUfGg0yr0BYI99TxBLO2kSgYsj7 za4Ih0HKGKKI9FeRJLJl83ot83HHWwn8kHNh34pq7Qwb4yZPnwgTCRb0D63DTNZ3qFSK +U1c3Mo5D5V94yHPNrkUJ3Y2gejr7UfXWKg3QZTdUXYAt9B5FbwI2XmhLeIid2u//pEx TYmg== 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=rfYOy7L85MdtcQ88k+lfhIIjhcOaxuYtKNcPHMwEQsI=; b=ZI3ELCGW3yazPS1Z+F51FeY5wFRMQDqMqL3Vgt9fiXKTKLWjuYctOhSbIFiqsmYWmw KsHilmqE3rGwoCfv8mMYvqYKfZkO6oB8id1UUTHwSGmBwlQQfrVnLGxA931xEnAmehZZ uSejCyqSm209tdPnMaTUYxNyib66Q0Qzu1xy5zRfAUOa1oGae5RTr2dRZ6ITQfiUoR3X 05kOdJ0ZRXXbral88X2hDqPpK+JGP+jH088/vHbZUBxD1ihUCWL7SmgpX0FWNuPIMd2W BNXoSe10rH64Xo4rFEX+I7IZuRCwlsH3+13UGP/qFekML6VJVQQ3x4iQiFm3prXNTy6a wKhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=knWhzUEE; 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 c7-20020a170903234700b001ac2ff9fbf8si5416053plh.403.2023.06.23.02.16.44; Fri, 23 Jun 2023 02:16:59 -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=knWhzUEE; 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 S231968AbjFWI64 (ORCPT + 99 others); Fri, 23 Jun 2023 04:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjFWI6s (ORCPT ); Fri, 23 Jun 2023 04:58:48 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A968A10C1; Fri, 23 Jun 2023 01:58:46 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510725; 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=rfYOy7L85MdtcQ88k+lfhIIjhcOaxuYtKNcPHMwEQsI=; b=knWhzUEEAUpZM8lHUEu/eXc+ozD4+EQx9Vv/n38Hd/h+Xap3AJYOXF/5VTV6+22Zre7/1M oOUXew1BzvDWkjKyNE8Xs7CQlPwhnyA4JW0qqnlIuenZlcOvaDXXFXn0qGFJuE9yTQE834 Xo3P8dWJ6gA+9BfIXNVlurWsMPIVI8uw47FDWBsYMUZo7KMyNkN7qbDZXIOJTNFaZ2QAOw UUSBPO1mIBjQGH06CySF6+pZcYuaLxhxtFclCKF6yuSckGrw0IZrJ/SKdsXWimflP9xp+W MYyVvW7poaLHVR/8ilityk7Npvsac90w/h1JE8wUBe0JR5J2dXQuu3RYB4i7Lw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 5832BE000A; Fri, 23 Jun 2023 08:58:43 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 03/13] iio: inkern: Check error explicitly in iio_channel_read_max() Date: Fri, 23 Jun 2023 10:58:20 +0200 Message-Id: <20230623085830.749991-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769484393531825216?= X-GMAIL-MSGID: =?utf-8?q?1769484393531825216?= The current implementation returns the error code as part of the default switch case. This can lead to returning an incorrect positive value in case of iio_avail_type enum entries evolution. In order to avoid this case, be more strict in error checking. Signed-off-by: Herve Codina Acked-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 872fd5c24147..f738db9a0c04 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -858,6 +858,9 @@ static int iio_channel_read_max(struct iio_channel *chan, val2 = &unused; ret = iio_channel_read_avail(chan, &vals, type, &length, info); + if (ret < 0) + return ret; + switch (ret) { case IIO_AVAIL_RANGE: switch (*type) { @@ -888,7 +891,7 @@ static int iio_channel_read_max(struct iio_channel *chan, return 0; default: - return ret; + return -EINVAL; } } From patchwork Fri Jun 23 08:58: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: 111986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629363vqr; Fri, 23 Jun 2023 02:00:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rBvESL3F5bHs9cRLA7eYcICn7wVQTx4UbLxN3Z2J8Y4W4LO13gRVnzri2x3WojQYWAjtP X-Received: by 2002:a05:6a20:7295:b0:115:a2f4:6284 with SMTP id o21-20020a056a20729500b00115a2f46284mr10170598pzk.16.1687510831029; Fri, 23 Jun 2023 02:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510831; cv=none; d=google.com; s=arc-20160816; b=0kjz1w3aXLR+Ht0rhWNPkK8LdeIFR8ADAG+QfdBZLqC2cI4KyMBXKAJGkbuMcl4Fxj PzX/JoFeINa65IcbNTYMgVX1z0xjoIFw8b8rgfOZlgFHN1P4v/yJjuviTPs7FR53W3hE zAzXzcoz/f+zFQklPsG6Dl3yQYBfJyO8qUNy0Vmb599Mrm/8cobJVfYBjcfg/9b9ZU2r IcgWWMWic+DOCoza1zMjw23iAFbjPwPiF7nNQOHUO5TDzD2I7g+q1MoXChbiRjmBhTUZ hLneICjeW07BdUKTFLHHhFcK1ndGaCR6ixYyVepsN7XFM64NVlnZ/9WI3nCoWBHBCJXQ GyVw== 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=rgrvFu84ZrZIMRnZAFcmpkUkbG8qISQlNfLp/T/UU5I=; b=Zh868LkaIEz+l6FkwQj/WLIFrEq6w58GndbR9/M71moQgTsBxpxTxd82vnEbOU46Yk 4/NEIpGtnirtJiBvUhdrO/3DYRpg6490i+ynb/4Cc9XhEGKZ16vEqpH4tiocsB9mMD0n i7ZPbUhQs9Cs8iW/CU3OCg0hpn8cXgsE0nKomU3afk7AK1DB9FSNRd2NX3OFMacFZ2RW dJj+uhQhr9zKjaxhDIFNCbt59sRYCy8udwKqmuHpNVOXmOoeu2iQjvHg8StFQ4fEEZyo WA5dLQSayhds+San6iMgibZds6nET11hrTBT3BP7DU9iPSBNB/Mj9nwHzwPIaAs3yFCe jeHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CLzL0Eh0; 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 b5-20020a170902d50500b001a637201992si9639724plg.488.2023.06.23.02.00.18; Fri, 23 Jun 2023 02:00:31 -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=CLzL0Eh0; 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 S231714AbjFWI67 (ORCPT + 99 others); Fri, 23 Jun 2023 04:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbjFWI6v (ORCPT ); Fri, 23 Jun 2023 04:58:51 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E25A2139; Fri, 23 Jun 2023 01:58:49 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510728; 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=rgrvFu84ZrZIMRnZAFcmpkUkbG8qISQlNfLp/T/UU5I=; b=CLzL0Eh08jrIftwnY5tvc3hLa+aqBLyyvgkWdSq2R+LHaFIfZ85y3mX8jo0cf5XVdbMEFh DgypWB/vJqWm7P+iXc5osF08rfQbYzZTIA7GsKgTDLEiCyKzHcnta9VBM9XflTHldBT3A2 mUm/7W2jpD1EYI1NpcDXcm85JLC/dY17N7zf1jjBsraTYjOI5bG+w0dAKNiIzlg/ZLcy2w PSvQf8MrjiCUwP7ojwlMT5/ScfzSqbC21LnEk503/aQ5XHgCJ++exjNUNd4cwhD5tLR6v0 q26ZvYHhagGUrCkIez/p7Do36tbr+uGCZG3fIF30RNeHAL3EKvrqOHJlmpGCwA== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 6D955E0007; Fri, 23 Jun 2023 08:58:45 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 04/13] iio: consumer.h: Fix raw values documentation notes Date: Fri, 23 Jun 2023 10:58:21 +0200 Message-Id: <20230623085830.749991-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483357222368071?= X-GMAIL-MSGID: =?utf-8?q?1769483357222368071?= The raw values notes mention 'ADC counts' and are not fully accurate. Reword the notes in order to remove the 'ADC counts' and describe the conversion needed between a raw value and a value in the standard units. Signed-off-by: Herve Codina Acked-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy --- include/linux/iio/consumer.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 6802596b017c..f536820b9cf2 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -201,8 +201,9 @@ struct iio_dev * @chan: The channel being queried. * @val: Value read back. * - * Note raw reads from iio channels are in adc counts and hence - * scale will need to be applied if standard units required. + * Note, if standard units are required, raw reads from iio channels + * need the offset (default 0) and scale (default 1) to be applied + * as (raw + offset) * scale. */ int iio_read_channel_raw(struct iio_channel *chan, int *val); @@ -212,8 +213,9 @@ int iio_read_channel_raw(struct iio_channel *chan, * @chan: The channel being queried. * @val: Value read back. * - * Note raw reads from iio channels are in adc counts and hence - * scale will need to be applied if standard units required. + * Note, if standard units are required, raw reads from iio channels + * need the offset (default 0) and scale (default 1) to be applied + * as (raw + offset) * scale. * * In opposit to the normal iio_read_channel_raw this function * returns the average of multiple reads. @@ -281,8 +283,9 @@ int iio_read_channel_attribute(struct iio_channel *chan, int *val, * @chan: The channel being queried. * @val: Value being written. * - * Note raw writes to iio channels are in dac counts and hence - * scale will need to be applied if standard units required. + * Note that for raw writes to iio channels, if the value provided is + * in standard units, the affect of the scale and offset must be removed + * as (value / scale) - offset. */ int iio_write_channel_raw(struct iio_channel *chan, int val); @@ -292,8 +295,9 @@ int iio_write_channel_raw(struct iio_channel *chan, int val); * @chan: The channel being queried. * @val: Value read back. * - * Note raw reads from iio channels are in adc counts and hence - * scale will need to be applied if standard units are required. + * Note, if standard units are required, raw reads from iio channels + * need the offset (default 0) and scale (default 1) to be applied + * as (raw + offset) * scale. */ int iio_read_max_channel_raw(struct iio_channel *chan, int *val); @@ -308,8 +312,9 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val); * For ranges, three vals are always returned; min, step and max. * For lists, all the possible values are enumerated. * - * Note raw available values from iio channels are in adc counts and - * hence scale will need to be applied if standard units are required. + * Note, if standard units are required, raw available values from iio + * channels need the offset (default 0) and scale (default 1) to be applied + * as (raw + offset) * scale. */ int iio_read_avail_channel_raw(struct iio_channel *chan, const int **vals, int *length); From patchwork Fri Jun 23 08:58:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629366vqr; Fri, 23 Jun 2023 02:00:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GfPCLEA904l5zastMki2xYQ3eXRPT6oorwhVwhrkb5LVGrnmOGxTOBr02GI2rO1YxAVvP X-Received: by 2002:a17:90a:c297:b0:25b:d977:466b with SMTP id f23-20020a17090ac29700b0025bd977466bmr18884769pjt.29.1687510831162; Fri, 23 Jun 2023 02:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510831; cv=none; d=google.com; s=arc-20160816; b=BJDSK4vVz1nRGZWS4xBk4EiAyfUOwEls1WACzxP5NxIv8bKfQd0GtYrPcaj+FRQnNh Jhq3d8JijrufiX4ppbddjGGYYxmsViGBvLPqC2iEYaXG5KsuK5hvShsd5O5XrNBS6+Yl /ug7j0a9EMFL3rryJq+QB+Ha6OPGDQcdYuT4lCdYxdkdmwddHwlBPhd5uojV8SomBU7M V4kFP/k+06ghOp86LZyx7SYW6BxrpxhUBcvL6+mW2TILevcUmHE5R+pjCq83MQsQLs5r OEexTx9QMGhDx3GXojkrB+lKEumoJ6+V3Y8qyleQXLKzGyH1EzpTD3V3JlJb6hKOcunr qJJw== 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=/hsiLkhiPhkv1THloCiztKYYIF7LrdRF7qyhpJmA/Ws=; b=04F9tq8xcToxMN4Xd1XiUz4+90ipbiPth+2jPxryXCGC4nBp0Q0cRY3SpAM+82DTez zRfjWyLestkMntKWiJO85cTaW3msjoHQqLDhmMbiyupgSMO34x45NTI+eXyZZbAAmVcM zsfclr4Fs5lQdHtePUU+/KfbmW5jx9Nj84HIKiUUewEVOBSxrqm4rziyrnrvWDtvTXTi jI5P38KapQVjPXnHmoXPz6ClAEVzlTf8GDWJ3Fq6BMkm5S6XKFmHWK5nW6hi1Oh36ohj gTMgBIVA39r5+poZkV3DHnxwBOwUwShHkbYvgt6N/bLng+zcB/cY5BMZpl7k25TpfO/1 6plw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ONhXLrnB; 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 v70-20020a638949000000b0053094305b59si1676373pgd.875.2023.06.23.02.00.18; Fri, 23 Jun 2023 02:00:31 -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=ONhXLrnB; 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 S231965AbjFWI7D (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbjFWI6w (ORCPT ); Fri, 23 Jun 2023 04:58:52 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C742137; Fri, 23 Jun 2023 01:58:50 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510729; 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=/hsiLkhiPhkv1THloCiztKYYIF7LrdRF7qyhpJmA/Ws=; b=ONhXLrnBHT9aoyHuwq5KlvouXzbQh+QAmv9J7ceVVSq34ivg6s8qyGIr6i04Sagh36RmE5 QX5t9pUBXx8h4CQxdlHYVRAdUnpCPiZ7B64oigbrIStqKvmyXOxh4QsLrrg4MvujZFuNaP BqfMwsfKiRw7UaBllrYpDvsidpVA5t8euhAHUmC0W4piebJHsAK+XMLIylcD1yi8cbCk1l fUpajUGxh2VxZM8U6BfKDYpZmT1NIw+chgYSsMPisZnwSJPEE27cYzbiWk6/kFRs0qWjK3 JkttD8Dx+vz3+ndT3Ph4yLXVgJZsZrX90UlV3MAc4PdcN/q8wXB1fbwC98NNow== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 2F61FE0004; Fri, 23 Jun 2023 08:58:48 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 05/13] iio: inkern: Remove the 'unused' variable usage in iio_channel_read_max() Date: Fri, 23 Jun 2023 10:58:22 +0200 Message-Id: <20230623085830.749991-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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_PASS,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?1769483357506109019?= X-GMAIL-MSGID: =?utf-8?q?1769483357506109019?= The code uses a local variable to initialize a null pointer in order to avoid accessing this null pointer later on. Simply removed the 'unused' variable and check for the null pointer just before accessing it. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index f738db9a0c04..ce537b4ca6ca 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -849,14 +849,10 @@ static int iio_channel_read_max(struct iio_channel *chan, int *val, int *val2, int *type, enum iio_chan_info_enum info) { - int unused; const int *vals; int length; int ret; - if (!val2) - val2 = &unused; - ret = iio_channel_read_avail(chan, &vals, type, &length, info); if (ret < 0) return ret; @@ -869,7 +865,8 @@ static int iio_channel_read_max(struct iio_channel *chan, break; default: *val = vals[4]; - *val2 = vals[5]; + if (val2) + *val2 = vals[5]; } return 0; From patchwork Fri Jun 23 08:58:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629731vqr; Fri, 23 Jun 2023 02:01:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zXLiPtI/3Ajb3D/zPfBrbyYmN1STcBzt3wEFQYzvpYMnEqY9kkvp3236PYL8gqtAMrw+K X-Received: by 2002:a05:6a20:430d:b0:11f:38d4:2df with SMTP id h13-20020a056a20430d00b0011f38d402dfmr19669787pzk.20.1687510860250; Fri, 23 Jun 2023 02:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510860; cv=none; d=google.com; s=arc-20160816; b=ONHhsLsSbXzllKveyoN5Yb5H3R1vcuScVKXzEhpiDtpgRyWAWpH7L1uQNn3hmuacwO 4fzGWJaGlG/vyPayHsNbo4aVYIQ2evUOc+tF1WAsXy0Icpd7w+B5YfplzYSYWoJvO98j 62W5v4s3rhmZ7CqWbRwHdX7FjIQtdk0rmlQfbgdcq3mk2S7oPzH9ObQTi/2YtqLhFa8Z D3EAVUywvSlGBlXP1kCR5BuwrIn3R7j1mmZDaG8X+pqUVIBUY2IdYJxBiUUnLPHrkwHh Sg+giibGLWPflWFrB6lrgsWv/1tgudqYL2viNnZcBZupdKwtBxCOXQiVMi888ngclgJR 6/AA== 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=mkU71o14uoctytXs7gdXc7TyHrVAKzksbO96FJMI7uc=; b=zwvGFvV336Th+urgyrISZenyk0lj9YS7nIZgl7Nhr+akFQtCZu/noOt5adHqlgQrvL lobDUbQdkQyuznNMofFFwSJBltI9t41h39NRAZPDonLHQb9Ty4jIUG6xF/RB/FJ41rEH t+cf90XqyHXmWl0Epj4PZi9q1d6sI0o4xRSGdpC9O9GzXNGSL4uEa0ZygeL53ktbJGRG XJeCKhCDr9MCXbyP0udIBvgdmlzB6G3MlAa4bAdZO7ZFeKc5qm0qnmBv+ppD+R5KaQZr c/49CxWwr89WOHILC88sNh0JLufeJqwhjQczR6VCuB+bSAeci+lGbvj0+PAXpO34wkir LqTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=if5wdub1; 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 a15-20020a170902eccf00b001b0603829afsi9069365plh.405.2023.06.23.02.00.37; Fri, 23 Jun 2023 02:01:00 -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=if5wdub1; 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 S232039AbjFWI7N (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbjFWI64 (ORCPT ); Fri, 23 Jun 2023 04:58:56 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0AF268C; Fri, 23 Jun 2023 01:58:52 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510731; 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=mkU71o14uoctytXs7gdXc7TyHrVAKzksbO96FJMI7uc=; b=if5wdub1BoVfKGcUUX71G7t5hc1sw/mT/HlyIApbnZWoD2GkG7/1bakVfLDYXTznxEcDV6 JiJdkEH6Xrw2wKcEMNp4+Jck042hGXluPTRVo5ylPsscYLYCumtkUNKbcVgJA2lFO3zXMZ W48nLuOXnO91debnTOvuh2vBxJgCQ5CJHrCiXU6WT2VQoVUHns5rQoXWzwoatkiesxR3pw +W8HXrfHOXim547FWsJVXx7QNQwhlLJ7JTuL9lzg4GQ6U1Lp4M4dKZ6P1ecBBCAfaZO795 SExyxgU2pEGz/kD3kY+pMmiwp3pQ0YqplT/2vblqP6dR6lnkPSNAl0CSlu43vA== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id DF83FE0019; Fri, 23 Jun 2023 08:58:49 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 06/13] iio: inkern: Fix headers inclusion order Date: Fri, 23 Jun 2023 10:58:23 +0200 Message-Id: <20230623085830.749991-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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_PASS,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?1769483387412947402?= X-GMAIL-MSGID: =?utf-8?q?1769483387412947402?= Fix the mutex.h inclusion order as it seems to be the only one misplaces. Signed-off-by: Herve Codina Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index ce537b4ca6ca..71d0424383b6 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -5,9 +5,9 @@ */ #include #include +#include #include #include -#include #include #include From patchwork Fri Jun 23 08:58:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629623vqr; Fri, 23 Jun 2023 02:00:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+QAFQvvCaODMFYIfZRaV94om00bNXkRiN2OkFMhACZMbPAU8K03BtaJJFS/YTywWUe2m2 X-Received: by 2002:a05:6a00:244a:b0:666:8cbb:6e02 with SMTP id d10-20020a056a00244a00b006668cbb6e02mr25329921pfj.8.1687510851701; Fri, 23 Jun 2023 02:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510851; cv=none; d=google.com; s=arc-20160816; b=w3seKS4mMFzDFIMDEQ77d3LgKPyuuQ/GeRFS6Rhf/2+dQpHK4Aw19vKQ4qk+KMk8gb 60MD0fN/CMuCixp/zIPiSQYKZ7dRrL8n15EMw8VbYi7PZHdjozgpT6sgGdoki6+JCFJw sTgiT3HmMKxW3A/nDpNvQdkB6OWclLwQNL1S9HZBGhA57zzyfy8n/DQA3PwuDACvnaA6 yB+6R74CWzhORrlOJjRwB/3q9wQfgPFxfTjJHDqFaxa9D85gucLoce6Fh3VqFOhpmhu8 zbEcbPe+HyoyH0BqlYa9CsgcvwLYxgs6+tdOf8XwJxfDTQjTEz4TuwkEVs+EpkzNf4ba b/7A== 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=WPVv4brVsiUHGeag/hBIO6Z/lcdFpqC+U3IbirtBNKo=; b=Ex5f+q6iWF4w7pkde40cuXIFml9jm++jjF7GcZbImZn1qjDiuBktiUH44c0EV5ro1T 4gzoeIu8+lsT+bPUt/lbj8AQngyMQs4dRpNx+o0k4ojz0ZbyVWDkpo4I2CJHKzXbj50N Dzc4TWI0RQ5pyCh7zpUnfbfo1Pa0loqBhTpCeCfbwPZzgDr7vKqhVWrl6NPOBzOQhnLs tqyisvOnFRx/Xr9x/+Ny5S7Tsj5LkP3ymPAh6Gru7OAfbu5dLc1J9juE51efrOcZy6wT SejiY5u/cfIRPWfOhgubVIfYpBU0uRhpKTs2knSBrstN7XmRZeu3WOauSs7brFJZwBtB d8tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=LVrM9sWw; 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 a25-20020aa79719000000b00646672f2be3si5698570pfg.282.2023.06.23.02.00.35; Fri, 23 Jun 2023 02:00:51 -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=LVrM9sWw; 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 S231609AbjFWI7S (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231829AbjFWI65 (ORCPT ); Fri, 23 Jun 2023 04:58:57 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 131052694; Fri, 23 Jun 2023 01:58:54 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510733; 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=WPVv4brVsiUHGeag/hBIO6Z/lcdFpqC+U3IbirtBNKo=; b=LVrM9sWwFLLdhXrM05i0UtyEQDJk6FeX3NPv10J51SP2lmGWJbawmPWtBziQwGdIg17o4D LNiBnVjUN0u8VQpy1uO9C9Z7dbO/rqZielSfAES1/L18Dg7yknoK5pPFoXiwkhl29CpCpr fM0LNC86R0tdXOVD17zDKN4ysH+RjzZ0e1BRcDJum0ItlWY9Kavf2UW9eVe8g9X5M7HkrN IMG1nIXLU04hbRVKBUUKu//uLO52Kf3R71TtPf8LSdooyrSwtoCt8eePtR9N2Pv67lZvxT MJxbovHNMRHw2LkSFuCLwqrLFPUdgWw6bs/GE8RncdIrA9mKkD+DCyGN4KieTA== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id E1C0BE0009; Fri, 23 Jun 2023 08:58:51 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v6 07/13] minmax: Introduce {min,max}_array() Date: Fri, 23 Jun 2023 10:58:24 +0200 Message-Id: <20230623085830.749991-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483378801542033?= X-GMAIL-MSGID: =?utf-8?q?1769483378801542033?= Introduce min_array() (resp max_array()) in order to get the minimal (resp maximum) of values present in an array. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy --- include/linux/minmax.h | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 396df1121bff..798c6963909f 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -133,6 +133,70 @@ */ #define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) +/* + * Remove a const qualifier from integer types + * _Generic(foo, type-name: association, ..., default: association) performs a + * comparison against the foo type (not the qualified type). + * Do not use the const keyword in the type-name as it will not match the + * unqualified type of foo. + */ +#define __unconst_integer_type_cases(type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 + +#define __unconst_integer_typeof(x) typeof( \ + _Generic((x), \ + char: (char)0, \ + __unconst_integer_type_cases(char), \ + __unconst_integer_type_cases(short), \ + __unconst_integer_type_cases(int), \ + __unconst_integer_type_cases(long), \ + __unconst_integer_type_cases(long long), \ + default: (x))) + +/* + * Do not check the array parameter using __must_be_array(). + * In the following legit use-case where the "array" passed is a simple pointer, + * __must_be_array() will return a failure. + * --- 8< --- + * int *buff + * ... + * min = min_array(buff, nb_items); + * --- 8< --- + * + * The first typeof(&(array)[0]) is needed in order to support arrays of both + * 'int *buff' and 'int buff[N]' types. + * + * The array can be an array of const items. + * typeof() keeps the const qualifier. Use __unconst_integer_typeof() in order + * to discard the const qualifier for the __element variable. + */ +#define __minmax_array(op, array, len) ({ \ + typeof(&(array)[0]) __array = (array); \ + typeof(len) __len = (len); \ + __unconst_integer_typeof(__array[0]) __element = __array[--__len]; \ + while (__len--) \ + __element = op(__element, __array[__len]); \ + __element; }) + +/** + * min_array - return minimum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define min_array(array, len) __minmax_array(min, array, len) + +/** + * max_array - return maximum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define max_array(array, len) __minmax_array(max, array, len) + /** * clamp_t - return a value clamped to a given range using a given type * @type: the type of variable to use From patchwork Fri Jun 23 08:58:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629663vqr; Fri, 23 Jun 2023 02:00:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Tv7eP41LSiVhs7b2h50ElCKtAkp/9Vrn8RM9b52GBzWb+u6W6/c7zF44YhLjewAPdfdqK X-Received: by 2002:a05:6a20:748c:b0:106:9266:4448 with SMTP id p12-20020a056a20748c00b0010692664448mr31960998pzd.16.1687510853961; Fri, 23 Jun 2023 02:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510853; cv=none; d=google.com; s=arc-20160816; b=MrPbVl1EYj4KQygxi/Xdvh98JeeHYV/xYdAcnVlMobeVxTA2Av1b8Lp90XsA3gIEQQ xdifAZo7R2AF+gTtrOdXjhE9tTNHwhMIZchAXQs0DNMdebBkgoP/vNAYKO3zQKyYerJp VfAIZFWjix9jk8Qmrl1Sb8/FKZOk79AsGwl4Nm+iwWKSfRsyXgGBxTB/9VhuCfXpbPGv BI1XAXs+ndTsSht867T99vEqSszBtU1SWc0Zwj6IJ+xZTmP76DqLPPluAk8ybWll0DV1 EjzZX9klz1k3RMk2BtVBFCgGXC7WCrv2DcXfzXvhsnfLjCKhsajY07v8eKT60a/0QLCm MeQA== 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=E9t2e1q3XqXgkAJ8mkN8CCPIM4SOxAmZg6pkigwfbv4=; b=UcnhP/NHvrjNLvfDYAEhp8kcHp4la2tXlAbo9nfedSxP2sB1jinvpyj/5KzKgyUE/f R0+CAot/cGIsg9rMpJ5+3Td6+Ar/yNdy1cuUtA0Ycad6oqJRVbZ/o/34Hr2DThQm9MnS FeIPZLDTISyw+ZhqkAG6W+irLjdrwNZgVvW+Je7eCNvOQ3hvw4/Xu2hNJHrgErqyxk0T mshRymY0jQfe/VZHFpMF5IoJtCJJ/N8ZR6MmjTMFTs2suwfcL3p567v2qiPyZCYAOe+C 3r6qniTWGy+4WKha3KECRGr44buv2wb4lXsWaY2mi1SZ90ioduseyuZYYJSzl15VPikx eRqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=LEQ97ShR; 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 j137-20020a636e8f000000b0053578f3de77si6009225pgc.239.2023.06.23.02.00.36; Fri, 23 Jun 2023 02:00:53 -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=LEQ97ShR; 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 S231974AbjFWI7X (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbjFWI7E (ORCPT ); Fri, 23 Jun 2023 04:59:04 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C5B26A1; Fri, 23 Jun 2023 01:58:57 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510735; 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=E9t2e1q3XqXgkAJ8mkN8CCPIM4SOxAmZg6pkigwfbv4=; b=LEQ97ShR1EMDXWLw8NWSlhKLPMTuk+/B/eKxLPY/qhtYF6SRZwlX2JrVaLWrq4TnQnGEQC 4d3JhmMIvOowmnxRcxn3Si9I6Yc39FqHSL9RIBAFhDtIcqtfSF6mf+mldQ6bkAi8gL43Qr SDI6gwfa1OnNFQ+N/zHFVsKFPcF99J49K8zCtJqgyUAHMhVbQXiibUsQ1AgUBpjeAtlW8n E9lb+Pe/C0I42rRMp0mCPuJmgcwDG57v/dTE4f/2YZ/JQCNaQthZS6cwMW3hjxI+yxY0U5 h8Kq0JpayMWc79ddAyyfso4nj+bCyfpoZhjvt7o0t6aG2f42QWVJv8k3fFzLiw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id DBB0FE000C; Fri, 23 Jun 2023 08:58:53 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 08/13] iio: inkern: Use max_array() to get the maximum value from an array Date: Fri, 23 Jun 2023 10:58:25 +0200 Message-Id: <20230623085830.749991-9-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483380888871617?= X-GMAIL-MSGID: =?utf-8?q?1769483380888871617?= Use max_array() to get the maximum value from an array instead of a custom local loop. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 71d0424383b6..8bfd91f74101 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -875,11 +876,7 @@ static int iio_channel_read_max(struct iio_channel *chan, return -EINVAL; switch (*type) { case IIO_VAL_INT: - *val = vals[--length]; - while (length) { - if (vals[--length] > *val) - *val = vals[length]; - } + *val = max_array(vals, length); break; default: /* FIXME: learn about max for other iio values */ From patchwork Fri Jun 23 08:58:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5629913vqr; Fri, 23 Jun 2023 02:01:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7I75A5xhMwJDDOZjpyzBkGPkpX2KJx7GcBCtOAheyuFaiyJzTSQcAQGJcrGf93On7J3r+/ X-Received: by 2002:a05:6a21:6811:b0:118:b2e1:9adb with SMTP id wr17-20020a056a21681100b00118b2e19adbmr20062657pzb.61.1687510876927; Fri, 23 Jun 2023 02:01:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510876; cv=none; d=google.com; s=arc-20160816; b=lFRH9xthKTGOLLoN9N6iEKujUDmkhkF13cNQhtEpiNvMED0YnOGABvO152mEic85JI Z6RLXo3Ssrt3Z7BRvZGNAHuEIBEAeKprDHaGapgZzx9SI0oDdYfbGZ75HSbKzFz/9V8B KfBlTYCT17AWxW8WICmTgPEeHQxbavGrD9QCew2CwFGrMoWg+/oz+vil4S8pRlsyIglO fdRBvHdNrV1QHjT+oB63XIvM8vF0LahiDcaDUuMlTKy+sriFEoA2je1x/r9cn3eGhX85 kQsGleyEt1VMmd51R/5c1WJW2iSAsyTd+r9OiAsWM6f1s1CZxfJQcUGHcZdoKNjwAXMK J8vQ== 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=/3vY6PvUZlTSJ5HdHvT7yC0rLG7cHyF3d0FdWNs26M4=; b=VybjNb6zUMqeSIqFMFS0OVKqRSR/ZFjGFjoq8/G4yFL/0DglWahj4lBPmPo00rNWLq 2mZhiDgY7g2rTYKROSUCSxG7cSB3bE5Nj8OfBJHtC6gcAUEaJVqEgkpz0QhnEJfKJIUC BoWsebnBEcw11LO8Sbd6ER8e5iXYQLjIZ7dRmoksQVbqpwF28rN4Q1w4GJ01eq0G5hIX Lk8CDSVfRmcviMf89Xtc6KgK3oR/jRwrmBJUYM3y1hMdB4VkIrdkvirz0hu92HROEA/0 hNLz3xpQ/7shL5I+EXHtYbk5xspo66q+l2cirAGPBLLzh63MpDjYOz3w71TnGWJmUI81 U8bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ffGwx+1N; 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 k62-20020a638441000000b0055390a944c1si3722465pgd.551.2023.06.23.02.00.54; Fri, 23 Jun 2023 02:01: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=ffGwx+1N; 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 S232083AbjFWI7l (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231980AbjFWI7R (ORCPT ); Fri, 23 Jun 2023 04:59:17 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88DD2271B; Fri, 23 Jun 2023 01:59:00 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510738; 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=/3vY6PvUZlTSJ5HdHvT7yC0rLG7cHyF3d0FdWNs26M4=; b=ffGwx+1NpPd8Gs4Bcn/9Y7DNE8c/5/vM1PDI/QXNuCi0EWVJEkH/as6BGMRRdbLxdmUWFG al/MuOhaHQLiBAuDvZd0/rTMoFW1hOmVSpvZUxZY0oRT1HUlVCkt0lEchORrYXKC7IyzAT nOEqag2Hq67673AvuRCJiu81sS1i1SFcmrg7Z7Pl7Qms3R/tLhupd/UxX5vv3B/tpL1V+0 L1lmIgHTpJIuc2cynxNL8eUxiFqWE+CIOX+N3Dkj97yfXpUA7jA+8thDfoH8yoz2yYzr8B hw40pGBXx6gRVlrYzj50EOKxr6cdd/PHsgXv8lcJw/H3sQPnaNqbYU8cmjOoGA== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id E3A52E0003; Fri, 23 Jun 2023 08:58:55 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 09/13] iio: inkern: Replace a FIXME comment by a TODO one Date: Fri, 23 Jun 2023 10:58:26 +0200 Message-Id: <20230623085830.749991-10-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483405245338570?= X-GMAIL-MSGID: =?utf-8?q?1769483405245338570?= This FIXME comment is more a TODO one. It is a note when someone will need for this currently unsupported case. Change from FIXME to TODO. Signed-off-by: Herve Codina Suggested-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 8bfd91f74101..19ddd77adb11 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -879,7 +879,7 @@ static int iio_channel_read_max(struct iio_channel *chan, *val = max_array(vals, length); break; default: - /* FIXME: learn about max for other iio values */ + /* TODO: learn about max for other iio values */ return -EINVAL; } return 0; From patchwork Fri Jun 23 08:58:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5630194vqr; Fri, 23 Jun 2023 02:01:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40KmYYyUDQ+odv5+Sebziy3UwuyKes4PHM0ljINczVJ3aHf3SQop1j3/9Eul+6oBjGW3MV X-Received: by 2002:a92:da52:0:b0:341:c05c:2813 with SMTP id p18-20020a92da52000000b00341c05c2813mr16811102ilq.0.1687510903226; Fri, 23 Jun 2023 02:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510903; cv=none; d=google.com; s=arc-20160816; b=XLvg8vMPkgZbD2dUnkepqbWntOZQSS6haS5KSxvVpE7NqD3R0rHyM2orx+tk3Bwj92 EKAYvko12ZV2g71sTE6jvmSLtJsy/LpwK7O8I4rnCJO+jJgV62MNDheAZkQsGMsfBJFJ mb2IwdNyd/JRxz4FoGaCJgdY26/KfNEk45DawT6EciQlVptBcVDwXKQBtWJrSNyS3ywv 0giY+i6KLYjOjWa6/d9WAiSGthI+cdhEf4oc7TaC38sD1jcSUJUOJ0Mp+NeNUzcY5tPA VcRxQWJkFQs0YeYJQ7UxV/23UeY6l3CHdlysZNB76UzWyjYARQJIPUC5RilpvfA9Q1nr rOeg== 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=LmVBaT1XSwl45bLGn3KFVgFskQ2sa3mEJW+ejheEDG4=; b=hmEcSOpIy7oCvARQMWKE5xB8DrpSGY6fKUuHLjPqqvk2FSLg8G3VJhXPl+pSmx4nqd lHf02qPyu7PxuLExhEcvFJDTo6nl4tjVcgnD0oZZVvg6l7ne+54fh3Hd2bQ4yxXPf/Bu AXorkOb3SMqXsei9n/+/c9cZhCJi+f4nwEeuEMSSWcUoxCHqL4F2eCOGE0HsxOWnVg4k QKYJW8pv5iA2i4n9UmNAgoB2sPdsAJz2uhVIafHlJy2cA2cqfGzjJCHFqf2delJIXXRW ScHRxH+Q8dKb4fiuBqa+WNN+16Y604O+Pjic5EEQIT0Yp+dkOmX0qVVK2s/PW3cLuASb tKyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=PT79qeZ5; 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 g28-20020aa79f1c000000b0065bbe39e1b3si4644200pfr.146.2023.06.23.02.01.13; Fri, 23 Jun 2023 02:01:43 -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=PT79qeZ5; 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 S231935AbjFWI7o (ORCPT + 99 others); Fri, 23 Jun 2023 04:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232062AbjFWI7W (ORCPT ); Fri, 23 Jun 2023 04:59:22 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4338A213E; Fri, 23 Jun 2023 01:59:02 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510740; 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=LmVBaT1XSwl45bLGn3KFVgFskQ2sa3mEJW+ejheEDG4=; b=PT79qeZ5ATXAGei2EHtmw9Ll9SzrHrts23MAxiEs48kmV+mYIKjyqryxF5IzGnCoJIPCci Ac/kjN3O2X7biLtzVeYB1KM1qPgTvVUiWnWhJX7Cz2rjSjWoyP30cF8pm5Gdxps2CbdMgP C7T6oUahuWlo+A72o3mauFbRB2Db5SGfVLD9i+LNhlUhL+an0dn9UfWF4567Tq5eSlfh2q t67iyHTsaM9sONXuLIOM26hO8hr1aqohG72feAmtKuKIbp/jFJ8hwi1VBx0iy3tBjFU12H f6JZKcVp2KWAy3EbVI76UhOKUF4kYOL/8dPc2wbgqNTYLfaUsH4U9cLgIwYnsw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id C2558E000A; Fri, 23 Jun 2023 08:58:58 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 10/13] iio: inkern: Add a helper to query an available minimum raw value Date: Fri, 23 Jun 2023 10:58:27 +0200 Message-Id: <20230623085830.749991-11-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483432807260435?= X-GMAIL-MSGID: =?utf-8?q?1769483432807260435?= A helper, iio_read_max_channel_raw() exists to read the available maximum raw value of a channel but nothing similar exists to read the available minimum raw value. This new helper, iio_read_min_channel_raw(), fills the hole and can be used for reading the available minimum raw value of a channel. It is fully based on the existing iio_read_max_channel_raw(). Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- drivers/iio/inkern.c | 63 ++++++++++++++++++++++++++++++++++++ include/linux/iio/consumer.h | 12 +++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 19ddd77adb11..7a1f6713318a 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -909,6 +909,69 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val) } EXPORT_SYMBOL_GPL(iio_read_max_channel_raw); +static int iio_channel_read_min(struct iio_channel *chan, + int *val, int *val2, int *type, + enum iio_chan_info_enum info) +{ + const int *vals; + int length; + int ret; + + ret = iio_channel_read_avail(chan, &vals, type, &length, info); + if (ret < 0) + return ret; + + switch (ret) { + case IIO_AVAIL_RANGE: + switch (*type) { + case IIO_VAL_INT: + *val = vals[0]; + break; + default: + *val = vals[0]; + if (val2) + *val2 = vals[1]; + } + return 0; + + case IIO_AVAIL_LIST: + if (length <= 0) + return -EINVAL; + switch (*type) { + case IIO_VAL_INT: + *val = min_array(vals, length); + break; + default: + /* TODO: learn about min for other iio values */ + return -EINVAL; + } + return 0; + + default: + return -EINVAL; + } +} + +int iio_read_min_channel_raw(struct iio_channel *chan, int *val) +{ + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev); + int ret; + int type; + + mutex_lock(&iio_dev_opaque->info_exist_lock); + if (!chan->indio_dev->info) { + ret = -ENODEV; + goto err_unlock; + } + + ret = iio_channel_read_min(chan, val, NULL, &type, IIO_CHAN_INFO_RAW); +err_unlock: + mutex_unlock(&iio_dev_opaque->info_exist_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iio_read_min_channel_raw); + int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev); diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index f536820b9cf2..e9910b41d48e 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -301,6 +301,18 @@ int iio_write_channel_raw(struct iio_channel *chan, int val); */ int iio_read_max_channel_raw(struct iio_channel *chan, int *val); +/** + * iio_read_min_channel_raw() - read minimum available raw value from a given + * channel, i.e. the minimum possible value. + * @chan: The channel being queried. + * @val: Value read back. + * + * Note, if standard units are required, raw reads from iio channels + * need the offset (default 0) and scale (default 1) to be applied + * as (raw + offset) * scale. + */ +int iio_read_min_channel_raw(struct iio_channel *chan, int *val); + /** * iio_read_avail_channel_raw() - read available raw values from a given channel * @chan: The channel being queried. From patchwork Fri Jun 23 08:58:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 112006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5648093vqr; Fri, 23 Jun 2023 02:44:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zWr6MQaRrN9E0HqV/6ToOTJ1FHscqvdxFchXAtScL3ZqlzXpveDBuGmEvrTWX1IgugPvj X-Received: by 2002:a17:902:6b45:b0:1ac:84dd:6d1f with SMTP id g5-20020a1709026b4500b001ac84dd6d1fmr18799529plt.1.1687513499449; Fri, 23 Jun 2023 02:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687513499; cv=none; d=google.com; s=arc-20160816; b=NBpyCrigz3AJeqkaafgIetcxqmTwEbHpo8kc+XjhoebD7i7QDnjuujY8cus5f6dBh4 KEJNYFj1JLD9SyTP3EdOjaOJ+XUBIgrql6yiWNrKBYmYxUNzxm/GJnCIxSYMwZIg+TgG vcL3BF7Gw6+5ecuip7wUvRt7TP15oaWU1P3CLGq655p3KY7EKI12bF+kYin6KQe8UMGf Gm0JH9xAKbqL4QgA9eiFLvEynumxzyXYXpceh1dtzjchd/0BIfDRqAKKWvMdZ6GHbu/I OZxMbnavT7RZ/KvHl4Osa3AZrhnVFooRJU9CYAfofgH7/skxDvtjn7QkB+YVXUcIX+yM toSw== 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=kVNcNG6lGwmhGkvgIcyEWY+MHma3vPNVL1G9SDQv0N4=; b=IPZp4sPXNTMAKJo+4DLf0K+PYTejswzUQMzVp+ZlA+hCM9iu7nTIBUYQxr8wxRbky5 knuMQhaq5QJBNmlgnN5E9ll+4nlELiF9HO4YHk8+xM4GkjfoLawt6wXPhX1Ncg/UJauM Ohr5B5hJ6/uRhP2IlMRlgmCToqH03GKT1V4kLwnSyvMZFx5qvaW/1bViPgKEeVZE2PDC OxS1mcmeNhUxw65bKd6OhRjwUbiDQB5CgcBYATEP9VvvyfuSA7nwVfVVZUFOy1YxG0JG +LskuaIwpYId2mW6JrbxbJ/NgE0zRaxwVJPojAO5+kMdgWLVZv0aa/xbXm7PlOU/n6hH uAOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=NFa8AHoK; 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 c11-20020a170902d48b00b001990520ebccsi742375plg.587.2023.06.23.02.44.47; Fri, 23 Jun 2023 02:44:59 -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=NFa8AHoK; 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 S231582AbjFWJAH (ORCPT + 99 others); Fri, 23 Jun 2023 05:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbjFWI7c (ORCPT ); Fri, 23 Jun 2023 04:59:32 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DC83294F; Fri, 23 Jun 2023 01:59:03 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510742; 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=kVNcNG6lGwmhGkvgIcyEWY+MHma3vPNVL1G9SDQv0N4=; b=NFa8AHoKRE12t09DpcXaVFTI8PO3edG9JnWGegP3OkV+14qrVfmrQHlJ6NJ+TpuxwzLVA6 f7KT4l3NLQeVGnpM0/hpHFDZ5njd6Osa68j78+2RbRhMTCmyWII/7X2ikwdlZnWMgg/2QC Nzbb0+JPJkXRxh9TBkhI2sioMXEF+sW7V9Rv9rbndl32ZkTPda4l6ghWVmd4pP/uZCFfr8 K8aQJgJ3hgvnrESCgsgDcJ4I0Rdzaj6GwviIUsjbyhP5W7CQRjOfwBKhcGRq0c8BtO9ia5 MT4SCCM0IzJ22na3KD7kOfn8AkKoc1LGUc2R4z+DPoGFuJpP4o7cdEsf3DdOOQ== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id A2F02E0008; Fri, 23 Jun 2023 08:59:00 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v6 11/13] ASoC: soc-dapm.h: Convert macros to return a compound literal Date: Fri, 23 Jun 2023 10:58:28 +0200 Message-Id: <20230623085830.749991-12-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769486154892672904?= X-GMAIL-MSGID: =?utf-8?q?1769486154892672904?= The SND_SOC_DAPM_* helpers family are used to build widgets array in a static way. Convert them to return a compound literal in order to use them in both static and dynamic way. With this conversion, the different SND_SOC_DAPM_* parameters can be computed by the code and the widget can be built based on this parameter computation. 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_INPUT(name); ... } Signed-off-by: Herve Codina Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy --- include/sound/soc-dapm.h | 138 ++++++++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 46 deletions(-) diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 87f8e1793af1..2e38dff16779 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -42,36 +42,45 @@ struct soc_enum; /* codec domain */ #define SND_SOC_DAPM_VMID(wname) \ -{ .id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0} /* platform domain */ #define SND_SOC_DAPM_SIGGEN(wname) \ -{ .id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM } #define SND_SOC_DAPM_SINK(wname) \ -{ .id = snd_soc_dapm_sink, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_sink, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM } #define SND_SOC_DAPM_INPUT(wname) \ -{ .id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM } #define SND_SOC_DAPM_OUTPUT(wname) \ -{ .id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM } #define SND_SOC_DAPM_MIC(wname, wevent) \ -{ .id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD} #define SND_SOC_DAPM_HP(wname, wevent) \ -{ .id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD} #define SND_SOC_DAPM_SPK(wname, wevent) \ -{ .id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD} #define SND_SOC_DAPM_LINE(wname, wevent) \ -{ .id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD} @@ -82,93 +91,110 @@ struct soc_enum; /* path domain */ #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\ wcontrols, wncontrols) \ -{ .id = snd_soc_dapm_pga, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pga, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols} #define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\ wcontrols, wncontrols) \ -{ .id = snd_soc_dapm_out_drv, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_out_drv, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols} #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \ wcontrols, wncontrols)\ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols} #define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \ wcontrols, wncontrols)\ -{ .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols} /* DEPRECATED: use SND_SOC_DAPM_SUPPLY */ #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \ -{ .id = snd_soc_dapm_micbias, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_micbias, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = NULL, .num_kcontrols = 0} #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \ -{ .id = snd_soc_dapm_switch, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_switch, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = 1} #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \ -{ .id = snd_soc_dapm_mux, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mux, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = 1} #define SND_SOC_DAPM_DEMUX(wname, wreg, wshift, winvert, wcontrols) \ -{ .id = snd_soc_dapm_demux, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_demux, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = 1} /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */ #define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\ wcontrols) \ -{ .id = snd_soc_dapm_pga, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pga, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)} #define SOC_MIXER_ARRAY(wname, wreg, wshift, winvert, \ wcontrols)\ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)} #define SOC_MIXER_NAMED_CTL_ARRAY(wname, wreg, wshift, winvert, \ wcontrols)\ -{ .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)} /* path domain with event - event handler must return 0 for success */ #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \ wncontrols, wevent, wflags) \ -{ .id = snd_soc_dapm_pga, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pga, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_OUT_DRV_E(wname, wreg, wshift, winvert, wcontrols, \ wncontrols, wevent, wflags) \ -{ .id = snd_soc_dapm_out_drv, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_out_drv, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \ wncontrols, wevent, wflags) \ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \ wcontrols, wncontrols, wevent, wflags) \ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, \ .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \ wevent, wflags) \ -{ .id = snd_soc_dapm_switch, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_switch, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = 1, \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \ wevent, wflags) \ -{ .id = snd_soc_dapm_mux, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mux, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = 1, \ .event = wevent, .event_flags = wflags} @@ -176,101 +202,121 @@ struct soc_enum; /* additional sequencing control within an event type */ #define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \ wevent, wflags) \ -{ .id = snd_soc_dapm_pga, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pga, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags, \ .subseq = wsubseq} #define SND_SOC_DAPM_SUPPLY_S(wname, wsubseq, wreg, wshift, winvert, wevent, \ wflags) \ -{ .id = snd_soc_dapm_supply, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_supply, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags, .subseq = wsubseq} /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */ #define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \ wevent, wflags) \ -{ .id = snd_soc_dapm_pga, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pga, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \ .event = wevent, .event_flags = wflags} #define SOC_MIXER_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \ wevent, wflags) \ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \ .event = wevent, .event_flags = wflags} #define SOC_MIXER_NAMED_CTL_E_ARRAY(wname, wreg, wshift, winvert, \ wcontrols, wevent, wflags) \ -{ .id = snd_soc_dapm_mixer, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_mixer, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \ .event = wevent, .event_flags = wflags} /* events that are pre and post DAPM */ #define SND_SOC_DAPM_PRE(wname, wevent) \ -{ .id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD} #define SND_SOC_DAPM_POST(wname, wevent) \ -{ .id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \ .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \ .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD} /* stream domain */ #define SND_SOC_DAPM_AIF_IN(wname, stname, wchan, wreg, wshift, winvert) \ -{ .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \ .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), } #define SND_SOC_DAPM_AIF_IN_E(wname, stname, wchan, wreg, wshift, winvert, \ wevent, wflags) \ -{ .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \ .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags } #define SND_SOC_DAPM_AIF_OUT(wname, stname, wchan, wreg, wshift, winvert) \ -{ .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \ .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), } #define SND_SOC_DAPM_AIF_OUT_E(wname, stname, wchan, wreg, wshift, winvert, \ wevent, wflags) \ -{ .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \ .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags } #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \ -{ .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) } #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \ wevent, wflags) \ -{ .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \ -{ .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), } #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \ wevent, wflags) \ -{ .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_CLOCK_SUPPLY(wname) \ -{ .id = snd_soc_dapm_clock_supply, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_clock_supply, .name = wname, \ .reg = SND_SOC_NOPM, .event = dapm_clock_event, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD } /* generic widgets */ #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \ -{ .id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \ +(struct snd_soc_dapm_widget) { \ + .id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \ .reg = wreg, .shift = wshift, .mask = wmask, \ .on_val = won_val, .off_val = woff_val, } #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \ -{ .id = snd_soc_dapm_supply, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_supply, .name = wname, \ SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ .event = wevent, .event_flags = wflags} #define SND_SOC_DAPM_REGULATOR_SUPPLY(wname, wdelay, wflags) \ -{ .id = snd_soc_dapm_regulator_supply, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_regulator_supply, .name = wname, \ .reg = SND_SOC_NOPM, .shift = wdelay, .event = dapm_regulator_event, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \ .on_val = wflags} #define SND_SOC_DAPM_PINCTRL(wname, active, sleep) \ -{ .id = snd_soc_dapm_pinctrl, .name = wname, \ +(struct snd_soc_dapm_widget) { \ + .id = snd_soc_dapm_pinctrl, .name = wname, \ .priv = (&(struct snd_soc_dapm_pinctrl_priv) \ { .active_state = active, .sleep_state = sleep,}), \ .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \ From patchwork Fri Jun 23 08:58:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5630285vqr; Fri, 23 Jun 2023 02:01:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7p1OcuJ//w0OX3OsZkZL2DCHYadNlGE+GasDn2L4dzNtXj/MDz3C6lO4dxC8xlrcfbmrLR X-Received: by 2002:a17:902:6b44:b0:1b5:3500:9e22 with SMTP id g4-20020a1709026b4400b001b535009e22mr18867158plt.63.1687510915866; Fri, 23 Jun 2023 02:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510915; cv=none; d=google.com; s=arc-20160816; b=cxADMHw65RGqFGG4fTs98yqbOIJosjr7knA1TBpN5kWGkS6O8uT3GlaEsJpaUR8nwG 1dnSmLo2HVKmxxh6zTT025KEYq5W87all13xdl7qZH6POuIW0RIfG8EcQncOcvVQ0Enh Wzk6WVZMcsMLjl+i8iwny19yJ6AvscQLBp6n+xPrfIj1dW3drBJEKMDHup3Mj2lv7A0d wuI8tbwCnoUD906Q5LUTcWTYnh5Rk2Z6LhmosMbgJkFFs8PJHgPXh5/ZFfpLbKGdntMm QqzOBKdQaKuCTA+pEBFu1tFWO4MSgewgZ9HBm8DNy+z9Atsibk6G41hksAbN3eDMlaIr KiaA== 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=g4cV75C48WjlZ1uH7x686man+Y4XKaXT2s76C7ByXHU=; b=YCrQfBhqblyBadFVlOaX5cFuEMYkUj7PNGv4WjDOaVg/hjgYTG9C6Wr65ke+kHWN2M 0WROGvW4tjsEip7mnhZBGtpovVHlC8mQFPwp0E2Rt7M5pCq3Xoa5q0CAMjFM1/LiNYGE kS2x6I14LgYedEbLEEHuIu3kmecXbqSmWWkdkAWBaAfmM/FizHppv8jB2Q6jbLdztT5+ n7zw49LGAXzuyViTG2SUQDAze54ZEKwnvbtVW6HDq9EEDFq9xGFKSvPCnVtP43meysGU zjyISpTqEz9b7LKiePXmfMWiyMlYuUokHZYCxtF4fyD0cg8mcpZNJmDt/1ZFNrCGE8mI j15Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cNIG7a7D; 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 a15-20020a170902eccf00b001b0603829afsi9069365plh.405.2023.06.23.02.01.28; Fri, 23 Jun 2023 02:01:55 -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=cNIG7a7D; 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 S232076AbjFWJAQ (ORCPT + 99 others); Fri, 23 Jun 2023 05:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232089AbjFWI7q (ORCPT ); Fri, 23 Jun 2023 04:59:46 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3BB2684; Fri, 23 Jun 2023 01:59:15 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510744; 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=g4cV75C48WjlZ1uH7x686man+Y4XKaXT2s76C7ByXHU=; b=cNIG7a7DvSGzDkzG7jWngfe1hIsCX42FUD/E9hv3czwV94WBADyNaPWR1ORdyUGjvG0nCH jDUno1CmlOL2ftVZ36lOgj78llIusMdEdB4LSA28nrdLKdUc+CkqPN0uEtsYTwuig5ms2c OnnuxwRLQpUectd6SLZM1uqdBsfsw2NgcT2ZSBIshGMNmrM6rggeFctaSMcwxWLz7uyZzN uxsKDAPFvV2X2CRQjdBYuMC4Qf88HbTP+pfx6BXNFtvsi0EIBsGLYS8USn2FhHDOZjgJ2N qQOGUI8vgX7aICMAhJ7IoZpnYIaiZuD7gjOAY3HyE7n304RacWH9abuoPGjD4w== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id A68C9E000D; Fri, 23 Jun 2023 08:59:02 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v6 12/13] ASoC: codecs: Add support for the generic IIO auxiliary devices Date: Fri, 23 Jun 2023 10:58:29 +0200 Message-Id: <20230623085830.749991-13-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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,SPF_HELO_PASS, 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?1769483446236854003?= X-GMAIL-MSGID: =?utf-8?q?1769483446236854003?= Industrial I/O devices can be present in the audio path. These devices needs to be used as audio components in order to be fully integrated in the audio path. This support allows to consider these Industrial I/O devices as auxiliary audio devices and allows one to control them using mixer controls. Signed-off-by: Herve Codina Reviewed-by: Jonathan Cameron Reviewed-by: Christophe Leroy --- sound/soc/codecs/Kconfig | 12 ++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/audio-iio-aux.c | 344 +++++++++++++++++++++++++++++++ 3 files changed, 358 insertions(+) create mode 100644 sound/soc/codecs/audio-iio-aux.c diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 44806bfe8ee5..92b7c417f1b2 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -53,6 +53,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_AK5558 imply SND_SOC_ALC5623 imply SND_SOC_ALC5632 + imply SND_SOC_AUDIO_IIO_AUX imply SND_SOC_AW8738 imply SND_SOC_AW88395 imply SND_SOC_BT_SCO @@ -608,6 +609,17 @@ config SND_SOC_ALC5632 tristate depends on I2C +config SND_SOC_AUDIO_IIO_AUX + tristate "Audio IIO Auxiliary device" + depends on IIO + help + Enable support for Industrial I/O devices as audio auxiliary devices. + This allows to have an IIO device present in the audio path and + controlled using mixer controls. + + To compile this driver as a module, choose M here: the module + will be called snd-soc-audio-iio-aux. + config SND_SOC_AW8738 tristate "Awinic AW8738 Audio Amplifier" select GPIOLIB diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 2c45c2f97e4e..f2828d3616c5 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -45,6 +45,7 @@ snd-soc-ak4671-objs := ak4671.o snd-soc-ak5386-objs := ak5386.o snd-soc-ak5558-objs := ak5558.o snd-soc-arizona-objs := arizona.o arizona-jack.o +snd-soc-audio-iio-aux-objs := audio-iio-aux.o snd-soc-aw8738-objs := aw8738.o snd-soc-aw88395-lib-objs := aw88395/aw88395_lib.o snd-soc-aw88395-objs := aw88395/aw88395.o \ @@ -421,6 +422,7 @@ obj-$(CONFIG_SND_SOC_AK5558) += snd-soc-ak5558.o obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o obj-$(CONFIG_SND_SOC_ARIZONA) += snd-soc-arizona.o +obj-$(CONFIG_SND_SOC_AUDIO_IIO_AUX) += snd-soc-audio-iio-aux.o obj-$(CONFIG_SND_SOC_AW8738) += snd-soc-aw8738.o obj-$(CONFIG_SND_SOC_AW88395_LIB) += snd-soc-aw88395-lib.o obj-$(CONFIG_SND_SOC_AW88395) +=snd-soc-aw88395.o diff --git a/sound/soc/codecs/audio-iio-aux.c b/sound/soc/codecs/audio-iio-aux.c new file mode 100644 index 000000000000..a8bf14239bd7 --- /dev/null +++ b/sound/soc/codecs/audio-iio-aux.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// ALSA SoC glue to use IIO devices as audio components +// +// Copyright 2023 CS GROUP France +// +// Author: Herve Codina + +#include +#include +#include +#include +#include +#include + +#include +#include + +struct audio_iio_aux_chan { + struct iio_channel *iio_chan; + const char *name; + int max; + int min; + bool is_invert_range; +}; + +struct audio_iio_aux { + struct device *dev; + struct audio_iio_aux_chan *chans; + unsigned int num_chans; +}; + +static int audio_iio_aux_info_volsw(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value; + + uinfo->count = 1; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = chan->max - chan->min; + uinfo->type = (uinfo->value.integer.max == 1) ? + SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; + return 0; +} + +static int audio_iio_aux_get_volsw(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value; + int max = chan->max; + int min = chan->min; + bool invert_range = chan->is_invert_range; + int ret; + int val; + + ret = iio_read_channel_raw(chan->iio_chan, &val); + if (ret < 0) + return ret; + + ucontrol->value.integer.value[0] = val - min; + if (invert_range) + ucontrol->value.integer.value[0] = max - ucontrol->value.integer.value[0]; + + return 0; +} + +static int audio_iio_aux_put_volsw(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value; + int max = chan->max; + int min = chan->min; + bool invert_range = chan->is_invert_range; + int val; + int ret; + int tmp; + + val = ucontrol->value.integer.value[0]; + if (val < 0) + return -EINVAL; + if (val > max - min) + return -EINVAL; + + val = val + min; + if (invert_range) + val = max - val; + + ret = iio_read_channel_raw(chan->iio_chan, &tmp); + if (ret < 0) + return ret; + + if (tmp == val) + return 0; + + ret = iio_write_channel_raw(chan->iio_chan, val); + if (ret) + return ret; + + return 1; /* The value changed */ +} + +static int audio_iio_aux_add_controls(struct snd_soc_component *component, + struct audio_iio_aux_chan *chan) +{ + struct snd_kcontrol_new control = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = chan->name, + .info = audio_iio_aux_info_volsw, + .get = audio_iio_aux_get_volsw, + .put = audio_iio_aux_put_volsw, + .private_value = (unsigned long)chan, + }; + + return snd_soc_add_component_controls(component, &control, 1); +} + +/* + * These data could be on stack but they are pretty big. + * As ASoC internally copy them and protect them against concurrent accesses + * (snd_soc_bind_card() protects using client_mutex), keep them in the global + * data area. + */ +static struct snd_soc_dapm_widget widgets[3]; +static struct snd_soc_dapm_route routes[2]; + +/* Be sure sizes are correct (need 3 widgets and 2 routes) */ +static_assert(ARRAY_SIZE(widgets) >= 3, "3 widgets are needed"); +static_assert(ARRAY_SIZE(routes) >= 2, "2 routes are needed"); + +static int audio_iio_aux_add_dapms(struct snd_soc_component *component, + struct audio_iio_aux_chan *chan) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + char *output_name; + char *input_name; + char *pga_name; + int ret; + + input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name); + if (!input_name) + return -ENOMEM; + + output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name); + if (!output_name) { + ret = -ENOMEM; + goto out_free_input_name; + } + + pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name); + if (!pga_name) { + ret = -ENOMEM; + goto out_free_output_name; + } + + widgets[0] = SND_SOC_DAPM_INPUT(input_name); + widgets[1] = SND_SOC_DAPM_OUTPUT(output_name); + widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0); + ret = snd_soc_dapm_new_controls(dapm, widgets, 3); + if (ret) + goto out_free_pga_name; + + routes[0].sink = pga_name; + routes[0].control = NULL; + routes[0].source = input_name; + routes[1].sink = output_name; + routes[1].control = NULL; + routes[1].source = pga_name; + ret = snd_soc_dapm_add_routes(dapm, routes, 2); + + /* Allocated names are no more needed (duplicated in ASoC internals) */ + +out_free_pga_name: + kfree(pga_name); +out_free_output_name: + kfree(output_name); +out_free_input_name: + kfree(input_name); + return ret; +} + +static int audio_iio_aux_component_probe(struct snd_soc_component *component) +{ + struct audio_iio_aux *iio_aux = snd_soc_component_get_drvdata(component); + struct audio_iio_aux_chan *chan; + int ret; + int i; + + for (i = 0; i < iio_aux->num_chans; i++) { + chan = iio_aux->chans + i; + + ret = iio_read_max_channel_raw(chan->iio_chan, &chan->max); + if (ret) + return dev_err_probe(component->dev, ret, + "chan[%d] %s: Cannot get max raw value\n", + i, chan->name); + + ret = iio_read_min_channel_raw(chan->iio_chan, &chan->min); + if (ret) + return dev_err_probe(component->dev, ret, + "chan[%d] %s: Cannot get min raw value\n", + i, chan->name); + + if (chan->min > chan->max) { + /* + * This should never happen but to avoid any check + * later, just swap values here to ensure that the + * minimum value is lower than the maximum value. + */ + dev_dbg(component->dev, "chan[%d] %s: Swap min and max\n", + i, chan->name); + swap(chan->min, chan->max); + } + + /* Set initial value */ + ret = iio_write_channel_raw(chan->iio_chan, + chan->is_invert_range ? chan->max : chan->min); + if (ret) + return dev_err_probe(component->dev, ret, + "chan[%d] %s: Cannot set initial value\n", + i, chan->name); + + ret = audio_iio_aux_add_controls(component, chan); + if (ret) + return ret; + + ret = audio_iio_aux_add_dapms(component, chan); + if (ret) + return ret; + + dev_dbg(component->dev, "chan[%d]: Added %s (min=%d, max=%d, invert=%s)\n", + i, chan->name, chan->min, chan->max, + str_on_off(chan->is_invert_range)); + } + + return 0; +} + +static const struct snd_soc_component_driver audio_iio_aux_component_driver = { + .probe = audio_iio_aux_component_probe, +}; + +static int audio_iio_aux_probe(struct platform_device *pdev) +{ + struct audio_iio_aux_chan *iio_aux_chan; + struct device *dev = &pdev->dev; + struct audio_iio_aux *iio_aux; + const char **names; + u32 *invert_ranges; + int count; + int ret; + int i; + + iio_aux = devm_kzalloc(dev, sizeof(*iio_aux), GFP_KERNEL); + if (!iio_aux) + return -ENOMEM; + + iio_aux->dev = dev; + + count = device_property_string_array_count(dev, "io-channel-names"); + if (count < 0) + return dev_err_probe(dev, count, "failed to count io-channel-names\n"); + + iio_aux->num_chans = count; + + iio_aux->chans = devm_kmalloc_array(dev, iio_aux->num_chans, + sizeof(*iio_aux->chans), GFP_KERNEL); + if (!iio_aux->chans) + return -ENOMEM; + + names = kcalloc(iio_aux->num_chans, sizeof(*names), GFP_KERNEL); + if (!names) + return -ENOMEM; + + invert_ranges = kcalloc(iio_aux->num_chans, sizeof(*invert_ranges), GFP_KERNEL); + if (!invert_ranges) { + ret = -ENOMEM; + goto out_free_names; + } + + ret = device_property_read_string_array(dev, "io-channel-names", + names, iio_aux->num_chans); + if (ret < 0) { + dev_err_probe(dev, ret, "failed to read io-channel-names\n"); + goto out_free_invert_ranges; + } + + /* + * snd-control-invert-range is optional and can contain fewer items + * than the number of channels. Unset values default to 0. + */ + count = device_property_count_u32(dev, "snd-control-invert-range"); + if (count > 0) { + count = min_t(unsigned int, count, iio_aux->num_chans); + ret = device_property_read_u32_array(dev, "snd-control-invert-range", + invert_ranges, count); + if (ret < 0) { + dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n"); + goto out_free_invert_ranges; + } + } + + for (i = 0; i < iio_aux->num_chans; i++) { + iio_aux_chan = iio_aux->chans + i; + iio_aux_chan->name = names[i]; + iio_aux_chan->is_invert_range = invert_ranges[i]; + + iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name); + if (IS_ERR(iio_aux_chan->iio_chan)) { + ret = PTR_ERR(iio_aux_chan->iio_chan); + dev_err_probe(dev, ret, "get IIO channel '%s' failed\n", + iio_aux_chan->name); + goto out_free_invert_ranges; + } + } + + platform_set_drvdata(pdev, iio_aux); + + ret = devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver, + NULL, 0); +out_free_invert_ranges: + kfree(invert_ranges); +out_free_names: + kfree(names); + return ret; +} + +static const struct of_device_id audio_iio_aux_ids[] = { + { .compatible = "audio-iio-aux" }, + { } +}; +MODULE_DEVICE_TABLE(of, audio_iio_aux_ids); + +static struct platform_driver audio_iio_aux_driver = { + .driver = { + .name = "audio-iio-aux", + .of_match_table = audio_iio_aux_ids, + }, + .probe = audio_iio_aux_probe, +}; +module_platform_driver(audio_iio_aux_driver); + +MODULE_AUTHOR("Herve Codina "); +MODULE_DESCRIPTION("IIO ALSA SoC aux driver"); +MODULE_LICENSE("GPL"); From patchwork Fri Jun 23 08:58:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 111994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5630239vqr; Fri, 23 Jun 2023 02:01:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IK3AIs/aNR2yiUOmkqzf+vYoZKaNBLhTBWRCca5+ef4lkIGdFVmkrdJvwzuX+6HtcYCc9 X-Received: by 2002:a05:6808:612:b0:3a1:a178:80ff with SMTP id y18-20020a056808061200b003a1a17880ffmr1991490oih.4.1687510907582; Fri, 23 Jun 2023 02:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687510907; cv=none; d=google.com; s=arc-20160816; b=EGBZBmrW6vuCqjJw2KHBmtizbSmYfUYBi9axFJcKXsC9ijNU11iLe+Oih3Xezd0+OM o2rjQRmJFIyZ/AAvQvylzGFCGlwkY2IIDOXl/StFPfJYqPQ+MPhqNvGOF8FMjVMzr84j PCVrc7rUNoQkSxFUhxNSHQam6GON1qQbo/RR2/IIN70kSTGcOkRLEpbcm/zm1bkqgjcw o6gRiSVCIYxSqJFPcJ7+THdPHR42clZEJ2ob1wg0YpM5dlSjv56Hu0UdBdb/D/Kvzm0j uwsgH2RtEB/RaDiqRETJ5C7vCgbawIoOBXvIYw9mfCdqKKuAu8u42tZuK7VCS/xlsABC md8A== 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=WiCubefUJT8lqguruRQEQMdku90oEPaE9zL5TkFrvME=; b=IvQW3/X2KijK4/iyG+87JWqYes86yqUdBCNgx/v5Sx0zRmRThKJZJQcK3odWuLGOci RZxf+dGgkwPbaO42uGL5rLFq607fofsfE5uyRrM/LP5Oq6yVfW/lx5kgM/2s9Yg2vfDA 5vN3NgqoXhz0ZNOshoYB0vxFQAYeokoUs/Ql/l6HsufwRSuxDYxDjiwlfc/ZT0SmHKgr PShsXuwWazxrDioqeCpLA5vZnc5yO+taElqrGHnmLp0mVYXf7+R1K1zgdFiqxIXppJ3g DX81gY70wvP+YcKV1e1w0BJG7oVmGsEYiHiRULiLUtuMTjuAtgsQFd+blvdngJredKlZ 3krg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Er+F9DMU; 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 v70-20020a638949000000b0053094305b59si1676373pgd.875.2023.06.23.02.01.21; Fri, 23 Jun 2023 02:01:47 -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=Er+F9DMU; 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 S232017AbjFWJAL (ORCPT + 99 others); Fri, 23 Jun 2023 05:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbjFWI7l (ORCPT ); Fri, 23 Jun 2023 04:59:41 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF0A2680; Fri, 23 Jun 2023 01:59:11 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687510746; 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=WiCubefUJT8lqguruRQEQMdku90oEPaE9zL5TkFrvME=; b=Er+F9DMUoyhxCT4e3wLHeMsS1VAU8PNH1Bul8bZKuE7b9UDWdIF+nl22bVCY4NHvZ9+3Xy vnwe1qxOxH/XHl1klPoHe3AQjzL2rg2JKRWm9yPuf4iKAfdVFHAjeN5ojCxCEvtaNopi5e WIpPlPZxrioUfayxbqdutoHsTZz+naztAStXu/QGtC7en9ibj7HvS9gznvcv9nqGW1rPS5 11Anc5P4V8bc6IpMlrf3gLKvD2d8Snf5O+TyQ/TBc8U6ZKAryVv1rRNFW5S7ANa8WTu1fd 38yb7/Tbgo2tth/LaCfHJC9M9i2KM33OLVDwtohEKTAWWkKjVCqC3D29bF9h5g== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 52723E000B; Fri, 23 Jun 2023 08:59:04 +0000 (UTC) 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 , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Wojciech Ziemba , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v6 13/13] ASoC: simple-card: Handle additional devices Date: Fri, 23 Jun 2023 10:58:30 +0200 Message-Id: <20230623085830.749991-14-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623085830.749991-1-herve.codina@bootlin.com> References: <20230623085830.749991-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_PASS,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?1769483437717850891?= X-GMAIL-MSGID: =?utf-8?q?1769483437717850891?= An additional-devs subnode can be present in the simple-card top node. This subnode is used to declared some "virtual" additional devices. Create related devices from this subnode and avoid this subnode presence to interfere with the already supported subnodes analysis. Signed-off-by: Herve Codina Reviewed-by: Christophe Leroy --- sound/soc/generic/simple-card.c | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 6f044cc8357e..ae4a47018278 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -348,6 +348,7 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, struct device *dev = simple_priv_to_dev(priv); struct device_node *top = dev->of_node; struct device_node *node; + struct device_node *add_devs; uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev); bool is_top = 0; int ret = 0; @@ -359,6 +360,8 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, is_top = 1; } + add_devs = of_get_child_by_name(top, PREFIX "additional-devs"); + /* loop for all dai-link */ do { struct asoc_simple_data adata; @@ -367,6 +370,12 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, struct device_node *np; int num = of_get_child_count(node); + /* Skip additional-devs node */ + if (node == add_devs) { + node = of_get_next_child(top, node); + continue; + } + /* get codec */ codec = of_get_child_by_name(node, is_top ? PREFIX "codec" : "codec"); @@ -380,12 +389,15 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, /* get convert-xxx property */ memset(&adata, 0, sizeof(adata)); - for_each_child_of_node(node, np) + for_each_child_of_node(node, np) { + if (np == add_devs) + continue; simple_parse_convert(dev, np, &adata); + } /* loop for all CPU/Codec node */ for_each_child_of_node(node, np) { - if (plat == np) + if (plat == np || add_devs == np) continue; /* * It is DPCM @@ -427,6 +439,7 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, } while (!is_top && node); error: + of_node_put(add_devs); of_node_put(node); return ret; } @@ -464,6 +477,31 @@ static int simple_for_each_link(struct asoc_simple_priv *priv, return ret; } +static void simple_depopulate_aux(void *data) +{ + struct asoc_simple_priv *priv = data; + + of_platform_depopulate(simple_priv_to_dev(priv)); +} + +static int simple_populate_aux(struct asoc_simple_priv *priv) +{ + struct device *dev = simple_priv_to_dev(priv); + struct device_node *node; + int ret; + + node = of_get_child_by_name(dev->of_node, PREFIX "additional-devs"); + if (!node) + return 0; + + ret = of_platform_populate(node, NULL, NULL, dev); + of_node_put(node); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, simple_depopulate_aux, priv); +} + static int simple_parse_of(struct asoc_simple_priv *priv, struct link_info *li) { struct snd_soc_card *card = simple_priv_to_card(priv); @@ -493,6 +531,10 @@ static int simple_parse_of(struct asoc_simple_priv *priv, struct link_info *li) if (ret < 0) return ret; + ret = simple_populate_aux(priv); + if (ret < 0) + return ret; + ret = snd_soc_of_parse_aux_devs(card, PREFIX "aux-devs"); return ret;