at v4.11 12 kB view raw
1#ifndef _LINUX_RESET_H_ 2#define _LINUX_RESET_H_ 3 4#include <linux/device.h> 5 6struct reset_control; 7 8#ifdef CONFIG_RESET_CONTROLLER 9 10int reset_control_reset(struct reset_control *rstc); 11int reset_control_assert(struct reset_control *rstc); 12int reset_control_deassert(struct reset_control *rstc); 13int reset_control_status(struct reset_control *rstc); 14 15struct reset_control *__of_reset_control_get(struct device_node *node, 16 const char *id, int index, bool shared, 17 bool optional); 18struct reset_control *__reset_control_get(struct device *dev, const char *id, 19 int index, bool shared, 20 bool optional); 21void reset_control_put(struct reset_control *rstc); 22struct reset_control *__devm_reset_control_get(struct device *dev, 23 const char *id, int index, bool shared, 24 bool optional); 25 26int __must_check device_reset(struct device *dev); 27 28static inline int device_reset_optional(struct device *dev) 29{ 30 return device_reset(dev); 31} 32 33#else 34 35static inline int reset_control_reset(struct reset_control *rstc) 36{ 37 return 0; 38} 39 40static inline int reset_control_assert(struct reset_control *rstc) 41{ 42 return 0; 43} 44 45static inline int reset_control_deassert(struct reset_control *rstc) 46{ 47 return 0; 48} 49 50static inline int reset_control_status(struct reset_control *rstc) 51{ 52 return 0; 53} 54 55static inline void reset_control_put(struct reset_control *rstc) 56{ 57} 58 59static inline int __must_check device_reset(struct device *dev) 60{ 61 WARN_ON(1); 62 return -ENOTSUPP; 63} 64 65static inline int device_reset_optional(struct device *dev) 66{ 67 return -ENOTSUPP; 68} 69 70static inline struct reset_control *__of_reset_control_get( 71 struct device_node *node, 72 const char *id, int index, bool shared, 73 bool optional) 74{ 75 return optional ? NULL : ERR_PTR(-ENOTSUPP); 76} 77 78static inline struct reset_control *__reset_control_get( 79 struct device *dev, const char *id, 80 int index, bool shared, bool optional) 81{ 82 return optional ? NULL : ERR_PTR(-ENOTSUPP); 83} 84 85static inline struct reset_control *__devm_reset_control_get( 86 struct device *dev, const char *id, 87 int index, bool shared, bool optional) 88{ 89 return optional ? NULL : ERR_PTR(-ENOTSUPP); 90} 91 92#endif /* CONFIG_RESET_CONTROLLER */ 93 94/** 95 * reset_control_get_exclusive - Lookup and obtain an exclusive reference 96 * to a reset controller. 97 * @dev: device to be reset by the controller 98 * @id: reset line name 99 * 100 * Returns a struct reset_control or IS_ERR() condition containing errno. 101 * If this function is called more then once for the same reset_control it will 102 * return -EBUSY. 103 * 104 * See reset_control_get_shared for details on shared references to 105 * reset-controls. 106 * 107 * Use of id names is optional. 108 */ 109static inline struct reset_control * 110__must_check reset_control_get_exclusive(struct device *dev, const char *id) 111{ 112#ifndef CONFIG_RESET_CONTROLLER 113 WARN_ON(1); 114#endif 115 return __reset_control_get(dev, id, 0, false, false); 116} 117 118/** 119 * reset_control_get_shared - Lookup and obtain a shared reference to a 120 * reset controller. 121 * @dev: device to be reset by the controller 122 * @id: reset line name 123 * 124 * Returns a struct reset_control or IS_ERR() condition containing errno. 125 * This function is intended for use with reset-controls which are shared 126 * between hardware-blocks. 127 * 128 * When a reset-control is shared, the behavior of reset_control_assert / 129 * deassert is changed, the reset-core will keep track of a deassert_count 130 * and only (re-)assert the reset after reset_control_assert has been called 131 * as many times as reset_control_deassert was called. Also see the remark 132 * about shared reset-controls in the reset_control_assert docs. 133 * 134 * Calling reset_control_assert without first calling reset_control_deassert 135 * is not allowed on a shared reset control. Calling reset_control_reset is 136 * also not allowed on a shared reset control. 137 * 138 * Use of id names is optional. 139 */ 140static inline struct reset_control *reset_control_get_shared( 141 struct device *dev, const char *id) 142{ 143 return __reset_control_get(dev, id, 0, true, false); 144} 145 146static inline struct reset_control *reset_control_get_optional_exclusive( 147 struct device *dev, const char *id) 148{ 149 return __reset_control_get(dev, id, 0, false, true); 150} 151 152static inline struct reset_control *reset_control_get_optional_shared( 153 struct device *dev, const char *id) 154{ 155 return __reset_control_get(dev, id, 0, true, true); 156} 157 158/** 159 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference 160 * to a reset controller. 161 * @node: device to be reset by the controller 162 * @id: reset line name 163 * 164 * Returns a struct reset_control or IS_ERR() condition containing errno. 165 * 166 * Use of id names is optional. 167 */ 168static inline struct reset_control *of_reset_control_get_exclusive( 169 struct device_node *node, const char *id) 170{ 171 return __of_reset_control_get(node, id, 0, false, false); 172} 173 174/** 175 * of_reset_control_get_shared - Lookup and obtain an shared reference 176 * to a reset controller. 177 * @node: device to be reset by the controller 178 * @id: reset line name 179 * 180 * When a reset-control is shared, the behavior of reset_control_assert / 181 * deassert is changed, the reset-core will keep track of a deassert_count 182 * and only (re-)assert the reset after reset_control_assert has been called 183 * as many times as reset_control_deassert was called. Also see the remark 184 * about shared reset-controls in the reset_control_assert docs. 185 * 186 * Calling reset_control_assert without first calling reset_control_deassert 187 * is not allowed on a shared reset control. Calling reset_control_reset is 188 * also not allowed on a shared reset control. 189 * Returns a struct reset_control or IS_ERR() condition containing errno. 190 * 191 * Use of id names is optional. 192 */ 193static inline struct reset_control *of_reset_control_get_shared( 194 struct device_node *node, const char *id) 195{ 196 return __of_reset_control_get(node, id, 0, true, false); 197} 198 199/** 200 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive 201 * reference to a reset controller 202 * by index. 203 * @node: device to be reset by the controller 204 * @index: index of the reset controller 205 * 206 * This is to be used to perform a list of resets for a device or power domain 207 * in whatever order. Returns a struct reset_control or IS_ERR() condition 208 * containing errno. 209 */ 210static inline struct reset_control *of_reset_control_get_exclusive_by_index( 211 struct device_node *node, int index) 212{ 213 return __of_reset_control_get(node, NULL, index, false, false); 214} 215 216/** 217 * of_reset_control_get_shared_by_index - Lookup and obtain an shared 218 * reference to a reset controller 219 * by index. 220 * @node: device to be reset by the controller 221 * @index: index of the reset controller 222 * 223 * When a reset-control is shared, the behavior of reset_control_assert / 224 * deassert is changed, the reset-core will keep track of a deassert_count 225 * and only (re-)assert the reset after reset_control_assert has been called 226 * as many times as reset_control_deassert was called. Also see the remark 227 * about shared reset-controls in the reset_control_assert docs. 228 * 229 * Calling reset_control_assert without first calling reset_control_deassert 230 * is not allowed on a shared reset control. Calling reset_control_reset is 231 * also not allowed on a shared reset control. 232 * Returns a struct reset_control or IS_ERR() condition containing errno. 233 * 234 * This is to be used to perform a list of resets for a device or power domain 235 * in whatever order. Returns a struct reset_control or IS_ERR() condition 236 * containing errno. 237 */ 238static inline struct reset_control *of_reset_control_get_shared_by_index( 239 struct device_node *node, int index) 240{ 241 return __of_reset_control_get(node, NULL, index, true, false); 242} 243 244/** 245 * devm_reset_control_get_exclusive - resource managed 246 * reset_control_get_exclusive() 247 * @dev: device to be reset by the controller 248 * @id: reset line name 249 * 250 * Managed reset_control_get_exclusive(). For reset controllers returned 251 * from this function, reset_control_put() is called automatically on driver 252 * detach. 253 * 254 * See reset_control_get_exclusive() for more information. 255 */ 256static inline struct reset_control * 257__must_check devm_reset_control_get_exclusive(struct device *dev, 258 const char *id) 259{ 260#ifndef CONFIG_RESET_CONTROLLER 261 WARN_ON(1); 262#endif 263 return __devm_reset_control_get(dev, id, 0, false, false); 264} 265 266/** 267 * devm_reset_control_get_shared - resource managed reset_control_get_shared() 268 * @dev: device to be reset by the controller 269 * @id: reset line name 270 * 271 * Managed reset_control_get_shared(). For reset controllers returned from 272 * this function, reset_control_put() is called automatically on driver detach. 273 * See reset_control_get_shared() for more information. 274 */ 275static inline struct reset_control *devm_reset_control_get_shared( 276 struct device *dev, const char *id) 277{ 278 return __devm_reset_control_get(dev, id, 0, true, false); 279} 280 281static inline struct reset_control *devm_reset_control_get_optional_exclusive( 282 struct device *dev, const char *id) 283{ 284 return __devm_reset_control_get(dev, id, 0, false, true); 285} 286 287static inline struct reset_control *devm_reset_control_get_optional_shared( 288 struct device *dev, const char *id) 289{ 290 return __devm_reset_control_get(dev, id, 0, true, true); 291} 292 293/** 294 * devm_reset_control_get_exclusive_by_index - resource managed 295 * reset_control_get_exclusive() 296 * @dev: device to be reset by the controller 297 * @index: index of the reset controller 298 * 299 * Managed reset_control_get_exclusive(). For reset controllers returned from 300 * this function, reset_control_put() is called automatically on driver 301 * detach. 302 * 303 * See reset_control_get_exclusive() for more information. 304 */ 305static inline struct reset_control * 306devm_reset_control_get_exclusive_by_index(struct device *dev, int index) 307{ 308 return __devm_reset_control_get(dev, NULL, index, false, false); 309} 310 311/** 312 * devm_reset_control_get_shared_by_index - resource managed 313 * reset_control_get_shared 314 * @dev: device to be reset by the controller 315 * @index: index of the reset controller 316 * 317 * Managed reset_control_get_shared(). For reset controllers returned from 318 * this function, reset_control_put() is called automatically on driver detach. 319 * See reset_control_get_shared() for more information. 320 */ 321static inline struct reset_control * 322devm_reset_control_get_shared_by_index(struct device *dev, int index) 323{ 324 return __devm_reset_control_get(dev, NULL, index, true, false); 325} 326 327/* 328 * TEMPORARY calls to use during transition: 329 * 330 * of_reset_control_get() => of_reset_control_get_exclusive() 331 * 332 * These inline function calls will be removed once all consumers 333 * have been moved over to the new explicit API. 334 */ 335static inline struct reset_control *reset_control_get( 336 struct device *dev, const char *id) 337{ 338 return reset_control_get_exclusive(dev, id); 339} 340 341static inline struct reset_control *reset_control_get_optional( 342 struct device *dev, const char *id) 343{ 344 return reset_control_get_optional_exclusive(dev, id); 345} 346 347static inline struct reset_control *of_reset_control_get( 348 struct device_node *node, const char *id) 349{ 350 return of_reset_control_get_exclusive(node, id); 351} 352 353static inline struct reset_control *of_reset_control_get_by_index( 354 struct device_node *node, int index) 355{ 356 return of_reset_control_get_exclusive_by_index(node, index); 357} 358 359static inline struct reset_control *devm_reset_control_get( 360 struct device *dev, const char *id) 361{ 362 return devm_reset_control_get_exclusive(dev, id); 363} 364 365static inline struct reset_control *devm_reset_control_get_optional( 366 struct device *dev, const char *id) 367{ 368 return devm_reset_control_get_optional_exclusive(dev, id); 369 370} 371 372static inline struct reset_control *devm_reset_control_get_by_index( 373 struct device *dev, int index) 374{ 375 return devm_reset_control_get_exclusive_by_index(dev, index); 376} 377#endif