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