From patchwork Sat Aug 5 18:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 712001 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 CE517C001DF for ; Tue, 8 Aug 2023 10:38:20 +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 732C984B; Tue, 8 Aug 2023 12:37:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 732C984B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691491098; bh=hYKzJQaX1SCl5vUDcGOW73cK/Vew/NVEeAQk9UvzNVk=; 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=PzkpzEEawwRmEKa+VLEEargx9HywXl0FZnYlvnA5oOlsXxdpEJGizezaERRUb7kCW 1cCXJ4oSE9EQZA1swaiX1N4qxlCvjKq8xTPqDbwFOVagdeaYO+Mk6Ee8VVUcqfPkxY lsWr0tc9YrgPFG+bt7enWxVMUJNCiuqtunOxRNKw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id CEDB9F805B5; Tue, 8 Aug 2023 12:35:43 +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 7AE7CF805B5; Tue, 8 Aug 2023 12:35:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F34FAF80425; Sat, 5 Aug 2023 20:06:45 +0200 (CEST) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6A580F80149 for ; Sat, 5 Aug 2023 20:05:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6A580F80149 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=r3Txk5RV Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fe2bc27029so30779615e9.3 for ; Sat, 05 Aug 2023 11:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691258741; x=1691863541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LYdoFc7rP2Qn0GrAVsnewk5f2j5o1yVoLkw8kbLJjy0=; b=r3Txk5RV5wSnvM9sUhJh/haq7s/rvtUErYBNeUGXZvyxG28S5pVHmusx9El8fjzzOe 8d+FE5hPEyvs6E8G708I/QCAREgKXVfvQssxNDWoYgjFC91e/qQv7JPBnvHddK5GuU/u 3r0ciKiuXdQpfn04ssBtDdwhkOrCPgF94itvMf4pV0ee8NBV7gE82gIDTSvSOCiCghQ7 DI4HZoNJEaQGng6dUKIkv8kUoBRQu/+PB9b4/F6GIOnwnJ5Xk2uTAuT5jpxW0HoCSWc1 RYStqJSmsIqGj464x8bUbin0bxRPm2TY5Cv9GtH1+nQoBAzbe6Y46Fn19RnmSOmP8Cdb pG7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691258741; x=1691863541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LYdoFc7rP2Qn0GrAVsnewk5f2j5o1yVoLkw8kbLJjy0=; b=ip+0iE8gF9tng3fgoF1arPksdff+7fA4GCvz2ei7oXjZq/wOlAfY9iLhC8RvIDc9Ck dhRNgyGgB1A+k4smGc8aH9b80yg7EHni/sFpWhP/F17aFxbwJAXGsVG8Q7/G4gcLbta+ NS0Q/z74OAUB5iGZhcxxfDzTTMfAu0nuwAcg4ZvYdh1gYvV77dOs+mZs2BmPRg54ae3N KkTTRvp00mctqPscZQpQ2DKQa+fp32Noipkd/dav/9Xszqv9vmY+3k7Eg7fvCeSqGW5c Gc2m7cHAl6LSDHaPuc/SymxUyz3V6p3heh+X3N6W3GiMUmOnzBGBIDstBqRMvXSlFc72 eFvw== X-Gm-Message-State: AOJu0YzBWvbdb8aiBPTvRDAfHZhumWpYEy9E6vUCzSJAE0zrlLLLKuZa Q0sPIzcnumW8PwWe995mzwI= X-Google-Smtp-Source: AGHT+IEhVL7vlQWncytTyM/13d+OkFFEwfUKiR3bSl2fOgd9CDDE30po2p9SosJ2ijsdOWBwvqj4ow== X-Received: by 2002:a1c:7205:0:b0:3f5:fff8:d4f3 with SMTP id n5-20020a1c7205000000b003f5fff8d4f3mr3949613wmc.7.1691258741186; Sat, 05 Aug 2023 11:05:41 -0700 (PDT) Received: from user-PC.. ([178.134.198.138]) by smtp.gmail.com with ESMTPSA id v4-20020a5d6104000000b003176aa612b1sm5710402wrt.38.2023.08.05.11.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 11:05:41 -0700 (PDT) From: Maksim Kiselev To: linux-kernel@vger.kernel.org Cc: Maksim Kiselev , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jaroslav Kysela , Takashi Iwai , Maxime Ripard , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org Subject: [PATCH v1 1/5] ASoC: dt-bindings: sun4i-a10-codec: Add binding for Allwinner D1 SoC Date: Sat, 5 Aug 2023 21:05:01 +0300 Message-Id: <20230805180506.718364-2-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230805180506.718364-1-bigunclemax@gmail.com> References: <20230805180506.718364-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-MailFrom: bigunclemax@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: IKIAGWDKAJVYTDZRVHS7FSZBG67WJPID X-Message-ID-Hash: IKIAGWDKAJVYTDZRVHS7FSZBG67WJPID X-Mailman-Approved-At: Tue, 08 Aug 2023 10:35:25 +0000 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 Allwinner D1 SoC has a internal audio codec that similar to previous ones, but it contains a three ADC channels instead of two, and also has a separate clocks for ADC and DAC modules. Signed-off-by: Maksim Kiselev Reviewed-by: Rob Herring --- .../sound/allwinner,sun4i-a10-codec.yaml | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/allwinner,sun4i-a10-codec.yaml b/Documentation/devicetree/bindings/sound/allwinner,sun4i-a10-codec.yaml index 78273647f766..cd9e2ca5783c 100644 --- a/Documentation/devicetree/bindings/sound/allwinner,sun4i-a10-codec.yaml +++ b/Documentation/devicetree/bindings/sound/allwinner,sun4i-a10-codec.yaml @@ -22,6 +22,7 @@ properties: - allwinner,sun8i-a23-codec - allwinner,sun8i-h3-codec - allwinner,sun8i-v3s-codec + - allwinner,sun20i-d1-codec reg: maxItems: 1 @@ -29,15 +30,9 @@ properties: interrupts: maxItems: 1 - clocks: - items: - - description: Bus Clock - - description: Module Clock + clocks: true - clock-names: - items: - - const: apb - - const: codec + clock-names: true dmas: items: @@ -103,6 +98,36 @@ required: allOf: - $ref: dai-common.yaml# + - if: + properties: + compatible: + const: allwinner,sun20i-d1-codec + then: + properties: + clocks: + items: + - description: Bus Clock + - description: ADC Module Clock + - description: DAC Module Clock + + clock-names: + items: + - const: apb + - const: adc + - const: dac + + else: + properties: + clocks: + items: + - description: Bus Clock + - description: Module Clock + + clock-names: + items: + - const: apb + - const: codec + - if: properties: compatible: @@ -111,6 +136,7 @@ allOf: - allwinner,sun8i-a23-codec - allwinner,sun8i-h3-codec - allwinner,sun8i-v3s-codec + - allwinner,sun20i-d1-codec then: if: @@ -229,6 +255,28 @@ allOf: - Mic - Speaker + - if: + properties: + compatible: + enum: + - allwinner,sun20i-d1-codec + + then: + properties: + allwinner,audio-routing: + items: + enum: + - HP + - LINEIN + - MIC3 + - MBIAS + - Headphone + - Headset Mic + - Line In + - Line Out + - Mic + - Speaker + unevaluatedProperties: false examples: From patchwork Sat Aug 5 18:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 712002 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 45F1BC001DF for ; Tue, 8 Aug 2023 10:37:44 +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 8140184D; Tue, 8 Aug 2023 12:36:52 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8140184D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691491062; bh=6HRC0XlQPnRXwRjQgG4MtK5y6OnWUwRDwCc8sYV5Mjc=; 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=TA6jpzvTNnMu2RaV95yjrsZBnj5K9FmMTRmH45ltjmmZiXMbulsNPFk3gPejNwJn/ Y5n9EG2ZQqw7Zl7BXpyA5JzrIkB106aNqLLffmZSPWUJrZBgriWozVdeHR73TKR47V HpvoFe/AhLn0hJllRic0M8wwHuGb51QHgtamrXfA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id DA76FF8059F; Tue, 8 Aug 2023 12:35:36 +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 2640AF8059F; Tue, 8 Aug 2023 12:35:36 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CB588F80425; Sat, 5 Aug 2023 20:05:53 +0200 (CEST) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 56BCAF801D5 for ; Sat, 5 Aug 2023 20:05:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 56BCAF801D5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=JXaio9I8 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fe12820bffso28443445e9.3 for ; Sat, 05 Aug 2023 11:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691258745; x=1691863545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ui9mFi+8YpeTm0k09SoqGWMWxqwLX8g/SM0GMtVVuxo=; b=JXaio9I8DD4b5kA/e3J4i8BugFtaIhTeAsqI8YpbFje4l002vWoSJ8cMKU0hUZuEmx lJAOUXG/CbuqOiK9JDZTQ473fZqnNUUQRQZYrGhXaFfFddAtxYbXuvYdP4MUOkxQVpCG 6k6GEhMUUMZw+XmGLr874mRvlbYTfED9V1LBPWg0EqkDvmmI9ce4MBY+N6pZa1lcQNdU tR4H3XCjWUe/PW7LQiz97Swp4uEEos7FS9Z7u18Zjm1kVlHGpx/tx/NPI5jN2g5bkxQz hbiHrAB7ihoLl3P2ybOtQlJLx4Ha62sof5/RxtfZL1sivlBqdiis7qyRd3rRo0eCwJD4 gekw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691258745; x=1691863545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ui9mFi+8YpeTm0k09SoqGWMWxqwLX8g/SM0GMtVVuxo=; b=P3Rp8MFl1D+gKolJ1euid0CTI4zQ1RXlOHMEa//y/KJI+U9/H4AIJJyhPWji7lqoi4 ye7VgQq9oeoUqIBJD+Fpv74HZFff40asySy1lGSJH/Tq6JyY9aEtbFEvJnz4CvelduTJ bjQTG1ib1yX40sLHQ9TfsehGlZz4tLcvIXgFjwlsfKZ2k554tYGHX9MIVqL/Nz4ws9WG 08/iqz07cHQXAXXFDcTDJWWExyknNKsLHXDE5c9vpIQeyYQb+Q2a1QQEuJnUm6a4K5Ri rknOMG/8B5VyKXo2kUwyo/RVgfy4yND3kJlfsI9Y5s7DzRoKhSqyRjpLZVUqyAso0HJA +2RA== X-Gm-Message-State: AOJu0Yzl5wkOlyZqPdT32OyJ5mi0iDJEh+Bq8S8n8axFw2B0jMnTpF09 hiIDNvgtbDs/zpZ6iMl5Btw= X-Google-Smtp-Source: AGHT+IH52KbShgZ7/MyYYljmA/7meZEjQcL6qqHPDeWo7emmXLPpHbnsfG22wPwvuhUIyNpA/ptA7Q== X-Received: by 2002:a5d:4b43:0:b0:317:5d3d:d37c with SMTP id w3-20020a5d4b43000000b003175d3dd37cmr2878909wrs.24.1691258744489; Sat, 05 Aug 2023 11:05:44 -0700 (PDT) Received: from user-PC.. ([178.134.198.138]) by smtp.gmail.com with ESMTPSA id v4-20020a5d6104000000b003176aa612b1sm5710402wrt.38.2023.08.05.11.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 11:05:44 -0700 (PDT) From: Maksim Kiselev To: linux-kernel@vger.kernel.org Cc: Maksim Kiselev , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jaroslav Kysela , Takashi Iwai , Maxime Ripard , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org Subject: [PATCH v1 2/5] ASoC: dt-bindings: Add schema for "allwinner,sun20i-d1-codec-analog" Date: Sat, 5 Aug 2023 21:05:02 +0300 Message-Id: <20230805180506.718364-3-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230805180506.718364-1-bigunclemax@gmail.com> References: <20230805180506.718364-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-MailFrom: bigunclemax@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: WQYU4MFJWZKHDWHDFDDUPMIDZDKKP4ZZ X-Message-ID-Hash: WQYU4MFJWZKHDWHDFDDUPMIDZDKKP4ZZ X-Mailman-Approved-At: Tue, 08 Aug 2023 10:35:25 +0000 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: Add a DT schema to describe the analog part of the Allwinner D1/T113s internal audio codec. Signed-off-by: Maksim Kiselev --- .../allwinner,sun20i-d1-codec-analog.yaml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/allwinner,sun20i-d1-codec-analog.yaml diff --git a/Documentation/devicetree/bindings/sound/allwinner,sun20i-d1-codec-analog.yaml b/Documentation/devicetree/bindings/sound/allwinner,sun20i-d1-codec-analog.yaml new file mode 100644 index 000000000000..7586076b9bc5 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/allwinner,sun20i-d1-codec-analog.yaml @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/allwinner,sun20i-d1-codec-analog.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner D1 Analog Codec + +maintainers: + - Maksim Kiselev + +properties: + compatible: + const: allwinner,sun20i-d1-codec-analog + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + codec_analog: codec-analog@2030300 { + compatible = "allwinner,sun20i-d1-codec-analog"; + reg = <0x02030300 0xd00>; + }; + +... + From patchwork Sat Aug 5 18:05:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 711622 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 9FBACC001DF for ; Tue, 8 Aug 2023 10:38: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 942E4839; Tue, 8 Aug 2023 12:37:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 942E4839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691491083; bh=CakRtJZLOYtmE1GbuaB0tr63l4mmlCVRiWUunvBtPP4=; 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=L7i8fa1iVa5dkqMXPqBKIlwpsYpVnKcc6oroNx9L8gm9VWLAvgC/qoco8nz69hSw7 Io1i5jz5NUzodDsT3cdmUZ9l0Elao2q1C6B0z9VeHeLjgW/h6/784kW9dJfmGUkQGY pgNBtqqE//TrPjd+7vBbQhxlddOsMJwC8IPzL4AY= Received: by alsa1.perex.cz (Postfix, from userid 50401) id C84C0F805AB; Tue, 8 Aug 2023 12:35:38 +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 14CC8F805AE; Tue, 8 Aug 2023 12:35:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 65DE7F80520; Sat, 5 Aug 2023 20:06:06 +0200 (CEST) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 819B2F8025A for ; Sat, 5 Aug 2023 20:05:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 819B2F8025A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=QON3iw8t Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fe1fc8768aso30918995e9.1 for ; Sat, 05 Aug 2023 11:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691258748; x=1691863548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UAC/Wd+inkjB4rZNJmg2rnNyd7z2tGVBYSRDfN+uDnU=; b=QON3iw8tvEZ8P9uEoQ+A96ZChbhfHc9Z0feSTck+faMU+BX7Qsu0BWekh0p4EKbKkI vDYftM3lwMovNMlCM7bYE+56Xe4Ij8+nVAFFGhsHP2KdQ73twlm/KjITE1OLk+QSMj39 mgwRgIhzR5ybKl6PibQz9ggtGB+SfsAvGz0AAQRPDBjR9FFXWY2XY1qNsf6yfPqP14jP f4XO3dx6HwaS84q4Up/LvwZnpk6M7YtDSgWvwYOGt5BqmQYpNNOKs+Om2YktGX0OeOH5 zIR+JeSu2ck2C/ppkGId2p6nOZrfDN3om8Bn4cOXdp5bc+X1JbAABza/DV9hS/s+Y9Cp FyDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691258748; x=1691863548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UAC/Wd+inkjB4rZNJmg2rnNyd7z2tGVBYSRDfN+uDnU=; b=RCNSX6vEpEfdAQQ4HL5NspIxigQVap2u92WYS+UW1ywJnMqP7RiAEhH2EAwGHbnIDg UOHYQuL2n8yw8SiR8bk2A6jt82LvAGf7B8OCfl3lzpCeMXL4QQVcLflSV1FPIqb55rB4 K1oAxteObDTC5ywcEBGx22b7NrN8ZQECKoOYRq1rAH5oAbVaO8oihiKMgyu/TsQGeoLB 0NzRz9+QD53OJbZt1R6RsSfqja2enOPe5IXYeqNQKcdzeeLcWiJ7ilXOoghQmpwWjmvm c+XnsYz+t1g+BDXqJ1X8PVsiTdCY93cELhfIdu6AExxsHKawKo0jJ0rhiuH5BTue3nIi 8XXg== X-Gm-Message-State: AOJu0YyYIvDFQ/hZ6DQ4rJFTfSZoBRDatsuEgNFLa0jhGXDbr1NxnRbr nwU00tWYszhDkk+hWEQTGBKM8Mnso5/fdw== X-Google-Smtp-Source: AGHT+IHq3qJBx8OwucTasP0y54mcsYMF8ABW5B6yS8muHb6MykWjBz3vRDYpRoFBtQWY1Dzou+tqWA== X-Received: by 2002:a7b:c850:0:b0:3fe:173e:4a34 with SMTP id c16-20020a7bc850000000b003fe173e4a34mr3579314wml.40.1691258748561; Sat, 05 Aug 2023 11:05:48 -0700 (PDT) Received: from user-PC.. ([178.134.198.138]) by smtp.gmail.com with ESMTPSA id v4-20020a5d6104000000b003176aa612b1sm5710402wrt.38.2023.08.05.11.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 11:05:48 -0700 (PDT) From: Maksim Kiselev To: linux-kernel@vger.kernel.org Cc: Maksim Kiselev , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jaroslav Kysela , Takashi Iwai , Maxime Ripard , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org Subject: [PATCH v1 3/5] ASoC: sunxi: sun4i-codec: add basic support for D1 audio codec Date: Sat, 5 Aug 2023 21:05:03 +0300 Message-Id: <20230805180506.718364-4-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230805180506.718364-1-bigunclemax@gmail.com> References: <20230805180506.718364-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-MailFrom: bigunclemax@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: 7VCGRZDXRINSKDYDZLUKW6KCVGOFHLUF X-Message-ID-Hash: 7VCGRZDXRINSKDYDZLUKW6KCVGOFHLUF X-Mailman-Approved-At: Tue, 08 Aug 2023 10:35:25 +0000 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: Allwinner D1 has an audio codec similar to earlier ones, but it comes with 3 channel ADC instead of 2, and many registers are moved. Add basic support for it. Signed-off-by: Maksim Kiselev --- sound/soc/sunxi/sun4i-codec.c | 364 ++++++++++++++++++++++++++++------ 1 file changed, 300 insertions(+), 64 deletions(-) diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c index 55328850aef5..4d4f396da3ee 100644 --- a/sound/soc/sunxi/sun4i-codec.c +++ b/sound/soc/sunxi/sun4i-codec.c @@ -232,15 +232,65 @@ /* TODO H3 DAP (Digital Audio Processing) bits */ +/* + * sun20i D1 and similar codecs specific registers + * + * Almost all registers moved on D1, including ADC digital controls, + * FIFO and RX data registers. Only DAC control are at the same offset. + */ + +#define SUN20I_D1_CODEC_DAC_VOL_CTRL (0x04) +#define SUN20I_D1_CODEC_DAC_VOL_SEL (16) +#define SUN20I_D1_CODEC_DAC_VOL_L (8) +#define SUN20I_D1_CODEC_DAC_VOL_R (0) +#define SUN20I_D1_CODEC_DAC_FIFOC (0x10) +#define SUN20I_D1_CODEC_ADC_FIFOC (0x30) +#define SUN20I_D1_CODEC_ADC_FIFOC_EN_AD (28) +#define SUN20I_D1_CODEC_ADC_FIFOC_RX_SAMPLE_BITS (16) +#define SUN20I_D1_CODEC_ADC_FIFOC_RX_TRIG_LEVEL (4) +#define SUN20I_D1_CODEC_ADC_FIFOC_ADC_DRQ_EN (3) +#define SUN20I_D1_CODEC_ADC_VOL_CTRL1 (0x34) +#define SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC3_VOL (16) +#define SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC2_VOL (8) +#define SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC1_VOL (0) +#define SUN20I_D1_CODEC_ADC_RXDATA (0x40) +#define SUN20I_D1_CODEC_ADC_DIG_CTRL (0x50) +#define SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC3_CH_EN (2) +#define SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC2_CH_EN (1) +#define SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC1_CH_EN (0) +#define SUN20I_D1_CODEC_VRA1SPEEDUP_DOWN_CTRL (0x54) + +/* TODO D1 DAP (Digital Audio Processing) bits */ + +struct sun4i_codec; + +struct sun4i_codec_quirks { + const struct regmap_config *regmap_config; + const struct snd_soc_component_driver *codec; + struct snd_soc_card * (*create_card)(struct device *dev); + struct reg_field reg_dac_fifoc; /* used for regmap_field */ + struct reg_field reg_adc_fifoc; /* used for regmap_field */ + unsigned int adc_drq_en; + unsigned int rx_sample_bits; + unsigned int rx_trig_level; + unsigned int reg_dac_txdata; /* TX FIFO offset for DMA config */ + unsigned int reg_adc_rxdata; /* RX FIFO offset for DMA config */ + bool has_reset; + bool has_dual_clock; +}; + struct sun4i_codec { struct device *dev; struct regmap *regmap; struct clk *clk_apb; - struct clk *clk_module; + struct clk *clk_module; /* used for ADC if clocks are separate */ + struct clk *clk_module_dac; struct reset_control *rst; struct gpio_desc *gpio_pa; + const struct sun4i_codec_quirks *quirks; - /* ADC_FIFOC register is at different offset on different SoCs */ + /* DAC/ADC FIFOC registers are at different offset on different SoCs */ + struct regmap_field *reg_dac_fifoc; struct regmap_field *reg_adc_fifoc; struct snd_dmaengine_dai_dma_data capture_dma_data; @@ -250,33 +300,33 @@ struct sun4i_codec { static void sun4i_codec_start_playback(struct sun4i_codec *scodec) { /* Flush TX FIFO */ - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); + regmap_field_set_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); /* Enable DAC DRQ */ - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN)); + regmap_field_set_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN)); } static void sun4i_codec_stop_playback(struct sun4i_codec *scodec) { /* Disable DAC DRQ */ - regmap_clear_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN)); + regmap_field_clear_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN)); } static void sun4i_codec_start_capture(struct sun4i_codec *scodec) { /* Enable ADC DRQ */ regmap_field_set_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN)); + BIT(scodec->quirks->adc_drq_en)); } static void sun4i_codec_stop_capture(struct sun4i_codec *scodec) { /* Disable ADC DRQ */ regmap_field_clear_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN)); + BIT(scodec->quirks->adc_drq_en)); } static int sun4i_codec_trigger(struct snd_pcm_substream *substream, int cmd, @@ -325,8 +375,8 @@ static int sun4i_codec_prepare_capture(struct snd_pcm_substream *substream, /* Set RX FIFO trigger level */ regmap_field_update_bits(scodec->reg_adc_fifoc, - 0xf << SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, - 0x7 << SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL); + 0xf << scodec->quirks->rx_trig_level, + 0x7 << scodec->quirks->rx_trig_level); /* * FIXME: Undocumented in the datasheet, but @@ -360,13 +410,13 @@ static int sun4i_codec_prepare_playback(struct snd_pcm_substream *substream, u32 val; /* Flush the TX FIFO */ - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); + regmap_field_set_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); /* Set TX FIFO Empty Trigger Level */ - regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - 0x3f << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL, - 0xf << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL); + regmap_field_update_bits(scodec->reg_dac_fifoc, + 0x3f << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL, + 0xf << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL); if (substream->runtime->rate > 32000) /* Use 64 bits FIR filter */ @@ -375,13 +425,12 @@ static int sun4i_codec_prepare_playback(struct snd_pcm_substream *substream, /* Use 32 bits FIR filter */ val = BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION); - regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION), - val); + regmap_field_update_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION), val); /* Send zeros when we have an underrun */ - regmap_clear_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_SEND_LASAT)); + regmap_field_clear_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_SEND_LASAT)); return 0; }; @@ -476,30 +525,32 @@ static int sun4i_codec_hw_params_capture(struct sun4i_codec *scodec, 7 << SUN4I_CODEC_ADC_FIFOC_ADC_FS, hwrate << SUN4I_CODEC_ADC_FIFOC_ADC_FS); - /* Set the number of channels we want to use */ - if (params_channels(params) == 1) - regmap_field_set_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN)); - else - regmap_field_clear_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN)); + if (!scodec->quirks->has_dual_clock) { + /* Set the number of channels we want to use */ + if (params_channels(params) == 1) + regmap_field_set_bits(scodec->reg_adc_fifoc, + BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN)); + else + regmap_field_clear_bits(scodec->reg_adc_fifoc, + BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN)); + } /* Set the number of sample bits to either 16 or 24 bits */ if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) { regmap_field_set_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS)); + BIT(scodec->quirks->rx_sample_bits)); regmap_field_clear_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE)); + BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE)); scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; } else { regmap_field_clear_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS)); + BIT(scodec->quirks->rx_sample_bits)); /* Fill most significant bits with valid data MSB */ regmap_field_set_bits(scodec->reg_adc_fifoc, - BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE)); + BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE)); scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; } @@ -514,9 +565,9 @@ static int sun4i_codec_hw_params_playback(struct sun4i_codec *scodec, u32 val; /* Set DAC sample rate */ - regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - 7 << SUN4I_CODEC_DAC_FIFOC_DAC_FS, - hwrate << SUN4I_CODEC_DAC_FIFOC_DAC_FS); + regmap_field_update_bits(scodec->reg_dac_fifoc, + 7 << SUN4I_CODEC_DAC_FIFOC_DAC_FS, + hwrate << SUN4I_CODEC_DAC_FIFOC_DAC_FS); /* Set the number of channels we want to use */ if (params_channels(params) == 1) @@ -524,27 +575,26 @@ static int sun4i_codec_hw_params_playback(struct sun4i_codec *scodec, else val = 0; - regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN), - val); + regmap_field_update_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN), val); /* Set the number of sample bits to either 16 or 24 bits */ if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) { - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS)); + regmap_field_set_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS)); /* Set TX FIFO mode to padding the LSBs with 0 */ - regmap_clear_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE)); + regmap_field_clear_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE)); scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; } else { - regmap_clear_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS)); + regmap_field_clear_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS)); /* Set TX FIFO mode to repeat the MSB */ - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE)); + regmap_field_set_bits(scodec->reg_dac_fifoc, + BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE)); scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; } @@ -565,7 +615,11 @@ static int sun4i_codec_hw_params(struct snd_pcm_substream *substream, if (!clk_freq) return -EINVAL; - ret = clk_set_rate(scodec->clk_module, clk_freq); + if (scodec->clk_module_dac && + substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + ret = clk_set_rate(scodec->clk_module_dac, clk_freq); + else + ret = clk_set_rate(scodec->clk_module, clk_freq); if (ret) return ret; @@ -607,10 +661,14 @@ static int sun4i_codec_startup(struct snd_pcm_substream *substream, * Stop issuing DRQ when we have room for less than 16 samples * in our TX FIFO */ - regmap_set_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, - 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT); + regmap_field_set_bits(scodec->reg_dac_fifoc, + 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT); - return clk_prepare_enable(scodec->clk_module); + if (scodec->clk_module_dac && + substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + return clk_prepare_enable(scodec->clk_module_dac); + else + return clk_prepare_enable(scodec->clk_module); } static void sun4i_codec_shutdown(struct snd_pcm_substream *substream, @@ -619,7 +677,11 @@ static void sun4i_codec_shutdown(struct snd_pcm_substream *substream, struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); - clk_disable_unprepare(scodec->clk_module); + if (scodec->clk_module_dac && + substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + clk_disable_unprepare(scodec->clk_module_dac); + else + clk_disable_unprepare(scodec->clk_module); } static const struct snd_soc_dai_ops sun4i_codec_dai_ops = { @@ -1229,6 +1291,55 @@ static const struct snd_soc_component_driver sun8i_a23_codec_codec = { .endianness = 1, }; +/* sun20i D1 codec */ +static const DECLARE_TLV_DB_SCALE(sun20i_d1_codec_dvol_scale, -12000, 75, 1); + +static const struct snd_kcontrol_new sun20i_d1_codec_codec_controls[] = { + SOC_SINGLE_TLV("DAC Playback Volume", SUN4I_CODEC_DAC_DPC, + SUN4I_CODEC_DAC_DPC_DVOL, 0x3f, 1, + sun6i_codec_dvol_scale), + SOC_DOUBLE_TLV("DAC Front Playback Volume", SUN20I_D1_CODEC_DAC_VOL_CTRL, + SUN20I_D1_CODEC_DAC_VOL_L, SUN20I_D1_CODEC_DAC_VOL_R, + 0xFF, 0, sun20i_d1_codec_dvol_scale), + + SOC_SINGLE_TLV("ADC1 Capture Volume", SUN20I_D1_CODEC_ADC_VOL_CTRL1, + SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC1_VOL, 0xff, 0, + sun20i_d1_codec_dvol_scale), + SOC_SINGLE_TLV("ADC2 Capture Volume", SUN20I_D1_CODEC_ADC_VOL_CTRL1, + SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC2_VOL, 0xff, 0, + sun20i_d1_codec_dvol_scale), + SOC_SINGLE_TLV("ADC3 Capture Volume", SUN20I_D1_CODEC_ADC_VOL_CTRL1, + SUN20I_D1_CODEC_ADC_VOL_CTRL1_ADC3_VOL, 0xff, 0, + sun20i_d1_codec_dvol_scale), +}; + +static const struct snd_soc_dapm_widget sun20i_d1_codec_codec_widgets[] = { + /* Digital parts of the ADCs */ + SND_SOC_DAPM_SUPPLY("ADC Enable", SUN20I_D1_CODEC_ADC_FIFOC, + SUN20I_D1_CODEC_ADC_FIFOC_EN_AD, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY("ADC1 CH Enable", SUN20I_D1_CODEC_ADC_DIG_CTRL, + SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC1_CH_EN, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY("ADC2 CH Enable", SUN20I_D1_CODEC_ADC_DIG_CTRL, + SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC2_CH_EN, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY("ADC3 CH Enable", SUN20I_D1_CODEC_ADC_DIG_CTRL, + SUN20I_D1_CODEC_ADC_DIG_CTRL_ADC3_CH_EN, 0, NULL, 0), + /* Digital parts of the DACs */ + SND_SOC_DAPM_SUPPLY("DAC Enable", SUN4I_CODEC_DAC_DPC, + SUN4I_CODEC_DAC_DPC_EN_DA, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY("DAC VOL_SEL Enable", SUN20I_D1_CODEC_DAC_VOL_CTRL, + SUN20I_D1_CODEC_DAC_VOL_SEL, 0, NULL, 0), +}; + +static const struct snd_soc_component_driver sun20i_d1_codec_codec = { + .controls = sun20i_d1_codec_codec_controls, + .num_controls = ARRAY_SIZE(sun20i_d1_codec_codec_controls), + .dapm_widgets = sun20i_d1_codec_codec_widgets, + .num_dapm_widgets = ARRAY_SIZE(sun20i_d1_codec_codec_widgets), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, +}; + static const struct snd_soc_component_driver sun4i_codec_component = { .name = "sun4i-codec", .legacy_dai_naming = 1, @@ -1528,6 +1639,66 @@ static struct snd_soc_card *sun8i_v3s_codec_create_card(struct device *dev) return card; }; +static const struct snd_soc_dapm_route sun20i_d1_codec_card_routes[] = { + /* ADC Routes */ + { "ADC1", NULL, "ADC Enable" }, + { "ADC2", NULL, "ADC Enable" }, + { "ADC3", NULL, "ADC Enable" }, + { "ADC1", NULL, "ADC1 CH Enable" }, + { "ADC2", NULL, "ADC2 CH Enable" }, + { "ADC3", NULL, "ADC3 CH Enable" }, + { "Codec Capture", NULL, "ADC1" }, + { "Codec Capture", NULL, "ADC2" }, + { "Codec Capture", NULL, "ADC3" }, + + /* DAC Routes */ + { "Left DAC", NULL, "DAC Enable" }, + { "Right DAC", NULL, "DAC Enable" }, + { "Left DAC", NULL, "DAC VOL_SEL Enable" }, + { "Right DAC", NULL, "DAC VOL_SEL Enable" }, + { "Left DAC", NULL, "Codec Playback" }, + { "Right DAC", NULL, "Codec Playback" }, +}; + +static struct snd_soc_card *sun20i_d1_codec_create_card(struct device *dev) +{ + struct snd_soc_card *card; + int ret; + + card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + if (!card) + return ERR_PTR(-ENOMEM); + + aux_dev.dlc.of_node = of_parse_phandle(dev->of_node, + "allwinner,codec-analog-controls", + 0); + if (!aux_dev.dlc.of_node) { + dev_err(dev, "Can't find analog controls for codec.\n"); + return ERR_PTR(-EINVAL); + } + + card->dai_link = sun4i_codec_create_link(dev, &card->num_links); + if (!card->dai_link) + return ERR_PTR(-ENOMEM); + + card->dev = dev; + card->owner = THIS_MODULE; + card->name = "D1 Audio Codec"; + card->dapm_widgets = sun6i_codec_card_dapm_widgets; + card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets); + card->dapm_routes = sun20i_d1_codec_card_routes; + card->num_dapm_routes = ARRAY_SIZE(sun20i_d1_codec_card_routes); + card->aux_dev = &aux_dev; + card->num_aux_devs = 1; + card->fully_routed = true; + + ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing"); + if (ret) + dev_warn(dev, "failed to parse audio-routing: %d\n", ret); + + return card; +}; + static const struct regmap_config sun4i_codec_regmap_config = { .reg_bits = 32, .reg_stride = 4, @@ -1570,21 +1741,22 @@ static const struct regmap_config sun8i_v3s_codec_regmap_config = { .max_register = SUN8I_H3_CODEC_ADC_DBG, }; -struct sun4i_codec_quirks { - const struct regmap_config *regmap_config; - const struct snd_soc_component_driver *codec; - struct snd_soc_card * (*create_card)(struct device *dev); - struct reg_field reg_adc_fifoc; /* used for regmap_field */ - unsigned int reg_dac_txdata; /* TX FIFO offset for DMA config */ - unsigned int reg_adc_rxdata; /* RX FIFO offset for DMA config */ - bool has_reset; +static const struct regmap_config sun20i_d1_codec_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = SUN20I_D1_CODEC_VRA1SPEEDUP_DOWN_CTRL, }; static const struct sun4i_codec_quirks sun4i_codec_quirks = { .regmap_config = &sun4i_codec_regmap_config, .codec = &sun4i_codec_codec, .create_card = sun4i_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN4I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN4I_CODEC_ADC_RXDATA, }; @@ -1593,7 +1765,11 @@ static const struct sun4i_codec_quirks sun6i_a31_codec_quirks = { .regmap_config = &sun6i_codec_regmap_config, .codec = &sun6i_codec_codec, .create_card = sun6i_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA, .has_reset = true, @@ -1603,7 +1779,11 @@ static const struct sun4i_codec_quirks sun7i_codec_quirks = { .regmap_config = &sun7i_codec_regmap_config, .codec = &sun7i_codec_codec, .create_card = sun4i_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN4I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN4I_CODEC_ADC_RXDATA, }; @@ -1612,7 +1792,11 @@ static const struct sun4i_codec_quirks sun8i_a23_codec_quirks = { .regmap_config = &sun8i_a23_codec_regmap_config, .codec = &sun8i_a23_codec_codec, .create_card = sun8i_a23_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA, .has_reset = true, @@ -1627,7 +1811,11 @@ static const struct sun4i_codec_quirks sun8i_h3_codec_quirks = { */ .codec = &sun8i_a23_codec_codec, .create_card = sun8i_h3_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA, .has_reset = true, @@ -1641,12 +1829,31 @@ static const struct sun4i_codec_quirks sun8i_v3s_codec_quirks = { */ .codec = &sun8i_a23_codec_codec, .create_card = sun8i_v3s_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN4I_CODEC_DAC_FIFOC, 0, 31), .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA, .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA, .has_reset = true, }; +static const struct sun4i_codec_quirks sun20i_d1_codec_quirks = { + .regmap_config = &sun20i_d1_codec_regmap_config, + .codec = &sun20i_d1_codec_codec, + .create_card = sun20i_d1_codec_create_card, + .reg_dac_fifoc = REG_FIELD(SUN20I_D1_CODEC_DAC_FIFOC, 0, 31), + .reg_adc_fifoc = REG_FIELD(SUN20I_D1_CODEC_ADC_FIFOC, 0, 31), + .adc_drq_en = SUN20I_D1_CODEC_ADC_FIFOC_ADC_DRQ_EN, + .rx_sample_bits = SUN20I_D1_CODEC_ADC_FIFOC_RX_SAMPLE_BITS, + .rx_trig_level = SUN20I_D1_CODEC_ADC_FIFOC_RX_TRIG_LEVEL, + .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA, + .reg_adc_rxdata = SUN20I_D1_CODEC_ADC_RXDATA, + .has_reset = true, + .has_dual_clock = true, +}; + static const struct of_device_id sun4i_codec_of_match[] = { { .compatible = "allwinner,sun4i-a10-codec", @@ -1672,6 +1879,10 @@ static const struct of_device_id sun4i_codec_of_match[] = { .compatible = "allwinner,sun8i-v3s-codec", .data = &sun8i_v3s_codec_quirks, }, + { + .compatible = "allwinner,sun20i-d1-codec", + .data = &sun20i_d1_codec_quirks, + }, {} }; MODULE_DEVICE_TABLE(of, sun4i_codec_of_match); @@ -1700,6 +1911,7 @@ static int sun4i_codec_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to determine the quirks to use\n"); return -ENODEV; } + scodec->quirks = quirks; scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base, quirks->regmap_config); @@ -1715,10 +1927,24 @@ static int sun4i_codec_probe(struct platform_device *pdev) return PTR_ERR(scodec->clk_apb); } - scodec->clk_module = devm_clk_get(&pdev->dev, "codec"); - if (IS_ERR(scodec->clk_module)) { - dev_err(&pdev->dev, "Failed to get the module clock\n"); - return PTR_ERR(scodec->clk_module); + if (quirks->has_dual_clock) { + scodec->clk_module = devm_clk_get(&pdev->dev, "adc"); + if (IS_ERR(scodec->clk_module)) { + dev_err(&pdev->dev, "Failed to get the ADC module clock\n"); + return PTR_ERR(scodec->clk_module); + } + + scodec->clk_module_dac = devm_clk_get(&pdev->dev, "dac"); + if (IS_ERR(scodec->clk_module_dac)) { + dev_err(&pdev->dev, "Failed to get the DAC module clock\n"); + return PTR_ERR(scodec->clk_module_dac); + } + } else { + scodec->clk_module = devm_clk_get(&pdev->dev, "codec"); + if (IS_ERR(scodec->clk_module)) { + dev_err(&pdev->dev, "Failed to get the module clock\n"); + return PTR_ERR(scodec->clk_module); + } } if (quirks->has_reset) { @@ -1749,6 +1975,16 @@ static int sun4i_codec_probe(struct platform_device *pdev) return ret; } + scodec->reg_dac_fifoc = devm_regmap_field_alloc(&pdev->dev, + scodec->regmap, + quirks->reg_dac_fifoc); + if (IS_ERR(scodec->reg_dac_fifoc)) { + ret = PTR_ERR(scodec->reg_dac_fifoc); + dev_err(&pdev->dev, "Failed to create regmap fields: %d\n", + ret); + return ret; + } + /* Enable the bus clock */ if (clk_prepare_enable(scodec->clk_apb)) { dev_err(&pdev->dev, "Failed to enable the APB clock\n"); From patchwork Sat Aug 5 18:05:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 711621 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 141D5C001DF for ; Tue, 8 Aug 2023 10:38:35 +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 36E4ADED; Tue, 8 Aug 2023 12:37:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 36E4ADED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691491113; bh=4O+AovqzHu/xgZKN2NEl0Tr/pgKFUcDa4hdbNa72GKE=; 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=uPizsDxCc+qVawCdWjwPOuMqUdUqBtaMZW+4B9jrSM6MORfaaGParpbkkcyfh1CZh KbD+4sjqk+FgNf+D7sMq8NrsRw9Ei8TGaVMWoVs9XWvy6TK97MFs3SxLGDM8BHzP+6 P9pdZAfkI8T6va87kTEvldtaz1ldJxrCqrGoIF3w= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 99E27F805D3; Tue, 8 Aug 2023 12:35:46 +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 06815F805D2; Tue, 8 Aug 2023 12:35:46 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1988AF8025A; Sat, 5 Aug 2023 20:06:59 +0200 (CEST) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 2012CF802BE for ; Sat, 5 Aug 2023 20:05:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2012CF802BE Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=VLxBlaI8 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-313e742a787so1846538f8f.1 for ; Sat, 05 Aug 2023 11:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691258753; x=1691863553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ho00aTSR6Nd9ZGhlL2/Ex6KOk4DJ3h9NtPcio400hoM=; b=VLxBlaI8OMxLcTfutZ+0EfaTTw8wCx3/tYk1MbmhoMTyKb5KLY63SI+rpGmulbi4/P 9Mp5rFEGSyq8vigwARVKAhhKJ8QEouwEbCKn5EJidI0mzGQLqwmwhenQ57d9Gb5hsUIY 3l+rcXOp1ne9gbzHU9GqbvzIX1hju1hW7RA9LNHHxJIQ0TptHx+JbEtVWRAJw54wSXS+ BIaXdz76P4K1zLflOleE/QEM/G9TUIx2gPledE5R0YqB9CPzso1egFaFVZ/H6VAmAWxh NNPRqowJH5nE8RK1eZtfwwnEF8b1kLGmT31vmbzRQwIFvQWLpWdtUeKs+5iCED5p75x9 b8zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691258753; x=1691863553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ho00aTSR6Nd9ZGhlL2/Ex6KOk4DJ3h9NtPcio400hoM=; b=MLKW6i1V8NZpPOAyqF7UccaFHf3hybj6h+kMnBzqRBsMSZ22NVwYMiNB7K8sUK+x8Y fGiJBCJwUR0P4xz0H5yx/vHD+AXENFXW8x0zGbw6DWyr+0KEIuqT+4o101uneu0LPRPf 869X84N6ZNUEQXZO5OJMOFWck4+HJc0YXmK1oRdgi6lPXMmsGiejDYsmfmenXhJzHLgg EPHdX0dn2uLF/RHslvkfAdxavfdSF/qe1tyREfRGHirm4VgTJp59p8OoJHvxZT8sFe5U jZB69U7d/epHNSlwXu3ztswMSXkDnFZGBOJc0pstiX4nAgR03TyN9J4Q8oEacWqcS1pc Uusw== X-Gm-Message-State: AOJu0YwBxAUDBulEGNIOSt9ZlFIYMdDxraWi8WTX8VN+lz0IiWrHQN5m rDglvINuMgjheEunSShazSI= X-Google-Smtp-Source: AGHT+IH9HhmtHMoM4vrXGnrK2R/jHU6vhHKZeu67GsZoQ2e8dcjlsXq+5hVc3u2LGqYnCflZERbX7w== X-Received: by 2002:a5d:6ac5:0:b0:317:6570:afec with SMTP id u5-20020a5d6ac5000000b003176570afecmr2366516wrw.3.1691258753198; Sat, 05 Aug 2023 11:05:53 -0700 (PDT) Received: from user-PC.. ([178.134.198.138]) by smtp.gmail.com with ESMTPSA id v4-20020a5d6104000000b003176aa612b1sm5710402wrt.38.2023.08.05.11.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 11:05:53 -0700 (PDT) From: Maksim Kiselev To: linux-kernel@vger.kernel.org Cc: Maksim Kiselev , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jaroslav Kysela , Takashi Iwai , Maxime Ripard , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org Subject: [PATCH v1 4/5] ASoC: sunxi: Add new driver for Allwinner D1/T113s codec's analog path controls Date: Sat, 5 Aug 2023 21:05:04 +0300 Message-Id: <20230805180506.718364-5-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230805180506.718364-1-bigunclemax@gmail.com> References: <20230805180506.718364-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-MailFrom: bigunclemax@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: FY7XQYECPTXZZYLHE43L25NHD6HCECXJ X-Message-ID-Hash: FY7XQYECPTXZZYLHE43L25NHD6HCECXJ X-Mailman-Approved-At: Tue, 08 Aug 2023 10:35:25 +0000 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 internal codec on D1/T113s is split into 2 parts like the previous ones. But now analog path controls registers are mapped directly on the bus, right after the registers of the digital part. Add an ASoC component driver for it. This should be tied to the codec audio card as an auxiliary device. Signed-off-by: Maksim Kiselev --- sound/soc/sunxi/Kconfig | 11 ++ sound/soc/sunxi/Makefile | 1 + sound/soc/sunxi/sun20i-d1-codec-analog.c | 220 +++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 sound/soc/sunxi/sun20i-d1-codec-analog.c diff --git a/sound/soc/sunxi/Kconfig b/sound/soc/sunxi/Kconfig index 1f18f016acbb..c67895d08079 100644 --- a/sound/soc/sunxi/Kconfig +++ b/sound/soc/sunxi/Kconfig @@ -38,6 +38,17 @@ config SND_SUN50I_CODEC_ANALOG Say Y or M if you want to add support for the analog controls for the codec embedded in Allwinner A64 SoC. +config SND_SUN20I_D1_CODEC_ANALOG + tristate "Allwinner D1 Codec Analog Controls Support" + depends on ARCH_SUNXI || COMPILE_TEST + select REGMAP_MMIO + help + This option enables the analog controls part of the internal audio + codec for Allwinner D1/T113s SoCs family. + + Say Y or M if you want to add support for the analog part of + the D1/T113s audio codec. + config SND_SUN4I_I2S tristate "Allwinner A10 I2S Support" select SND_SOC_GENERIC_DMAENGINE_PCM diff --git a/sound/soc/sunxi/Makefile b/sound/soc/sunxi/Makefile index 4483fe9c94ef..ba6a5ed334a0 100644 --- a/sound/soc/sunxi/Makefile +++ b/sound/soc/sunxi/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_SND_SUN4I_I2S) += sun4i-i2s.o obj-$(CONFIG_SND_SUN4I_SPDIF) += sun4i-spdif.o obj-$(CONFIG_SND_SUN8I_CODEC_ANALOG) += sun8i-codec-analog.o obj-$(CONFIG_SND_SUN50I_CODEC_ANALOG) += sun50i-codec-analog.o +obj-$(CONFIG_SND_SUN20I_D1_CODEC_ANALOG) += sun20i-d1-codec-analog.o obj-$(CONFIG_SND_SUN8I_CODEC) += sun8i-codec.o obj-$(CONFIG_SND_SUN8I_ADDA_PR_REGMAP) += sun8i-adda-pr-regmap.o obj-$(CONFIG_SND_SUN50I_DMIC) += sun50i-dmic.o diff --git a/sound/soc/sunxi/sun20i-d1-codec-analog.c b/sound/soc/sunxi/sun20i-d1-codec-analog.c new file mode 100644 index 000000000000..5c269d56cd2f --- /dev/null +++ b/sound/soc/sunxi/sun20i-d1-codec-analog.c @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * This driver supports the analog controls for the internal codec + * found in Allwinner's D1/T113s SoCs family. + * + * Based on sun50i-codec-analog.c + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* Codec analog control register offsets and bit fields */ +#define SUN20I_D1_ADDA_ADC1 (0x00) +#define SUN20I_D1_ADDA_ADC2 (0x04) +#define SUN20I_D1_ADDA_ADC3 (0x08) +#define SUN20I_D1_ADDA_ADC_EN (31) +#define SUN20I_D1_ADDA_ADC_PGA_EN (30) +#define SUN20I_D1_ADDA_ADC_MIC_SIN_EN (28) +#define SUN20I_D1_ADDA_ADC_LINEINLEN (23) +#define SUN20I_D1_ADDA_ADC_PGA_GAIN (8) + +#define SUN20I_D1_ADDA_DAC (0x10) +#define SUN20I_D1_ADDA_DAC_DACL_EN (15) +#define SUN20I_D1_ADDA_DAC_DACR_EN (14) + +#define SUN20I_D1_ADDA_MICBIAS (0x18) +#define SUN20I_D1_ADDA_MICBIAS_MMICBIASEN (7) + +#define SUN20I_D1_ADDA_RAMP (0x1C) +#define SUN20I_D1_ADDA_RAMP_RD_EN (0) + +#define SUN20I_D1_ADDA_HP2 (0x40) +#define SUN20I_D1_ADDA_HP2_HEADPHONE_GAIN (28) + +#define SUN20I_D1_ADDA_ADC_CUR_REG (0x4C) + +static const DECLARE_TLV_DB_RANGE(sun20i_d1_codec_adc_gain_scale, + 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), + 1, 3, TLV_DB_SCALE_ITEM(600, 0, 0), + 4, 4, TLV_DB_SCALE_ITEM(900, 0, 0), + 5, 31, TLV_DB_SCALE_ITEM(1000, 100, 0), +); + +static const DECLARE_TLV_DB_SCALE(sun20i_d1_codec_hp_vol_scale, -4200, 600, 0); + +/* volume controls */ +static const struct snd_kcontrol_new sun20i_d1_codec_controls[] = { + SOC_SINGLE_TLV("Headphone Playback Volume", + SUN20I_D1_ADDA_HP2, + SUN20I_D1_ADDA_HP2_HEADPHONE_GAIN, 0x7, 1, + sun20i_d1_codec_hp_vol_scale), + SOC_SINGLE_TLV("ADC1 Gain Capture Volume", + SUN20I_D1_ADDA_ADC1, + SUN20I_D1_ADDA_ADC_PGA_GAIN, 0x1f, 0, + sun20i_d1_codec_adc_gain_scale), + SOC_SINGLE_TLV("ADC2 Gain Capture Volume", + SUN20I_D1_ADDA_ADC2, + SUN20I_D1_ADDA_ADC_PGA_GAIN, 0x1f, 0, + sun20i_d1_codec_adc_gain_scale), + SOC_SINGLE_TLV("ADC3 Gain Capture Volume", + SUN20I_D1_ADDA_ADC3, + SUN20I_D1_ADDA_ADC_PGA_GAIN, 0x1f, 0, + sun20i_d1_codec_adc_gain_scale), +}; + +/* ADC mixer controls */ +static const struct snd_kcontrol_new sun20i_d1_codec_mixer_controls[] = { + SOC_DAPM_DOUBLE_R("Line In Switch", + SUN20I_D1_ADDA_ADC1, + SUN20I_D1_ADDA_ADC2, + SUN20I_D1_ADDA_ADC_LINEINLEN, 1, 0), +}; + +static const char * const sun20i_d1_codec_mic3_src_enum_text[] = { + "Differential", "Single", +}; + +static SOC_ENUM_SINGLE_DECL(sun20i_d1_codec_mic3_src_enum, + SUN20I_D1_ADDA_ADC3, + SUN20I_D1_ADDA_ADC_MIC_SIN_EN, + sun20i_d1_codec_mic3_src_enum_text); + +static const struct snd_kcontrol_new sun20i_d1_codec_mic3_input_src[] = { + SOC_DAPM_ENUM("MIC3 Source Capture Route", + sun20i_d1_codec_mic3_src_enum), +}; + +static const struct snd_soc_dapm_widget sun20i_d1_codec_widgets[] = { + /* DAC */ + SND_SOC_DAPM_DAC("Left DAC", NULL, SUN20I_D1_ADDA_DAC, + SUN20I_D1_ADDA_DAC_DACL_EN, 0), + SND_SOC_DAPM_DAC("Right DAC", NULL, SUN20I_D1_ADDA_DAC, + SUN20I_D1_ADDA_DAC_DACR_EN, 0), + /* ADC */ + SND_SOC_DAPM_ADC("ADC1", NULL, SUN20I_D1_ADDA_ADC1, + SUN20I_D1_ADDA_ADC_EN, 0), + SND_SOC_DAPM_ADC("ADC2", NULL, SUN20I_D1_ADDA_ADC2, + SUN20I_D1_ADDA_ADC_EN, 0), + SND_SOC_DAPM_ADC("ADC3", NULL, SUN20I_D1_ADDA_ADC3, + SUN20I_D1_ADDA_ADC_EN, 0), + + /* ADC Mixers */ + SND_SOC_DAPM_MIXER("ADC1 Mixer", SND_SOC_NOPM, 0, 0, + sun20i_d1_codec_mixer_controls, + ARRAY_SIZE(sun20i_d1_codec_mixer_controls)), + SND_SOC_DAPM_MIXER("ADC2 Mixer", SND_SOC_NOPM, 0, 0, + sun20i_d1_codec_mixer_controls, + ARRAY_SIZE(sun20i_d1_codec_mixer_controls)), + + /* Headphone */ + SND_SOC_DAPM_OUTPUT("HP"), + SND_SOC_DAPM_SUPPLY("RAMP Enable", SUN20I_D1_ADDA_RAMP, + SUN20I_D1_ADDA_RAMP_RD_EN, 0, NULL, 0), + + /* Line input */ + SND_SOC_DAPM_INPUT("LINEIN"), + + /* Microphone input */ + SND_SOC_DAPM_INPUT("MIC3"), + + /* Microphone input path */ + SND_SOC_DAPM_MUX("MIC3 Source Capture Route", SND_SOC_NOPM, 0, 0, + sun20i_d1_codec_mic3_input_src), + + SND_SOC_DAPM_PGA("Mic3 Amplifier", SUN20I_D1_ADDA_ADC3, + SUN20I_D1_ADDA_ADC_PGA_EN, 0, NULL, 0), + + /* Microphone Bias */ + SND_SOC_DAPM_SUPPLY("MBIAS", SUN20I_D1_ADDA_MICBIAS, + SUN20I_D1_ADDA_MICBIAS_MMICBIASEN, 0, NULL, 0), +}; + +static const struct snd_soc_dapm_route sun20i_d1_codec_routes[] = { + /* Headphone Routes */ + { "HP", NULL, "Left DAC" }, + { "HP", NULL, "Right DAC" }, + { "HP", NULL, "RAMP Enable" }, + + /* Line input Routes */ + { "ADC1", NULL, "ADC1 Mixer" }, + { "ADC2", NULL, "ADC2 Mixer" }, + { "ADC1 Mixer", "Line In Switch", "LINEIN" }, + { "ADC2 Mixer", "Line In Switch", "LINEIN" }, + + /* Microphone Routes */ + { "MIC3 Source Capture Route", "Differential", "MIC3" }, + { "MIC3 Source Capture Route", "Single", "MIC3" }, + { "Mic3 Amplifier", NULL, "MIC3 Source Capture Route" }, + { "ADC3", NULL, "Mic3 Amplifier" }, +}; + +static const struct snd_soc_component_driver sun20i_d1_codec_analog_cmpnt_drv = { + .controls = sun20i_d1_codec_controls, + .num_controls = ARRAY_SIZE(sun20i_d1_codec_controls), + .dapm_widgets = sun20i_d1_codec_widgets, + .num_dapm_widgets = ARRAY_SIZE(sun20i_d1_codec_widgets), + .dapm_routes = sun20i_d1_codec_routes, + .num_dapm_routes = ARRAY_SIZE(sun20i_d1_codec_routes), +}; + +static const struct of_device_id sun20i_d1_codec_analog_of_match[] = { + { + .compatible = "allwinner,sun20i-d1-codec-analog", + }, + {} +}; +MODULE_DEVICE_TABLE(of, sun20i_d1_codec_analog_of_match); + +static const struct regmap_config sun20i_d1_codec_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = SUN20I_D1_ADDA_ADC_CUR_REG, +}; + +static int sun20i_d1_codec_analog_probe(struct platform_device *pdev) +{ + struct regmap *regmap; + void __iomem *base; + + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) { + dev_err(&pdev->dev, "Failed to map the registers\n"); + return PTR_ERR(base); + } + + regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun20i_d1_codec_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&pdev->dev, "Failed to create regmap\n"); + return PTR_ERR(regmap); + } + + return devm_snd_soc_register_component(&pdev->dev, + &sun20i_d1_codec_analog_cmpnt_drv, + NULL, 0); +} + +static struct platform_driver sun20i_d1_codec_analog_driver = { + .driver = { + .name = "sun20i-d1-codec-analog", + .of_match_table = sun20i_d1_codec_analog_of_match, + }, + .probe = sun20i_d1_codec_analog_probe, +}; +module_platform_driver(sun20i_d1_codec_analog_driver); + +MODULE_DESCRIPTION("Allwinner internal codec analog controls driver for D1"); +MODULE_AUTHOR("Maksim Kiselev "); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:sun20i-d1-codec-analog"); From patchwork Sat Aug 5 18:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 712000 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 0D9C9C001DF for ; Tue, 8 Aug 2023 10:38:57 +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 3131E847; Tue, 8 Aug 2023 12:38:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3131E847 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691491135; bh=pAXgC7Nll/1yEWipy/eZZlMIyyKvenDBBKMACXoT6hY=; 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=Q1PxfHXOmCsnC5pt2vaFW3F+WiUNrmNkHFcZOUQrRrbZzBdLUoBhKDj63p+WEt92s lNlbeF4fFcCB2yw/0SOkAw8r358BRQ4UehCsATtjp5Y3G+FixT0ALftTdQmjydMaX0 vQSI09c+Edd5vs08GCDwtk0NQUcvRufyCfQEsVBE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9EF0BF805DF; Tue, 8 Aug 2023 12:35: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 DD844F805D8; Tue, 8 Aug 2023 12:35:48 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4CD58F8025A; Sat, 5 Aug 2023 20:07:00 +0200 (CEST) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C39F6F801D5 for ; Sat, 5 Aug 2023 20:05:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C39F6F801D5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=qYKcS/LR Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31765792c7cso2770102f8f.0 for ; Sat, 05 Aug 2023 11:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691258757; x=1691863557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jjaA2yNdWRxoAIXKsMRIdPQiU+5JdGf4g+hfiGSEvXE=; b=qYKcS/LRkaOGXq4NdDRZzuiufmfi/JdXCUCdjxwvNlMaybZDSX+xGMyEpQTIV9OZnZ Gp4GB7jEPbcH9CWDW84PAFwbO0TClcrL1aQj9C8N3+bq0nxcYCPolbMCJ0eeZvdBV9ay ZAxs/9qDf+W5rvv6Y9l+xHmmsRaC5BJEAfFMJSpt0sHRKes7er/87raNN1FouMnr0lNA iYYMr5A7x6LN4+vL4w4rTM6AwN9sc0kyUnxH5uI4v5kMrNw/MNjSdGEhaL4kvXojMj65 CznA+lUQm1lfKGBNQPnmKeQYtKKcVEGKXUzGXIRDiviT6mXGGyTe0umYKJHf2Up2LKYA oYMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691258757; x=1691863557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jjaA2yNdWRxoAIXKsMRIdPQiU+5JdGf4g+hfiGSEvXE=; b=WNz16SCe5iD5RJ9DJeq6Zp3RrgJVJk9qGkEc3uk6esdESzHmZalpJ4CLGtQ1O8G1sn YzZrr+9X8iR+P4BqsPbnpITxs4pWqe4QPHwSN6LG9lXBdJGOHarCkIHDbWrvfx0MHtBh ss8AT7Lq3u2BoN4AgPET2psmJD+7rvG/VWdmIgrSsUYWvvwa/wXTY0GByINrIayOyPpE z5+WMKSQ6CQml1P15H0SPraUUxGSpX0OXerWPHUkUPNMOPAio3sIS5WisoJnzBGcZtQy ISW+pFRWKR+9t6vgKq9hhtO6MLaOq2S71EnG9yKeZm4eFrIfgr+ihGHfVgs9Sji8wUt3 2fVA== X-Gm-Message-State: AOJu0Yx+nHM/zf/donqqtHukgFeqtEkKLZ04P0MowP4E6fxRq56S0lP7 FuvUgLaqyxFJ1poY91mWqQQ= X-Google-Smtp-Source: AGHT+IHH4WVwBu7aihjp9nuzFtSfjcWnZEsanbwbY8snGr0wZKCSwwwsVErXaYwxTLHpE9k4p+t7Qg== X-Received: by 2002:a5d:4447:0:b0:317:3d36:b2cd with SMTP id x7-20020a5d4447000000b003173d36b2cdmr3214277wrr.71.1691258756721; Sat, 05 Aug 2023 11:05:56 -0700 (PDT) Received: from user-PC.. ([178.134.198.138]) by smtp.gmail.com with ESMTPSA id v4-20020a5d6104000000b003176aa612b1sm5710402wrt.38.2023.08.05.11.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 11:05:56 -0700 (PDT) From: Maksim Kiselev To: linux-kernel@vger.kernel.org Cc: Maksim Kiselev , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jaroslav Kysela , Takashi Iwai , Maxime Ripard , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org Subject: [PATCH v1 5/5] riscv: dts: allwinner: d1: Add device nodes for internal audio codec Date: Sat, 5 Aug 2023 21:05:05 +0300 Message-Id: <20230805180506.718364-6-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230805180506.718364-1-bigunclemax@gmail.com> References: <20230805180506.718364-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-MailFrom: bigunclemax@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: D5S2NUQCLLHUPFUHO2VXLJSCQZC3XARH X-Message-ID-Hash: D5S2NUQCLLHUPFUHO2VXLJSCQZC3XARH X-Mailman-Approved-At: Tue, 08 Aug 2023 10:35:25 +0000 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: Add DT nodes for the internal D1/T113s audio codec and its analog part. Signed-off-by: Maksim Kiselev --- .../boot/dts/allwinner/sunxi-d1s-t113.dtsi | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi b/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi index 1c48bfff1715..6ceb141c3f93 100644 --- a/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi +++ b/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi @@ -180,6 +180,28 @@ ths: thermal-sensor@2009400 { #thermal-sensor-cells = <0>; }; + codec: codec@2030000 { + #sound-dai-cells = <0>; + compatible = "allwinner,sun20i-d1-codec"; + reg = <0x02030000 0x300>; + interrupts = ; + clocks = <&ccu CLK_BUS_AUDIO>, + <&ccu CLK_AUDIO_ADC>, + <&ccu CLK_AUDIO_DAC>; + clock-names = "apb", "adc", "dac"; + resets = <&ccu RST_BUS_AUDIO>; + dmas = <&dma 7>, <&dma 7>; + dma-names = "rx", "tx"; + allwinner,codec-analog-controls = <&codec_analog>; + status = "disabled"; + }; + + codec_analog: codec-analog@2030300 { + compatible = "allwinner,sun20i-d1-codec-analog"; + reg = <0x02030300 0xd00>; + status = "disabled"; + }; + dmic: dmic@2031000 { compatible = "allwinner,sun20i-d1-dmic", "allwinner,sun50i-h6-dmic";