11#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_
12#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_
28#include <pinctrl_soc.h>
42#define PINCTRL_STATE_DEFAULT 0U
44#define PINCTRL_STATE_SLEEP 1U
47#define PINCTRL_STATE_PRIV_START 2U
63#if defined(CONFIG_PINCTRL_STORE_REG) || defined(__DOXYGEN__)
77#define PINCTRL_REG_NONE 0U
81#if !defined(CONFIG_PM) && !defined(CONFIG_PM_DEVICE)
83#define PINCTRL_SKIP_SLEEP 1
92#define Z_PINCTRL_STATE_ID(state_idx, node_id) \
93 _CONCAT(PINCTRL_STATE_, \
94 DT_PINCTRL_IDX_TO_NAME_UPPER_TOKEN(node_id, state_idx))
102#define Z_PINCTRL_DEV_CONFIG_NAME(node_id) \
103 _CONCAT(__pinctrl_dev_config, DEVICE_DT_NAME_GET(node_id))
111#define Z_PINCTRL_STATES_NAME(node_id) \
112 _CONCAT(__pinctrl_states, DEVICE_DT_NAME_GET(node_id))
121#define Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id) \
122 _CONCAT(__pinctrl_state_pins_ ## state_idx, DEVICE_DT_NAME_GET(node_id))
135#define Z_PINCTRL_SKIP_STATE(state_idx, node_id) \
136 _CONCAT(PINCTRL_SKIP_, \
137 DT_PINCTRL_IDX_TO_NAME_UPPER_TOKEN(node_id, state_idx))
145#define Z_PINCTRL_STATE_PINS_DEFINE(state_idx, node_id) \
146 COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
147 (static const pinctrl_soc_pin_t \
148 Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id)[] = \
149 Z_PINCTRL_STATE_PINS_INIT(node_id, pinctrl_ ## state_idx)))
157#define Z_PINCTRL_STATE_INIT(state_idx, node_id) \
158 COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
160 .pins = Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id), \
161 .pin_cnt = ARRAY_SIZE(Z_PINCTRL_STATE_PINS_NAME(state_idx, \
163 .id = Z_PINCTRL_STATE_ID(state_idx, node_id) \
171#define Z_PINCTRL_STATES_DEFINE(node_id) \
172 static const struct pinctrl_state \
173 Z_PINCTRL_STATES_NAME(node_id)[] = { \
174 LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
175 Z_PINCTRL_STATE_INIT, (,), node_id) \
178#ifdef CONFIG_PINCTRL_STORE_REG
184#define Z_PINCTRL_DEV_CONFIG_INIT(node_id) \
186 .reg = DT_REG_ADDR(node_id), \
187 .states = Z_PINCTRL_STATES_NAME(node_id), \
188 .state_cnt = ARRAY_SIZE(Z_PINCTRL_STATES_NAME(node_id)), \
191#define Z_PINCTRL_DEV_CONFIG_INIT(node_id) \
193 .states = Z_PINCTRL_STATES_NAME(node_id), \
194 .state_cnt = ARRAY_SIZE(Z_PINCTRL_STATES_NAME(node_id)), \
198#ifdef CONFIG_PINCTRL_NON_STATIC
199#define Z_PINCTRL_DEV_CONFIG_STATIC
201#define Z_PINCTRL_DEV_CONFIG_STATIC static
204#ifdef CONFIG_PINCTRL_DYNAMIC
205#define Z_PINCTRL_DEV_CONFIG_CONST
207#define Z_PINCTRL_DEV_CONFIG_CONST const
212#if defined(CONFIG_PINCTRL_NON_STATIC) || defined(__DOXYGEN__)
225#define PINCTRL_DT_DEV_CONFIG_DECLARE(node_id) \
226 extern Z_PINCTRL_DEV_CONFIG_CONST struct pinctrl_dev_config \
227 Z_PINCTRL_DEV_CONFIG_NAME(node_id)
241#define PINCTRL_DT_DEFINE(node_id) \
242 LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
243 Z_PINCTRL_STATE_PINS_DEFINE, (;), node_id); \
244 Z_PINCTRL_STATES_DEFINE(node_id) \
245 Z_PINCTRL_DEV_CONFIG_STATIC Z_PINCTRL_DEV_CONFIG_CONST \
246 struct pinctrl_dev_config Z_PINCTRL_DEV_CONFIG_NAME(node_id) = \
247 Z_PINCTRL_DEV_CONFIG_INIT(node_id)
256#define PINCTRL_DT_INST_DEFINE(inst) PINCTRL_DT_DEFINE(DT_DRV_INST(inst))
264#define PINCTRL_DT_DEV_CONFIG_GET(node_id) &Z_PINCTRL_DEV_CONFIG_NAME(node_id)
274#define PINCTRL_DT_INST_DEV_CONFIG_GET(inst) \
275 PINCTRL_DT_DEV_CONFIG_GET(DT_DRV_INST(inst))
324#ifdef CONFIG_PINCTRL_STORE_REG
358#if defined(CONFIG_PINCTRL_DYNAMIC) || defined(__DOXYGEN__)
376#define PINCTRL_DT_STATE_PINS_DEFINE(node_id, prop) \
377 static const pinctrl_soc_pin_t prop ## _pins[] = \
378 Z_PINCTRL_STATE_PINS_INIT(node_id, prop); \
415#define PINCTRL_DT_STATE_INIT(prop, state) \
417 .pins = prop ## _pins, \
418 .pin_cnt = ARRAY_SIZE(prop ## _pins), \
451 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:344
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:318
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:77
#define ENOSYS
Function not implemented.
Definition errno.h:82
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:62
uint8_t state_cnt
Number of state configurations.
Definition pinctrl.h:73
const struct pinctrl_state * states
List of state configurations.
Definition pinctrl.h:71
uintptr_t reg
Device address (only available if CONFIG_PINCTRL_STORE_REG is enabled).
Definition pinctrl.h:68
Type for R-Car pin.
Definition pinctrl_rcar_common.h:38
Pin control state configuration.
Definition pinctrl.h:52
const pinctrl_soc_pin_t * pins
Pin configurations.
Definition pinctrl.h:54
uint8_t pin_cnt
Number of pin configurations.
Definition pinctrl.h:56
uint8_t id
State identifier (see PINCTRL_STATES).
Definition pinctrl.h:58