devicetree: replace DT_HAS_DRV_INST with DT_INST_FOREACH
Make drivers multi-instance wherever possible using DT_INST_FOREACH. This allows removing DT_HAS_DRV_INST in favor of making drivers just do the right thing regardless of how many instances there are. There are a few exceptions: - SoC drivers which use CMake input files (like i2c_dw.c) or otherwise would require more time to convert than I have at the moment. For the sake of expediency, just inline the DT_HAS_DRV_INST expansion for now in these cases. - SoC drivers which are explicitly single-instance (like the nRF SAADC driver). Again for the sake of expediency, drop a BUILD_ASSERT in those cases to make sure the assumption that all supported SoCs have at most one available instance is valid, failing fast otherwise. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
763a9433a7
commit
87e1743ae0
46 changed files with 571 additions and 1301 deletions
|
@ -463,103 +463,44 @@ static const struct led_driver_api ht16k33_leds_api = {
|
|||
|
||||
#define HT16K33_DEVICE(id) \
|
||||
static const struct ht16k33_cfg ht16k33_##id##_cfg = { \
|
||||
.i2c_dev_name = DT_INST_BUS_LABEL(id), \
|
||||
.i2c_addr = DT_INST_REG_ADDR(id), \
|
||||
.i2c_dev_name = DT_INST_BUS_LABEL(id), \
|
||||
.i2c_addr = DT_INST_REG_ADDR(id), \
|
||||
.irq_enabled = false, \
|
||||
}; \
|
||||
\
|
||||
static struct ht16k33_data ht16k33_##id##_data; \
|
||||
static struct ht16k33_data ht16k33_##id##_data; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(ht16k33_##id, DT_INST_LABEL(id), \
|
||||
&ht16k33_init, &ht16k33_##id##_data, \
|
||||
&ht16k33_##id##_cfg, POST_KERNEL, \
|
||||
CONFIG_LED_INIT_PRIORITY, &ht16k33_leds_api)
|
||||
DEVICE_AND_API_INIT(ht16k33_##id, DT_INST_LABEL(id), \
|
||||
&ht16k33_init, &ht16k33_##id##_data, \
|
||||
&ht16k33_##id##_cfg, POST_KERNEL, \
|
||||
CONFIG_LED_INIT_PRIORITY, &ht16k33_leds_api)
|
||||
|
||||
#ifdef CONFIG_HT16K33_KEYSCAN
|
||||
#define HT16K33_DEVICE_WITH_IRQ(id) \
|
||||
static const struct ht16k33_cfg ht16k33_##id##_cfg = { \
|
||||
.i2c_dev_name = DT_INST_BUS_LABEL(id), \
|
||||
.i2c_addr = DT_INST_REG_ADDR(id), \
|
||||
.i2c_dev_name = DT_INST_BUS_LABEL(id), \
|
||||
.i2c_addr = DT_INST_REG_ADDR(id), \
|
||||
.irq_enabled = true, \
|
||||
.irq_dev_name = \
|
||||
DT_INST_GPIO_LABEL(id, irq_gpios), \
|
||||
DT_INST_GPIO_LABEL(id, irq_gpios), \
|
||||
.irq_pin = DT_INST_GPIO_PIN(id, irq_gpios), \
|
||||
.irq_flags = \
|
||||
DT_INST_GPIO_FLAGS(id, irq_gpios), \
|
||||
DT_INST_GPIO_FLAGS(id, irq_gpios), \
|
||||
}; \
|
||||
\
|
||||
static struct ht16k33_data ht16k33_##id##_data; \
|
||||
static struct ht16k33_data ht16k33_##id##_data; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(ht16k33_##id, DT_INST_LABEL(id), \
|
||||
&ht16k33_init, &ht16k33_##id##_data, \
|
||||
&ht16k33_##id##_cfg, POST_KERNEL, \
|
||||
CONFIG_LED_INIT_PRIORITY, &ht16k33_leds_api)
|
||||
DEVICE_AND_API_INIT(ht16k33_##id, DT_INST_LABEL(id), \
|
||||
&ht16k33_init, &ht16k33_##id##_data, \
|
||||
&ht16k33_##id##_cfg, POST_KERNEL, \
|
||||
CONFIG_LED_INIT_PRIORITY, &ht16k33_leds_api)
|
||||
#else /* ! CONFIG_HT16K33_KEYSCAN */
|
||||
#define HT16K33_DEVICE_WITH_IRQ(id) HT16K33_DEVICE(id)
|
||||
#endif /* ! CONFIG_HT16K33_KEYSCAN */
|
||||
|
||||
/* Support up to eight HT16K33 devices */
|
||||
#define HT16K33_INSTANTIATE(id) \
|
||||
COND_CODE_1(DT_INST_NODE_HAS_PROP(id, irq_gpios), \
|
||||
(HT16K33_DEVICE_WITH_IRQ(id)), \
|
||||
(HT16K33_DEVICE(id)))
|
||||
|
||||
#if DT_HAS_DRV_INST(0)
|
||||
#if DT_INST_NODE_HAS_PROP(0, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(0);
|
||||
#else
|
||||
HT16K33_DEVICE(0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(1)
|
||||
#if DT_INST_NODE_HAS_PROP(1, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(1);
|
||||
#else
|
||||
HT16K33_DEVICE(1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(2)
|
||||
#if DT_INST_NODE_HAS_PROP(2, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(2);
|
||||
#else
|
||||
HT16K33_DEVICE(2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(3)
|
||||
#if DT_INST_NODE_HAS_PROP(3, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(3);
|
||||
#else
|
||||
HT16K33_DEVICE(3);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(4)
|
||||
#if DT_INST_NODE_HAS_PROP(4, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(4);
|
||||
#else
|
||||
HT16K33_DEVICE(4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(5)
|
||||
#if DT_INST_NODE_HAS_PROP(5, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(5);
|
||||
#else
|
||||
HT16K33_DEVICE(5);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(6)
|
||||
#if DT_INST_NODE_HAS_PROP(6, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(6);
|
||||
#else
|
||||
HT16K33_DEVICE(6);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DT_HAS_DRV_INST(7)
|
||||
#if DT_INST_NODE_HAS_PROP(7, irq_gpios)
|
||||
HT16K33_DEVICE_WITH_IRQ(7);
|
||||
#else
|
||||
HT16K33_DEVICE(7);
|
||||
#endif
|
||||
#endif
|
||||
DT_INST_FOREACH(HT16K33_INSTANTIATE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue