From patchwork Mon Sep 12 15:46:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 9327025 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 5129760839 for ; Mon, 12 Sep 2016 16:29:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42DE428D94 for ; Mon, 12 Sep 2016 16:29:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37DC328E3C; Mon, 12 Sep 2016 16:29:42 +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 DFEBB28D94 for ; Mon, 12 Sep 2016 16:29:40 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3E8EC26695B; Mon, 12 Sep 2016 18:29:39 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C68BF26697B; Mon, 12 Sep 2016 18:27:21 +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 48E4C266943; Mon, 12 Sep 2016 17:46:57 +0200 (CEST) Received: from mail1.bemta6.messagelabs.com (mail1.bemta6.messagelabs.com [193.109.254.105]) by alsa0.perex.cz (Postfix) with ESMTP id 2B0FC265A82 for ; Mon, 12 Sep 2016 17:46:52 +0200 (CEST) Received: from [85.158.140.211] by server-1.bemta-6.messagelabs.com id FA/2B-21406-CEDC6D75; Mon, 12 Sep 2016 15:46:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRWlGSWpSXmKPExsUSt3Opse7rs9f CDX7uMrC4cvEQk8XUh0/YLL5d6WCyuLxrDptF565+VovVbxawWGz4vpbRgd1jw+cmNo+ds+6y eyze85LJY9OqTjaPfW+XsXms33KVxePzJrkA9ijWzLyk/IoE1oy2f79ZC6aoVmzc1cDawDhTo YuRi0NIYD2jxMxV91i6GDmBnAqJ7l2P2UBsNgELicknHoDZLAKqEn0fZzCB2MICgRKN3YeZQZ pFBLoYJVa/eswO4jALbGaUaOj4D1bFK+AgcW/ZFEYIW1Di5MwnYBuYBSQkDr54wQyxzUDi9IJ GsLiEgL3E9PdXgeIcQLa+ROOxWIiwocT3Wd+gSswlnr36yjaBkX8WkqmzkExdwMi0ilG9OLWo LLVI11AvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyMwyBmAYAfjzudOhxglOZiUR HmTBK+FC/El5adUZiQWZ8QXleakFh9ilOHgUJLgPX4GKCdYlJqeWpGWmQOMN5i0BAePkgjvDZ A0b3FBYm5xZjpE6hSjopQ471eQhABIIqM0D64NFuOXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsG oJMw7D2QKT2ZeCdz0V0CLmYAWP916GWRxSSJCSqqBsUJ/p+10TVfPWwvmXlx71neeA+Me7cOX M3Smm91PXSxsu+p6V+UM+zJlh1PRPnxz5j3/cH1HbY2p4iK1/TvdOqVuRqdaxOdaTGn6qB3kb yfUn5Hx+5Dm15U2V/f1GnI9vyOu8PZxnaen0d8o9oXC/zYG/hLkZme+z8554P/hDxdKX8d2Lb 1YrsRSnJFoqMVcVJwIADZMZ2vsAgAA X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-15.tower-194.messagelabs.com!1473695211!55164035!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8668 invoked from network); 12 Sep 2016 15:46:51 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-15.tower-194.messagelabs.com with AES128-SHA encrypted SMTP; 12 Sep 2016 15:46:51 -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, 12 Sep 2016 16:46:51 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id F1EAF3FA9D; Mon, 12 Sep 2016 16:46:50 +0100 (BST) From: Adam Thomson Date: Mon, 12 Sep 2016 16:46:50 +0100 To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai Message-ID: <20160912154650.F1EAF3FA9D@swsrvapps-01.diasemi.com> 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: 12/09/2016 13:33:00 Cc: Sathyanarayana Nujella , alsa-devel@alsa-project.org, Support Opensource , linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH] ASoC: da7219: Support HP detect procedure when MCLK not present 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 driver code assumes that MCLK will be present during the procedure, or if it has control of MCLK then it can make sure it's enabled. Some platforms however do not provide MCLK to the driver in this way, and will not leave MCLK enabled when Codec is in STANDBY state. This patch adds support for the HP detect procedure when running from the device's internal oscillator, to ensure all platforms can make use of this feature correctly. Signed-off-by: Adam Thomson --- sound/soc/codecs/da7219-aad.c | 34 ++++++++++++++++++++++++++++++++-- sound/soc/codecs/da7219-aad.h | 6 ++++-- sound/soc/codecs/da7219.h | 2 ++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index 4e369a1..fc27dab 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -115,7 +115,7 @@ static void da7219_aad_hptest_work(struct work_struct *work) struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); u16 tonegen_freq_hptest; - u8 accdet_cfg8; + u8 pll_srm_sts, gain_ramp_ctrl, accdet_cfg8; int report = 0, ret = 0; /* Lock DAPM and any Kcontrols that are affected by this test */ @@ -133,6 +133,20 @@ static void da7219_aad_hptest_work(struct work_struct *work) } } + /* + * If MCLK not present, then we're using the internal oscillator and + * require different frequency settings to achieve the same result. + */ + pll_srm_sts = snd_soc_read(codec, DA7219_PLL_SRM_STS); + if (pll_srm_sts & DA7219_PLL_SRM_STS_MCLK) + tonegen_freq_hptest = cpu_to_le16(DA7219_AAD_HPTEST_RAMP_FREQ); + else + tonegen_freq_hptest = cpu_to_le16(DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC); + + /* Ensure gain ramping at fastest rate */ + gain_ramp_ctrl = snd_soc_read(codec, DA7219_GAIN_RAMP_CTRL); + snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, DA7219_GAIN_RAMP_RATE_X8); + /* Bypass cache so it saves current settings */ regcache_cache_bypass(da7219->regmap, true); @@ -195,9 +209,15 @@ static void da7219_aad_hptest_work(struct work_struct *work) snd_soc_write(codec, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK | DA7219_HP_R_AMP_EN_MASK); + /* + * If we're running from the internal oscillator then give audio paths + * time to settle before running test. + */ + if (!(pll_srm_sts & DA7219_PLL_SRM_STS_MCLK)) + msleep(DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY); + /* Configure & start Tone Generator */ snd_soc_write(codec, DA7219_TONE_GEN_ON_PER, DA7219_BEEP_ON_PER_MASK); - tonegen_freq_hptest = cpu_to_le16(DA7219_AAD_HPTEST_RAMP_FREQ); regmap_raw_write(da7219->regmap, DA7219_TONE_GEN_FREQ1_L, &tonegen_freq_hptest, sizeof(tonegen_freq_hptest)); snd_soc_update_bits(codec, DA7219_TONE_GEN_CFG2, @@ -256,6 +276,16 @@ static void da7219_aad_hptest_work(struct work_struct *work) snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_8, DA7219_HPTEST_EN_MASK, 0); + /* + * If we're running from the internal oscillator then give audio paths + * time to settle before allowing headphones to be driven as required. + */ + if (!(pll_srm_sts & DA7219_PLL_SRM_STS_MCLK)) + msleep(DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY); + + /* Restore gain ramping rate */ + snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, gain_ramp_ctrl); + /* Drive Headphones/lineout */ snd_soc_update_bits(codec, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK, DA7219_HP_L_AMP_OE_MASK); diff --git a/sound/soc/codecs/da7219-aad.h b/sound/soc/codecs/da7219-aad.h index 4fccf67..a34be48 100644 --- a/sound/soc/codecs/da7219-aad.h +++ b/sound/soc/codecs/da7219-aad.h @@ -176,8 +176,10 @@ #define DA7219_AAD_MICBIAS_CHK_DELAY 10 #define DA7219_AAD_MICBIAS_CHK_RETRIES 5 -#define DA7219_AAD_HPTEST_RAMP_FREQ 0x28 -#define DA7219_AAD_HPTEST_PERIOD 65 +#define DA7219_AAD_HPTEST_RAMP_FREQ 0x28 +#define DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC 0x4D +#define DA7219_AAD_HPTEST_PERIOD 65 +#define DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY 20 enum da7219_aad_event_regs { DA7219_AAD_IRQ_REG_A = 0, diff --git a/sound/soc/codecs/da7219.h b/sound/soc/codecs/da7219.h index ff2a2f0..545576d 100644 --- a/sound/soc/codecs/da7219.h +++ b/sound/soc/codecs/da7219.h @@ -224,6 +224,7 @@ #define DA7219_PLL_SRM_STATE_MASK (0xF << 0) #define DA7219_PLL_SRM_STATUS_SHIFT 4 #define DA7219_PLL_SRM_STATUS_MASK (0xF << 4) +#define DA7219_PLL_SRM_STS_MCLK (0x1 << 4) #define DA7219_PLL_SRM_STS_SRM_LOCK (0x1 << 7) /* DA7219_DIG_ROUTING_DAI = 0x2A */ @@ -576,6 +577,7 @@ /* DA7219_GAIN_RAMP_CTRL = 0x92 */ #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_MAX 4 /* DA7219_PC_COUNT = 0x94 */