Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4546582rwb; Mon, 21 Nov 2022 08:53:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5jKnKDMy4vJRfaSWeSzG9zMhecKyiZAs9A0cWOLhIPo+T13HsG1zPS+dPj/ZkrocDhAIVG X-Received: by 2002:a17:902:7793:b0:189:24b3:c86 with SMTP id o19-20020a170902779300b0018924b30c86mr197647pll.84.1669049636184; Mon, 21 Nov 2022 08:53:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669049636; cv=none; d=google.com; s=arc-20160816; b=sQWOrAShhsysTTe7hXDM27aEbR1TDPn6wY6A/uWo0egUJ4WALe1MRUwOU1YBCYn19T T8zoIOIR+dHmErtr9KIOEOjCggZkt2DFi/dl2Z5yHPsddNtAHxzQAjvlOv7uX+a3L4DW vPol1WQRgZ33UadFLpJqAUHtOabNS3kl+mNfM8BO3zPxUKJ41plt1T6f5mrf7MzzBqkn lnK1JcoF8lytj0B8mIDEi8hwWG6WjPhnEHjcWtFGmxjQKTV+6KJ7LVUC6k6ACvscL+jW KEnPiSl647aWeahqSJ8sTgatvVJpeBpv/NzIgI8ZbZBUKFSTKUFMUApTyFH2N7KCqcaB LrMg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=xl/FN5KoB7nmyZmXS9UtVhL91uSDXymEYb59rrJ8tcw=; b=RCczZwETJUzvjGQDB7g0f2DZn2A7pbQq8lxePHebImNl4Mqtu+Dr9lpCi0zr4LG4DV l24XiP3pM9sOPkxUU8/4Atad1NcJepU5kHHBUjILAVmaWUkx9GYrO1+OAjdAH+HYsGdy uiLLrTe7jHvegNke1y9/pE0x90FjdvgZT6fSTq+ShSCU4P0uCqTEbFa9r2ZrITQtmb53 6wXW1I2yY95p4mU7mJ7maJoSn0b/IElWbZBJVlHCisTfZVu++tOWVinwyjS5FEUAORFv bUeECT+QlKi6RecqXxRKVTCEw6lhjDWzy34jSIzcP/qYC/eq8idonP7T+/0BDsgUx1Ms Mcsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h69-20020a638348000000b00476df7b4c95si11969923pge.287.2022.11.21.08.53.43; Mon, 21 Nov 2022 08:53:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbiKUQmV convert rfc822-to-8bit (ORCPT + 91 others); Mon, 21 Nov 2022 11:42:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiKUQmT (ORCPT ); Mon, 21 Nov 2022 11:42:19 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B381ADA8; Mon, 21 Nov 2022 08:42:16 -0800 (PST) Received: from frapeml500002.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4NGClr0LXGz67v9b; Tue, 22 Nov 2022 00:39:36 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by frapeml500002.china.huawei.com (7.182.85.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 17:42:14 +0100 Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 16:42:13 +0000 Date: Mon, 21 Nov 2022 16:42:12 +0000 From: Jonathan Cameron To: Rajat Khandelwal CC: , , , , , , , Subject: Re: [PATCH v10] iio: temperature: Add driver support for Maxim MAX30208 Message-ID: <20221121164212.00005484@Huawei.com> In-Reply-To: References: <20221118153729.762018-1-rajat.khandelwal@linux.intel.com> <20221117163040.00001f5a@Huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml500003.china.huawei.com (7.191.162.67) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 Nov 2022 18:27:10 +0530 Rajat Khandelwal wrote: > Have provided inline comments. > Please provide your comments for me to spin a v11 :) > > On 11/17/2022 10:00 PM, Jonathan Cameron wrote: > > On Fri, 18 Nov 2022 21:07:29 +0530 > > Rajat Khandelwal wrote: > > > >> Maxim MAX30208 is a digital temperature sensor with 0.1?C accuracy. > >> > >> Add support for max30208 driver in iio subsystem. > > Blank line here. > > > >> Datasheet:https://datasheets.maximintegrated.com/en/ds/MAX30208.pdf > >> > > Datasheet part of the tags block, so no blank line between that and the SoB. > > That makes life easy for tools parsing git messages. > > - Got it. Will do that. > > > > >> Signed-off-by: Rajat Khandelwal > > One query inline. Basically boils down to what we do after > > overflow occurs. I assume you are right and the first reading is the most recent, but > > I think we still want to flush the whole fifo in that case to get back to > > a sane state for future reads. > > > > Jonathan > > > >> +/** > >> + * max30208_request() - Request a reading > >> + * @data: Struct comprising member elements of the device > >> + * > >> + * Requests a reading from the device and waits until the conversion is ready. > >> + */ > >> +static int max30208_request(struct max30208_data *data) > >> +{ > >> + /* > >> + * Sensor can take up to 500 ms to respond so execute a total of > >> + * 10 retries to give the device sufficient time. > >> + */ > >> + int retries = 10; > >> + u8 regval; > >> + int ret; > >> + > >> + ret = i2c_smbus_read_byte_data(data->client, MAX30208_TEMP_SENSOR_SETUP); > >> + if (ret < 0) > >> + return ret; > >> + > >> + regval = ret | MAX30208_TEMP_SENSOR_SETUP_CONV; > >> + > >> + ret = i2c_smbus_write_byte_data(data->client, MAX30208_TEMP_SENSOR_SETUP, regval); > >> + if (ret) > >> + return ret; > >> + > >> + while (retries--) { > >> + ret = i2c_smbus_read_byte_data(data->client, MAX30208_STATUS); > >> + if (ret < 0) > >> + return ret; > >> + > >> + if (ret & MAX30208_STATUS_TEMP_RDY) > >> + return 0; > >> + > >> + msleep(50); > >> + } > >> + dev_err(&data->client->dev, "Temperature conversion failed\n"); > >> + > >> + return -ETIMEDOUT; > >> +} > >> + > >> +static int max30208_update_temp(struct max30208_data *data) > >> +{ > >> + u8 data_count; > >> + int ret; > >> + > >> + mutex_lock(&data->lock); > >> + > >> + ret = max30208_request(data); > >> + if (ret) > >> + goto unlock; > >> + > >> + ret = i2c_smbus_read_byte_data(data->client, MAX30208_FIFO_OVF_CNTR); > >> + if (ret < 0) > >> + goto unlock; > >> + else if (!ret) { > >> + ret = i2c_smbus_read_byte_data(data->client, MAX30208_FIFO_DATA_CNTR); > >> + if (ret < 0) > >> + goto unlock; > >> + > >> + data_count = ret; > >> + } else > >> + data_count = 1; > >> + > >> + while (data_count) { > >> + ret = i2c_smbus_read_word_swapped(data->client, MAX30208_FIFO_DATA); > >> + if (ret < 0) > >> + goto unlock; > >> + > >> + data_count--; > >> + } > > Hmm. Given you've been poking this a lot, I guess this works and the part is > > as just odd. Just to check one last case... Does max30208_request() guarantee we can't > > get... > > > > 1. Read first time, overflow set so we read latest result - leaving > > 31 ancient values in the fifo. > > 2. Read again really quickly and get those ancient values. > > ? > > > > Perhaps we should flush out those unwanted values from the fifo, so after > > overflow we get back to a normal state rather than immediately overflowing again. > > > > More than possible that I still don't understand how this device works though! > > - Ok, so whenever user wants a temperature reading, conversion first takes place and then > the reading gets returned. So, user will always get the latest converted reading despite > the number of ancient readings. > Flushing everytime we get an overflow is not required I think because even though overflow > could happen again, user still gets the latest updated reading. Also, I plan to incorporate > buffered flow in IIO. Even though, I think let FIFO remain intact because it doesn't impact > the recent readings. Fair enough. Sounds like yes, we are guaranteed there will always be a new reading before we start popping entries off the fifo again. If that's the case, all is fine as is - was just really hard to figure that out from the code / datasheet, so I wanted to check. Jonathan > > >> + > >> +unlock: > >> + mutex_unlock(&data->lock); > >> + return ret; > >> +} > >> +