Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: pinctrl: nrf: Add support for setting initial pin state #61280

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/pinctrl/pinctrl_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
#if defined(NRF_PSEL_SPIM)
case NRF_FUN_SPIM_SCK:
NRF_PSEL_SPIM(reg, SCK) = psel;
write = 0U;
write = NRF_GET_INIT(pins[i]);
dir = NRF_GPIO_PIN_DIR_OUTPUT;
input = NRF_GPIO_PIN_INPUT_CONNECT;
break;
Expand Down
2 changes: 2 additions & 0 deletions dts/bindings/pinctrl/nordic,nrf-pinctrl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ child-binding:
- bias-pull-down
- bias-pull-up
- low-power-enable
- output-high
- output-low

properties:
psels:
Expand Down
21 changes: 19 additions & 2 deletions include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* The whole nRF pin configuration information is encoded in a 32-bit bitfield
* organized as follows:
*
* - 31..16: Pin function.
* - 31 Pin initial state.
* - 30..16: Pin function.
* - 15: Reserved.
* - 14: Pin inversion mode.
* - 13: Pin low power mode.
Expand All @@ -24,10 +25,14 @@
* @{
*/

/** Position of the output initial state. */
#define NRF_INIT_POS 31U
/** Mask for the output initial state. */
#define NRF_INIT_MSK 0x1U
/** Position of the function field. */
#define NRF_FUN_POS 16U
/** Mask for the function field. */
#define NRF_FUN_MSK 0xFFFFU
#define NRF_FUN_MSK 0x7FFFU
/** Position of the invert field. */
#define NRF_INVERT_POS 14U
/** Mask for the invert field. */
Expand Down Expand Up @@ -193,6 +198,18 @@

/** @} */

/**
* @name nRF pinctrl init state.
* @{
*/

/** High initial pin state. */
#define NRF_INIT_HIGH 1U
/** Low initial pin state. */
#define NRF_INIT_LOW 0U

/** @} */

/**
* @brief Utility macro to build nRF psels property entry.
*
Expand Down
11 changes: 10 additions & 1 deletion soc/arm/nordic_nrf/common/pinctrl_soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ typedef uint32_t pinctrl_soc_pin_t;
((NRF_PULL_UP * DT_PROP(node_id, bias_pull_up)) << NRF_PULL_POS) | \
(DT_PROP(node_id, nordic_drive_mode) << NRF_DRIVE_POS) | \
((NRF_LP_ENABLE * DT_PROP(node_id, low_power_enable)) << NRF_LP_POS) |\
(DT_PROP(node_id, nordic_invert) << NRF_INVERT_POS) \
(DT_PROP(node_id, nordic_invert) << NRF_INVERT_POS) | \
((NRF_INIT_LOW * DT_PROP(node_id, output_low)) << NRF_INIT_POS) | \
((NRF_INIT_HIGH * DT_PROP(node_id, output_high)) << NRF_INIT_POS) \
),

/**
Expand All @@ -52,6 +54,13 @@ typedef uint32_t pinctrl_soc_pin_t;
DT_FOREACH_PROP_ELEM, psels, \
Z_PINCTRL_STATE_PIN_INIT)}

/**
* @brief Utility macro to obtain pin initial state.
*
* @param pincfg Pin configuration bit field.
*/
#define NRF_GET_INIT(pincfg) (((pincfg) >> NRF_INIT_POS) & NRF_INIT_MSK)

/**
* @brief Utility macro to obtain pin function.
*
Expand Down
Loading