Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1130458pxk; Fri, 18 Sep 2020 04:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ+sPBaWWJ41+/kR7LUJISnfOHXQ921yDYYCsfBhElIV1u2ncYNp2tto+lRJahgV5Lvpma X-Received: by 2002:a50:f102:: with SMTP id w2mr38846508edl.63.1600429458926; Fri, 18 Sep 2020 04:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600429458; cv=none; d=google.com; s=arc-20160816; b=JW3c3F/mWO+kN1LqeDn3/qrJuXz1n1tlPod57WK1xN3Ku1QZ2j0ezqUdJG3cYwcndz +ZnmQ2XuTzuMOogvTvRVX0psnN7bKB1/ljS/fFUQCFJHuZ7vTmT2oRelrcv9uaxC6eNF 21Esf12l+9C8rmqj/Ms7XTvg8YYUeCzMl/AnuRVEuI6VTJ67zrcxre09U6250SYzysNs xLPvixswH7QscBaAcW150/ym+R81pDQ8Z4auJR2CcC2A45zyJP7F8xyTljLugaG5SNnw gIJM5Cz4JYh/XlkMl3/1FR4GqjALcsTytwqDDb0mZOpnmiwiyqo9dM8YcJ8Th5QvWIpd vPhw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:dkim-signature; bh=ew//nIO5dKXvaZr2/EGqobhhCsQ55JTGE+weINnJVVs=; b=U9Gj6nGntHk266KFH28TFGXzTUt7naAIICagnmIARjVXOhwvyuOobkkga+k77Fsp5H bxnR5rPxO29RDl5gXqf+i5Lnac59qD9ZfDIsTNF4czju/WhGW82YqpE/cjHfTB5c+ptR UH9HBz3nlUEDxIQeNEPKlEdJR62JKgQTfeBAN6Mh0jgA5KXX8i5MomBQFRRJZU8bX4/f CdeotXtc4bGAmSHUFnVVWED7+PmTLnZ3Y7+XMcpKs6E6iTuajwdFi5CSWkBv2X86sNKr r6IQ5ox+4FsfGwZfqs3nfBRDeVBARQY1DgcW5ujlo/iq8uIFumMtjx3uEHzitbJgCs1c S2uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=m+b7uQrA; 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 u19si1937452ejx.710.2020.09.18.04.43.55; Fri, 18 Sep 2020 04:44:18 -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=m+b7uQrA; 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 S1726553AbgIRLkg (ORCPT + 99 others); Fri, 18 Sep 2020 07:40:36 -0400 Received: from smtp2.axis.com ([195.60.68.18]:42506 "EHLO smtp2.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgIRLkd (ORCPT ); Fri, 18 Sep 2020 07:40:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=2756; q=dns/txt; s=axis-central1; t=1600429232; x=1631965232; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ew//nIO5dKXvaZr2/EGqobhhCsQ55JTGE+weINnJVVs=; b=m+b7uQrAGCRyYAXI0QInatFVm23DnQ5FEerqFr74ZBNiqpuIkZXNIcQ3 dPBezFWPkQw4dt4N+G3LvI8ZVEVRcsGSkfiJLZhZWYoN2DITlO0o7XUcB UML06SiUnBJXsP2j6QjRbQ/rPuWwIlYQm8lpex9SpvMKEa+rubco2fT3y IgNQxv3k+tADcAwSNGgGBnBpbkJzCcoo0mx3t8SD+QuIVtX0Oxz849lq9 AfVdZ/SKYl4BBr074uNUY9jcwpx/AgHEgz3sCaBJZvu1FdoJ61MGU9uB3 4VishjxzwvnbegzTpbdatMpUXl6UC1Npb+Qv5xDBXj99UMtW9QTvhdtCx Q==; IronPort-SDR: DKC8VO5L1SMacHypEV5JHzAI747iaewCGeQgHSpCHCveVnZOS/TzSoR4GEWOZVWPkTKXVU1aSm Y4uwYAocMzwzDhLcUZOBifmWda1/ttxrtZDLB2Clm8PzVztFAPeY4ahX4EqOaWPUrqUapk+U0q Mv4zE7BZF6lxLd3SbREJvC8r0KzysFZfKSwM9RyU+GU615LnrArMje3VZQ7UWU6jMo2JE0l/WO EfWoE46wX/B7VW5LIMCE1ukk0o8fohIW82hYgBQLkfW9aQRmNjaC+e0aN3dM4bEbx+QjnWsVDt jl4= X-IronPort-AV: E=Sophos;i="5.77,274,1596492000"; d="scan'208";a="12637620" From: Camel Guo To: , , , , CC: , , , , Camel Guo Subject: [PATCH v5 2/2] ASoC: tlv320adcx140: Add support for configuring GPIO pin Date: Fri, 18 Sep 2020 13:40:25 +0200 Message-ID: <20200918114025.18205-2-camel.guo@axis.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200918114025.18205-1-camel.guo@axis.com> References: <20200918114025.18205-1-camel.guo@axis.com> 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 --- 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