Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_RESET_H_ |
| 2 | #define _LINUX_RESET_H_ |
| 3 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 4 | #include <linux/device.h> |
| 5 | |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 6 | struct reset_control; |
| 7 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 8 | #ifdef CONFIG_RESET_CONTROLLER |
| 9 | |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 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); |
Dinh Nguyen | 729de41 | 2014-10-10 10:21:14 -0500 | [diff] [blame] | 13 | int reset_control_status(struct reset_control *rstc); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 14 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 15 | struct reset_control *__of_reset_control_get(struct device_node *node, |
| 16 | const char *id, int index); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 17 | void reset_control_put(struct reset_control *rstc); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 18 | struct reset_control *__devm_reset_control_get(struct device *dev, |
| 19 | const char *id, int index); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 20 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 21 | int __must_check device_reset(struct device *dev); |
| 22 | |
| 23 | static inline int device_reset_optional(struct device *dev) |
| 24 | { |
| 25 | return device_reset(dev); |
| 26 | } |
| 27 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 28 | #else |
| 29 | |
| 30 | static inline int reset_control_reset(struct reset_control *rstc) |
| 31 | { |
| 32 | WARN_ON(1); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static inline int reset_control_assert(struct reset_control *rstc) |
| 37 | { |
| 38 | WARN_ON(1); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static inline int reset_control_deassert(struct reset_control *rstc) |
| 43 | { |
| 44 | WARN_ON(1); |
| 45 | return 0; |
| 46 | } |
| 47 | |
Dinh Nguyen | 729de41 | 2014-10-10 10:21:14 -0500 | [diff] [blame] | 48 | static inline int reset_control_status(struct reset_control *rstc) |
| 49 | { |
| 50 | WARN_ON(1); |
| 51 | return 0; |
| 52 | } |
| 53 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 54 | static inline void reset_control_put(struct reset_control *rstc) |
| 55 | { |
| 56 | WARN_ON(1); |
| 57 | } |
| 58 | |
| 59 | static inline int device_reset_optional(struct device *dev) |
| 60 | { |
Philipp Zabel | 39b4da7 | 2015-10-29 09:55:00 +0100 | [diff] [blame] | 61 | return -ENOTSUPP; |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 64 | static inline struct reset_control *__of_reset_control_get( |
| 65 | struct device_node *node, |
| 66 | const char *id, int index) |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 67 | { |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 68 | return ERR_PTR(-EINVAL); |
| 69 | } |
| 70 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 71 | static inline struct reset_control *__devm_reset_control_get( |
| 72 | struct device *dev, |
| 73 | const char *id, int index) |
| 74 | { |
| 75 | return ERR_PTR(-EINVAL); |
| 76 | } |
| 77 | |
| 78 | #endif /* CONFIG_RESET_CONTROLLER */ |
| 79 | |
| 80 | /** |
| 81 | * reset_control_get - Lookup and obtain a reference to a reset controller. |
| 82 | * @dev: device to be reset by the controller |
| 83 | * @id: reset line name |
| 84 | * |
| 85 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 86 | * |
| 87 | * Use of id names is optional. |
| 88 | */ |
| 89 | static inline struct reset_control *__must_check reset_control_get( |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 90 | struct device *dev, const char *id) |
| 91 | { |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 92 | #ifndef CONFIG_RESET_CONTROLLER |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 93 | WARN_ON(1); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 94 | #endif |
| 95 | return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0); |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 96 | } |
| 97 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 98 | static inline struct reset_control *reset_control_get_optional( |
| 99 | struct device *dev, const char *id) |
| 100 | { |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 101 | return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * of_reset_control_get - Lookup and obtain a reference to a reset controller. |
| 106 | * @node: device to be reset by the controller |
| 107 | * @id: reset line name |
| 108 | * |
| 109 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 110 | * |
| 111 | * Use of id names is optional. |
| 112 | */ |
| 113 | static inline struct reset_control *of_reset_control_get( |
| 114 | struct device_node *node, const char *id) |
| 115 | { |
| 116 | return __of_reset_control_get(node, id, 0); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * of_reset_control_get_by_index - Lookup and obtain a reference to a reset |
| 121 | * controller by index. |
| 122 | * @node: device to be reset by the controller |
| 123 | * @index: index of the reset controller |
| 124 | * |
| 125 | * This is to be used to perform a list of resets for a device or power domain |
| 126 | * in whatever order. Returns a struct reset_control or IS_ERR() condition |
| 127 | * containing errno. |
| 128 | */ |
| 129 | static inline struct reset_control *of_reset_control_get_by_index( |
| 130 | struct device_node *node, int index) |
| 131 | { |
| 132 | return __of_reset_control_get(node, NULL, index); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * devm_reset_control_get - resource managed reset_control_get() |
| 137 | * @dev: device to be reset by the controller |
| 138 | * @id: reset line name |
| 139 | * |
| 140 | * Managed reset_control_get(). For reset controllers returned from this |
| 141 | * function, reset_control_put() is called automatically on driver detach. |
| 142 | * See reset_control_get() for more information. |
| 143 | */ |
| 144 | static inline struct reset_control *__must_check devm_reset_control_get( |
| 145 | struct device *dev, const char *id) |
| 146 | { |
| 147 | #ifndef CONFIG_RESET_CONTROLLER |
| 148 | WARN_ON(1); |
| 149 | #endif |
| 150 | return __devm_reset_control_get(dev, id, 0); |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static inline struct reset_control *devm_reset_control_get_optional( |
| 154 | struct device *dev, const char *id) |
| 155 | { |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 156 | return __devm_reset_control_get(dev, id, 0); |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 159 | /** |
| 160 | * devm_reset_control_get_by_index - resource managed reset_control_get |
| 161 | * @dev: device to be reset by the controller |
| 162 | * @index: index of the reset controller |
| 163 | * |
| 164 | * Managed reset_control_get(). For reset controllers returned from this |
| 165 | * function, reset_control_put() is called automatically on driver detach. |
| 166 | * See reset_control_get() for more information. |
| 167 | */ |
| 168 | static inline struct reset_control *devm_reset_control_get_by_index( |
| 169 | struct device *dev, int index) |
Hans de Goede | e3ec0a8 | 2014-04-13 14:09:15 +0200 | [diff] [blame] | 170 | { |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame^] | 171 | return __devm_reset_control_get(dev, NULL, index); |
Hans de Goede | e3ec0a8 | 2014-04-13 14:09:15 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 174 | #endif |