31290195b89391a2791be3ea2be2d7baf51881de
[openwrt/openwrt.git] / target / linux / lantiq / patches-3.18 / 0005-MIPS-lantiq-add-reset-controller-api-support.patch
1 From 223f1c46e109a8420765aee099a5d1dc4ab7ee98 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Tue, 3 Sep 2013 13:18:12 +0200
4 Subject: [PATCH 05/36] MIPS: lantiq: add reset-controller api support
5
6 Add a reset-controller binding for the reset registers found on the lantiq
7 SoC.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 ---
11 arch/mips/lantiq/xway/reset.c | 61 +++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 61 insertions(+)
13
14 --- a/arch/mips/lantiq/xway/reset.c
15 +++ b/arch/mips/lantiq/xway/reset.c
16 @@ -14,6 +14,7 @@
17 #include <linux/delay.h>
18 #include <linux/of_address.h>
19 #include <linux/of_platform.h>
20 +#include <linux/reset-controller.h>
21
22 #include <asm/reboot.h>
23
24 @@ -113,6 +114,66 @@ void ltq_reset_once(unsigned int module,
25 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
26 }
27
28 +static int ltq_assert_device(struct reset_controller_dev *rcdev,
29 + unsigned long id)
30 +{
31 + u32 val;
32 +
33 + if (id < 8)
34 + return -1;
35 +
36 + val = ltq_rcu_r32(RCU_RST_REQ);
37 + val |= BIT(id);
38 + ltq_rcu_w32(val, RCU_RST_REQ);
39 +
40 + return 0;
41 +}
42 +
43 +static int ltq_deassert_device(struct reset_controller_dev *rcdev,
44 + unsigned long id)
45 +{
46 + u32 val;
47 +
48 + if (id < 8)
49 + return -1;
50 +
51 + val = ltq_rcu_r32(RCU_RST_REQ);
52 + val &= ~BIT(id);
53 + ltq_rcu_w32(val, RCU_RST_REQ);
54 +
55 + return 0;
56 +}
57 +
58 +static int ltq_reset_device(struct reset_controller_dev *rcdev,
59 + unsigned long id)
60 +{
61 + ltq_assert_device(rcdev, id);
62 + return ltq_deassert_device(rcdev, id);
63 +}
64 +
65 +static struct reset_control_ops reset_ops = {
66 + .reset = ltq_reset_device,
67 + .assert = ltq_assert_device,
68 + .deassert = ltq_deassert_device,
69 +};
70 +
71 +static struct reset_controller_dev reset_dev = {
72 + .ops = &reset_ops,
73 + .owner = THIS_MODULE,
74 + .nr_resets = 32,
75 + .of_reset_n_cells = 1,
76 +};
77 +
78 +void ltq_rst_init(void)
79 +{
80 + reset_dev.of_node = of_find_compatible_node(NULL, NULL,
81 + "lantiq,xway-reset");
82 + if (!reset_dev.of_node)
83 + pr_err("Failed to find reset controller node");
84 + else
85 + reset_controller_register(&reset_dev);
86 +}
87 +
88 static void ltq_machine_restart(char *command)
89 {
90 local_irq_disable();