From: Antoni Pokusinski <apokusinski01@gmail.com>
To: linux@roeck-us.net
Cc: apokusinski01@gmail.com, jdelvare@suse.com,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH v3] hwmon: (sht4x): add heater support
Date: Wed, 28 Aug 2024 18:05:11 +0200 [thread overview]
Message-ID: <20240828160511.307768-1-apokusinski01@gmail.com> (raw)
In-Reply-To: <790f67c3-84f4-441b-bd80-0c11f002af5b@roeck-us.net>
Hello,
I've been thinking on how to approach the problem of NACKs received
from the sensor while the heater is on but I haven't found
a perfectly satisfying solution either. This is due to the fact that
the device does not provide any way to check if the heater is on/off.
1. I guess that the simplest possible approach would involve sleeping
in `heater_enable_store()`:
ssize_t heater_enable_store() {
...
mutex_lock(data->lock);
ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
msleep(...) /* for >100 or >1000 ms */
mutex_unlock(data->lock);
...
}
This way, the user would have to wait for the heating to complete in
order to read RH or temperature measurement. However, I find this
solution unacceptable since it's completely unnecessary for the user
to wait for the heating to complete.
2. A better solution could be possibly to use a wait queue in order
to defer the job of enabling the heater:
struct sht4x_data {
...
struct work_struct* heater_work; /* This would be initialized
with the handler described
below */
}
The task of sending the "heater_enable" command and sleeping would be
performed by the worker function:
static void heater_enable_handler(struct work_struct *work) {
...
mutex_lock(data->lock);
ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
msleep(...) /* for >100 or >1000 ms */
mutex_unlock(data->lock);
...
}
And that above mentioned work would be scheduled
in `heater_enable_store()`:
ssize_t heater_enable_store() {
...
schedule_work(data->heater_work);
...
}
I think that this approach with work queue is better since the user
doesn't have to wait for the heating to complete and the RH or
temperature measurements can also be retrieved without the NACK error
(even though the user still may have to wait for the heater to be
off), since the `data->lock` mutex is used to guard both measurement
reads from the sensor and the heating in `heater_enable_handler`.
I'm worried though about the situation where the user writes 1 to
"heater_enable" while it's already enabled. Since the `work_struct`
is already on the queue, the `heater_enable_store` would return an
error and I see no easy solution to this for now.
Regards,
Antoni Pokusinski
next prev parent reply other threads:[~2024-08-28 16:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 12:58 [PATCH v3] hwmon: (sht4x): add heater support Antoni Pokusinski
2024-08-26 18:37 ` Guenter Roeck
2024-08-28 16:05 ` Antoni Pokusinski [this message]
2024-08-28 16:35 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240828160511.307768-1-apokusinski01@gmail.com \
--to=apokusinski01@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox