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