xref: /openbmc/linux/drivers/clk/rockchip/clk.c (revision dfff24bde7fb8d57482e907d5dfb0be3a9e28119)
1a245fecbSHeiko Stübner /*
2a245fecbSHeiko Stübner  * Copyright (c) 2014 MundoReader S.L.
3a245fecbSHeiko Stübner  * Author: Heiko Stuebner <heiko@sntech.de>
4a245fecbSHeiko Stübner  *
5a245fecbSHeiko Stübner  * based on
6a245fecbSHeiko Stübner  *
7a245fecbSHeiko Stübner  * samsung/clk.c
8a245fecbSHeiko Stübner  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
9a245fecbSHeiko Stübner  * Copyright (c) 2013 Linaro Ltd.
10a245fecbSHeiko Stübner  * Author: Thomas Abraham <thomas.ab@samsung.com>
11a245fecbSHeiko Stübner  *
12a245fecbSHeiko Stübner  * This program is free software; you can redistribute it and/or modify
13a245fecbSHeiko Stübner  * it under the terms of the GNU General Public License as published by
14a245fecbSHeiko Stübner  * the Free Software Foundation; either version 2 of the License, or
15a245fecbSHeiko Stübner  * (at your option) any later version.
16a245fecbSHeiko Stübner  *
17a245fecbSHeiko Stübner  * This program is distributed in the hope that it will be useful,
18a245fecbSHeiko Stübner  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19a245fecbSHeiko Stübner  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20a245fecbSHeiko Stübner  * GNU General Public License for more details.
21a245fecbSHeiko Stübner  */
22a245fecbSHeiko Stübner 
23a245fecbSHeiko Stübner #include <linux/slab.h>
24a245fecbSHeiko Stübner #include <linux/clk.h>
25a245fecbSHeiko Stübner #include <linux/clk-provider.h>
2690c59025SHeiko Stübner #include <linux/mfd/syscon.h>
2790c59025SHeiko Stübner #include <linux/regmap.h>
286f1294b5SHeiko Stübner #include <linux/reboot.h>
29a245fecbSHeiko Stübner #include "clk.h"
30a245fecbSHeiko Stübner 
31a245fecbSHeiko Stübner /**
32a245fecbSHeiko Stübner  * Register a clock branch.
33a245fecbSHeiko Stübner  * Most clock branches have a form like
34a245fecbSHeiko Stübner  *
35a245fecbSHeiko Stübner  * src1 --|--\
36a245fecbSHeiko Stübner  *        |M |--[GATE]-[DIV]-
37a245fecbSHeiko Stübner  * src2 --|--/
38a245fecbSHeiko Stübner  *
39a245fecbSHeiko Stübner  * sometimes without one of those components.
40a245fecbSHeiko Stübner  */
411a4b1819SHeiko Stübner static struct clk *rockchip_clk_register_branch(const char *name,
424a1caed3SUwe Kleine-König 		const char *const *parent_names, u8 num_parents, void __iomem *base,
43a245fecbSHeiko Stübner 		int muxdiv_offset, u8 mux_shift, u8 mux_width, u8 mux_flags,
44a245fecbSHeiko Stübner 		u8 div_shift, u8 div_width, u8 div_flags,
45a245fecbSHeiko Stübner 		struct clk_div_table *div_table, int gate_offset,
46a245fecbSHeiko Stübner 		u8 gate_shift, u8 gate_flags, unsigned long flags,
47a245fecbSHeiko Stübner 		spinlock_t *lock)
48a245fecbSHeiko Stübner {
49a245fecbSHeiko Stübner 	struct clk *clk;
50a245fecbSHeiko Stübner 	struct clk_mux *mux = NULL;
51a245fecbSHeiko Stübner 	struct clk_gate *gate = NULL;
52a245fecbSHeiko Stübner 	struct clk_divider *div = NULL;
53a245fecbSHeiko Stübner 	const struct clk_ops *mux_ops = NULL, *div_ops = NULL,
54a245fecbSHeiko Stübner 			     *gate_ops = NULL;
55a245fecbSHeiko Stübner 
56a245fecbSHeiko Stübner 	if (num_parents > 1) {
57a245fecbSHeiko Stübner 		mux = kzalloc(sizeof(*mux), GFP_KERNEL);
58a245fecbSHeiko Stübner 		if (!mux)
59a245fecbSHeiko Stübner 			return ERR_PTR(-ENOMEM);
60a245fecbSHeiko Stübner 
61a245fecbSHeiko Stübner 		mux->reg = base + muxdiv_offset;
62a245fecbSHeiko Stübner 		mux->shift = mux_shift;
63a245fecbSHeiko Stübner 		mux->mask = BIT(mux_width) - 1;
64a245fecbSHeiko Stübner 		mux->flags = mux_flags;
65a245fecbSHeiko Stübner 		mux->lock = lock;
66a245fecbSHeiko Stübner 		mux_ops = (mux_flags & CLK_MUX_READ_ONLY) ? &clk_mux_ro_ops
67a245fecbSHeiko Stübner 							: &clk_mux_ops;
68a245fecbSHeiko Stübner 	}
69a245fecbSHeiko Stübner 
70a245fecbSHeiko Stübner 	if (gate_offset >= 0) {
71a245fecbSHeiko Stübner 		gate = kzalloc(sizeof(*gate), GFP_KERNEL);
72a245fecbSHeiko Stübner 		if (!gate)
73a245fecbSHeiko Stübner 			return ERR_PTR(-ENOMEM);
74a245fecbSHeiko Stübner 
75a245fecbSHeiko Stübner 		gate->flags = gate_flags;
76a245fecbSHeiko Stübner 		gate->reg = base + gate_offset;
77a245fecbSHeiko Stübner 		gate->bit_idx = gate_shift;
78a245fecbSHeiko Stübner 		gate->lock = lock;
79a245fecbSHeiko Stübner 		gate_ops = &clk_gate_ops;
80a245fecbSHeiko Stübner 	}
81a245fecbSHeiko Stübner 
82a245fecbSHeiko Stübner 	if (div_width > 0) {
83a245fecbSHeiko Stübner 		div = kzalloc(sizeof(*div), GFP_KERNEL);
84a245fecbSHeiko Stübner 		if (!div)
85a245fecbSHeiko Stübner 			return ERR_PTR(-ENOMEM);
86a245fecbSHeiko Stübner 
87a245fecbSHeiko Stübner 		div->flags = div_flags;
88a245fecbSHeiko Stübner 		div->reg = base + muxdiv_offset;
89a245fecbSHeiko Stübner 		div->shift = div_shift;
90a245fecbSHeiko Stübner 		div->width = div_width;
91a245fecbSHeiko Stübner 		div->lock = lock;
92a245fecbSHeiko Stübner 		div->table = div_table;
93e6d5e7d9SJames Hogan 		div_ops = &clk_divider_ops;
94a245fecbSHeiko Stübner 	}
95a245fecbSHeiko Stübner 
96a245fecbSHeiko Stübner 	clk = clk_register_composite(NULL, name, parent_names, num_parents,
97a245fecbSHeiko Stübner 				     mux ? &mux->hw : NULL, mux_ops,
98a245fecbSHeiko Stübner 				     div ? &div->hw : NULL, div_ops,
99a245fecbSHeiko Stübner 				     gate ? &gate->hw : NULL, gate_ops,
100a245fecbSHeiko Stübner 				     flags);
101a245fecbSHeiko Stübner 
102a245fecbSHeiko Stübner 	return clk;
103a245fecbSHeiko Stübner }
104a245fecbSHeiko Stübner 
105b2155a71SHeiko Stübner static struct clk *rockchip_clk_register_frac_branch(const char *name,
1064a1caed3SUwe Kleine-König 		const char *const *parent_names, u8 num_parents,
1074a1caed3SUwe Kleine-König 		void __iomem *base, int muxdiv_offset, u8 div_flags,
108b2155a71SHeiko Stübner 		int gate_offset, u8 gate_shift, u8 gate_flags,
109b2155a71SHeiko Stübner 		unsigned long flags, spinlock_t *lock)
110b2155a71SHeiko Stübner {
111b2155a71SHeiko Stübner 	struct clk *clk;
112b2155a71SHeiko Stübner 	struct clk_gate *gate = NULL;
113b2155a71SHeiko Stübner 	struct clk_fractional_divider *div = NULL;
114b2155a71SHeiko Stübner 	const struct clk_ops *div_ops = NULL, *gate_ops = NULL;
115b2155a71SHeiko Stübner 
116b2155a71SHeiko Stübner 	if (gate_offset >= 0) {
117b2155a71SHeiko Stübner 		gate = kzalloc(sizeof(*gate), GFP_KERNEL);
118b2155a71SHeiko Stübner 		if (!gate)
119b2155a71SHeiko Stübner 			return ERR_PTR(-ENOMEM);
120b2155a71SHeiko Stübner 
121b2155a71SHeiko Stübner 		gate->flags = gate_flags;
122b2155a71SHeiko Stübner 		gate->reg = base + gate_offset;
123b2155a71SHeiko Stübner 		gate->bit_idx = gate_shift;
124b2155a71SHeiko Stübner 		gate->lock = lock;
125b2155a71SHeiko Stübner 		gate_ops = &clk_gate_ops;
126b2155a71SHeiko Stübner 	}
127b2155a71SHeiko Stübner 
128b2155a71SHeiko Stübner 	if (muxdiv_offset < 0)
129b2155a71SHeiko Stübner 		return ERR_PTR(-EINVAL);
130b2155a71SHeiko Stübner 
131b2155a71SHeiko Stübner 	div = kzalloc(sizeof(*div), GFP_KERNEL);
132b2155a71SHeiko Stübner 	if (!div)
133b2155a71SHeiko Stübner 		return ERR_PTR(-ENOMEM);
134b2155a71SHeiko Stübner 
135b2155a71SHeiko Stübner 	div->flags = div_flags;
136b2155a71SHeiko Stübner 	div->reg = base + muxdiv_offset;
137b2155a71SHeiko Stübner 	div->mshift = 16;
1385d49a6e1SAndy Shevchenko 	div->mwidth = 16;
1395d49a6e1SAndy Shevchenko 	div->mmask = GENMASK(div->mwidth - 1, 0) << div->mshift;
140b2155a71SHeiko Stübner 	div->nshift = 0;
1415d49a6e1SAndy Shevchenko 	div->nwidth = 16;
1425d49a6e1SAndy Shevchenko 	div->nmask = GENMASK(div->nwidth - 1, 0) << div->nshift;
143b2155a71SHeiko Stübner 	div->lock = lock;
144b2155a71SHeiko Stübner 	div_ops = &clk_fractional_divider_ops;
145b2155a71SHeiko Stübner 
146b2155a71SHeiko Stübner 	clk = clk_register_composite(NULL, name, parent_names, num_parents,
147b2155a71SHeiko Stübner 				     NULL, NULL,
148b2155a71SHeiko Stübner 				     &div->hw, div_ops,
149b2155a71SHeiko Stübner 				     gate ? &gate->hw : NULL, gate_ops,
150b2155a71SHeiko Stübner 				     flags);
151b2155a71SHeiko Stübner 
152b2155a71SHeiko Stübner 	return clk;
153b2155a71SHeiko Stübner }
154b2155a71SHeiko Stübner 
155a245fecbSHeiko Stübner static DEFINE_SPINLOCK(clk_lock);
156a245fecbSHeiko Stübner static struct clk **clk_table;
157a245fecbSHeiko Stübner static void __iomem *reg_base;
158a245fecbSHeiko Stübner static struct clk_onecell_data clk_data;
15990c59025SHeiko Stübner static struct device_node *cru_node;
16090c59025SHeiko Stübner static struct regmap *grf;
161a245fecbSHeiko Stübner 
162a245fecbSHeiko Stübner void __init rockchip_clk_init(struct device_node *np, void __iomem *base,
163a245fecbSHeiko Stübner 			      unsigned long nr_clks)
164a245fecbSHeiko Stübner {
165a245fecbSHeiko Stübner 	reg_base = base;
16690c59025SHeiko Stübner 	cru_node = np;
16790c59025SHeiko Stübner 	grf = ERR_PTR(-EPROBE_DEFER);
168a245fecbSHeiko Stübner 
169a245fecbSHeiko Stübner 	clk_table = kcalloc(nr_clks, sizeof(struct clk *), GFP_KERNEL);
170a245fecbSHeiko Stübner 	if (!clk_table)
171a245fecbSHeiko Stübner 		pr_err("%s: could not allocate clock lookup table\n", __func__);
172a245fecbSHeiko Stübner 
173a245fecbSHeiko Stübner 	clk_data.clks = clk_table;
174a245fecbSHeiko Stübner 	clk_data.clk_num = nr_clks;
175a245fecbSHeiko Stübner 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
176a245fecbSHeiko Stübner }
177a245fecbSHeiko Stübner 
17890c59025SHeiko Stübner struct regmap *rockchip_clk_get_grf(void)
17990c59025SHeiko Stübner {
18090c59025SHeiko Stübner 	if (IS_ERR(grf))
18190c59025SHeiko Stübner 		grf = syscon_regmap_lookup_by_phandle(cru_node, "rockchip,grf");
18290c59025SHeiko Stübner 	return grf;
18390c59025SHeiko Stübner }
18490c59025SHeiko Stübner 
185a245fecbSHeiko Stübner void rockchip_clk_add_lookup(struct clk *clk, unsigned int id)
186a245fecbSHeiko Stübner {
187a245fecbSHeiko Stübner 	if (clk_table && id)
188a245fecbSHeiko Stübner 		clk_table[id] = clk;
189a245fecbSHeiko Stübner }
190a245fecbSHeiko Stübner 
19190c59025SHeiko Stübner void __init rockchip_clk_register_plls(struct rockchip_pll_clock *list,
19290c59025SHeiko Stübner 				unsigned int nr_pll, int grf_lock_offset)
19390c59025SHeiko Stübner {
19490c59025SHeiko Stübner 	struct clk *clk;
19590c59025SHeiko Stübner 	int idx;
19690c59025SHeiko Stübner 
19790c59025SHeiko Stübner 	for (idx = 0; idx < nr_pll; idx++, list++) {
19890c59025SHeiko Stübner 		clk = rockchip_clk_register_pll(list->type, list->name,
19990c59025SHeiko Stübner 				list->parent_names, list->num_parents,
20090c59025SHeiko Stübner 				reg_base, list->con_offset, grf_lock_offset,
20190c59025SHeiko Stübner 				list->lock_shift, list->mode_offset,
2024f8a7c54SHeiko Stuebner 				list->mode_shift, list->rate_table,
2034f8a7c54SHeiko Stuebner 				list->pll_flags, &clk_lock);
20490c59025SHeiko Stübner 		if (IS_ERR(clk)) {
20590c59025SHeiko Stübner 			pr_err("%s: failed to register clock %s\n", __func__,
20690c59025SHeiko Stübner 				list->name);
20790c59025SHeiko Stübner 			continue;
20890c59025SHeiko Stübner 		}
20990c59025SHeiko Stübner 
21090c59025SHeiko Stübner 		rockchip_clk_add_lookup(clk, list->id);
21190c59025SHeiko Stübner 	}
21290c59025SHeiko Stübner }
21390c59025SHeiko Stübner 
214a245fecbSHeiko Stübner void __init rockchip_clk_register_branches(
215a245fecbSHeiko Stübner 				      struct rockchip_clk_branch *list,
216a245fecbSHeiko Stübner 				      unsigned int nr_clk)
217a245fecbSHeiko Stübner {
218a245fecbSHeiko Stübner 	struct clk *clk = NULL;
219a245fecbSHeiko Stübner 	unsigned int idx;
220a245fecbSHeiko Stübner 	unsigned long flags;
221a245fecbSHeiko Stübner 
222a245fecbSHeiko Stübner 	for (idx = 0; idx < nr_clk; idx++, list++) {
223a245fecbSHeiko Stübner 		flags = list->flags;
224a245fecbSHeiko Stübner 
225a245fecbSHeiko Stübner 		/* catch simple muxes */
226a245fecbSHeiko Stübner 		switch (list->branch_type) {
227a245fecbSHeiko Stübner 		case branch_mux:
228a245fecbSHeiko Stübner 			clk = clk_register_mux(NULL, list->name,
229a245fecbSHeiko Stübner 				list->parent_names, list->num_parents,
230a245fecbSHeiko Stübner 				flags, reg_base + list->muxdiv_offset,
231a245fecbSHeiko Stübner 				list->mux_shift, list->mux_width,
232a245fecbSHeiko Stübner 				list->mux_flags, &clk_lock);
233a245fecbSHeiko Stübner 			break;
234a245fecbSHeiko Stübner 		case branch_divider:
235a245fecbSHeiko Stübner 			if (list->div_table)
236a245fecbSHeiko Stübner 				clk = clk_register_divider_table(NULL,
237a245fecbSHeiko Stübner 					list->name, list->parent_names[0],
238a245fecbSHeiko Stübner 					flags, reg_base + list->muxdiv_offset,
239a245fecbSHeiko Stübner 					list->div_shift, list->div_width,
240a245fecbSHeiko Stübner 					list->div_flags, list->div_table,
241a245fecbSHeiko Stübner 					&clk_lock);
242a245fecbSHeiko Stübner 			else
243a245fecbSHeiko Stübner 				clk = clk_register_divider(NULL, list->name,
244a245fecbSHeiko Stübner 					list->parent_names[0], flags,
245a245fecbSHeiko Stübner 					reg_base + list->muxdiv_offset,
246a245fecbSHeiko Stübner 					list->div_shift, list->div_width,
247a245fecbSHeiko Stübner 					list->div_flags, &clk_lock);
248a245fecbSHeiko Stübner 			break;
249a245fecbSHeiko Stübner 		case branch_fraction_divider:
250b2155a71SHeiko Stübner 			clk = rockchip_clk_register_frac_branch(list->name,
251b2155a71SHeiko Stübner 				list->parent_names, list->num_parents,
252b2155a71SHeiko Stübner 				reg_base, list->muxdiv_offset, list->div_flags,
253b2155a71SHeiko Stübner 				list->gate_offset, list->gate_shift,
254b2155a71SHeiko Stübner 				list->gate_flags, flags, &clk_lock);
255a245fecbSHeiko Stübner 			break;
256a245fecbSHeiko Stübner 		case branch_gate:
257a245fecbSHeiko Stübner 			flags |= CLK_SET_RATE_PARENT;
258a245fecbSHeiko Stübner 
259a245fecbSHeiko Stübner 			clk = clk_register_gate(NULL, list->name,
260a245fecbSHeiko Stübner 				list->parent_names[0], flags,
261a245fecbSHeiko Stübner 				reg_base + list->gate_offset,
262a245fecbSHeiko Stübner 				list->gate_shift, list->gate_flags, &clk_lock);
263a245fecbSHeiko Stübner 			break;
264a245fecbSHeiko Stübner 		case branch_composite:
265a245fecbSHeiko Stübner 			clk = rockchip_clk_register_branch(list->name,
266a245fecbSHeiko Stübner 				list->parent_names, list->num_parents,
267a245fecbSHeiko Stübner 				reg_base, list->muxdiv_offset, list->mux_shift,
268a245fecbSHeiko Stübner 				list->mux_width, list->mux_flags,
269a245fecbSHeiko Stübner 				list->div_shift, list->div_width,
270a245fecbSHeiko Stübner 				list->div_flags, list->div_table,
271a245fecbSHeiko Stübner 				list->gate_offset, list->gate_shift,
272a245fecbSHeiko Stübner 				list->gate_flags, flags, &clk_lock);
273a245fecbSHeiko Stübner 			break;
27489bf26cbSAlexandru M Stan 		case branch_mmc:
27589bf26cbSAlexandru M Stan 			clk = rockchip_clk_register_mmc(
27689bf26cbSAlexandru M Stan 				list->name,
27789bf26cbSAlexandru M Stan 				list->parent_names, list->num_parents,
27889bf26cbSAlexandru M Stan 				reg_base + list->muxdiv_offset,
27989bf26cbSAlexandru M Stan 				list->div_shift
28089bf26cbSAlexandru M Stan 			);
28189bf26cbSAlexandru M Stan 			break;
2828a76f443SHeiko Stuebner 		case branch_inverter:
2838a76f443SHeiko Stuebner 			clk = rockchip_clk_register_inverter(
2848a76f443SHeiko Stuebner 				list->name, list->parent_names,
2858a76f443SHeiko Stuebner 				list->num_parents,
2868a76f443SHeiko Stuebner 				reg_base + list->muxdiv_offset,
2878a76f443SHeiko Stuebner 				list->div_shift, list->div_flags, &clk_lock);
2888a76f443SHeiko Stuebner 			break;
289a245fecbSHeiko Stübner 		}
290a245fecbSHeiko Stübner 
291a245fecbSHeiko Stübner 		/* none of the cases above matched */
292a245fecbSHeiko Stübner 		if (!clk) {
293a245fecbSHeiko Stübner 			pr_err("%s: unknown clock type %d\n",
294a245fecbSHeiko Stübner 			       __func__, list->branch_type);
295a245fecbSHeiko Stübner 			continue;
296a245fecbSHeiko Stübner 		}
297a245fecbSHeiko Stübner 
298a245fecbSHeiko Stübner 		if (IS_ERR(clk)) {
299a245fecbSHeiko Stübner 			pr_err("%s: failed to register clock %s: %ld\n",
300a245fecbSHeiko Stübner 			       __func__, list->name, PTR_ERR(clk));
301a245fecbSHeiko Stübner 			continue;
302a245fecbSHeiko Stübner 		}
303a245fecbSHeiko Stübner 
304a245fecbSHeiko Stübner 		rockchip_clk_add_lookup(clk, list->id);
305a245fecbSHeiko Stübner 	}
306a245fecbSHeiko Stübner }
307fe94f974SHeiko Stübner 
308f6fba5f6SHeiko Stuebner void __init rockchip_clk_register_armclk(unsigned int lookup_id,
3094a1caed3SUwe Kleine-König 			const char *name, const char *const *parent_names,
310f6fba5f6SHeiko Stuebner 			u8 num_parents,
311f6fba5f6SHeiko Stuebner 			const struct rockchip_cpuclk_reg_data *reg_data,
312f6fba5f6SHeiko Stuebner 			const struct rockchip_cpuclk_rate_table *rates,
313f6fba5f6SHeiko Stuebner 			int nrates)
314f6fba5f6SHeiko Stuebner {
315f6fba5f6SHeiko Stuebner 	struct clk *clk;
316f6fba5f6SHeiko Stuebner 
317f6fba5f6SHeiko Stuebner 	clk = rockchip_clk_register_cpuclk(name, parent_names, num_parents,
318f6fba5f6SHeiko Stuebner 					   reg_data, rates, nrates, reg_base,
319f6fba5f6SHeiko Stuebner 					   &clk_lock);
320f6fba5f6SHeiko Stuebner 	if (IS_ERR(clk)) {
321f6fba5f6SHeiko Stuebner 		pr_err("%s: failed to register clock %s: %ld\n",
322f6fba5f6SHeiko Stuebner 		       __func__, name, PTR_ERR(clk));
323f6fba5f6SHeiko Stuebner 		return;
324f6fba5f6SHeiko Stuebner 	}
325f6fba5f6SHeiko Stuebner 
326f6fba5f6SHeiko Stuebner 	rockchip_clk_add_lookup(clk, lookup_id);
327f6fba5f6SHeiko Stuebner }
328f6fba5f6SHeiko Stuebner 
329692d8328SUwe Kleine-König void __init rockchip_clk_protect_critical(const char *const clocks[],
330692d8328SUwe Kleine-König 					  int nclocks)
331fe94f974SHeiko Stübner {
332fe94f974SHeiko Stübner 	int i;
333fe94f974SHeiko Stübner 
334fe94f974SHeiko Stübner 	/* Protect the clocks that needs to stay on */
335fe94f974SHeiko Stübner 	for (i = 0; i < nclocks; i++) {
336fe94f974SHeiko Stübner 		struct clk *clk = __clk_lookup(clocks[i]);
337fe94f974SHeiko Stübner 
338fe94f974SHeiko Stübner 		if (clk)
339fe94f974SHeiko Stübner 			clk_prepare_enable(clk);
340fe94f974SHeiko Stübner 	}
341fe94f974SHeiko Stübner }
3426f1294b5SHeiko Stübner 
3436f1294b5SHeiko Stübner static unsigned int reg_restart;
344*dfff24bdSHeiko Stuebner static void (*cb_restart)(void);
3456f1294b5SHeiko Stübner static int rockchip_restart_notify(struct notifier_block *this,
3466f1294b5SHeiko Stübner 				   unsigned long mode, void *cmd)
3476f1294b5SHeiko Stübner {
348*dfff24bdSHeiko Stuebner 	if (cb_restart)
349*dfff24bdSHeiko Stuebner 		cb_restart();
350*dfff24bdSHeiko Stuebner 
3516f1294b5SHeiko Stübner 	writel(0xfdb9, reg_base + reg_restart);
3526f1294b5SHeiko Stübner 	return NOTIFY_DONE;
3536f1294b5SHeiko Stübner }
3546f1294b5SHeiko Stübner 
3556f1294b5SHeiko Stübner static struct notifier_block rockchip_restart_handler = {
3566f1294b5SHeiko Stübner 	.notifier_call = rockchip_restart_notify,
3576f1294b5SHeiko Stübner 	.priority = 128,
3586f1294b5SHeiko Stübner };
3596f1294b5SHeiko Stübner 
360*dfff24bdSHeiko Stuebner void __init rockchip_register_restart_notifier(unsigned int reg, void (*cb)(void))
3616f1294b5SHeiko Stübner {
3626f1294b5SHeiko Stübner 	int ret;
3636f1294b5SHeiko Stübner 
3646f1294b5SHeiko Stübner 	reg_restart = reg;
365*dfff24bdSHeiko Stuebner 	cb_restart = cb;
3666f1294b5SHeiko Stübner 	ret = register_restart_handler(&rockchip_restart_handler);
3676f1294b5SHeiko Stübner 	if (ret)
3686f1294b5SHeiko Stübner 		pr_err("%s: cannot register restart handler, %d\n",
3696f1294b5SHeiko Stübner 		       __func__, ret);
3706f1294b5SHeiko Stübner }
371