Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7321199ybi; Wed, 5 Jun 2019 15:28:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOPsMoUe9D4RGwQKuiB9eCEbxAzemIoLlcMtSLf5p9zFzJz2AWpXfDsECfArdXhFZQge2K X-Received: by 2002:a62:e815:: with SMTP id c21mr6692876pfi.244.1559773716134; Wed, 05 Jun 2019 15:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559773716; cv=none; d=google.com; s=arc-20160816; b=MC6OWvDVYKLzMkKuU2wfmIXA02kWbqzoKbCwlbveSYhN5UhYoDCsHDabW4ohnKv6Rj F5lKt2ny8mPc32DYapXHTEDggVyomihZXNCh1T6t8iM0y/5TFtplwr+wWxE5vUy4fxSN A3LV8j97TCxBg4a07Q9bDJDiyLhnNTzBB8mnjZT9H0fVdsaly0/jFuHzjwCDvI9gqyeJ qJyK0xZOEVzdJ5SNwXMValS8RPOvMkVXFzJwvWMyFGAgB0Qhg1fnqWCkrcyh5eYikOz2 bLVDHTDt1rs0nVBJQqWgaC3x0NXQ7BAu6ikxjbu9wx20OaTBbyJSs4QnDdhMciP9p5xW ZnQw== 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=rhUtpEm6FfHJ/8xuo7UZiivJ8sKeG3d3CbKRTHxlhd4=; b=s3dFJgsCV3kH3C2DEZ7yhtSNEHsKFNV0b6GNedU2DGykDn8VmN8MCbHyHrGC+jFzKt f9xEPp8QsPJ3sCH6jq5VDOxBdnAQq+7xKDXxwZc6IzfRNy95vOsV4YLNsHQI92IxXwmZ ZfOQMIkuDV/LcbucXtqdFsyCJGNHkP9jV3b1ag7lxzDUZ/4g9VbeCdYQRwBDlb2xMSaG 1ZgK/eOitzKRZn26JcFV+GbCnloMdRCd5tzYK5BKfIEpT2e2GIeORXg/ygdD/x5lXvCH I4eQ6HQwOOja024/2YRq7YoKAJ6+BLegAv/5w/cxAMq+WP2KKnzhyDzXyntsVo4gRQX8 oRSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KOUFqxnx; 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 s2si29467225plp.326.2019.06.05.15.28.19; Wed, 05 Jun 2019 15:28:36 -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=KOUFqxnx; 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 S1726787AbfFEWY7 (ORCPT + 99 others); Wed, 5 Jun 2019 18:24:59 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:35819 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbfFEWY5 (ORCPT ); Wed, 5 Jun 2019 18:24:57 -0400 Received: by mail-it1-f195.google.com with SMTP id n189so117257itd.0 for ; Wed, 05 Jun 2019 15:24:57 -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=rhUtpEm6FfHJ/8xuo7UZiivJ8sKeG3d3CbKRTHxlhd4=; b=KOUFqxnxYe+Ka1b9hOIG5/8rTjl9GVuuyCrRATSD+U9e2aGTXMPBoxTEBEHVBhupe7 odxEdhYiVzc9oOhxVi9lz5pAhtYCYAUDHj+JFf1CBVkJdcwPVPFXoyifeRVY3KVJ0NwN vG2idK67ggCKGeyTSJ+Qcko+jbXcgwAFuTgSE= 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=rhUtpEm6FfHJ/8xuo7UZiivJ8sKeG3d3CbKRTHxlhd4=; b=YZxrA+Cwz7wef1zOAVE0JrElNWZwree8oa2McjDkFXty0oOBh3NXeUtzZ5aZfl3J7a lIJ0SoNxjgtRSMaOecYgIchL5cm63HEMOsi9utvohw3gY2Pi3Ukzq0WHJFFl+JScrZar JRWOS3XNEQ8bbjmkIBju1OV1sPGOnHJ33vB7p1zJVzaSxruRyU688ZkAkKZXj19BC8Zb ljpbz7a1HU7qel4RVz28twQatyToQk0/vHo+59LiBsa1VyZ9Uzo7zOgyYDg70jem4M8J BSinjbwtM2cGPajMJp7hpv7X1OQ9okNANG2ikFWSgWCyAXrUtrguCEETdruWL+fVAuJL Tu7w== X-Gm-Message-State: APjAAAUOn3sUTQbtfczybx/rguVcQ8PVSzu4lEC9dICitcSNIexmdibU ac/9r80ZSxLMAJ7jglZaWKLq0Otebd8z3g== X-Received: by 2002:a24:6ecd:: with SMTP id w196mr14815683itc.104.1559773490898; Wed, 05 Jun 2019 15:24:50 -0700 (PDT) Received: from localhost ([2620:15c:183:200:33ce:f5cf:f863:d3a6]) by smtp.gmail.com with ESMTPSA id 139sm70322itv.38.2019.06.05.15.24.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 15:24:50 -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: Wed, 5 Jun 2019 16:24:17 -0600 Message-Id: <20190605222419.54479-3-fletcherw@chromium.org> X-Mailer: git-send-email 2.22.0.rc1.311.g5d7573a151-goog In-Reply-To: <20190605222419.54479-1-fletcherw@chromium.org> References: <20190507220115.90395-1-fletcherw@chromium.org> <20190605222419.54479-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 62489a8c3fed6e..65bef50ded1151 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.rc1.311.g5d7573a151-goog