@@ -2517,24 +2517,26 @@ function(dt_num_regs var)
2517
2517
endfunction ()
2518
2518
2519
2519
# Usage:
2520
- # dt_reg_addr(<var> PATH <path> [INDEX <idx>])
2520
+ # dt_reg_addr(<var> PATH <path> [INDEX <idx>] [NAME <name>] )
2521
2521
#
2522
- # Get the base address of the register block at index <idx>.
2523
- # If <idx> is omitted, then the value at index 0 will be returned.
2522
+ # Get the base address of the register block at index <idx>, or with
2523
+ # name <name>. If <idx> and <name> are both omitted, the value at
2524
+ # index 0 will be returned. Do not give both <idx> and <name>.
2524
2525
#
2525
2526
# The value will be returned in the <var> parameter.
2526
2527
#
2527
2528
# Results can be:
2528
2529
# - The base address of the register block
2529
2530
# - <var> will be undefined if node does not exists or does not have a register
2530
- # block at the requested index.
2531
+ # block at the requested index or with the requested name
2531
2532
#
2532
2533
# <var> : Return variable where the address value will be stored
2533
2534
# PATH <path> : Node path
2534
- # INDEX <idx> : Index number
2535
+ # INDEX <idx> : Register block index number
2536
+ # NAME <name> : Register block name
2535
2537
function (dt_reg_addr var)
2536
2538
set (req_single_args "PATH" )
2537
- set (single_args "INDEX" )
2539
+ set (single_args "INDEX;NAME " )
2538
2540
cmake_parse_arguments (DT_REG "" "${req_single_args} ;${single_args} " "" ${ARGN} )
2539
2541
2540
2542
if (${ARGV0} IN_LIST req_single_args)
@@ -2549,8 +2551,16 @@ function(dt_reg_addr var)
2549
2551
endif ()
2550
2552
endforeach ()
2551
2553
2552
- if (NOT DEFINED DT_REG_INDEX)
2554
+ if (DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
2555
+ message (FATAL_ERROR "dt_reg_addr(${ARGV0} ...) given both INDEX and NAME" )
2556
+ elseif (NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
2553
2557
set (DT_REG_INDEX 0)
2558
+ elseif (DEFINED DT_REG_NAME)
2559
+ _dt_reg_get_index(DT_REG_INDEX "${DT_REG_PATH} " "${DT_REG_NAME} " )
2560
+ if (DT_REG_INDEX EQUAL "-1" )
2561
+ set (${var} PARENT_SCOPE)
2562
+ return ()
2563
+ endif ()
2554
2564
endif ()
2555
2565
2556
2566
get_target_property (${var} _list devicetree_target "DT_REG|${DT_REG_PATH} |ADDR" )
@@ -2565,19 +2575,21 @@ function(dt_reg_addr var)
2565
2575
endfunction ()
2566
2576
2567
2577
# Usage:
2568
- # dt_reg_size(<var> PATH <path> [INDEX <idx>])
2578
+ # dt_reg_size(<var> PATH <path> [INDEX <idx>] [NAME <name>] )
2569
2579
#
2570
- # Get the size of the register block at index <idx>.
2571
- # If INDEX is omitted, then the value at index 0 will be returned.
2580
+ # Get the size of the register block at index <idx>, or with
2581
+ # name <name>. If <idx> and <name> are both omitted, the value at
2582
+ # index 0 will be returned. Do not give both <idx> and <name>.
2572
2583
#
2573
2584
# The value will be returned in the <value> parameter.
2574
2585
#
2575
2586
# <var> : Return variable where the size value will be stored
2576
2587
# PATH <path> : Node path
2577
- # INDEX <idx> : Index number
2588
+ # INDEX <idx> : Register block index number
2589
+ # NAME <name> : Register block name
2578
2590
function (dt_reg_size var)
2579
2591
set (req_single_args "PATH" )
2580
- set (single_args "INDEX" )
2592
+ set (single_args "INDEX;NAME " )
2581
2593
cmake_parse_arguments (DT_REG "" "${req_single_args} ;${single_args} " "" ${ARGN} )
2582
2594
2583
2595
if (${ARGV0} IN_LIST req_single_args)
@@ -2592,8 +2604,16 @@ function(dt_reg_size var)
2592
2604
endif ()
2593
2605
endforeach ()
2594
2606
2595
- if (NOT DEFINED DT_REG_INDEX)
2607
+ if (DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
2608
+ message (FATAL_ERROR "dt_reg_size(${ARGV0} ...) given both INDEX and NAME" )
2609
+ elseif (NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
2596
2610
set (DT_REG_INDEX 0)
2611
+ elseif (DEFINED DT_REG_NAME)
2612
+ _dt_reg_get_index(DT_REG_INDEX "${DT_REG_PATH} " "${DT_REG_NAME} " )
2613
+ if (DT_REG_INDEX EQUAL "-1" )
2614
+ set (${var} PARENT_SCOPE)
2615
+ return ()
2616
+ endif ()
2597
2617
endif ()
2598
2618
2599
2619
get_target_property (${var} _list devicetree_target "DT_REG|${DT_REG_PATH} |SIZE" )
@@ -2607,6 +2627,17 @@ function(dt_reg_size var)
2607
2627
set (${var} ${${var} } PARENT_SCOPE)
2608
2628
endfunction ()
2609
2629
2630
+ # Internal helper for dt_reg_addr/dt_reg_size; not meant to be used directly
2631
+ function (_dt_reg_get_index var path name )
2632
+ dt_prop(reg_names PATH "${path} " PROPERTY "reg-names" )
2633
+ if (NOT DEFINED reg_names)
2634
+ set (index "-1" )
2635
+ else ()
2636
+ list (FIND reg_names "${name} " index)
2637
+ endif ()
2638
+ set ("${var} " "${index} " PARENT_SCOPE)
2639
+ endfunction ()
2640
+
2610
2641
# Usage:
2611
2642
# dt_has_chosen(<var> PROPERTY <prop>)
2612
2643
#
0 commit comments