From patchwork Tue Feb 20 22:15:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10230943 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 89EBF601E7 for ; Tue, 20 Feb 2018 22:16:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C45C286A1 for ; Tue, 20 Feb 2018 22:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61367287E3; Tue, 20 Feb 2018 22:16:19 +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 59797286A1 for ; Tue, 20 Feb 2018 22:16:18 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id A59EE267556; Tue, 20 Feb 2018 23:15:30 +0100 (CET) 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 5BA77267538; Tue, 20 Feb 2018 23:15:27 +0100 (CET) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by alsa0.perex.cz (Postfix) with ESMTP id 8068126752D for ; Tue, 20 Feb 2018 23:15:25 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DAD22402290A; Tue, 20 Feb 2018 22:15:24 +0000 (UTC) Received: from dhcp-44-202.space.revspace.nl.com (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4F872024CA7; Tue, 20 Feb 2018 22:15:23 +0000 (UTC) From: Hans de Goede To: Mark Brown , Bard Liao Date: Tue, 20 Feb 2018 23:15:05 +0100 Message-Id: <20180220221511.22861-5-hdegoede@redhat.com> In-Reply-To: <20180220221511.22861-1-hdegoede@redhat.com> References: <20180220221511.22861-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 20 Feb 2018 22:15:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 20 Feb 2018 22:15:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Cc: Hans de Goede , alsa-devel@alsa-project.org, Carlo Caione , Takashi Iwai Subject: [alsa-devel] [PATCH 05/11] ASoC: rt5651: Allow specifying micbias over-current thresholds through pdata 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP OVer-Current-Detection (OVCD) for the micbias current is used to detect if an inserted jack is a headset or headphones (mic shorted to ground). Some boards may need different values for the OVCD threshold because of a resistor on the board in serial with or parallel to the jack mic contact. This commit adds support for the sofar unset OVCD scale-factor register values and adds support for specifying both the current threshold and the scale-factor to pdata and this commets sets these values only once from rt5651_set_jack() instead of setting them every time we do jack-detection. This commit sets the new pdata values for this to 2000uA with a scale-factor of 0.75 for the KIANO SlimNote 14.2 device, which is the only rt5652 using device on which jack-detection is currently enabled. Signed-off-by: Hans de Goede --- include/sound/rt5651.h | 29 +++++++++++++++++++++++++++- sound/soc/codecs/rt5651.c | 27 +++++++++++++++++--------- sound/soc/codecs/rt5651.h | 10 ++++++++++ sound/soc/intel/boards/bytcr_rt5651.c | 36 +++++++++++++++++++++++++++++------ 4 files changed, 86 insertions(+), 16 deletions(-) diff --git a/include/sound/rt5651.h b/include/sound/rt5651.h index 18b79a761f10..7b000406589c 100644 --- a/include/sound/rt5651.h +++ b/include/sound/rt5651.h @@ -18,12 +18,39 @@ enum rt5651_jd_src { RT5651_JD2, }; +/* These mirror the RT5651_MIC1_OVTH_*UA consts and MUST be in the same order */ +enum rt5651_ovth_curr { + RT5651_OVTH_600UA, + RT5651_OVTH_1500UA, + RT5651_OVTH_2000UA, +}; + +/* These mirror the RT5651_MIC_OVCD_SF* consts and MUST be in the same order */ +enum rt5651_ovcd_sf { + RT5651_OVCD_SF_0P5, + RT5651_OVCD_SF_0P75, + RT5651_OVCD_SF_1P0, + RT5651_OVCD_SF_1P5, +}; + +/* + * Note testing on various boards has shown that good defaults for ovth_curr + * and ovth_sf are 2000UA and 0.75. For an effective threshold of 1500UA, + * this seems to be more reliable then 1500UA and 1.0. Some boards may need + * different values because of a resistor on the board in serial with or + * parallel to the jack mic contact. + */ struct rt5651_platform_data { /* IN2 can optionally be differential */ bool in2_diff; - + /* Configure GPIO2 as DMIC1 SCL */ bool dmic_en; + /* Jack detect source or JD_NULL to disable jack-detect */ enum rt5651_jd_src jd_src; + /* Jack micbias overcurrent detect current threshold */ + enum rt5651_ovth_curr ovth_curr; + /* Jack micbias overcurrent detect current scale-factor */ + enum rt5651_ovcd_sf ovth_sf; }; #endif diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c index 4b0509f7e001..1e20cdb8b569 100644 --- a/sound/soc/codecs/rt5651.c +++ b/sound/soc/codecs/rt5651.c @@ -1575,6 +1575,7 @@ static int rt5651_set_jack(struct snd_soc_codec *codec, regmap_update_bits(rt5651->regmap, RT5651_GPIO_CTRL1, RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ); + /* Select jack detect source */ switch (rt5651->pdata.jd_src) { case RT5651_JD1_1: regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2, @@ -1607,11 +1608,25 @@ static int rt5651_set_jack(struct snd_soc_codec *codec, break; } + /* Enable jack detect power */ regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG2, RT5651_PWR_JD_M, RT5651_PWR_JD_M); + /* + * Set OVCD threshold current and scale-factor from pdata. + */ + regmap_write(rt5651->regmap, RT5651_PR_BASE + RT5651_BIAS_CUR4, 0xa800 | + (rt5651->pdata.ovth_sf << RT5651_MIC_OVCD_SF_SFT)); + regmap_update_bits(rt5651->regmap, RT5651_MICBIAS, - 0x38, 0x38); + RT5651_MIC1_OVCD_MASK | + RT5651_MIC1_OVTH_MASK | + RT5651_PWR_CLK12M_MASK | + RT5651_PWR_MB_MASK, + RT5651_MIC1_OVCD_DIS | + (rt5651->pdata.ovth_curr << RT5651_MIC1_OVTH_SFT) | + RT5651_PWR_MB_PU | + RT5651_PWR_CLK12M_PU); ret = devm_request_threaded_irq(codec->dev, rt5651->irq, NULL, rt5651_irq, @@ -1795,14 +1810,8 @@ static int rt5651_jack_detect(struct snd_soc_codec *codec, int jack_insert) snd_soc_dapm_mutex_unlock(dapm); snd_soc_update_bits(codec, RT5651_MICBIAS, - RT5651_MIC1_OVCD_MASK | - RT5651_MIC1_OVTH_MASK | - RT5651_PWR_CLK12M_MASK | - RT5651_PWR_MB_MASK, - RT5651_MIC1_OVCD_EN | - RT5651_MIC1_OVTH_600UA | - RT5651_PWR_MB_PU | - RT5651_PWR_CLK12M_PU); + RT5651_MIC1_OVCD_MASK, + RT5651_MIC1_OVCD_EN); msleep(100); if (snd_soc_read(codec, RT5651_IRQ_CTRL2) & RT5651_MB1_OC_CLR) jack_type = SND_JACK_HEADPHONE; diff --git a/sound/soc/codecs/rt5651.h b/sound/soc/codecs/rt5651.h index 151ac92f6bad..96168a1e87c1 100644 --- a/sound/soc/codecs/rt5651.h +++ b/sound/soc/codecs/rt5651.h @@ -138,6 +138,7 @@ /* Index of Codec Private Register definition */ #define RT5651_BIAS_CUR1 0x12 #define RT5651_BIAS_CUR3 0x14 +#define RT5651_BIAS_CUR4 0x15 #define RT5651_CLSD_INT_REG1 0x1c #define RT5651_CHPUMP_INT_REG1 0x24 #define RT5651_MAMP_INT_REG2 0x37 @@ -1966,6 +1967,15 @@ #define RT5651_D_GATE_EN_SFT 0 /* Codec Private Register definition */ + +/* MIC Over current threshold scale factor (0x15) */ +#define RT5651_MIC_OVCD_SF_MASK (0x3 << 8) +#define RT5651_MIC_OVCD_SF_SFT 8 +#define RT5651_MIC_OVCD_SF_0P5 (0x0 << 8) +#define RT5651_MIC_OVCD_SF_0P75 (0x1 << 8) +#define RT5651_MIC_OVCD_SF_1P0 (0x2 << 8) +#define RT5651_MIC_OVCD_SF_1P5 (0x3 << 8) + /* 3D Speaker Control (0x63) */ #define RT5651_3D_SPK_MASK (0x1 << 15) #define RT5651_3D_SPK_SFT 15 diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c index 8ef5b5500fb7..a6cc0bc85db8 100644 --- a/sound/soc/intel/boards/bytcr_rt5651.c +++ b/sound/soc/intel/boards/bytcr_rt5651.c @@ -49,11 +49,26 @@ enum { BYT_RT5651_JD2 = (RT5651_JD2 << 4), }; -#define BYT_RT5651_MAP(quirk) ((quirk) & GENMASK(3, 0)) -#define BYT_RT5651_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4) -#define BYT_RT5651_DMIC_EN BIT(16) -#define BYT_RT5651_MCLK_EN BIT(17) -#define BYT_RT5651_MCLK_25MHZ BIT(18) +enum { + BYT_RT5651_OVTH_600UA = (RT5651_OVTH_600UA << 8), + BYT_RT5651_OVTH_1500UA = (RT5651_OVTH_1500UA << 8), + BYT_RT5651_OVTH_2000UA = (RT5651_OVTH_2000UA << 8), +}; + +enum { + BYT_RT5651_OVCD_SF_0P5 = (RT5651_OVCD_SF_0P5 << 12), + BYT_RT5651_OVCD_SF_0P75 = (RT5651_OVCD_SF_0P75 << 12), + BYT_RT5651_OVCD_SF_1P0 = (RT5651_OVCD_SF_1P0 << 12), + BYT_RT5651_OVCD_SF_1P5 = (RT5651_OVCD_SF_1P5 << 12), +}; + +#define BYT_RT5651_MAP(quirk) ((quirk) & GENMASK(3, 0)) +#define BYT_RT5651_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4) +#define BYT_RT5651_OVTH(quirk) (((quirk) & GENMASK(11, 8)) >> 8) +#define BYT_RT5651_OVCD_SF(quirk) (((quirk) & GENMASK(15, 12)) >> 12) +#define BYT_RT5651_DMIC_EN BIT(16) +#define BYT_RT5651_MCLK_EN BIT(17) +#define BYT_RT5651_MCLK_25MHZ BIT(18) struct byt_rt5651_private { struct clk *mclk; @@ -73,9 +88,14 @@ static void log_quirks(struct device *dev) dev_info(dev, "quirk IN2_MAP enabled"); if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN3_MAP) dev_info(dev, "quirk IN3_MAP enabled"); - if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) + if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) { dev_info(dev, "quirk jack-detect src %ld\n", BYT_RT5651_JDSRC(byt_rt5651_quirk)); + dev_info(dev, "quirk ovth_curr %ld\n", + BYT_RT5651_OVTH(byt_rt5651_quirk)); + dev_info(dev, "quirk ovth_sf %ld\n", + BYT_RT5651_OVCD_SF(byt_rt5651_quirk)); + } if (byt_rt5651_quirk & BYT_RT5651_DMIC_EN) dev_info(dev, "quirk DMIC enabled"); if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) @@ -299,6 +319,8 @@ static const struct dmi_system_id byt_rt5651_quirk_table[] = { }, .driver_data = (void *)(BYT_RT5651_MCLK_EN | BYT_RT5651_JD1_1 | + BYT_RT5651_OVTH_2000UA | + BYT_RT5651_OVCD_SF_0P75 | BYT_RT5651_IN1_IN2_MAP), }, {} @@ -373,6 +395,8 @@ static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime) } pdata.jd_src = BYT_RT5651_JDSRC(byt_rt5651_quirk); + pdata.ovth_curr = BYT_RT5651_OVTH(byt_rt5651_quirk); + pdata.ovth_sf = BYT_RT5651_OVCD_SF(byt_rt5651_quirk); if (byt_rt5651_quirk & BYT_RT5651_DMIC_EN) pdata.dmic_en = true; rt5651_set_pdata(codec, &pdata);