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