Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5116611pxv; Tue, 20 Jul 2021 20:14:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrPQMvrHgmhYzobGSysJeM0nZJEXHz3HOC+8PFy2fT2zJ5v0WrvWCEys7DSlx/SG245S53 X-Received: by 2002:a17:906:4745:: with SMTP id j5mr36200518ejs.75.1626837241999; Tue, 20 Jul 2021 20:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626837241; cv=none; d=google.com; s=arc-20160816; b=tPamJloLcL7njlm9mnzfsUUCei4WsSxJxNWocxTFu+oSIwXPm0X6eBY6HvbbkZkL4T zp/f1H/vKKaYGTjx80T04p0nm3HpPypLq1boRE94KqlA2uNY9vd5CN2L8F9KxAyOvg+I 85n/YKklkoh4fFuV+qrY8BsvExHejlBLuNI/s9TV9zFA4VKSNbCw8PhuvKxAn27rIYTD qxYU/jPg3MkcyiEe8GdZ19JnFDtyLZbXDXsnHTKqo1T8yawIM6AcFsaHZioixLUQMmm6 4NYmtX2AhIhmCTQ6yIP2aKoOGpbZs14eBIe/fx8IupXhwoCQ3DJsxpEexRdqiqSfXnLi sppw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KxRWxmUWooh8K8wECdDWjv2qMB1v7LjacHyh+1GZlIs=; b=LfaQDyF2+OhCF6UJDiT9peZcFXGJtiV9TS/QuLKUbTXgI1ZGj0Ovk6anziTG47kwsA hlLIiym414A3FoEJPFh0pRXlGI7nI84ZRkjiOXGhbMSmTa/IVuoWYmJyaMiIUMGB0/1k UwxSEofvJV9NxiNfju30EwWIht/LaqKz0H09+YLmplVTgZnjV3aQcNO5bakT7llFoDAq gBxdb+oBlcfXBDsGDneNDvyusiqn745SkaKu04Oncnu/PpBVCqT3ELLK/zV2u9xiVPTQ AN8reY+WR+4kwwMhgI6EPa6oFaJ/6gK/W4TCsrHCAU3MinHrY5xmD9En+ZHZQi9djJov cuJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="jG7T/o6a"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si26149905edx.566.2021.07.20.20.13.38; Tue, 20 Jul 2021 20:14:01 -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=@gmail.com header.s=20161025 header.b="jG7T/o6a"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbhGUCb0 (ORCPT + 99 others); Tue, 20 Jul 2021 22:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231432AbhGUC01 (ORCPT ); Tue, 20 Jul 2021 22:26:27 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF8FC061574; Tue, 20 Jul 2021 20:07:05 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id ay16so282612qvb.12; Tue, 20 Jul 2021 20:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KxRWxmUWooh8K8wECdDWjv2qMB1v7LjacHyh+1GZlIs=; b=jG7T/o6af+b1FGPAiPh53sHSINRFk6kcIBKwTZ6RDWSgRqEclxkI42G6t3wsSgKDBX /BQpGNps3TOb34oUWrmOVluFYccEAxAwXY6jFypNvMmYtnOQJI1i1I59xoOWGLWHAaF6 31NnBl60aMIw382WEozMGYQLpqvaNmJOGTDgKZQzlSlAnhpP1e5lC0e9/kQSxVJgFlcg +wGtNMGRX6jXdV7sveuDZ1a8Nm//i6RqnPnLO/Cvcdm0DMuCGYXlxbAzCu0t2ye3tELi BS6IRR6d3+BxwBODc8fQCciRaQ2g8yvP3UxSYO/rbZTVXTcvt7yVTjn6J/rcivk2X/Ro 8uVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KxRWxmUWooh8K8wECdDWjv2qMB1v7LjacHyh+1GZlIs=; b=WPRw3TD1zxpdGNCW/RFHZnjM/AWFOYB0LyQsjBNQ6H61IE8pra64eVZTWmbRjHoeiO aPC375ZHB7ekCOg03oQY/OnNjCGI7qSmFql9cu1k6jV5Xx46dwqU7MDs3jUL7RclWh1E 1OjakvIB7QKSmz60v2saN7pjBb+xXhJvGwzppnMMAV6meZtIVWeB+xd48jeUSSiM9Wut peYezumePPVwHrXf8ElXYm3TlVuYS+AKzxJT1ysReZGqSwvZyulzRCDpq57LmJSl7fmF otnYSco75bRBoWtttBWDfLrKKX5I9w39qhS5AHjP2lQXarn43rHQi1lsqjryzabCum31 4APA== X-Gm-Message-State: AOAM533he1zcpCO9P0sp8ga9p2z4a1JneYTKOqeU7G9lf4CPKGtHDpxz lU/tVc5aySlmf0XmwjDDMY4= X-Received: by 2002:a05:6214:242b:: with SMTP id gy11mr33839017qvb.9.1626836824487; Tue, 20 Jul 2021 20:07:04 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id g76sm10561024qke.127.2021.07.20.20.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 20:07:04 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v6 05/13] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support Date: Tue, 20 Jul 2021 23:06:05 -0400 Message-Id: <20210721030613.3105327-6-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210721030613.3105327-1-liambeguin@gmail.com> References: <20210721030613.3105327-1-liambeguin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Beguin Some ADCs use IIO_VAL_INT_PLUS_{NANO,MICRO} scale types. Add support for these to allow using the iio-rescaler with them. Signed-off-by: Liam Beguin --- drivers/iio/afe/iio-rescale.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index d0669fd8eac5..2b73047365cc 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -41,6 +41,20 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, do_div(tmp, 1000000000LL); *val = tmp; return scale_type; + case IIO_VAL_INT_PLUS_NANO: + tmp = ((s64)*val * 1000000000LL + *val2) * rescale->numerator; + tmp = div_s64(tmp, rescale->denominator); + + *val = div_s64(tmp, 1000000000LL); + *val2 = tmp - *val * 1000000000LL; + return scale_type; + case IIO_VAL_INT_PLUS_MICRO: + tmp = ((s64)*val * 1000000LL + *val2) * rescale->numerator; + tmp = div_s64(tmp, rescale->denominator); + + *val = div_s64(tmp, 1000000); + *val2 = tmp - *val * 1000000; + return scale_type; default: return -EOPNOTSUPP; } -- 2.30.1.489.g328c10930387