Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1955737ybm; Sun, 31 May 2020 04:03:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDNV4LrSyE/VSYJZjGlqlv9yGci2+A+nN35RzNvo/mMMZ8nKmJT6km2mVfYtJWjBVakyEx X-Received: by 2002:a50:f7c4:: with SMTP id i4mr16836282edn.306.1590923005459; Sun, 31 May 2020 04:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590923005; cv=none; d=google.com; s=arc-20160816; b=ZFkJJSnZLmJ+/oTf2ehC+HzaW6GPenAtoQauPNdxaneP5meK7Pc0WuDBPP6t0fL/vJ CIAtoBeiXxsKD59Gk/chnq7CB5kkqj8/TAhxbvru46WkGPHgUaW1vmxtT44gZMesDTXj Y28AioZFwGV4z9IcNwPJm0GXuv29u3bqSXwkEIsorPbLMZmnylal4RlsBVEmBckeAcgR Rq3xT3f6X5w5Bj42BA2A9MRNwO/Ghuw4vnVnFjsh8pPpXjdJ3JfOuKquFZKZkz7q9vK4 ziNRhnt2BruqwFCrJhOUickYL8ajH7U/RT53+7nfbBJusolwuIbRq3P7DKGk0rBMUlNL CtYQ== 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; bh=dJcoE5q60lD2qnnlGeRgThHXLVHdSAuVI5FfJHxcllw=; b=Zyz89xHvazkTSraPD1kgYx4lYSCWt6/Q6DbNuqSIckh25TtmFL6EgAtvb1ZkoKj7jz oxcEGDMbTF3da8yAyrX/T3jd0AOZyGktTfVR5cwWlhC9qXeLrlcx2B9tNX8AQu2lY3cL 15xmNIAjR5FXh3bIB7lK140eusZGLDXff1jyoPLZKl0dWq+SGGnxh/yPQPSdI2a7sKQo pvqBLdSnFCW6z7tzMgxJULtVQjEKnZ0w+/xI0BiPOpZCpDfn1e4wiRivZMJRNMT2SIyx 22yKgho0wmsSVm3xVzvuXcOKjeSu14HYQCYdy7J4jM8nn7Hx9tvjJa4mKyzSXo3zRd3Y ZVxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=whX4xGE+; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si4114108edo.382.2020.05.31.04.03.03; Sun, 31 May 2020 04:03:25 -0700 (PDT) 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=@kernel.org header.s=default header.b=whX4xGE+; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728848AbgEaKwd (ORCPT + 99 others); Sun, 31 May 2020 06:52:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:54870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728288AbgEaKwa (ORCPT ); Sun, 31 May 2020 06:52:30 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 D43E92077D; Sun, 31 May 2020 10:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590922349; bh=GtfQqpLz+UA0E0hOaFJGXiH9ZOAFoetaFP4PLzghpaM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=whX4xGE+O46Lk8RKfVNzPjfTl9BNo/bX8dVULJ6+OzOxkdriGZqxGL247/cu2ZrAt v81BLHTvbgPOCd3HJ0rtTFLsFRacW0+HaMfSAPUz+N+IKqc/6odhvQwzIAWVypzEZv KBJqiycdHHQcIsXRzmpM/2ha1YKsO1RTXu5OWfLc= Date: Sun, 31 May 2020 11:52:24 +0100 From: Jonathan Cameron To: Jishnu Prakash Cc: agross@kernel.org, bjorn.andersson@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, mka@chromium.org, linus.walleij@linaro.org, Jonathan.Cameron@huawei.com, andy.shevchenko@gmail.com, amit.kucheria@verdurent.com, smohanad@codeaurora.org, kgunda@codeaurora.org, aghayal@codeaurora.org, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-msm-owner@vger.kernel.org Subject: Re: [PATCH V6 7/7] iio: adc: Add a common read function for PMIC5 and PMIC7 Message-ID: <20200531115224.700b11d3@archlinux> In-Reply-To: <1590684869-15400-8-git-send-email-jprakash@codeaurora.org> References: <1590684869-15400-1-git-send-email-jprakash@codeaurora.org> <1590684869-15400-8-git-send-email-jprakash@codeaurora.org> X-Mailer: Claws Mail 3.17.5 (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 Thu, 28 May 2020 22:24:29 +0530 Jishnu Prakash wrote: > Add a common function used for read_raw callback for both PMIC5 > and PMIC7 ADCs. > > Signed-off-by: Jishnu Prakash Hmm. I'm not completely sold on this one. Suggestions below. Jonathan > --- > drivers/iio/adc/qcom-spmi-adc5.c | 53 +++++++++++++++++++--------------------- > 1 file changed, 25 insertions(+), 28 deletions(-) > > diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c > index 0f9af66..fe49741 100644 > --- a/drivers/iio/adc/qcom-spmi-adc5.c > +++ b/drivers/iio/adc/qcom-spmi-adc5.c > @@ -449,6 +449,13 @@ static int adc7_do_conversion(struct adc5_chip *adc, > return ret; > } > > +struct adc_do_conversion { > + int (*adc_do_conversion)(struct adc5_chip *adc, > + struct adc5_channel_prop *prop, > + struct iio_chan_spec const *chan, > + u16 *data_volt, u16 *data_cur); Why use a structure for this? It's just a function pointer. If they form is too long you can always use a typedef. This is fine if you have other stuff coming shortly that will add to this structure but for now it's just a bit confusing. Directly passing the function pointer will reduce the amount of coded added here and make the argument in favour of refactoring rather stronger. > +}; > + > static irqreturn_t adc5_isr(int irq, void *dev_id) > { > struct adc5_chip *adc = dev_id; > @@ -487,9 +494,9 @@ static int adc7_of_xlate(struct iio_dev *indio_dev, > return -EINVAL; > } > > -static int adc5_read_raw(struct iio_dev *indio_dev, > +static int adc_read_raw_common(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, int *val, int *val2, > - long mask) > + long mask, struct adc_do_conversion do_conv) > { > struct adc5_chip *adc = iio_priv(indio_dev); > struct adc5_channel_prop *prop; > @@ -500,8 +507,8 @@ static int adc5_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_PROCESSED: > - ret = adc5_do_conversion(adc, prop, chan, > - &adc_code_volt, &adc_code_cur); > + ret = do_conv.adc_do_conversion(adc, prop, chan, > + &adc_code_volt, &adc_code_cur); > if (ret) > return ret; > > @@ -518,36 +525,26 @@ static int adc5_read_raw(struct iio_dev *indio_dev, > } > } > > -static int adc7_read_raw(struct iio_dev *indio_dev, > +static int adc5_read_raw(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, int *val, int *val2, > long mask) > { > - struct adc5_chip *adc = iio_priv(indio_dev); > - struct adc5_channel_prop *prop; > - u16 adc_code_volt, adc_code_cur; > - int ret; > - > - prop = &adc->chan_props[chan->address]; > - > - switch (mask) { > - case IIO_CHAN_INFO_PROCESSED: > - ret = adc7_do_conversion(adc, prop, chan, > - &adc_code_volt, &adc_code_cur); > - if (ret) > - return ret; > + struct adc_do_conversion do_conv; > > - ret = qcom_adc5_hw_scale(prop->scale_fn_type, > - &adc5_prescale_ratios[prop->prescale], > - adc->data, > - adc_code_volt, val); > + do_conv.adc_do_conversion = adc5_do_conversion; > + return adc_read_raw_common(indio_dev, chan, val, val2, > + mask, do_conv); > +} > > - if (ret) > - return ret; > +static int adc7_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, int *val, int *val2, > + long mask) > +{ > + struct adc_do_conversion do_conv; > > - return IIO_VAL_INT; > - default: > - return -EINVAL; > - } > + do_conv.adc_do_conversion = adc7_do_conversion; > + return adc_read_raw_common(indio_dev, chan, val, val2, > + mask, do_conv); > } > > static const struct iio_info adc5_info = {