From patchwork Tue May 23 15:12:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 13252504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6744C7EE26 for ; Tue, 23 May 2023 15:14:05 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 311A3208; Tue, 23 May 2023 17:13:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 311A3208 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854843; bh=omyK8EMZFIuk2H2NcLRfSrI/todecGtoc2EXB60MIrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=TPzwArumM0d+tOZEMIUUpBd3QsvwNWvLBsZmD4uCtn9HpgFWZb2fG97YTtXU+4ptJ HSzdu+s/Ko7Kmb126ARURIPa5Fcy8FcW5Ijr2JsUxdFj408SKU4+s2WQp/m2TVrxqn TyMK3A17pbDeLWZj+74FVwtPzkwx5fGTykNcwitc= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3EF5FF80544; Tue, 23 May 2023 17:12:44 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B9DA9F8026A; Tue, 23 May 2023 17:12:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3867FF8026A; Tue, 23 May 2023 17:12:39 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 40B58F80086 for ; Tue, 23 May 2023 17:12:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 40B58F80086 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=lWPvq8cH Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 43971C0002; Tue, 23 May 2023 15:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854751; 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=GyTXVmL/5teIh8xuYTUUi3ltQcCGVDf6AcEbfADS6og=; b=lWPvq8cHwMHdAVLda4Fk0kYQp99VhMod7NzwHN7h56uzv3+/D0DlZbDz13zNPwM2YrzGCd OtRfdXy/i4wOdaa6ba+WNUEAuFl9vAZ1Pe4xzCgsOBnWQKGu7uESCYVfm0DyEF8/7ELdGf tlRHgkS3twGReZMKIDkZLvLssgthcUV3phHWcU0gTfeek7p2DVaVJjFOcaaVQzpKazHq1U sOVJ3/gP1i/mOimYgjbGMqJB6pWCiQkyKxmyB98bChgTXQnW4StIpZ3Mlxp6Hv/Q7MipUZ 8xuXSd1oGp8rjcWTT4Nj0FajGz9JkgIri0PP+quO25k8G/bMyJAD0+O4P/fo6w== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 1/9] ASoC: dt-bindings: Add audio-iio-aux Date: Tue, 23 May 2023 17:12:15 +0200 Message-Id: <20230523151223.109551-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: FG75ZL6G56TTKGVZCERLJCA6WAQOSKGF X-Message-ID-Hash: FG75ZL6G56TTKGVZCERLJCA6WAQOSKGF X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- .../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 Tue May 23 15:12:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 13252506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF7A3C77B75 for ; Tue, 23 May 2023 15:14:30 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9FC16826; Tue, 23 May 2023 17:13:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9FC16826 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854867; bh=cvt4qSEMq/xa7Zrcpq+YtTKXlgndf6d5qkmGg4fmBF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CDGgya9a8Uy6QNwjRgu//aIOxpZnjsPP8wuZU5/MeA4wHtaES3PwpOtF/ITmzh358 HBESALG+qGvB12otD+xBuWbvoL7dDD8BxNTfy4bm248N4cVTPXculBPXzwUJVpVTXl xbSbxVFjQU6Gldo2QtZ5tPIrjlQTmr80PP7UWyi0= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6D031F80570; Tue, 23 May 2023 17:12:49 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0B4E8F80563; Tue, 23 May 2023 17:12:49 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D8929F80553; Tue, 23 May 2023 17:12:44 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B1368F800DF for ; Tue, 23 May 2023 17:12:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B1368F800DF Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=EvezOhAv Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 85B0DC0008; Tue, 23 May 2023 15:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854759; 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=5N9NSA3ycLJUSucfBk1k0lUH03RfOeo/UXNYngARjpo=; b=EvezOhAvwI6QLfONUptzen99rqPE2gcCja9TLNST4YCqrBJe1hw2Csg90Nenr/O7S/mpKL ezDdg89iS2+2OjRf8OwzWRWlmmXsLO4mQBRl8CDdVM4i+zEHSu8n4Y5sNoDP78LA6fCj3k 9DufT16RrzkROIA/bwVHFm8tZ85m7SKPF+MpoE+5Ah8Kek0l277HVdwFPIG1rR1j2g77W1 ZTHJX/b3OW0fnXF28gDgm3+m2YZLAUT0YtmlNWGTPk8ghEbgVcP+Ls4U+Xz6M4LiPPt61Q IQp30rqwgpAs5Z3W17X4wneSKsUKYfZwqVcknT2cDx9W38kp0iRCay0Gen5/EQ== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 2/9] ASoC: dt-bindings: simple-card: Add additional-devs subnode Date: Tue, 23 May 2023 17:12:16 +0200 Message-Id: <20230523151223.109551-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: J3O5OEOGI6Z4J2NHAT2XSIPTCFNESYVD X-Message-ID-Hash: J3O5OEOGI6Z4J2NHAT2XSIPTCFNESYVD X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- .../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 Tue May 23 15:12:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 13252507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 51374C77B75 for ; Tue, 23 May 2023 15:14:56 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 49B42839; Tue, 23 May 2023 17:14:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 49B42839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854894; bh=6T9XHnTWoSc7qaR9ksGN8PqCFcVFpFzIRQ1LrWaIMbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UTKikr7SAvlMVq0bcp4nk7Qyr/8bKjnSst9mbVKgt7IL7/GDiyF82j3p3oJ/J0xH6 tNlz5L+jlAaCWJGwuUMp+V7LUll08Qn13YKNg9MrLfncBECOlwmd20tAEK06hH/gXR y/9D1XcM8F/EkjXHDyDw45daJl5K7nVbs0dz1LKw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 65B14F8058C; Tue, 23 May 2023 17:12:50 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E1CBAF80563; Tue, 23 May 2023 17:12:49 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AD9FDF80567; Tue, 23 May 2023 17:12:45 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DBEADF80548 for ; Tue, 23 May 2023 17:12:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DBEADF80548 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=SHHtcMfh Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id C2404C000C; Tue, 23 May 2023 15:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854762; 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=iaB/0wDo6caLF16LcGUil+N2SlVgAqTWL0MVlJHk1e0=; b=SHHtcMfh8AILZzywUiY+JuAsqPsBNtIXcI99+1kFaoQx5tj45NNugTxMOGHKc9hsTpwRQt rekNusNg0UOA9IZBQjhpH6EnJljUKPtYlMsujlxrj9Pdi8NLBEzE5+3kImsVnYjIwY8hwH tFx7JS/y8wGDFj3ki1R0Gg3gk8tqZ1KTbXxxm6netGuSSOd1LxYP/puO8boVlj/KFEbNEQ tTcDj0Xb17GTmOJX/tWtfSzWYp1vX4LV6zx3Vs64lntAwgGStP3ZRyP489WiO7pyKuVLbV /rnhF87CmiYy8fNos+Ria3POWqavMpiBPD1d7l1w4hcgPh9m46SMxDrE/jy1vg== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 3/9] iio: inkern: Check error explicitly in iio_channel_read_max() Date: Tue, 23 May 2023 17:12:17 +0200 Message-Id: <20230523151223.109551-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: 7MX5FLMI7OKS75GFS3M6MMXHRSXWVDKE X-Message-ID-Hash: 7MX5FLMI7OKS75GFS3M6MMXHRSXWVDKE X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 Tue May 23 15:12:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 13252514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33B06C7EE26 for ; Tue, 23 May 2023 15:15:05 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EA63983B; Tue, 23 May 2023 17:14:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EA63983B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854903; bh=0j6HFxNsZpLS0q8NIkLckwtshJIE16XVruIPnFGFY1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=qN4zPRzfo/olXLLfuJfJPbhdxzAYajdkvNqMqdbLFYqV+4Sv/k0/XR12SqGBojU/X vsEPb9JiZlzh369tWtlUl0d8a4SL0gwO3gdtf7QwgRAWM32VU6r10XuBdP3A+nGr2L YMkHfacA43PsPxhgjwnD7fKdUAXo1DkGa9BrCs0E= Received: by alsa1.perex.cz (Postfix, from userid 50401) id DCC44F805A1; Tue, 23 May 2023 17:12:52 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 67414F805A0; Tue, 23 May 2023 17:12:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A1652F80568; Tue, 23 May 2023 17:12:48 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B5CF4F80548 for ; Tue, 23 May 2023 17:12:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B5CF4F80548 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=DCytTTlw Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id BB54AC0013; Tue, 23 May 2023 15:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854764; 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=B5Rp2Pe2hP+HZpzHQ6QCIJu8OkM1HG2ZQQx1TOta918=; b=DCytTTlwfYZ07XCnOC1y/PBxT/gt5Bv3UFAB1EGhRvleTo7U3AOLO8sxWlvI8yCC0E5kJS hpdV6Nx4P+qyD22hEu+LTLixj4X2zB/efzVU0C2VRSSinU3m/rfAcPup0BHVQSk3uxYh2P mFRLWDfTLBEW1GBVHtMaEeP7q5QAmR7hEaY2V4cwIUPHj2Ynid7erDgBv2fbMX7Hl3C6RA Ptx7ur7w85pztC+90lDvuhCgjxyjfuv32j7XqgLXnRmgq+2aYluashCX0sIDzD+SyjQeuo GXwV0M4nRAM/LZamGyqdUMVZ4aKLA/gi73pV79ZxUbqjigH9hGmJKAy5M8Yvfw== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 4/9] iio: consumer.h: Fix raw values documentation notes Date: Tue, 23 May 2023 17:12:18 +0200 Message-Id: <20230523151223.109551-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: QL5JNAMC4GVVBYYGYPC4YA43IMH4MHE3 X-Message-ID-Hash: QL5JNAMC4GVVBYYGYPC4YA43IMH4MHE3 X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 Tue May 23 15:12:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 13252515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D335C7EE26 for ; Tue, 23 May 2023 15:15:23 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 47BE4857; Tue, 23 May 2023 17:14:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 47BE4857 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854920; bh=SWkFMorzUG/B74G+IKL+xq+GSHPrDH7fAwdTOyUk+5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=P8vDyQQ3rlFg/nfjRpu7QJ60ZA6HguskVc27mhRxlgMnN2DmOWOD8H45LMq8XgAf4 U6bLLFsIAzJGlPwufMfjsLe28HNlu/PQ7YFQZfTtFCH+j4mFQ7AqRYA4+Np0M8jcuK lB78IK4hZ59m/hhXNjMspV5Zbh636YU+U25RE+Pc= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 73DFEF805B5; Tue, 23 May 2023 17:12:56 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0EEABF805AA; Tue, 23 May 2023 17:12:56 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C1BEAF805A0; Tue, 23 May 2023 17:12:51 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B6F4FF8057A for ; Tue, 23 May 2023 17:12:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B6F4FF8057A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=jP6jBYuj Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id E0A95C0003; Tue, 23 May 2023 15:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854768; 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=Q6wIbPlk+sj6CdZp+Zuzd40lnLgxHVN50MgCxORNnY8=; b=jP6jBYujyeZx6X332heui2VJL16U7AzCW3vRSIz0ewZFtPtxlyxjZtVeFB8kQkprD8paxU Yr0eWkm1yaW/OOQ6+vlTRY1zscjzVn1COnKeZ4GmVPc3eNVFbJuaSb1l+vwojg3zSloMf3 yIEj34rk/kxXtdQkEODM+DqhBLca6pwBDT+t9e23wopKuP6BqTJ4MoORm6el/gcdZW1V+L ZF2I/SqzRV4SH6nwka6/tzPUwQUsX6mSPhgZSL9HAf2SAPbLbk1dGA7H4ry/qOZlNovOst cysuG+zyzlqXbP3bRZFmE7YApdvmeYBXjnZy/dsTnVxeGZAsXGyuvJp+ad08ug== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 5/9] iio: inkern: Add a helper to query an available minimum raw value Date: Tue, 23 May 2023 17:12:19 +0200 Message-Id: <20230523151223.109551-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: FNKNZGU2FBCL7TS2BIDKKJ4FFKSZVYS6 X-Message-ID-Hash: FNKNZGU2FBCL7TS2BIDKKJ4FFKSZVYS6 X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Acked-by: Jonathan Cameron --- drivers/iio/inkern.c | 70 ++++++++++++++++++++++++++++++++++++ include/linux/iio/consumer.h | 12 +++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index f738db9a0c04..07b26ff8a334 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -915,6 +915,76 @@ 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) +{ + 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; + + switch (ret) { + case IIO_AVAIL_RANGE: + switch (*type) { + case IIO_VAL_INT: + *val = vals[0]; + break; + default: + *val = vals[0]; + *val2 = vals[1]; + } + return 0; + + case IIO_AVAIL_LIST: + if (length <= 0) + return -EINVAL; + switch (*type) { + case IIO_VAL_INT: + *val = vals[--length]; + while (length) { + if (vals[--length] < *val) + *val = vals[length]; + } + break; + default: + /* FIXME: 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 Tue May 23 15:12: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: 13252516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0C16C77B75 for ; Tue, 23 May 2023 15:15:49 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9FBD9207; Tue, 23 May 2023 17:14:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9FBD9207 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854946; bh=cKnE6MOfSRRFJRCk9xV4VRZ0DGjqhFr8a4myCmk3KAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OU5/hOVUeh2oU9JrN348vPN9gg4UNG8PAqHiK2EJLHhuGtoNE/RnSrupjTmQUA89v n26HdZ7jrKco9C1OGQaZUV/lOnVJYlevyg/sfOyRRI/srMbmtcC1v5vkawSAWtGa09 vUlxr1WpEBcCj4Fq10pzL5XhFe33DnOpe8o91rP0= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 12145F805C2; Tue, 23 May 2023 17:12:58 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 623E2F805C3; Tue, 23 May 2023 17:12:57 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 25D4BF805AA; Tue, 23 May 2023 17:12:53 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7713AF80579 for ; Tue, 23 May 2023 17:12:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7713AF80579 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=OJWTwCnl Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 3D8ECC0008; Tue, 23 May 2023 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DrMZ95BLnGjcDr2P+qmpgq0WbufG1vHwF/RueaYJS28=; b=OJWTwCnlWn+Xthk0Xfek+s2r5juF2h7SNMSfs+CDSVW51lOc8n36dXjfmK4BGPJBYbTAPt 86JjRd4Mcrd49qLXHvDbArKC/E8hki2QuxdslB+MaEZqxwzDROqTu3G8Z0Oz5C6eQX+enW 1FEIgs2cKR0VhE8GLUYxb3DvhzjllrjjdzEjgxzsfnZWENwkRrwuSFZJ1V6owA63QJX4at E+lI4csyxxNOldCH4gEdjII1NaSjAe/tFPmI74ueGDSpFa0nTIg+UIMmKFywgHxEA6Z5du 0P+mF8ZkTdK3AP4vyWzvlgggQVXF+c6HB2D3ptw9OPIUQUqHT2gaJZ7N9lx2tQ== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 6/9] ASoC: soc-dapm.h: Add a helper to build a DAPM widget dynamically Date: Tue, 23 May 2023 17:12:20 +0200 Message-Id: <20230523151223.109551-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: UCAOEZ4DYNLKB3M6WO7S566VWSU7GKRK X-Message-ID-Hash: UCAOEZ4DYNLKB3M6WO7S566VWSU7GKRK X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The SND_SOC_DAPM_* helpers family are used to build widgets array in a static way. Introduce SND_SOC_DAPM_WIDGET() in order to use the SND_SOC_DAPM_* helpers family in a dynamic way. The different SND_SOC_DAPM_* parameters can be computed by the code and the widget can be built based on this parameter computation. For instance: static int create_widget(char *input_name) { struct snd_soc_dapm_widget widget; char name*; ... name = input_name; if (!name) name = "default"; widget = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_INPUT(name)); ... } Signed-off-by: Herve Codina --- include/sound/soc-dapm.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 87f8e1793af1..6b62fe5c779c 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -276,7 +276,17 @@ struct soc_enum; .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD } - +/* + * Helper to create a widget 'dynamically' + * This can be used with any of the SND_SOC_DAPM_* widget helper. + * For instance: + * struct snd_soc_dapm_widget widget; + * ... + * widget = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_INPUT(input_name)); + */ +#define SND_SOC_DAPM_WIDGET(_widget)({ \ + struct snd_soc_dapm_widget _w[1] = { _widget }; \ + _w[0]; }) /* dapm kcontrol types */ #define SOC_DAPM_DOUBLE(xname, reg, lshift, rshift, max, invert) \ From patchwork Tue May 23 15:12: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: 13252517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DCA9C77B75 for ; Tue, 23 May 2023 15:16:05 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5768E200; Tue, 23 May 2023 17:15:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5768E200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854962; bh=StTu1NYwiPiVRX5uxh8vYyDQWpkcbG2tYhChu4t/XP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Ai370/lLJ1UkHOHfHLipzoTW8k7FCxvFLKBdBTkPHV1PxFRGS35/+/B/RU86gXhrl 3H4Rfjy+S+xeVh98U9GLVt7kBWs4Hwrrhfq1B4QaP+/HKQzXzZP6LAkqFZLnRYb7WB RJg7tnRQGNjWWXjuIoU5w8yQSF8Jg0pxx6Iavyzs= Received: by alsa1.perex.cz (Postfix, from userid 50401) id BCD9FF805D5; Tue, 23 May 2023 17:13:04 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id AE270F805C4; Tue, 23 May 2023 17:13:03 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B807AF805D2; Tue, 23 May 2023 17:12:59 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5B065F805AF for ; Tue, 23 May 2023 17:12:52 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5B065F805AF Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=GbtXbWm2 Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 5F82CC0010; Tue, 23 May 2023 15:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854772; 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=KYIlIqVca3vAJgJe+g8vlwK9WmMG6k1vY9NUqUSS7V8=; b=GbtXbWm2sShByDFAqOdoLnI2ZwhLghTVwEnG76MC2ua2ZeyINv0ajSi49e9ONWLbdp1Qsk y0BJCyBei6v3N83LAkx4J6gWDv4YMb85W0TkNX+o/PcTnPEb3xSiAT8dv+Y9onowkmJ8t1 fUjytyKKqoUCLdgycDrurDcU2yKpAD3cuP9F2yDhrv/BKvCCIFX0SohV7yss24zRDrGVXf PiNBVNtL4KcN8c8/3emZ7mqCkK6+12Cg1XcgqQEQLuogPFQzuBSW8f6oElVZ0lvEDGTJAt rbQiKE+2egHTPQB8m5KuK1UQkujlwv8CLfpeUQDSKK5i40hQiAIADYT5oxILUA== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 7/9] ASoC: codecs: Add support for the generic IIO auxiliary devices Date: Tue, 23 May 2023 17:12:21 +0200 Message-Id: <20230523151223.109551-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: OQ4JO5VTOOF43LQIS4SNG4AWN5DVVZGG X-Message-ID-Hash: OQ4JO5VTOOF43LQIS4SNG4AWN5DVVZGG X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 auxliary audio devices and allows to control them using mixer controls. Signed-off-by: Herve Codina Reviewed-by: Jonathan Cameron --- sound/soc/codecs/Kconfig | 12 ++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/audio-iio-aux.c | 302 +++++++++++++++++++++++++++++++ 3 files changed, 316 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..21575c4b35fd --- /dev/null +++ b/sound/soc/codecs/audio-iio-aux.c @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// audio-iio-aux.c -- ALSA SoC glue to use IIO devices as audio components +// +// Copyright 2023 CS GROUP France +// +// Author: Herve Codina + +#include +#include +#include +#include +#include + +struct audio_iio_aux_chan { + struct iio_channel *iio_chan; + const char *name; + bool is_invert_range; + int max; + int min; +}; + +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 = {0}; + + control.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + control.name = chan->name; + control.info = audio_iio_aux_info_volsw; + control.get = audio_iio_aux_get_volsw; + control.put = audio_iio_aux_put_volsw; + control.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] = {0}; +static struct snd_soc_dapm_route routes[2] = {0}; + +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 *input_name = NULL; + char *output_name = NULL; + char *pga_name = NULL; + int ret; + + input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name); + if (!input_name) { + ret = -ENOMEM; + goto end; + } + output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name); + if (!output_name) { + ret = -ENOMEM; + goto end; + } + pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name); + if (!pga_name) { + ret = -ENOMEM; + goto end; + } + + BUILD_BUG_ON(ARRAY_SIZE(widgets) < 3); + widgets[0] = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_INPUT(input_name)); + widgets[1] = SND_SOC_DAPM_WIDGET(SND_SOC_DAPM_OUTPUT(output_name)); + widgets[2] = SND_SOC_DAPM_WIDGET(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 end; + + BUILD_BUG_ON(ARRAY_SIZE(routes) < 2); + 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); + +end: + /* Allocated names are no more needed (duplicated in ASoC internals) */ + kfree(pga_name); + kfree(output_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) { + dev_err(component->dev, "chan[%d] %s: Cannot get max raw value (%d)\n", + i, chan->name, ret); + return ret; + } + + ret = iio_read_min_channel_raw(chan->iio_chan, &chan->min); + if (ret) { + dev_err(component->dev, "chan[%d] %s: Cannot get min raw value (%d)\n", + i, chan->name, ret); + return ret; + } + + /* Set initial value */ + ret = iio_write_channel_raw(chan->iio_chan, + chan->is_invert_range ? chan->max : chan->min); + if (ret) { + dev_err(component->dev, "chan[%d] %s: Cannot set initial value (%d)\n", + i, chan->name, ret); + return ret; + } + + 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, + chan->is_invert_range ? "on" : "off"); + } + + 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 device_node *np = pdev->dev.of_node; + struct audio_iio_aux_chan *iio_aux_chan; + struct audio_iio_aux *iio_aux; + int count; + u32 tmp; + int ret; + int i; + + iio_aux = devm_kzalloc(&pdev->dev, sizeof(*iio_aux), GFP_KERNEL); + if (!iio_aux) + return -ENOMEM; + + iio_aux->dev = &pdev->dev; + + count = of_property_count_strings(np, "io-channel-names"); + if (count < 0) { + dev_err(iio_aux->dev, "%pOF: failed to read io-channel-names\n", np); + return count; + } + + iio_aux->chans = devm_kmalloc_array(&pdev->dev, count, + sizeof(*iio_aux->chans), GFP_KERNEL); + if (!iio_aux->chans) + return -ENOMEM; + iio_aux->num_chans = count; + + for (i = 0; i < iio_aux->num_chans; i++) { + iio_aux_chan = iio_aux->chans + i; + + ret = of_property_read_string_index(np, "io-channel-names", i, + &iio_aux_chan->name); + if (ret < 0) { + dev_err(iio_aux->dev, "%pOF: failed to read io-channel-names[%d]\n", np, i); + return ret; + } + + iio_aux_chan->iio_chan = devm_iio_channel_get(iio_aux->dev, iio_aux_chan->name); + if (IS_ERR(iio_aux_chan->iio_chan)) { + return dev_err_probe(iio_aux->dev, + PTR_ERR(iio_aux_chan->iio_chan), + "get IIO channel '%s' failed\n", + iio_aux_chan->name); + } + + tmp = 0; + of_property_read_u32_index(np, "snd-control-invert-range", i, &tmp); + iio_aux_chan->is_invert_range = tmp; + } + + platform_set_drvdata(pdev, iio_aux); + + return devm_snd_soc_register_component(iio_aux->dev, + &audio_iio_aux_component_driver, + NULL, 0); +} + +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 Tue May 23 15:12: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: 13252519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78CCEC77B75 for ; Tue, 23 May 2023 15:16:25 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 673ED6C0; Tue, 23 May 2023 17:15:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 673ED6C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854982; bh=W3MeMMTxy+pVlU3P67UfZXzoEsayT5B8rpJp8L3Sx9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=lqbxr+RyMqUT8QfD8FFloxyb1jDBZU1cC8NKzpDgLr1HARZgPaJNS8pVpyA/ySan0 4BBpTF16C3pSmBjCSYFfgjM5zyekIMEVEkM60wyc9TGew7oOonyfJyC//LpF4yAnBt S+0sTSTk81rh7bxfMMczncDcQOH5IaiJCPuazLF8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 08F98F805EF; Tue, 23 May 2023 17:13:09 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id DCAA9F805EC; Tue, 23 May 2023 17:13:08 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 796F9F805D7; Tue, 23 May 2023 17:13:04 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B840AF805B4 for ; Tue, 23 May 2023 17:12:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B840AF805B4 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=EBpNWx/8 Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 40781C0018; Tue, 23 May 2023 15:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854774; 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=wyrbVwxZ0KTdJmelqko+tUdutg5HmqXXq7T/rn7OWng=; b=EBpNWx/8LcFOktzb/W/4ZB5ZW9iPWLEYoo9hpOU2o5gxHr7fzxt9ecSz33yHx/0Or82Un7 G7WTwex35OTs3Ydmuwv/GHXCM2fZ7NVPyxKLIaiXEX0WSU5pdrxe15H8feq5tkB5mA6okY Bob3oDS6NogidlnIGqFHA5U2bhdthUhj+xwEjEAHCbPBWC0I+vTscCosqMjTF2ZJLKYONm TbF+yjcNp86S30P7Csq1jV6kGBuvAANsR2HPuoKyNKAdVqJvz62yyZ2efUYPRvX+8MfBgk JSVdO4I0WM+x1rPMw75o0xNTbWMDdWs9wYhU0mkgWBjfX1MCFhj7YbEWpIrqhg== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 8/9] ASoC: simple-card: Add missing of_node_put() in case of error Date: Tue, 23 May 2023 17:12:22 +0200 Message-Id: <20230523151223.109551-9-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: ZMDUZCD5SUNIEM6TCT7UHHR6SY5LSHDN X-Message-ID-Hash: ZMDUZCD5SUNIEM6TCT7UHHR6SY5LSHDN X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In the error path, a of_node_put() for platform is missing. Just add it. Signed-off-by: Herve Codina Acked-by: Kuninori Morimoto --- sound/soc/generic/simple-card.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 6f044cc8357e..5a5e4ecd0f61 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -416,6 +416,7 @@ static int __simple_for_each_link(struct asoc_simple_priv *priv, if (ret < 0) { of_node_put(codec); + of_node_put(plat); of_node_put(np); goto error; } From patchwork Tue May 23 15:12: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: 13252518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15E03C7EE26 for ; Tue, 23 May 2023 15:16:16 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2B20286E; Tue, 23 May 2023 17:15:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2B20286E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684854974; bh=Q3Tagmkm9x49TqXtMJXK2UPLv+r91Z8Cc0MknZnDSRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=akFwme99EIRPTHFS47jOtKvNSCqx1A51chw9K1uzMrzmqCuMAwTwOCUllOjWqjx7/ rmvz+RZrsG8tELnzRS1PPD+LzS6ynfJNGhi2borrGv6q+PLN+Xbgp3NZTdMu3AiAkY pgJFT2BKv/dmNZ49b9gksTur346hEJvawgOE3XIo= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5DE2CF805E0; Tue, 23 May 2023 17:13:07 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 8ECF3F805DF; Tue, 23 May 2023 17:13:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 66F13F805C4; Tue, 23 May 2023 17:13:03 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8CF9AF805AA for ; Tue, 23 May 2023 17:12:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8CF9AF805AA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=IZBvW7uf Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id A8BFCC0002; Tue, 23 May 2023 15:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854776; 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=rIgj9hYW8BvuR/TDsfHXr8sG/1TWuLwG/JP4/jjJtyQ=; b=IZBvW7ufNfmBKRdFYU2zKdQY3poFbD6ku8VIEy0wSJzRFfUMQ0lvdQcbQgs2nS17SfIzAJ tLUjKVqr/RSK7nBgjE3CoOTiMCIp0G/fRadFVnuY0keir3Y0Zu9X3iHCw/YGNgrnIad82L Eqx7GWI1MMPrNJMmDBI/VGXLaDqO6NWhIpdOJsFyMSEZ4+GmP+nUdTb9p+/bWwEBhDC9sG Ym5KhIssszuqIewM+VlX8ZKrLKhStOhiN6uZQfi4yIfw7GzyClaK76oKoB/XSHOO77k4jk HPX5OOXyOts4LDfxRTS1ssBs0dqdxpb0dYgCQz9/mueuDAEHgZRj9BZ4vHYvow== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 9/9] ASoC: simple-card: Handle additional devices Date: Tue, 23 May 2023 17:12:23 +0200 Message-Id: <20230523151223.109551-10-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: XF4R46IGI7VPPGCNOKAR6WX6AYY3F5LL X-Message-ID-Hash: XF4R46IGI7VPPGCNOKAR6WX6AYY3F5LL X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- sound/soc/generic/simple-card.c | 52 +++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 5a5e4ecd0f61..4992ab433d6a 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 @@ -428,6 +440,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; } @@ -652,6 +665,36 @@ static int simple_soc_probe(struct snd_soc_card *card) return 0; } +static void simple_populate_aux_release(struct device *dev, void *res) +{ + of_platform_depopulate(*(struct device **)res); +} + +static int simple_populate_aux(struct asoc_simple_priv *priv) +{ + struct device *dev = simple_priv_to_dev(priv); + struct device_node *node; + struct device **ptr; + int ret; + + node = of_get_child_by_name(dev->of_node, PREFIX "additional-devs"); + if (!node) + return 0; + + ptr = devres_alloc(simple_populate_aux_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = of_platform_populate(node, NULL, NULL, dev); + if (ret) { + devres_free(ptr); + } else { + *ptr = dev; + devres_add(dev, ptr); + } + return ret; +} + static int asoc_simple_probe(struct platform_device *pdev) { struct asoc_simple_priv *priv; @@ -688,6 +731,11 @@ static int asoc_simple_probe(struct platform_device *pdev) return ret; if (np && of_device_is_available(np)) { + ret = simple_populate_aux(priv); + if (ret < 0) { + dev_err_probe(dev, ret, "populate aux error\n"); + goto err; + } ret = simple_parse_of(priv, li); if (ret < 0) {