1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2022-2023, Microchip
*/
#ifndef __DRIVERS_PINCTRL_H
#define __DRIVERS_PINCTRL_H
#include <bitstring.h>
#include <kernel/dt_driver.h>
#include <sys/queue.h>
#include <tee_api_types.h>
enum pinctrl_dt_prop {
/* Property "bias-disable" found in pinctrl node */
PINCTRL_DT_PROP_BIAS_DISABLE,
/* Property "bias-pull-up" found in pinctrl node */
PINCTRL_DT_PROP_BIAS_PULL_UP,
/* Property "bias-pull-down" found in pinctrl node */
PINCTRL_DT_PROP_BIAS_PULL_DOWN,
/* Terminal ID */
PINCTRL_DT_PROP_MAX
};
/*
* struct pinconf - Pinctrl device
* @ops: Operation handlers
* @priv: Pinctrl driver private data
*/
struct pinconf {
const struct pinctrl_ops *ops;
void *priv;
};
/*
* struct pinctrl_state - Pinctrl configuration state
* @conf_count: Number of cells in @confs
* @confs: Array of pin configurations related to the pinctrl config state
*/
struct pinctrl_state {
unsigned int conf_count;
struct pinconf *confs[];
};
struct pinctrl_ops {
/* Apply a pinctrl configuration */
TEE_Result (*conf_apply)(struct pinconf *conf);
/* Release resources allocated for a pinctrl configuration */
void (*conf_free)(struct pinconf *conf);
};
/**
* pinctrl_dt_get_func - Typedef of function to get a pin configuration from
* a device tree property
*
* @args: Pointer to device tree phandle arguments of the pin control reference
* @data: Pointer to data given at pinctrl_register_provider() call
* @out_pinconf: Output pin configuration reference upon success
*/
typedef TEE_Result (*pinctrl_dt_get_func)(struct dt_pargs *pargs, void *data,
struct pinconf **out_pinconf);
#ifdef CFG_DRIVERS_PINCTRL
/**
* pinctrl_dt_register_provider - Register a pinctrl controller provider
*
* @fdt: Device tree to work on
* @nodeoffset: Node offset of the pin controller
* @get_pinctrl: Callback to match the pin controller with a struct pinconf
* @data: Data which will be passed to the get_pinctrl callback
* Return a TEE_Result compliant value
*/
static inline TEE_Result pinctrl_register_provider(const void *fdt,
int nodeoffset,
pinctrl_dt_get_func func,
void *data)
{
return dt_driver_register_provider(fdt, nodeoffset,
(get_of_device_func)func, data,
DT_DRIVER_PINCTRL);
}
/**
* pinctrl_get_state_by_name - Obtain a pinctrl state by name
*
* @fdt: Device tree to work on
* @nodeoffset: Node offset of the pin controller
* @name: name of the pinctrl state to obtain from device-tree
* @state: Pointer filled with the retrieved state, must be freed after use
using pinctrl_free_state()
* Return a TEE_Result compliant value
*/
TEE_Result pinctrl_get_state_by_name(const void *fdt, int nodeoffset,
const char *name,
struct pinctrl_state **state);
/**
* pinctrl_get_state_by_idx - Obtain a pinctrl state by index
*
* @fdt: Device tree to work on
* @nodeoffset: Node offset of the pin controller
* @pinctrl_id: Index of the pinctrl state to obtain from device-tree
* @state: Pointer filled with the retrieved state, must be freed after use
using pinctrl_free_state()
* Return a TEE_Result compliant value
*/
TEE_Result pinctrl_get_state_by_idx(const void *fdt, int nodeoffset,
unsigned int pinctrl_id,
struct pinctrl_state **state);
/**
* pinctrl_free_state - Free a pinctrl state that was previously obtained
*
* @state: State to be freed
*/
void pinctrl_free_state(struct pinctrl_state *state);
/**
* pinctrl_apply_state - apply a pinctrl state
*
* @state: State to be applied
* Return a TEE_Result compliant value
*/
TEE_Result pinctrl_apply_state(struct pinctrl_state *state);
/*
* pinctrl_parse_dt_pin_modes - Parse DT node properties
* @fdt: Device tree to work on
* @nodeoffset: Pinctrl node
* @modes: Output allocated regulator properties
* Return a TEE_Result compliant value
*/
TEE_Result pinctrl_parse_dt_pin_modes(const void *fdt, int nodeoffset,
bitstr_t **modes);
#else /* CFG_DRIVERS_PINCTRL */
static inline TEE_Result
pinctrl_register_provider(const void *fdt __unused, int nodeoffset __unused,
get_of_device_func func __unused, void *data __unused)
{
return TEE_ERROR_NOT_SUPPORTED;
}
static inline TEE_Result
pinctrl_get_state_by_name(const void *fdt __unused, int nodeoffset __unused,
const char *name __unused,
struct pinctrl_state **state __unused)
{
return TEE_ERROR_NOT_SUPPORTED;
}
static inline TEE_Result
pinctrl_get_state_by_idx(const void *fdt __unused, int nodeoffset __unused,
unsigned int pinctrl_id __unused,
struct pinctrl_state **state __unused)
{
return TEE_ERROR_NOT_SUPPORTED;
}
static inline void pinctrl_free_state(struct pinctrl_state *state __unused)
{
}
static inline TEE_Result pinctrl_apply_state(struct pinctrl_state *s __unused)
{
return TEE_ERROR_NOT_SUPPORTED;
}
static inline TEE_Result pinctrl_parse_dt_pin_modes(const void *fdt __unused,
int nodeoffset __unused,
bitstr_t **modes __unused)
{
return TEE_ERROR_NOT_SUPPORTED;
}
#endif /* CFG_DRIVERS_PINCTRL */
#endif /* __DRIVERS_PINCTRL_H */
|