drivers: sensor: ams_iAQcore: Update driver to use i2c_dt_spec

Move driver to use i2c_dt_spec for I2C bus access.

Signed-off-by: Kumar Gala <galak@kernel.org>
This commit is contained in:
Kumar Gala 2022-06-10 17:13:57 -05:00 committed by Maureen Helm
commit e3f991b7b8
2 changed files with 15 additions and 10 deletions

View file

@ -23,6 +23,7 @@ static int iaqcore_sample_fetch(const struct device *dev,
enum sensor_channel chan) enum sensor_channel chan)
{ {
struct iaq_core_data *drv_data = dev->data; struct iaq_core_data *drv_data = dev->data;
const struct iaq_core_config *config = dev->config;
struct iaq_registers buf; struct iaq_registers buf;
struct i2c_msg msg; struct i2c_msg msg;
int ret, tries; int ret, tries;
@ -35,8 +36,7 @@ static int iaqcore_sample_fetch(const struct device *dev,
for (tries = 0; tries < CONFIG_IAQ_CORE_MAX_READ_RETRIES; tries++) { for (tries = 0; tries < CONFIG_IAQ_CORE_MAX_READ_RETRIES; tries++) {
ret = i2c_transfer(drv_data->i2c, &msg, 1, ret = i2c_transfer_dt(&config->i2c, &msg, 1);
DT_INST_REG_ADDR(0));
if (ret < 0) { if (ret < 0) {
LOG_ERR("Failed to read registers data [%d].", ret); LOG_ERR("Failed to read registers data [%d].", ret);
return -EIO; return -EIO;
@ -100,13 +100,11 @@ static const struct sensor_driver_api iaq_core_driver_api = {
static int iaq_core_init(const struct device *dev) static int iaq_core_init(const struct device *dev)
{ {
struct iaq_core_data *drv_data = dev->data; const struct iaq_core_config *config = dev->config;
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0)); if (!device_is_ready(config->i2c.bus)) {
if (drv_data->i2c == NULL) { LOG_ERR("Bus device is not ready");
LOG_ERR("Failed to get pointer to %s device!", return -ENODEV;
DT_INST_BUS_LABEL(0));
return -EINVAL;
} }
return 0; return 0;
@ -114,6 +112,10 @@ static int iaq_core_init(const struct device *dev)
static struct iaq_core_data iaq_core_driver; static struct iaq_core_data iaq_core_driver;
static const struct iaq_core_config iaq_core_config = {
.i2c = I2C_DT_SPEC_INST_GET(0),
};
DEVICE_DT_INST_DEFINE(0, iaq_core_init, NULL, DEVICE_DT_INST_DEFINE(0, iaq_core_init, NULL,
&iaq_core_driver, NULL, POST_KERNEL, &iaq_core_driver, &iaq_core_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &iaq_core_driver_api); CONFIG_SENSOR_INIT_PRIORITY, &iaq_core_driver_api);

View file

@ -17,8 +17,11 @@ struct iaq_registers {
uint16_t voc; uint16_t voc;
} __packed; } __packed;
struct iaq_core_config {
struct i2c_dt_spec i2c;
};
struct iaq_core_data { struct iaq_core_data {
const struct device *i2c;
uint16_t co2; uint16_t co2;
uint16_t voc; uint16_t voc;
uint8_t status; uint8_t status;