Lines Matching +full:alert +full:- +full:celsius

1 // SPDX-License-Identifier: GPL-2.0+
3 * hdc3020.c - Support for the TI HDC3020,HDC3021 and HDC3022
8 * Copyright (C) 2024 Liebherr-Electronics and Drives GmbH
70 #define HDC3020_MIN_TEMP_MICRO -39872968
139 struct i2c_client *client = data->client; in hdc3020_write_bytes()
143 msg.addr = client->addr; in hdc3020_write_bytes()
153 ret = i2c_transfer(client->adapter, &msg, 1); in hdc3020_write_bytes()
159 dev_err(&client->dev, "Could not write sensor command\n"); in hdc3020_write_bytes()
161 return -ETIMEDOUT; in hdc3020_write_bytes()
169 struct i2c_client *client = data->client; in hdc3020_read_bytes()
172 .addr = client->addr, in hdc3020_read_bytes()
178 .addr = client->addr, in hdc3020_read_bytes()
191 ret = i2c_transfer(client->adapter, msg, 2); in hdc3020_read_bytes()
197 dev_err(&client->dev, "Could not read sensor data\n"); in hdc3020_read_bytes()
199 return -ETIMEDOUT; in hdc3020_read_bytes()
213 return -EINVAL; in hdc3020_read_be16()
239 return -EINVAL; in hdc3020_read_measurement()
244 return -EINVAL; in hdc3020_read_measurement()
251 return -EINVAL; in hdc3020_read_measurement()
263 if (chan->type != IIO_TEMP && chan->type != IIO_HUMIDITYRELATIVE) in hdc3020_read_raw()
264 return -EINVAL; in hdc3020_read_raw()
268 guard(mutex)(&data->lock); in hdc3020_read_raw()
269 ret = hdc3020_read_measurement(data, chan->type, val); in hdc3020_read_raw()
276 guard(mutex)(&data->lock); in hdc3020_read_raw()
277 if (chan->type == IIO_TEMP) in hdc3020_read_raw()
289 guard(mutex)(&data->lock); in hdc3020_read_raw()
290 if (chan->type == IIO_TEMP) in hdc3020_read_raw()
303 if (chan->type == IIO_TEMP) in hdc3020_read_raw()
310 if (chan->type != IIO_TEMP) in hdc3020_read_raw()
311 return -EINVAL; in hdc3020_read_raw()
313 *val = -16852; in hdc3020_read_raw()
317 return -EINVAL; in hdc3020_read_raw()
326 if (mask != IIO_CHAN_INFO_RAW || chan->type != IIO_CURRENT) in hdc3020_read_available()
327 return -EINVAL; in hdc3020_read_available()
341 return -EINVAL; in hdc3020_update_heater()
364 if (chan->type != IIO_CURRENT) in hdc3020_write_raw()
365 return -EINVAL; in hdc3020_write_raw()
367 guard(mutex)(&data->lock); in hdc3020_write_raw()
371 return -EINVAL; in hdc3020_write_raw()
382 * datasheet. Result is degree celsius scaled by 65535. in hdc3020_thresh_get_temp()
387 return -2949075 + (175 * temp); in hdc3020_thresh_get_temp()
454 s_clr = s_thresh - s_hyst; in hdc3020_thresh_clr()
498 guard(mutex)(&data->lock); in hdc3020_write_thresh()
510 s_val = (val < 0) ? (val * 1000000 - val2) : (val * 1000000 + val2); in hdc3020_write_thresh()
511 switch (chan->type) { in hdc3020_write_thresh()
526 s_hyst = div_s64(abs(s_thresh - s_clr), 65535); in hdc3020_write_thresh()
535 * in degree celsius scaled by 65535. Scale by 1000000 in hdc3020_write_thresh()
540 * Units of s_val are in micro degree celsius, scale by in hdc3020_write_thresh()
552 return -EOPNOTSUPP; in hdc3020_write_thresh()
568 s_hyst = div_s64(abs(s_thresh - s_clr), 65535); in hdc3020_write_thresh()
593 return -EOPNOTSUPP; in hdc3020_write_thresh()
597 return -EOPNOTSUPP; in hdc3020_write_thresh()
623 guard(mutex)(&data->lock); in hdc3020_read_thresh()
628 switch (chan->type) { in hdc3020_read_thresh()
641 *val = abs(thresh - clr); in hdc3020_read_thresh()
644 return -EOPNOTSUPP; in hdc3020_read_thresh()
660 *val = abs(thresh - clr); in hdc3020_read_thresh()
663 return -EOPNOTSUPP; in hdc3020_read_thresh()
668 return -EOPNOTSUPP; in hdc3020_read_thresh()
736 if (data->reset_gpio) in hdc3020_power_off()
737 gpiod_set_value_cansleep(data->reset_gpio, 1); in hdc3020_power_off()
739 return regulator_disable(data->vdd_supply); in hdc3020_power_off()
746 ret = regulator_enable(data->vdd_supply); in hdc3020_power_on()
752 if (data->reset_gpio) { in hdc3020_power_on()
753 gpiod_set_value_cansleep(data->reset_gpio, 0); in hdc3020_power_on()
757 if (data->client->irq) { in hdc3020_power_on()
759 * The alert output is activated by default upon power up, in hdc3020_power_on()
787 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in hdc3020_probe()
788 return -EOPNOTSUPP; in hdc3020_probe()
790 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in hdc3020_probe()
792 return -ENOMEM; in hdc3020_probe()
794 dev_set_drvdata(&client->dev, indio_dev); in hdc3020_probe()
797 data->client = client; in hdc3020_probe()
798 mutex_init(&data->lock); in hdc3020_probe()
802 indio_dev->name = "hdc3020"; in hdc3020_probe()
803 indio_dev->modes = INDIO_DIRECT_MODE; in hdc3020_probe()
804 indio_dev->info = &hdc3020_info; in hdc3020_probe()
805 indio_dev->channels = hdc3020_channels; in hdc3020_probe()
806 indio_dev->num_channels = ARRAY_SIZE(hdc3020_channels); in hdc3020_probe()
808 data->vdd_supply = devm_regulator_get(&client->dev, "vdd"); in hdc3020_probe()
809 if (IS_ERR(data->vdd_supply)) in hdc3020_probe()
810 return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply), in hdc3020_probe()
813 data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in hdc3020_probe()
815 if (IS_ERR(data->reset_gpio)) in hdc3020_probe()
816 return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio), in hdc3020_probe()
821 return dev_err_probe(&client->dev, ret, "Power on failed\n"); in hdc3020_probe()
823 ret = devm_add_action_or_reset(&data->client->dev, hdc3020_exit, data); in hdc3020_probe()
827 if (client->irq) { in hdc3020_probe()
828 ret = devm_request_threaded_irq(&client->dev, client->irq, in hdc3020_probe()
833 return dev_err_probe(&client->dev, ret, in hdc3020_probe()
837 ret = devm_iio_device_register(&data->client->dev, indio_dev); in hdc3020_probe()
839 return dev_err_probe(&client->dev, ret, "Failed to add device"); in hdc3020_probe()