diff options
Diffstat (limited to 'arch/arm/mach-prima2/rstc.c')
-rw-r--r-- | arch/arm/mach-prima2/rstc.c | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/arch/arm/mach-prima2/rstc.c b/arch/arm/mach-prima2/rstc.c index ccb53391147a..4887a2a4c698 100644 --- a/arch/arm/mach-prima2/rstc.c +++ b/arch/arm/mach-prima2/rstc.c | |||
@@ -13,57 +13,38 @@ | |||
13 | #include <linux/device.h> | 13 | #include <linux/device.h> |
14 | #include <linux/of.h> | 14 | #include <linux/of.h> |
15 | #include <linux/of_address.h> | 15 | #include <linux/of_address.h> |
16 | #include <linux/platform_device.h> | ||
16 | #include <linux/reboot.h> | 17 | #include <linux/reboot.h> |
18 | #include <linux/reset-controller.h> | ||
17 | 19 | ||
18 | void __iomem *sirfsoc_rstc_base; | 20 | #include <asm/system_misc.h> |
19 | static DEFINE_MUTEX(rstc_lock); | ||
20 | |||
21 | static struct of_device_id rstc_ids[] = { | ||
22 | { .compatible = "sirf,prima2-rstc" }, | ||
23 | { .compatible = "sirf,marco-rstc" }, | ||
24 | {}, | ||
25 | }; | ||
26 | 21 | ||
27 | static int __init sirfsoc_of_rstc_init(void) | 22 | #define SIRFSOC_RSTBIT_NUM 64 |
28 | { | ||
29 | struct device_node *np; | ||
30 | 23 | ||
31 | np = of_find_matching_node(NULL, rstc_ids); | 24 | static void __iomem *sirfsoc_rstc_base; |
32 | if (!np) { | 25 | static DEFINE_MUTEX(rstc_lock); |
33 | pr_err("unable to find compatible sirf rstc node in dtb\n"); | ||
34 | return -ENOENT; | ||
35 | } | ||
36 | |||
37 | sirfsoc_rstc_base = of_iomap(np, 0); | ||
38 | if (!sirfsoc_rstc_base) | ||
39 | panic("unable to map rstc cpu registers\n"); | ||
40 | |||
41 | of_node_put(np); | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | early_initcall(sirfsoc_of_rstc_init); | ||
46 | 26 | ||
47 | int sirfsoc_reset_device(struct device *dev) | 27 | static int sirfsoc_reset_module(struct reset_controller_dev *rcdev, |
28 | unsigned long sw_reset_idx) | ||
48 | { | 29 | { |
49 | u32 reset_bit; | 30 | u32 reset_bit = sw_reset_idx; |
50 | 31 | ||
51 | if (of_property_read_u32(dev->of_node, "reset-bit", &reset_bit)) | 32 | if (reset_bit >= SIRFSOC_RSTBIT_NUM) |
52 | return -EINVAL; | 33 | return -EINVAL; |
53 | 34 | ||
54 | mutex_lock(&rstc_lock); | 35 | mutex_lock(&rstc_lock); |
55 | 36 | ||
56 | if (of_device_is_compatible(dev->of_node, "sirf,prima2-rstc")) { | 37 | if (of_device_is_compatible(rcdev->of_node, "sirf,prima2-rstc")) { |
57 | /* | 38 | /* |
58 | * Writing 1 to this bit resets corresponding block. Writing 0 to this | 39 | * Writing 1 to this bit resets corresponding block. Writing 0 to this |
59 | * bit de-asserts reset signal of the corresponding block. | 40 | * bit de-asserts reset signal of the corresponding block. |
60 | * datasheet doesn't require explicit delay between the set and clear | 41 | * datasheet doesn't require explicit delay between the set and clear |
61 | * of reset bit. it could be shorter if tests pass. | 42 | * of reset bit. it could be shorter if tests pass. |
62 | */ | 43 | */ |
63 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) | reset_bit, | 44 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) | (1 << reset_bit), |
64 | sirfsoc_rstc_base + (reset_bit / 32) * 4); | 45 | sirfsoc_rstc_base + (reset_bit / 32) * 4); |
65 | msleep(10); | 46 | msleep(10); |
66 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) & ~reset_bit, | 47 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) & ~(1 << reset_bit), |
67 | sirfsoc_rstc_base + (reset_bit / 32) * 4); | 48 | sirfsoc_rstc_base + (reset_bit / 32) * 4); |
68 | } else { | 49 | } else { |
69 | /* | 50 | /* |
@@ -73,9 +54,9 @@ int sirfsoc_reset_device(struct device *dev) | |||
73 | * datasheet doesn't require explicit delay between the set and clear | 54 | * datasheet doesn't require explicit delay between the set and clear |
74 | * of reset bit. it could be shorter if tests pass. | 55 | * of reset bit. it could be shorter if tests pass. |
75 | */ | 56 | */ |
76 | writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8); | 57 | writel(1 << reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8); |
77 | msleep(10); | 58 | msleep(10); |
78 | writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8 + 4); | 59 | writel(1 << reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8 + 4); |
79 | } | 60 | } |
80 | 61 | ||
81 | mutex_unlock(&rstc_lock); | 62 | mutex_unlock(&rstc_lock); |
@@ -83,9 +64,57 @@ int sirfsoc_reset_device(struct device *dev) | |||
83 | return 0; | 64 | return 0; |
84 | } | 65 | } |
85 | 66 | ||
67 | static struct reset_control_ops sirfsoc_rstc_ops = { | ||
68 | .reset = sirfsoc_reset_module, | ||
69 | }; | ||
70 | |||
71 | static struct reset_controller_dev sirfsoc_reset_controller = { | ||
72 | .ops = &sirfsoc_rstc_ops, | ||
73 | .nr_resets = SIRFSOC_RSTBIT_NUM, | ||
74 | }; | ||
75 | |||
86 | #define SIRFSOC_SYS_RST_BIT BIT(31) | 76 | #define SIRFSOC_SYS_RST_BIT BIT(31) |
87 | 77 | ||
88 | void sirfsoc_restart(enum reboot_mode mode, const char *cmd) | 78 | static void sirfsoc_restart(enum reboot_mode mode, const char *cmd) |
89 | { | 79 | { |
90 | writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base); | 80 | writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base); |
91 | } | 81 | } |
82 | |||
83 | static int sirfsoc_rstc_probe(struct platform_device *pdev) | ||
84 | { | ||
85 | struct device_node *np = pdev->dev.of_node; | ||
86 | sirfsoc_rstc_base = of_iomap(np, 0); | ||
87 | if (!sirfsoc_rstc_base) { | ||
88 | dev_err(&pdev->dev, "unable to map rstc cpu registers\n"); | ||
89 | return -ENOMEM; | ||
90 | } | ||
91 | |||
92 | sirfsoc_reset_controller.of_node = np; | ||
93 | arm_pm_restart = sirfsoc_restart; | ||
94 | |||
95 | if (IS_ENABLED(CONFIG_RESET_CONTROLLER)) | ||
96 | reset_controller_register(&sirfsoc_reset_controller); | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | static const struct of_device_id rstc_ids[] = { | ||
102 | { .compatible = "sirf,prima2-rstc" }, | ||
103 | { .compatible = "sirf,marco-rstc" }, | ||
104 | {}, | ||
105 | }; | ||
106 | |||
107 | static struct platform_driver sirfsoc_rstc_driver = { | ||
108 | .probe = sirfsoc_rstc_probe, | ||
109 | .driver = { | ||
110 | .name = "sirfsoc_rstc", | ||
111 | .owner = THIS_MODULE, | ||
112 | .of_match_table = rstc_ids, | ||
113 | }, | ||
114 | }; | ||
115 | |||
116 | static int __init sirfsoc_rstc_init(void) | ||
117 | { | ||
118 | return platform_driver_register(&sirfsoc_rstc_driver); | ||
119 | } | ||
120 | subsys_initcall(sirfsoc_rstc_init); | ||