1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Consumer interface the pin control subsystem 4 * 5 * Copyright (C) 2012 ST-Ericsson SA 6 * Written on behalf of Linaro for ST-Ericsson 7 * Based on bits of regulator core, gpio core and clk core 8 * 9 * Author: Linus Walleij <linus.walleij@linaro.org> 10 */ 11 #ifndef __LINUX_PINCTRL_CONSUMER_H 12 #define __LINUX_PINCTRL_CONSUMER_H 13 14 #include <linux/err.h> 15 #include <linux/types.h> 16 17 #include <linux/pinctrl/pinctrl-state.h> 18 19 struct device; 20 struct gpio_chip; 21 22 /* This struct is private to the core and should be regarded as a cookie */ 23 struct pinctrl; 24 struct pinctrl_state; 25 26 #ifdef CONFIG_PINCTRL 27 28 /* External interface to pin control */ 29 bool pinctrl_gpio_can_use_line(struct gpio_chip *gc, unsigned int offset); 30 int pinctrl_gpio_request(struct gpio_chip *gc, unsigned int offset); 31 void pinctrl_gpio_free(struct gpio_chip *gc, unsigned int offset); 32 int pinctrl_gpio_direction_input(struct gpio_chip *gc, 33 unsigned int offset); 34 int pinctrl_gpio_direction_output(struct gpio_chip *gc, 35 unsigned int offset); 36 int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 37 unsigned long config); 38 39 struct pinctrl * __must_check pinctrl_get(struct device *dev); 40 void pinctrl_put(struct pinctrl *p); 41 struct pinctrl_state * __must_check pinctrl_lookup_state(struct pinctrl *p, 42 const char *name); 43 int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); 44 45 struct pinctrl * __must_check devm_pinctrl_get(struct device *dev); 46 void devm_pinctrl_put(struct pinctrl *p); 47 int pinctrl_select_default_state(struct device *dev); 48 49 #ifdef CONFIG_PM 50 int pinctrl_pm_select_default_state(struct device *dev); 51 int pinctrl_pm_select_sleep_state(struct device *dev); 52 int pinctrl_pm_select_idle_state(struct device *dev); 53 #else 54 static inline int pinctrl_pm_select_default_state(struct device *dev) 55 { 56 return 0; 57 } 58 static inline int pinctrl_pm_select_sleep_state(struct device *dev) 59 { 60 return 0; 61 } 62 static inline int pinctrl_pm_select_idle_state(struct device *dev) 63 { 64 return 0; 65 } 66 #endif 67 68 #else /* !CONFIG_PINCTRL */ 69 70 static inline bool 71 pinctrl_gpio_can_use_line(struct gpio_chip *gc, unsigned int offset) 72 { 73 return true; 74 } 75 76 static inline int 77 pinctrl_gpio_request(struct gpio_chip *gc, unsigned int offset) 78 { 79 return 0; 80 } 81 82 static inline void 83 pinctrl_gpio_free(struct gpio_chip *gc, unsigned int offset) 84 { 85 } 86 87 static inline int 88 pinctrl_gpio_direction_input(struct gpio_chip *gc, unsigned int offset) 89 { 90 return 0; 91 } 92 93 static inline int 94 pinctrl_gpio_direction_output(struct gpio_chip *gc, unsigned int offset) 95 { 96 return 0; 97 } 98 99 static inline int 100 pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 101 unsigned long config) 102 { 103 return 0; 104 } 105 106 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) 107 { 108 return NULL; 109 } 110 111 static inline void pinctrl_put(struct pinctrl *p) 112 { 113 } 114 115 static inline struct pinctrl_state * __must_check pinctrl_lookup_state(struct pinctrl *p, 116 const char *name) 117 { 118 return NULL; 119 } 120 121 static inline int pinctrl_select_state(struct pinctrl *p, 122 struct pinctrl_state *s) 123 { 124 return 0; 125 } 126 127 static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev) 128 { 129 return NULL; 130 } 131 132 static inline void devm_pinctrl_put(struct pinctrl *p) 133 { 134 } 135 136 static inline int pinctrl_select_default_state(struct device *dev) 137 { 138 return 0; 139 } 140 141 static inline int pinctrl_pm_select_default_state(struct device *dev) 142 { 143 return 0; 144 } 145 146 static inline int pinctrl_pm_select_sleep_state(struct device *dev) 147 { 148 return 0; 149 } 150 151 static inline int pinctrl_pm_select_idle_state(struct device *dev) 152 { 153 return 0; 154 } 155 156 #endif /* CONFIG_PINCTRL */ 157 158 static inline struct pinctrl * __must_check pinctrl_get_select(struct device *dev, 159 const char *name) 160 { 161 struct pinctrl *p; 162 struct pinctrl_state *s; 163 int ret; 164 165 p = pinctrl_get(dev); 166 if (IS_ERR(p)) 167 return p; 168 169 s = pinctrl_lookup_state(p, name); 170 if (IS_ERR(s)) { 171 pinctrl_put(p); 172 return ERR_CAST(s); 173 } 174 175 ret = pinctrl_select_state(p, s); 176 if (ret < 0) { 177 pinctrl_put(p); 178 return ERR_PTR(ret); 179 } 180 181 return p; 182 } 183 184 static inline struct pinctrl * __must_check pinctrl_get_select_default(struct device *dev) 185 { 186 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); 187 } 188 189 static inline struct pinctrl * __must_check devm_pinctrl_get_select(struct device *dev, 190 const char *name) 191 { 192 struct pinctrl *p; 193 struct pinctrl_state *s; 194 int ret; 195 196 p = devm_pinctrl_get(dev); 197 if (IS_ERR(p)) 198 return p; 199 200 s = pinctrl_lookup_state(p, name); 201 if (IS_ERR(s)) { 202 devm_pinctrl_put(p); 203 return ERR_CAST(s); 204 } 205 206 ret = pinctrl_select_state(p, s); 207 if (ret < 0) { 208 devm_pinctrl_put(p); 209 return ERR_PTR(ret); 210 } 211 212 return p; 213 } 214 215 static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(struct device *dev) 216 { 217 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); 218 } 219 220 #endif /* __LINUX_PINCTRL_CONSUMER_H */ 221
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.