devicetree.h: clocks: Add support for _BY_NAME macros
Add the following macro's to get clock info by name: DT_CLOCKS_LABEL_BY_NAME DT_CLOCKS_CELL_BY_NAME DT_INST_CLOCKS_LABEL_BY_NAME DT_INST_CLOCKS_CELL_BY_NAME Signed-off-by: Kumar Gala <kumar.gala@linaro.org> Co-Authored-By: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
c28a3e82bb
commit
fc6aa9214c
3 changed files with 112 additions and 0 deletions
|
@ -54,6 +54,39 @@ extern "C" {
|
|||
#define DT_CLOCKS_LABEL_BY_IDX(node_id, idx) \
|
||||
DT_PROP_BY_PHANDLE_IDX(node_id, clocks, idx, label)
|
||||
|
||||
/**
|
||||
* @brief Get clock controller "name" (label property) by name
|
||||
*
|
||||
* It's an error if the clock controller referenced by the phandle
|
||||
* in property "clocks" at index "idx" has no label property.
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* clk1: clkctrl@... {
|
||||
* label = "CLK_1";
|
||||
* };
|
||||
*
|
||||
* clk2: clkctrl@... {
|
||||
* label = "CLK_2";
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* clocks = <&clk1 10 20>, <&clk2 30 40>;
|
||||
* clock-names = "alpha", "beta";
|
||||
* };
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_CLOCKS_LABEL_BY_NAME(DT_NODELABEL(n), beta) // "CLK_2"
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores "clock" name
|
||||
* @return the label property for the referenced node by name
|
||||
* @see DT_PHANDLE_BY_NAME()
|
||||
*/
|
||||
#define DT_CLOCKS_LABEL_BY_NAME(node_id, name) \
|
||||
DT_PROP(DT_PHANDLE_BY_NAME(node_id, clocks, name), label)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_CLOCKS_LABEL_BY_IDX(node_id, 0)
|
||||
* @param node_id node identifier
|
||||
|
@ -96,6 +129,41 @@ extern "C" {
|
|||
#define DT_CLOCKS_CELL_BY_IDX(node_id, cell, idx) \
|
||||
DT_PHA_BY_IDX(node_id, clocks, idx, cell)
|
||||
|
||||
/**
|
||||
* @brief Get clock controller "cell" value by name
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* clk1: clkctrl@... {
|
||||
* label = "CLK_1";
|
||||
* #clock-cells = < 2 >;
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* clocks = < &clk1 10 20 >, < &clk1 30 40 >;
|
||||
* clock-names = "alpha", "beta";
|
||||
* };
|
||||
*
|
||||
* Bindings fragment for the clk1 node:
|
||||
*
|
||||
* clock-cells:
|
||||
* - bus
|
||||
* - bits
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_CLOCKS_CELL_BY_NAME(DT_NODELABEL(n), alpha, bus) // 10
|
||||
* DT_CLOCKS_CELL_BY_NAME(DT_NODELABEL(n), beta, bits) // 40
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores specifier name
|
||||
* @param cell binding's cell name within the specifier referenced as "name"
|
||||
* @return the value of the cell inside the named specifier
|
||||
* @see DT_PHA_PHANDLE_IDX()
|
||||
*/
|
||||
#define DT_CLOCKS_CELL_BY_NAME(node_id, name, cell) \
|
||||
DT_PHA_BY_NAME(node_id, clocks, name, cell)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_CLOCKS_CELL_BY_IDX(node_id, cell, 0)
|
||||
* @param node_id node identifier
|
||||
|
@ -115,6 +183,16 @@ extern "C" {
|
|||
#define DT_INST_CLOCKS_LABEL_BY_IDX(inst, idx) \
|
||||
DT_CLOCKS_LABEL_BY_IDX(DT_DRV_INST(inst), idx)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "name" (label property) by name
|
||||
* (see @ref DT_CLOCKS_LABEL_BY_NAME)
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores specifier name
|
||||
* @return the label property for the named specifier by name
|
||||
*/
|
||||
#define DT_INST_CLOCKS_LABEL_BY_NAME(inst, name) \
|
||||
DT_CLOCKS_LABEL_BY_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "name"
|
||||
* (see @ref DT_CLOCKS_LABEL_BY_IDX)
|
||||
|
@ -133,6 +211,17 @@ extern "C" {
|
|||
#define DT_INST_CLOCKS_CELL_BY_IDX(inst, cell, idx) \
|
||||
DT_CLOCKS_CELL_BY_IDX(DT_DRV_INST(inst), cell, idx)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "cell" value by name
|
||||
* (see @ref DT_CLOCKS_CELL_BY_NAME)
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores specifier name
|
||||
* @param cell binding's cell name within the specifier referenced as "name"
|
||||
* @return the value of the cell inside the named specifier
|
||||
*/
|
||||
#define DT_INST_CLOCKS_CELL_BY_NAME(inst, name, cell) \
|
||||
DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(inst), name, cell)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "cell" value at an index 0
|
||||
* @param inst instance number
|
||||
|
|
|
@ -222,6 +222,7 @@
|
|||
dmas = <&test_dma1 1 2>, <&test_dma2 3 4>;
|
||||
dma-names = "tx", "rx";
|
||||
clocks = <&test_clk 3 7>, <&test_fixed_clk>, <&test_clk 8 2>;
|
||||
clock-names = "clk-a", "clk-fixed", "clk-b";
|
||||
};
|
||||
|
||||
/* there should only be one of these */
|
||||
|
|
|
@ -1173,6 +1173,11 @@ static void test_clocks(void)
|
|||
"TEST_CLOCK"),
|
||||
"label 0");
|
||||
|
||||
/* DT_CLOCKS_LABEL_BY_NAME */
|
||||
zassert_true(!strcmp(DT_CLOCKS_LABEL_BY_NAME(TEST_TEMP, clk_b),
|
||||
"TEST_CLOCK"),
|
||||
"label b");
|
||||
|
||||
/* DT_CLOCKS_LABEL */
|
||||
zassert_true(!strcmp(DT_CLOCKS_LABEL(TEST_TEMP), "TEST_CLOCK"),
|
||||
"label 0");
|
||||
|
@ -1182,6 +1187,12 @@ static void test_clocks(void)
|
|||
"clk 2 bits");
|
||||
zassert_equal(DT_CLOCKS_CELL_BY_IDX(TEST_TEMP, bus, 2), 8, "clk 2 bus");
|
||||
|
||||
/* DT_CLOCKS_CELL_BY_NAME */
|
||||
zassert_equal(DT_CLOCKS_CELL_BY_NAME(TEST_TEMP, clk_a, bits), 7,
|
||||
"clk-a bits");
|
||||
zassert_equal(DT_CLOCKS_CELL_BY_NAME(TEST_TEMP, clk_b, bus), 8,
|
||||
"clk-b bus");
|
||||
|
||||
/* DT_CLOCKS_CELL */
|
||||
zassert_equal(DT_CLOCKS_CELL(TEST_TEMP, bits), 7, "clk bits");
|
||||
zassert_equal(DT_CLOCKS_CELL(TEST_TEMP, bus), 3, "clk bus");
|
||||
|
@ -1199,6 +1210,11 @@ static void test_clocks(void)
|
|||
"TEST_CLOCK"),
|
||||
"label 0");
|
||||
|
||||
/* DT_INST_CLOCKS_LABEL_BY_NAME */
|
||||
zassert_true(!strcmp(DT_INST_CLOCKS_LABEL_BY_NAME(0, clk_b),
|
||||
"TEST_CLOCK"),
|
||||
"label b");
|
||||
|
||||
/* DT_INST_CLOCKS_LABEL */
|
||||
zassert_true(!strcmp(DT_INST_CLOCKS_LABEL(0), "TEST_CLOCK"),
|
||||
"label 0");
|
||||
|
@ -1208,6 +1224,12 @@ static void test_clocks(void)
|
|||
"clk 2 bits");
|
||||
zassert_equal(DT_INST_CLOCKS_CELL_BY_IDX(0, bus, 2), 8, "clk 2 bus");
|
||||
|
||||
/* DT_INST_CLOCKS_CELL_BY_NAME */
|
||||
zassert_equal(DT_INST_CLOCKS_CELL_BY_NAME(0, clk_a, bits), 7,
|
||||
"clk-a bits");
|
||||
zassert_equal(DT_INST_CLOCKS_CELL_BY_NAME(0, clk_b, bus), 8,
|
||||
"clk-b bus");
|
||||
|
||||
/* DT_INST_CLOCKS_CELL */
|
||||
zassert_equal(DT_INST_CLOCKS_CELL(0, bits), 7, "clk bits");
|
||||
zassert_equal(DT_INST_CLOCKS_CELL(0, bus), 3, "clk bus");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue