Lines Matching +full:reg +full:- +full:rc
4 * SPDX-License-Identifier: Apache-2.0
113 const struct si7210_config *config = dev->config; in si7210_sleep()
114 struct si7210_data *data = dev->data; in si7210_sleep()
115 int rc; in si7210_sleep() local
119 * the register, but they get reloaded from OTP during wake-up. in si7210_sleep()
121 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_CTRL3, 0); in si7210_sleep()
122 if (rc < 0) { in si7210_sleep()
124 return rc; in si7210_sleep()
128 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_POWER_CTRL, in si7210_sleep()
130 if (rc < 0) { in si7210_sleep()
132 return rc; in si7210_sleep()
136 data->reg_dspsigsel = 0x00; in si7210_sleep()
137 data->reg_arautoinc = 0x00; in si7210_sleep()
145 const struct si7210_config *config = dev->config; in si7210_wakeup()
147 int rc; in si7210_wakeup() local
154 rc = i2c_read_dt(&config->bus, &val, 1); in si7210_wakeup()
155 if (rc < 0) { in si7210_wakeup()
156 LOG_ERR("Failed to go wake-up chip"); in si7210_wakeup()
157 return rc; in si7210_wakeup()
169 int rc; in si7210_reset() local
171 rc = si7210_sleep(dev); in si7210_reset()
172 if (rc < 0) { in si7210_reset()
173 return rc; in si7210_reset()
176 rc = si7210_wakeup(dev); in si7210_reset()
178 return rc; in si7210_reset()
184 const struct si7210_config *config = dev->config; in si7210_otp_reg_read_byte()
185 int rc; in si7210_otp_reg_read_byte() local
187 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_OTP_ADDR, otp_reg_addr); in si7210_otp_reg_read_byte()
188 if (rc) { in si7210_otp_reg_read_byte()
190 return rc; in si7210_otp_reg_read_byte()
193 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_OTP_CTRL, SI7210_BIT_OTP_CTRL_READEN); in si7210_otp_reg_read_byte()
194 if (rc) { in si7210_otp_reg_read_byte()
196 return rc; in si7210_otp_reg_read_byte()
204 rc = i2c_reg_read_byte_dt(&config->bus, SI7210_REG_OTP_DATA, value); in si7210_otp_reg_read_byte()
205 if (rc) { in si7210_otp_reg_read_byte()
207 return rc; in si7210_otp_reg_read_byte()
217 for (int reg = SI7210_OTPREG_SN1; reg <= SI7210_OTPREG_SN4; reg++) { in si7210_read_sn() local
219 int rc; in si7210_read_sn() local
221 rc = si7210_otp_reg_read_byte(dev, reg, &val8); in si7210_read_sn()
222 if (rc < 0) { in si7210_read_sn()
223 return rc; in si7210_read_sn()
237 const struct si7210_config *config = dev->config; in si7210_set_dspsigsel()
238 struct si7210_data *data = dev->data; in si7210_set_dspsigsel()
239 int rc; in si7210_set_dspsigsel() local
241 if (data->reg_dspsigsel == value) { in si7210_set_dspsigsel()
245 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_DSPSIGSEL, value); in si7210_set_dspsigsel()
246 if (rc < 0) { in si7210_set_dspsigsel()
248 return rc; in si7210_set_dspsigsel()
251 data->reg_dspsigsel = value; in si7210_set_dspsigsel()
259 const struct si7210_config *config = dev->config; in si7210_set_arautoinc()
260 struct si7210_data *data = dev->data; in si7210_set_arautoinc()
261 int rc; in si7210_set_arautoinc() local
263 if (data->reg_arautoinc == value) { in si7210_set_arautoinc()
267 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_ARAUTOINC, value); in si7210_set_arautoinc()
268 if (rc < 0) { in si7210_set_arautoinc()
270 return rc; in si7210_set_arautoinc()
273 data->reg_arautoinc = value; in si7210_set_arautoinc()
280 const struct si7210_config *config = dev->config; in si7210_sample_fetch_one()
282 int rc; in si7210_sample_fetch_one() local
285 rc = si7210_set_dspsigsel(dev, channel); in si7210_sample_fetch_one()
286 if (rc < 0) { in si7210_sample_fetch_one()
287 return rc; in si7210_sample_fetch_one()
291 rc = si7210_set_arautoinc(dev, 1); in si7210_sample_fetch_one()
292 if (rc < 0) { in si7210_sample_fetch_one()
293 return rc; in si7210_sample_fetch_one()
297 rc = i2c_reg_write_byte_dt(&config->bus, SI7210_REG_POWER_CTRL, in si7210_sample_fetch_one()
299 if (rc < 0) { in si7210_sample_fetch_one()
301 return rc; in si7210_sample_fetch_one()
310 rc = i2c_burst_read_dt(&config->bus, SI7210_REG_DSPSIGM, (uint8_t *)&val, sizeof(val)); in si7210_sample_fetch_one()
311 if (rc < 0) { in si7210_sample_fetch_one()
313 return rc; in si7210_sample_fetch_one()
323 struct si7210_data *data = dev->data; in si7210_sample_fetch()
325 int rc; in si7210_sample_fetch() local
336 return -EIO; in si7210_sample_fetch()
344 rc = si7210_sample_fetch_one(dev, SI7210_BIT_DSPSIGSEL_TEMP, &dspsig); in si7210_sample_fetch()
345 if (rc < 0) { in si7210_sample_fetch()
346 return rc; in si7210_sample_fetch()
349 data->temp_sample = dspsig >> 3; in si7210_sample_fetch()
354 rc = si7210_sample_fetch_one(dev, SI7210_BIT_DSPSIGSEL_MAG, &dspsig); in si7210_sample_fetch()
355 if (rc < 0) { in si7210_sample_fetch()
356 return rc; in si7210_sample_fetch()
359 data->mag_sample = dspsig; in si7210_sample_fetch()
372 struct si7210_data *data = dev->data; in si7210_channel_get()
378 tmp = data->temp_sample; in si7210_channel_get()
380 /* temperature_raw = -3.83e-6 * value^2 + 0.16094 * value - 279.80 */ in si7210_channel_get()
381 tmp = (-383 * tmp * tmp) / 100 + (160940 * tmp) - 279800000; in si7210_channel_get()
384 tmp = (tmp * (2048 + data->otp_temp_gain)) / 2048; in si7210_channel_get()
385 tmp = tmp + (data->otp_temp_offset * 62500); in si7210_channel_get()
388 * Additional offset of -0.222 x VDD. The datasheet recommends in si7210_channel_get()
391 tmp -= 732600; in si7210_channel_get()
393 val->val1 = tmp / 1000000; in si7210_channel_get()
394 val->val2 = tmp % 1000000; in si7210_channel_get()
398 tmp = data->mag_sample; in si7210_channel_get()
400 if (data->scale == si7210_scale_200G) { in si7210_channel_get()
402 * Formula in mT (datasheet) for the 20mT scale: (value - 16384) * 0.00125 in si7210_channel_get()
403 * => Formula in G for the 200G scale: (value - 16384) * 0.0125 in si7210_channel_get()
405 tmp = (tmp - 16384) * 12500; in si7210_channel_get()
408 * Formula in mT (datasheet) for the 200mT scale: (value - 16384) * 0.0125 in si7210_channel_get()
409 * => Formula in G for the 2000G scale: (value - 16384) * 0.125 in si7210_channel_get()
411 tmp = (tmp - 16384) * 1250; in si7210_channel_get()
414 val->val1 = tmp / 1000000; in si7210_channel_get()
415 val->val2 = tmp % 1000000; in si7210_channel_get()
418 return -ENOTSUP; in si7210_channel_get()
433 int rc; in si7210_pm_action() local
437 /* Wake-up the chip */ in si7210_pm_action()
438 rc = si7210_wakeup(dev); in si7210_pm_action()
442 rc = si7210_sleep(dev); in si7210_pm_action()
445 return -ENOTSUP; in si7210_pm_action()
448 return rc; in si7210_pm_action()
454 const struct si7210_config *config = dev->config; in si7210_init()
455 struct si7210_data *data = dev->data; in si7210_init()
459 int rc; in si7210_init() local
461 if (!device_is_ready(config->bus.bus)) { in si7210_init()
462 LOG_ERR("I2C bus %s not ready!", config->bus.bus->name); in si7210_init()
463 return -ENODEV; in si7210_init()
467 rc = si7210_wakeup(dev); in si7210_init()
468 if (rc < 0) { in si7210_init()
469 LOG_ERR("Failed to wake-up device"); in si7210_init()
470 return rc; in si7210_init()
474 rc = i2c_reg_read_byte_dt(&config->bus, SI7210_REG_CHIPID, &chipid); in si7210_init()
475 if (rc < 0) { in si7210_init()
477 return rc; in si7210_init()
482 return -EINVAL; in si7210_init()
494 rc = si7210_otp_reg_read_byte(dev, SI7210_OTPREG_PART_BASE, &part_base); in si7210_init()
495 if (rc < 0) { in si7210_init()
496 return rc; in si7210_init()
498 rc = si7210_otp_reg_read_byte(dev, SI7210_OTPREG_PART_VARIANT, &part_variant); in si7210_init()
499 if (rc < 0) { in si7210_init()
500 return rc; in si7210_init()
504 rc = si7210_read_sn(dev, &sn); in si7210_init()
505 if (rc < 0) { in si7210_init()
506 return rc; in si7210_init()
509 LOG_INF("Found Si72%02d-%c-%02d S/N %08x, at I2C address 0x%x", in si7210_init()
510 part_base, rev, part_variant, sn, config->bus.addr); in si7210_init()
513 data->scale = (part_variant == 5 || part_variant == 15) ? in si7210_init()
517 rc = si7210_otp_reg_read_byte(dev, SI7210_OTPREG_TEMP_OFFSET, &data->otp_temp_offset); in si7210_init()
518 if (rc < 0) { in si7210_init()
519 return rc; in si7210_init()
521 rc = si7210_otp_reg_read_byte(dev, SI7210_OTPREG_TEMP_GAIN, &data->otp_temp_gain); in si7210_init()
522 if (rc < 0) { in si7210_init()
523 return rc; in si7210_init()
527 rc = si7210_reset(dev); in si7210_init()
528 if (rc < 0) { in si7210_init()
530 return rc; in si7210_init()