Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2096240rdh; Sat, 25 Nov 2023 13:27:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrYAcGJnbnF8Ac64R4W5r0NUAbdhGPDyvUvI/auHdgdgertivofXZboSjR95efjLS9+EpM X-Received: by 2002:a05:6e02:12e5:b0:35b:4731:15f3 with SMTP id l5-20020a056e0212e500b0035b473115f3mr8295592iln.10.1700947660155; Sat, 25 Nov 2023 13:27:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700947660; cv=none; d=google.com; s=arc-20160816; b=1LE6f7XVmvFSam9z4JOyYiWT8n+ZdCRowYPCUP53izJ6LMlg9+BNUzK9as+rByDHuf ql6TIJMKxBZpC6nMEAwoTrI0qfv3F59ZR7m56MqjJNxHBQoJi8nP46d5VcwiRBnVwhRc jnV9z8EQq4e2dl7jPWXJO57e+3Wy28ZDfcXxlXdFo/DBEsDGofU3tQv1eQ8+Jdrec1Hl qZZCOOGO4ASsM6grNi+MOOEUWsv+c4Ta4c/1j/HMj2c//ZAbtK1GeRDoFTeioMtJXRZl 5x0IKvaEYFgFE5eeR9VSrYGC/onpZE7rUmNmONuQfO3696EkicsPU/h0t5YKs5oFkB6h xWHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=X02zGjhQuwfxCdCE8WnNqfJdr7djRtz+1k91SJ9Klbs=; fh=FYOMPJxvCxKD1LfvVKGRrLk4H//41SSqlU+v038B8iM=; b=LtodUqSstIxI4a6coavNXOeXEkSogQPnYmA0kCUhBfaTuYreqmLGcyzXc7tKHh9hC0 7mRkXptFV2Y70YSDzGR6h6dOTIDjpzmHtCvQ3Fndd3n21XVDLXXQuseHXMooNIyLxdyW v674qOKr28sdkQShgBFB5PNImc09SpCgISiL0wjCr5g/e5LVIyXeEV6qN6/50lvQWBIp VhA6zIoPJHelfZsIia63aafi3lpASos93cixrQ9TjqYgncN2fXk9/ABNrKcXDU5bq+vx qrsICNZ4AcbzUfQMdM2GRRlXLfFvA/eGBCl9BfvFjCu7U8/1AY0PX4KTLyVbGDl6DDfl VL6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=m7ne2YBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=melexis.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id n128-20020a632786000000b005b8f38f9976si6453995pgn.765.2023.11.25.13.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 13:27:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=m7ne2YBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=melexis.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B21E3801F12C; Sat, 25 Nov 2023 13:27:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbjKYV1V (ORCPT + 99 others); Sat, 25 Nov 2023 16:27:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjKYV1S (ORCPT ); Sat, 25 Nov 2023 16:27:18 -0500 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38206193 for ; Sat, 25 Nov 2023 13:27:24 -0800 (PST) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1f060e059a3so1832055fac.1 for ; Sat, 25 Nov 2023 13:27:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1700947642; x=1701552442; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=X02zGjhQuwfxCdCE8WnNqfJdr7djRtz+1k91SJ9Klbs=; b=m7ne2YBZm/oLfO56OJs1BRKWp5Gsz7lXY4wNyx5VDiiq4Xy/PjEgnAoKDfWj5kF61T twlWmEIMkPEoiVnDdPOq75xriTCFnbISPSGNpjSpzRk9ohem6YNrTtewZQ9P2UxBJ3Hi LtG68A7V1cAN84cpmFudpVBrvhp0iDbhCF8YG+jPJRoagNvEpl/U12HeZDUIOwptFS71 gKwcBmLqv2i7gJB+cyoaUEhL93MLrmzSADs6Yjf4pxfjSeVXapYD+Pt8JeAnT25cDfMm x3PPF0c3TDOO6lBB3RiiGpI+XBoB6diUVmb4FaWsHnOj576pnoqifa8vgNWwCoXaNbFF OgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700947642; x=1701552442; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X02zGjhQuwfxCdCE8WnNqfJdr7djRtz+1k91SJ9Klbs=; b=nn8w0PY8zBf6WAgF2l5KNYPyX1x85OtakyLf9HwR/yf8XvmZfAu0mwNAd4UaDwwXsQ KOYRmv63R42PxWmHz5uSGad68lEFNji+Zry7yYjhGimn89RmbelQEJcsuZoHs3ZCyCEi W8a5GBXu9NXNyuVsP53bPgp79v43wwElai8IRrfkHvOkj+870tYKA3MgLZuLly6YdQMf Ra9/08sk1pZT5uXjvVO2dmBfflO9jlK26Usb7AMG/7MrU+PUrY9eVdf7/yHXNU+YdVLn 1amVVAEc/Ll6j8/lhzne7n6XGKG9iAXgsGTufwNNtHFr9mwJSr5CzjjqRt6iLddce3s3 RthA== X-Gm-Message-State: AOJu0Yy+rWNNb77FlvV7jnSqP+eNkpXtXQpPlwk+RaDufcx1jZugeEG9 KZbrAlJlurWVmTYDeFxEwzF40duuyjmGnHWfTzMSksBeHcV7wDqnbpM= X-Received: by 2002:a05:6870:c1ce:b0:1f9:8f0e:1c56 with SMTP id i14-20020a056870c1ce00b001f98f0e1c56mr9029500oad.50.1700947642595; Sat, 25 Nov 2023 13:27:22 -0800 (PST) MIME-Version: 1.0 References: <20231125175318.25c0d6ea@jic23-huawei> In-Reply-To: <20231125175318.25c0d6ea@jic23-huawei> From: Crt Mori Date: Sat, 25 Nov 2023 22:26:46 +0100 Message-ID: Subject: Re: [PATCH 1/2] iio: temperature: mlx90635 MLX90635 IR Temperature sensor To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sat, 25 Nov 2023 13:27:37 -0800 (PST) On Sat, 25 Nov 2023 at 18:53, Jonathan Cameron wrote: > > On Wed, 22 Nov 2023 11:24:06 +0100 > Crt Mori wrote: > > > MLX90635 is an Infra Red contactless temperature sensor most suitable > > for consumer applications where measured object temperature is in range > > between -20 to 100 degrees Celsius. It has improved accuracy for > > measurements within temperature range of human body and can operate in > > ambient temperature range between -20 to 85 degrees Celsius. > > > > Driver provides simple power management possibility as it returns to > > lowest possible power mode (Step sleep mode) in which temperature > > measurements can still be performed, yet for continuous measuring it > > switches to Continuous power mode where measurements constantly change > > without triggering. > > > > Signed-off-by: Crt Mori > Hi Crt, > > Very nice. A few minor bits inline. > > Note (as normal for me), I haven't sanity checked any calibration maths - just assuming > you got that bit right as don't want to spend ages comparing datasheet maths to what > you have coded up + I'm not sure I can get the datasheet anyway :) > > Jonathan > Hi Jonathan, Maths I have unit tests where I did floating point (which will be released as embedded library same as for 90632) to integer conversion and ensure that the delta is less then the error of the sensor. So math I take full responsibility :) Datasheet will be public probably in March, when hopefully the sensor is already part of the main Android kernel as well. But your review is anyway very valuable and detailed. Thanks for all the remarks - there is just one discussion below I would love to complete for future reference. Best regards, Crt >> ... > > + if (ret < 0) { > > + dev_err(&data->client->dev, "Powering EEPROM failed\n"); > > + return ret; > > + } > > + usleep_range(MLX90635_TIMING_EE_ACTIVE_MIN, MLX90635_TIMING_EE_ACTIVE_MAX); > > + > > + regcache_mark_dirty(data->regmap); > > + > > + ret = regcache_sync(data->regmap); > > + if (ret < 0) { > > + dev_err(&data->client->dev, > > + "Failed to cache everything: %d\n", ret); > > + return ret; > > + } > > + > > + ret = regcache_sync_region(data->regmap, MLX90635_EE_Ha, MLX90635_EE_Gb); > > Why is this needed given you just synced the whole thing? > Well, this is the discussion I wanted to have. I expected regcache_sync to perform i2c read of all the read_regs defined in regmap to get them to cache - but it didn't. Then I expected the same from sync_region, but it didn't, so I manually read them below. So discussion I want to have is: why would we regcache_sync, if no reads are performed? And second one is why would we return EBUSY for volatile register range when cache_only is active? Current driver implementation is very specific in bypassing all these, so I am quite certain this regcache_sync_region here is not needed and below regmap_async_complete as well, but I cannot be sure, since regcache_sync doesn't really do the job I would expect it to do. I looked into the code, but could not find the reason, why I do not see any reads on oscilloscope and why I need to physically read registers below, so that they are cached. regmap totally knows which registers it should cache, but it does not at init, nor at regcache_sync request. And if you remember in 90632 I had a similar remark, but could not reproduce as EEPROM was readable in most powermodes (well all used in driver), now I checked with scope and since I know this chip does not allow EEPROM reading during the step sleep mode, so everything was much easier to conclude. > > + if (ret < 0) { > > + dev_err(&data->client->dev, > > + "Failed to sync EEEPROM region: %d\n", ret); > > + return ret; > > + } > > + > > + ret = mlx90635_read_ee_ambient(data->regmap, &PG, &PO, &Gb); > > + if (ret < 0) { > > + dev_err(&data->client->dev, > > + "Failed to read to cache Ambient coefficients EEPROM region: %d\n", ret); > > + return ret; > > + } > > + > > + ret = mlx90635_read_ee_object(data->regmap, &Ea, &Eb, &Fa, &Fb, &Ga, &Gb, &Ha, &Hb, &Fa_scale); > > + if (ret < 0) { > > + dev_err(&data->client->dev, > > + "Failed to read to cache Object coefficients EEPROM region: %d\n", ret); > > + return ret; > > + } > > + > > + ret = regmap_async_complete(data->regmap); > > What is this syncing here for? Several calls above include internal calls to this. > My knowledge of this stuff is limited, so I may well be misunderstanding what this does. > > > + if (ret < 0) { > > + dev_err(&data->client->dev, > > + "Failed to complete sync: %d\n", ret); > > + return ret; > > + } > > + > > + return ret; > > +} > > ... > ... > > + mlx90635 = iio_priv(indio_dev); > > + i2c_set_clientdata(client, indio_dev); > > + mlx90635->client = client; > > + mlx90635->regmap = regmap; > > + mlx90635->powerstatus = MLX90635_PWR_STATUS_SLEEP_STEP; > > + > > + mutex_init(&mlx90635->lock); > > + indio_dev->name = id->name; > > Not keen on doing this as it can be fragile if id and of tables get out of sync > or we are using backwards compatibles in dt bindings. > > Given only one part supported, just hard code the name for now. > Can you elaborate? Because I have the same thing in 90632 and I would fix there as well. I assumed this is for linking to dt, to ensure it is defined there? > > + indio_dev->modes = INDIO_DIRECT_MODE; > > + indio_dev->info = &mlx90635_info; > > + indio_dev->channels = mlx90635_channels; > > + indio_dev->num_channels = ARRAY_SIZE(mlx90635_channels); > > + ... > > > + if (MLX90635_DSP_VERSION(dsp_version) == MLX90635_ID_DSPv1) { > > + dev_dbg(&client->dev, > > + "Detected DSP v1 calibration %x\n", dsp_version); > > + } else if ((dsp_version & MLX90635_DSP_FIXED) == MLX90635_DSP_FIXED) { > > FIELD_GET() for that bit then just check if it is 0 or 1 > > > + dev_dbg(&client->dev, > > + "Detected Unknown EEPROM calibration %lx\n", MLX90635_DSP_VERSION(dsp_version)); > > + } else { > > + dev_err(&client->dev, > > + "Wrong fixed top bit %lx (expected 0x8X0X)\n", > > + dsp_version & MLX90635_DSP_FIXED); > > I'd like to understand what breaks if this happens but we carry on anyway? > I'd 'hope' that any future DSP version is backwards compatible or that there was some way to know if > the difference between backwards compatible versions and ones that aren't. > The top bit in high nibble is fixed to 1, to ensure that we have endianness correct in the wild. We did the same later on in 90632 where we had plenty of trouble the way people read 16 bits. So if that top bit is not there (bottom nibble has it hardcoded to 0), then for certain we do not have the correct chip. And as for compatible DSP versions: when we release incompatible one, I will upgrade the driver, otherwise we have some more slack in the driver to keep on working, because that was also lesson learnt from my side in 90632 as there are compatible DSP versions possible and used, but we are still honest and bump also the DSP version here. > > + return -EPROTONOSUPPORT; > > + } > ... > >