refactor: Move away from deprecated label usages.

* Move away from DT_LABEL.
* Move to DEVICE_DT_GET for non-behavior device access.
* Move various drivers to `gpio_spec_dt` and `DT` related macros.
* Remove mcp23017 while at it, since better upstream driver is
  available.
This commit is contained in:
Peter Johanson
2023-01-17 20:40:44 -05:00
committed by Pete Johanson
parent 062f94d014
commit 09ed79a867
41 changed files with 199 additions and 828 deletions

View File

@@ -19,11 +19,9 @@
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
static int ec11_get_ab_state(const struct device *dev) {
struct ec11_data *drv_data = dev->data;
const struct ec11_config *drv_cfg = dev->config;
return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) |
gpio_pin_get(drv_data->b, drv_cfg->b_pin);
return (gpio_pin_get_dt(&drv_cfg->a) << 1) | gpio_pin_get_dt(&drv_cfg->b);
}
static int ec11_sample_fetch(const struct device *dev, enum sensor_channel chan) {
@@ -94,27 +92,25 @@ int ec11_init(const struct device *dev) {
struct ec11_data *drv_data = dev->data;
const struct ec11_config *drv_cfg = dev->config;
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a_label, drv_cfg->a_pin, drv_cfg->b_label,
drv_cfg->b_pin, drv_cfg->resolution);
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a.port->name, drv_cfg->a.pin,
drv_cfg->b.port->name, drv_cfg->b.pin, drv_cfg->resolution);
drv_data->a = device_get_binding(drv_cfg->a_label);
if (drv_data->a == NULL) {
LOG_ERR("Failed to get pointer to A GPIO device");
if (!device_is_ready(drv_cfg->a.port)) {
LOG_ERR("A GPIO device is not ready");
return -EINVAL;
}
drv_data->b = device_get_binding(drv_cfg->b_label);
if (drv_data->b == NULL) {
LOG_ERR("Failed to get pointer to B GPIO device");
if (!device_is_ready(drv_cfg->b.port)) {
LOG_ERR("B GPIO device is not ready");
return -EINVAL;
}
if (gpio_pin_configure(drv_data->a, drv_cfg->a_pin, drv_cfg->a_flags | GPIO_INPUT)) {
if (gpio_pin_configure_dt(&drv_cfg->a, GPIO_INPUT)) {
LOG_DBG("Failed to configure A pin");
return -EIO;
}
if (gpio_pin_configure(drv_data->b, drv_cfg->b_pin, drv_cfg->b_flags | GPIO_INPUT)) {
if (gpio_pin_configure_dt(&drv_cfg->b, GPIO_INPUT)) {
LOG_DBG("Failed to configure B pin");
return -EIO;
}
@@ -134,12 +130,8 @@ int ec11_init(const struct device *dev) {
#define EC11_INST(n) \
struct ec11_data ec11_data_##n; \
const struct ec11_config ec11_cfg_##n = { \
.a_label = DT_INST_GPIO_LABEL(n, a_gpios), \
.a_pin = DT_INST_GPIO_PIN(n, a_gpios), \
.a_flags = DT_INST_GPIO_FLAGS(n, a_gpios), \
.b_label = DT_INST_GPIO_LABEL(n, b_gpios), \
.b_pin = DT_INST_GPIO_PIN(n, b_gpios), \
.b_flags = DT_INST_GPIO_FLAGS(n, b_gpios), \
.a = GPIO_DT_SPEC_INST_GET(n, a_gpios), \
.b = GPIO_DT_SPEC_INST_GET(n, b_gpios), \
COND_CODE_0(DT_INST_NODE_HAS_PROP(n, resolution), (1), (DT_INST_PROP(n, resolution))), \
}; \
DEVICE_DT_INST_DEFINE(n, ec11_init, NULL, &ec11_data_##n, &ec11_cfg_##n, POST_KERNEL, \