drivers: sensor: bmc150_magn: Update driver to use gpio_dt_spec
Simplify driver by using gpio_dt_spec for bus access.
Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
diff --git a/drivers/sensor/bmc150_magn/bmc150_magn.c b/drivers/sensor/bmc150_magn/bmc150_magn.c
index 19ab6b6..f84fcba 100644
--- a/drivers/sensor/bmc150_magn/bmc150_magn.c
+++ b/drivers/sensor/bmc150_magn/bmc150_magn.c
@@ -587,11 +587,8 @@
static const struct bmc150_magn_config bmc150_magn_config = {
.i2c = I2C_DT_SPEC_INST_GET(0),
-#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
- .gpio_drdy_dev_name = DT_INST_GPIO_LABEL(0, drdy_gpios),
- .gpio_drdy_int_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
- .gpio_drdy_int_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
-#endif
+ IF_ENABLED(CONFIG_BMC150_MAGN_TRIGGER_DRDY,
+ (.int_gpio = GPIO_DT_SPEC_INST_GET(0, drdy_gpios),))
};
static struct bmc150_magn_data bmc150_magn_data;
diff --git a/drivers/sensor/bmc150_magn/bmc150_magn.h b/drivers/sensor/bmc150_magn/bmc150_magn.h
index 5c4e0a0..7a7ea67 100644
--- a/drivers/sensor/bmc150_magn/bmc150_magn.h
+++ b/drivers/sensor/bmc150_magn/bmc150_magn.h
@@ -86,9 +86,7 @@
struct bmc150_magn_config {
struct i2c_dt_spec i2c;
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
- char *gpio_drdy_dev_name;
- gpio_pin_t gpio_drdy_int_pin;
- gpio_dt_flags_t gpio_drdy_int_flags;
+ struct gpio_dt_spec int_gpio;
#endif
};
diff --git a/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c b/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c
index 7920b27..eb1b141 100644
--- a/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c
+++ b/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c
@@ -18,15 +18,11 @@
static inline void setup_drdy(const struct device *dev,
bool enable)
{
- struct bmc150_magn_data *data = dev->data;
const struct bmc150_magn_config *const cfg =
dev->config;
- gpio_pin_interrupt_configure(data->gpio_drdy,
- cfg->gpio_drdy_int_pin,
- enable
- ? GPIO_INT_EDGE_TO_ACTIVE
- : GPIO_INT_DISABLE);
+ gpio_pin_interrupt_configure_dt(&cfg->int_gpio,
+ enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
}
@@ -105,7 +101,6 @@
static int bmc150_magn_set_drdy_polarity(const struct device *dev, int state)
{
- struct bmc150_magn_data *data = dev->data;
const struct bmc150_magn_config *config = dev->config;
if (state) {
@@ -150,22 +145,18 @@
data, NULL, NULL,
K_PRIO_COOP(10), 0, K_NO_WAIT);
- data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
- if (!data->gpio_drdy) {
- LOG_DBG("gpio controller %s not found",
- config->gpio_drdy_dev_name);
- return -EINVAL;
+ if (!device_is_ready(config->int_gpio.port)) {
+ LOG_ERR("GPIO device not ready");
+ return -ENODEV;
}
- gpio_pin_configure(data->gpio_drdy, config->gpio_drdy_int_pin,
- config->gpio_drdy_int_flags
- | GPIO_INT_EDGE_TO_ACTIVE);
+ gpio_pin_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&data->gpio_cb,
bmc150_magn_gpio_drdy_callback,
- BIT(config->gpio_drdy_int_pin));
+ BIT(config->int_gpio.pin));
- if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
+ if (gpio_add_callback(config->int_gpio.port, &data->gpio_cb) < 0) {
LOG_DBG("failed to set gpio callback");
return -EIO;
}