From patchwork Mon May 8 11:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Anikiel?= X-Patchwork-Id: 680025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24A19C77B7F for ; Mon, 8 May 2023 11:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235982AbjEHLcL (ORCPT ); Mon, 8 May 2023 07:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235934AbjEHLbq (ORCPT ); Mon, 8 May 2023 07:31:46 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD5823D205 for ; Mon, 8 May 2023 04:31:01 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ad714536cfso19170341fa.0 for ; Mon, 08 May 2023 04:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; t=1683545461; x=1686137461; 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=ymKooIYpnS0yXmXMVqwK3LSKOegi+Ec1cIWEbDw6jNE=; b=EkbqMgpAbp9yuEgOG1A3wXusm0aFuxDIqSVict33dumhnUUCzPqZz/659moGrwOhHF pPFk+3yCI4QXcUi01EhSOBw6VaAiHtQPM+YIMzA/2+qi7olUCEk3u6uDy6A2v+8NQ2zK ZnZ8RpyT9XAfSuCIsajRwnGBkA/LT9BBPy2uK+9KuAlJZ70s0z/DkhmcR/+MLKSseZ39 3WZg6CT0HDHuiKqwgjwg7prejSMg5M1t4v+TP+dat13Mf0wDnfP2JIzfd9rgkmr24x63 G8P6wTgwuIp/0vi7wl2VIM5kk47T2Xj7Cka51IRwAm6KoWVs4p1sfhGcV93fJMslV/tE +rhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683545461; x=1686137461; 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=ymKooIYpnS0yXmXMVqwK3LSKOegi+Ec1cIWEbDw6jNE=; b=RBOrcU3nU8Ax9+YSULzOto9Kdh3hKGs7zE5ZthWkqHjCch6dQgjViotAy2a1mdKubw od1/0B4ptGFmQhG0MPRySJGdvHfbtMXPdxisRrCB3CuaVeV2rMFQuDmNx3PqY7yCiCUT J0W1LlBsNA8dSdxTmAZOMtxqQ8UemvbBYQZxdhc+HDlcvFSdAq8fnV1nIeXK43htHWRK VUA+qeff+4oo2AdrMNZXrOw7PjrffM5liQpFaReNXFH4gRXxhZMuWmVYMzTgACCVXLb2 dOdKCLz+rkgCW0/39X6MHrGC12wa8EtYoBpQ2iXgTB+l0iVs+KWKvLuO5KIRQerSjkvr /vPw== X-Gm-Message-State: AC+VfDyIsv1WddyBXGJvdZ+pYdYpxKNHWJVFVxThK49PTnNcwl+QdFOG Jlrgl7vTH5LNJmxBVDpDUB4cDg== X-Google-Smtp-Source: ACHHUZ7Xo1m77SC9+1H52SaylyUjEYosNnuWegDfTXW98eJ0YFRyE7rIxq+OofISewu6mn1JhUksog== X-Received: by 2002:a2e:9d87:0:b0:2a8:a629:c203 with SMTP id c7-20020a2e9d87000000b002a8a629c203mr2801101ljj.32.1683545461381; Mon, 08 May 2023 04:31:01 -0700 (PDT) Received: from panikiel.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id k8-20020a2e2408000000b002a8b9353338sm1144406ljk.117.2023.05.08.04.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 04:31:01 -0700 (PDT) From: =?utf-8?q?Pawe=C5=82_Anikiel?= To: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: perex@perex.cz, tiwai@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, dinguyen@kernel.org, lars@metafoo.de, nuno.sa@analog.com, upstream@semihalf.com, amstan@chromium.org, =?utf-8?q?P?= =?utf-8?q?awe=C5=82_Anikiel?= Subject: [PATCH v2 7/7] ASoC: ssm2602: Add workaround for playback distortions Date: Mon, 8 May 2023 13:30:37 +0200 Message-ID: <20230508113037.137627-8-pan@semihalf.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230508113037.137627-1-pan@semihalf.com> References: <20230508113037.137627-1-pan@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Apply a workaround for what appears to be a hardware quirk. The problem seems to happen when enabling "whole chip power" (bit D7 register R6) for the very first time after the chip receives power. If either "output" (D4) or "DAC" (D3) aren't powered on at that time, playback becomes very distorted later on. This happens on the Google Chameleon v3, as well as on a ZYBO Z7-10: https://ez.analog.com/audio/f/q-a/543726/solved-ssm2603-right-output-offset-issue/480229 I suspect this happens only when using an external MCLK signal (which is the case for both of these boards). Here are some experiments run on a Google Chameleon v3. These were run in userspace using a wrapper around the i2cset utility: ssmset() { i2cset -y 0 0x1a $(($1*2)) $2 } For each of the following sequences, we apply power to the ssm2603 chip, set the configuration registers R0-R5 and R7-R8, run the selected sequence, and check for distortions on playback. ssmset 0x09 0x01 # core ssmset 0x06 0x07 # chip, out, dac OK ssmset 0x09 0x01 # core ssmset 0x06 0x87 # out, dac ssmset 0x06 0x07 # chip OK (disable MCLK) ssmset 0x09 0x01 # core ssmset 0x06 0x1f # chip ssmset 0x06 0x07 # out, dac (enable MCLK) OK ssmset 0x09 0x01 # core ssmset 0x06 0x1f # chip ssmset 0x06 0x07 # out, dac NOT OK ssmset 0x06 0x1f # chip ssmset 0x09 0x01 # core ssmset 0x06 0x07 # out, dac NOT OK ssmset 0x09 0x01 # core ssmset 0x06 0x0f # chip, out ssmset 0x06 0x07 # dac NOT OK ssmset 0x09 0x01 # core ssmset 0x06 0x17 # chip, dac ssmset 0x06 0x07 # out NOT OK For each of the following sequences, we apply power to the ssm2603 chip, run the selected sequence, issue a reset with R15, configure R0-R5 and R7-R8, run one of the NOT OK sequences from above, and check for distortions. ssmset 0x09 0x01 # core ssmset 0x06 0x07 # chip, out, dac OK (disable MCLK) ssmset 0x09 0x01 # core ssmset 0x06 0x07 # chip, out, dac (enable MCLK after reset) NOT OK ssmset 0x09 0x01 # core ssmset 0x06 0x17 # chip, dac NOT OK ssmset 0x09 0x01 # core ssmset 0x06 0x0f # chip, out NOT OK ssmset 0x06 0x07 # chip, out, dac NOT OK Signed-off-by: Paweł Anikiel --- sound/soc/codecs/ssm2602.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index 00b60369b029..c29324403e9d 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c @@ -53,6 +53,18 @@ static const struct reg_default ssm2602_reg[SSM2602_CACHEREGNUM] = { { .reg = 0x09, .def = 0x0000 } }; +/* + * ssm2602 register patch + * Workaround for playback distortions after power up: activates digital + * core, and then powers on output, DAC, and whole chip at the same time + */ + +static const struct reg_sequence ssm2602_patch[] = { + { SSM2602_ACTIVE, 0x01 }, + { SSM2602_PWR, 0x07 }, + { SSM2602_RESET, 0x00 }, +}; + /*Appending several "None"s just for OSS mixer use*/ static const char *ssm2602_input_select[] = { @@ -598,6 +610,9 @@ static int ssm260x_component_probe(struct snd_soc_component *component) return ret; } + regmap_register_patch(ssm2602->regmap, ssm2602_patch, + ARRAY_SIZE(ssm2602_patch)); + /* set the update bits */ regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL, LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);