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