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 /** 53 * pinctrl_dt_get_func - Typedef of function to get a pin configuration from 54 * a device tree property 55 * 56 * @args: Pointer to device tree phandle arguments of the pin control reference 57 * @data: Pointer to data given at pinctrl_register_provider() call 58 * @out_pinconf: Output pin configuration reference upon success 59 */ 60 typedef TEE_Result (*pinctrl_dt_get_func)(struct dt_pargs *pargs, void *data, 61 struct pinconf **out_pinconf); 62 63 #ifdef CFG_DRIVERS_PINCTRL 64 /** 65 * pinctrl_dt_register_provider - Register a pinctrl controller provider 66 * 67 * @fdt: Device tree to work on 68 * @nodeoffset: Node offset of the pin controller 69 * @get_pinctrl: Callback to match the pin controller with a struct pinconf 70 * @data: Data which will be passed to the get_pinctrl callback 71 * Return a TEE_Result compliant value 72 */ 73 static inline TEE_Result pinctrl_register_provider(const void *fdt, 74 int nodeoffset, 75 pinctrl_dt_get_func func, 76 void *data) 77 { 78 return dt_driver_register_provider(fdt, nodeoffset, 79 (get_of_device_func)func, data, 80 DT_DRIVER_PINCTRL); 81 } 82 83 /** 84 * pinctrl_get_state_by_name - Obtain a pinctrl state by name 85 * 86 * @fdt: Device tree to work on 87 * @nodeoffset: Node offset of the pin controller 88 * @name: name of the pinctrl state to obtain from device-tree 89 * @state: Pointer filled with the retrieved state, must be freed after use 90 using pinctrl_free_state() 91 * Return a TEE_Result compliant value 92 */ 93 TEE_Result pinctrl_get_state_by_name(const void *fdt, int nodeoffset, 94 const char *name, 95 struct pinctrl_state **state); 96 97 /** 98 * pinctrl_get_state_by_idx - Obtain a pinctrl state by index 99 * 100 * @fdt: Device tree to work on 101 * @nodeoffset: Node offset of the pin controller 102 * @pinctrl_id: Index of the pinctrl state to obtain from device-tree 103 * @state: Pointer filled with the retrieved state, must be freed after use 104 using pinctrl_free_state() 105 * Return a TEE_Result compliant value 106 */ 107 TEE_Result pinctrl_get_state_by_idx(const void *fdt, int nodeoffset, 108 unsigned int pinctrl_id, 109 struct pinctrl_state **state); 110 111 /** 112 * pinctrl_free_state - Free a pinctrl state that was previously obtained 113 * 114 * @state: State to be freed 115 */ 116 void pinctrl_free_state(struct pinctrl_state *state); 117 118 /** 119 * pinctrl_apply_state - apply a pinctrl state 120 * 121 * @state: State to be applied 122 * Return a TEE_Result compliant value 123 */ 124 TEE_Result pinctrl_apply_state(struct pinctrl_state *state); 125 126 /* 127 * pinctrl_parse_dt_pin_modes - Parse DT node properties 128 * @fdt: Device tree to work on 129 * @nodeoffset: Pinctrl node 130 * @modes: Output allocated regulator properties 131 * Return a TEE_Result compliant value 132 */ 133 TEE_Result pinctrl_parse_dt_pin_modes(const void *fdt, int nodeoffset, 134 bitstr_t **modes); 135 #else /* CFG_DRIVERS_PINCTRL */ 136 static inline TEE_Result 137 pinctrl_register_provider(const void *fdt __unused, int nodeoffset __unused, 138 get_of_device_func func __unused, void *data __unused) 139 { 140 return TEE_ERROR_NOT_SUPPORTED; 141 } 142 143 static inline TEE_Result 144 pinctrl_get_state_by_name(const void *fdt __unused, int nodeoffset __unused, 145 const char *name __unused, 146 struct pinctrl_state **state __unused) 147 { 148 return TEE_ERROR_NOT_SUPPORTED; 149 } 150 151 static inline TEE_Result 152 pinctrl_get_state_by_idx(const void *fdt __unused, int nodeoffset __unused, 153 unsigned int pinctrl_id __unused, 154 struct pinctrl_state **state __unused) 155 { 156 return TEE_ERROR_NOT_SUPPORTED; 157 } 158 159 static inline void pinctrl_free_state(struct pinctrl_state *state __unused) 160 { 161 } 162 163 static inline TEE_Result pinctrl_apply_state(struct pinctrl_state *s __unused) 164 { 165 return TEE_ERROR_NOT_SUPPORTED; 166 } 167 168 static inline TEE_Result pinctrl_parse_dt_pin_modes(const void *fdt __unused, 169 int nodeoffset __unused, 170 bitstr_t **modes __unused) 171 { 172 return TEE_ERROR_NOT_SUPPORTED; 173 } 174 175 #endif /* CFG_DRIVERS_PINCTRL */ 176 #endif /* __DRIVERS_PINCTRL_H */ 177