From patchwork Thu May 19 02:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12854460 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 71F24C433EF for ; Thu, 19 May 2022 02:15:22 +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 8E15115CC; Thu, 19 May 2022 04:14:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8E15115CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1652926520; bh=9jOLkACMpzUaRW5lm2N2mzfzmwCAQiS6MSiy3qPkOak=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fncVVns6VxQc3ns5nYLZCtuBb0tV/k4wdI5LeTmvnOK6Da/zyNGF4NrwGdHz7gRyx NR9ZbPuenIhNY0JRrzurAXQKGfgYqb81iqNoI4VmPIBkp10Iu32YYsJFPnCmlPxsQW 2Ww1QAH/xdAC3/+b+Cr9EM4Iw0lh3QuUWyczCdjI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2A721F80269; Thu, 19 May 2022 04:14:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 77F5AF80109; Thu, 19 May 2022 04:14:00 +0200 (CEST) Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 05089F80109 for ; Thu, 19 May 2022 04:13:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 05089F80109 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JD/qYhP8" Received: by mail-pg1-x534.google.com with SMTP id c22so3786755pgu.2 for ; Wed, 18 May 2022 19:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rr/Z8lIuwod83sK9/THugMPkDoGeWIkKPvWwosbdeJg=; b=JD/qYhP8UezTRIl7mKJGofTp75y3YtKRngrnVQszhFCd4lZCs9pmDCenW24A5jCJ7+ h4Gk3rVAQVegkmW6Hr9YaC7lprEelCqi9IulyVW8sRGFRmFPqom3LyxAv2/+j/tlEvch vK1ACsyddt/yHqV/1U9npLlm7rxM96WbDWGJSCIRpPvd8jgjubMSZt223UTAGCLCLLoF 0FuLQTB3qOGgnPtineoSO5YNto7RaUE6SIVGzAIeAuS5TNkbBxaScLaUrdlCvY2lLmGk +FL3cyjwwY8lDmqRN1S9ktnen8h8hMx/qefPPzebN3SlyORa41CeAaf7E9LXceotYgz/ HqTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rr/Z8lIuwod83sK9/THugMPkDoGeWIkKPvWwosbdeJg=; b=yUnxeEPL7fheM2sA2Fz//0ESxwv4cOBfdD2GCp31Cs1zjfYwI1q2jhwE99XM1yRK2+ PrHl42sV2GoBA8gIVUYLHbaz1agjzzzbgIYDvnFk2FBfLItslYPmCy6X2JyfrsbequOg mjywi5RhXUj8KZvyRwhlRc5NjjZyhahQ19NJCOL1MTlDbK6hB9dzFuYPTIkuPouIq43G 0W666b54dWVHUyNTnXAPpxG+lD6gd1xDhew1V+yh6AJHaR0s3pyU5o7bH2yhvJ7wPJVQ 64QBDokxUY9TaoG3cEq6TJMp7I8p8wtLXx8rJ/G74zL5n3w9lSoKXAWoeeAoxsZzwnH/ NQwA== X-Gm-Message-State: AOAM532gakyLl6dmmn7dH6pAjEGjgILnX00C3YgyNFBU111/j6cYRvhj 6oGM5bEGB6sQI8TDTnRoh2g= X-Google-Smtp-Source: ABdhPJyBc/0cVz+8VsM/S5tpnBd7rbXw47kTwP5NVdBeln1UfPz2L1MVm8nKVr7/+pA0z90fFBweuA== X-Received: by 2002:a63:6a45:0:b0:3c1:47b7:edce with SMTP id f66-20020a636a45000000b003c147b7edcemr1957623pgc.207.1652926431111; Wed, 18 May 2022 19:13:51 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:568:8697:c74:ab15:730:f5f3]) by smtp.gmail.com with ESMTPSA id je4-20020a170903264400b0015ebb3bf277sm2366603plb.238.2022.05.18.19.13.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 May 2022 19:13:50 -0700 (PDT) From: cy_huang To: broonie@kernel.org, perex@perex.cz, tiwai@suse.com Subject: [PATCH 1/2] ASoC: rt9120: Fix 3byte read, valule offset typo Date: Thu, 19 May 2022 10:13:37 +0800 Message-Id: <1652926418-8519-2-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1652926418-8519-1-git-send-email-u0084500@gmail.com> References: <1652926418-8519-1-git-send-email-u0084500@gmail.com> Cc: oder_chiou@realtek.com, alsa-devel@alsa-project.org, ritchie_hsieh@richtek.com, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, ChiYuan Huang , allen_lin@richtek.com 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" From: ChiYuan Huang For RG 3byte read, the value order is offset [0], [1], and [2]. Signed-off-by: ChiYuan Huang --- sound/soc/codecs/rt9120.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt9120.c b/sound/soc/codecs/rt9120.c index cdf8ad2..94d42be 100644 --- a/sound/soc/codecs/rt9120.c +++ b/sound/soc/codecs/rt9120.c @@ -372,7 +372,7 @@ static int rt9120_reg_read(void *context, unsigned int reg, unsigned int *val) *val = be32_to_cpup((__be32 *)raw); break; case 3: - *val = raw[0] << 16 | raw[1] << 8 | raw[0]; + *val = raw[0] << 16 | raw[1] << 8 | raw[2]; break; case 2: *val = be16_to_cpup((__be16 *)raw); From patchwork Thu May 19 02:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12854461 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 1A7EDC433EF for ; Thu, 19 May 2022 02:15:41 +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 5D4DCE0F; Thu, 19 May 2022 04:14:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5D4DCE0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1652926539; bh=ybk25WGdBM6dpL+VILu/rrGmuwlvmVZYAsjPgtcFRgw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=F/jwycoDRCV/Hy8j0XScrfc3CclNlCiS9DRzpUKtBdsWVAAGPYthzcZ1KgE6SGBcp qBevPixDrV62FqZUHxNqq+Lhtacym7NCRPUrQOpuo/T76fzqRgQLbeWPgBumnwlAMd ysiWhU1scl8Cr2UZ03kFfbn8vy4cld4SxvOLlYrs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B080EF8047B; Thu, 19 May 2022 04:14:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 92216F804A9; Thu, 19 May 2022 04:14:00 +0200 (CEST) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 41A24F80269 for ; Thu, 19 May 2022 04:13:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 41A24F80269 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TuSEjTsg" Received: by mail-pg1-x535.google.com with SMTP id q76so3749155pgq.10 for ; Wed, 18 May 2022 19:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wyq2Los7z2YQuHxhySTXRtJAk+YnndZRPaJjpNvCr8w=; b=TuSEjTsgu8bKEUlEZySSXPqZJGxx9GeOlFB46KJun0qNXIigT6+gPEJytAlE1OHo2M W9IDT/qkArhUDBp8R5Zpm1qhWdFBaEkxdge9VuHMgmkMmztr+MxKnmIzAAgDneGp+iuy nvc0wvvp+FjoTm+CROi5sRElaQ+xPqyrAom47a4Lgna5CzuSswFLcWZh4L6Q25H1pAmc ZDD0drYe0vUxbB+ufugyCnz5HuYuDqx1AZqDi0uQ2j8g+OIl125UqGx+YWK7IhUtj73K g7fdCgigLGx4NwErdAz8GiL9pAwsCphuDNIn0JCWSPIJ+u5sZ5Udw7KI+Fwe3jcwHyXC g3Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wyq2Los7z2YQuHxhySTXRtJAk+YnndZRPaJjpNvCr8w=; b=X8kba5Hajb9LY/eS3m+EorGDSfFf1vtA/TwCnIDC8No1dm9wzJzgd9bkOl7MvAL4yo WO4pCzoXhLLu0KhoZPDtPhG7vvSfIBwM8YziNQleSxsarOz39jfpBMVvtWGQVgsaqwF6 DnqKFLov9EHtyciFS0qanfGqQbKujMtddMUzZ3nj2IWedmU8205evTW30Qfy6+4O/Uec R67RlqyZVxCdDKi0goqCiL0UaEDWkp9p+ObnlIJA1OuEtWomrRFmZYy9U8W0TiwC2oXa PzZRSaO8HhlQyarIy4o4BK/18Mm5rArlV/VL3qbm0BTnGvKgoDLoZd7CV8A1UZi5XF/G W09g== X-Gm-Message-State: AOAM533sFAU0eZ/+sX/ofXIVsZl1uPC/LGyWR1Rb76PErZAs1AVhadB7 o5+bnGxHkUOZEtMcKxCBrXI= X-Google-Smtp-Source: ABdhPJwGOU545bZP0+XM7ca6pZFSklswcp3GoMluQyeKnLw0Q6vv6iMHjVJ7EUNsyjg6yaSoor1f2w== X-Received: by 2002:a63:d813:0:b0:3f5:f9d8:7cce with SMTP id b19-20020a63d813000000b003f5f9d87ccemr2001690pgh.585.1652926435270; Wed, 18 May 2022 19:13:55 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:568:8697:c74:ab15:730:f5f3]) by smtp.gmail.com with ESMTPSA id je4-20020a170903264400b0015ebb3bf277sm2366603plb.238.2022.05.18.19.13.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 May 2022 19:13:54 -0700 (PDT) From: cy_huang To: broonie@kernel.org, perex@perex.cz, tiwai@suse.com Subject: [PATCH 2/2] ASoC: rt9120: Use pm_runtime and regcache to optimize 'pwdnn' logic Date: Thu, 19 May 2022 10:13:38 +0800 Message-Id: <1652926418-8519-3-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1652926418-8519-1-git-send-email-u0084500@gmail.com> References: <1652926418-8519-1-git-send-email-u0084500@gmail.com> Cc: oder_chiou@realtek.com, alsa-devel@alsa-project.org, ritchie_hsieh@richtek.com, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, ChiYuan Huang , allen_lin@richtek.com 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" From: ChiYuan Huang From the datasheet, the only way to meet the lowest power consumption is to pull low the 'pwdnn' gpio. But if it is low, IC will keep in reset state, all registers reset to default. And the power consumption is listed below 1. amp off and 'pwdnn' high => idle state, PVDD = 1mA, DVDD = 7mA 2. amp off and 'pwdnn' low => shutdown state, PVDD < 20uA, DVDD < 15uA It's the large difference for the consumption current This fix is to use pm_runtime and regcache to handle 'pwdnn' gpio control. Signed-off-by: ChiYuan Huang --- sound/soc/codecs/rt9120.c | 111 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt9120.c b/sound/soc/codecs/rt9120.c index 94d42be..da495bd 100644 --- a/sound/soc/codecs/rt9120.c +++ b/sound/soc/codecs/rt9120.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,7 @@ enum { struct rt9120_data { struct device *dev; struct regmap *regmap; + struct gpio_desc *pwdnn_gpio; int chip_idx; }; @@ -160,6 +162,8 @@ static int rt9120_codec_probe(struct snd_soc_component *comp) snd_soc_component_init_regmap(comp, data->regmap); + pm_runtime_get_sync(comp->dev); + /* Internal setting */ if (data->chip_idx == CHIP_IDX_RT9120S) { snd_soc_component_write(comp, RT9120_REG_INTERCFG, 0xde); @@ -167,6 +171,9 @@ static int rt9120_codec_probe(struct snd_soc_component *comp) } else snd_soc_component_write(comp, RT9120_REG_INTERNAL0, 0x04); + pm_runtime_mark_last_busy(comp->dev); + pm_runtime_put(comp->dev); + return 0; } @@ -338,6 +345,18 @@ static const struct regmap_access_table rt9120_wr_table = { .n_yes_ranges = ARRAY_SIZE(rt9120_wr_yes_ranges), }; +static bool rt9120_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case 0x00 ... 0x01: + case 0x10: + case 0x30 ... 0x40: + return true; + default: + return false; + } +} + static int rt9120_get_reg_size(unsigned int reg) { switch (reg) { @@ -397,14 +416,49 @@ static int rt9120_reg_write(void *context, unsigned int reg, unsigned int val) return i2c_smbus_write_i2c_block_data(i2c, reg, size, rawp + offs); } +static const struct reg_default rt9120_reg_defaults[] = { + { .reg = 0x02, .def = 0x02 }, + { .reg = 0x03, .def = 0xf2 }, + { .reg = 0x04, .def = 0x01 }, + { .reg = 0x05, .def = 0xc0 }, + { .reg = 0x06, .def = 0x28 }, + { .reg = 0x07, .def = 0x04 }, + { .reg = 0x08, .def = 0xff }, + { .reg = 0x09, .def = 0x01 }, + { .reg = 0x0a, .def = 0x01 }, + { .reg = 0x0b, .def = 0x00 }, + { .reg = 0x0c, .def = 0x04 }, + { .reg = 0x11, .def = 0x30 }, + { .reg = 0x12, .def = 0x08 }, + { .reg = 0x13, .def = 0x12 }, + { .reg = 0x14, .def = 0x09 }, + { .reg = 0x15, .def = 0x00 }, + { .reg = 0x20, .def = 0x7ff }, + { .reg = 0x21, .def = 0x180 }, + { .reg = 0x22, .def = 0x180 }, + { .reg = 0x23, .def = 0x00 }, + { .reg = 0x24, .def = 0x80 }, + { .reg = 0x25, .def = 0x180 }, + { .reg = 0x26, .def = 0x640 }, + { .reg = 0x27, .def = 0x180 }, + { .reg = 0x63, .def = 0x5e }, + { .reg = 0x65, .def = 0x66 }, + { .reg = 0x6c, .def = 0xe0 }, + { .reg = 0xf8, .def = 0x44 }, +}; + static const struct regmap_config rt9120_regmap_config = { .reg_bits = 8, .val_bits = 32, .max_register = RT9120_REG_DIGCFG, + .reg_defaults = rt9120_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(rt9120_reg_defaults), + .cache_type = REGCACHE_RBTREE, .reg_read = rt9120_reg_read, .reg_write = rt9120_reg_write, + .volatile_reg = rt9120_volatile_reg, .wr_table = &rt9120_wr_table, .rd_table = &rt9120_rd_table, }; @@ -450,7 +504,6 @@ static int rt9120_do_register_reset(struct rt9120_data *data) static int rt9120_probe(struct i2c_client *i2c) { struct rt9120_data *data; - struct gpio_desc *pwdnn_gpio; struct regulator *dvdd_supply; int dvdd_supply_volt, ret; @@ -461,12 +514,12 @@ static int rt9120_probe(struct i2c_client *i2c) data->dev = &i2c->dev; i2c_set_clientdata(i2c, data); - pwdnn_gpio = devm_gpiod_get_optional(&i2c->dev, "pwdnn", - GPIOD_OUT_HIGH); - if (IS_ERR(pwdnn_gpio)) { + data->pwdnn_gpio = devm_gpiod_get_optional(&i2c->dev, "pwdnn", + GPIOD_OUT_HIGH); + if (IS_ERR(data->pwdnn_gpio)) { dev_err(&i2c->dev, "Failed to initialize 'pwdnn' gpio\n"); - return PTR_ERR(pwdnn_gpio); - } else if (pwdnn_gpio) { + return PTR_ERR(data->pwdnn_gpio); + } else if (data->pwdnn_gpio) { dev_dbg(&i2c->dev, "'pwdnn' from low to high, wait chip on\n"); msleep(RT9120_CHIPON_WAITMS); } @@ -508,11 +561,55 @@ static int rt9120_probe(struct i2c_client *i2c) } } + pm_runtime_set_autosuspend_delay(&i2c->dev, 1000); + pm_runtime_use_autosuspend(&i2c->dev); + pm_runtime_set_active(&i2c->dev); + pm_runtime_mark_last_busy(&i2c->dev); + pm_runtime_enable(&i2c->dev); + return devm_snd_soc_register_component(&i2c->dev, &rt9120_component_driver, &rt9120_dai, 1); } +static int rt9120_remove(struct i2c_client *i2c) +{ + pm_runtime_disable(&i2c->dev); + pm_runtime_set_suspended(&i2c->dev); + return 0; +} + +static int __maybe_unused rt9120_runtime_suspend(struct device *dev) +{ + struct rt9120_data *data = dev_get_drvdata(dev); + + if (data->pwdnn_gpio) { + regcache_cache_only(data->regmap, true); + regcache_mark_dirty(data->regmap); + gpiod_set_value(data->pwdnn_gpio, 0); + } + + return 0; +} + +static int __maybe_unused rt9120_runtime_resume(struct device *dev) +{ + struct rt9120_data *data = dev_get_drvdata(dev); + + if (data->pwdnn_gpio) { + gpiod_set_value(data->pwdnn_gpio, 1); + msleep(RT9120_CHIPON_WAITMS); + regcache_cache_only(data->regmap, false); + regcache_sync(data->regmap); + } + + return 0; +} + +static const struct dev_pm_ops rt9120_pm_ops = { + SET_RUNTIME_PM_OPS(rt9120_runtime_suspend, rt9120_runtime_resume, NULL) +}; + static const struct of_device_id __maybe_unused rt9120_device_table[] = { { .compatible = "richtek,rt9120", }, { } @@ -523,8 +620,10 @@ static struct i2c_driver rt9120_driver = { .driver = { .name = "rt9120", .of_match_table = rt9120_device_table, + .pm = &rt9120_pm_ops, }, .probe_new = rt9120_probe, + .remove = rt9120_remove, }; module_i2c_driver(rt9120_driver);