Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1280593ybi; Fri, 14 Jun 2019 11:44:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxm0upZeW+ATBgg72D/0OgKbrtN9K3ulaGHf4t1ENcgQ82kvIyo0OfGe6Obco6voGt1Ltml X-Received: by 2002:a63:950d:: with SMTP id p13mr37198096pgd.269.1560537858943; Fri, 14 Jun 2019 11:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560537858; cv=none; d=google.com; s=arc-20160816; b=zhlGf2JndmdNCAfvBqUenIbeWsFV2NqC4JKZ5m7LMu1ifC4en4lsw29NueMlQsG0gC B1O4z5Is4g3o6q5MzXp3TmO6Hn9EXwnEla5V+X1d6i6oHJVI6gOJ6qcK47d796lYRmiq xvuk18c6RVlvlhL8AewCqyv5n9KbXERUlMMYL+UEDqPGQNv4/uobiCd2JTYVfZHPdvZ3 JXYDe4p4nWVLPieTRLpX+L9fgjgFDemVomupKDnVjsFbWZ+yY+myrLIT0k0alvgJJ/Tc mFHE6KCFbWvBym+k6IX6ZBWfZ5zS6S9Ix1tgVbd+OWy8lLkaNUoZA4W6W7kNw0h1d0Es FeJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6A6QO3r9JA5KqQ6BQwgPWC4SMx29ox8Mc2UBAF9Zkc0=; b=lIYVZGSKufbvCCuy9fJwAIzuicdFhLZzAlXdMRKrLRM+jxsBPYxfG48SbWnqxsBZ5y 09DbW3Min5xFWnuo54EQRQqSo+3kqB98vh330kIcy+/En8Rhqui7I3nU6ebF9ZSI8CbJ QzdTlPK70nsrPzZfTjZP4tL+AY3k+N/yxJFsBi79GjvIZdiRyMALW6h77UzOXirBOtZ7 FuB/k9l3h6+7Klkq26rjL95/4AYpgNqWPg8/aQzqnI4xj3Eh/sC1QEUfDFuySsDJMrkL A6a/NZmJ8fYyK9sDFjxeCH+ptzIqH7rhkQhWCd6Comi9VFx8pbb3coMTTADoxbC18OKD bwGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ktJ4GD1L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si3123232pgr.22.2019.06.14.11.44.03; Fri, 14 Jun 2019 11:44:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ktJ4GD1L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbfFNSnn (ORCPT + 99 others); Fri, 14 Jun 2019 14:43:43 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:38192 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbfFNSnm (ORCPT ); Fri, 14 Jun 2019 14:43:42 -0400 Received: by mail-io1-f66.google.com with SMTP id k13so7948993iop.5 for ; Fri, 14 Jun 2019 11:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6A6QO3r9JA5KqQ6BQwgPWC4SMx29ox8Mc2UBAF9Zkc0=; b=ktJ4GD1Likw1JDUZGK66z/qklGDtukOpRSIRnOv7OUixKXUPsp3sv9hStDuzMgofIg yfAPuDRoElV/ZWVrumi4fE+B1Ugm+oZvakOHEl2R2NRIHyOnC/s376GCY2a0w2k4IeUj sPMt0RzMlUsjRNaZCWds0+dxFkJkkY6gmR8fg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6A6QO3r9JA5KqQ6BQwgPWC4SMx29ox8Mc2UBAF9Zkc0=; b=d/pp83WuEfSroZtjuRuAglhgUK4THr8kGCMQ0XGb/+iRmCjiMHvrHjdLN5jsELkduc RIY/L6m3jVxBkMieiCytJKVpzkDnP46PyFWeBGeXDNHWc5Vgkq25A11hBOrSUQOBrdAe 5o1TRKVKoSqGnlHXgNV9Sg5Oc7cyXyDnacmFvtmhplpzrSePvOpIFXPpZZhid4AvGJfN bMFDk4cGzKLyfL+Zfzbc1CXI7bjw+IiIXYwCjEmeKSbc3h2azSCtJu4yrhXJs3j4SGze ybWOMyEZONGlhaAinPHiZ9e1HOQdau4HNs/oqDSb4oJNmPLq7aUJJDnZeGCBAdlis1Pn rnbA== X-Gm-Message-State: APjAAAUxWrT1MRxBwo9V0MpfwueZl8gSRtwGb+Vq+vrUXkMoPDaBi0QH iXCMe9iJSc+eSxGug2SgYGQ84CY5YGLnyg== X-Received: by 2002:a02:c519:: with SMTP id s25mr63894181jam.11.1560537820734; Fri, 14 Jun 2019 11:43:40 -0700 (PDT) Received: from localhost ([2620:15c:183:200:33ce:f5cf:f863:d3a6]) by smtp.gmail.com with ESMTPSA id c23sm4245686iod.11.2019.06.14.11.43.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jun 2019 11:43:40 -0700 (PDT) From: Fletcher Woodruff To: linux-kernel@vger.kernel.org Cc: Fletcher Woodruff , Jaroslav Kysela , Liam Girdwood , Mark Brown , Oder Chiou , Takashi Iwai , Curtis Malainey , Ross Zwisler , alsa-devel@alsa-project.org, Ben Zhang Subject: [PATCH v6 2/4] ASoC: rt5677: move jack-detect init to i2c probe Date: Fri, 14 Jun 2019 12:43:13 -0600 Message-Id: <20190614184315.252945-3-fletcherw@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190614184315.252945-1-fletcherw@chromium.org> References: <20190614184315.252945-1-fletcherw@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch moves the code to select the gpios for jack detection from rt5677_probe to rt5677_init_irq (called from rt5677_i2c_probe). It also sets some registers to fix bugs related to jack detection, and adds some constants and comments to make it easier to understand what certain register settings are controlling. Signed-off-by: Ben Zhang Signed-off-by: Fletcher Woodruff --- sound/soc/codecs/rt5677.c | 60 ++++++++++++++++++++++----------------- sound/soc/codecs/rt5677.h | 6 ++++ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 63e28eaf1f40ba..b508fd9b7d4536 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -4716,37 +4716,13 @@ static int rt5677_probe(struct snd_soc_component *component) snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); - regmap_write(rt5677->regmap, RT5677_DIG_MISC, 0x0020); + regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, + ~RT5677_IRQ_DEBOUNCE_SEL_MASK, 0x0020); regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00); for (i = 0; i < RT5677_GPIO_NUM; i++) rt5677_gpio_config(rt5677, i, rt5677->pdata.gpio_config[i]); - if (rt5677->irq_data) { - regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, 0x8000, - 0x8000); - regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x0018, - 0x0008); - - if (rt5677->pdata.jd1_gpio) - regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1, - RT5677_SEL_GPIO_JD1_MASK, - rt5677->pdata.jd1_gpio << - RT5677_SEL_GPIO_JD1_SFT); - - if (rt5677->pdata.jd2_gpio) - regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1, - RT5677_SEL_GPIO_JD2_MASK, - rt5677->pdata.jd2_gpio << - RT5677_SEL_GPIO_JD2_SFT); - - if (rt5677->pdata.jd3_gpio) - regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1, - RT5677_SEL_GPIO_JD3_MASK, - rt5677->pdata.jd3_gpio << - RT5677_SEL_GPIO_JD3_SFT); - } - mutex_init(&rt5677->dsp_cmd_lock); mutex_init(&rt5677->dsp_pri_lock); @@ -5095,6 +5071,7 @@ static int rt5677_init_irq(struct i2c_client *i2c) { int ret; struct rt5677_priv *rt5677 = i2c_get_clientdata(i2c); + unsigned int jd_mask = 0, jd_val = 0; if (!rt5677->pdata.jd1_gpio && !rt5677->pdata.jd2_gpio && @@ -5106,6 +5083,37 @@ static int rt5677_init_irq(struct i2c_client *i2c) return -EINVAL; } + /* + * Select RC as the debounce clock so that GPIO works even when + * MCLK is gated which happens when there is no audio stream + * (SND_SOC_BIAS_OFF). + */ + regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, + RT5677_IRQ_DEBOUNCE_SEL_MASK, + RT5677_IRQ_DEBOUNCE_SEL_RC); + + /* Enable auto power on RC when GPIO states are changed */ + regmap_update_bits(rt5677->regmap, RT5677_GEN_CTRL1, 0xff, 0xff); + + /* Select and enable jack detection sources per platform data */ + if (rt5677->pdata.jd1_gpio) { + jd_mask |= RT5677_SEL_GPIO_JD1_MASK; + jd_val |= rt5677->pdata.jd1_gpio << RT5677_SEL_GPIO_JD1_SFT; + } + if (rt5677->pdata.jd2_gpio) { + jd_mask |= RT5677_SEL_GPIO_JD2_MASK; + jd_val |= rt5677->pdata.jd2_gpio << RT5677_SEL_GPIO_JD2_SFT; + } + if (rt5677->pdata.jd3_gpio) { + jd_mask |= RT5677_SEL_GPIO_JD3_MASK; + jd_val |= rt5677->pdata.jd3_gpio << RT5677_SEL_GPIO_JD3_SFT; + } + regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1, jd_mask, jd_val); + + /* Set GPIO1 pin to be IRQ output */ + regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, + RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ); + ret = regmap_add_irq_chip(rt5677->regmap, i2c->irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0, &rt5677_irq_chip, &rt5677->irq_data); diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 183d92b030459f..7a89bfa95dc0bf 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1636,6 +1636,12 @@ #define RT5677_GPIO6_P_NOR (0x0 << 0) #define RT5677_GPIO6_P_INV (0x1 << 0) +/* General Control (0xfa) */ +#define RT5677_IRQ_DEBOUNCE_SEL_MASK (0x3 << 3) +#define RT5677_IRQ_DEBOUNCE_SEL_MCLK (0x0 << 3) +#define RT5677_IRQ_DEBOUNCE_SEL_RC (0x1 << 3) +#define RT5677_IRQ_DEBOUNCE_SEL_SLIM (0x2 << 3) + /* Virtual DSP Mixer Control (0xf7 0xf8 0xf9) */ #define RT5677_DSP_IB_01_H (0x1 << 15) #define RT5677_DSP_IB_01_H_SFT 15 -- 2.22.0.410.gd8fdbe21b5-goog