Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3748356imm; Sat, 25 Aug 2018 01:47:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbLAw4YTWl+tdeO5moAd2cQAqD2nfvm9AcE/VA6nKulOxuLAFxnaMc+ZS1PaYh/cqzql7if X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr4948598plq.337.1535186839748; Sat, 25 Aug 2018 01:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535186839; cv=none; d=google.com; s=arc-20160816; b=1Hz++xs/hyS4l71pOWK/OzbADRr8G82TTopsze0fjIrusWuTdesmLD4l4h0eJL/sOV cbdcPHK4paZoeEUz7ByRyVHvDfNW7EA8p3iAZVoaqq9a0qTxjGImca83DdYZ/0iNKquN Y6XPbvTYmOvBk9c4Ry5KoYCHEalULYEOB+E2F+MupGWC3RwlRJTSK9tB2BQ+4fyjkthC mfCWYfISxchD/T6ryCoH5akUIzEr4iQQLctm5XDdVHGg44WS+StF+ru6Vq419PXol7sW 3uMBQuxveHmoeirXCTpyriLncV24jQWKP7AGCkUqcjlMj0g0CMat/KZtN++AH76WVKU+ 3Jqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=D/EVfCwN66RlldiK0cNJm7k2ZMT1zDBHlsIre+1yjFY=; b=wPZDmu1YXVzdfkGkWjdNiRuBtt27un2l9yckTauyUe4370E0miDJCpp5VzvG7BzhZE 74uCIx0t0137HOniCJyL1SyFQsaXWlSQh1mc6uDP+so+5QR3VU/iYtoD8hjf4rh+XoSG AlMNzfC4Dn9t9+S4llljvuQ4oBoDSn5A+F3S2pIeSDA0PSoc2zprsicJDMEWimTbYWrM DHgM8iGHCl0EgfNehJUOPB0fVKwFwmXCJBWtDptXUKOKV57Dd216i1SndlP9+m00jaga 0CFxW6jznOAxKwrIuMD8kEOl2IWVEZsOPRvrxGFH19ufivylQYvQq/nUWtgmtrwk0UF2 xuCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=18dI5END; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r30-v6si5154800pgk.87.2018.08.25.01.46.41; Sat, 25 Aug 2018 01:47:19 -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=@kernel.org header.s=default header.b=18dI5END; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726686AbeHYMWT (ORCPT + 99 others); Sat, 25 Aug 2018 08:22:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:35812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbeHYMWT (ORCPT ); Sat, 25 Aug 2018 08:22:19 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB0A621477; Sat, 25 Aug 2018 08:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535186642; bh=F7eB4YPsis3op95iT1DD5/mWTi2mcKAKYMzRRUMeLSg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=18dI5END0cjQDKLfgsV9YXoZ41T7IOQeqSUGOdAw7TOO7jiezuIUvZbhxtzzCmM68 ofyRoIrAiT2pjXIBYAoCWhJnRm4Sb0Vvnjh6BMqP1Ws+k4AdenQl1TNh/oALrfA6j5 y6tDUzj4rCH3b1MWNRusCkqjiueA2PSfYe8FwuOY= Date: Sat, 25 Aug 2018 09:43:57 +0100 From: Jonathan Cameron To: Baolin Wang Cc: robh+dt@kernel.org, mark.rutland@arm.com, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, freeman.liu@spreadtrum.com, broonie@kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] iio: adc: sc27xx: Add ADC scale calibration Message-ID: <20180825094357.6425ab4a@archlinux> In-Reply-To: References: <4a7e33457617e6f0f7c9627fe20ddd3039e4fe82.1535103920.git.baolin.wang@linaro.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Aug 2018 17:53:16 +0800 Baolin Wang wrote: > This patch adds support to read calibration values from the eFuse > controller to calibrate the ADC channel scales, which can make ADC > sample data more accurate. > > Signed-off-by: Baolin Wang This looks good to me. I'll leave it for now though given open questions on patch 1 and to allow others time to comment on this if they wish - particularly as it includes a binding addition. Jonathan > --- > .../bindings/iio/adc/sprd,sc27xx-adc.txt | 4 ++ > drivers/iio/adc/sc27xx_adc.c | 52 ++++++++++++++++++-- > 2 files changed, 53 insertions(+), 3 deletions(-) > > diff --git a/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt b/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt > index 8aad960..b4daa15 100644 > --- a/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt > +++ b/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt > @@ -12,6 +12,8 @@ Required properties: > - interrupts: The interrupt number for the ADC device. > - #io-channel-cells: Number of cells in an IIO specifier. > - hwlocks: Reference to a phandle of a hwlock provider node. > +- nvmem-cells: A phandle to the calibration cells provided by eFuse device. > +- nvmem-cell-names: Should be "big_scale_calib", "small_scale_calib". > > Example: > > @@ -32,5 +34,7 @@ Example: > interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; > #io-channel-cells = <1>; > hwlocks = <&hwlock 4>; > + nvmem-cells = <&adc_big_scale>, <&adc_small_scale>; > + nvmem-cell-names = "big_scale_calib", "small_scale_calib"; > }; > }; > diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c > index 153c311..7ac78eda 100644 > --- a/drivers/iio/adc/sc27xx_adc.c > +++ b/drivers/iio/adc/sc27xx_adc.c > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -87,16 +88,48 @@ struct sc27xx_adc_linear_graph { > * should use the small-scale graph, and if more than 1.2v, we should use the > * big-scale graph. > */ > -static const struct sc27xx_adc_linear_graph big_scale_graph = { > +static struct sc27xx_adc_linear_graph big_scale_graph = { > 4200, 3310, > 3600, 2832, > }; > > -static const struct sc27xx_adc_linear_graph small_scale_graph = { > +static struct sc27xx_adc_linear_graph small_scale_graph = { > 1000, 3413, > 100, 341, > }; > > +static const struct sc27xx_adc_linear_graph big_scale_graph_calib = { > + 4200, 856, > + 3600, 733, > +}; > + > +static const struct sc27xx_adc_linear_graph small_scale_graph_calib = { > + 1000, 833, > + 100, 80, > +}; > + > +static int sc27xx_adc_get_calib_data(u32 calib_data, int calib_adc) > +{ > + return ((calib_data & 0xff) + calib_adc - 128) * 4; > +} > + > +static void > +sc27xx_adc_scale_calibration(const struct sc27xx_adc_linear_graph *calib_graph, > + u32 calib_data, bool big_scale) > +{ > + struct sc27xx_adc_linear_graph *graph; > + > + if (big_scale) > + graph = &big_scale_graph; > + else > + graph = &small_scale_graph; > + > + /* Only need to calibrate the adc values in the linear graph. */ > + graph->adc0 = sc27xx_adc_get_calib_data(calib_data, calib_graph->adc0); > + graph->adc1 = sc27xx_adc_get_calib_data(calib_data >> 8, > + calib_graph->adc1); > +} > + > static int sc27xx_adc_get_ratio(int channel, int scale) > { > switch (channel) { > @@ -209,7 +242,7 @@ static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, > *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK; > } > > -static int sc27xx_adc_to_volt(const struct sc27xx_adc_linear_graph *graph, > +static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph, > int raw_adc) > { > int tmp; > @@ -371,6 +404,7 @@ static int sc27xx_adc_write_raw(struct iio_dev *indio_dev, > > static int sc27xx_adc_enable(struct sc27xx_adc_data *data) > { > + u32 val; > int ret; > > ret = regmap_update_bits(data->regmap, SC27XX_MODULE_EN, > @@ -390,6 +424,18 @@ static int sc27xx_adc_enable(struct sc27xx_adc_data *data) > if (ret) > goto disable_clk; > > + /* ADC channel scales' calibration from nvmem device */ > + ret = nvmem_cell_read_u32(data->dev, "big_scale_calib", &val); > + if (ret) > + goto disable_clk; > + > + sc27xx_adc_scale_calibration(&big_scale_graph_calib, val, true); > + > + ret = nvmem_cell_read_u32(data->dev, "small_scale_calib", &val); > + if (ret) > + goto disable_clk; > + > + sc27xx_adc_scale_calibration(&small_scale_graph_calib, val, false); > return 0; > > disable_clk: