Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1668272pxv; Fri, 23 Jul 2021 14:19:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqtUOhibcAJ9AYkKDuGO+nJXB3MEmZi5j8K/Azuzv5AJ4rDb6CW2ImHVXaNFx2N8m18BLX X-Received: by 2002:a05:6e02:12ea:: with SMTP id l10mr4742684iln.130.1627075158214; Fri, 23 Jul 2021 14:19:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1627075158; cv=pass; d=google.com; s=arc-20160816; b=WVeAidwQe5yhNlC+MusPfNCnl0JidQnjtfJtHn3AlD6d+pvjXVJGEEtRS6cB22JNfK yJGPXblTxaftsmT41cihE08kuOF5FCJPmuFlf3muWVWu/Nio0FZpU4Ma3V9jvm2MFwpV 0NPcq05IJpxdaNd5bul899//Cmt9U8qQI+49WVMsf3MsWxLza1bjnSdtcWAtKTaqpc2n KDgs7hUBZ+Jl1QYy2G91F5vNJ/bJUa/YqRVsXRMw+wR+26JxY0dSkAbqbSFVqa9w4EDF CTFOFCu0c9uhYwHSc2qLkbqvqWPe7LWN/z2lDJPxxivJzcEmUhif+o9WtcVYDvW75PBd NLFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id :organization:from:references:cc:to:subject:dkim-signature; bh=S5Savn5lKyr7Ob5tpIFCf+s7i0d6Q25vYuwA8NmYrO4=; b=LasxZwRg6GfnHfm24OoqZFQXQHuQwDVFWzPM1HDPhOEIE5xj3CxXyb6a8PvnYFGGT3 79QcS/DMxWwye/KMmwmpkBBStG0+OhbDsbUAczpeqdCY1dxGZv19nwFgipi0/6eKsZC+ /p3C/QJjKRumQIo8yPV01dJgAiy0ZRKSP7sInqkL+OEXCHYFlD3kT7rg5uIUl01le+oe VZmYOG2Y6cCxxHR4UdnV2I2HRV2vrogRY3UJaj0vtARSdWZHhN7WTv44Q9RRcnoUSmhy yHFXPWcuUoNJCq9BUOMyzZTuHEibIZsVTE9sHofVNb5Ixz2Or3Cxb25HwrOp6ozuIFLz fvsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@axentia.se header.s=selector2 header.b="S/iR3HJU"; arc=pass (i=1 spf=pass spfdomain=axentia.se dkim=pass dkdomain=axentia.se dmarc=pass fromdomain=axentia.se); 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 p31si38566410jac.95.2021.07.23.14.19.06; Fri, 23 Jul 2021 14:19:18 -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=@axentia.se header.s=selector2 header.b="S/iR3HJU"; arc=pass (i=1 spf=pass spfdomain=axentia.se dkim=pass dkdomain=axentia.se dmarc=pass fromdomain=axentia.se); 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 S231383AbhGWUg2 (ORCPT + 99 others); Fri, 23 Jul 2021 16:36:28 -0400 Received: from mail-eopbgr40108.outbound.protection.outlook.com ([40.107.4.108]:23107 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229648AbhGWUg1 (ORCPT ); Fri, 23 Jul 2021 16:36:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CWFu6d6mlXuaHBnpUpLgZy0oTL16x2TXyt+fgAxpy5XlI2cvDa2EHAvb9PEshPzGdwhjdZGbft1D/zskOiQesM+oobLp/yPOm80mm5fYNw87PuJ+zJEnr5XiXQln0XpMm2+M2fGe+PhfpndFyO6FIH6I7GJLz0yxrHAprrvDJAHRe5wMvRAf4g6u/d4RLIheDEjpFkrISJVrtbsLa0YiemFygyA5fTLKiwpjVFY2Aovva1DMwET1XHvOM75GFFgJrzJjTbq3pSk3+lGFL2NaWQCf5wA/CApdISiGT4nrOS2Im+VjjXXX/9COO+iv80GkXg3y0kTHXmRhb7sfuSI7HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S5Savn5lKyr7Ob5tpIFCf+s7i0d6Q25vYuwA8NmYrO4=; b=QEwHyWz9EDnHdBC/ZLh+hd4t1bHktPCS4J3tT4CO6s2o/VoLQrg838uRHEaXtmgz/eci8fuxhYvUwrBBNEPTxt0tzcb7sfaztaDLiLoqzGhSlukrT47Ch+Umndn/bxRT+DZUf9CT5EVTHDuPHZROTuh0mHa7EInLtv70h9Kmw7arPGTi+uVKC0+LiYPrmwyejYHPGHhCz/qfT9zFbkHifBg/v2+rYILyoQ3WVEvyqKYmQaETWQcSBUwMa/OGAzop7tv/KMouawTkGaEG3aGPb8f/toMeqmvJ4yUAEIPdLiikJfqq5nOZzBu3k42CzqooaWfBY7yneuDfyDWRM8mO3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=axentia.se; dmarc=pass action=none header.from=axentia.se; dkim=pass header.d=axentia.se; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentia.se; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S5Savn5lKyr7Ob5tpIFCf+s7i0d6Q25vYuwA8NmYrO4=; b=S/iR3HJUe4QwNa+ZyVAxOhFcCG5lWFa7Ejr0JU9FMpcayr02K2eYitxxRvaD3bdbZJuCDvhf0PI12NfJQemCWqJMd/JhQXRmwoAwi6wNrR2rVDFsPcZeyk8+szGoVKc66Hc8Yr+5hp0zUL76usbnzbb54UzQiz+cAcp/OkrWtDo= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=axentia.se; Received: from DB8PR02MB5482.eurprd02.prod.outlook.com (2603:10a6:10:eb::29) by DB9PR02MB6747.eurprd02.prod.outlook.com (2603:10a6:10:1fb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24; Fri, 23 Jul 2021 21:16:57 +0000 Received: from DB8PR02MB5482.eurprd02.prod.outlook.com ([fe80::14ca:a41:2218:3578]) by DB8PR02MB5482.eurprd02.prod.outlook.com ([fe80::14ca:a41:2218:3578%6]) with mapi id 15.20.4352.029; Fri, 23 Jul 2021 21:16:57 +0000 Subject: Re: [PATCH v6 05/13] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support To: Liam Beguin , 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 References: <20210721030613.3105327-1-liambeguin@gmail.com> <20210721030613.3105327-6-liambeguin@gmail.com> From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Fri, 23 Jul 2021 23:16:53 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 In-Reply-To: <20210721030613.3105327-6-liambeguin@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: HE1PR0701CA0090.eurprd07.prod.outlook.com (2603:10a6:3:64::34) To DB8PR02MB5482.eurprd02.prod.outlook.com (2603:10a6:10:eb::29) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.13.3] (85.229.94.233) by HE1PR0701CA0090.eurprd07.prod.outlook.com (2603:10a6:3:64::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.7 via Frontend Transport; Fri, 23 Jul 2021 21:16:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 358fa80d-0d60-4022-3c09-08d94e1f33c4 X-MS-TrafficTypeDiagnostic: DB9PR02MB6747: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k1jvVlRQoxp7e33bmgz7xm8BvHOjnleE6PxEj0bOe36zId2VtZryFBAqGYE1dpYHADGPAMruQtux6sqDYo/GMKSTQup015HdPWdPCZEc+Ga1spZ8Nn96X3QZ2Q8F20qliTfdHK/kn3zU8lkw+fWfEAMCzXFEfZbFnOzQLz4sD8mk2xg6DGM81GIjGGUepST1qQlVM4ZlIzyJeiRyyn048/U2A5k7Iw3aqyhrvkWVkktKsBmEStef5YnANaVmQ3ZTo+UQxNUgIDFK64Ld2rEJhr3y6kQlc3rmwFMhHDBsurZB0gI/6bHqvOhxBJd4+zKm4fT6/bR7rsQTM59ybYluxxkim/FoWTRO/BRFXfZqcCT8Xf4KCALyTXVQ0OQGLUdnZFRx3w2RsF3LbCrdqwWh9gpvHw6bhvcoC14SJew2cfyGtQDHttzJNILWiBkcZ35I+crUZhCVqGM9wCeAnAWGQECsalkHe5PKuo97hP02kzYxneVn4ztdJzFwimiljLyBPaIAVdWY7T1RX6PIXb3l95ITtddfgGH3mP6pw7U+xf41Ck+Ayn7KaLMqWrdd7pc8b4Bs01WglZjjNAqTcsQSi5fcun0I/Uo9euuNa0zBJZN5+b5SPyYu3VWTy2Fw3IwfORyEvCEtw2dQ6VOpHMhtu9rX8N0kJAVCKVOoGTT3isjNF0RrOR5zTV6f1rpkA9XqcGEoE8zWKXfV7aVWhZ7chck8rWJwBDYQIYR+29PuTIc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB8PR02MB5482.eurprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(39830400003)(366004)(376002)(136003)(396003)(346002)(478600001)(956004)(16576012)(5660300002)(316002)(36756003)(2906002)(31686004)(53546011)(36916002)(8936002)(2616005)(4326008)(86362001)(8676002)(66476007)(66556008)(6666004)(31696002)(66946007)(186003)(6486002)(26005)(38100700002)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UnpzMzZvN3hNaDdldTRKcU5GbHRiTkp3VmYwb3hncUE1bHEyamFHbnhKbTZX?= =?utf-8?B?RmdYVWlaeUpIV1h2ek85dnk1U09aS0ZSam5RN1NqdlZGeEtPVHNlTVB5cmxN?= =?utf-8?B?ZjNJWXBiUVE3MWJFeHZKWkxuNU1zQjFaRThJc2N2bU1wcFBlYlJRaGxVVURD?= =?utf-8?B?YkdRWlVFaHFvUzJqT1psb25wVUxYMTJtZXR0R3hVb3lFb1ZSbHYvYXFFSkpL?= =?utf-8?B?cFVoc3ZJUi9mY1JQKzFLbVMwM0NtMDJHWkdvbEZuTDJnYk93dHJKdldxbXFS?= =?utf-8?B?TnpkSUhPaHkzOGdUUEppd2ZqYmcvNkVmMVNKUWFZazZQUlRpNlRMbGwzOExZ?= =?utf-8?B?bHRCR1FEZmVlcTR6TmhsMnNnd1hFTS8vN2Npd2l5YXJrb1lNU1B1VlBtb3Ro?= =?utf-8?B?cUEwSlRCZGlWYk1tYVZYS1ZIMUtCeVhFMG16b0p5U0h5MVFTTXBoRjZlUU9S?= =?utf-8?B?SENtTkY4U2VCK2VRRERiRHJqOFVSVk5BUW1iTmE0K3d3WjRUQ1VqSXZFOTJF?= =?utf-8?B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TUNFSlhSR1Vs?= =?utf-8?B?NU1JUVNrdldRU1MwRENhK0hja1Uvb0R3bFZuQjBzOHdYZS9vRkFLQzNKRGpR?= =?utf-8?B?RUdlK3FRc0prM1h1OENKZHNwZ2V1WEJQYndWRDhyZTNMTW93NXFhdGlJVXNS?= =?utf-8?B?ZVlIQzYvdWNHcGtWeHZFKzYxQkkxZnA5Ym9Ma21jN0VrT3kxcUdVNXR6MzV0?= =?utf-8?B?VTY4cEc0d3pYSlRxSFBZM3h0SWFwZ25Cd0VVbGsyZEVwZ2pPU3hUcm0xaGNj?= =?utf-8?B?dHUyblRlV0pBN2Nlc0lvVEZDbUdMbFh5UzdMZ0pQRTg5RGN4Y0xOOVJ0dm4w?= =?utf-8?Q?igPHT0TlsUdiHYTH+hsiM2rvKk4ItjF2fJf5twz?= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-Network-Message-Id: 358fa80d-0d60-4022-3c09-08d94e1f33c4 X-MS-Exchange-CrossTenant-AuthSource: DB8PR02MB5482.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2021 21:16:57.1075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: R8tfDSGvWjOm3bSRf1V+ASiJ7fj36OTANgL0b19PvvFwzJjn7MXww+a17NpHuUn2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR02MB6747 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-07-21 05:06, Liam Beguin wrote: > 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; Hi! My objection from v5 still stands. Did you forget or did you simply send the wrong patch? Untested suggestion, this time handling negative values and canonicalizing any overflow from the fraction calculation. neg = *val < 0 || *val2 < 0; tmp = (s64)abs(*val) * rescale->numerator; rem = do_div(tmp, rescale->denominator); *val = tmp; tmp = rem * 1000000000LL + (s64)abs(*val2) * rescale->numerator; do_div(tmp, rescale->denominator); *val2 = do_div(tmp, 1000000000LL); *val += tmp; if (neg) { if (*val < 0) *val = -*val; else *val2 = -*val; } > + case IIO_VAL_INT_PLUS_MICRO: > + tmp = ((s64)*val * 1000000LL + *val2) * rescale->numerator; > + tmp = div_s64(tmp, rescale->denominator); > + > + *val = div_s64(tmp, 1000000); Why do you not have the LL suffix here? Cheers, Peter > + *val2 = tmp - *val * 1000000; > + return scale_type; > default: > return -EOPNOTSUPP; > } >