3b3947c6bf0acef1d3e59ac89c80e7234823b270
[openwrt/openwrt.git] / target / linux / oxnas / patches-3.14 / 100-obtain-reset-controller-from-device-tree.patch
1 Index: linux-3.13.7/drivers/reset/core.c
2 ===================================================================
3 --- linux-3.13.7.orig/drivers/reset/core.c
4 +++ linux-3.13.7/drivers/reset/core.c
5 @@ -127,15 +127,16 @@ int reset_control_deassert(struct reset_
6 EXPORT_SYMBOL_GPL(reset_control_deassert);
7
8 /**
9 - * reset_control_get - Lookup and obtain a reference to a reset controller.
10 - * @dev: device to be reset by the controller
11 + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
12 + * @node: device to be reset by the controller
13 * @id: reset line name
14 *
15 * Returns a struct reset_control or IS_ERR() condition containing errno.
16 *
17 * Use of id names is optional.
18 */
19 -struct reset_control *reset_control_get(struct device *dev, const char *id)
20 +struct reset_control *of_reset_control_get(struct device_node *node,
21 + const char *id)
22 {
23 struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
24 struct reset_controller_dev *r, *rcdev;
25 @@ -144,13 +145,10 @@ struct reset_control *reset_control_get(
26 int rstc_id;
27 int ret;
28
29 - if (!dev)
30 - return ERR_PTR(-EINVAL);
31 -
32 if (id)
33 - index = of_property_match_string(dev->of_node,
34 + index = of_property_match_string(node,
35 "reset-names", id);
36 - ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells",
37 + ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
38 index, &args);
39 if (ret)
40 return ERR_PTR(ret);
41 @@ -185,12 +183,35 @@ struct reset_control *reset_control_get(
42 return ERR_PTR(-ENOMEM);
43 }
44
45 - rstc->dev = dev;
46 rstc->rcdev = rcdev;
47 rstc->id = rstc_id;
48
49 return rstc;
50 }
51 +EXPORT_SYMBOL_GPL(of_reset_control_get);
52 +
53 +/**
54 + * reset_control_get - Lookup and obtain a reference to a reset controller.
55 + * @dev: device to be reset by the controller
56 + * @id: reset line name
57 + *
58 + * Returns a struct reset_control or IS_ERR() condition containing errno.
59 + *
60 + * Use of id names is optional.
61 + */
62 +struct reset_control *reset_control_get(struct device *dev, const char *id)
63 +{
64 + struct reset_control *rstc;
65 +
66 + if (!dev)
67 + return ERR_PTR(-EINVAL);
68 +
69 + rstc = of_reset_control_get(dev->of_node, id);
70 + if (!IS_ERR(rstc))
71 + rstc->dev = dev;
72 +
73 + return rstc;
74 +}
75 EXPORT_SYMBOL_GPL(reset_control_get);
76
77 /**
78 Index: linux-3.13.7/include/linux/reset.h
79 ===================================================================
80 --- linux-3.13.7.orig/include/linux/reset.h
81 +++ linux-3.13.7/include/linux/reset.h
82 @@ -1,6 +1,8 @@
83 #ifndef _LINUX_RESET_H_
84 #define _LINUX_RESET_H_
85
86 +#include <linux/of.h>
87 +
88 struct device;
89 struct reset_control;
90
91 @@ -8,6 +10,8 @@ int reset_control_reset(struct reset_con
92 int reset_control_assert(struct reset_control *rstc);
93 int reset_control_deassert(struct reset_control *rstc);
94
95 +struct reset_control *of_reset_control_get(struct device_node *node,
96 + const char *id);
97 struct reset_control *reset_control_get(struct device *dev, const char *id);
98 void reset_control_put(struct reset_control *rstc);
99 struct reset_control *devm_reset_control_get(struct device *dev, const char *id);