Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3385873ybt; Tue, 23 Jun 2020 00:36:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWHGwIXtVlj9vyomf0jM4Rmpd2k2uvIkoPJp5ZSQ6om5LGctsBQgSS2C20Nqutk+XsUfdu X-Received: by 2002:aa7:d9d6:: with SMTP id v22mr21416684eds.66.1592897810855; Tue, 23 Jun 2020 00:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592897810; cv=none; d=google.com; s=arc-20160816; b=ZMDfyii4X2G8QZwGSFzEAnfjhDYt0oph3IVUAoXdzYG+9d6crxE+tRoPjbK3aTkuo7 +KzOC2NneGDWYYN/TL0cfO4Gl7/glona5oW9EfLxHbBdIkoO20s8kzKEY3VGP65r1WYW TH5XmJQWYuI174zjo2WCn5C2+XWVs9V6H5kicUB4mcw9pNdF/T5KsCVqkZ6lbxD2C4ZI 2aFypmzQ3yF+iXZ9qNWEk0IaqyOJEzMSh+bkp5w36oDiasnAivuL/cb3mwPRczgUeQX+ chnSMb/9HadTdkvlf1l81Ho4WuoH0KJSbKTm2MQxdcdl+KAMNTzM6lTf18UCreQXj8Ap b8Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=lakqupZmsNZf5TreKphxpnROhQ0dpQJl4y7QgjtKSMI=; b=OfKm1Ca8c8NzrlIgMd+wDIDnotS7Lr9xE12GXUbm3ZOFUHIm71fIQ1XHksLbAVJoQV tVglbHUI5w3cJMQWyUDvWpWXkX8pNfKGSUTf9SKyJMYpuZWHRA5h7C/cqP1krTNCNdD5 P2KZ9BV/NHDWnkZUo3/I5ME1/NWwELSAtbD/nRSSZB1+fpBvVLxKbQf98ajKaj2jy95d pKBXEy3YMB8IuFdm48h85R6mSuZ0WsWbw6JAw33NH+AzbWvStXEzNmaGHahTGxxbYfdG nNPFnaoGxHfRbWyFLab71COCFfsiAf9g7HoNpqmIgBEKasdq0ekkGQzFHXrcvGBKm8lu LYgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b="Seg/Ia5n"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si10137683ejf.3.2020.06.23.00.36.27; Tue, 23 Jun 2020 00:36:50 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b="Seg/Ia5n"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731811AbgFWHbd (ORCPT + 99 others); Tue, 23 Jun 2020 03:31:33 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:54402 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731777AbgFWHbb (ORCPT ); Tue, 23 Jun 2020 03:31:31 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1592897490; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=lakqupZmsNZf5TreKphxpnROhQ0dpQJl4y7QgjtKSMI=; b=Seg/Ia5nThjrHfXcv5nnVbOPzHXHnIX4m5Jrd1G9zN0co6fNMTWV/yS0MrG53Dhl/UwHtwWU nYpAsUjFH5wV/XidaR6w0BA368tbKBhCBPFV2ZXOdFDdkC1E2Ds9JB18qiMZVBPF2MaNo8eQ V8JzMaVvq/WJc0Fu5zHthfWU6nk= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n14.prod.us-west-2.postgun.com with SMTP id 5ef1afd05866879c76642e48 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 23 Jun 2020 07:31:28 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 92F30C433B1; Tue, 23 Jun 2020 07:31:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from jprakash-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jprakash) by smtp.codeaurora.org (Postfix) with ESMTPSA id BE071C433C6; Tue, 23 Jun 2020 07:31:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org BE071C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=jprakash@codeaurora.org From: Jishnu Prakash To: 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, Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org Cc: linux-arm-msm-owner@vger.kernel.org, Jishnu Prakash Subject: [PATCH V7 7/7] iio: adc: Combine read functions for PMIC5 and PMIC7 Date: Tue, 23 Jun 2020 12:59:59 +0530 Message-Id: <1592897399-24089-8-git-send-email-jprakash@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592897399-24089-1-git-send-email-jprakash@codeaurora.org> References: <1592897399-24089-1-git-send-email-jprakash@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a common function used for read_raw callback for both PMIC5 and PMIC7 ADCs. Signed-off-by: Jishnu Prakash --- drivers/iio/adc/qcom-spmi-adc5.c | 49 ++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index 0f9af66..88efadb 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -449,6 +449,11 @@ static int adc7_do_conversion(struct adc5_chip *adc, return ret; } +typedef 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); + static irqreturn_t adc5_isr(int irq, void *dev_id) { struct adc5_chip *adc = dev_id; @@ -487,9 +492,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, adc_do_conversion do_conv) { struct adc5_chip *adc = iio_priv(indio_dev); struct adc5_channel_prop *prop; @@ -500,8 +505,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, prop, chan, + &adc_code_volt, &adc_code_cur); if (ret) return ret; @@ -518,36 +523,20 @@ 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; - - ret = qcom_adc5_hw_scale(prop->scale_fn_type, - &adc5_prescale_ratios[prop->prescale], - adc->data, - adc_code_volt, val); - - if (ret) - return ret; + return adc_read_raw_common(indio_dev, chan, val, val2, + mask, adc5_do_conversion); +} - return IIO_VAL_INT; - default: - return -EINVAL; - } +static int adc7_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, int *val2, + long mask) +{ + return adc_read_raw_common(indio_dev, chan, val, val2, + mask, adc7_do_conversion); } static const struct iio_info adc5_info = { -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project