From patchwork Mon Sep 26 13:29:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 9350677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89D786077A for ; Mon, 26 Sep 2016 13:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74E2C28DA5 for ; Mon, 26 Sep 2016 13:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 682B028DA9; Mon, 26 Sep 2016 13:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA01E28DA8 for ; Mon, 26 Sep 2016 13:31:54 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0DB69266735; Mon, 26 Sep 2016 15:31:53 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 5F3A5265598; Mon, 26 Sep 2016 15:29:34 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id EDFF5266735; Mon, 26 Sep 2016 15:29:24 +0200 (CEST) Received: from mail1.bemta3.messagelabs.com (mail1.bemta3.messagelabs.com [195.245.230.166]) by alsa0.perex.cz (Postfix) with ESMTP id 32BB5265598 for ; Mon, 26 Sep 2016 15:29:21 +0200 (CEST) Received: from [85.158.137.99] by server-6.bemta-3.messagelabs.com id 73/2F-28813-1B229E75; Mon, 26 Sep 2016 13:29:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjleJIrShJLcpLzFFi42KJ27nUWHej0st wg8e7mCyuXDzEZDH14RM2i5vvnjNZfLvSwWRxedccNovOXf2sFqvfLGCx2PB9LaNF4+u5rA6c Hhs+N7F5zG64yOKxc9Zddo/Fe14yeWxa1cnmse/tMjaPv7P2s3is33KVxePzJrkAzijWzLyk/ IoE1oyDHa1sBevFKw4tfsTWwPhDuIuRi0NIYD2jxKJd+9m6GDmBnAqJq9vuMIPYvAKZElce/W MCsTkF3CWWfr7IClHjJnF98hMwm03AQmLyiQdgvSwCqhKNk+8zgtjCAl4S5x9MYwVZICLQxSi x+tVjdhCHWeA/o8TmkwtZIDYISpyc+QTMZhaQkDj44gUzxAYDidMLGsHiEgL2EtPfXwWKcwDZ +hKNx2IhwoYS32d9gyoxl9hz/j7TBEbBWUimzkIydQEj0ypGjeLUorLUIl0jM72kosz0jJLcx MwcXUMDY73c1OLixPTUnMSkYr3k/NxNjMD4qWdgYNzB2LDX7xCjJAeTkiivntzLcCG+pPyUyo zE4oz4otKc1OJDjDIcHEoSvO8UgXKCRanpqRVpmTnASIZJS3DwKInwcgOjWYi3uCAxtzgzHSJ 1ilFRSpx3D0ifAEgiozQPrg2WPC4xykoJ8zIyMDAI8RSkFuVmlqDKv2IU52BUEuaVABnPk5lX Ajf9FdBiJqDFS0+8AFlckoiQkmpgnM3VeUxj/+t/2xvFblqdXlNxSjxJYc1Z/1thW4tFT0cZn ju5oo3x6spsq0l/ijh7Iue1B/MqLP9ztH/v/XXqV940OXTybuy/0RMZ9c/y3630BL3eBZmiIV 5Coet/3vnOc+26/qG2+Yy5m/Y0Fek+fl+88dyNVdZGGrorFr9ewsjjGP6g7OsfWSWW4oxEQy3 mouJEANlr544ZAwAA X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-11.tower-217.messagelabs.com!1474896560!47046753!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4486 invoked from network); 26 Sep 2016 13:29:20 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-11.tower-217.messagelabs.com with AES128-SHA encrypted SMTP; 26 Sep 2016 13:29:20 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.248.2; Mon, 26 Sep 2016 14:29:20 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 16F253FB80; Mon, 26 Sep 2016 14:29:20 +0100 (BST) Message-ID: <4c191834ee78d57c9e9d60b758d9ef767a47a523.1474896038.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Mon, 26 Sep 2016 14:29:20 +0100 To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 26/09/2016 10:27:00 Cc: alsa-devel@alsa-project.org, Support Opensource , Xing Zheng , linux-kernel@vger.kernel.org, Hsin-Yu Chao , Sathyanarayana Nujella Subject: [alsa-devel] [PATCH 1/2] ASoC: da7219: Reset codec gracefully, if still active X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the reset code in i2c_probe only resets the AAD part of the device and not the entire codec. This patch updates the driver to resolve this and ensures that if the codec is still active from a previous boot then the audio paths are powered down prior to reset. Signed-off-by: Adam Thomson --- sound/soc/codecs/da7219.c | 30 +++++++++++++++++++++++++++--- sound/soc/codecs/da7219.h | 5 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 9d08c11..eecb6d6 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -1925,7 +1925,8 @@ static int da7219_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct da7219_priv *da7219; - int ret; + unsigned int system_active, system_status; + int i, ret; da7219 = devm_kzalloc(&i2c->dev, sizeof(struct da7219_priv), GFP_KERNEL); @@ -1941,14 +1942,37 @@ static int da7219_i2c_probe(struct i2c_client *i2c, return ret; } - /* Software reset codec. */ + regcache_cache_bypass(da7219->regmap, true); + + /* Disable audio paths if still active from previous start */ + regmap_read(da7219->regmap, DA7219_SYSTEM_ACTIVE, &system_active); + if (system_active) { + regmap_write(da7219->regmap, DA7219_GAIN_RAMP_CTRL, + DA7219_GAIN_RAMP_RATE_NOMINAL); + regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_INPUT, 0x00); + regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_OUTPUT, 0x01); + + for (i = 0; i < DA7219_SYS_STAT_CHECK_RETRIES; ++i) { + regmap_read(da7219->regmap, DA7219_SYSTEM_STATUS, + &system_status); + if (!system_status) + break; + + msleep(DA7219_SYS_STAT_CHECK_DELAY); + } + } + + /* Soft reset codec */ regmap_write_bits(da7219->regmap, DA7219_ACCDET_CONFIG_1, DA7219_ACCDET_EN_MASK, 0); regmap_write_bits(da7219->regmap, DA7219_CIF_CTRL, - DA7219_CIF_REG_SOFT_RESET_MASK, 0); + DA7219_CIF_REG_SOFT_RESET_MASK, + DA7219_CIF_REG_SOFT_RESET_MASK); regmap_write_bits(da7219->regmap, DA7219_SYSTEM_ACTIVE, DA7219_SYSTEM_ACTIVE_MASK, 0); + regcache_cache_bypass(da7219->regmap, false); + ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_da7219, &da7219_dai, 1); if (ret < 0) { diff --git a/sound/soc/codecs/da7219.h b/sound/soc/codecs/da7219.h index 545576d..f1b3ad8 100644 --- a/sound/soc/codecs/da7219.h +++ b/sound/soc/codecs/da7219.h @@ -578,6 +578,7 @@ #define DA7219_GAIN_RAMP_RATE_SHIFT 0 #define DA7219_GAIN_RAMP_RATE_MASK (0x3 << 0) #define DA7219_GAIN_RAMP_RATE_X8 (0x0 << 0) +#define DA7219_GAIN_RAMP_RATE_NOMINAL (0x1 << 0) #define DA7219_GAIN_RAMP_RATE_MAX 4 /* DA7219_PC_COUNT = 0x94 */ @@ -772,6 +773,10 @@ /* SRM */ #define DA7219_SRM_CHECK_RETRIES 8 +/* System Controller */ +#define DA7219_SYS_STAT_CHECK_RETRIES 6 +#define DA7219_SYS_STAT_CHECK_DELAY 50 + enum da7219_clk_src { DA7219_CLKSRC_MCLK = 0, DA7219_CLKSRC_MCLK_SQR,