blob: 9d56606ac87f3268644351959eb15e340bdcb4b3 [file] [log] [blame]
Thomas Gleixnera636cd62019-05-19 15:51:34 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Binghua Duan02c981c2011-07-08 17:40:12 +08002/*
3 * reset controller for CSR SiRFprimaII
4 *
5 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
Binghua Duan02c981c2011-07-08 17:40:12 +08006 */
7
8#include <linux/kernel.h>
9#include <linux/mutex.h>
10#include <linux/io.h>
11#include <linux/delay.h>
12#include <linux/device.h>
13#include <linux/of.h>
14#include <linux/of_address.h>
Barry Songe7eda912014-01-10 03:15:42 +000015#include <linux/platform_device.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070016#include <linux/reboot.h>
Barry Songe7eda912014-01-10 03:15:42 +000017#include <linux/reset-controller.h>
18
Arnd Bergmann48352e52014-03-11 10:53:31 +010019#include <asm/system_misc.h>
20
Barry Songe7eda912014-01-10 03:15:42 +000021#define SIRFSOC_RSTBIT_NUM 64
Binghua Duan02c981c2011-07-08 17:40:12 +080022
Arnd Bergmann48352e52014-03-11 10:53:31 +010023static void __iomem *sirfsoc_rstc_base;
Binghua Duan02c981c2011-07-08 17:40:12 +080024static DEFINE_MUTEX(rstc_lock);
25
Barry Songe7eda912014-01-10 03:15:42 +000026static int sirfsoc_reset_module(struct reset_controller_dev *rcdev,
27 unsigned long sw_reset_idx)
Binghua Duan02c981c2011-07-08 17:40:12 +080028{
Barry Songe7eda912014-01-10 03:15:42 +000029 u32 reset_bit = sw_reset_idx;
Binghua Duan02c981c2011-07-08 17:40:12 +080030
Barry Songe7eda912014-01-10 03:15:42 +000031 if (reset_bit >= SIRFSOC_RSTBIT_NUM)
Barry Song0ecb40c2012-12-20 17:40:47 +080032 return -EINVAL;
Binghua Duan02c981c2011-07-08 17:40:12 +080033
34 mutex_lock(&rstc_lock);
35
Barry Songe664c3f2015-01-04 14:48:20 +080036 /*
37 * Writing 1 to this bit resets corresponding block.
38 * Writing 0 to this bit de-asserts reset signal of the
39 * corresponding block. datasheet doesn't require explicit
40 * delay between the set and clear of reset bit. it could
41 * be shorter if tests pass.
42 */
43 writel(readl(sirfsoc_rstc_base +
Xianglong Dua2a25682014-05-07 15:08:21 +080044 (reset_bit / 32) * 4) | (1 << reset_bit),
Barry Songe664c3f2015-01-04 14:48:20 +080045 sirfsoc_rstc_base + (reset_bit / 32) * 4);
46 msleep(20);
47 writel(readl(sirfsoc_rstc_base +
Xianglong Dua2a25682014-05-07 15:08:21 +080048 (reset_bit / 32) * 4) & ~(1 << reset_bit),
Barry Songe664c3f2015-01-04 14:48:20 +080049 sirfsoc_rstc_base + (reset_bit / 32) * 4);
Binghua Duan02c981c2011-07-08 17:40:12 +080050
51 mutex_unlock(&rstc_lock);
52
53 return 0;
54}
Russell King125c4032011-11-05 10:23:27 +000055
Barry Songe7eda912014-01-10 03:15:42 +000056static struct reset_control_ops sirfsoc_rstc_ops = {
57 .reset = sirfsoc_reset_module,
58};
59
60static struct reset_controller_dev sirfsoc_reset_controller = {
61 .ops = &sirfsoc_rstc_ops,
62 .nr_resets = SIRFSOC_RSTBIT_NUM,
63};
64
Arnd Bergmann48352e52014-03-11 10:53:31 +010065#define SIRFSOC_SYS_RST_BIT BIT(31)
66
67static void sirfsoc_restart(enum reboot_mode mode, const char *cmd)
68{
69 writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
70}
71
Barry Songe7eda912014-01-10 03:15:42 +000072static int sirfsoc_rstc_probe(struct platform_device *pdev)
73{
74 struct device_node *np = pdev->dev.of_node;
75 sirfsoc_rstc_base = of_iomap(np, 0);
76 if (!sirfsoc_rstc_base) {
77 dev_err(&pdev->dev, "unable to map rstc cpu registers\n");
78 return -ENOMEM;
79 }
80
81 sirfsoc_reset_controller.of_node = np;
Arnd Bergmann48352e52014-03-11 10:53:31 +010082 arm_pm_restart = sirfsoc_restart;
Barry Songe7eda912014-01-10 03:15:42 +000083
Arnd Bergmann48352e52014-03-11 10:53:31 +010084 if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
85 reset_controller_register(&sirfsoc_reset_controller);
Barry Songe7eda912014-01-10 03:15:42 +000086
87 return 0;
88}
89
90static const struct of_device_id rstc_ids[] = {
91 { .compatible = "sirf,prima2-rstc" },
Barry Songe7eda912014-01-10 03:15:42 +000092 {},
93};
94
95static struct platform_driver sirfsoc_rstc_driver = {
96 .probe = sirfsoc_rstc_probe,
97 .driver = {
98 .name = "sirfsoc_rstc",
Barry Songe7eda912014-01-10 03:15:42 +000099 .of_match_table = rstc_ids,
100 },
101};
102
103static int __init sirfsoc_rstc_init(void)
104{
105 return platform_driver_register(&sirfsoc_rstc_driver);
106}
107subsys_initcall(sirfsoc_rstc_init);