hwmon: (sht4x) Rely on subsystem locking

Attribute access is now serialized in the hardware monitoring core,
so locking in the driver code is no longer necessary. Drop it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Guenter Roeck 2025-09-07 15:12:01 -07:00
parent caff6fba51
commit 53dfa12299
1 changed files with 11 additions and 29 deletions

View File

@ -55,7 +55,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
/** /**
* struct sht4x_data - All the data required to operate an SHT4X chip * struct sht4x_data - All the data required to operate an SHT4X chip
* @client: the i2c client associated with the SHT4X * @client: the i2c client associated with the SHT4X
* @lock: a mutex that is used to prevent parallel access to the i2c client
* @heating_complete: the time that the last heating finished * @heating_complete: the time that the last heating finished
* @data_pending: true if and only if there are measurements to retrieve after heating * @data_pending: true if and only if there are measurements to retrieve after heating
* @heater_power: the power at which the heater will be started * @heater_power: the power at which the heater will be started
@ -68,7 +67,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
*/ */
struct sht4x_data { struct sht4x_data {
struct i2c_client *client; struct i2c_client *client;
struct mutex lock; /* atomic read data updates */
unsigned long heating_complete; /* in jiffies */ unsigned long heating_complete; /* in jiffies */
bool data_pending; bool data_pending;
u32 heater_power; /* in milli-watts */ u32 heater_power; /* in milli-watts */
@ -87,7 +85,7 @@ struct sht4x_data {
*/ */
static int sht4x_read_values(struct sht4x_data *data) static int sht4x_read_values(struct sht4x_data *data)
{ {
int ret = 0; int ret;
u16 t_ticks, rh_ticks; u16 t_ticks, rh_ticks;
unsigned long next_update; unsigned long next_update;
struct i2c_client *client = data->client; struct i2c_client *client = data->client;
@ -96,8 +94,6 @@ static int sht4x_read_values(struct sht4x_data *data)
u8 raw_data[SHT4X_RESPONSE_LENGTH]; u8 raw_data[SHT4X_RESPONSE_LENGTH];
unsigned long curr_jiffies; unsigned long curr_jiffies;
mutex_lock(&data->lock);
curr_jiffies = jiffies; curr_jiffies = jiffies;
if (time_before(curr_jiffies, data->heating_complete)) if (time_before(curr_jiffies, data->heating_complete))
msleep(jiffies_to_msecs(data->heating_complete - curr_jiffies)); msleep(jiffies_to_msecs(data->heating_complete - curr_jiffies));
@ -110,11 +106,11 @@ static int sht4x_read_values(struct sht4x_data *data)
msecs_to_jiffies(data->update_interval); msecs_to_jiffies(data->update_interval);
if (data->valid && time_before_eq(jiffies, next_update)) if (data->valid && time_before_eq(jiffies, next_update))
goto unlock; return 0;
ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN); ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);
if (ret < 0) if (ret < 0)
goto unlock; return ret;
usleep_range(SHT4X_MEAS_DELAY_HPM, SHT4X_MEAS_DELAY_HPM + SHT4X_DELAY_EXTRA); usleep_range(SHT4X_MEAS_DELAY_HPM, SHT4X_MEAS_DELAY_HPM + SHT4X_DELAY_EXTRA);
} }
@ -123,7 +119,7 @@ static int sht4x_read_values(struct sht4x_data *data)
if (ret != SHT4X_RESPONSE_LENGTH) { if (ret != SHT4X_RESPONSE_LENGTH) {
if (ret >= 0) if (ret >= 0)
ret = -ENODATA; ret = -ENODATA;
goto unlock; return ret;
} }
t_ticks = raw_data[0] << 8 | raw_data[1]; t_ticks = raw_data[0] << 8 | raw_data[1];
@ -132,26 +128,20 @@ static int sht4x_read_values(struct sht4x_data *data)
crc = crc8(sht4x_crc8_table, &raw_data[0], SHT4X_WORD_LEN, CRC8_INIT_VALUE); crc = crc8(sht4x_crc8_table, &raw_data[0], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
if (crc != raw_data[2]) { if (crc != raw_data[2]) {
dev_err(&client->dev, "data integrity check failed\n"); dev_err(&client->dev, "data integrity check failed\n");
ret = -EIO; return -EIO;
goto unlock;
} }
crc = crc8(sht4x_crc8_table, &raw_data[3], SHT4X_WORD_LEN, CRC8_INIT_VALUE); crc = crc8(sht4x_crc8_table, &raw_data[3], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
if (crc != raw_data[5]) { if (crc != raw_data[5]) {
dev_err(&client->dev, "data integrity check failed\n"); dev_err(&client->dev, "data integrity check failed\n");
ret = -EIO; return -EIO;
goto unlock;
} }
data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000; data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000;
data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000; data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000;
data->last_updated = jiffies; data->last_updated = jiffies;
data->valid = true; data->valid = true;
ret = 0; return 0;
unlock:
mutex_unlock(&data->lock);
return ret;
} }
static ssize_t sht4x_interval_write(struct sht4x_data *data, long val) static ssize_t sht4x_interval_write(struct sht4x_data *data, long val)
@ -287,22 +277,16 @@ static ssize_t heater_enable_store(struct device *dev,
heating_time_bound = 1100; heating_time_bound = 1100;
} }
mutex_lock(&data->lock); if (time_before(jiffies, data->heating_complete))
return -EBUSY;
if (time_before(jiffies, data->heating_complete)) {
ret = -EBUSY;
goto unlock;
}
ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN); ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
if (ret < 0) if (ret < 0)
goto unlock; return ret;
data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound); data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound);
data->data_pending = true; data->data_pending = true;
unlock: return 0;
mutex_unlock(&data->lock);
return ret;
} }
static ssize_t heater_power_show(struct device *dev, static ssize_t heater_power_show(struct device *dev,
@ -422,8 +406,6 @@ static int sht4x_probe(struct i2c_client *client)
data->heater_time = 1000; data->heater_time = 1000;
data->heating_complete = jiffies; data->heating_complete = jiffies;
mutex_init(&data->lock);
crc8_populate_msb(sht4x_crc8_table, SHT4X_CRC8_POLYNOMIAL); crc8_populate_msb(sht4x_crc8_table, SHT4X_CRC8_POLYNOMIAL);
ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN); ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);