Lines Matching +full:reg +full:- +full:offset
4 * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/dt-bindings/sensor/tmp116.h>
28 static int tmp116_reg_read(const struct device *dev, uint8_t reg, in tmp116_reg_read() argument
31 const struct tmp116_dev_config *cfg = dev->config; in tmp116_reg_read()
33 if (i2c_burst_read_dt(&cfg->bus, reg, (uint8_t *)val, 2) in tmp116_reg_read()
35 return -EIO; in tmp116_reg_read()
43 static int tmp116_reg_write(const struct device *dev, uint8_t reg, in tmp116_reg_write() argument
46 const struct tmp116_dev_config *cfg = dev->config; in tmp116_reg_write()
47 uint8_t tx_buf[3] = {reg, val >> 8, val & 0xFF}; in tmp116_reg_write()
49 return i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in tmp116_reg_write()
69 static bool check_eeprom_bounds(const struct device *dev, off_t offset, in check_eeprom_bounds() argument
72 struct tmp116_data *drv_data = dev->data; in check_eeprom_bounds()
74 if ((offset + len) > EEPROM_TMP116_SIZE || in check_eeprom_bounds()
75 offset % EEPROM_SIZE_REG != 0 || in check_eeprom_bounds()
80 /* TMP117 uses EEPROM[2] as temperature offset register */ in check_eeprom_bounds()
81 if (drv_data->id == TMP117_DEVICE_ID && in check_eeprom_bounds()
82 offset <= EEPROM_TMP117_RESERVED && in check_eeprom_bounds()
83 (offset + len) > EEPROM_TMP117_RESERVED) { in check_eeprom_bounds()
90 int tmp116_eeprom_write(const struct device *dev, off_t offset, in tmp116_eeprom_write() argument
93 uint8_t reg; in tmp116_eeprom_write() local
97 if (!check_eeprom_bounds(dev, offset, len)) { in tmp116_eeprom_write()
98 return -EINVAL; in tmp116_eeprom_write()
106 for (reg = (offset / 2); reg < offset / 2 + len / 2; reg++) { in tmp116_eeprom_write()
109 res = tmp116_reg_write(dev, reg + TMP116_REG_EEPROM1, val); in tmp116_eeprom_write()
134 int tmp116_eeprom_read(const struct device *dev, off_t offset, void *data, in tmp116_eeprom_read() argument
137 uint8_t reg; in tmp116_eeprom_read() local
141 if (!check_eeprom_bounds(dev, offset, len)) { in tmp116_eeprom_read()
142 return -EINVAL; in tmp116_eeprom_read()
145 for (reg = (offset / 2); reg < offset / 2 + len / 2; reg++) { in tmp116_eeprom_read()
146 res = tmp116_reg_read(dev, reg + TMP116_REG_EEPROM1, dst); in tmp116_eeprom_read()
164 * @retval -EIO Otherwise
170 dev->name); in tmp116_device_id_check()
171 return -EIO; in tmp116_device_id_check()
176 dev->name); in tmp116_device_id_check()
177 return -EINVAL; in tmp116_device_id_check()
186 struct tmp116_data *drv_data = dev->data; in tmp116_sample_fetch()
195 drv_data->sample = 0U; in tmp116_sample_fetch()
201 dev->name); in tmp116_sample_fetch()
206 LOG_DBG("%s: no data ready", dev->name); in tmp116_sample_fetch()
207 return -EBUSY; in tmp116_sample_fetch()
214 dev->name); in tmp116_sample_fetch()
219 drv_data->sample = (int16_t)value; in tmp116_sample_fetch()
228 struct tmp116_data *drv_data = dev->data; in tmp116_channel_get()
232 return -ENOTSUP; in tmp116_channel_get()
239 tmp = ((int16_t)drv_data->sample * (int32_t)TMP116_RESOLUTION) / 10; in tmp116_channel_get()
240 val->val1 = tmp / 1000000; /* uCelsius */ in tmp116_channel_get()
241 val->val2 = tmp % 1000000; in tmp116_channel_get()
269 return -EINVAL; in tmp116_conv_value()
278 struct tmp116_data *drv_data = dev->data; in tmp116_attr_set()
283 return -ENOTSUP; in tmp116_attr_set()
296 if (drv_data->id != TMP117_DEVICE_ID) { in tmp116_attr_set()
297 LOG_ERR("%s: Offset is only supported by TMP117", in tmp116_attr_set()
298 dev->name); in tmp116_attr_set()
299 return -EINVAL; in tmp116_attr_set()
302 * The offset is encoded into the temperature register format. in tmp116_attr_set()
304 value = (((val->val1) * 10000000) + ((val->val2) * 10)) in tmp116_attr_set()
311 switch (val->val1) { in tmp116_attr_set()
329 return -EINVAL; in tmp116_attr_set()
342 return -ENOTSUP; in tmp116_attr_set()
353 return -ENOTSUP; in tmp116_attr_get()
364 return -ENOTSUP; in tmp116_attr_get()
367 val->val1 = data; in tmp116_attr_get()
368 val->val2 = 0; in tmp116_attr_get()
382 struct tmp116_data *drv_data = dev->data; in tmp116_init()
383 const struct tmp116_dev_config *cfg = dev->config; in tmp116_init()
387 if (!device_is_ready(cfg->bus.bus)) { in tmp116_init()
388 LOG_ERR("I2C dev %s not ready", cfg->bus.bus->name); in tmp116_init()
389 return -EINVAL; in tmp116_init()
398 drv_data->id = id; in tmp116_init()
400 rc = tmp116_write_config(dev, TMP116_CFGR_CONV, cfg->odr); in tmp116_init()