From patchwork Fri Jun 24 10:47:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584886 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 279E4C433EF for ; Fri, 24 Jun 2022 10:48:54 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9E75A183B; Fri, 24 Jun 2022 12:48:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9E75A183B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067732; bh=bBRa8nevTNOZWvilLQ4FsUBKwTmWUgsHXM7MPfQlOVc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VfkM2wz/qCp++tI0uUPA9szE/OkBQhfrVHgPRmrhkbtGMZ167BKX74kiRlsTSdkWT +qZPOpreyAmWkl7Xlm6P1hy2VjwfSLb2RXehN0VkMq06OfKwAwNgFJbcaVVoSNK6lT R7iyWblDJ4j/CUjpA9kVOtmSEaSNTlPBWUCiI1QQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 0C6B1F80107; Fri, 24 Jun 2022 12:48:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E5BC5F80535; Fri, 24 Jun 2022 12:47:59 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id C292AF800CB for ; Fri, 24 Jun 2022 12:47:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C292AF800CB Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id 79992284B6F; Fri, 24 Jun 2022 10:47:22 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 1/8] ASoC: dt-bindings: max98396: add voltage supplies Date: Fri, 24 Jun 2022 12:47:05 +0200 Message-Id: <20220624104712.1934484-2-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The device is supplied with 3 core voltages (DVVDIO, DVDD, AVDD), and PVDD and/or VBAT. Signed-off-by: Daniel Mack --- .../bindings/sound/adi,max98396.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml index ec4c10c2598a..a23ac8036e1c 100644 --- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml +++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml @@ -24,6 +24,21 @@ properties: maxItems: 1 description: I2C address of the device. + avdd-supply: + description: A 1.8V supply that powers up the AVDD pin. + + dvdd-supply: + description: A 1.2V supply that powers up the DVDD pin. + + dvddio-supply: + description: A 1.2V or 1.8V supply that powers up the VDDIO pin. + + pvdd-supply: + description: A 3.0V to 20V supply that powers up the PVDD pin. + + vbat-supply: + description: A 3.3V to 5.5V supply that powers up the VBAT pin. + adi,vmon-slot-no: description: slot number of the voltage sense monitor $ref: "/schemas/types.yaml#/definitions/uint32" @@ -72,6 +87,10 @@ examples: max98396: amplifier@39 { compatible = "adi,max98396"; reg = <0x39>; + dvdd-supply = <®ulator_1v2>; + dvddio-supply = <®ulator_1v8>; + avdd-supply = <®ulator_1v8>; + pvdd-supply = <®ulator_pvdd>; adi,vmon-slot-no = <0>; adi,imon-slot-no = <1>; reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; From patchwork Fri Jun 24 10:47:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584883 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 BDB99C43334 for ; Fri, 24 Jun 2022 10:50:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 19DC818A3; Fri, 24 Jun 2022 12:49:47 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 19DC818A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067837; bh=w7NyuKS2fB0qJIklVkx3Wr2CO6++x0SgPB6695j11tA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eQDCoZTyOJftRoVom0YAxIOeZ5XjjjmoxY0FG21CzaOJyJZg/wggeTWF7n/5NL9PX qdl1my1p2VzkiufQTA2xh3kK+5uR1xJmVs1VhqNGZYp7nFifo4UFhAtGBQsJgdsLf7 12humnXblkBOwKUoTDh/cfIFHy7+//XNYlC3NV80= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 84BF5F80558; Fri, 24 Jun 2022 12:48:11 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6417FF80139; Fri, 24 Jun 2022 12:48:07 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 16EF7F804ED for ; Fri, 24 Jun 2022 12:47:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 16EF7F804ED Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id 3EA16504570; Fri, 24 Jun 2022 10:47:23 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells Date: Fri, 24 Jun 2022 12:47:06 +0200 Message-Id: <20220624104712.1934484-3-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Add this mandatory DT property to the yaml documentation. Signed-off-by: Daniel Mack --- Documentation/devicetree/bindings/sound/adi,max98396.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml index a23ac8036e1c..8887e74b7ea5 100644 --- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml +++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml @@ -72,6 +72,9 @@ properties: reset-gpios: maxItems: 1 + "#sound-dai-cells": + const: 0 + required: - compatible - reg @@ -94,5 +97,6 @@ examples: adi,vmon-slot-no = <0>; adi,imon-slot-no = <1>; reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; + #sound-dai-cells: <0>; }; }; From patchwork Fri Jun 24 10:47:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584639 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 6AE75C433EF for ; Fri, 24 Jun 2022 10:49:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 907AA188F; Fri, 24 Jun 2022 12:48:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 907AA188F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067742; bh=Kkk/85OkEaUuxlqSwYtKeEnayjcgoahYQMQVVwVkBVw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jso6s5Vj/KwywwG/1QVtkfEMa6nTvEhQr31jyAuAUFI0JvkiC2QGops+hFgmXkPa7 SceWG4C45UdGcp39S7YEs5nFOp48BPnZUeniUIcARh0eXkxjsUmIWdbv6xLKypsuxH AapcFDjgv6vyGa8VmnDDqprfZz6Q2hFSe6WOl5nI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C4E52F80537; Fri, 24 Jun 2022 12:48:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F4188F800CB; Fri, 24 Jun 2022 12:47:59 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 9FA9EF80107 for ; Fri, 24 Jun 2022 12:47:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9FA9EF80107 Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id D3B84504573; Fri, 24 Jun 2022 10:47:23 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no Date: Fri, 24 Jun 2022 12:47:07 +0200 Message-Id: <20220624104712.1934484-4-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" This property allows to select the PCM data input channel that is routed to the speaker audio processing bypass path. The driver already implements this property. While at it, fix the default value for adi,imon-slot-no. Signed-off-by: Daniel Mack --- .../devicetree/bindings/sound/adi,max98396.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml index 8887e74b7ea5..c848397a7248 100644 --- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml +++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml @@ -51,13 +51,22 @@ properties: $ref: "/schemas/types.yaml#/definitions/uint32" minimum: 0 maximum: 15 - default: 0 + default: 1 adi,spkfb-slot-no: description: slot number of speaker DSP monitor $ref: "/schemas/types.yaml#/definitions/uint32" minimum: 0 maximum: 15 + default: 2 + + adi,bypass-slot-no: + description: + Selects the PCM data input channel that is routed to the speaker + audio processing bypass path. + $ref: "/schemas/types.yaml#/definitions/uint32" + minimum: 0 + maximum: 15 default: 0 adi,interleave-mode: From patchwork Fri Jun 24 10:47:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584637 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 BF515C433EF for ; Fri, 24 Jun 2022 10:50:19 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EEEDF18C6; Fri, 24 Jun 2022 12:49:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EEEDF18C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067818; bh=SSPDuw7byl8qgGSmkBH5/4+DN/JOsaCgCXbfG1weDp0=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=k4ZZZSohT1DKm7sxQAhHEBA98bmuaAJy0o0EHDlnvkCCFnBiqxzuEtKBD/0pGQuE6 SJeiVe8CpAQVNDKQJFw2b9/sirUKZt6I76m8tKVqtGZf6xweEsr2sZIJ9C+mfhfTkD yLsgsMfKCX2r6HdwJwK9+WZzw/6iU8Uo2OX3n+H8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 11FD9F80549; Fri, 24 Jun 2022 12:48:11 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0287EF8053E; Fri, 24 Jun 2022 12:48:06 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 6583DF80137 for ; Fri, 24 Jun 2022 12:47:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6583DF80137 Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id 32D53504576; Fri, 24 Jun 2022 10:47:24 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 4/8] ASoC: max98396: add voltage regulators Date: Fri, 24 Jun 2022 12:47:08 +0200 Message-Id: <20220624104712.1934484-5-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The device has up to 5 potentially independent power supplies: AVDD, DVDD, DVVDIO, VBAT and PVDD. The former 3 are mandatory for the device to function. One of VBAT and PVDD should also be made available. Regulators are enabled during probe time and will stay active except when in suspend mode. Futher, the chip needs to be informed about the presence of VBAT through a bit in register 0x20a0. Signed-off-by: Daniel Mack --- sound/soc/codecs/max98396.c | 117 +++++++++++++++++++++++++++++++++++- sound/soc/codecs/max98396.h | 7 +++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index 56eb62bb041f..06ac637f2696 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -5,11 +5,18 @@ #include #include #include +#include #include #include #include #include "max98396.h" +static const char * const max98396_core_supplies[MAX98396_NUM_CORE_SUPPLIES] = { + "avdd", + "dvdd", + "dvddio", +}; + static struct reg_default max98396_reg[] = { {MAX98396_R2000_SW_RESET, 0x00}, {MAX98396_R2001_INT_RAW1, 0x00}, @@ -1329,6 +1336,12 @@ static int max98396_probe(struct snd_soc_component *component) regmap_write(max98396->regmap, MAX98397_R2057_PCM_RX_SRC2, 0x10); } + /* Supply control */ + regmap_update_bits(max98396->regmap, + MAX98396_R20A0_AMP_SUPPLY_CTL, + MAX98396_AMP_SUPPLY_NOVBAT, + (max98396->vbat == NULL) ? + MAX98396_AMP_SUPPLY_NOVBAT : 0); /* Enable DC blocker */ regmap_update_bits(max98396->regmap, MAX98396_R2092_AMP_DSP_CFG, 1, 1); @@ -1424,12 +1437,38 @@ static int max98396_suspend(struct device *dev) regcache_cache_only(max98396->regmap, true); regcache_mark_dirty(max98396->regmap); + regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES, + max98396->core_supplies); + if (max98396->pvdd) + regulator_disable(max98396->pvdd); + + if (max98396->vbat) + regulator_disable(max98396->vbat); + return 0; } static int max98396_resume(struct device *dev) { struct max98396_priv *max98396 = dev_get_drvdata(dev); + int ret; + + ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES, + max98396->core_supplies); + if (ret < 0) + return ret; + + if (max98396->pvdd) { + ret = regulator_enable(max98396->pvdd); + if (ret < 0) + return ret; + } + + if (max98396->vbat) { + ret = regulator_enable(max98396->vbat); + if (ret < 0) + return ret; + } regcache_cache_only(max98396->regmap, false); max98396_reset(max98396, dev); @@ -1513,11 +1552,24 @@ static void max98396_read_device_property(struct device *dev, max98396->bypass_slot = 0; } +static void max98396_core_supplies_disable(void *priv) +{ + struct max98396_priv *max98396 = priv; + + regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES, + max98396->core_supplies); +} + +static void max98396_supply_disable(void *r) +{ + regulator_disable((struct regulator *) r); +} + static int max98396_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max98396_priv *max98396 = NULL; - int ret, reg; + int i, ret, reg; max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL); @@ -1543,6 +1595,69 @@ static int max98396_i2c_probe(struct i2c_client *i2c, return ret; } + /* Obtain regulator supplies */ + for (i = 0; i < MAX98396_NUM_CORE_SUPPLIES; i++) + max98396->core_supplies[i].supply = max98396_core_supplies[i]; + + ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES, + max98396->core_supplies); + if (ret < 0) { + dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret); + return ret; + } + + max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat"); + if (IS_ERR(max98396->vbat)) { + if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER) + return -EPROBE_DEFER; + + max98396->vbat = NULL; + } + + max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd"); + if (IS_ERR(max98396->pvdd)) { + if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER) + return -EPROBE_DEFER; + + max98396->pvdd = NULL; + } + + ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES, + max98396->core_supplies); + if (ret < 0) { + dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret); + return ret; + } + + ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable, + max98396); + if (ret < 0) + return ret; + + if (max98396->pvdd) { + ret = regulator_enable(max98396->pvdd); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&i2c->dev, + max98396_supply_disable, + max98396->pvdd); + if (ret < 0) + return ret; + } + + if (max98396->vbat) { + ret = regulator_enable(max98396->vbat); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&i2c->dev, + max98396_supply_disable, + max98396->vbat); + if (ret < 0) + return ret; + } + /* update interleave mode info */ if (device_property_read_bool(&i2c->dev, "adi,interleave_mode")) max98396->interleave_mode = true; diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h index 694411038597..8fa081f5d2d3 100644 --- a/sound/soc/codecs/max98396.h +++ b/sound/soc/codecs/max98396.h @@ -274,6 +274,9 @@ #define MAX98396_DSP_SPK_SAFE_EN_SHIFT (5) #define MAX98396_DSP_SPK_WB_FLT_EN_SHIFT (6) +/* MAX98396_R20A0_AMP_SUPPLY_CTL */ +#define MAX98396_AMP_SUPPLY_NOVBAT (0x1 << 0) + /* MAX98396_R20E0_IV_SENSE_PATH_CFG */ #define MAX98396_IV_SENSE_DCBLK_EN_MASK (0x3 << 0) #define MAX98396_IV_SENSE_DCBLK_EN_SHIFT (0) @@ -291,9 +294,13 @@ enum { CODEC_TYPE_MAX98397, }; +#define MAX98396_NUM_CORE_SUPPLIES 3 + struct max98396_priv { struct regmap *regmap; struct gpio_desc *reset_gpio; + struct regulator_bulk_data core_supplies[MAX98396_NUM_CORE_SUPPLIES]; + struct regulator *pvdd, *vbat; unsigned int v_slot; unsigned int i_slot; unsigned int bypass_slot; From patchwork Fri Jun 24 10:47:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584884 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 67B64C433EF for ; Fri, 24 Jun 2022 10:49:59 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B4006183E; Fri, 24 Jun 2022 12:49:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B4006183E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067797; bh=sEtRBhxM1rDhwev4tv8Ux2lP84NN8gT9990pnhrLamQ=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TmxizHCpaEsFp3vk/SDK5bh6F58+8mKO3nkAoLD/AH+rN9Ix3jZqKYV3hJipb6TrL NIJBebUbNc4tIFslowzd/MCkZoC7y64VJS/kdG/PUo/Mo4hcZJU3s3nfC6cq3TqRcU F9iSUnzxpZhLh9as34yUKlcBd9FQxTx8fV5X864g= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9266FF80544; Fri, 24 Jun 2022 12:48:10 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 108BEF80139; Fri, 24 Jun 2022 12:48:07 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id D3D46F8016E for ; Fri, 24 Jun 2022 12:47:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D3D46F8016E Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id C070D504578; Fri, 24 Jun 2022 10:47:24 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 5/8] ASoC: max98396: Improve some error prints Date: Fri, 24 Jun 2022 12:47:09 +0200 Message-Id: <20220624104712.1934484-6-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Let's log what actually failed and log at some more places. Signed-off-by: Daniel Mack --- sound/soc/codecs/max98396.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index 06ac637f2696..faa81b4bb709 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -372,7 +372,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) break; default: - dev_err(component->dev, "DAI invert mode unsupported\n"); + dev_err(component->dev, "DAI invert mode %d unsupported\n", + fmt & SND_SOC_DAIFMT_INV_MASK); return -EINVAL; } @@ -391,6 +392,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) format |= MAX98396_PCM_FORMAT_TDM_MODE0; break; default: + dev_err(component->dev, "DAI format %d unsupported\n", + fmt & SND_SOC_DAIFMT_FORMAT_MASK); return -EINVAL; } @@ -461,8 +464,9 @@ static int max98396_set_clock(struct snd_soc_component *component, /* BCLK configuration */ value = max98396_get_bclk_sel(blr_clk_ratio); if (!value) { - dev_err(component->dev, "format unsupported %d\n", - params_format(params)); + dev_err(component->dev, + "blr_clk_ratio %d unsupported, format %d\n", + blr_clk_ratio, params_format(params)); return -EINVAL; } @@ -647,7 +651,7 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai, chan_sz = MAX98396_PCM_MODE_CFG_CHANSZ_32; break; default: - dev_err(component->dev, "format unsupported %d\n", + dev_err(component->dev, "slot width %d unsupported\n", slot_width); return -EINVAL; } From patchwork Fri Jun 24 10:47:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584638 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 8005FC43334 for ; Fri, 24 Jun 2022 10:49:48 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 678AD1838; Fri, 24 Jun 2022 12:48:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 678AD1838 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067786; bh=N1Z/0RghyFfehixXn+LE7Fsqk3oKYwhb4qWTgZ+cabQ=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LOJjDICQvizKqgps46CVry4/tSO8sGjitdxV2rMf4K5S/dZdaomx07WJcn8Ivz2Sl 0VnO+iPf1FBBV/HDwcQ+JLKKARQXWqD0EgYxpjpdL6XI20u+9PlOGi7ctKHOaVnbPh TgW2fvYRdjkuWFpkCaGBaqu5grY2hUHqw+gmJRcQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 02875F8053E; Fri, 24 Jun 2022 12:48:08 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 81671F8053E; Fri, 24 Jun 2022 12:48:04 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 75B4BF80139 for ; Fri, 24 Jun 2022 12:47:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 75B4BF80139 Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id 1DA5C50457A; Fri, 24 Jun 2022 10:47:25 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings Date: Fri, 24 Jun 2022 12:47:10 +0200 Message-Id: <20220624104712.1934484-7-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" max98396_dai_set_fmt() modifes register 2041 and touches bits in the mask 0x3a. Make sure to use the right mask for that operation. Signed-off-by: Daniel Mack --- sound/soc/codecs/max98396.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index faa81b4bb709..0a1d98279a3e 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -349,12 +349,15 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { struct snd_soc_component *component = codec_dai->component; struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component); - unsigned int format = 0; + unsigned int format_mask, format = 0; unsigned int bclk_pol = 0; int ret, status; int reg; bool update = false; + format_mask = MAX98396_PCM_MODE_CFG_FORMAT_MASK | + MAX98396_PCM_MODE_CFG_LRCLKEDGE; + dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); switch (fmt & SND_SOC_DAIFMT_INV_MASK) { @@ -405,7 +408,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, ®); if (ret < 0) return -EINVAL; - if (format != (reg & MAX98396_PCM_BCLKEDGE_BSEL_MASK)) { + if (format != (reg & format_mask)) { update = true; } else { ret = regmap_read(max98396->regmap, @@ -422,8 +425,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) regmap_update_bits(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, - MAX98396_PCM_BCLKEDGE_BSEL_MASK, - format); + format_mask, format); regmap_update_bits(max98396->regmap, MAX98396_R2042_PCM_CLK_SETUP, From patchwork Fri Jun 24 10:47:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584882 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 24AC3C43334 for ; Fri, 24 Jun 2022 10:51:13 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 56743172E; Fri, 24 Jun 2022 12:50:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 56743172E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067871; bh=0bsT6+zl7D9tYSewyoYhG2yQHV7TkzKfgZdf20MGWxY=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I+LywgYclTvQ/YhHXzLW3p7BPtr/KUTdBTEO3jU/sm7BVrPtdSbtnpTGQtstBO9+V VxBmbMew/ieXsfXeKzH3DtSxoWIltuDqAoUE88EEERrQTLpL3TDrvcyz1z33aSeyKq zcQE3GwP/2IopVMC5Zln4SVwPbnlN0o7rse5moa8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 20ED6F80571; Fri, 24 Jun 2022 12:48:33 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3B552F80567; Fri, 24 Jun 2022 12:48:32 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 2EF78F80567 for ; Fri, 24 Jun 2022 12:48:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2EF78F80567 Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id 7E57F50457B; Fri, 24 Jun 2022 10:47:25 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 7/8] ASoC: max98396: Implement DSP speaker monitor Date: Fri, 24 Jun 2022 12:47:11 +0200 Message-Id: <20220624104712.1934484-8-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Allow the selection of the TDM slot that is used to send back speaker monitor data. The DT property adi,spkfb-slot-no can be used to configure this setting which defaults to 2. Signed-off-by: Daniel Mack --- sound/soc/codecs/max98396.c | 8 ++++++++ sound/soc/codecs/max98396.h | 1 + 2 files changed, 9 insertions(+) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index 0a1d98279a3e..f28831f4e74b 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -1377,6 +1377,9 @@ static int max98396_probe(struct snd_soc_component *component) regmap_write(max98396->regmap, MAX98396_R2045_PCM_TX_CTRL_2, max98396->i_slot); + regmap_write(max98396->regmap, + MAX98396_R204A_PCM_TX_CTRL_7, + max98396->spkfb_slot); if (max98396->v_slot < 8) if (max98396->device_id == CODEC_TYPE_MAX98396) @@ -1552,6 +1555,11 @@ static void max98396_read_device_property(struct device *dev, else max98396->i_slot = 1; + if (!device_property_read_u32(dev, "adi,spkfb-slot-no", &value)) + max98396->spkfb_slot = value & 0xF; + else + max98396->spkfb_slot = 2; + if (!device_property_read_u32(dev, "adi,bypass-slot-no", &value)) max98396->bypass_slot = value & 0xF; else diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h index 8fa081f5d2d3..ff330ef61568 100644 --- a/sound/soc/codecs/max98396.h +++ b/sound/soc/codecs/max98396.h @@ -303,6 +303,7 @@ struct max98396_priv { struct regulator *pvdd, *vbat; unsigned int v_slot; unsigned int i_slot; + unsigned int spkfb_slot; unsigned int bypass_slot; bool interleave_mode; unsigned int ch_size; From patchwork Fri Jun 24 10:47:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 584636 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 92341C43334 for ; Fri, 24 Jun 2022 10:50:48 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D565F18A9; Fri, 24 Jun 2022 12:49:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D565F18A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1656067846; bh=KCIT30npe4ogYODluNp/GiXwQg/ljYKVGzf5o1Tx1bk=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lOAxI0LDdT9RwE/cJnvvDYjsnDr1LarPGfPgbMLQZoiBqs4ChtQMb1K6ycefAZ2fM OITN8y03EpZ6BPOmiPDsPQuqHyudlDbd93U6jRlXkRMoSW1taI0tePqLW6KDO6ICU9 bVqGEGFRg5ozANTWeG00ivQlO5jGsWGRE8T70z9E= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 02959F80559; Fri, 24 Jun 2022 12:48:12 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DF61CF80543; Fri, 24 Jun 2022 12:48:09 +0200 (CEST) Received: from mail.bugwerft.de (mail.bugwerft.de [46.23.86.59]) by alsa1.perex.cz (Postfix) with ESMTP id 39073F80246 for ; Fri, 24 Jun 2022 12:47:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 39073F80246 Received: from hq-00021.holoplot.net (unknown [176.126.217.202]) by mail.bugwerft.de (Postfix) with ESMTPSA id BA70F50457C; Fri, 24 Jun 2022 10:47:25 +0000 (UTC) From: Daniel Mack To: broonie@kernel.org, ryan.lee.analog@gmail.com Subject: [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings Date: Fri, 24 Jun 2022 12:47:12 +0200 Message-Id: <20220624104712.1934484-9-daniel@zonque.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624104712.1934484-1-daniel@zonque.org> References: <20220624104712.1934484-1-daniel@zonque.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, Daniel Mack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" In TDM mode, the BSEL register value must be set according to table 5 in the datasheet. This patch adds a lookup function and uses it in max98396_dai_tdm_slot(). As the first 3 entries can also be used for non-TDM setups, the code now re-uses the same code for such scenarios. max98396_set_clock() is folded into its only user for clarity. Signed-off-by: Daniel Mack --- sound/soc/codecs/max98396.c | 124 +++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index f28831f4e74b..f1657a5f2140 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -438,47 +438,55 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) return 0; } -/* BCLKs per LRCLK */ -static const int bclk_sel_table[] = { - 32, 48, 64, 96, 128, 192, 256, 384, 512, 320, +/* Refer to table 5 in the datasheet */ +static const struct max98396_pcm_config { + int in, out, width, bsel, max_sr; +} max98396_pcm_configs[] = { + { .in = 2, .out = 4, .width = 16, .bsel = 0x2, /* 32 */ .max_sr = 192000 }, + { .in = 2, .out = 6, .width = 24, .bsel = 0x3, /* 48 */ .max_sr = 192000 }, + { .in = 2, .out = 8, .width = 32, .bsel = 0x4, /* 64 */ .max_sr = 192000 }, + { .in = 3, .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 192000 }, + { .in = 4, .out = 8, .width = 16, .bsel = 0x4, /* 64 */ .max_sr = 192000 }, + { .in = 4, .out = 12, .width = 24, .bsel = 0x5, /* 96 */ .max_sr = 192000 }, + { .in = 4, .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 192000 }, + { .in = 5, .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 192000 }, + { .in = 7, .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 192000 }, + { .in = 2, .out = 4, .width = 16, .bsel = 0x2, /* 32 */ .max_sr = 96000 }, + { .in = 2, .out = 6, .width = 24, .bsel = 0x3, /* 48 */ .max_sr = 96000 }, + { .in = 2, .out = 8, .width = 32, .bsel = 0x4, /* 64 */ .max_sr = 96000 }, + { .in = 3, .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 96000 }, + { .in = 4, .out = 8, .width = 16, .bsel = 0x4, /* 64 */ .max_sr = 96000 }, + { .in = 4, .out = 12, .width = 24, .bsel = 0x5, /* 96 */ .max_sr = 96000 }, + { .in = 4, .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 96000 }, + { .in = 5, .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 96000 }, + { .in = 7, .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 96000 }, + { .in = 7, .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 96000 }, + { .in = 8, .out = 16, .width = 16, .bsel = 0x6, /* 128 */ .max_sr = 96000 }, + { .in = 8, .out = 24, .width = 24, .bsel = 0x7, /* 192 */ .max_sr = 96000 }, + { .in = 8, .out = 32, .width = 32, .bsel = 0x8, /* 256 */ .max_sr = 96000 }, + { .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 96000 }, + { .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 96000 }, + { .in = 16, .out = 32, .width = 16, .bsel = 0x8, /* 256 */ .max_sr = 96000 }, + { .in = 7, .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 48000 }, + { .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 48000 }, + { .in = 10, .out = 40, .width = 32, .bsel = 0xb, /* 320 */ .max_sr = 48000 }, + { .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 48000 }, + { .in = 16, .out = 48, .width = 24, .bsel = 0x9, /* 384 */ .max_sr = 48000 }, + { .in = 16, .out = 64, .width = 32, .bsel = 0xa, /* 512 */ .max_sr = 48000 }, }; -static int max98396_get_bclk_sel(int bclk) +static int max98396_pcm_config_index(int in_slots, int out_slots, int width) { int i; - /* match BCLKs per LRCLK */ - for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) { - if (bclk_sel_table[i] == bclk) - return i + 2; - } - return 0; -} -static int max98396_set_clock(struct snd_soc_component *component, - struct snd_pcm_hw_params *params) -{ - struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component); - /* BCLK/LRCLK ratio calculation */ - int blr_clk_ratio = params_channels(params) * max98396->ch_size; - int value; - - if (!max98396->tdm_mode) { - /* BCLK configuration */ - value = max98396_get_bclk_sel(blr_clk_ratio); - if (!value) { - dev_err(component->dev, - "blr_clk_ratio %d unsupported, format %d\n", - blr_clk_ratio, params_format(params)); - return -EINVAL; - } + for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) { + const struct max98396_pcm_config *c = &max98396_pcm_configs[i]; - regmap_update_bits(max98396->regmap, - MAX98396_R2042_PCM_CLK_SETUP, - MAX98396_PCM_CLK_SETUP_BSEL_MASK, - value); + if (in_slots == c->in && out_slots <= c->out && width == c->width) + return i; } - return 0; + return -1; } static int max98396_dai_hw_params(struct snd_pcm_substream *substream, @@ -489,8 +497,7 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream, struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component); unsigned int sampling_rate = 0; unsigned int chan_sz = 0; - int ret, reg; - int status; + int ret, reg, status, bsel; bool update = false; /* pcm mode configuration */ @@ -510,8 +517,6 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream, goto err; } - max98396->ch_size = snd_pcm_format_width(params_format(params)); - dev_dbg(component->dev, "format supported %d", params_format(params)); @@ -559,6 +564,33 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream, goto err; } + if (max98396->tdm_mode) { + if (params_rate(params) > max98396->tdm_max_samplerate) { + dev_err(component->dev, "TDM sample rate %d too high", + params_rate(params)); + goto err; + } + } else { + /* BCLK configuration */ + ret = max98396_pcm_config_index(params_channels(params), + params_channels(params), + snd_pcm_format_width(params_format(params))); + if (ret < 0) { + dev_err(component->dev, + "no PCM config for %d channels, format %d\n", + params_channels(params), params_format(params)); + goto err; + } + + bsel = max98396_pcm_configs[ret].bsel; + + if (params_rate(params) > max98396_pcm_configs[ret].max_sr) { + dev_err(component->dev, "sample rate %d too high", + params_rate(params)); + goto err; + } + } + ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); if (ret < 0) goto err; @@ -604,12 +636,15 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream, MAX98396_IVADC_SR_MASK, sampling_rate << MAX98396_IVADC_SR_SHIFT); - ret = max98396_set_clock(component, params); + regmap_update_bits(max98396->regmap, + MAX98396_R2042_PCM_CLK_SETUP, + MAX98396_PCM_CLK_SETUP_BSEL_MASK, + bsel); if (status && update) max98396_global_enable_onoff(max98396->regmap, true); - return ret; + return 0; err: return -EINVAL; @@ -634,13 +669,16 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai, max98396->tdm_mode = true; /* BCLK configuration */ - bsel = max98396_get_bclk_sel(slots * slot_width); - if (bsel == 0) { - dev_err(component->dev, "BCLK %d not supported\n", - slots * slot_width); + ret = max98396_pcm_config_index(slots, slots, slot_width); + if (ret < 0) { + dev_err(component->dev, "no TDM config for %d slots %d bits\n", + slots, slot_width); return -EINVAL; } + bsel = max98396_pcm_configs[ret].bsel; + max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr; + /* Channel size configuration */ switch (slot_width) { case 16: