11#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_
12#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_
26#include <pinctrl_soc.h>
40#define PINCTRL_STATE_DEFAULT 0U
42#define PINCTRL_STATE_SLEEP 1U
45#define PINCTRL_STATE_PRIV_START 2U
52 const pinctrl_soc_pin_t *
pins;
61#if defined(CONFIG_PINCTRL_STORE_REG) || defined(__DOXYGEN__)
75#define PINCTRL_REG_NONE 0U
79#ifndef CONFIG_PM_DEVICE
81#define PINCTRL_SKIP_SLEEP 1
90#define Z_PINCTRL_STATE_ID(state_idx, node_id) \
91 _CONCAT(PINCTRL_STATE_, \
92 DT_PINCTRL_IDX_TO_NAME_UPPER_TOKEN(node_id, state_idx))
100#define Z_PINCTRL_DEV_CONFIG_NAME(node_id) \
101 _CONCAT(__pinctrl_dev_config, DEVICE_DT_NAME_GET(node_id))
109#define Z_PINCTRL_STATES_NAME(node_id) \
110 _CONCAT(__pinctrl_states, DEVICE_DT_NAME_GET(node_id))
119#define Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id) \
120 _CONCAT(__pinctrl_state_pins_ ## state_idx, DEVICE_DT_NAME_GET(node_id))
133#define Z_PINCTRL_SKIP_STATE(state_idx, node_id) \
134 _CONCAT(PINCTRL_SKIP_, \
135 DT_PINCTRL_IDX_TO_NAME_UPPER_TOKEN(node_id, state_idx))
143#define Z_PINCTRL_STATE_PINS_DEFINE(state_idx, node_id) \
144 COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
145 (static const pinctrl_soc_pin_t \
146 Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id)[] = \
147 Z_PINCTRL_STATE_PINS_INIT(node_id, pinctrl_ ## state_idx)))
155#define Z_PINCTRL_STATE_INIT(state_idx, node_id) \
156 COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
158 .id = Z_PINCTRL_STATE_ID(state_idx, node_id), \
159 .pins = Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id), \
160 .pin_cnt = ARRAY_SIZE(Z_PINCTRL_STATE_PINS_NAME(state_idx, \
169#define Z_PINCTRL_STATES_DEFINE(node_id) \
170 static const struct pinctrl_state \
171 Z_PINCTRL_STATES_NAME(node_id)[] = { \
172 LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
173 Z_PINCTRL_STATE_INIT, (,), node_id) \
176#ifdef CONFIG_PINCTRL_STORE_REG
182#define Z_PINCTRL_DEV_CONFIG_INIT(node_id) \
184 .reg = DT_REG_ADDR(node_id), \
185 .states = Z_PINCTRL_STATES_NAME(node_id), \
186 .state_cnt = ARRAY_SIZE(Z_PINCTRL_STATES_NAME(node_id)), \
189#define Z_PINCTRL_DEV_CONFIG_INIT(node_id) \
191 .states = Z_PINCTRL_STATES_NAME(node_id), \
192 .state_cnt = ARRAY_SIZE(Z_PINCTRL_STATES_NAME(node_id)), \
196#ifdef CONFIG_PINCTRL_NON_STATIC
197#define Z_PINCTRL_DEV_CONFIG_STATIC
199#define Z_PINCTRL_DEV_CONFIG_STATIC static
202#ifdef CONFIG_PINCTRL_DYNAMIC
203#define Z_PINCTRL_DEV_CONFIG_CONST
205#define Z_PINCTRL_DEV_CONFIG_CONST const
210#if defined(CONFIG_PINCTRL_NON_STATIC) || defined(__DOXYGEN__)
223#define PINCTRL_DT_DEV_CONFIG_DECLARE(node_id) \
224 extern Z_PINCTRL_DEV_CONFIG_CONST struct pinctrl_dev_config \
225 Z_PINCTRL_DEV_CONFIG_NAME(node_id)
239#define PINCTRL_DT_DEFINE(node_id) \
240 LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
241 Z_PINCTRL_STATE_PINS_DEFINE, (;), node_id); \
242 Z_PINCTRL_STATES_DEFINE(node_id) \
243 Z_PINCTRL_DEV_CONFIG_STATIC Z_PINCTRL_DEV_CONFIG_CONST \
244 struct pinctrl_dev_config Z_PINCTRL_DEV_CONFIG_NAME(node_id) = \
245 Z_PINCTRL_DEV_CONFIG_INIT(node_id)
254#define PINCTRL_DT_INST_DEFINE(inst) PINCTRL_DT_DEFINE(DT_DRV_INST(inst))
262#define PINCTRL_DT_DEV_CONFIG_GET(node_id) &Z_PINCTRL_DEV_CONFIG_NAME(node_id)
272#define PINCTRL_DT_INST_DEV_CONFIG_GET(inst) \
273 PINCTRL_DT_DEV_CONFIG_GET(DT_DRV_INST(inst))
322#ifdef CONFIG_PINCTRL_STORE_REG
356#if defined(CONFIG_PINCTRL_DYNAMIC) || defined(__DOXYGEN__)
374#define PINCTRL_DT_STATE_PINS_DEFINE(node_id, prop) \
375 static const pinctrl_soc_pin_t prop ## _pins[] = \
376 Z_PINCTRL_STATE_PINS_INIT(node_id, prop); \
413#define PINCTRL_DT_STATE_INIT(prop, state) \
416 .pins = prop ## _pins, \
417 .pin_cnt = ARRAY_SIZE(prop ## _pins) \
449 ARG_UNUSED(state_cnt);
Devicetree pin control helpers.
int pinctrl_update_states(struct pinctrl_dev_config *config, const struct pinctrl_state *states, uint8_t state_cnt)
Update states with a new set.
static int pinctrl_apply_state(const struct pinctrl_dev_config *config, uint8_t id)
Apply a state from the given device configuration.
Definition: pinctrl.h:342
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
Configure a set of pins.
static int pinctrl_apply_state_direct(const struct pinctrl_dev_config *config, const struct pinctrl_state *state)
Apply a state directly from the provided state configuration.
Definition: pinctrl.h:316
int pinctrl_lookup_state(const struct pinctrl_dev_config *config, uint8_t id, const struct pinctrl_state **state)
Find the state configuration for the given state id.
#define PINCTRL_REG_NONE
Utility macro to indicate no register is used.
Definition: pinctrl.h:75
#define ENOSYS
Function not implemented.
Definition: errno.h:83
state
Definition: parser_state.h:29
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
Pin controller configuration for a given device.
Definition: pinctrl.h:60
uint8_t state_cnt
Number of state configurations.
Definition: pinctrl.h:71
const struct pinctrl_state * states
List of state configurations.
Definition: pinctrl.h:69
uintptr_t reg
Device address (only available if <code>CONFIG_PINCTRL_STORE_REG</code> <verbatim>embed:rst:inline...
Definition: pinctrl.h:66
Pin control state configuration.
Definition: pinctrl.h:50
const pinctrl_soc_pin_t * pins
Pin configurations.
Definition: pinctrl.h:52
uint8_t pin_cnt
Number of pin configurations.
Definition: pinctrl.h:54
uint8_t id
State identifier (see PINCTRL_STATES).
Definition: pinctrl.h:56