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

@ -40,42 +40,31 @@ struct adc_hdl {
u8_t resolution;
};
#define ADC_HDL_LIST_ENTRY(inst) \
{ \
.device_name = DT_INST_LABEL(inst), \
.channel_config = { \
.gain = ADC_GAIN_1, \
.reference = ADC_REF_INTERNAL, \
.acquisition_time = ADC_ACQ_TIME_DEFAULT, \
.channel_id = 0, \
}, \
.resolution = 0, \
}
/*
* TODO generalize with a more flexible for-each macro that doesn't
* assume a semicolon separator.
*/
struct adc_hdl adc_list[] = {
#if DT_HAS_DRV_INST(0)
{
.device_name = DT_INST_LABEL(0),
.channel_config = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 0,
},
.resolution = 0,
},
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(0))
ADC_HDL_LIST_ENTRY(0),
#endif
#if DT_HAS_DRV_INST(1)
{
.device_name = DT_INST_LABEL(1),
.channel_config = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 0,
},
.resolution = 0,
},
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(1))
ADC_HDL_LIST_ENTRY(1),
#endif
#if DT_HAS_DRV_INST(2)
{
.device_name = DT_INST_LABEL(2),
.channel_config = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 0,
},
.resolution = 0,
},
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(2))
ADC_HDL_LIST_ENTRY(2),
#endif
};
@ -475,18 +464,25 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_adc_cmds,
SHELL_SUBCMD_SET_END /* Array terminated. */
);
SHELL_STATIC_SUBCMD_SET_CREATE(sub_adc,
#if DT_HAS_DRV_INST(0)
SHELL_CMD(ADC_0, &sub_adc_cmds, "ADC_0", NULL),
#define ADC_SHELL_COMMAND(inst) \
SHELL_CMD(ADC_##inst, &sub_adc_cmds, "ADC_" #inst, NULL),
/*
* TODO generalize with a more flexible for-each macro that doesn't
* assume a semicolon separator.
*/
SHELL_STATIC_SUBCMD_SET_CREATE(
sub_adc,
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(0))
ADC_SHELL_COMMAND(0),
#endif
#if DT_HAS_DRV_INST(1)
SHELL_CMD(ADC_1, &sub_adc_cmds, "ADC_1", NULL),
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(1))
ADC_SHELL_COMMAND(1),
#endif
#if DT_HAS_DRV_INST(2)
SHELL_CMD(ADC_2, &sub_adc_cmds, "ADC_2", NULL),
#if DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(2))
ADC_SHELL_COMMAND(2),
#endif
SHELL_SUBCMD_SET_END /* Array terminated. */
);
SHELL_CMD_REGISTER(adc, &sub_adc, "ADC commands", NULL);