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:
Martí Bolívar 2020-05-05 16:06:32 -07:00 committed by Kumar Gala
commit 87e1743ae0
46 changed files with 571 additions and 1301 deletions

View file

@ -200,7 +200,14 @@ static const struct counter_driver_api mcux_lptmr_driver_api = {
#define LPTMR_GLITCH_32768 kLPTMR_Prescale_Glitch_15
#define TO_LPTMR_GLITCH(val) _DO_CONCAT(LPTMR_GLITCH_, val)
#if DT_HAS_DRV_INST(0)
/*
* This driver is single-instance. If the devicetree contains multiple
* instances, this will fail and the driver needs to be revisited.
*/
BUILD_ASSERT(DT_NUM_INST(DT_DRV_COMPAT) <= 1,
"unsupported lptmr instance");
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(0))
static struct mcux_lptmr_data mcux_lptmr_data_0;
static void mcux_lptmr_irq_config_0(struct device *dev);
@ -247,4 +254,4 @@ static void mcux_lptmr_irq_config_0(struct device *dev)
mcux_lptmr_isr, DEVICE_GET(mcux_lptmr_0), 0);
irq_enable(DT_INST_IRQN(0));
}
#endif /* DT_HAS_DRV_INST(0) */
#endif /* DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(0)) */