Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3527674pxm; Mon, 28 Feb 2022 23:24:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhLCas8C97w/yYDe1kzkGsNaeooSOL6bhsHuszRLrY8MUCAy0mS8IDQ/R15ZcGZCl+rYEk X-Received: by 2002:a63:5d09:0:b0:372:9a55:bf89 with SMTP id r9-20020a635d09000000b003729a55bf89mr20565392pgb.321.1646119468272; Mon, 28 Feb 2022 23:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646119468; cv=none; d=google.com; s=arc-20160816; b=pId6/RatOu9MyGTyX48kt6vNkr8TKbNAfS+HP4jzQGP6rH/hpAhGv4hbTS8cQtqaKQ EDk9UhcEyvi6BnGNVtWlVs1ur0ZDrYasfeLikH/kNLr8XHE3fPPPOV2yOeIhWbqEnaBj XXNP7U1+1Su+v9L3MWk/Eze/pe0sDUShfly6YSfv25klx5/hyc9Zg+39UdKxScam5Cxk OGkg21GIe1FNTG2NdOG/yVN1e1xO9StHSiLzynKDJUsskaxpQ0zz8q68CrQWMhkro56J o02l1vSToUqtWJaukPAwtCPOlMOlo2Sa3YrqjUG1/t57VOvNiZ3yIXh5vJrhoD0n42lP Vatw== 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=pWn16AqiLrfX1zebjhB5rEinNun20KnuW9bQckIBJC8=; b=HwRNYsYVl/yoR0Fw5w2caN+cgAn+4k6smGY7w+1r8lKje/EDUek3Ig3ay6LFx9q6dH qx0cN8JdKt8Mbxd0RHaRGx1By3lQvsfkMCRN2ywrUoW9fpMJvL/h6qIM7uW5WTA/S2La 1249eYCDJjgvJWXAmbIBxfhz/ks8xpyz2y+vAj3d2lHvcY8fFXKvReKuTTylPl1Vbzoi 8EFunT9HGlzplrqxnhqLBITaYZR7ueyxvBK1PIaG9zMrGDKZVidujKP+MuaxvXLALFd9 GpOt7sP6IlGKpMXUP7f5AlSnxgSqUREOcnImoTbePRlxZLoW76pvHNfU3fRzygNrnU2E OXKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TgTuw2Ew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020a056a00125500b004e1b1ac5adasi11413281pfi.342.2022.02.28.23.24.13; Mon, 28 Feb 2022 23:24:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TgTuw2Ew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232285AbiCAG3O (ORCPT + 99 others); Tue, 1 Mar 2022 01:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232609AbiCAG3K (ORCPT ); Tue, 1 Mar 2022 01:29:10 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0CBC57B36; Mon, 28 Feb 2022 22:28:27 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so728559wmp.5; Mon, 28 Feb 2022 22:28:27 -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=pWn16AqiLrfX1zebjhB5rEinNun20KnuW9bQckIBJC8=; b=TgTuw2EwRUTqgMpH6oWu/LUo4Tj0DaFq2gazb8ukk2M3E5/N/ABnZq0JN+mM815Ir9 vcgeDnECaVsw5QKgVp2TQprmJ75xfE7Q6Z46b7RN/DNTKR7QWx+YdLObRbto2cx62b76 U2Eizso9FS2bTMBrKswDzRbpOry/gMiKnA0EbBCVm7muvxnd8HShq6B1E7K9lYPJcGA2 ufdDL0oUpRNchJdWw4xSxScgUuh60nKzX5uqHuna+MBM6k52Efm5kO3D+4Qs++AxWTY1 66sbxn9PxSVef8cZmyoJn7blrikHWzY2mf89TbTVevUvJahlgApgW6lbAfNhWvftwYEr GInQ== 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=pWn16AqiLrfX1zebjhB5rEinNun20KnuW9bQckIBJC8=; b=tXhUMKpCEIpLZkJbYWwJwl6w2BOxkmgt6FmzILtHoSXUR2BFtgWNoaepdTQJ1UtZQp 3yPfvxmTkEkLWz2r+MZpwdSLEZ6pJZzhmBDcjDjwYZzpFKEqaQk7YkBMarEErO8CM58s HF3Az6BXyaTG7Qu2ZdwPB9UWX5AJVu4dekQUrbDE7vCQXYIqatHQNnReUQ3jBWe2R7bB xbrHH045MW2OJEUPfpULX0Q0HdmWRupWTuCAxRPDB+IAz9ZsKTIA3i+Z2Q6KAwIZMiRv T/K6JN5NLno55x93AIefWQQKpmh7KyYzy/ezpjbsNL0BQHGFbkGKWJgDGT0kexe+7bD0 kSXQ== X-Gm-Message-State: AOAM532rdixdAL8dXyjMsOCjzgiFOP+r2L/G8nHWOnqid66v5FDyBV6M qqT312h0L83H+db4KH9a1zjpvWZ6VGdv6XD0E3g= X-Received: by 2002:a05:600c:42d6:b0:380:ed47:43e8 with SMTP id j22-20020a05600c42d600b00380ed4743e8mr15770755wme.61.1646116106338; Mon, 28 Feb 2022 22:28:26 -0800 (PST) MIME-Version: 1.0 References: <20220106125947.139523-1-gengcixi@gmail.com> <20220106125947.139523-4-gengcixi@gmail.com> <20220225101942.00002f43@Huawei.com> In-Reply-To: <20220225101942.00002f43@Huawei.com> From: Cixi Geng Date: Tue, 1 Mar 2022 14:27:50 +0800 Message-ID: Subject: Re: [PATCH 3/7] iio: adc: sc27xx: structure adjuststment and optimization To: Jonathan Cameron Cc: Baolin Wang , 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jonathan Cameron =E4=BA=8E2022=E5=B9=B42=E6= =9C=8825=E6=97=A5=E5=91=A8=E4=BA=94 18:19=E5=86=99=E9=81=93=EF=BC=9A > > On Wed, 23 Feb 2022 20:46:08 +0800 > Cixi Geng wrote: > > > Baolin Wang =E4=BA=8E2022=E5=B9=B42=E6=9C=8810= =E6=97=A5=E5=91=A8=E5=9B=9B 16:07=E5=86=99=E9=81=93=EF=BC=9A > > > > > > On Mon, Jan 24, 2022 at 4:07 PM Cixi Geng wrote: > > > > > > > > Baolin Wang =E4=BA=8E2022=E5=B9=B41=E6=9C= =8817=E6=97=A5=E5=91=A8=E4=B8=80 14:15=E5=86=99=E9=81=93=EF=BC=9A > > > > > > > > > > On Thu, Jan 13, 2022 at 9:54 AM Cixi Geng wr= ote: > > > > > > > > > > > > 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 compatibl= e > > > > > > > > with SC2731 PMIC since it has different scale and ratio cal= culation > > > > > > > > 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_adc.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 differe= nt > > > > > > > > + * 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_scale_graph =3D { > > > > > > > > 100, 341, > > > > > > > > }; > > > > > > > > > > > > > > > > +static const struct sc27xx_adc_linear_graph sc2731_big_sca= le_graph_calib =3D { > > > > > > > > + 4200, 850, > > > > > > > > + 3600, 728, > > > > > > > > +}; > > > > > > > > + > > > > > > > > +static const struct sc27xx_adc_linear_graph sc2731_small_s= cale_graph_calib =3D { > > > > > > > > + 1000, 838, > > > > > > > > + 100, 84, > > > > > > > > +}; > > > > > > > > > > > > > > The original big_scale_graph_calib and small_scale_graph_cali= b are for > > > > > > > SC2731 PMIC, why add new structure definition for SC2731? > > > > > > > > > > > > > > > + > > > > > > > > static const struct sc27xx_adc_linear_graph big_scale_grap= h_calib =3D { > > > > > > > > 4200, 856, > > > > > > > > 3600, 733, > > > > > > > > @@ -130,11 +157,11 @@ static int sc27xx_adc_scale_calibrati= on(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 sc27xx_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 ch= annel, int scale) > > > > > > > > return SC27XX_VOLT_RATIO(1, 1); > > > > > > > > } > > > > > > > > > > > > > > > > +/* > > > > > > > > + * According to the datasheet set specific value on some c= hannel. > > > > > > > > + */ > > > > > > > > +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 implemente= d 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 ch= annel > > > > > scale by iio_info. Please also refer to other drivers how ot hand= le > > > > > the channel scale. > > > > Hi Baolin, I understand the adc_write_raw() function is the method= to set > > > > channal scale for the userspace, we can change the channel scale by= write > > > > a value on a user code. did i understand right? > > > > out scale_init is to set scale value when the driver probe stage, = and I also > > > > did not found other adc driver use the adc_write_raw() during the d= river > > > > initialization phase. > > > > > > Hi Jonathan, > > > > > > How do you think about the method in this patch to set the channel > > > scale? Thanks. > > > > > Hi Jonathan, > > Could you have a loot at this patch ,and give some advice about the > > method to set the channel scale? Thanks very much. > > Hi, thanks for poking me on this - I'd missed the question buried deep in= the thread! > > Anyhow, I don't quite follow the discussion but think it could be focused > on one of 2 questions... > > 1) Does setting an initial default make sense? > Yes, this is an acceptable thing to do if there is a particular set of= defaults > and there is no risk of regressions (i.e. the device wasn't previously= supported > with different defaults). > 2) Should you use the write_raw callback to actually do the setting? > Probably not as it has a set of parameters that don't make as much sen= se from within > the driver. It 'might' make sense to have a common _set() function fo= r this > feature which is called both in this initialization case and from the = write_raw() > function however as that could do bounds checking etc in one common pl= ace. > However, it is very simple here, so perhaps not necessary. > > Jonathan > Hi Jonathan, thanks for your comment ! And Baolin, I will send a new verision for the patches tto keep the scale_init and fix other issues . thanks! > > > -- > > > Baolin Wang >