From patchwork Wed Dec 4 01:33:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13893120 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90657846F; Wed, 4 Dec 2024 01:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276187; cv=none; b=GLse93PU0dUIeX+aS95WcMCKfquDHNybRsQL/GM4uiCDcQPUKpS2/9xbLTMzf9qMyhPt+MMA5xLXYXicV/1RnadTzuTkYTkJHuMLP/js7O6WaZld0u3iL95uBdlvEgDzOiaef75TGSmvPO2Aefm9kHHmtXq3YQRbiec5q4tR2Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276187; c=relaxed/simple; bh=FFvequ/mfqiZtc1OdaDGJVhmmWqYniLAWEv5dTvXPgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JQrHaG9TcpzuA5ndkTCDDVJwUnk+eFXxBghrZjqp/tpsWxw2zF+01zJRAWUlXpLAJJKOlWx9E2PefOy1BheSOFOHohkJpLI+EC0ONQKf/pTb5733tWAP8JU7cDFRTwa8FGpVRmQj9Acxf2zQmLqvq6rApRJ4vKBpMcJ3+mQqQyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=P8pr9Oxc; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P8pr9Oxc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733276186; x=1764812186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FFvequ/mfqiZtc1OdaDGJVhmmWqYniLAWEv5dTvXPgA=; b=P8pr9OxcLdOMk1OKJ9QS0/kGhLRK4+vAp1xSsPt9t9JOtVjDIbMt9pAH 9up2tfVwaTDoeBc0Lpyxm3Cz9PDOj948Wg8WQBLKRD8c4ws91ScIAKPYM Ykv37EjkfCZHBq7tiL1n50Esh2ZEkXuteKBU+0Wv7hSzIH+/F2fDROdgN dMEMeoWDiuml3piSo89gbEHe6ypnYKad7Xm5mT22/zyzyWl4dvZt0k4ky hCVaR0e6NVGkMhZOTPdnWdNDiwb0HDcjmtrQSUzAjbbu3q2WWRQak0Uy8 T4h01bLYaMRsXOLYzmtRYzbqTXtrOtuamhWio05m8ly5QmP2yu3hgbB1r g==; X-CSE-ConnectionGUID: h/99cnFuRdiFvifo17h1FQ== X-CSE-MsgGUID: XEsCOEeRQt+5RnHiqCvdbw== X-IronPort-AV: E=McAfee;i="6700,10204,11275"; a="33655185" X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="33655185" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2024 17:36:25 -0800 X-CSE-ConnectionGUID: ogI+hdr7StmUIZ1QlIcXzw== X-CSE-MsgGUID: eDEuZZ1xQGS6VbcKxAgC9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="98600611" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 03 Dec 2024 17:36:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 223721EC; Wed, 04 Dec 2024 03:36:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Rosin , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 1/4] iio: afe: rescale: Don't use ^ for booleans Date: Wed, 4 Dec 2024 03:33:16 +0200 Message-ID: <20241204013620.862943-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> References: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are two (non-critical) issues with the code. First of all, the eXclusive OR is not defined for booleans, so boolean to integer promotion is required, Second, the u32 variable is used to keep boolean value, so boolean is converted implicitly to the integer. All these are not needed when variable is defined as boolean to begin with and operations are replaced by simple != and ||. Fixes: 701ee14da95d ("iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support") Signed-off-by: Andy Shevchenko --- drivers/iio/afe/iio-rescale.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index b6a46036d5ea..470dd7d41b2a 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -26,7 +26,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, int _val, _val2; s32 rem, rem2; u32 mult; - u32 neg; + bool neg; switch (scale_type) { case IIO_VAL_INT: @@ -95,7 +95,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, * If only one of the rescaler elements or the schan scale is * negative, the combined scale is negative. */ - if (neg ^ ((rescale->numerator < 0) ^ (rescale->denominator < 0))) { + if (neg != (rescale->numerator < 0 || rescale->denominator < 0)) { if (*val) *val = -*val; else From patchwork Wed Dec 4 01:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13893119 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E2922500B8; Wed, 4 Dec 2024 01:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276187; cv=none; b=CnwclujkyT28pU5UgqPK7HEdv3MpbE6X97GDdKez7alBP+AfppzpTSaBsbH864kmRtBWMC48xx7hmFeO4Rv+04ynRj+9E7/IMyZh7aOo1lJWui8rYxoT2IVa1iZy/gOuBnyT+Eo3IqhMOSoMpxc70OzkWohrFFaJOyzadCbGMxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276187; c=relaxed/simple; bh=mjLYAJWAsJEP7C3SPxpA96ZZvMOvnlODGBD00nA+UHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ko5PIChUvJhhXrZyLREDyAdXNgWHbXxs9Y6LGAiyUVOCIh46OZSVAbjrFbyjJwILFqnVvYSDbzhDD4QzhIDWwgMrd43+hixf3hLjiPJKBz0buPbUYHFn2azRnuEcK0WxehnccOJgEU31O9qrm1Bp5sAG1eKT9a7ZsI7zjbya71w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SbBHyb1i; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SbBHyb1i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733276186; x=1764812186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mjLYAJWAsJEP7C3SPxpA96ZZvMOvnlODGBD00nA+UHI=; b=SbBHyb1igaqH9TxUAM5ODMj5UKCreJzK958PqscnzMGipsosa+i0DXFP S2Yyj6C3BlzjRwOtzkXbjHHNpa0yWZsJO27Gi0VEq0REcsTA/zyYfqh3+ YB4djkMiqWfhuWHD+VOOlH9tPUWcXkM+fU0N52AFKc/Y9XM4uput4rVaE 09jiUvzTMz4cNS3CY6suLic/M1au+94PYuLJV2Perj1wTgEE3sNOEQrEt 0j6okyOfqTEGk1GixGc7qbjupnEA9+PeV5f4XSJVRauca05bYknS2pZ7i tJdUXSYFcWFVGnnJWoJVndIdy6TF/kjQdiQNHWOpDvrYaGobu17XvSFBY A==; X-CSE-ConnectionGUID: elPpvnXTQsOSjkNHnzd2hw== X-CSE-MsgGUID: aYVDXF+vS4W2H3EHd1IPtg== X-IronPort-AV: E=McAfee;i="6700,10204,11275"; a="37293577" X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="37293577" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2024 17:36:25 -0800 X-CSE-ConnectionGUID: FqNcxhpARV+GxDMfSicfZA== X-CSE-MsgGUID: 2rjJOPfDRUe/t+A2j89SUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="98694830" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 03 Dec 2024 17:36:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2790842D; Wed, 04 Dec 2024 03:36:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Rosin , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 2/4] iio: afe: rescale: Don't use ULL(1) << x instead of BIT(x) Date: Wed, 4 Dec 2024 03:33:17 +0200 Message-ID: <20241204013620.862943-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> References: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ULL(1) << x is just an open-coded implementation of BIT_ULL(). Replace the former by the latter. Note, the rest of the code properly uses BIT()/BIT_ULL() already. Signed-off-by: Andy Shevchenko --- drivers/iio/afe/iio-rescale.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 470dd7d41b2a..9d33e7aabe4d 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -8,6 +8,7 @@ * Author: Peter Rosin */ +#include #include #include #include @@ -62,7 +63,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, if (scale_type == IIO_VAL_FRACTIONAL) tmp = *val2; else - tmp = ULL(1) << *val2; + tmp = BIT_ULL(*val2); rem2 = *val % (int)tmp; *val = *val / (int)tmp; From patchwork Wed Dec 4 01:33:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13893122 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4F511078F; Wed, 4 Dec 2024 01:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276189; cv=none; b=TkLfMsYDsg52Crn2rYBrky3E7V6wB3pT3E4qbKI8ZTDeFgOlubfZ1sPPtWBtR7w1Kzp0Nutkqh2rNN95QQsnovuxMDb3o99m5NasziYhny/UN+wVcEVhfo0rZlOaRKCJxqPaHwSVfgXlcljlVkmLs2gvqaP2qOOfb2UusFHhXfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276189; c=relaxed/simple; bh=1MIHsLPSy27gu43t9ml1sSj+k0Yt18S4T21rqcDaZuk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/fgekJkR0VwiS7qTheb6GKLiDLlToBx1fZzHmwKmeYPx/PhGDO+otBYx4AhIARN5sYJT1goZFQvSHthtFU2kyDkhgUXXs5RpsuFeT3IsU/OQzF5ngUpfbexE+8ogPRhv3Fdz2JZBFs0AvJPb7jdrugRqddDHz/OcJzeM4GMYPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MpxRobF3; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MpxRobF3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733276188; x=1764812188; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1MIHsLPSy27gu43t9ml1sSj+k0Yt18S4T21rqcDaZuk=; b=MpxRobF3OyU+b0X/EmXVWlySrJ9JZN18hkxu2uf/8tkj5f62QMPsFDW1 r1ifRhUJBGYaEzXahheD2KVEaJc9nUdz2ei67FU46wcd8Wm6RoHXTqVey rSUa7X+eKbH45Wv5SMnUtTMb7rbG8GWFT87iCwBXd6DUd2OIEX2IiBnFX 7CfukVyaTQ+mKB3AbKyB3nXtyPCdeSFzzkEEo6mZqPg2mQi5SVtUqWw8x VcG3/ti0hc2GBHhjUhXO3JJsYxa3gus00naZD0aTmV4BU7EzLfM4Nh41R +NKVFNT47y/4bLcNKVsUn+XG6YcJTLwLD7OEB6IV8Ov0uOZIwrcTP6lL1 A==; X-CSE-ConnectionGUID: EZtmPe+zQDiiAK3As+ggSQ== X-CSE-MsgGUID: fN+Q5olASxSxdGCzeZ8RhQ== X-IronPort-AV: E=McAfee;i="6700,10204,11275"; a="33655193" X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="33655193" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2024 17:36:25 -0800 X-CSE-ConnectionGUID: ifHqhnJsTgiYHcoPKNNj2Q== X-CSE-MsgGUID: QWro1jOZS9eXfD/pFG+9PQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="98600610" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 03 Dec 2024 17:36:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 390D3710; Wed, 04 Dec 2024 03:36:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Rosin , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 3/4] iio: afe: rescale: Re-use generic struct s32_fract Date: Wed, 4 Dec 2024 03:33:18 +0200 Message-ID: <20241204013620.862943-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> References: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of custom data type re-use generic struct s32_fract. No changes intended. Signed-off-by: Andy Shevchenko --- drivers/iio/afe/iio-rescale.c | 79 +++++++++++++++++---------------- include/linux/iio/afe/rescale.h | 5 ++- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 9d33e7aabe4d..bbc73798082d 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -23,6 +23,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, int *val, int *val2) { + struct s32_fract *fract = &rescale->fract; s64 tmp; int _val, _val2; s32 rem, rem2; @@ -31,10 +32,10 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, switch (scale_type) { case IIO_VAL_INT: - *val *= rescale->numerator; - if (rescale->denominator == 1) + *val *= fract->numerator; + if (fract->denominator == 1) return scale_type; - *val2 = rescale->denominator; + *val2 = fract->denominator; return IIO_VAL_FRACTIONAL; case IIO_VAL_FRACTIONAL: /* @@ -42,8 +43,8 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, * potential accuracy loss (for in kernel consumers) by * keeping a fractional representation. */ - if (!check_mul_overflow(*val, rescale->numerator, &_val) && - !check_mul_overflow(*val2, rescale->denominator, &_val2)) { + if (!check_mul_overflow(*val, fract->numerator, &_val) && + !check_mul_overflow(*val2, fract->denominator, &_val2)) { *val = _val; *val2 = _val2; return IIO_VAL_FRACTIONAL; @@ -51,8 +52,8 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, fallthrough; case IIO_VAL_FRACTIONAL_LOG2: tmp = (s64)*val * 1000000000LL; - tmp = div_s64(tmp, rescale->denominator); - tmp *= rescale->numerator; + tmp = div_s64(tmp, fract->denominator); + tmp *= fract->numerator; tmp = div_s64_rem(tmp, 1000000000LL, &rem); *val = tmp; @@ -84,11 +85,11 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, */ neg = *val < 0 || *val2 < 0; - tmp = (s64)abs(*val) * abs(rescale->numerator); - *val = div_s64_rem(tmp, abs(rescale->denominator), &rem); + tmp = (s64)abs(*val) * abs(fract->numerator); + *val = div_s64_rem(tmp, abs(fract->denominator), &rem); - tmp = (s64)rem * mult + (s64)abs(*val2) * abs(rescale->numerator); - tmp = div_s64(tmp, abs(rescale->denominator)); + tmp = (s64)rem * mult + (s64)abs(*val2) * abs(fract->numerator); + tmp = div_s64(tmp, abs(fract->denominator)); *val += div_s64_rem(tmp, mult, val2); @@ -96,7 +97,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, * If only one of the rescaler elements or the schan scale is * negative, the combined scale is negative. */ - if (neg != (rescale->numerator < 0 || rescale->denominator < 0)) { + if (neg != (fract->numerator < 0 || fract->denominator < 0)) { if (*val) *val = -*val; else @@ -323,6 +324,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 = &rescale->fract; u32 sense; u32 gain_mult = 1; u32 gain_div = 1; @@ -345,16 +347,16 @@ 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; } @@ -362,6 +364,7 @@ static int rescale_current_sense_amplifier_props(struct device *dev, static int rescale_current_sense_shunt_props(struct device *dev, struct rescale *rescale) { + struct s32_fract *fract = &rescale->fract; u32 shunt; u32 factor; int ret; @@ -374,8 +377,8 @@ 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; } @@ -383,26 +386,25 @@ static int rescale_current_sense_shunt_props(struct device *dev, static int rescale_voltage_divider_props(struct device *dev, struct rescale *rescale) { + struct s32_fract *fract = &rescale->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; } @@ -410,6 +412,7 @@ static int rescale_voltage_divider_props(struct device *dev, static int rescale_temp_sense_rtd_props(struct device *dev, struct rescale *rescale) { + struct s32_fract *fract = &rescale->fract; u32 factor; u32 alpha; u32 iexc; @@ -440,8 +443,8 @@ static int rescale_temp_sense_rtd_props(struct device *dev, tmp = r0 * iexc * alpha / 1000000; factor = gcd(tmp, 1000000); - rescale->numerator = 1000000 / factor; - rescale->denominator = tmp / factor; + fract->numerator = 1000000 / factor; + fract->denominator = tmp / factor; rescale->offset = -1 * ((r0 * iexc) / 1000); @@ -451,6 +454,7 @@ static int rescale_temp_sense_rtd_props(struct device *dev, static int rescale_temp_transducer_props(struct device *dev, struct rescale *rescale) { + struct s32_fract *fract = &rescale->fract; s32 offset = 0; s32 sense = 1; s32 alpha; @@ -464,11 +468,10 @@ static int rescale_temp_transducer_props(struct device *dev, return ret; } - rescale->numerator = 1000000; - rescale->denominator = alpha * sense; + fract->numerator = 1000000; + fract->denominator = alpha * sense; - rescale->offset = div_s64((s64)offset * rescale->denominator, - rescale->numerator); + rescale->offset = div_s64((s64)offset * fract->denominator, fract->numerator); return 0; } @@ -550,15 +553,15 @@ static int rescale_probe(struct platform_device *pdev) rescale = iio_priv(indio_dev); rescale->cfg = device_get_match_data(dev); - rescale->numerator = 1; - rescale->denominator = 1; + rescale->fract.numerator = 1; + rescale->fract.denominator = 1; rescale->offset = 0; ret = rescale->cfg->props(dev, rescale); if (ret) return ret; - if (!rescale->numerator || !rescale->denominator) { + if (!rescale->fract.numerator || !rescale->fract.denominator) { dev_err(dev, "invalid scaling factor.\n"); return -EINVAL; } diff --git a/include/linux/iio/afe/rescale.h b/include/linux/iio/afe/rescale.h index 6eecb435488f..d6998806b4f5 100644 --- a/include/linux/iio/afe/rescale.h +++ b/include/linux/iio/afe/rescale.h @@ -6,7 +6,9 @@ #ifndef __IIO_RESCALE_H__ #define __IIO_RESCALE_H__ +#include #include + #include struct device; @@ -19,12 +21,11 @@ struct rescale_cfg { struct rescale { const struct rescale_cfg *cfg; + struct s32_fract fract; struct iio_channel *source; struct iio_chan_spec chan; struct iio_chan_spec_ext_info *ext_info; bool chan_processed; - s32 numerator; - s32 denominator; s32 offset; }; From patchwork Wed Dec 4 01:33:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13893121 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F8F6EAF6; Wed, 4 Dec 2024 01:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276188; cv=none; b=hNnweHjf/2Nt1iPB64iiNKJ2eZKONgbdyUxEWvmYIWKS+WaBcW/VqrzjlmBIQrDHPoanAI4gTP2BBhYxOWzaWc51Mx/upofJOZ+KA3jXWtpVvBnsIk3UATFusxKQA5Iav8LQAGtYLZhVCv4CJoCHah9+vH83m9Cg2yvSerrVhnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733276188; c=relaxed/simple; bh=Fe2tQ9m02I6JfppWG1r7EPIzo3auSyK5naADPlvnj+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N5kQbqBo08ZD4HVeEaFBTL+7NeTP6h74tHEsiwOnHFaWXXPW/ew3WDqJCpfE7fql3aMzTVxcVwsWsLu86qmQd/ABOCdkpojj0mFDKZKODIEDc4gmtqNdepjaieqatBVSX8KWdHfhc6KLTE09plmrPOJTgSfjxnaGPlpcMPGSMJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hoNZTpW/; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hoNZTpW/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733276187; x=1764812187; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fe2tQ9m02I6JfppWG1r7EPIzo3auSyK5naADPlvnj+I=; b=hoNZTpW/mv9fwifZfaeyFVNgCQOxRz88R7B2XeLYGc86p2OS3zbS08bW IzI/aD+EjOJZYK+k/fvJQ2l1rjvx75IrvBgizJOVYSwNZHRJxY/sEDqFv eqkYhT1G68zefddvlcE+kH3pFJ1fg+vbZIEzkQHOXuTbIEc7gS2sc7VxZ 9QRtPRw8tM7bl/KZJzNF/MgLR5AqqYUfy7dyWBKfo7+5EtVxtyQ9dX6Ve D1Lo6mIK/vtVm0rE1b+o2gRlzU8nSoD0sxpgb7BQ+CX6XJebBVqWVRYnM AV6DJEkC/+GmzV/r9j71z5i3tl0+NPEqFv+Wivt81Th8IfoyLnnWZYmm1 g==; X-CSE-ConnectionGUID: elyN3KfhTR+aQQB2W87Xfg== X-CSE-MsgGUID: X9zXaDH+RZK28b5Q+0xfDg== X-IronPort-AV: E=McAfee;i="6700,10204,11275"; a="37293581" X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="37293581" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2024 17:36:25 -0800 X-CSE-ConnectionGUID: tFDOS+nAQrqP0DQ5BJlrxQ== X-CSE-MsgGUID: Ta81aQz0ToGp4TLO6pGSQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,206,1728975600"; d="scan'208";a="98694833" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 03 Dec 2024 17:36:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3FF8EA6B; Wed, 04 Dec 2024 03:36:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Rosin , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 4/4] iio: afe: rescale: Don't use "proxy" headers Date: Wed, 4 Dec 2024 03:33:19 +0200 Message-ID: <20241204013620.862943-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> References: <20241204013620.862943-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update header inclusions to follow IWYU (Include What You Use) principle. Signed-off-by: Andy Shevchenko --- drivers/iio/afe/iio-rescale.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index bbc73798082d..067823a356d9 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -9,12 +9,16 @@ */ #include +#include #include #include +#include #include #include +#include #include #include +#include #include #include