Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1015932pxk; Fri, 18 Sep 2020 01:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTHM3T11aZYg9SmkuTGhj/g2FJ9ewgC9VFJWQ4ZrSiwof9GBekgWds854GprGSLpWwAl8E X-Received: by 2002:a50:e80a:: with SMTP id e10mr37629517edn.4.1600416963999; Fri, 18 Sep 2020 01:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600416963; cv=none; d=google.com; s=arc-20160816; b=JEITKvn1vQCh704bPYQRBSMP29S3EjFHibH9ZWQHVDVKLUFMTLWdZUh7rE6cNizZFh bfE3VGLpWN4XLiz0WnUhQu8BI1CLNEJ7hGoCeF4AP2er8KmDcsXV2vCzAn7X/aMSZdgs Mbte2iu1E+sT8Im0qePVyngnHGexyqz/D+7yg1JeQjGG0k3PYRfeiqIF77eyoOEjY9Gm 5JaHVGKd8dAWldgEmLqVkncbimsgzmYej0iTdqPx5dLO8f1kx1wTYKo/tgCx/gEg4lLI WG4XkQdasfHay3S4TajgMeWiDdzqQjbwihg8PCgjKB2vPMvyWUsQyWk2CEi5546Gcx43 jfuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=Oe/kyqOSS+vfTj2Z8DmOJ/QTD4lls0VVIA5KQlOYFoA=; b=uB0TFz8sOlyc6QL7JR49i9iDSYCOZKpm8lQoEtIy49NA1HeBhKeJpcwYT+JBwlB9rX h/YxwZz7xq+eNay87ZJbDouCc94eFvco/3khy3YyXFJOVs9NclS0+UYJQ94+2joVIaem Y/wx0m9TQN/w7iFR3d1FVTJtTDss9w7TuH0G5KURP1E5L8xiAIvA5Zr7XzURRm7XHPaH hJvw8Ul6YFxrTFCVwQKcZ0vCqA+1xc9yFJMlZvHwhttlF8HnXbEC4kfuDuyGI/Irw/W+ ymFkYP9HCF7HiJCvyEDhPMVbt4lTWkHn7ntvsLTQq2EjpUloXllFgqQdtzrk+9wobIA/ HQxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Dn6QaBy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si1888549ejr.213.2020.09.18.01.15.41; Fri, 18 Sep 2020 01:16:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Dn6QaBy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbgIRHjt (ORCPT + 99 others); Fri, 18 Sep 2020 03:39:49 -0400 Received: from smtp1.axis.com ([195.60.68.17]:47428 "EHLO smtp1.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgIRHjt (ORCPT ); Fri, 18 Sep 2020 03:39:49 -0400 X-Greylist: delayed 429 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Sep 2020 03:39:48 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=2795; q=dns/txt; s=axis-central1; t=1600414788; x=1631950788; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Oe/kyqOSS+vfTj2Z8DmOJ/QTD4lls0VVIA5KQlOYFoA=; b=Dn6QaBy53de54tZbNz9gNScZixBBlCSlEwaBN5BjjF2/XHkqzlbkkmIK aocy6ZiFxSr8ka2WzZmDWufHHGta1JrJHBQCwnqwSITBqwujusw8goDye 9ovaU0/uek6cAQdMWG90MXMzX5UuLWgmUWymwBA6DualZ6mVyTBwzwuwa 3V+XxjzDqrEa1NmF/Q5dn4mKCw92BMXb62rC4R8L8eCza2nhSQThCdoIf j4Ytw5T5r8rXoIyJYPgqoabNwmkNNu2qjGLfuohzYqC3vOREjP1nHsOhY sKL8G/fQ9JrFqqD4zr1xU4kkg9K/mpJwi8E2OOlVYP2rRB4KQBQuvSMBe g==; IronPort-SDR: g9KO4QFRGuI7AzF3iVWt7fmncB6/fVBHINfXbzLhJHMQ2Vc+92pfEtd82Xjr+oKxls3MbeS0oe iS+jHKAiYGTJ2YqtyP1ea04tDpg1uZl6vMNSp37r/FfIO0tv4bzDbLWFA+muiaR3TVB+ZCv/rY 5qoFneBOQ+bezyd/2sXjYp5WkK4fUkgOiZlsoQKn3CZC4Jv73zkIlav10bWFCeaskWjz/HF8oX ggCePMMNi3d2CiIUbT7ir7YQfbv5SiiqbLBt+t+wPVk/ezjEljJGnz8WzP7hpJPtcxzSgLdjXC CCY= X-IronPort-AV: E=Sophos;i="5.77,274,1596492000"; d="scan'208";a="13094802" From: Camel Guo To: , , , CC: , , , Camel Guo Subject: [PATCH v4] ASoC: tlv320adcx140: Add support for configuring GPIO pin Date: Fri, 18 Sep 2020 09:32:29 +0200 Message-ID: <20200918073229.27348-1-camel.guo@axis.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Camel Guo Add support to configure the GPIO pin to the specific configuration. The GPIO pin can be configured as GPO, IRQ, SDOUT2, PDMCLK, MICBASE_EN, GPI, MCLK, SDIN, PDMDIN1, PDMDIN2, PDMDIN3 or PDMDIN4 and the output drive can be configured with various configuration. Signed-off-by: Camel Guo Acked-by: Dan Murphy --- v4: - Rebase and fix merge conflict - Add Acked-by from Dan v3: - Add ADCX140_NUM_GPIO_CFGS avoiding using magic number - Remove unneeded check on ret in adcx140_configure_gpio sound/soc/codecs/tlv320adcx140.c | 40 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tlv320adcx140.h | 5 ++++ 2 files changed, 45 insertions(+) diff --git a/sound/soc/codecs/tlv320adcx140.c b/sound/soc/codecs/tlv320adcx140.c index 28dbd7d5e149..53a80246aee1 100644 --- a/sound/soc/codecs/tlv320adcx140.c +++ b/sound/soc/codecs/tlv320adcx140.c @@ -861,6 +861,42 @@ static int adcx140_configure_gpo(struct adcx140_priv *adcx140) } +static int adcx140_configure_gpio(struct adcx140_priv *adcx140) +{ + int gpio_count = 0; + u32 gpio_outputs[ADCX140_NUM_GPIO_CFGS]; + u32 gpio_output_val = 0; + int ret; + + gpio_count = device_property_count_u32(adcx140->dev, + "ti,gpio-config"); + if (gpio_count == 0) + return 0; + + if (gpio_count != ADCX140_NUM_GPIO_CFGS) + return -EINVAL; + + ret = device_property_read_u32_array(adcx140->dev, "ti,gpio-config", + gpio_outputs, gpio_count); + if (ret) + return ret; + + if (gpio_outputs[0] > ADCX140_GPIO_CFG_MAX) { + dev_err(adcx140->dev, "GPIO config out of range\n"); + return -EINVAL; + } + + if (gpio_outputs[1] > ADCX140_GPIO_DRV_MAX) { + dev_err(adcx140->dev, "GPIO drive out of range\n"); + return -EINVAL; + } + + gpio_output_val = gpio_outputs[0] << ADCX140_GPIO_SHIFT + | gpio_outputs[1]; + + return regmap_write(adcx140->regmap, ADCX140_GPIO_CFG0, gpio_output_val); +} + static int adcx140_codec_probe(struct snd_soc_component *component) { struct adcx140_priv *adcx140 = snd_soc_component_get_drvdata(component); @@ -958,6 +994,10 @@ static int adcx140_codec_probe(struct snd_soc_component *component) return ret; } + ret = adcx140_configure_gpio(adcx140); + if (ret) + return ret; + ret = adcx140_configure_gpo(adcx140); if (ret) goto out; diff --git a/sound/soc/codecs/tlv320adcx140.h b/sound/soc/codecs/tlv320adcx140.h index 107bd7927d9c..d7d4e3a88b5c 100644 --- a/sound/soc/codecs/tlv320adcx140.h +++ b/sound/soc/codecs/tlv320adcx140.h @@ -148,4 +148,9 @@ #define ADCX140_TX_FILL BIT(0) +#define ADCX140_NUM_GPIO_CFGS 2 +#define ADCX140_GPIO_SHIFT 4 +#define ADCX140_GPIO_CFG_MAX 15 +#define ADCX140_GPIO_DRV_MAX 5 + #endif /* _TLV320ADCX140_ */ -- 2.20.1