a22cfc8020b6fb232dbae0043fbaa17708bae4a0
[openwrt/svn-archive/archive.git] / target / linux / ramips / patches-3.9 / 0155-reset-MIPS-ralink-add-core-device-reset-wrapper.patch
1 From 4bec674c9f3f0bc137cf5aa4d2cb01e9f8027b3d Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 8 May 2013 22:08:39 +0200
4 Subject: [PATCH 155/164] reset: MIPS: ralink: add core/device reset wrapper
5
6 Add a helper for reseting different devices ont he SoC.
7
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 ---
10 arch/mips/Kconfig | 1 +
11 arch/mips/ralink/of.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
12 arch/mips/ralink/reset.c | 1 +
13 3 files changed, 61 insertions(+)
14
15 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
16 index b237c50..cfc7153 100644
17 --- a/arch/mips/Kconfig
18 +++ b/arch/mips/Kconfig
19 @@ -444,6 +444,7 @@ config RALINK
20 select HAVE_MACH_CLKDEV
21 select CLKDEV_LOOKUP
22 select ARCH_REQUIRE_GPIOLIB
23 + select ARCH_HAS_RESET_CONTROLLER
24
25 config SGI_IP22
26 bool "SGI IP22 (Indy/Indigo2)"
27 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
28 index 8efb02b..2faf478 100644
29 --- a/arch/mips/ralink/of.c
30 +++ b/arch/mips/ralink/of.c
31 @@ -14,16 +14,22 @@
32 #include <linux/sizes.h>
33 #include <linux/of_fdt.h>
34 #include <linux/kernel.h>
35 +#include <linux/module.h>
36 #include <linux/bootmem.h>
37 #include <linux/of_platform.h>
38 #include <linux/of_address.h>
39 +#include <linux/reset-controller.h>
40
41 #include <asm/reboot.h>
42 #include <asm/bootinfo.h>
43 #include <asm/addrspace.h>
44
45 +#include <asm/mach-ralink/ralink_regs.h>
46 +
47 #include "common.h"
48
49 +#define SYSC_REG_RESET_CTRL 0x034
50 +
51 __iomem void *rt_sysc_membase;
52 __iomem void *rt_memc_membase;
53
54 @@ -96,6 +102,53 @@ void __init plat_mem_setup(void)
55 soc_info.mem_size_max * SZ_1M);
56 }
57
58 +static int ralink_assert_device(struct reset_controller_dev *rcdev, unsigned long id)
59 +{
60 + u32 val;
61 +
62 + if (id < 8)
63 + return -1;
64 +
65 + val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
66 + val |= BIT(id);
67 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
68 +
69 + return 0;
70 +}
71 +
72 +static int ralink_deassert_device(struct reset_controller_dev *rcdev, unsigned long id)
73 +{
74 + u32 val;
75 +
76 + if (id < 8)
77 + return -1;
78 +
79 + val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
80 + val &= ~BIT(id);
81 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
82 +
83 + return 0;
84 +}
85 +
86 +static int ralink_reset_device(struct reset_controller_dev *rcdev, unsigned long id)
87 +{
88 + ralink_assert_device(rcdev, id);
89 + return ralink_deassert_device(rcdev, id);
90 +}
91 +
92 +static struct reset_control_ops reset_ops = {
93 + .reset = ralink_reset_device,
94 + .assert = ralink_assert_device,
95 + .deassert = ralink_deassert_device,
96 +};
97 +
98 +static struct reset_controller_dev reset_dev = {
99 + .ops = &reset_ops,
100 + .owner = THIS_MODULE,
101 + .nr_resets = 32,
102 + .of_reset_n_cells = 1,
103 +};
104 +
105 static int __init plat_of_setup(void)
106 {
107 static struct of_device_id of_ids[3];
108 @@ -110,6 +163,12 @@ static int __init plat_of_setup(void)
109 if (of_platform_populate(NULL, of_ids, NULL, NULL))
110 panic("failed to populate DT\n");
111
112 + reset_dev.of_node = of_find_compatible_node(NULL, NULL, "ralink,rt2880-reset");
113 + if (!reset_dev.of_node)
114 + panic("Failed to find reset controller node");
115 +
116 + reset_controller_register(&reset_dev);
117 +
118 ralink_pinmux();
119
120 return 0;
121 diff --git a/arch/mips/ralink/reset.c b/arch/mips/ralink/reset.c
122 index 22120e5..6c15f4f 100644
123 --- a/arch/mips/ralink/reset.c
124 +++ b/arch/mips/ralink/reset.c
125 @@ -10,6 +10,7 @@
126
127 #include <linux/pm.h>
128 #include <linux/io.h>
129 +#include <linux/module.h>
130
131 #include <asm/reboot.h>
132
133 --
134 1.7.10.4
135