diff options
| author | Hans de Goede <hdegoede@redhat.com> | 2016-02-23 12:46:26 -0500 |
|---|---|---|
| committer | Philipp Zabel <p.zabel@pengutronix.de> | 2016-03-30 09:42:05 -0400 |
| commit | 0b52297f2288ca239e598afe6c92db83d8d2bfcd (patch) | |
| tree | af0f180666543d4a45bf4c68270edbc3c606a5d9 /drivers/reset | |
| parent | c15ddec2ca06076a11195313aa1fce47d2a28c5d (diff) | |
reset: Add support for shared reset controls
In some SoCs some hw-blocks share a reset control. Add support for this
setup by adding new:
reset_control_get_shared()
devm_reset_control_get_shared()
devm_reset_control_get_shared_by_index()
methods to get a reset_control. Note that this patch omits adding of_
variants, if these are needed later they can be easily added.
This patch also changes the behavior of the existing exclusive
reset_control_get() variants, if these are now called more then once
for the same reset_control they will return -EBUSY. To catch existing
drivers triggering this error (there should not be any) a WARN_ON(1)
is added in this path.
When a reset_control is shared, the behavior of reset_control_assert /
deassert is changed, for shared reset_controls these will work like the
clock-enable/disable and regulator-on/off functions. They will keep a
deassert_count, and only (re-)assert the reset after reset_control_assert
has been called as many times as reset_control_deassert was called.
Calling reset_control_assert without first calling reset_control_deassert
is not allowed on a shared reset control. Calling reset_control_reset is
also not allowed on a shared reset control.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers/reset')
| -rw-r--r-- | drivers/reset/core.c | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 957750600ff3..72b32bd15549 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
| 10 | */ | 10 | */ |
| 11 | #include <linux/atomic.h> | ||
| 11 | #include <linux/device.h> | 12 | #include <linux/device.h> |
| 12 | #include <linux/err.h> | 13 | #include <linux/err.h> |
| 13 | #include <linux/export.h> | 14 | #include <linux/export.h> |
| @@ -29,12 +30,16 @@ static LIST_HEAD(reset_controller_list); | |||
| 29 | * @id: ID of the reset controller in the reset | 30 | * @id: ID of the reset controller in the reset |
| 30 | * controller device | 31 | * controller device |
| 31 | * @refcnt: Number of gets of this reset_control | 32 | * @refcnt: Number of gets of this reset_control |
| 33 | * @shared: Is this a shared (1), or an exclusive (0) reset_control? | ||
| 34 | * @deassert_cnt: Number of times this reset line has been deasserted | ||
| 32 | */ | 35 | */ |
| 33 | struct reset_control { | 36 | struct reset_control { |
| 34 | struct reset_controller_dev *rcdev; | 37 | struct reset_controller_dev *rcdev; |
| 35 | struct list_head list; | 38 | struct list_head list; |
| 36 | unsigned int id; | 39 | unsigned int id; |
| 37 | unsigned int refcnt; | 40 | unsigned int refcnt; |
| 41 | int shared; | ||
| 42 | atomic_t deassert_count; | ||
| 38 | }; | 43 | }; |
| 39 | 44 | ||
| 40 | /** | 45 | /** |
| @@ -91,9 +96,14 @@ EXPORT_SYMBOL_GPL(reset_controller_unregister); | |||
| 91 | /** | 96 | /** |
| 92 | * reset_control_reset - reset the controlled device | 97 | * reset_control_reset - reset the controlled device |
| 93 | * @rstc: reset controller | 98 | * @rstc: reset controller |
| 99 | * | ||
| 100 | * Calling this on a shared reset controller is an error. | ||
| 94 | */ | 101 | */ |
| 95 | int reset_control_reset(struct reset_control *rstc) | 102 | int reset_control_reset(struct reset_control *rstc) |
| 96 | { | 103 | { |
| 104 | if (WARN_ON(rstc->shared)) | ||
| 105 | return -EINVAL; | ||
| 106 | |||
| 97 | if (rstc->rcdev->ops->reset) | 107 | if (rstc->rcdev->ops->reset) |
| 98 | return rstc->rcdev->ops->reset(rstc->rcdev, rstc->id); | 108 | return rstc->rcdev->ops->reset(rstc->rcdev, rstc->id); |
| 99 | 109 | ||
| @@ -104,26 +114,48 @@ EXPORT_SYMBOL_GPL(reset_control_reset); | |||
| 104 | /** | 114 | /** |
| 105 | * reset_control_assert - asserts the reset line | 115 | * reset_control_assert - asserts the reset line |
| 106 | * @rstc: reset controller | 116 | * @rstc: reset controller |
| 117 | * | ||
| 118 | * Calling this on an exclusive reset controller guarantees that the reset | ||
| 119 | * will be asserted. When called on a shared reset controller the line may | ||
| 120 | * still be deasserted, as long as other users keep it so. | ||
| 121 | * | ||
| 122 | * For shared reset controls a driver cannot expect the hw's registers and | ||
| 123 | * internal state to be reset, but must be prepared for this to happen. | ||
| 107 | */ | 124 | */ |
| 108 | int reset_control_assert(struct reset_control *rstc) | 125 | int reset_control_assert(struct reset_control *rstc) |
| 109 | { | 126 | { |
| 110 | if (rstc->rcdev->ops->assert) | 127 | if (!rstc->rcdev->ops->assert) |
| 111 | return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id); | 128 | return -ENOTSUPP; |
| 112 | 129 | ||
| 113 | return -ENOTSUPP; | 130 | if (rstc->shared) { |
| 131 | if (WARN_ON(atomic_read(&rstc->deassert_count) == 0)) | ||
| 132 | return -EINVAL; | ||
| 133 | |||
| 134 | if (atomic_dec_return(&rstc->deassert_count) != 0) | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id); | ||
| 114 | } | 139 | } |
| 115 | EXPORT_SYMBOL_GPL(reset_control_assert); | 140 | EXPORT_SYMBOL_GPL(reset_control_assert); |
| 116 | 141 | ||
| 117 | /** | 142 | /** |
| 118 | * reset_control_deassert - deasserts the reset line | 143 | * reset_control_deassert - deasserts the reset line |
| 119 | * @rstc: reset controller | 144 | * @rstc: reset controller |
| 145 | * | ||
| 146 | * After calling this function, the reset is guaranteed to be deasserted. | ||
| 120 | */ | 147 | */ |
| 121 | int reset_control_deassert(struct reset_control *rstc) | 148 | int reset_control_deassert(struct reset_control *rstc) |
| 122 | { | 149 | { |
| 123 | if (rstc->rcdev->ops->deassert) | 150 | if (!rstc->rcdev->ops->deassert) |
| 124 | return rstc->rcdev->ops->deassert(rstc->rcdev, rstc->id); | 151 | return -ENOTSUPP; |
| 125 | 152 | ||
| 126 | return -ENOTSUPP; | 153 | if (rstc->shared) { |
| 154 | if (atomic_inc_return(&rstc->deassert_count) != 1) | ||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | |||
| 158 | return rstc->rcdev->ops->deassert(rstc->rcdev, rstc->id); | ||
| 127 | } | 159 | } |
| 128 | EXPORT_SYMBOL_GPL(reset_control_deassert); | 160 | EXPORT_SYMBOL_GPL(reset_control_deassert); |
| 129 | 161 | ||
| @@ -144,7 +176,7 @@ EXPORT_SYMBOL_GPL(reset_control_status); | |||
| 144 | 176 | ||
| 145 | static struct reset_control *__reset_control_get( | 177 | static struct reset_control *__reset_control_get( |
| 146 | struct reset_controller_dev *rcdev, | 178 | struct reset_controller_dev *rcdev, |
| 147 | unsigned int index) | 179 | unsigned int index, int shared) |
| 148 | { | 180 | { |
| 149 | struct reset_control *rstc; | 181 | struct reset_control *rstc; |
| 150 | 182 | ||
| @@ -152,6 +184,9 @@ static struct reset_control *__reset_control_get( | |||
| 152 | 184 | ||
| 153 | list_for_each_entry(rstc, &rcdev->reset_control_head, list) { | 185 | list_for_each_entry(rstc, &rcdev->reset_control_head, list) { |
| 154 | if (rstc->id == index) { | 186 | if (rstc->id == index) { |
| 187 | if (WARN_ON(!rstc->shared || !shared)) | ||
| 188 | return ERR_PTR(-EBUSY); | ||
| 189 | |||
| 155 | rstc->refcnt++; | 190 | rstc->refcnt++; |
| 156 | return rstc; | 191 | return rstc; |
| 157 | } | 192 | } |
| @@ -167,6 +202,7 @@ static struct reset_control *__reset_control_get( | |||
| 167 | list_add(&rstc->list, &rcdev->reset_control_head); | 202 | list_add(&rstc->list, &rcdev->reset_control_head); |
| 168 | rstc->id = index; | 203 | rstc->id = index; |
| 169 | rstc->refcnt = 1; | 204 | rstc->refcnt = 1; |
| 205 | rstc->shared = shared; | ||
| 170 | 206 | ||
| 171 | return rstc; | 207 | return rstc; |
| 172 | } | 208 | } |
| @@ -185,7 +221,7 @@ static void __reset_control_put(struct reset_control *rstc) | |||
| 185 | } | 221 | } |
| 186 | 222 | ||
| 187 | struct reset_control *__of_reset_control_get(struct device_node *node, | 223 | struct reset_control *__of_reset_control_get(struct device_node *node, |
| 188 | const char *id, int index) | 224 | const char *id, int index, int shared) |
| 189 | { | 225 | { |
| 190 | struct reset_control *rstc; | 226 | struct reset_control *rstc; |
| 191 | struct reset_controller_dev *r, *rcdev; | 227 | struct reset_controller_dev *r, *rcdev; |
| @@ -235,7 +271,7 @@ struct reset_control *__of_reset_control_get(struct device_node *node, | |||
| 235 | } | 271 | } |
| 236 | 272 | ||
| 237 | /* reset_list_mutex also protects the rcdev's reset_control list */ | 273 | /* reset_list_mutex also protects the rcdev's reset_control list */ |
| 238 | rstc = __reset_control_get(rcdev, rstc_id); | 274 | rstc = __reset_control_get(rcdev, rstc_id, shared); |
| 239 | 275 | ||
| 240 | mutex_unlock(&reset_list_mutex); | 276 | mutex_unlock(&reset_list_mutex); |
| 241 | 277 | ||
| @@ -265,7 +301,7 @@ static void devm_reset_control_release(struct device *dev, void *res) | |||
| 265 | } | 301 | } |
| 266 | 302 | ||
| 267 | struct reset_control *__devm_reset_control_get(struct device *dev, | 303 | struct reset_control *__devm_reset_control_get(struct device *dev, |
| 268 | const char *id, int index) | 304 | const char *id, int index, int shared) |
| 269 | { | 305 | { |
| 270 | struct reset_control **ptr, *rstc; | 306 | struct reset_control **ptr, *rstc; |
| 271 | 307 | ||
| @@ -274,7 +310,8 @@ struct reset_control *__devm_reset_control_get(struct device *dev, | |||
| 274 | if (!ptr) | 310 | if (!ptr) |
| 275 | return ERR_PTR(-ENOMEM); | 311 | return ERR_PTR(-ENOMEM); |
| 276 | 312 | ||
| 277 | rstc = __of_reset_control_get(dev ? dev->of_node : NULL, id, index); | 313 | rstc = __of_reset_control_get(dev ? dev->of_node : NULL, |
| 314 | id, index, shared); | ||
| 278 | if (!IS_ERR(rstc)) { | 315 | if (!IS_ERR(rstc)) { |
| 279 | *ptr = rstc; | 316 | *ptr = rstc; |
| 280 | devres_add(dev, ptr); | 317 | devres_add(dev, ptr); |
