kernel: update 3.10 to 3.10.2
[openwrt/svn-archive/archive.git] / target / linux / ramips / patches-3.10 / 0028-reset-MIPS-ralink-add-core-device-reset-wrapper.patch
1 From 0cc20912b376305452cdc5c8e7b97e156ba90e93 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 28/33] 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 --- a/arch/mips/Kconfig
16 +++ b/arch/mips/Kconfig
17 @@ -444,6 +444,7 @@ config RALINK
18 select HAVE_MACH_CLKDEV
19 select CLKDEV_LOOKUP
20 select ARCH_REQUIRE_GPIOLIB
21 + select ARCH_HAS_RESET_CONTROLLER
22
23 config SGI_IP22
24 bool "SGI IP22 (Indy/Indigo2)"
25 --- a/arch/mips/ralink/of.c
26 +++ b/arch/mips/ralink/of.c
27 @@ -14,16 +14,22 @@
28 #include <linux/sizes.h>
29 #include <linux/of_fdt.h>
30 #include <linux/kernel.h>
31 +#include <linux/module.h>
32 #include <linux/bootmem.h>
33 #include <linux/of_platform.h>
34 #include <linux/of_address.h>
35 +#include <linux/reset-controller.h>
36
37 #include <asm/reboot.h>
38 #include <asm/bootinfo.h>
39 #include <asm/addrspace.h>
40
41 +#include <asm/mach-ralink/ralink_regs.h>
42 +
43 #include "common.h"
44
45 +#define SYSC_REG_RESET_CTRL 0x034
46 +
47 __iomem void *rt_sysc_membase;
48 __iomem void *rt_memc_membase;
49
50 @@ -96,6 +102,53 @@ void __init plat_mem_setup(void)
51 soc_info.mem_size_max * SZ_1M);
52 }
53
54 +static int ralink_assert_device(struct reset_controller_dev *rcdev, unsigned long id)
55 +{
56 + u32 val;
57 +
58 + if (id < 8)
59 + return -1;
60 +
61 + val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
62 + val |= BIT(id);
63 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
64 +
65 + return 0;
66 +}
67 +
68 +static int ralink_deassert_device(struct reset_controller_dev *rcdev, unsigned long id)
69 +{
70 + u32 val;
71 +
72 + if (id < 8)
73 + return -1;
74 +
75 + val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
76 + val &= ~BIT(id);
77 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
78 +
79 + return 0;
80 +}
81 +
82 +static int ralink_reset_device(struct reset_controller_dev *rcdev, unsigned long id)
83 +{
84 + ralink_assert_device(rcdev, id);
85 + return ralink_deassert_device(rcdev, id);
86 +}
87 +
88 +static struct reset_control_ops reset_ops = {
89 + .reset = ralink_reset_device,
90 + .assert = ralink_assert_device,
91 + .deassert = ralink_deassert_device,
92 +};
93 +
94 +static struct reset_controller_dev reset_dev = {
95 + .ops = &reset_ops,
96 + .owner = THIS_MODULE,
97 + .nr_resets = 32,
98 + .of_reset_n_cells = 1,
99 +};
100 +
101 static int __init plat_of_setup(void)
102 {
103 static struct of_device_id of_ids[3];
104 @@ -110,6 +163,12 @@ static int __init plat_of_setup(void)
105 if (of_platform_populate(NULL, of_ids, NULL, NULL))
106 panic("failed to populate DT\n");
107
108 + reset_dev.of_node = of_find_compatible_node(NULL, NULL, "ralink,rt2880-reset");
109 + if (!reset_dev.of_node)
110 + panic("Failed to find reset controller node");
111 +
112 + reset_controller_register(&reset_dev);
113 +
114 ralink_pinmux();
115
116 return 0;
117 --- a/arch/mips/ralink/reset.c
118 +++ b/arch/mips/ralink/reset.c
119 @@ -10,6 +10,7 @@
120
121 #include <linux/pm.h>
122 #include <linux/io.h>
123 +#include <linux/module.h>
124
125 #include <asm/reboot.h>
126