blob: 0090784ff41059ffee6dd50caaee43684ad24a66 [file] [log] [blame]
Philipp Zabel61fc4132012-11-19 17:23:13 +01001/*
2 * Reset Controller framework
3 *
4 * Copyright 2013 Philipp Zabel, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
Hans de Goede0b522972016-02-23 18:46:26 +010011#include <linux/atomic.h>
Philipp Zabel61fc4132012-11-19 17:23:13 +010012#include <linux/device.h>
13#include <linux/err.h>
14#include <linux/export.h>
15#include <linux/kernel.h>
Philipp Zabeld25e4332017-05-31 17:42:29 +020016#include <linux/kref.h>
Philipp Zabel61fc4132012-11-19 17:23:13 +010017#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/reset.h>
20#include <linux/reset-controller.h>
21#include <linux/slab.h>
22
Hans de Goedec15ddec2016-02-23 18:46:25 +010023static DEFINE_MUTEX(reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +010024static LIST_HEAD(reset_controller_list);
25
26/**
27 * struct reset_control - a reset control
28 * @rcdev: a pointer to the reset controller device
29 * this reset control belongs to
Hans de Goedec15ddec2016-02-23 18:46:25 +010030 * @list: list entry for the rcdev's reset controller list
Philipp Zabel61fc4132012-11-19 17:23:13 +010031 * @id: ID of the reset controller in the reset
32 * controller device
Hans de Goedec15ddec2016-02-23 18:46:25 +010033 * @refcnt: Number of gets of this reset_control
Hans de Goede0b522972016-02-23 18:46:26 +010034 * @shared: Is this a shared (1), or an exclusive (0) reset_control?
35 * @deassert_cnt: Number of times this reset line has been deasserted
Martin Blumenstingl7da33a32016-11-12 14:13:03 +010036 * @triggered_count: Number of times this reset line has been reset. Currently
37 * only used for shared resets, which means that the value
38 * will be either 0 or 1.
Philipp Zabel61fc4132012-11-19 17:23:13 +010039 */
40struct reset_control {
41 struct reset_controller_dev *rcdev;
Hans de Goedec15ddec2016-02-23 18:46:25 +010042 struct list_head list;
Philipp Zabel61fc4132012-11-19 17:23:13 +010043 unsigned int id;
Philipp Zabeld25e4332017-05-31 17:42:29 +020044 struct kref refcnt;
Ramiro Oliveiraee48c722017-01-13 17:57:40 +000045 bool shared;
Hans de Goede0b522972016-02-23 18:46:26 +010046 atomic_t deassert_count;
Martin Blumenstingl7da33a32016-11-12 14:13:03 +010047 atomic_t triggered_count;
Philipp Zabel61fc4132012-11-19 17:23:13 +010048};
49
50/**
51 * of_reset_simple_xlate - translate reset_spec to the reset line number
52 * @rcdev: a pointer to the reset controller device
53 * @reset_spec: reset line specifier as found in the device tree
54 * @flags: a flags pointer to fill in (optional)
55 *
56 * This simple translation function should be used for reset controllers
57 * with 1:1 mapping, where reset lines can be indexed by number without gaps.
58 */
Rashika Kheria0c5b2b92013-12-19 14:11:10 +053059static int of_reset_simple_xlate(struct reset_controller_dev *rcdev,
Philipp Zabel61fc4132012-11-19 17:23:13 +010060 const struct of_phandle_args *reset_spec)
61{
Philipp Zabel61fc4132012-11-19 17:23:13 +010062 if (reset_spec->args[0] >= rcdev->nr_resets)
63 return -EINVAL;
64
65 return reset_spec->args[0];
66}
Philipp Zabel61fc4132012-11-19 17:23:13 +010067
68/**
69 * reset_controller_register - register a reset controller device
70 * @rcdev: a pointer to the initialized reset controller device
71 */
72int reset_controller_register(struct reset_controller_dev *rcdev)
73{
74 if (!rcdev->of_xlate) {
75 rcdev->of_reset_n_cells = 1;
76 rcdev->of_xlate = of_reset_simple_xlate;
77 }
78
Hans de Goedec15ddec2016-02-23 18:46:25 +010079 INIT_LIST_HEAD(&rcdev->reset_control_head);
80
81 mutex_lock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +010082 list_add(&rcdev->list, &reset_controller_list);
Hans de Goedec15ddec2016-02-23 18:46:25 +010083 mutex_unlock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +010084
85 return 0;
86}
87EXPORT_SYMBOL_GPL(reset_controller_register);
88
89/**
90 * reset_controller_unregister - unregister a reset controller device
91 * @rcdev: a pointer to the reset controller device
92 */
93void reset_controller_unregister(struct reset_controller_dev *rcdev)
94{
Hans de Goedec15ddec2016-02-23 18:46:25 +010095 mutex_lock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +010096 list_del(&rcdev->list);
Hans de Goedec15ddec2016-02-23 18:46:25 +010097 mutex_unlock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +010098}
99EXPORT_SYMBOL_GPL(reset_controller_unregister);
100
Masahiro Yamada8d5b5d52016-05-01 19:36:57 +0900101static void devm_reset_controller_release(struct device *dev, void *res)
102{
103 reset_controller_unregister(*(struct reset_controller_dev **)res);
104}
105
106/**
107 * devm_reset_controller_register - resource managed reset_controller_register()
108 * @dev: device that is registering this reset controller
109 * @rcdev: a pointer to the initialized reset controller device
110 *
111 * Managed reset_controller_register(). For reset controllers registered by
112 * this function, reset_controller_unregister() is automatically called on
113 * driver detach. See reset_controller_register() for more information.
114 */
115int devm_reset_controller_register(struct device *dev,
116 struct reset_controller_dev *rcdev)
117{
118 struct reset_controller_dev **rcdevp;
119 int ret;
120
121 rcdevp = devres_alloc(devm_reset_controller_release, sizeof(*rcdevp),
122 GFP_KERNEL);
123 if (!rcdevp)
124 return -ENOMEM;
125
126 ret = reset_controller_register(rcdev);
127 if (!ret) {
128 *rcdevp = rcdev;
129 devres_add(dev, rcdevp);
130 } else {
131 devres_free(rcdevp);
132 }
133
134 return ret;
135}
136EXPORT_SYMBOL_GPL(devm_reset_controller_register);
137
Philipp Zabel61fc4132012-11-19 17:23:13 +0100138/**
139 * reset_control_reset - reset the controlled device
140 * @rstc: reset controller
Hans de Goede0b522972016-02-23 18:46:26 +0100141 *
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100142 * On a shared reset line the actual reset pulse is only triggered once for the
143 * lifetime of the reset_control instance: for all but the first caller this is
144 * a no-op.
145 * Consumers must not use reset_control_(de)assert on shared reset lines when
146 * reset_control_reset has been used.
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000147 *
148 * If rstc is NULL it is an optional reset and the function will just
149 * return 0.
Philipp Zabel61fc4132012-11-19 17:23:13 +0100150 */
151int reset_control_reset(struct reset_control *rstc)
152{
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100153 int ret;
154
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000155 if (!rstc)
156 return 0;
157
158 if (WARN_ON(IS_ERR(rstc)))
Hans de Goede0b522972016-02-23 18:46:26 +0100159 return -EINVAL;
160
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100161 if (!rstc->rcdev->ops->reset)
162 return -ENOTSUPP;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100163
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100164 if (rstc->shared) {
165 if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
166 return -EINVAL;
167
168 if (atomic_inc_return(&rstc->triggered_count) != 1)
169 return 0;
170 }
171
172 ret = rstc->rcdev->ops->reset(rstc->rcdev, rstc->id);
Jerome Brunete5a1dad2017-02-15 19:15:51 +0100173 if (rstc->shared && ret)
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100174 atomic_dec(&rstc->triggered_count);
175
176 return ret;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100177}
178EXPORT_SYMBOL_GPL(reset_control_reset);
179
180/**
181 * reset_control_assert - asserts the reset line
182 * @rstc: reset controller
Hans de Goede0b522972016-02-23 18:46:26 +0100183 *
184 * Calling this on an exclusive reset controller guarantees that the reset
185 * will be asserted. When called on a shared reset controller the line may
186 * still be deasserted, as long as other users keep it so.
187 *
188 * For shared reset controls a driver cannot expect the hw's registers and
189 * internal state to be reset, but must be prepared for this to happen.
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100190 * Consumers must not use reset_control_reset on shared reset lines when
191 * reset_control_(de)assert has been used.
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000192 * return 0.
193 *
194 * If rstc is NULL it is an optional reset and the function will just
195 * return 0.
Philipp Zabel61fc4132012-11-19 17:23:13 +0100196 */
197int reset_control_assert(struct reset_control *rstc)
198{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000199 if (!rstc)
200 return 0;
201
202 if (WARN_ON(IS_ERR(rstc)))
Philipp Zabela3774e12016-06-20 13:05:14 +0200203 return -EINVAL;
204
Hans de Goede0b522972016-02-23 18:46:26 +0100205 if (!rstc->rcdev->ops->assert)
206 return -ENOTSUPP;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100207
Hans de Goede0b522972016-02-23 18:46:26 +0100208 if (rstc->shared) {
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100209 if (WARN_ON(atomic_read(&rstc->triggered_count) != 0))
210 return -EINVAL;
211
Hans de Goede0b522972016-02-23 18:46:26 +0100212 if (WARN_ON(atomic_read(&rstc->deassert_count) == 0))
213 return -EINVAL;
214
215 if (atomic_dec_return(&rstc->deassert_count) != 0)
216 return 0;
217 }
218
219 return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100220}
221EXPORT_SYMBOL_GPL(reset_control_assert);
222
223/**
224 * reset_control_deassert - deasserts the reset line
225 * @rstc: reset controller
Hans de Goede0b522972016-02-23 18:46:26 +0100226 *
227 * After calling this function, the reset is guaranteed to be deasserted.
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100228 * Consumers must not use reset_control_reset on shared reset lines when
229 * reset_control_(de)assert has been used.
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000230 * return 0.
231 *
232 * If rstc is NULL it is an optional reset and the function will just
233 * return 0.
Philipp Zabel61fc4132012-11-19 17:23:13 +0100234 */
235int reset_control_deassert(struct reset_control *rstc)
236{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000237 if (!rstc)
238 return 0;
239
240 if (WARN_ON(IS_ERR(rstc)))
Philipp Zabela3774e12016-06-20 13:05:14 +0200241 return -EINVAL;
242
Hans de Goede0b522972016-02-23 18:46:26 +0100243 if (!rstc->rcdev->ops->deassert)
244 return -ENOTSUPP;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100245
Hans de Goede0b522972016-02-23 18:46:26 +0100246 if (rstc->shared) {
Martin Blumenstingl7da33a32016-11-12 14:13:03 +0100247 if (WARN_ON(atomic_read(&rstc->triggered_count) != 0))
248 return -EINVAL;
249
Hans de Goede0b522972016-02-23 18:46:26 +0100250 if (atomic_inc_return(&rstc->deassert_count) != 1)
251 return 0;
252 }
253
254 return rstc->rcdev->ops->deassert(rstc->rcdev, rstc->id);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100255}
256EXPORT_SYMBOL_GPL(reset_control_deassert);
257
258/**
Dinh Nguyen729de412014-10-10 10:21:14 -0500259 * reset_control_status - returns a negative errno if not supported, a
260 * positive value if the reset line is asserted, or zero if the reset
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000261 * line is not asserted or if the desc is NULL (optional reset).
Dinh Nguyen729de412014-10-10 10:21:14 -0500262 * @rstc: reset controller
263 */
264int reset_control_status(struct reset_control *rstc)
265{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000266 if (!rstc)
267 return 0;
268
269 if (WARN_ON(IS_ERR(rstc)))
Philipp Zabela3774e12016-06-20 13:05:14 +0200270 return -EINVAL;
271
Dinh Nguyen729de412014-10-10 10:21:14 -0500272 if (rstc->rcdev->ops->status)
273 return rstc->rcdev->ops->status(rstc->rcdev, rstc->id);
274
Philipp Zabel39b4da72015-10-29 09:55:00 +0100275 return -ENOTSUPP;
Dinh Nguyen729de412014-10-10 10:21:14 -0500276}
277EXPORT_SYMBOL_GPL(reset_control_status);
278
Philipp Zabel62e24c52016-02-05 13:41:39 +0100279static struct reset_control *__reset_control_get_internal(
Hans de Goedec15ddec2016-02-23 18:46:25 +0100280 struct reset_controller_dev *rcdev,
Ramiro Oliveiraee48c722017-01-13 17:57:40 +0000281 unsigned int index, bool shared)
Hans de Goedec15ddec2016-02-23 18:46:25 +0100282{
283 struct reset_control *rstc;
284
285 lockdep_assert_held(&reset_list_mutex);
286
287 list_for_each_entry(rstc, &rcdev->reset_control_head, list) {
288 if (rstc->id == index) {
Hans de Goede0b522972016-02-23 18:46:26 +0100289 if (WARN_ON(!rstc->shared || !shared))
290 return ERR_PTR(-EBUSY);
291
Philipp Zabeld25e4332017-05-31 17:42:29 +0200292 kref_get(&rstc->refcnt);
Hans de Goedec15ddec2016-02-23 18:46:25 +0100293 return rstc;
294 }
295 }
296
297 rstc = kzalloc(sizeof(*rstc), GFP_KERNEL);
298 if (!rstc)
299 return ERR_PTR(-ENOMEM);
300
301 try_module_get(rcdev->owner);
302
303 rstc->rcdev = rcdev;
304 list_add(&rstc->list, &rcdev->reset_control_head);
305 rstc->id = index;
Philipp Zabeld25e4332017-05-31 17:42:29 +0200306 kref_init(&rstc->refcnt);
Hans de Goede0b522972016-02-23 18:46:26 +0100307 rstc->shared = shared;
Hans de Goedec15ddec2016-02-23 18:46:25 +0100308
309 return rstc;
310}
311
Philipp Zabeld25e4332017-05-31 17:42:29 +0200312static void __reset_control_release(struct kref *kref)
313{
314 struct reset_control *rstc = container_of(kref, struct reset_control,
315 refcnt);
316
317 lockdep_assert_held(&reset_list_mutex);
318
319 module_put(rstc->rcdev->owner);
320
321 list_del(&rstc->list);
322 kfree(rstc);
323}
324
Philipp Zabel62e24c52016-02-05 13:41:39 +0100325static void __reset_control_put_internal(struct reset_control *rstc)
Hans de Goedec15ddec2016-02-23 18:46:25 +0100326{
327 lockdep_assert_held(&reset_list_mutex);
328
Philipp Zabeld25e4332017-05-31 17:42:29 +0200329 kref_put(&rstc->refcnt, __reset_control_release);
Hans de Goedec15ddec2016-02-23 18:46:25 +0100330}
331
Hans de Goede6c96f052016-02-23 18:46:24 +0100332struct reset_control *__of_reset_control_get(struct device_node *node,
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000333 const char *id, int index, bool shared,
334 bool optional)
Philipp Zabel61fc4132012-11-19 17:23:13 +0100335{
Philipp Zabeld056c9b2015-12-08 18:49:53 +0100336 struct reset_control *rstc;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100337 struct reset_controller_dev *r, *rcdev;
338 struct of_phandle_args args;
Philipp Zabel61fc4132012-11-19 17:23:13 +0100339 int rstc_id;
340 int ret;
341
Hans de Goede6c96f052016-02-23 18:46:24 +0100342 if (!node)
343 return ERR_PTR(-EINVAL);
344
345 if (id) {
346 index = of_property_match_string(node,
347 "reset-names", id);
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000348 if (index == -EILSEQ)
349 return ERR_PTR(index);
Hans de Goede6c96f052016-02-23 18:46:24 +0100350 if (index < 0)
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000351 return optional ? NULL : ERR_PTR(-ENOENT);
Hans de Goede6c96f052016-02-23 18:46:24 +0100352 }
353
Maxime Ripardfc0a5922013-12-20 22:41:07 +0100354 ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
Philipp Zabel61fc4132012-11-19 17:23:13 +0100355 index, &args);
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000356 if (ret == -EINVAL)
Philipp Zabel61fc4132012-11-19 17:23:13 +0100357 return ERR_PTR(ret);
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000358 if (ret)
359 return optional ? NULL : ERR_PTR(ret);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100360
Hans de Goedec15ddec2016-02-23 18:46:25 +0100361 mutex_lock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100362 rcdev = NULL;
363 list_for_each_entry(r, &reset_controller_list, list) {
364 if (args.np == r->of_node) {
365 rcdev = r;
366 break;
367 }
368 }
369 of_node_put(args.np);
370
371 if (!rcdev) {
Hans de Goedec15ddec2016-02-23 18:46:25 +0100372 mutex_unlock(&reset_list_mutex);
Philipp Zabel3d103022013-07-18 13:55:22 +0200373 return ERR_PTR(-EPROBE_DEFER);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100374 }
375
Maxime Riparde6777742016-01-14 16:24:44 +0100376 if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) {
Hans de Goedec15ddec2016-02-23 18:46:25 +0100377 mutex_unlock(&reset_list_mutex);
Maxime Riparde6777742016-01-14 16:24:44 +0100378 return ERR_PTR(-EINVAL);
379 }
380
Philipp Zabel61fc4132012-11-19 17:23:13 +0100381 rstc_id = rcdev->of_xlate(rcdev, &args);
382 if (rstc_id < 0) {
Hans de Goedec15ddec2016-02-23 18:46:25 +0100383 mutex_unlock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100384 return ERR_PTR(rstc_id);
385 }
386
Hans de Goedec15ddec2016-02-23 18:46:25 +0100387 /* reset_list_mutex also protects the rcdev's reset_control list */
Philipp Zabel62e24c52016-02-05 13:41:39 +0100388 rstc = __reset_control_get_internal(rcdev, rstc_id, shared);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100389
Hans de Goedec15ddec2016-02-23 18:46:25 +0100390 mutex_unlock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100391
392 return rstc;
393}
Hans de Goede6c96f052016-02-23 18:46:24 +0100394EXPORT_SYMBOL_GPL(__of_reset_control_get);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100395
Philipp Zabel62e24c52016-02-05 13:41:39 +0100396struct reset_control *__reset_control_get(struct device *dev, const char *id,
397 int index, bool shared, bool optional)
398{
399 if (dev->of_node)
400 return __of_reset_control_get(dev->of_node, id, index, shared,
401 optional);
402
403 return optional ? NULL : ERR_PTR(-EINVAL);
404}
405EXPORT_SYMBOL_GPL(__reset_control_get);
406
Philipp Zabel61fc4132012-11-19 17:23:13 +0100407/**
408 * reset_control_put - free the reset controller
409 * @rstc: reset controller
410 */
Philipp Zabel61fc4132012-11-19 17:23:13 +0100411void reset_control_put(struct reset_control *rstc)
412{
Heiner Kallweit48914862017-02-01 08:05:22 +0100413 if (IS_ERR_OR_NULL(rstc))
Philipp Zabel61fc4132012-11-19 17:23:13 +0100414 return;
415
Hans de Goedec15ddec2016-02-23 18:46:25 +0100416 mutex_lock(&reset_list_mutex);
Philipp Zabel62e24c52016-02-05 13:41:39 +0100417 __reset_control_put_internal(rstc);
Hans de Goedec15ddec2016-02-23 18:46:25 +0100418 mutex_unlock(&reset_list_mutex);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100419}
420EXPORT_SYMBOL_GPL(reset_control_put);
421
422static void devm_reset_control_release(struct device *dev, void *res)
423{
424 reset_control_put(*(struct reset_control **)res);
425}
426
Hans de Goede6c96f052016-02-23 18:46:24 +0100427struct reset_control *__devm_reset_control_get(struct device *dev,
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000428 const char *id, int index, bool shared,
429 bool optional)
Philipp Zabel61fc4132012-11-19 17:23:13 +0100430{
431 struct reset_control **ptr, *rstc;
432
433 ptr = devres_alloc(devm_reset_control_release, sizeof(*ptr),
434 GFP_KERNEL);
435 if (!ptr)
436 return ERR_PTR(-ENOMEM);
437
Philipp Zabel62e24c52016-02-05 13:41:39 +0100438 rstc = __reset_control_get(dev, id, index, shared, optional);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100439 if (!IS_ERR(rstc)) {
440 *ptr = rstc;
441 devres_add(dev, ptr);
442 } else {
443 devres_free(ptr);
444 }
445
446 return rstc;
447}
Hans de Goede6c96f052016-02-23 18:46:24 +0100448EXPORT_SYMBOL_GPL(__devm_reset_control_get);
Philipp Zabel61fc4132012-11-19 17:23:13 +0100449
Philipp Zabel61fc4132012-11-19 17:23:13 +0100450/**
451 * device_reset - find reset controller associated with the device
452 * and perform reset
453 * @dev: device to be reset by the controller
454 *
455 * Convenience wrapper for reset_control_get() and reset_control_reset().
456 * This is useful for the common case of devices with single, dedicated reset
457 * lines.
458 */
459int device_reset(struct device *dev)
460{
461 struct reset_control *rstc;
462 int ret;
463
464 rstc = reset_control_get(dev, NULL);
465 if (IS_ERR(rstc))
466 return PTR_ERR(rstc);
467
468 ret = reset_control_reset(rstc);
469
470 reset_control_put(rstc);
471
472 return ret;
473}
474EXPORT_SYMBOL_GPL(device_reset);