devicetree: Add DT_INST version of some DT_*_HAS_* macros

Add DT_INST implementations of DT_PROP_HAS_IDX, DT_PHA_HAS_CELL_AT_IDX,
and DT_INST_PHA_HAS_CELL.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-03-25 16:36:57 -05:00 committed by Kumar Gala
commit ec4584348e
2 changed files with 39 additions and 4 deletions

View file

@ -1071,6 +1071,18 @@
#define DT_INST_PROP_BY_IDX(inst, prop, idx) \ #define DT_INST_PROP_BY_IDX(inst, prop, idx) \
DT_PROP_BY_IDX(DT_DRV_INST(inst), prop, idx) DT_PROP_BY_IDX(DT_DRV_INST(inst), prop, idx)
/**
* @brief Is index "idx" valid for an array type property
* on a DT_DRV_COMPAT instance?
* @param inst instance number
* @param prop lowercase-and-underscores property name
* @param idx index to check
* @return 1 if "idx" is a valid index into the given property,
* 0 otherwise.
*/
#define DT_INST_PROP_HAS_IDX(inst, prop, idx) \
DT_PROP_HAS_IDX(DT_DRV_INST(inst), prop, idx)
/** /**
* @brief Get a DT_DRV_COMPAT property length * @brief Get a DT_DRV_COMPAT property length
* @param inst instance number * @param inst instance number
@ -1329,6 +1341,31 @@
#define DT_INST_NODE_HAS_PROP(inst, prop) \ #define DT_INST_NODE_HAS_PROP(inst, prop) \
DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop) DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
/**
* @brief Does a phandle array have a named cell specifier at an index?
* for a DT_DRV_COMPAT instance
* @param inst instance number
* @param pha lowercase-and-underscores property with type "phandle-array"
* @param idx index to check
* @param cell named cell value whose existence to check
* @return 1 if the named cell exists in the specifier at index idx,
* 0 otherwise.
*/
#define DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, idx, cell) \
DT_PHA_HAS_CELL_AT_IDX(DT_DRV_INST(inst), pha, idx, cell)
/**
* @brief Does a phandle array have a named cell specifier at index 0
* for a DT_DRV_COMPAT instance?
* @param inst instance number
* @param pha lowercase-and-underscores property with type "phandle-array"
* @param cell named cell value whose existence to check
* @return 1 if the named cell exists in the specifier at index 0,
* 0 otherwise.
*/
#define DT_INST_PHA_HAS_CELL(inst, pha, cell) \
DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, 0, cell)
/** /**
* @brief is index valid for interrupt property on a DT_DRV_COMPAT instance? * @brief is index valid for interrupt property on a DT_DRV_COMPAT instance?
* Equivalent to DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx). * Equivalent to DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx).

View file

@ -581,7 +581,7 @@ static void test_phandles(void)
zassert_equal(ARRAY_SIZE(gps), 2, "gpios size"); zassert_equal(ARRAY_SIZE(gps), 2, "gpios size");
zassert_equal(DT_PROP_LEN(TEST_PH, gpios), 2, "pha len"); zassert_equal(DT_PROP_LEN(TEST_PH, gpios), 2, "pha len");
/* DT_PHA_HAS_IDX */ /* DT_PROP_HAS_IDX */
zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 0), "has idx 0"); zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 0), "has idx 0");
zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 1), "has idx 1"); zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 1), "has idx 1");
zassert_false(DT_PROP_HAS_IDX(TEST_PH, gpios, 2), "!has idx 2"); zassert_false(DT_PROP_HAS_IDX(TEST_PH, gpios, 2), "!has idx 2");
@ -686,8 +686,7 @@ static void test_phandles(void)
"TEST_GPIO_2"), "TEST_GPIO_2"),
"gpios[1].label"); "gpios[1].label");
#if 0 /* DT_INST_PROP_HAS_IDX */
/* DT_INST_PHA_HAS_IDX */
zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 0), "has idx 0"); zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 0), "has idx 0");
zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 1), "has idx 1"); zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 1), "has idx 1");
zassert_false(DT_INST_PROP_HAS_IDX(0, gpios, 2), "!has idx 2"); zassert_false(DT_INST_PROP_HAS_IDX(0, gpios, 2), "!has idx 2");
@ -710,7 +709,6 @@ static void test_phandles(void)
/* DT_INST_PHA_HAS_CELL */ /* DT_INST_PHA_HAS_CELL */
zassert_true(DT_INST_PHA_HAS_CELL(0, gpios, flags), "has gpio flags"); zassert_true(DT_INST_PHA_HAS_CELL(0, gpios, flags), "has gpio flags");
zassert_false(DT_INST_PHA_HAS_CELL(0, gpios, bar), "no gpio bar"); zassert_false(DT_INST_PHA_HAS_CELL(0, gpios, bar), "no gpio bar");
#endif
/* DT_INST_PHANDLE_BY_IDX */ /* DT_INST_PHANDLE_BY_IDX */
zassert_true(!strcmp(DT_LABEL(DT_INST_PHANDLE_BY_IDX(0, gpios, 0)), zassert_true(!strcmp(DT_LABEL(DT_INST_PHANDLE_BY_IDX(0, gpios, 0)),