From patchwork Mon Jan 24 17:20:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B79C4332F for ; Mon, 24 Jan 2022 17:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244384AbiAXRUb (ORCPT ); Mon, 24 Jan 2022 12:20:31 -0500 Received: from mga14.intel.com ([192.55.52.115]:58855 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244321AbiAXRU2 (ORCPT ); Mon, 24 Jan 2022 12:20:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044828; x=1674580828; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gDQSUskimsF+BvPq9Sv63P2zlzyWFSa/xN8KMVRN7Z4=; b=fsqK1u14VR/IvEwTXzV+ZUYVeOIO9w5GqP9psy+4Gmlerk+3snU6GfUI IcQmKO04COQCzuNknVvnQ1UYYI7IruBm3HFyb+Qk4UQn9J14UzGPMV+Ho IZAzNWn+WN5/tOLGf0/qQlvW31Lx8CN1UqJkRhM3elnv1LCWJyEbvTZxH rLXJotScuYBDNLTPxHikaOwpocr3o6yh4W7YM7K4aCSpDKLcBbii0mPcN PIBDuQ9YvFfESF8E00XLns50IMtVeiLSbWlwy28XZR6gSc2cxN4osIby+ cabA2IA65x104JpkCcSEf1OhJyuY0i2cFzptLDwtmA2UOK0m76ASVvtAn Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="246316985" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="246316985" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="617320047" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jan 2022 09:20:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 97045178; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 1/6] math.h: Introduce data types for fractional numbers Date: Mon, 24 Jan 2022 19:20:27 +0200 Message-Id: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Introduce a macro to produce data types like struct TYPE_fract { __TYPE numerator; __TYPE denominator; }; to be used in the code wherever it's needed. In the following changes convert some users to it. Signed-off-by: Andy Shevchenko --- May be pulled via IIO tree. v3: no changes v2: no changes include/linux/math.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/math.h b/include/linux/math.h index 53674a327e39..439b8f0b9ebd 100644 --- a/include/linux/math.h +++ b/include/linux/math.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MATH_H #define _LINUX_MATH_H +#include #include #include @@ -106,6 +107,17 @@ } \ ) +#define __STRUCT_FRACT(type) \ +struct type##_fract { \ + __##type numerator; \ + __##type denominator; \ +}; +__STRUCT_FRACT(s16) +__STRUCT_FRACT(u16) +__STRUCT_FRACT(s32) +__STRUCT_FRACT(u32) +#undef __STRUCT_FRACT + /* * Multiplies an integer by a fraction, while avoiding unnecessary * overflow or loss of precision. From patchwork Mon Jan 24 17:20:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B174C4332F for ; Mon, 24 Jan 2022 17:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244385AbiAXRUb (ORCPT ); Mon, 24 Jan 2022 12:20:31 -0500 Received: from mga04.intel.com ([192.55.52.120]:37867 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244359AbiAXRU2 (ORCPT ); Mon, 24 Jan 2022 12:20:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044828; x=1674580828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RVVPkYMMp87PkJON1Ymf9k5n3tLKBCKMpBFOUFvL4KE=; b=CNqgUIJpNinmvHkbc5uF6q7BsgPtimJh1pL/FLaTbDLMhJJ46WTtN18F ZESEIJcBE8FlFb8cJ/4/y5qKgKR1mFM7K2f4mwROKvn6+ePSv+gA5dOY2 S0+Jj9GmZJWcK/0bu5Fa658oKPEWdHjzL51v9imoPx8vv/Sm9z05nU//x JIlA0MQGtoIoqK0pIZOxwtVGV59IrGaYcwPPzEDKddgAsk26Z9KEFF5vf bpAn7BWUaKA5fHDbj3A/zSnt3mSNSyT1hExwyPnvrscKFM1cYZD/pDvW7 AUPZBgE48I3UkWxWID2Rl2t1XHbJVN+SSgARJMVREa6VAswKWC478aYD+ g==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="244933222" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="244933222" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="627578404" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 24 Jan 2022 09:20:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id A244AB7; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 2/6] iio: adc: rn5t618: Re-use generic struct u16_fract Date: Mon, 24 Jan 2022 19:20:28 +0200 Message-Id: <20220124172032.87893-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> References: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Instead of custom data type re-use generic struct u16_fract. No changes intended. Signed-off-by: Andy Shevchenko --- v3: no changes drivers/iio/adc/rn5t618-adc.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/iio/adc/rn5t618-adc.c b/drivers/iio/adc/rn5t618-adc.c index 7d891b4ea461..6bf32907f01d 100644 --- a/drivers/iio/adc/rn5t618-adc.c +++ b/drivers/iio/adc/rn5t618-adc.c @@ -42,11 +42,6 @@ struct rn5t618_adc_data { int irq; }; -struct rn5t618_channel_ratios { - u16 numerator; - u16 denominator; -}; - enum rn5t618_channels { LIMMON = 0, VBAT, @@ -58,7 +53,7 @@ enum rn5t618_channels { AIN0 }; -static const struct rn5t618_channel_ratios rn5t618_ratios[8] = { +static const struct u16_fract rn5t618_ratios[8] = { [LIMMON] = {50, 32}, /* measured across 20mOhm, amplified by 32 */ [VBAT] = {2, 1}, [VADP] = {3, 1}, From patchwork Mon Jan 24 17:20:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F271C433EF for ; Mon, 24 Jan 2022 17:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244353AbiAXRU0 (ORCPT ); Mon, 24 Jan 2022 12:20:26 -0500 Received: from mga05.intel.com ([192.55.52.43]:33543 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244274AbiAXRUZ (ORCPT ); Mon, 24 Jan 2022 12:20:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044825; x=1674580825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/5wu6jTRsftWHS1sGrTpaPtl4CwQ65yAvK9AFROQxzE=; b=n8UDwj4RmTK3Q8aIGvT5jbhcdDuToQmNjo3VPwO8CpVB75AFrgvkcB7d wBZbtVbzw+vMvaPwtaLQsCWGY0ROpwR3EYnJBEOOPMGN4q6u8ZC4oitD2 yM98427sILE93tJSQ1/LUG9E56H8o+QYzJ8rzWbQ8W7wNbJpndZg5z3C9 LFlgKiYUgKfHqSTm2ThVp7dGgn6ZkoKJ2woyZXW8+zn3mLonxwGLzNn9q YchrhhcudUT2bDdUyiYTFDH56JkeWDcA25yq0ZLqW+5cstQ4e1Z5HIeK2 UseNg2JKA2iuY6WLf9kt0viUGoSJ7rc4b82ydqLVlaw/SyfCV5hJDsMcc w==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="332452742" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="332452742" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="768748116" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 24 Jan 2022 09:20:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id AB4CC616; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 3/6] iio: adc: twl4030-madc: Re-use generic struct s16_fract Date: Mon, 24 Jan 2022 19:20:29 +0200 Message-Id: <20220124172032.87893-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> References: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Instead of custom data type re-use generic struct s16_fract. No changes intended. Signed-off-by: Andy Shevchenko --- v3: no changes drivers/iio/adc/twl4030-madc.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/iio/adc/twl4030-madc.c b/drivers/iio/adc/twl4030-madc.c index 6ce40cc4568a..f8f8aea15612 100644 --- a/drivers/iio/adc/twl4030-madc.c +++ b/drivers/iio/adc/twl4030-madc.c @@ -231,13 +231,7 @@ static const struct iio_chan_spec twl4030_madc_iio_channels[] = { static struct twl4030_madc_data *twl4030_madc; -struct twl4030_prescale_divider_ratios { - s16 numerator; - s16 denominator; -}; - -static const struct twl4030_prescale_divider_ratios -twl4030_divider_ratios[16] = { +static const struct s16_fract twl4030_divider_ratios[16] = { {1, 1}, /* CHANNEL 0 No Prescaler */ {1, 1}, /* CHANNEL 1 No Prescaler */ {6, 10}, /* CHANNEL 2 */ @@ -256,7 +250,6 @@ twl4030_divider_ratios[16] = { {5, 11}, /* CHANNEL 15 */ }; - /* Conversion table from -3 to 55 degrees Celcius */ static int twl4030_therm_tbl[] = { 30800, 29500, 28300, 27100, From patchwork Mon Jan 24 17:20:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2464AC43217 for ; Mon, 24 Jan 2022 17:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244399AbiAXRUc (ORCPT ); Mon, 24 Jan 2022 12:20:32 -0500 Received: from mga12.intel.com ([192.55.52.136]:20837 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244347AbiAXRU3 (ORCPT ); Mon, 24 Jan 2022 12:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044828; x=1674580828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ol3QlmypIgkLYpGLJiPGUhUsKaWSsFp4xvZU8I5jV8I=; b=QlYHipZ4y6kTABQkAqS6piSaaneIalEFizNlktqsn6jt+7VRyZtRuOQx AQwfo+K+6CBHYEgRyZVNi5xUA9V9rJ1j5mmnqqwx5KsJMLf/KzoD4J0Vo V8KwRxzoRoPgEG+hscPBc+QOx2SwhXO2AIY8OsbjhEcel7NUfp2DNulS0 GgzlGM6MGCczr3OdMKK2uxR4qNXpgYrwiVHaMwLwJ4zISxYd2mRl3zDnq KhFC98C+Jw82juS6q7sdSno3InnDz6V40L9gPahgtXrgYuMzPq0510tkM /S65hdiHQ53RunE5oT9pVB+HJcQkAZpvij0UWPDV/iUp8Nisb6Yl4Btwq A==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="226079531" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="226079531" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="534324057" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 24 Jan 2022 09:20:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id B44E29E7; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 4/6] iio: adc: qcom-vadc-common: Re-use generic struct u32_fract Date: Mon, 24 Jan 2022 19:20:30 +0200 Message-Id: <20220124172032.87893-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> References: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Instead of custom data type re-use generic struct u32_fract. No changes intended. Signed-off-by: Andy Shevchenko --- v3: no changes v2: comile-tested, i.o.w. fixed compilation errors drivers/iio/adc/qcom-pm8xxx-xoadc.c | 15 ++-- drivers/iio/adc/qcom-spmi-vadc.c | 24 +++---- drivers/iio/adc/qcom-vadc-common.c | 92 ++++++++++++------------ include/linux/iio/adc/qcom-vadc-common.h | 15 +--- 4 files changed, 69 insertions(+), 77 deletions(-) diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index 21d7eff645c3..5e9e56821075 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -175,7 +175,7 @@ struct xoadc_channel { const char *datasheet_name; u8 pre_scale_mux:2; u8 amux_channel:4; - const struct vadc_prescale_ratio prescale; + const struct u32_fract prescale; enum iio_chan_type type; enum vadc_scale_fn_type scale_fn_type; u8 amux_ip_rsv:3; @@ -218,7 +218,9 @@ struct xoadc_variant { .datasheet_name = __stringify(_dname), \ .pre_scale_mux = _presmux, \ .amux_channel = _amux, \ - .prescale = { .num = _prenum, .den = _preden }, \ + .prescale = { \ + .numerator = _prenum, .denominator = _preden, \ + }, \ .type = _type, \ .scale_fn_type = _scale, \ .amux_ip_rsv = _amip, \ @@ -809,12 +811,11 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev, BIT(IIO_CHAN_INFO_PROCESSED); iio_chan->indexed = 1; - dev_dbg(dev, "channel [PRESCALE/MUX: %02x AMUX: %02x] \"%s\" " - "ref voltage: %d, decimation %d " - "prescale %d/%d, scale function %d\n", + dev_dbg(dev, + "channel [PRESCALE/MUX: %02x AMUX: %02x] \"%s\" ref voltage: %d, decimation %d prescale %d/%d, scale function %d\n", hwchan->pre_scale_mux, hwchan->amux_channel, ch->name, - ch->amux_ip_rsv, ch->decimation, hwchan->prescale.num, - hwchan->prescale.den, hwchan->scale_fn_type); + ch->amux_ip_rsv, ch->decimation, hwchan->prescale.numerator, + hwchan->prescale.denominator, hwchan->scale_fn_type); return 0; } diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index 07b1a99381d9..34202ba52469 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -122,15 +122,15 @@ struct vadc_priv { struct mutex lock; }; -static const struct vadc_prescale_ratio vadc_prescale_ratios[] = { - {.num = 1, .den = 1}, - {.num = 1, .den = 3}, - {.num = 1, .den = 4}, - {.num = 1, .den = 6}, - {.num = 1, .den = 20}, - {.num = 1, .den = 8}, - {.num = 10, .den = 81}, - {.num = 1, .den = 10} +static const struct u32_fract vadc_prescale_ratios[] = { + { .numerator = 1, .denominator = 1 }, + { .numerator = 1, .denominator = 3 }, + { .numerator = 1, .denominator = 4 }, + { .numerator = 1, .denominator = 6 }, + { .numerator = 1, .denominator = 20 }, + { .numerator = 1, .denominator = 8 }, + { .numerator = 10, .denominator = 81 }, + { .numerator = 1, .denominator = 10 }, }; static int vadc_read(struct vadc_priv *vadc, u16 offset, u8 *data) @@ -404,13 +404,13 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) return ret; } -static int vadc_prescaling_from_dt(u32 num, u32 den) +static int vadc_prescaling_from_dt(u32 numerator, u32 denominator) { unsigned int pre; for (pre = 0; pre < ARRAY_SIZE(vadc_prescale_ratios); pre++) - if (vadc_prescale_ratios[pre].num == num && - vadc_prescale_ratios[pre].den == den) + if (vadc_prescale_ratios[pre].numerator == numerator && + vadc_prescale_ratios[pre].denominator == denominator) break; if (pre == ARRAY_SIZE(vadc_prescale_ratios)) diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 14723896aab2..6c6aec848f98 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -289,44 +289,44 @@ static const struct vadc_map_pt adcmap7_100k[] = { { 2420, 130048 } }; -static const struct vadc_prescale_ratio adc5_prescale_ratios[] = { - {.num = 1, .den = 1}, - {.num = 1, .den = 3}, - {.num = 1, .den = 4}, - {.num = 1, .den = 6}, - {.num = 1, .den = 20}, - {.num = 1, .den = 8}, - {.num = 10, .den = 81}, - {.num = 1, .den = 10}, - {.num = 1, .den = 16} +static const struct u32_fract adc5_prescale_ratios[] = { + { .numerator = 1, .denominator = 1 }, + { .numerator = 1, .denominator = 3 }, + { .numerator = 1, .denominator = 4 }, + { .numerator = 1, .denominator = 6 }, + { .numerator = 1, .denominator = 20 }, + { .numerator = 1, .denominator = 8 }, + { .numerator = 10, .denominator = 81 }, + { .numerator = 1, .denominator = 10 }, + { .numerator = 1, .denominator = 16 }, }; static int qcom_vadc_scale_hw_calib_volt( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_uv); static int qcom_vadc_scale_hw_calib_therm( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); static int qcom_vadc7_scale_hw_calib_therm( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); static int qcom_vadc_scale_hw_smb_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); static int qcom_vadc_scale_hw_chg5_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); static int qcom_vadc_scale_hw_calib_die_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); static int qcom_vadc7_scale_hw_calib_die_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec); @@ -406,7 +406,7 @@ static void qcom_vadc_scale_calib(const struct vadc_linear_graph *calib_graph, } static int qcom_vadc_scale_volt(const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_uv) { @@ -414,15 +414,15 @@ static int qcom_vadc_scale_volt(const struct vadc_linear_graph *calib_graph, qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage); - voltage = voltage * prescale->den; - result = div64_s64(voltage, prescale->num); + voltage *= prescale->denominator; + result = div64_s64(voltage, prescale->numerator); *result_uv = result; return 0; } static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_mdec) { @@ -444,7 +444,7 @@ static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph, } static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_mdec) { @@ -454,8 +454,8 @@ static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph, qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage); if (voltage > 0) { - temp = voltage * prescale->den; - do_div(temp, prescale->num * 2); + temp = voltage * prescale->denominator; + do_div(temp, prescale->numerator * 2); voltage = temp; } else { voltage = 0; @@ -467,7 +467,7 @@ static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph, } static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_mdec) { @@ -475,8 +475,8 @@ static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph, qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage); - voltage = voltage * prescale->den; - voltage = div64_s64(voltage, prescale->num); + voltage *= prescale->denominator; + voltage = div64_s64(voltage, prescale->numerator); voltage = ((PMI_CHG_SCALE_1) * (voltage * 2)); voltage = (voltage + PMI_CHG_SCALE_2); result = div64_s64(voltage, 1000000); @@ -487,21 +487,21 @@ static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph, /* convert voltage to ADC code, using 1.875V reference */ static u16 qcom_vadc_scale_voltage_code(s32 voltage, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const u32 full_scale_code_volt, unsigned int factor) { s64 volt = voltage; s64 adc_vdd_ref_mv = 1875; /* reference voltage */ - volt *= prescale->num * factor * full_scale_code_volt; - volt = div64_s64(volt, (s64)prescale->den * adc_vdd_ref_mv * 1000); + volt *= prescale->numerator * factor * full_scale_code_volt; + volt = div64_s64(volt, (s64)prescale->denominator * adc_vdd_ref_mv * 1000); return volt; } static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, unsigned int factor) { @@ -520,8 +520,8 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, voltage = (s64) adc_code * adc_vdd_ref_mv * 1000; voltage = div64_s64(voltage, data->full_scale_code_volt); if (voltage > 0) { - voltage *= prescale->den; - temp = prescale->num * factor; + voltage *= prescale->denominator; + temp = prescale->numerator * factor; voltage = div64_s64(voltage, temp); } else { voltage = 0; @@ -531,7 +531,7 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, } static int qcom_vadc7_scale_hw_calib_therm( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -557,7 +557,7 @@ static int qcom_vadc7_scale_hw_calib_therm( } static int qcom_vadc_scale_hw_calib_volt( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_uv) { @@ -568,7 +568,7 @@ static int qcom_vadc_scale_hw_calib_volt( } static int qcom_vadc_scale_hw_calib_therm( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -584,7 +584,7 @@ static int qcom_vadc_scale_hw_calib_therm( } static int qcom_vadc_scale_hw_calib_die_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -596,7 +596,7 @@ static int qcom_vadc_scale_hw_calib_die_temp( } static int qcom_vadc7_scale_hw_calib_die_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -611,7 +611,7 @@ static int qcom_vadc7_scale_hw_calib_die_temp( } static int qcom_vadc_scale_hw_smb_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -623,7 +623,7 @@ static int qcom_vadc_scale_hw_smb_temp( } static int qcom_vadc_scale_hw_chg5_temp( - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result_mdec) { @@ -636,7 +636,7 @@ static int qcom_vadc_scale_hw_chg5_temp( int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result) { @@ -667,7 +667,7 @@ EXPORT_SYMBOL(qcom_vadc_scale); u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio, u32 full_scale_code_volt, int temp) { - const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio]; + const struct u32_fract *prescale = &adc5_prescale_ratios[prescale_ratio]; s32 voltage; voltage = qcom_vadc_map_temp_voltage(adcmap_100k_104ef_104fb_1875_vref, @@ -682,7 +682,7 @@ int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, const struct adc5_data *data, u16 adc_code, int *result) { - const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio]; + const struct u32_fract *prescale = &adc5_prescale_ratios[prescale_ratio]; if (!(scaletype >= SCALE_HW_CALIB_DEFAULT && scaletype < SCALE_HW_CALIB_INVALID)) { @@ -695,13 +695,13 @@ int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, } EXPORT_SYMBOL(qcom_adc5_hw_scale); -int qcom_adc5_prescaling_from_dt(u32 num, u32 den) +int qcom_adc5_prescaling_from_dt(u32 numerator, u32 denominator) { unsigned int pre; for (pre = 0; pre < ARRAY_SIZE(adc5_prescale_ratios); pre++) - if (adc5_prescale_ratios[pre].num == num && - adc5_prescale_ratios[pre].den == den) + if (adc5_prescale_ratios[pre].numerator == numerator && + adc5_prescale_ratios[pre].denominator == denominator) break; if (pre == ARRAY_SIZE(adc5_prescale_ratios)) diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h index 33f60f43e1aa..ce78d4804994 100644 --- a/include/linux/iio/adc/qcom-vadc-common.h +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -6,6 +6,7 @@ #ifndef QCOM_VADC_COMMON_H #define QCOM_VADC_COMMON_H +#include #include #define VADC_CONV_TIME_MIN_US 2000 @@ -79,16 +80,6 @@ struct vadc_linear_graph { s32 gnd; }; -/** - * struct vadc_prescale_ratio - Represent scaling ratio for ADC input. - * @num: the inverse numerator of the gain applied to the input channel. - * @den: the inverse denominator of the gain applied to the input channel. - */ -struct vadc_prescale_ratio { - u32 num; - u32 den; -}; - /** * enum vadc_scale_fn_type - Scaling function to convert ADC code to * physical scaled units for the channel. @@ -144,12 +135,12 @@ struct adc5_data { int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, + const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_mdec); struct qcom_adc5_scale_type { - int (*scale_fn)(const struct vadc_prescale_ratio *prescale, + int (*scale_fn)(const struct u32_fract *prescale, const struct adc5_data *data, u16 adc_code, int *result); }; From patchwork Mon Jan 24 17:20:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B91CC433EF for ; Mon, 24 Jan 2022 17:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244413AbiAXRUd (ORCPT ); Mon, 24 Jan 2022 12:20:33 -0500 Received: from mga02.intel.com ([134.134.136.20]:35243 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244324AbiAXRU3 (ORCPT ); Mon, 24 Jan 2022 12:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044829; x=1674580829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=se/aEC9HgTBzxLx3OJbYihBez8zl3RiKCuUOJXNE4gU=; b=EQ3zGLjSjSRMPxfPQkdJ1Th5KxAtTLidmuk1RTQ+z7H/rDj1ykJDP0O0 Ox3CrJi6WWSxRYydDRGs+TVBm/xPEhfqRE2L/d8yi6lO01BWXM/zOrNo6 MDsEchm2BaeMlth9N425DeXutbP5b86XdAarPiJ4iqsXF5dwZESfcR9xa Om0TDAwqYbF7VUOCWC6gwwulMc0Xn24zB+FP4aNePpIEBYeIsic92A09C GcJpEDG4riINVoxJbR6s1FCOg2+iQmMOFjH8e6Tg+pqk2NP4gGlnn0dat JcalsGi6voYbyLDE0t1euHQs6KS3xwcIiYiDLpJ/fC2U3a5tayMBROkLb g==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="233460796" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="233460796" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="532144834" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 24 Jan 2022 09:20:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id BCD55A51; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 5/6] iio: afe: iio-rescale: Group rescale field assignments in ->probe() Date: Mon, 24 Jan 2022 19:20:31 +0200 Message-Id: <20220124172032.87893-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> References: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Group rescale field assignments in the ->probe() for better maintenance. Signed-off-by: Andy Shevchenko --- v3: new patch drivers/iio/afe/iio-rescale.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 774eb3044edd..8b9d2aa1502e 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -322,7 +322,7 @@ static int rescale_probe(struct platform_device *pdev) return -ENOMEM; rescale = iio_priv(indio_dev); - + rescale->source = source; rescale->cfg = of_device_get_match_data(dev); rescale->numerator = 1; rescale->denominator = 1; @@ -338,8 +338,6 @@ static int rescale_probe(struct platform_device *pdev) platform_set_drvdata(pdev, indio_dev); - rescale->source = source; - indio_dev->name = dev_name(dev); indio_dev->info = &rescale_info; indio_dev->modes = INDIO_DIRECT_MODE; From patchwork Mon Jan 24 17:20:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12722486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D8A2C4167E for ; Mon, 24 Jan 2022 17:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244398AbiAXRUf (ORCPT ); Mon, 24 Jan 2022 12:20:35 -0500 Received: from mga03.intel.com ([134.134.136.65]:17853 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244389AbiAXRUc (ORCPT ); Mon, 24 Jan 2022 12:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643044831; x=1674580831; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HUNTtC4SehQi3UDg50mC4uWw+k23kUBXzji3SHfmIfM=; b=Muo/q4/zYjhtLXL1on/BBLXoiIBHLeE82KPqN5ZDi/QiEdGWxes9VC2d KzyxFPx/HWBj6S3frRp6JS8y+Pzuloct1vw4tvdQ5SEDB4r5HR1MT5Qsw ZhTNyMqjPMdTYIM0uh84Rlj+CxAskAInCLikC5akQIObwDsnHx/T0skhm ulWhDzPNpUw4RDMlzop29DleU7ZEp3VeCCI3bbXq8JbLD7/vK72oFnbTk wbOt7l/D4v6OlmE4jNkRB4BaCT7lIby6TBHY/v4xS4+kod7UdTA5Rq+zt ehqiO+cW0sgGPiHKGw9DHRNANE6snTEacJWF7AjKX2/rt4s5pHo5JUlb5 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="246044028" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="246044028" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 09:20:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="766469370" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 24 Jan 2022 09:20:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id C5FE4A5F; Mon, 24 Jan 2022 19:20:35 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Andreas Kemnade , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Jonathan Cameron , Lars-Peter Clausen , Peter Rosin Subject: [PATCH v3 6/6] iio: afe: iio-rescale: Re-use generic struct s32_fract Date: Mon, 24 Jan 2022 19:20:32 +0200 Message-Id: <20220124172032.87893-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> References: <20220124172032.87893-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Instead of custom data type re-use generic struct s32_fract. No changes intended. The new member is put to be the first one to avoid additional pointer arithmetic. Besides that one may switch to use fract member to perform container_of(), which will be no-op in this case, to get struct rescale. Signed-off-by: Andy Shevchenko --- v3: split out assignment reshuffling (Jonathan) drivers/iio/afe/iio-rescale.c | 70 ++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 8b9d2aa1502e..0368bca8a485 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -21,17 +22,16 @@ struct rescale; struct rescale_cfg { enum iio_chan_type type; - int (*props)(struct device *dev, struct rescale *rescale); + int (*props)(struct device *dev, struct s32_fract *fract); }; struct rescale { + struct s32_fract fract; const struct rescale_cfg *cfg; struct iio_channel *source; struct iio_chan_spec chan; struct iio_chan_spec_ext_info *ext_info; bool chan_processed; - s32 numerator; - s32 denominator; }; static int rescale_read_raw(struct iio_dev *indio_dev, @@ -39,6 +39,7 @@ static int rescale_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct rescale *rescale = iio_priv(indio_dev); + struct s32_fract *fract = &rescale->fract; unsigned long long tmp; int ret; @@ -67,19 +68,19 @@ static int rescale_read_raw(struct iio_dev *indio_dev, } switch (ret) { case IIO_VAL_FRACTIONAL: - *val *= rescale->numerator; - *val2 *= rescale->denominator; + *val *= fract->numerator; + *val2 *= fract->denominator; return ret; case IIO_VAL_INT: - *val *= rescale->numerator; - if (rescale->denominator == 1) + *val *= fract->numerator; + if (fract->denominator == 1) return ret; - *val2 = rescale->denominator; + *val2 = fract->denominator; return IIO_VAL_FRACTIONAL; case IIO_VAL_FRACTIONAL_LOG2: tmp = *val * 1000000000LL; - do_div(tmp, rescale->denominator); - tmp *= rescale->numerator; + do_div(tmp, fract->denominator); + tmp *= fract->numerator; do_div(tmp, 1000000000LL); *val = tmp; return ret; @@ -175,7 +176,7 @@ static int rescale_configure_channel(struct device *dev, } static int rescale_current_sense_amplifier_props(struct device *dev, - struct rescale *rescale) + struct s32_fract *fract) { u32 sense; u32 gain_mult = 1; @@ -199,22 +200,22 @@ static int rescale_current_sense_amplifier_props(struct device *dev, * numerator/denominator from overflowing. */ factor = gcd(sense, 1000000); - rescale->numerator = 1000000 / factor; - rescale->denominator = sense / factor; + fract->numerator = 1000000 / factor; + fract->denominator = sense / factor; - factor = gcd(rescale->numerator, gain_mult); - rescale->numerator /= factor; - rescale->denominator *= gain_mult / factor; + factor = gcd(fract->numerator, gain_mult); + fract->numerator /= factor; + fract->denominator *= gain_mult / factor; - factor = gcd(rescale->denominator, gain_div); - rescale->numerator *= gain_div / factor; - rescale->denominator /= factor; + factor = gcd(fract->denominator, gain_div); + fract->numerator *= gain_div / factor; + fract->denominator /= factor; return 0; } static int rescale_current_sense_shunt_props(struct device *dev, - struct rescale *rescale) + struct s32_fract *fract) { u32 shunt; u32 factor; @@ -228,35 +229,33 @@ static int rescale_current_sense_shunt_props(struct device *dev, } factor = gcd(shunt, 1000000); - rescale->numerator = 1000000 / factor; - rescale->denominator = shunt / factor; + fract->numerator = 1000000 / factor; + fract->denominator = shunt / factor; return 0; } static int rescale_voltage_divider_props(struct device *dev, - struct rescale *rescale) + struct s32_fract *fract) { int ret; u32 factor; - ret = device_property_read_u32(dev, "output-ohms", - &rescale->denominator); + ret = device_property_read_u32(dev, "output-ohms", &fract->denominator); if (ret) { dev_err(dev, "failed to read output-ohms: %d\n", ret); return ret; } - ret = device_property_read_u32(dev, "full-ohms", - &rescale->numerator); + ret = device_property_read_u32(dev, "full-ohms", &fract->numerator); if (ret) { dev_err(dev, "failed to read full-ohms: %d\n", ret); return ret; } - factor = gcd(rescale->numerator, rescale->denominator); - rescale->numerator /= factor; - rescale->denominator /= factor; + factor = gcd(fract->numerator, fract->denominator); + fract->numerator /= factor; + fract->denominator /= factor; return 0; } @@ -299,6 +298,7 @@ static int rescale_probe(struct platform_device *pdev) struct iio_dev *indio_dev; struct iio_channel *source; struct rescale *rescale; + struct s32_fract *fract; int sizeof_ext_info; int sizeof_priv; int i; @@ -324,14 +324,16 @@ static int rescale_probe(struct platform_device *pdev) rescale = iio_priv(indio_dev); rescale->source = source; rescale->cfg = of_device_get_match_data(dev); - rescale->numerator = 1; - rescale->denominator = 1; - ret = rescale->cfg->props(dev, rescale); + fract = &rescale->fract; + fract->numerator = 1; + fract->denominator = 1; + + ret = rescale->cfg->props(dev, fract); if (ret) return ret; - if (!rescale->numerator || !rescale->denominator) { + if (!fract->numerator || !fract->denominator) { dev_err(dev, "invalid scaling factor.\n"); return -EINVAL; }