Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5048865ybi; Sat, 20 Jul 2019 11:44:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGUK9BtMZB8q7tYEBoHrlf4Q/tx+F25su3eUGW9y+SlF18fLOxQfNIFGVIIdHQhSAoAOYK X-Received: by 2002:a17:902:4501:: with SMTP id m1mr64748317pld.111.1563648269859; Sat, 20 Jul 2019 11:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563648269; cv=none; d=google.com; s=arc-20160816; b=mL4AGkgEcwZ8Cw9V7SekzhQaUgybqvtx1OaqwVZ3O62QkmcfcNuCzoiF2PwrC0FNhZ h9nKxyFbuZvCGSB07ptIeGSkO+ozYRTcRfqBpbJyonGRAkhB1NP5e1/xll9VL3lfmsJv nLpPyzxGc3jjfdeUbweH5OC1A0GS1WSiQq3fYxYoq7XqQGWYwWHrlQXDjuAq878RYPIp 4i7a9mmoXa4VT/2fSuBPuftrHLw15husewxSWJXuGwPmzoRHj4CNauaGh5/3D2l/huOG GiUa/aChJMsSRRx1osu3bHNSd7iFVIvlD2SxIK/cwpHzqxb2lwKoUeXQKz+7gIvciGGv b7bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rjy01hz76qJsGBlj89nPeHsxAVMf/NWX8i7ANc3NyP4=; b=ZNGFpiIsY2PssN4hWC2HG4vhdjGjsyU/pr0pEwVpk30SVRmBrbPA4C7pf5BsqtDsLi ZgAPb8hpBcQBMvs3x9P+7Stu5XPpG9wzsMhxEmv01cvkW8Y21W/R6kePYl0JGQrNcpxk 0nahzbfFK2F9LMzKIzRfaYi+f6TwtF5Ne1sl9MaQuUjjdnyzKLRv5jVVthpRJveUcP9V 6ScZYeLc5cvyQ7dBtLtm89xS1/SZNtg2YKH1I+24Ewer4jtrOdEfYlIY5ItY7BbF49hY 3mltNkkg1VKnOm86OlK1QWEUwxcJTLz1OKsoa1ssg5y5enZVWTdDjJMQyRhwnUPVRAJI CJKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I+ScoAv8; 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 v10si3946958pgq.17.2019.07.20.11.44.14; Sat, 20 Jul 2019 11:44:29 -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=I+ScoAv8; 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 S1728587AbfGTOOF (ORCPT + 99 others); Sat, 20 Jul 2019 10:14:05 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:40589 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728488AbfGTOOE (ORCPT ); Sat, 20 Jul 2019 10:14:04 -0400 Received: by mail-qk1-f196.google.com with SMTP id s145so25430353qke.7 for ; Sat, 20 Jul 2019 07:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rjy01hz76qJsGBlj89nPeHsxAVMf/NWX8i7ANc3NyP4=; b=I+ScoAv8q6Te/9p4Qm1WL3NsGcfq1HXumf4DYD5boY31ZFYqRutFNJ1S92hcXfaKdW ySGkDcfSmbEzvu3bCYyoyAniE54YCEDSk197kKGmTg4uC1O/yTTF/2skSaI2wwX6wvoy /UYRUWxI/jlJK8siKJrmwj689HohB+ApkpM7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rjy01hz76qJsGBlj89nPeHsxAVMf/NWX8i7ANc3NyP4=; b=DrZwZb69UkwSiOFxWBxBKng2rZUObReJs8aBYINaZvL/0gxMhuv7I7+FcJjn6L5TEH /WfiJ1z8bK5TiNKa8t58LZmJyCU8g59uC0pMOoaOW+infiD0+KTu2ZIqDcQyOMiOMwqb aBVDQdAuRtPPOytob1FvdC4jlpUGLnOjTfrq39BPTBdiUZWz7wgFn0/u7PjSSVk9fUAk iBMHJv/r00rYc5zlMoVEK8s4Yt8YXhnokkIwVArCLZO/xu/eEmi4whEiI5/XoWnqvUX+ TeWSGdO8YEqtjUWZfkneSMc3C7us3oVgeJwId5JnBu6Q4YEVAkEWoxeU21dWajYZyF3D apHg== X-Gm-Message-State: APjAAAVgCtHCq3cChahC9ZzBhNWqhU+qFKMzIyk7JN8rL7slEIoo8vvA c3eHO2rxbHrFHvjvrKqotsoliICoSr81fkDEKThjAA== X-Received: by 2002:ae9:f017:: with SMTP id l23mr39448045qkg.457.1563632043392; Sat, 20 Jul 2019 07:14:03 -0700 (PDT) MIME-Version: 1.0 References: <20190718080119.30707-1-zhiyong.tao@mediatek.com> <20190718080119.30707-3-zhiyong.tao@mediatek.com> In-Reply-To: <20190718080119.30707-3-zhiyong.tao@mediatek.com> From: Nicolas Boichat Date: Sat, 20 Jul 2019 22:13:51 +0800 Message-ID: Subject: Re: [PATCH v1 2/2] auxadc: mediatek: support efuse calibration in auxadc driver To: Zhiyong Tao Cc: Rob Herring , jic23@kernel.org, knaack.h@gmx.de, Lars-Peter Clausen , pmeerw@pmeerw.net, srv_heupstream , hui.liu@mediatek.com, jg_poxu@mediatek.com, sj.huang@mediatek.com, Yingjoe Chen , Sean Wang , Erin Lo , Eddie Huang , Matthias Brugger , Sascha Hauer , devicetree@vger.kernel.org, lkml , linux-arm Mailing List , linux-iio@vger.kernel.org, "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 18, 2019 at 4:01 PM Zhiyong Tao wrote: > > 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; Why do you need these 2 (global) variables? They are set in mt6577_auxadc_update_cali but never read anywhere. > +struct adc_cali_info { > + u32 cali_ge_a; > + u32 cali_oe_a; > + u32 gain; > +}; > +static struct adc_cali_info adc_cali; This should be inside struct mt6577_auxadc_device structure. And... I still do not understand what this does, since nothing reads back adc_cali either... On gerrit (https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1624410), you mentioned that thermal module will use these, can you please upload these changes as part of this series, so that we can review the whole thing in one piece (and understand better how to fix this interface). > + > +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); Cast is not necessary. > + > + 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; Or just return mt6577_auxadc_update_cali(&pdev->dev); > > err_power_off: > -- > 2.12.5 >