kernel/4.3: update to version 4.3.3
[openwrt/openwrt.git] / target / linux / mediatek / patches / 0003-clk-mediatek-Add-reset-controller-support.patch
1 From c91e8490e45c68ea517f70f24568034b7735e8b9 Mon Sep 17 00:00:00 2001
2 From: Sascha Hauer <s.hauer@pengutronix.de>
3 Date: Thu, 23 Apr 2015 10:35:40 +0200
4 Subject: [PATCH 03/76] clk: mediatek: Add reset controller support
5
6 The pericfg and infracfg units also provide reset lines to several
7 other SoC internal units. This adds a function which can be called
8 from the pericfg and infracfg initialization functions which will
9 register the reset controller using reset_controller_register. The
10 reset controller will provide support for resetting the units
11 connected to the pericfg and infracfg controller. The units resetted
12 by this controller can use the standard reset device tree binding
13 to gain access to the reset lines.
14
15 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
16 Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
17 ---
18 drivers/clk/mediatek/Makefile | 1 +
19 drivers/clk/mediatek/clk-mtk.h | 10 +++++
20 drivers/clk/mediatek/reset.c | 97 ++++++++++++++++++++++++++++++++++++++++
21 3 files changed, 108 insertions(+)
22 create mode 100644 drivers/clk/mediatek/reset.c
23
24 --- a/drivers/clk/mediatek/Makefile
25 +++ b/drivers/clk/mediatek/Makefile
26 @@ -1 +1,2 @@
27 obj-y += clk-mtk.o clk-pll.o clk-gate.o
28 +obj-$(CONFIG_RESET_CONTROLLER) += reset.o
29 --- a/drivers/clk/mediatek/clk-mtk.h
30 +++ b/drivers/clk/mediatek/clk-mtk.h
31 @@ -156,4 +156,14 @@ void __init mtk_clk_register_plls(struct
32 const struct mtk_pll_data *plls, int num_plls,
33 struct clk_onecell_data *clk_data);
34
35 +#ifdef CONFIG_RESET_CONTROLLER
36 +void mtk_register_reset_controller(struct device_node *np,
37 + unsigned int num_regs, int regofs);
38 +#else
39 +static inline void mtk_register_reset_controller(struct device_node *np,
40 + unsigned int num_regs, int regofs)
41 +{
42 +}
43 +#endif
44 +
45 #endif /* __DRV_CLK_MTK_H */
46 --- /dev/null
47 +++ b/drivers/clk/mediatek/reset.c
48 @@ -0,0 +1,97 @@
49 +/*
50 + * Copyright (c) 2014 MediaTek Inc.
51 + *
52 + * This program is free software; you can redistribute it and/or modify
53 + * it under the terms of the GNU General Public License version 2 as
54 + * published by the Free Software Foundation.
55 + *
56 + * This program is distributed in the hope that it will be useful,
57 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
58 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59 + * GNU General Public License for more details.
60 + */
61 +
62 +#include <linux/mfd/syscon.h>
63 +#include <linux/module.h>
64 +#include <linux/of.h>
65 +#include <linux/platform_device.h>
66 +#include <linux/regmap.h>
67 +#include <linux/reset-controller.h>
68 +#include <linux/slab.h>
69 +
70 +#include "clk-mtk.h"
71 +
72 +struct mtk_reset {
73 + struct regmap *regmap;
74 + int regofs;
75 + struct reset_controller_dev rcdev;
76 +};
77 +
78 +static int mtk_reset_assert(struct reset_controller_dev *rcdev,
79 + unsigned long id)
80 +{
81 + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
82 +
83 + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
84 + BIT(id % 32), ~0);
85 +}
86 +
87 +static int mtk_reset_deassert(struct reset_controller_dev *rcdev,
88 + unsigned long id)
89 +{
90 + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
91 +
92 + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
93 + BIT(id % 32), 0);
94 +}
95 +
96 +static int mtk_reset(struct reset_controller_dev *rcdev,
97 + unsigned long id)
98 +{
99 + int ret;
100 +
101 + ret = mtk_reset_assert(rcdev, id);
102 + if (ret)
103 + return ret;
104 +
105 + return mtk_reset_deassert(rcdev, id);
106 +}
107 +
108 +static struct reset_control_ops mtk_reset_ops = {
109 + .assert = mtk_reset_assert,
110 + .deassert = mtk_reset_deassert,
111 + .reset = mtk_reset,
112 +};
113 +
114 +void mtk_register_reset_controller(struct device_node *np,
115 + unsigned int num_regs, int regofs)
116 +{
117 + struct mtk_reset *data;
118 + int ret;
119 + struct regmap *regmap;
120 +
121 + regmap = syscon_node_to_regmap(np);
122 + if (IS_ERR(regmap)) {
123 + pr_err("Cannot find regmap for %s: %ld\n", np->full_name,
124 + PTR_ERR(regmap));
125 + return;
126 + }
127 +
128 + data = kzalloc(sizeof(*data), GFP_KERNEL);
129 + if (!data)
130 + return;
131 +
132 + data->regmap = regmap;
133 + data->regofs = regofs;
134 + data->rcdev.owner = THIS_MODULE;
135 + data->rcdev.nr_resets = num_regs * 32;
136 + data->rcdev.ops = &mtk_reset_ops;
137 + data->rcdev.of_node = np;
138 +
139 + ret = reset_controller_register(&data->rcdev);
140 + if (ret) {
141 + pr_err("could not register reset controller: %d\n", ret);
142 + kfree(data);
143 + return;
144 + }
145 +}