blob: 7c251eb11d012616a4c9ee75fc7af70120f6e99a [file] [log] [blame]
Binghua Duan02c981c2011-07-08 17:40:12 +08001/*
2 * reset controller for CSR SiRFprimaII
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/kernel.h>
10#include <linux/mutex.h>
11#include <linux/io.h>
12#include <linux/delay.h>
13#include <linux/device.h>
14#include <linux/of.h>
15#include <linux/of_address.h>
Barry Songe7eda912014-01-10 03:15:42 +000016#include <linux/platform_device.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070017#include <linux/reboot.h>
Barry Songe7eda912014-01-10 03:15:42 +000018#include <linux/reset-controller.h>
19
Arnd Bergmann48352e52014-03-11 10:53:31 +010020#include <asm/system_misc.h>
21
Barry Songe7eda912014-01-10 03:15:42 +000022#define SIRFSOC_RSTBIT_NUM 64
Binghua Duan02c981c2011-07-08 17:40:12 +080023
Arnd Bergmann48352e52014-03-11 10:53:31 +010024static void __iomem *sirfsoc_rstc_base;
Binghua Duan02c981c2011-07-08 17:40:12 +080025static DEFINE_MUTEX(rstc_lock);
26
Barry Songe7eda912014-01-10 03:15:42 +000027static int sirfsoc_reset_module(struct reset_controller_dev *rcdev,
28 unsigned long sw_reset_idx)
Binghua Duan02c981c2011-07-08 17:40:12 +080029{
Barry Songe7eda912014-01-10 03:15:42 +000030 u32 reset_bit = sw_reset_idx;
Binghua Duan02c981c2011-07-08 17:40:12 +080031
Barry Songe7eda912014-01-10 03:15:42 +000032 if (reset_bit >= SIRFSOC_RSTBIT_NUM)
Barry Song0ecb40c2012-12-20 17:40:47 +080033 return -EINVAL;
Binghua Duan02c981c2011-07-08 17:40:12 +080034
35 mutex_lock(&rstc_lock);
36
Barry Songe664c3f2015-01-04 14:48:20 +080037 /*
38 * Writing 1 to this bit resets corresponding block.
39 * Writing 0 to this bit de-asserts reset signal of the
40 * corresponding block. datasheet doesn't require explicit
41 * delay between the set and clear of reset bit. it could
42 * be shorter if tests pass.
43 */
44 writel(readl(sirfsoc_rstc_base +
Xianglong Dua2a25682014-05-07 15:08:21 +080045 (reset_bit / 32) * 4) | (1 << reset_bit),
Barry Songe664c3f2015-01-04 14:48:20 +080046 sirfsoc_rstc_base + (reset_bit / 32) * 4);
47 msleep(20);
48 writel(readl(sirfsoc_rstc_base +
Xianglong Dua2a25682014-05-07 15:08:21 +080049 (reset_bit / 32) * 4) & ~(1 << reset_bit),
Barry Songe664c3f2015-01-04 14:48:20 +080050 sirfsoc_rstc_base + (reset_bit / 32) * 4);
Binghua Duan02c981c2011-07-08 17:40:12 +080051
52 mutex_unlock(&rstc_lock);
53
54 return 0;
55}
Russell King125c4032011-11-05 10:23:27 +000056
Barry Songe7eda912014-01-10 03:15:42 +000057static struct reset_control_ops sirfsoc_rstc_ops = {
58 .reset = sirfsoc_reset_module,
59};
60
61static struct reset_controller_dev sirfsoc_reset_controller = {
62 .ops = &sirfsoc_rstc_ops,
63 .nr_resets = SIRFSOC_RSTBIT_NUM,
64};
65
Arnd Bergmann48352e52014-03-11 10:53:31 +010066#define SIRFSOC_SYS_RST_BIT BIT(31)
67
68static void sirfsoc_restart(enum reboot_mode mode, const char *cmd)
69{
70 writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
71}
72
Barry Songe7eda912014-01-10 03:15:42 +000073static int sirfsoc_rstc_probe(struct platform_device *pdev)
74{
75 struct device_node *np = pdev->dev.of_node;
76 sirfsoc_rstc_base = of_iomap(np, 0);
77 if (!sirfsoc_rstc_base) {
78 dev_err(&pdev->dev, "unable to map rstc cpu registers\n");
79 return -ENOMEM;
80 }
81
82 sirfsoc_reset_controller.of_node = np;
Arnd Bergmann48352e52014-03-11 10:53:31 +010083 arm_pm_restart = sirfsoc_restart;
Barry Songe7eda912014-01-10 03:15:42 +000084
Arnd Bergmann48352e52014-03-11 10:53:31 +010085 if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
86 reset_controller_register(&sirfsoc_reset_controller);
Barry Songe7eda912014-01-10 03:15:42 +000087
88 return 0;
89}
90
91static const struct of_device_id rstc_ids[] = {
92 { .compatible = "sirf,prima2-rstc" },
Barry Songe7eda912014-01-10 03:15:42 +000093 {},
94};
95
96static struct platform_driver sirfsoc_rstc_driver = {
97 .probe = sirfsoc_rstc_probe,
98 .driver = {
99 .name = "sirfsoc_rstc",
Barry Songe7eda912014-01-10 03:15:42 +0000100 .of_match_table = rstc_ids,
101 },
102};
103
104static int __init sirfsoc_rstc_init(void)
105{
106 return platform_driver_register(&sirfsoc_rstc_driver);
107}
108subsys_initcall(sirfsoc_rstc_init);