73ecca10f7514e7c8fc66a1128d92cf0bae5dc16
[openwrt.git] / target / linux / sunxi / patches-3.13 / 201-reset-add-of_reset_control_get.patch
1 From 0325b48d6149e131c90ed6ec77458f4d2df73898 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Fri, 20 Dec 2013 22:41:07 +0100
4 Subject: [PATCH] reset: Add of_reset_control_get
5
6 In some cases, you might need to deassert from reset an hardware block that
7 doesn't associated to a struct device (CPUs, timers, etc.).
8
9 Add a small helper to retrieve the reset controller from the device tree
10 without the need to pass a struct device.
11
12 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
13 ---
14  drivers/reset/core.c  | 39 ++++++++++++++++++++++++++++++---------
15  include/linux/reset.h |  4 ++++
16  2 files changed, 34 insertions(+), 9 deletions(-)
17
18 diff --git a/drivers/reset/core.c b/drivers/reset/core.c
19 index d1b6089..4f3dda7 100644
20 --- a/drivers/reset/core.c
21 +++ b/drivers/reset/core.c
22 @@ -127,15 +127,16 @@ int reset_control_deassert(struct reset_control *rstc)
23  EXPORT_SYMBOL_GPL(reset_control_deassert);
24  
25  /**
26 - * reset_control_get - Lookup and obtain a reference to a reset controller.
27 - * @dev: device to be reset by the controller
28 + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
29 + * @node: device to be reset by the controller
30   * @id: reset line name
31   *
32   * Returns a struct reset_control or IS_ERR() condition containing errno.
33   *
34   * Use of id names is optional.
35   */
36 -struct reset_control *reset_control_get(struct device *dev, const char *id)
37 +struct reset_control *of_reset_control_get(struct device_node *node,
38 +                                          const char *id)
39  {
40         struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
41         struct reset_controller_dev *r, *rcdev;
42 @@ -144,13 +145,10 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
43         int rstc_id;
44         int ret;
45  
46 -       if (!dev)
47 -               return ERR_PTR(-EINVAL);
48 -
49         if (id)
50 -               index = of_property_match_string(dev->of_node,
51 +               index = of_property_match_string(node,
52                                                  "reset-names", id);
53 -       ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells",
54 +       ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
55                                          index, &args);
56         if (ret)
57                 return ERR_PTR(ret);
58 @@ -185,12 +183,35 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
59                 return ERR_PTR(-ENOMEM);
60         }
61  
62 -       rstc->dev = dev;
63         rstc->rcdev = rcdev;
64         rstc->id = rstc_id;
65  
66         return rstc;
67  }
68 +EXPORT_SYMBOL_GPL(of_reset_control_get);
69 +
70 +/**
71 + * reset_control_get - Lookup and obtain a reference to a reset controller.
72 + * @dev: device to be reset by the controller
73 + * @id: reset line name
74 + *
75 + * Returns a struct reset_control or IS_ERR() condition containing errno.
76 + *
77 + * Use of id names is optional.
78 + */
79 +struct reset_control *reset_control_get(struct device *dev, const char *id)
80 +{
81 +       struct reset_control *rstc;
82 +
83 +       if (!dev)
84 +               return ERR_PTR(-EINVAL);
85 +
86 +       rstc = of_reset_control_get(dev->of_node, id);
87 +       if (!IS_ERR(rstc))
88 +               rstc->dev = dev;
89 +
90 +       return rstc;
91 +}
92  EXPORT_SYMBOL_GPL(reset_control_get);
93  
94  /**
95 diff --git a/include/linux/reset.h b/include/linux/reset.h
96 index 6082247..a398025 100644
97 --- a/include/linux/reset.h
98 +++ b/include/linux/reset.h
99 @@ -1,6 +1,8 @@
100  #ifndef _LINUX_RESET_H_
101  #define _LINUX_RESET_H_
102  
103 +#include <linux/of.h>
104 +
105  struct device;
106  struct reset_control;
107  
108 @@ -8,6 +10,8 @@
109  int reset_control_assert(struct reset_control *rstc);
110  int reset_control_deassert(struct reset_control *rstc);
111  
112 +struct reset_control *of_reset_control_get(struct device_node *node,
113 +                                          const char *id);
114  struct reset_control *reset_control_get(struct device *dev, const char *id);
115  void reset_control_put(struct reset_control *rstc);
116  struct reset_control *devm_reset_control_get(struct device *dev, const char *id);
117 -- 
118 1.8.5.1
119