Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1094876pxm; Wed, 23 Feb 2022 18:01:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz95Mg506HOgN8iMf+LFzPQ7slcZf46PF0zq77dW5clOdedz1OrHPOZGK2lcWx84g9vb1i1 X-Received: by 2002:a17:90b:19d4:b0:1bc:3489:73b9 with SMTP id nm20-20020a17090b19d400b001bc348973b9mr446355pjb.175.1645668065156; Wed, 23 Feb 2022 18:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645668065; cv=none; d=google.com; s=arc-20160816; b=WrRNy++2tkZ+r09Zc+9MZtHbvTRdIWqUhlW/iTv8crEQ3iwmptGbEZL54h8MmU5TAu wwJ6z33o9Il2YF3QtzQcb8bOb+aXyZZB4o2+LGwNEgESgGrpcOZfAS4NxBmlCIfOakY9 sj1yiwNi761YOPy0KEHiZXKhnCQl06I/Lfr79wTc2cuQTcePIjkQSnCPwOnD9bzFvX7m YkacrxkPMhCuYLj4xDPL/5z/CZHtg1HxrBnp/uo8+a+fuH3Yhug/NtQJRk1ZDy66smLa 6uKrrhHDU5M3uDHtI8V6eyJCEsTlSL5wMq0zAJtg82eXnmlkAIf0hfmWdscS+PEGidkA Cc3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=i55z3pOW9V6Bu0WaroA/XOCY0+AorvQDiheA/c25Gxg=; b=k24qB/eBkgkfyRF3kTU8CKEyOuIIicIW3W+ivQKQ9wBTb2mAxofh9MJeA6h/mNGf17 N2OWe5NJddp/gUcWcgyS8dODA5TQDdL57glyYGQpWUdRXObEviBqAueJcKmGUGejpfny i/E8Hj6yyMulr4iNVr3D6WeX+qzix5I1TcTklwMQ5+SvpkVXJGUA7eL+O+tVbK12SkbE 0PLosi/qb7xcOputru/cyLJOmsKla2yi6GAVWk+9R5PP/z40Hai3CIIj0ux1cf9K1I/i keM/QR5CMogw9MzbeDHkR+fHPCeG73S6917RSk41W5CgcxMjs6dToP+88PVycvItAf1p 8z7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lrreJxet; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id rm12si1149602pjb.48.2022.02.23.18.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 18:01:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lrreJxet; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13E19251E47; Wed, 23 Feb 2022 17:29:27 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbiBXAu0 (ORCPT + 99 others); Wed, 23 Feb 2022 19:50:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbiBXAuX (ORCPT ); Wed, 23 Feb 2022 19:50:23 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37058F210E; Wed, 23 Feb 2022 16:49:44 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id vz16so1055619ejb.0; Wed, 23 Feb 2022 16:49:44 -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; bh=i55z3pOW9V6Bu0WaroA/XOCY0+AorvQDiheA/c25Gxg=; b=lrreJxet9kc+GEpo9F4jktMaOeiwvvyc45FRfBb6zIssQ3F1Vj2LsRMKKQe8swMOEa GVYUey1uv+8KueY6TfbLzKto9r5KJNeMuhquzFjFwf/a9fmHcHfm4NMRHiPY9lhs/vIT 85sp2CHhRl7GpPdG1M1NQhETMlkQT8kRjmp2BcvEl8yk8J3kOf2xroi+PL1XStKlay60 Yo6gqYw7aS2arvLnPWMMXpg0FqhEv/QPX+R+03cKQW5+JnW4qE3m9T4YUmV+4QQfo+0N rAioGSEt1UHy85mdTRZ2Zconj4Cm6B9qkn58o5NZrUeFER6rsyL7ohGFR2HdTcBAGshp sjbg== 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; bh=i55z3pOW9V6Bu0WaroA/XOCY0+AorvQDiheA/c25Gxg=; b=lQyedV9+HC707kPQZU0iws8dMZ3tZLA3XyPILJBosGX9pdT0SBZq0OvhWKQj0V5F3T OX+m8wPQvH0Bu7DSLeRMUhWmr3+D7crwXV8NKIOlQmLfKMSklYRL8kV1SJ2juzM5jadl 7DTZQOrZLqZDZt4b/kavCiZJRG4sTglEYJhU51EnV9lvfb41cW2K4OENRO4rPuMzv0L3 XG39yx0p//hj9kkMzB8Rx7wEWSgYv/03Y8iH490sHa9dPSCh+ZGWRqsYLcz+m3UAMOUV CFu2QxCGSik4ihtIUOAxNJEH1VMGQvbo+b9wRgX0QxvGfTod3g40tbZLmCJhMxb0bzYO C3Cw== X-Gm-Message-State: AOAM532FOU5Gm033BbL0xKXGS8dIcIK8HcVmob47J6/kvnWpjIzg/R0g b2Pg2kbKgbn74S5XoejHu0z3cCA+n66g3ATCDUc= X-Received: by 2002:a17:906:5950:b0:6b3:65b7:82d3 with SMTP id g16-20020a170906595000b006b365b782d3mr225501ejr.636.1645663677923; Wed, 23 Feb 2022 16:47:57 -0800 (PST) MIME-Version: 1.0 References: <20220223163525.13399-1-jagathjog1996@gmail.com> <20220223163525.13399-6-jagathjog1996@gmail.com> In-Reply-To: <20220223163525.13399-6-jagathjog1996@gmail.com> From: Andy Shevchenko Date: Thu, 24 Feb 2022 02:46:34 +0200 Message-ID: Subject: Re: [PATCH v5 5/7] iio: potentiometer: Add device specific read_raw function To: Jagath Jog J Cc: Jonathan Cameron , Lars-Peter Clausen , Slawomir Stepien , Rob Herring , linux-iio , devicetree , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, Feb 23, 2022 at 6:35 PM Jagath Jog J wrote: > > Added function pointer in the device specific structure to > call the appropriate device read_raw function, so that the > other type of devices with different read method can be > handled. > > Signed-off-by: Jagath Jog J > --- > drivers/iio/potentiometer/ds1803.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c > index aeb74ee46fbc..878188351f8f 100644 > --- a/drivers/iio/potentiometer/ds1803.c > +++ b/drivers/iio/potentiometer/ds1803.c > @@ -32,6 +32,8 @@ struct ds1803_cfg { > int kohms; > const struct iio_chan_spec *channels; > u8 num_channels; > + int (*read)(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, int *val); > }; > > struct ds1803_data { > @@ -55,6 +57,22 @@ static const struct iio_chan_spec ds1803_channels[] = { > DS1803_CHANNEL(1, DS1803_WIPER_1), > }; > > +static int ds1803_read(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val) > +{ > + struct ds1803_data *data = iio_priv(indio_dev); > + int ret; > + u8 result[ARRAY_SIZE(ds1803_channels)]; > + > + ret = i2c_master_recv(data->client, result, indio_dev->num_channels); > + if (ret < 0) > + return ret; > + > + *val = result[chan->channel]; > + return ret; > +} > + > static const struct ds1803_cfg ds1803_cfg[] = { > [DS1803_010] = { > .wipers = 2, > @@ -62,6 +80,7 @@ static const struct ds1803_cfg ds1803_cfg[] = { > .kohms = 10, > .channels = ds1803_channels, > .num_channels = ARRAY_SIZE(ds1803_channels), > + .read = ds1803_read, > }, > [DS1803_050] = { > .wipers = 2, > @@ -69,6 +88,7 @@ static const struct ds1803_cfg ds1803_cfg[] = { > .kohms = 50, > .channels = ds1803_channels, > .num_channels = ARRAY_SIZE(ds1803_channels), > + .read = ds1803_read, > }, > [DS1803_100] = { > .wipers = 2, > @@ -76,6 +96,7 @@ static const struct ds1803_cfg ds1803_cfg[] = { > .kohms = 100, > .channels = ds1803_channels, > .num_channels = ARRAY_SIZE(ds1803_channels), > + .read = ds1803_read, > }, > }; > > @@ -84,20 +105,15 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, > int *val, int *val2, long mask) > { > struct ds1803_data *data = iio_priv(indio_dev); > - int pot = chan->channel; > int ret; > - u8 result[ARRAY_SIZE(ds1803_channels)]; > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - ret = i2c_master_recv(data->client, result, > - indio_dev->num_channels); > + ret = data->cfg->read(indio_dev, chan, val); > if (ret < 0) > return ret; > > - *val = result[pot]; > return IIO_VAL_INT; > - Seems like a stray change. Up to Jonathan to decide what to do (no need for resend b/c of this). > case IIO_CHAN_INFO_SCALE: > *val = 1000 * data->cfg->kohms; > *val2 = data->cfg->avail[2]; /* Max wiper position */ > -- > 2.17.1 > -- With Best Regards, Andy Shevchenko