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: 98036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2201976rwl; Tue, 23 May 2023 08:15:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4S+rmHcHUm2MAO2wVkcsH8dzDg/beX28QDaQPjR0vUPjjnqJPIlwBeCg+irGcMIWGng/va X-Received: by 2002:a05:6a20:748e:b0:10c:b9ed:6a3f with SMTP id p14-20020a056a20748e00b0010cb9ed6a3fmr1316389pzd.7.1684854948760; Tue, 23 May 2023 08:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854948; cv=none; d=google.com; s=arc-20160816; b=L2onkZ551mC5779it04QK6iAQPB9Zrjwsra5lAYH3OMeBBeo6+VMP/kN+6vdGJ5ELm onRhD4IkiDSNHtOZXXu3y4NjKYoy39jjPNnx9zEG0OlcIIq31WKdDQw9EtCmBriJpBEi fgFfOWH9qIGvFiskLQiPUNJF8LAVJ8nnkcSnR5wgu6Kr4M0YIsGLXYdXY6mXu8YxLYkD x1A2A/ey7pFhjxz02eR3hTwGrEvxac3fVbYz+IW6bqbs5PCjL4TkWuiziNflAapae+rX sS1p1Ct0sTTGgFJTEe/f2oMj0q7kWfg9rbn5vDUrDJhUek3xHUT3/JAyNAkIJwlVZ7DM dTtA== 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=GyTXVmL/5teIh8xuYTUUi3ltQcCGVDf6AcEbfADS6og=; b=Vkf5S6n5ttAewAF3MPbFWzeerMyhLv+DAVvH8lDwXCynV1oxugAqbq0EKINJmjacHH smcAWnMZCDhGe6hiwWdYgbk97ke0kHBt+2GHwSVjxyDscWs4txXmPknPqk7f7zrSNYpD hpNfcCwW8vCk2jPl01Zqg37iRJ0UGOgaizcYy9wVy7rzJreYqD+H6t2qylO9UdGlZURB RGu0lN5rTefbrLZlVNiSI+z3YTbAs7GYc6Ygnp/g/dMP3nqBSWwO325A/oWqs5lVPRgE v2/9YZkM5qjD3zoOwCesjs9BgZKMg6+BTMz59vBnlYg26IpZ7QTXMfD4l9yqBbqR38y6 7buA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lWPvq8cH; 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 g68-20020a636b47000000b005303a66d412si125053pgc.812.2023.05.23.08.15.35; Tue, 23 May 2023 08:15:48 -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=lWPvq8cH; 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 S237456AbjEWPMi (ORCPT + 99 others); Tue, 23 May 2023 11:12:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237439AbjEWPMf (ORCPT ); Tue, 23 May 2023 11:12:35 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0243BFA; Tue, 23 May 2023 08:12:32 -0700 (PDT) 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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698462764347860?= X-GMAIL-MSGID: =?utf-8?q?1766698462764347860?= 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: 98047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2209090rwl; Tue, 23 May 2023 08:26:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hHJVq2ZPzmfiow87eQ54uzqiEuac+Xg+PXbEzjbfpaHTSa9t6tqf90nj0x/cxfhZe5HnG X-Received: by 2002:a05:6a20:8f0b:b0:106:a0d1:a0c8 with SMTP id b11-20020a056a208f0b00b00106a0d1a0c8mr17684499pzk.0.1684855574503; Tue, 23 May 2023 08:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684855574; cv=none; d=google.com; s=arc-20160816; b=KU/c4NhSuDJYpFpOIyvP6Pi6FSloZZimQtJ5dWG9JuKYA+QxwJ60AyZYcQT72p1dFy PEx1GVOEFpJvntcGIe9+DpxT8pf26AARLqpwigp/9DQnj5Qw0qufCnIq/Uae8FlL8cEt OynH0RLGD4JXHvHyaq7ALVw96snecCfPoXMkqncZ62pgZgMzBaiF/UfN+dCttq7jdn1a wekbFqL0oQ8m3uhGX8Yrf4u5PYbmR1/1AvwO8GdGdzwn4rc03iKopmZtAzfmKuS76AJL CZr6ShzUvOUEuambmpVZFn3Dpq/FfUGL32Ape2Qg5oh7LzDxUUWjcQOwzj/0XC3REeXB ZR8A== 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=5N9NSA3ycLJUSucfBk1k0lUH03RfOeo/UXNYngARjpo=; b=y4a8ncPCGZ6yXF9LhQUxjUy2JT3WZHoF0qVoqzQvsLA2LDjSSh1y1eBoPhA2QtqKVv +HOGZ2UzBU1J5jnQznbEEXaxHlXjPoIL2nqjeW7WukQvtwhVM01726X0SNqQjIpCCbgT i3dZ0iqxb7oBhDpxaxQoKa6TzHcWgcUYWIXo/m6xZ4o8b8XEIuH4Qg4MlytN76LrI8aB /X4KST/2oR0RgC3IvrHnzBsvFeIelI03IGmC0d/v3lE5XeCZ7y+9ttsnPXAFJZHRT/XH IDEzW2BM5ItXWTGhBHMGebIPTlZA8GjQ+L+oKrd86wZiN6J/DkAOqPI1rK8yHxHv//Fa ilWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EvezOhAv; 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 g80-20020a625253000000b006434e20d01asi5140444pfb.199.2023.05.23.08.26.01; Tue, 23 May 2023 08:26:14 -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=EvezOhAv; 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 S237461AbjEWPMs (ORCPT + 99 others); Tue, 23 May 2023 11:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237126AbjEWPMm (ORCPT ); Tue, 23 May 2023 11:12:42 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42305129; Tue, 23 May 2023 08:12:40 -0700 (PDT) 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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766699118552911215?= X-GMAIL-MSGID: =?utf-8?q?1766699118552911215?= 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: 98037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202225rwl; Tue, 23 May 2023 08:16:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zJGLP9x1vcFRfh/yhO/xXdf8FXAl5nZjeC8Yn98SvfLXfJMVMuINC97UuBw/io6G3Kte8 X-Received: by 2002:a05:6a21:998f:b0:10a:be5c:6e26 with SMTP id ve15-20020a056a21998f00b0010abe5c6e26mr12229623pzb.3.1684854967411; Tue, 23 May 2023 08:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854967; cv=none; d=google.com; s=arc-20160816; b=rc0OhbyXU19Kz1PgrBOrkvzhgncsN8iFFqlpeBceiN7SDGX7WkgtnA7sHFOemX95Q9 CQKWJsnYxzyHy4FU00epusxUZ0iwzjA9FBkwk2pAZwk25mhG9h6YXx6Y8yMAUT2Lssy7 nsDcy2mIun0GBBEHqh+gJ+4+5ocXn8Uj9rgFlTyI8XWqU2dp9xntCMoyDhQfzqV75zh6 6bwQzhxR64yZ/GAzLg6FSkFpyqbzkvAB9ivHcztGHxmmaEZIykfyR3LMY1ORdy8DVHN5 HJfayG8I6IBm//ADfqoIeNs219odEINfNnna87dIrbunwvwlJY8MgsqOZm4cPwQRBMIZ MtCw== 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=iaB/0wDo6caLF16LcGUil+N2SlVgAqTWL0MVlJHk1e0=; b=E63LcNfBXMGlI+q/AcUeujoOIY7ZOqMebeifn6m8LTy8ENBGzEr/gIVBGg9zVoaGeg ORafP/urDEdB68MpuvPKWw4Xt4+WJYdVNc/sZq6YIiQ0+Gx1wO2/qHm9tJCQdlFgSbB7 QFgXJH+oKkRuZ2zAjJBECgrxNA5h/1Y3WROw3h4o2INsIbPASIDt2+Ux6fMHmdFtlJpN 4DwuRk4FSjwfT/nHYXzlNFUNcT2gb8NKD7eeXdKDz0OKDSmqvtR8nkfpkc857doW0DM+ j/Ya07qXamAePbyNQvkf30H22v+GadEcrkmLtrS04v/XWxnlv+gCoxDrknZdtrT8gCQF f8Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SHHtcMfh; 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 g186-20020a6252c3000000b0064d44f6fd24si6488650pfb.56.2023.05.23.08.15.54; Tue, 23 May 2023 08:16:07 -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=SHHtcMfh; 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 S236996AbjEWPMw (ORCPT + 99 others); Tue, 23 May 2023 11:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237458AbjEWPMq (ORCPT ); Tue, 23 May 2023 11:12:46 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C49DA139; Tue, 23 May 2023 08:12:43 -0700 (PDT) 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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698482238446318?= X-GMAIL-MSGID: =?utf-8?q?1766698482238446318?= 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: 98038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202241rwl; Tue, 23 May 2023 08:16:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ij0YNxTAPLkGL00BhtARY3yPLAHgTCWVDrDQRN6PdNIu82QTj+IHppfzTTX/AH1KWTkCZ X-Received: by 2002:a05:6a20:9388:b0:109:2f11:8b77 with SMTP id x8-20020a056a20938800b001092f118b77mr16523030pzh.1.1684854969051; Tue, 23 May 2023 08:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854969; cv=none; d=google.com; s=arc-20160816; b=KPLoVliIxfWhPCNNZBpLqRbU/55dAaGH8/a298nfL6phLraCKDje3nrYplHeuNqg27 lgAz3xDfghWhOBPRCcXiRUicWlQRJ7rySmanNRbuPIr3GPz8Cr6ZF9COwL4enrT6HnDV 98cag4DqqlxYqNjJwPllHbgI/U1Wm033RcK0/tB5UTB7ZSVz2cWjJS4bezaAL8i0RNWI PygT4MVfMOgUHkEG1zm/ZNWSKxQqFcdf8ISh8psuin2Vl1jUvccAqVX7lZXcQCUR8nsF o9tt8i3NBZ3V31WB948QEmPaSg2Ym6wwV6fzoxaYs/sNhqt87na/5sta+3I6dh7rtpCs 9Xvg== 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=B5Rp2Pe2hP+HZpzHQ6QCIJu8OkM1HG2ZQQx1TOta918=; b=r9M2wtsU9NGuM31Tp/COZYPGlRaggpqu0jDk6lHOcgK4mzzxFnaNB5F/y3bSDCDjdI UQCY3teNkzmV8t6iwxR72yRnORgAw0Hspiyv0lXos901A+YRPhQ/iCfawYLpQo5ezePt JCafyeIbSXSfgTnniK7HV1hgpTbZjNY18TF8Je4znC2kJz9h6rwjl2ISYk4XKeSVsi13 GcXRAqkYtj0QGpKfuXEaVW6NC3DTkz62SORWdJyQHJ3EvOV9YvaXpdgalE/BefoxMOrm BfHgEUqX0Q5/i+Lr+1KsryLU5Us3xwpLBkHyNmurkgkD7WWVpd8X6DI7YHosinaOGubQ KUuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=DCytTTlw; 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-20020aa798de000000b0064d72691d73si1653315pfm.316.2023.05.23.08.15.56; Tue, 23 May 2023 08:16:09 -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=DCytTTlw; 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 S237475AbjEWPMy (ORCPT + 99 others); Tue, 23 May 2023 11:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237467AbjEWPMu (ORCPT ); Tue, 23 May 2023 11:12:50 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 115EB13E; Tue, 23 May 2023 08:12:45 -0700 (PDT) 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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698484022716896?= X-GMAIL-MSGID: =?utf-8?q?1766698484022716896?= 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: 98039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202337rwl; Tue, 23 May 2023 08:16:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70Ljp6fjaxIqr7eoUQ3ta5B08FlBPPJR9ZUumQQGgILTWKr8eEzVyQtFL6XvVsYBmNbCtL X-Received: by 2002:a17:902:e848:b0:1ad:d500:19d3 with SMTP id t8-20020a170902e84800b001add50019d3mr19168837plg.23.1684854976262; Tue, 23 May 2023 08:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854976; cv=none; d=google.com; s=arc-20160816; b=0RG4ay37/U1idsNtNcCotbGwhfAxsk5ttXXhjk1O6CtqMJpAJTFOEjQp+/N0uVdk74 X2ubIvx9dq3Zhy/YIeEML1vG/1VQWuAnlGC2DEgOVgPxHz90y3Tgkt8ac5iH7f/hldP+ f9yhLF46Ru8Ryj+KaePUktvh4LWj4ZnPkA+VXvr6D1Q3peCuWoBWbJeVArCvcKwOtiCK AG8PJBpLN0QXqTDVd78X/DQWMV3h0zHKa9B0SlLofZ4j5pM+vdkyi95z9zO7UbCiOw1v AIu3/t5bWkxcxxPMSIXMGL0LnQgHjYyJtSwDct7Wz5JkYU3AJ0Tk4oZvw6/SdViXR9xQ Fyog== 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=Q6wIbPlk+sj6CdZp+Zuzd40lnLgxHVN50MgCxORNnY8=; b=SgOl55BJH2BYfQYq7053hZgfRrF80at1LSwVm+hL9Ez8/rzgPakZf7r+pyHICuTppS P48cX9j0xInjam0iN4E7Oo3qrjvUmsWkIckiINMaBaw/vu8JKtEiZg8vAXpXuquhckyw KMpeiwiysq+ZSexZJAMCH0Ie0/tWkI8LDT5p6j7Vt2q4h8T6j12FOGijMFF9/uuoj2HM PjNfrN4yYhVTABAgKrg3/S2vTK0B5Wc9INo6qyt0i1er8R1SiyDpJvG1JkPeRecew5fL YluhP8nZ/wl95VVst2ZCQgPDXK1fqhHqGOS3FSao9P8k41ZS2n6D1y07VpicfcEMZ5VR U9Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=jP6jBYuj; 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 g7-20020a1709029f8700b001adbb45eae6si6569987plq.331.2023.05.23.08.16.02; Tue, 23 May 2023 08:16: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=jP6jBYuj; 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 S237020AbjEWPNE (ORCPT + 99 others); Tue, 23 May 2023 11:13:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236190AbjEWPNA (ORCPT ); Tue, 23 May 2023 11:13:00 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D1118E; Tue, 23 May 2023 08:12:49 -0700 (PDT) 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 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_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698491459723365?= X-GMAIL-MSGID: =?utf-8?q?1766698491459723365?= 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: 98040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202343rwl; Tue, 23 May 2023 08:16:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7IbdGa5Zwak93gP7lq445roAjitQq3O4j6lNl5Kj4zMq3pqzo7EVMw5Fa2tGhJTruGy1hJ X-Received: by 2002:a17:90b:3582:b0:255:435e:ceb6 with SMTP id mm2-20020a17090b358200b00255435eceb6mr9502769pjb.17.1684854976815; Tue, 23 May 2023 08:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854976; cv=none; d=google.com; s=arc-20160816; b=OqSos5nZwEOUJNY4ZCQrJjCFHqPNKI65jMohUmUItvSJ/Nwk2+RANRApcOBoipgoTQ dcUi2MBIdvm6mJnJfhjv4zJlTRDzeHWCJy1SkkxasquwvDG9Dm5sEhzHiwVHVzblUb77 4LNUpEuAWW5brubUXFJrL5z/4iN5AxeJhpxtd5742G5Q9Z3cnUY+VuOGD/OzEkHa7y8O A3p80l5ZLeChzs1FCibKrV5KH/moqLMkojEX+qukVbQSLtewYIYVqkanjIzMYM/WlFCk Tjti3GXqd7MbroEz5wTJWAl07PCD64Pz1JfuQgqPBFyuPafpkbMTVmYqsFCb1AlQe8W5 swag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DrMZ95BLnGjcDr2P+qmpgq0WbufG1vHwF/RueaYJS28=; b=IKHVcC5OZld3YDWmRU4Hc7ODxXXrlqyjiRtP5d4hvJTP+cXUi1Fshd+b9vqp6JGpEM SSzjOc/HsO0MT74epu8Fcgfh+Z71GBqda8f3/ac5t2vdt31iff755VVCewIyRhKFADmi XsNWUY0Ceber+BfrJURp2Lfjd9comyc2ZUi4m5Ca65F2dNjxu41gR9NQroXsR01DovlS hDDlxxYcTKjzf38ID63GZpEzmo9YiMQRy1ydmKu7RQI6etNf8vwc82ppYHNpEuEqFJG7 ZsOnEluza8Lm9NOf9Ipl9aIvHoZwDv63N7f51BrcX4k/J33JGFdUXZNOSKrJnsqQaaTI ++9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OJWTwCnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a17090ad50a00b0023d22d0f0fdsi2036672pju.19.2023.05.23.08.16.04; Tue, 23 May 2023 08:16: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=OJWTwCnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237499AbjEWPNP (ORCPT + 99 others); Tue, 23 May 2023 11:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjEWPNE (ORCPT ); Tue, 23 May 2023 11:13:04 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1981B1; Tue, 23 May 2023 08:12:51 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 3D8ECC0008; Tue, 23 May 2023 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DrMZ95BLnGjcDr2P+qmpgq0WbufG1vHwF/RueaYJS28=; b=OJWTwCnlWn+Xthk0Xfek+s2r5juF2h7SNMSfs+CDSVW51lOc8n36dXjfmK4BGPJBYbTAPt 86JjRd4Mcrd49qLXHvDbArKC/E8hki2QuxdslB+MaEZqxwzDROqTu3G8Z0Oz5C6eQX+enW 1FEIgs2cKR0VhE8GLUYxb3DvhzjllrjjdzEjgxzsfnZWENwkRrwuSFZJ1V6owA63QJX4at E+lI4csyxxNOldCH4gEdjII1NaSjAe/tFPmI74ueGDSpFa0nTIg+UIMmKFywgHxEA6Z5du 0P+mF8ZkTdK3AP4vyWzvlgggQVXF+c6HB2D3ptw9OPIUQUqHT2gaJZ7N9lx2tQ== From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 6/9] ASoC: soc-dapm.h: Add a helper to build a DAPM widget dynamically Date: Tue, 23 May 2023 17:12:20 +0200 Message-Id: <20230523151223.109551-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698492057690775?= X-GMAIL-MSGID: =?utf-8?q?1766698492057690775?= 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: 98041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202519rwl; Tue, 23 May 2023 08:16:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4x3fXVkBFC1iZW38eAmO9MLYu74e0CfhDwoDM/MQPGKUfyl4f1Yau1MNTEGhtJIpBzubgN X-Received: by 2002:a05:6a00:2314:b0:63b:5c82:e209 with SMTP id h20-20020a056a00231400b0063b5c82e209mr17363622pfh.10.1684854990334; Tue, 23 May 2023 08:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854990; cv=none; d=google.com; s=arc-20160816; b=dhjvjkrN+BWiHvMNjjxABsiGsoK1F7nL5DWGcqEo7RlnUhgoxPDOzPZ6B4zwuVDgUW jrz+zy3mRyAhp7nB/bLkSKXFQ4jKUTXVk0D7T3X1KYvWo3LPCAPGTr/M0nSrdyvTgMQp GJxxMqxoblRH6qYwM+uxGxH7SE4e3J+ABv23/NHT6nkjGWa+ItiJxg4KTdnG6wAJ1+Jq WQTY0h0siQ6WK72MjnkAtruFq0J0LNlfZt+V+2U8kzz/FSjLN5Lxeu8+IaxQtIIirjbh TgoncpvSKnztT2KHIqrmX6J4SeurJosZV3oPopGA/wgtWyLNDUEDXPrkXlfX41SYpif0 uekQ== 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=KYIlIqVca3vAJgJe+g8vlwK9WmMG6k1vY9NUqUSS7V8=; b=rENGsV1us04dLvR9W8hfLc+YAwKhJQ+UwuBdZ2Q+uod3x/2ayLi+CaXwNQwJcOcPem 2V+z0vxFAMrFN//VlvuAbWZWJbDkr4mOUnPMWZorpQk2eMek2bYGXXameRpSfiBv6DRU T2mjUogeMs029fwBxlfhDbYN5KIltmtJD1YRGE2nC0RWl5aHSE/cauxF2L8530ryT2/O 4uqgsGZZK5cXWfbkylJN1m+pr0FOPBodn/kmb0XZONiKhb3p6Fc4i05rmu9itdJnN0Av Fct3y+iwLh9FbT1XPdbnciDBCdedAlMaeEpb7tmzayi90MWMwvRX58E5oB6UWTRJPc+Z rJUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GbtXbWm2; 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 z189-20020a6333c6000000b005347ee82fb0si6765563pgz.108.2023.05.23.08.16.17; Tue, 23 May 2023 08:16: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=GbtXbWm2; 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 S237421AbjEWPNU (ORCPT + 99 others); Tue, 23 May 2023 11:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237472AbjEWPNH (ORCPT ); Tue, 23 May 2023 11:13:07 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C85A81B5; Tue, 23 May 2023 08:12:53 -0700 (PDT) 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 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_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698506012269274?= X-GMAIL-MSGID: =?utf-8?q?1766698506012269274?= 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: 98042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202530rwl; Tue, 23 May 2023 08:16:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+S/UaWWFK4WHsqedl2n9zd6YPkOWSPGhKOqvY4+FmGUNBFgX6i1NnVjWqKK2EfILme7AX X-Received: by 2002:a05:6a20:938f:b0:105:6d0e:c037 with SMTP id x15-20020a056a20938f00b001056d0ec037mr15080792pzh.38.1684854991277; Tue, 23 May 2023 08:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854991; cv=none; d=google.com; s=arc-20160816; b=ytEHB/chO7OWYghX38cCeJnxsAd8XlVJlA01yRQ/XnGZgO0zMbhlWRmIbsE2+DFxcy /XvoY6xBFQDn5G9qE9CIIyL2+z9dG9BiSFxm7ktvs1Cdy7PaRrr6DWWeSLfyVqsc83d7 psG6YRApn86A29ng/RcN4PlMc/MFR8mYx9YvZ4LT9mun5VpBiAbPjdXOi07y+CrAGosC o03vy0x7GuzNOwwapCGGxyomJ68Aef140PykOGbq4a+PYFuFVNG/UmtCwOE/WJPLOW3m iOLk1XcyuxHks0ku+64yB3+uWz/AYPnl8SRMvfkNJ8LuSmPuQC6E14m72GZ3eSZWX91c wdfw== 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=wyrbVwxZ0KTdJmelqko+tUdutg5HmqXXq7T/rn7OWng=; b=EoHreDIm76LaHPlyQZrCOROCnvck4l9nL615UyuaJcRcxqHgHWjADf/GtfcWEJyJDm eaS0jbF21kGqHc8s5136ea1mf0LlswEkd4dNHpNZBNs3hbI+drY4JrSXQD/qH2UXtyYg skvSCHiaZqDZIcozMYVO4+s9tsgzbC4fs/pzBQQNubhlsYyUsszlIWp0cTs55J34x22E IIHOeUpMeLLF8f2AsyfG2fAJuuM2EFwKru+SNQRCuOfCtGzC02BahxEo9RuqaYkf5/Wd lbypxHeWwKYA95Uk3niiyj+mv1R8yvVNEsbXkf+77CoS7IVYoP0hyb/daF9JmPZMHZnk 8WdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="EBpNWx/8"; 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 s2-20020a632c02000000b005288509b88asi2965385pgs.681.2023.05.23.08.16.18; Tue, 23 May 2023 08:16: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="EBpNWx/8"; 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 S237518AbjEWPNX (ORCPT + 99 others); Tue, 23 May 2023 11:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237477AbjEWPNJ (ORCPT ); Tue, 23 May 2023 11:13:09 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE239E43; Tue, 23 May 2023 08:12:55 -0700 (PDT) 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 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_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698507417175741?= X-GMAIL-MSGID: =?utf-8?q?1766698507417175741?= 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: 98044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202652rwl; Tue, 23 May 2023 08:16:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65eofZeJrrWVnNFiSuXUEwidj1whZXQuTgXqd99k4tC/ZvtTgYumTUJTooeNn+meB0033s X-Received: by 2002:a05:6a00:1486:b0:63f:120a:1dc3 with SMTP id v6-20020a056a00148600b0063f120a1dc3mr21330336pfu.0.1684855001450; Tue, 23 May 2023 08:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684855001; cv=none; d=google.com; s=arc-20160816; b=gXKLKmb/8jeLoQj3CobOUfTvy33viercw9WjUM2UCUkwJ23joY9+Z+laeBfK0/zfVy a4XrBNQytRiNucSmGAXtdtUMbaEZBDN62xcNztQFDPKHWL6wWUITe806MVfesfl5WgOT 6GBCbIjLMK3g76XupTJc4I8G2PwGX3T9sYFTQ8ibA+V1IPsK4O/0bcoj47/Wa9OmG3Dh 6Ayfzqm1ivgJQ+eNaEnZpWh3HqZSjzSJRcYao9ooQHXZXrSUko2tqpjJvS6L3/9BfAgs zAbKuhW0LwY16KqtcJx0+e5Kgb8wJilkVj/RWkMlyKbiREPThE6hcWtLzeHt4uxj8S+H tYnw== 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=rIgj9hYW8BvuR/TDsfHXr8sG/1TWuLwG/JP4/jjJtyQ=; b=QL0g+mnkn0KxS7TI/9J+rM4oBxfxHIcuPFfpCgpYAJt2SA0EgAL+9oeGs7XlR/wbDo d6Xoy6ooReyHmjlbO9u5TXTSh5IL81D5wPDIn3HTUZLHfULdy09OSJoizV3+03Iwzsao fJ9XsXeiOnpDcz8+CGEcLh5D86xs3ed1XXPZJIxaDCEkoorOFPb2Busq4GlYb41U430b FOjvvgh0sAlYRt5lEDSTNbBz+/f7f6bSCuzv7BYfld5UENGPgX1tHOvWx9IUN1lPg70R AS99vTMdEvkji46abibucEFchWwnw83rOaxLBp8n+n1G/m37w6Qactbm8/nQpdMisqix pDoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=IZBvW7uf; 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 bt18-20020a632912000000b0053045e0307esi1638860pgb.451.2023.05.23.08.16.28; Tue, 23 May 2023 08:16:41 -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=IZBvW7uf; 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 S237538AbjEWPN3 (ORCPT + 99 others); Tue, 23 May 2023 11:13:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237492AbjEWPNP (ORCPT ); Tue, 23 May 2023 11:13:15 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 069CDE58; Tue, 23 May 2023 08:12:57 -0700 (PDT) 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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698517689019310?= X-GMAIL-MSGID: =?utf-8?q?1766698517689019310?= 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) {