Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2823428pxb; Mon, 17 Jan 2022 06:31:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0qkIX0uUCVUI0EGpvnvvxNaTvhuiEAYK9DMXodyltXWegW0Juq6LjHFKmtw+5XPqVGEZP X-Received: by 2002:a17:90a:9d81:: with SMTP id k1mr25060252pjp.129.1642429890966; Mon, 17 Jan 2022 06:31:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642429890; cv=none; d=google.com; s=arc-20160816; b=OGW7UxQQHon7xIvu1P7fyNv0qEiXsR3yT8NTEdyezEnhCqke6lnSrfEEHASUcdKLaP WD5BqCScVKA2QBKodG/gwl2m3p4AoXwyFWqzUI1/5tHFN2v2nVN+wSw3DqQTse9NzQgh 8t1/bovKIVzL15MjOZTlz+C5/chBtX2re6nS+0UV1wi9dWVpdsRgh9zkKmLvGahCeDwX MOlgmvEcBphEnM2V5uucodLTMTyX4NoUzFRTbpbKze2RysGs2HLre978ekr9VGDkVloQ VUcM/ZIOIc3LxpfjH/PbL3v9v0gzAL47z9dKc1VbPIDxpj4Km8YCmD/3s8ci5w2UNZWE U0bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=miI/KTSUJYn7JPetqRU0AB1f5MN5qyavg3LuiL7Shbo=; b=rm/FwCoJx5hEplZ6sxgxAWtfM5QM+ble2Hm630DOzJS1gDEPgL1XbUoRwUN+mveoLN EXpZu3p4tLI2u0tWrlOiRQwpMnfCEt36SI4TOxYO3dHWtulIV1sXHiJ2yDd+1aUqYt48 4kQb3WpY+n0da4He5CgWAUGl5HIwsjE6MoYH1SACBSl/2KyA68Ks373ow7L+ohBqZd4K FmSKPDCQvo/tnTctyvArzv7ji2P1Qvn2LCdwrdRwhPnd+ybFkjT/28e8ojSVQp6bpZJg 5EVZp+6AkAH3PwL4ctHNP3P4KXtkPalGFLyLVyeFtnqDkbFGLWJoY5Sbn9UJmBioQQtk mp+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="eJgC/w4t"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a128si13827768pfb.275.2022.01.17.06.31.13; Mon, 17 Jan 2022 06:31:30 -0800 (PST) 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 header.i=@gmail.com header.s=20210112 header.b="eJgC/w4t"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234619AbiAQGPd (ORCPT + 99 others); Mon, 17 Jan 2022 01:15:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234488AbiAQGPc (ORCPT ); Mon, 17 Jan 2022 01:15:32 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC44CC061574; Sun, 16 Jan 2022 22:15:31 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id c190so16941356qkg.9; Sun, 16 Jan 2022 22:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=miI/KTSUJYn7JPetqRU0AB1f5MN5qyavg3LuiL7Shbo=; b=eJgC/w4tZZIDx/VIS/oo7EKER6fTg2++v8jMnNLwXrYepPhpSfGzdOKQE0t1dO3smU 3TVeZWbQvadozW9FI2I/3eOLZhv73z7lmeod4a45ssJxwEvzY4wENIJOLXiFh4uGjIHK TM3AwlFaNdw4PS9wVGPPvGYvvEevf1m1JFvtJsaPkLJsSmy/i+ee/8g6PJ/oUDAO62Dk 8mzsT3NquVi1dwtxPZeiv1/ef09SpO6yDfK/qONFYGdLqhcwILwYjmBgdpzoh633ZMoa Vb6hH9MU35hsUr4fKA0M5uP03a3tnf2xVs+MQzqTqOb62BtnxY3s0nREbZNx5l36CVMc kSgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=miI/KTSUJYn7JPetqRU0AB1f5MN5qyavg3LuiL7Shbo=; b=GxK/cFcCzb25urJ/fVMajcxdcZU9qzwhSnobOVnLobvNdPXzuWtESkWPMI/pu7TTjV KG/xfY6CK0qiymRl5w4CLpWCH1mT4OzY5H1IpAUpDmOj7GBPr3Gz/K1vNR43tAK5qnmY /uX0qqD91DMj4fZmjwZvxL3fGS/wBzV3CH9y8EIEuzDZBP408vQO9RKoPdPm9Mw8UmhW cy6T8MJ3CKWmQG4EmjKokmmEX0pEfr8R1/pbwLarQCUWWhiRzv5uY9o5+6r0zTUigbaD +zb/2k7z7B/769rHw5xq8joKZhJoqgRQucUetg3c77OM0rsfz/WbUg4QP5UA3uj7dZGQ lIPw== X-Gm-Message-State: AOAM531nanSw5/a5BRUiXb2gzxT18Ir/YdBAabm0VpIY4u7OpuTtdTCn dgb/qdx8atUXo5QHW8SBKSh7X+7fQdpyhkvRgF8u+0wSjFo= X-Received: by 2002:a05:620a:470b:: with SMTP id bs11mr2825914qkb.210.1642400130779; Sun, 16 Jan 2022 22:15:30 -0800 (PST) MIME-Version: 1.0 References: <20220106125947.139523-1-gengcixi@gmail.com> <20220106125947.139523-4-gengcixi@gmail.com> In-Reply-To: From: Baolin Wang Date: Mon, 17 Jan 2022 14:16:10 +0800 Message-ID: Subject: Re: [PATCH 3/7] iio: adc: sc27xx: structure adjuststment and optimization To: Cixi Geng Cc: Orson Zhai , Chunyan Zhang , jic23@kernel.org, Lars-Peter Clausen , Rob Herring , lgirdwood@gmail.com, Mark Brown , =?UTF-8?B?5pyx546J5piOIChZdW1pbmcgWmh1LzExNDU3KQ==?= , linux-iio@vger.kernel.org, Devicetree List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 13, 2022 at 9:54 AM Cixi Geng wrote: > > Baolin Wang =E4=BA=8E2022=E5=B9=B41=E6=9C=887=E6= =97=A5=E5=91=A8=E4=BA=94 15:03=E5=86=99=E9=81=93=EF=BC=9A > > > > On Thu, Jan 6, 2022 at 9:00 PM Cixi Geng wrote: > > > > > > From: Cixi Geng > > > > > > Introduce one variant device data structure to be compatible > > > with SC2731 PMIC since it has different scale and ratio calculation > > > and so on. > > > > > > Signed-off-by: Yuming Zhu > > > Signed-off-by: Cixi Geng > > > --- > > > drivers/iio/adc/sc27xx_adc.c | 94 ++++++++++++++++++++++++++++++----= -- > > > 1 file changed, 79 insertions(+), 15 deletions(-) > > > > > > diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_ad= c.c > > > index aee076c8e2b1..d2712e54ee79 100644 > > > --- a/drivers/iio/adc/sc27xx_adc.c > > > +++ b/drivers/iio/adc/sc27xx_adc.c > > > @@ -12,9 +12,9 @@ > > > #include > > > > > > /* PMIC global registers definition */ > > > -#define SC27XX_MODULE_EN 0xc08 > > > +#define SC2731_MODULE_EN 0xc08 > > > #define SC27XX_MODULE_ADC_EN BIT(5) > > > -#define SC27XX_ARM_CLK_EN 0xc10 > > > +#define SC2731_ARM_CLK_EN 0xc10 > > > #define SC27XX_CLK_ADC_EN BIT(5) > > > #define SC27XX_CLK_ADC_CLK_EN BIT(6) > > > > > > @@ -78,6 +78,23 @@ struct sc27xx_adc_data { > > > int channel_scale[SC27XX_ADC_CHANNEL_MAX]; > > > u32 base; > > > int irq; > > > + const struct sc27xx_adc_variant_data *var_data; > > > +}; > > > + > > > +/* > > > + * Since different PMICs of SC27xx series can have different > > > + * address and ratio, we should save ratio config and base > > > + * in the device data structure. > > > + */ > > > +struct sc27xx_adc_variant_data { > > > + u32 module_en; > > > + u32 clk_en; > > > + u32 scale_shift; > > > + u32 scale_mask; > > > + const struct sc27xx_adc_linear_graph *bscale_cal; > > > + const struct sc27xx_adc_linear_graph *sscale_cal; > > > + void (*init_scale)(struct sc27xx_adc_data *data); > > > + int (*get_ratio)(int channel, int scale); > > > }; > > > > > > struct sc27xx_adc_linear_graph { > > > @@ -103,6 +120,16 @@ static struct sc27xx_adc_linear_graph small_scal= e_graph =3D { > > > 100, 341, > > > }; > > > > > > +static const struct sc27xx_adc_linear_graph sc2731_big_scale_graph_c= alib =3D { > > > + 4200, 850, > > > + 3600, 728, > > > +}; > > > + > > > +static const struct sc27xx_adc_linear_graph sc2731_small_scale_graph= _calib =3D { > > > + 1000, 838, > > > + 100, 84, > > > +}; > > > > The original big_scale_graph_calib and small_scale_graph_calib are for > > SC2731 PMIC, why add new structure definition for SC2731? > > > > > + > > > static const struct sc27xx_adc_linear_graph big_scale_graph_calib = =3D { > > > 4200, 856, > > > 3600, 733, > > > @@ -130,11 +157,11 @@ static int sc27xx_adc_scale_calibration(struct = sc27xx_adc_data *data, > > > size_t len; > > > > > > if (big_scale) { > > > - calib_graph =3D &big_scale_graph_calib; > > > + calib_graph =3D data->var_data->bscale_cal; > > > graph =3D &big_scale_graph; > > > cell_name =3D "big_scale_calib"; > > > } else { > > > - calib_graph =3D &small_scale_graph_calib; > > > + calib_graph =3D data->var_data->sscale_cal; > > > graph =3D &small_scale_graph; > > > cell_name =3D "small_scale_calib"; > > > } > > > @@ -160,7 +187,7 @@ static int sc27xx_adc_scale_calibration(struct sc= 27xx_adc_data *data, > > > return 0; > > > } > > > > > > -static int sc27xx_adc_get_ratio(int channel, int scale) > > > +static int sc2731_adc_get_ratio(int channel, int scale) > > > { > > > switch (channel) { > > > case 1: > > > @@ -185,6 +212,21 @@ static int sc27xx_adc_get_ratio(int channel, int= scale) > > > return SC27XX_VOLT_RATIO(1, 1); > > > } > > > > > > +/* > > > + * According to the datasheet set specific value on some channel. > > > + */ > > > +static void sc2731_adc_scale_init(struct sc27xx_adc_data *data) > > > +{ > > > + int i; > > > + > > > + for (i =3D 0; i < SC27XX_ADC_CHANNEL_MAX; i++) { > > > + if (i =3D=3D 5) > > > + data->channel_scale[i] =3D 1; > > > + else > > > + data->channel_scale[i] =3D 0; > > > + } > > > +} > > > > This is unnecessary I think, please see sc27xx_adc_write_raw() that > > can set the channel scale. > Did you mean that all the PMIC's scale_init function should put into > the sc27xx_adc_write_raw? No. > but the scale_init is all different by each PMIC, if implemented in > the write_raw, will add a lot of > if or switch_case branch What I mean is we should follow the original method to set the channel scale by iio_info. Please also refer to other drivers how ot handle the channel scale. --=20 Baolin Wang