Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1959171ybi; Thu, 18 Jul 2019 01:03:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyuo3/sR/ylgXfWvN4ONoZssk0A0Ntrs13HORIG6DkJ3r9BFzaqdKYqcdICpBSJM8Tt8E/a X-Received: by 2002:a17:90a:2305:: with SMTP id f5mr52069404pje.128.1563437036837; Thu, 18 Jul 2019 01:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563437036; cv=none; d=google.com; s=arc-20160816; b=AINJp+k0xrozyYkd8spLZ3WDN1bX/Tuvf+FfqnN0gTm4VpPZg1m1n6axGqoIS5Z8Nu p6fREcsQ1eB7s4dyLZQCWxD8+EgAyqhDndwiUh7xsl2/PuDTT9+OVJFmUwEjoXoGIzKf SPdncoj6mwYWSau0jQcdTOCIT4Jz0+sNakNGrVyNCm+OgYA7CvUDt+tzVRA85u0BaKf9 hRdsZfrQ6NWICje1ag1ABDyNRXCu6p8lnzSyRxp2wuN9Ba7UnHmO27jiZlZ7AquhYUnQ jTg9LctIO7eGCKabKy4q+HVW8senYD4ORCRmxUo0QYC6jo3DQsBUK9V7L7mlhq/RwWBW nmNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=MNicDhtBJZ9MjPpbWEexFedfrHlLctibe68rhFZUd5M=; b=yOSdOjgzWoG+PGmhnZVXCS/92DeitFFI4u8v0Co8vsnfKt72BSbjJQztm0X/MiUBhk NDhf/62pnheAOB9gZ4GGIUH+xYUqjBDH6jGtQag2IUj3LnfOu2veVwtl72aFI5VRGxxB zoV3noAYvWXJoKEI5EEHp9bPbJG68w8XbPB29d+xqbLfxRJdUVjHh8NCHEDJjaOBbrmS uvtvLCUER5cWDumstUUUtE0ZXSiACH1Udlyf4B8yRXpmclQbA2W0mfPo+Wnq5n9crE39 JZlp9pqJLoupcYuXca8Km79zOWoC36f3abkyQ2CEQ5W0TLMF3I/Hhj/wmp7f5dbvsxCO iM3w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17si1422127plo.46.2019.07.18.01.03.40; Thu, 18 Jul 2019 01:03:56 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389425AbfGRIBh (ORCPT + 99 others); Thu, 18 Jul 2019 04:01:37 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:40751 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2389321AbfGRIBf (ORCPT ); Thu, 18 Jul 2019 04:01:35 -0400 X-UUID: 4512913e817a4a958b64f5ef79152754-20190718 X-UUID: 4512913e817a4a958b64f5ef79152754-20190718 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 556583377; Thu, 18 Jul 2019 16:01:27 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 18 Jul 2019 16:01:26 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 18 Jul 2019 16:01:25 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , , , , , Zhiyong Tao Subject: [PATCH v1 2/2] auxadc: mediatek: support efuse calibration in auxadc driver Date: Thu, 18 Jul 2019 16:01:19 +0800 Message-ID: <20190718080119.30707-3-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.12.5 In-Reply-To: <20190718080119.30707-1-zhiyong.tao@mediatek.com> References: <20190718080119.30707-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch support efuse calibration in auxadc driver Signed-off-by: Zhiyong Tao Signed-off-by: jg_poxu --- drivers/iio/adc/mt6577_auxadc.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c index 95d76abb64ec..e30d9736b1a5 100644 --- a/drivers/iio/adc/mt6577_auxadc.c +++ b/drivers/iio/adc/mt6577_auxadc.c @@ -17,12 +17,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include /* Register definitions */ #define MT6577_AUXADC_CON0 0x00 @@ -42,6 +44,13 @@ #define MT6577_AUXADC_POWER_READY_MS 1 #define MT6577_AUXADC_SAMPLE_READY_US 25 +#define ADC_GE_A_SHIFT 10 +#define ADC_GE_A_MASK (0x3ff << ADC_GE_A_SHIFT) +#define ADC_OE_A_SHIFT 0 +#define ADC_OE_A_MASK (0x3ff << ADC_OE_A_SHIFT) +#define ADC_CALI_EN_A_SHIFT 20 +#define ADC_CALI_EN_A_MASK (0x1 << ADC_CALI_EN_A_SHIFT) + struct mt6577_auxadc_device { void __iomem *reg_base; struct clk *adc_clk; @@ -74,6 +83,64 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = { MT6577_AUXADC_CHANNEL(15), }; +s32 cali_oe; +s32 cali_ge; +struct adc_cali_info { + u32 cali_ge_a; + u32 cali_oe_a; + u32 gain; +}; +static struct adc_cali_info adc_cali; + +static int mt6577_auxadc_update_cali(struct device *dev) +{ + struct nvmem_cell *cell; + u32 *buf; + size_t len; + int ret = 0; + + cali_oe = 0; + cali_ge = 0; + + cell = nvmem_cell_get(dev, "calibration-data"); + if (IS_ERR(cell)) { + if (PTR_ERR(cell) == -EPROBE_DEFER) + return PTR_ERR(cell); + return 0; + } + + buf = (u32 *)nvmem_cell_read(cell, &len); + + nvmem_cell_put(cell); + + if (IS_ERR(buf)) + return PTR_ERR(buf); + + if (len < sizeof(u32)) { + dev_warn(dev, "invalid calibration data\n"); + ret = -EINVAL; + goto out; + } + + if (((buf[0] & ADC_CALI_EN_A_MASK) >> ADC_CALI_EN_A_SHIFT) != 0) { + adc_cali.cali_oe_a = + (buf[0] & ADC_OE_A_MASK) >> ADC_OE_A_SHIFT; + adc_cali.cali_ge_a = + ((buf[0] & ADC_GE_A_MASK) >> ADC_GE_A_SHIFT); + + cali_ge = adc_cali.cali_ge_a - 512; + cali_oe = adc_cali.cali_oe_a - 512; + adc_cali.gain = 1 + cali_ge; + } else { + dev_info(dev, "Device not calibrated, using default calibration values\n"); + } + +out: + kfree(buf); + + return ret; +} + static inline void mt6577_auxadc_mod_reg(void __iomem *reg, u32 or_mask, u32 and_mask) { @@ -274,6 +341,10 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) goto err_power_off; } + ret = mt6577_auxadc_update_cali(&pdev->dev); + if (ret) + return ret; + return 0; err_power_off: -- 2.12.5