From patchwork Thu Jul 18 08:01:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhiyong.tao" X-Patchwork-Id: 11048639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8B90112C for ; Thu, 18 Jul 2019 08:02:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8C262878F for ; Thu, 18 Jul 2019 08:02:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC30E287CC; Thu, 18 Jul 2019 08:02:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 695E22878F for ; Thu, 18 Jul 2019 08:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QaVItr5YaonI8YNSehbSjIjnupB6Ew3rbQL3IJaC7+Y=; b=Yd3dlpX1xXmwZE t1gPVPlzgvGjjcLatuBpkiUwAKlbui++nvyyKePWVDjriGPPFrmWvN8cPSOReYezatCldG+iLNHep RsMQlwcUmwh4qrd4ijOL4syzAPZJssXSScAU4DIIEgEWfs50l+J/sbY+yqqOt/Yg5ViI/nGPzvkYs ebaDsoJKkmnywEbRjyzZkh1/zCwJl+Qy2y7Ibyc0HZkohGBoALbnZWvaHoyqqTIqvo03Js+PHdcNy ZYxrvl4xCSI1/hIYiBnl36vjcpK7RN7KNrw4/fRRuMOFRen5GfnpO2flOwEirbFrLzd9iRR8UH2pD XkdCtj8hkHdR/80TT0Uw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1ho1Mn-0001Q1-0N; Thu, 18 Jul 2019 08:02:17 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ho1M9-0000w4-Ii; Thu, 18 Jul 2019 08:01:39 +0000 X-UUID: 6e648b24c3dc44a7bec79d81d2c9053a-20190718 X-UUID: 6e648b24c3dc44a7bec79d81d2c9053a-20190718 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 2128258724; Thu, 18 Jul 2019 00:01:34 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 18 Jul 2019 01:01:33 -0700 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: , , , , 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 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190718_010137_617213_1448F33D X-CRM114-Status: GOOD ( 13.18 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, sean.wang@mediatek.com, srv_heupstream@mediatek.com, linux-iio@vger.kernel.org, Zhiyong Tao , erin.lo@mediatek.com, hui.liu@mediatek.com, linux-kernel@vger.kernel.org, sj.huang@mediatek.com, linux-mediatek@lists.infradead.org, eddie.huang@mediatek.com, matthias.bgg@gmail.com, yingjoe.chen@mediatek.com, jg_poxu@mediatek.com, s.hauer@pengutronix.de, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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: