Skip to content

Commit f463e6d

Browse files
gmarullcarlescufi
authored andcommitted
soc: nordic: pinctrl: rework nordic,clock-enable
Instead of forcing users to provide this setting, allow to describe which signals require CLOCKPIN enablement at device nodes. This is later captured by the pinctrl macros and applied in the pinctrl driver. Note that name has been adjusted to nordic,clockpin-enable to avoid confusion with clock related settings. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 72f90ee commit f463e6d

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

drivers/pinctrl/pinctrl_nrf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
365365
nrf_gpio_cfg(pin, dir, input, NRF_GET_PULL(pins[i]),
366366
drive, NRF_GPIO_PIN_NOSENSE);
367367
#if NRF_GPIO_HAS_CLOCKPIN
368-
nrf_gpio_pin_clock_set(pin, NRF_GET_CLOCK_ENABLE(pins[i]));
368+
nrf_gpio_pin_clock_set(pin, NRF_GET_CLOCKPIN_ENABLE(pins[i]));
369369
#endif
370370
}
371371
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
properties:
5+
nordic,clockpin-enable:
6+
type: array
7+
description: |
8+
List of signals that require CLOCKPIN setting enablement.

include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* The whole nRF pin configuration information is encoded in a 32-bit bitfield
1111
* organized as follows:
1212
*
13-
* - 31..17: Pin function.
13+
* - 31..18: Pin function.
14+
* - 17: Clockpin enable.
1415
* - 16: Pin inversion mode.
1516
* - 15: Pin low power mode.
1617
* - 14..11: Pin output drive configuration.
@@ -27,10 +28,10 @@
2728
#define NRF_FUN_POS 18U
2829
/** Mask for the function field. */
2930
#define NRF_FUN_MSK 0x3FFFU
30-
/** Position of the clock enable field. */
31-
#define NRF_CLOCK_ENABLE_POS 17U
32-
/** Mask for the clock enable field. */
33-
#define NRF_CLOCK_ENABLE_MSK 0x1U
31+
/** Position of the clockpin enable field. */
32+
#define NRF_CLOCKPIN_ENABLE_POS 17U
33+
/** Mask for the clockpin enable field. */
34+
#define NRF_CLOCKPIN_ENABLE_MSK 0x1U
3435
/** Position of the invert field. */
3536
#define NRF_INVERT_POS 16U
3637
/** Mask for the invert field. */

soc/nordic/common/pinctrl_soc.h

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,52 @@ extern "C" {
2525
/** Type for nRF pin. */
2626
typedef uint32_t pinctrl_soc_pin_t;
2727

28+
/**
29+
* @brief Utility macro to check if a function requires clockpin enable.
30+
*
31+
* @param node_id Node identifier.
32+
* @param prop Property name.
33+
* @param idx Property entry index.
34+
* @param p_node_id Parent node identifier.
35+
*/
36+
#define Z_CHECK_CLOCKPIN_ENABLE(node_id, prop, idx, fun) \
37+
DT_PROP_BY_IDX(node_id, prop, idx) == fun ? BIT(NRF_CLOCKPIN_ENABLE_POS) :
38+
39+
/**
40+
* @brief Utility macro compute the clockpin enable bit.
41+
*
42+
* @note DT_FOREACH_PROP_ELEM_SEP_VARGS() is used instead of
43+
* DT_FOREACH_PROP_ELEM_VARGS() because the latter is already resolved in the
44+
* same run.
45+
*
46+
* @param node_id Node identifier.
47+
* @param prop Property name.
48+
* @param idx Property entry index.
49+
* @param p_node_id Parent node identifier.
50+
*/
51+
#define Z_GET_CLOCKPIN_ENABLE(node_id, prop, idx, p_node_id) \
52+
COND_CODE_1(DT_NODE_HAS_PROP(p_node_id, nordic_clockpin_enable), \
53+
((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
54+
p_node_id, nordic_clockpin_enable, Z_CHECK_CLOCKPIN_ENABLE, \
55+
(), NRF_GET_FUN(DT_PROP_BY_IDX(node_id, prop, idx))) \
56+
0)), (0))
57+
2858
/**
2959
* @brief Utility macro to initialize each pin.
3060
*
3161
* @param node_id Node identifier.
3262
* @param prop Property name.
3363
* @param idx Property entry index.
64+
* @param p_node_id Parent node identifier.
3465
*/
35-
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
66+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx, p_node_id) \
3667
(DT_PROP_BY_IDX(node_id, prop, idx) | \
3768
((NRF_PULL_DOWN * DT_PROP(node_id, bias_pull_down)) << NRF_PULL_POS) |\
3869
((NRF_PULL_UP * DT_PROP(node_id, bias_pull_up)) << NRF_PULL_POS) | \
3970
(DT_PROP(node_id, nordic_drive_mode) << NRF_DRIVE_POS) | \
4071
((NRF_LP_ENABLE * DT_PROP(node_id, low_power_enable)) << NRF_LP_POS) |\
4172
(DT_PROP(node_id, nordic_invert) << NRF_INVERT_POS) | \
42-
(DT_PROP(node_id, nordic_clock_enable) << NRF_CLOCK_ENABLE_POS) \
73+
Z_GET_CLOCKPIN_ENABLE(node_id, prop, idx, p_node_id) \
4374
),
4475

4576
/**
@@ -50,8 +81,8 @@ typedef uint32_t pinctrl_soc_pin_t;
5081
*/
5182
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
5283
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
53-
DT_FOREACH_PROP_ELEM, psels, \
54-
Z_PINCTRL_STATE_PIN_INIT)}
84+
DT_FOREACH_PROP_ELEM_VARGS, psels, \
85+
Z_PINCTRL_STATE_PIN_INIT, node_id)}
5586

5687
/**
5788
* @brief Utility macro to obtain pin function.
@@ -61,11 +92,12 @@ typedef uint32_t pinctrl_soc_pin_t;
6192
#define NRF_GET_FUN(pincfg) (((pincfg) >> NRF_FUN_POS) & NRF_FUN_MSK)
6293

6394
/**
64-
* @brief Utility macro to obtain pin clock enable flag.
95+
* @brief Utility macro to obtain pin clockpin enable flag.
6596
*
6697
* @param pincfg Pin configuration bit field.
6798
*/
68-
#define NRF_GET_CLOCK_ENABLE(pincfg) (((pincfg) >> NRF_CLOCK_ENABLE_POS) & NRF_CLOCK_ENABLE_MSK)
99+
#define NRF_GET_CLOCKPIN_ENABLE(pincfg) \
100+
(((pincfg) >> NRF_CLOCKPIN_ENABLE_POS) & NRF_CLOCKPIN_ENABLE_MSK)
69101

70102
/**
71103
* @brief Utility macro to obtain pin inversion flag.

0 commit comments

Comments
 (0)