Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp223525pxa; Tue, 11 Aug 2020 00:57:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBEachoWpyA7ntdO7P1EiGHPdLngwPfPVzyD4ipOvp7zePSdkQGWPYXyivcq6ECMY6Z688 X-Received: by 2002:a05:6402:2206:: with SMTP id cq6mr19334114edb.349.1597132678921; Tue, 11 Aug 2020 00:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597132678; cv=none; d=google.com; s=arc-20160816; b=xYE67zQBufdWAhZi8Uq9x1GrcZ4cgMbo4+umr4p/kqsmwZYpSPn21SXLEMQsUpmdwj 1QcHMNZ2qaaKbWQ3K3gb5Pe+FaOHUqP+KZ6pzTDxRtXZrtqgemWVqslMwLRmwzIRgqos QYg2cLA8S61XHapN6pmlNWRKy/0p3dUgzNLmUB0FhFuHS3FI3SbhVN2a2OUlj/cQkIsk 4UNKpJku+m9QF9q/S4439p3UwlPUmL4Dv95+s5500MobnvFiSmafXs4anXv+bWJ0R5b+ sJizExV888r0w/phpucPdhe7i0WSQcNFffe2dv6Z9PUC6UeiU6RLmkvA9V/150nkWKnD tqbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Z5wWPMoezqlPQW+XdXx9xDErG0vZ5Ug+GxrnTbtmQ7M=; b=Rg7EpA8/ceJCx2vcpLUOJ869Dn+5vFIwOUOL1afqxYyk7wUATHVJmmmuYVqTddYJR3 KOaOCPTTWqmWHf7cr4HDYr6UYXnY5uTaBjhRrreIelPEJEUzW2NNZXxMpb0PX9i4GFhg MnZL+xTPrdhW9dpRAWOurTPAc7P1qDILj90ZNpojwCWz2egGdztD1maIaYJFBNrSJNp5 wDvCLwta+AXQ0CqJF1aXOES2lSS1XnhtlrVUKcPsS7jgYwV8H8lewao2Uznl4dg44tyH EyhL4hoYAHMBT+NnoC9H2QBP49FBXWIidxpsz32RBRaTmQJmNYAnbI4xeTpA7ZxYv/+5 LECw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=AWg5Or5Y; 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 x8si12169382ejs.414.2020.08.11.00.57.35; Tue, 11 Aug 2020 00:57:58 -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=@melexis.com header.s=google header.b=AWg5Or5Y; 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 S1728208AbgHKHyf (ORCPT + 99 others); Tue, 11 Aug 2020 03:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728133AbgHKHyd (ORCPT ); Tue, 11 Aug 2020 03:54:33 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BB02C06174A for ; Tue, 11 Aug 2020 00:54:33 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id y18so9786949ilp.10 for ; Tue, 11 Aug 2020 00:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z5wWPMoezqlPQW+XdXx9xDErG0vZ5Ug+GxrnTbtmQ7M=; b=AWg5Or5YERYKPYus/eM6Psz/6DB+ozbeyIgm5BdkcNrz+qaXydnw5C9h2yoNvdDN5L BVwNYvfnGupyhB3fNudXRx17vToJsrp/WuFz7OccXouv5EOMlCDhKyQf7arOLvEgKskr CHcdKTyQDaZXTITMAdPG1+EqwrysS4FjRXFq250kG9RyuPLfOcHhaxHzbop867temC91 HgjqFt4KcdcPJmq7FOCUhWbGmRQXhBFFXtn4eYrvOXDDrYHUFDdiCo79izc/XOb+Nm1G ZvIkJlOL1BHQdPwPAOneQ41ySPYmks5pmre/t7gxMA0veF6Q25TcnXlzhJ/O5GfmhkfZ IhAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z5wWPMoezqlPQW+XdXx9xDErG0vZ5Ug+GxrnTbtmQ7M=; b=cN4CxCTp38xdDKWDcLWuKj0OKrJrb2/o61KBmhtnDFBUI3ryfCaSCfRcWB5UNOpibK YfTv8PcORPcD2r1HTMUHpWt3Y05QM5y2P8nlcXgZX+atRLeYumxZtcVsQDlpZgzR5ziS yYtNEQ58420iwdExA5gpVgM7WIkAWo61elwC1ytbzYxcll/Tsx2Ey2d2lIE+VYHsJl1Y WaYfKXzTVpiALi+qJx10cBZ36KkXRNhVCLPgg5iaWLzl18CAJJ9LkkUwR1NF10hi0pzQ A4HzPQ49K/cnOm/kRr4NyZlALw7M/9nbk2vtaebHEdL5zBfDvqMmogwnOBC1wL/8LpqG pkzQ== X-Gm-Message-State: AOAM5334F54viOpSpAlyNyAlv6w5RT8CoC103Mh/tcNb2W9p+OhFL6+k xQ33QhFWuIi6CA0Ih6NNHl51BRLPnZB9kUt0BFmAMw== X-Received: by 2002:a92:cb12:: with SMTP id s18mr5277285ilo.13.1597132470806; Tue, 11 Aug 2020 00:54:30 -0700 (PDT) MIME-Version: 1.0 References: <20200808121026.1300375-1-cmo@melexis.com> <20200808121026.1300375-3-cmo@melexis.com> <20200809143222.4e19ea38@archlinux> In-Reply-To: From: Crt Mori Date: Tue, 11 Aug 2020 09:53:55 +0200 Message-ID: Subject: Re: [PATCH v4 2/4] iio:temperature:mlx90632: Adding extended calibration option To: Jonathan Cameron Cc: Andy Shevchenko , linux-iio , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 9 Aug 2020 at 23:05, Crt Mori wrote: > > On Sun, 9 Aug 2020 at 15:32, Jonathan Cameron wrote: > > > > On Sat, 8 Aug 2020 23:57:59 +0200 > > Crt Mori wrote: > > > > > Hi, > > > I am very sorry you missed them, I thought you saw it (reply on v3 of > > > the patch). Maybe something happened to that mail, as it contained > > > link to datasheet, so I will omit it now. > > > > > > Except for the order, only the remarks below are still open (did you > > > get the polling trail I did?) > > > > > > On Sat, 8 Aug 2020 at 22:04, Andy Shevchenko wrote: > > > > > > > > On Sat, Aug 8, 2020 at 3:11 PM Crt Mori wrote: > > > > > > > > > > For some time the market wants medical grade accuracy in medical range, > > > > > while still retaining the declared accuracy outside of the medical range > > > > > within the same sensor. That is why we created extended calibration > > > > > which is automatically switched to when object temperature is too high. > > > > > > > > > > This patch also introduces the object_ambient_temperature variable which > > > > > is needed for more accurate calculation of the object infra-red > > > > > footprint as sensor's ambient temperature might be totally different > > > > > than what the ambient temperature is at object and that is why we can > > > > > have some more errors which can be eliminated. Currently this temperature > > > > > is fixed at 25, but the interface to adjust it by user (with external > > > > > sensor or just IR measurement of the other object which acts as ambient), > > > > > will be introduced in another commit. > > > > > > > > The kernel doc patch should go before this patch. > > > > > > > > ... > > > > > > > > > + *ambient_new_raw = (s16)read_tmp; > > > > > > > > > + *ambient_old_raw = (s16)read_tmp; > > > > > > > > Sorry, did I miss your answer about these castings all over the patch? > > > > > > > > > > These castings are in fact needed. You read unsigned integer, but the > > > return value is signed integer. Without the cast it did not extend the > > > signed bit, but just wrote the value to signed. Also I find it more > > > obvious with casts, that I did not "accidentally" convert to signed. > > > > Should we perhaps be making this explicit for the cases where we > > are sign extending? That doesn't include these two as the lvalue > > is s16, but does include some of the others. > > > > sign_extend32(read_tmp, 15) > > > > So for you lines like > s32 read; > read = (read + (s16)read_tmp) / 2; > > would actually be better as: > read = (read + sign_extend32(read_tmp, 15)) / 2; > > Hm, strange. I would read that more align the read_tmp to 32 bit than > the value you have in read_tmp is actually a signed 16 bit integer... > OK, I did some trails without the casts and had deja-vu from the first series of patches I submitted. I noticed that without a cast the value that ends up in variable is not extended to signed, but it is unsigned value truncated. This same finding leads to have these casts already in current ambient and object raw read functions. So now only debate is if sign_extend32 is useful in this case, as read in the current case is 32 bit (before it was also 16 bit). My preference is to leave unified across the driver. > > > > > > > ... > > > > > > > > > + ret = regmap_read(regmap, MLX90632_RAM_1(17), &read_tmp); > > > > > + ret = regmap_read(regmap, MLX90632_RAM_2(17), &read_tmp); > > > > > + ret = regmap_read(regmap, MLX90632_RAM_1(18), &read_tmp); > > > > > + ret = regmap_read(regmap, MLX90632_RAM_2(18), &read_tmp); > > > > > + ret = regmap_read(regmap, MLX90632_RAM_1(19), &read_tmp); > > > > > + ret = regmap_read(regmap, MLX90632_RAM_2(19), &read_tmp); > > > > > > > > What so special about these magic 17, 18, 19? Can you provide definitions? > > > > > > > When we started 0 to 19 were all open for access, from userspace, then > > > only 1 and 2 were used with calculations, and now we use 17, 18 and > > > 19. Matter of fact is, I can't provide a descriptive name as it > > > depends on DSP version and as you can see now within the same DSP > > > version, also on the ID part. While RAM3 vs RAM1 and RAM2 could be > > > named RAM_OBJECT1, RAM_OBJECT2, RAM_AMBIENT, knowing our development > > > that might not be true in the next configuration, so I rather keep the > > > naming as in the datasheet. > > Normal solution for that is to version the defines as well. > > > > MLX90632_FW3_RAM_1_AMBIENT etc > > When a new version changes this, then you introduced new defines to > > support that firmware. > > > > OK will add those, but it is ending up as: > MLX90632_RAM_DSP5_AMBIENT > MLX90632_RAM_DSP5_EXTENDED_AMBIENT > MLX90632_RAM_DSP5_OBJECT_1 > MLX90632_RAM_DSP5_EXTENDED_OBJECT_1 > MLX90632_RAM_DSP5_OBJECT_2 > MLX90632_RAM_DSP5_EXTENDED_OBJECT_2 > > ok? > > > > > > > ... > > > > > > > > > + int tries = 4; > > > > > > > > > + while (tries-- > 0) { > > > > > + ret = mlx90632_perform_measurement(data); > > > > > + if (ret < 0) > > > > > + goto read_unlock; > > > > > + > > > > > + if (ret == 19) > > > > > + break; > > > > > + } > > > > > + if (tries < 0) { > > > > > + ret = -ETIMEDOUT; > > > > > + goto read_unlock; > > > > > + } > > > > > > > > Please avoid ping-pong type of changes in the same series (similar way > > > > as for kernel doc), which means don't introduce something you are > > > > going to change later on. Patch to move to do {} while () should go > > > > before this one. > > > > > > OK, will fix that ordering in v5, but will wait till we solve also > > > above discussions to avoid adding new versions. > > > > > > > > > > > -- > > > > With Best Regards, > > > > Andy Shevchenko > > > > > > And about that voodoo stuff with numbers: > > > > > > Honestly, the equation is in the datasheet[1] and this is just making > > > floating point to fixed point with proper intermediate scaling > > > (initially I had defines of TENTOX, but that was not desired). There > > > is no better explanation of this voodoo. > > > > We all love fixed point arithmetic :) > > > > Jonathan