1 /*
2 * Copyright (C) 2016 Broadcom
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14 #include <linux/io.h>
15 #include <linux/of_address.h>
16 #include <linux/of_platform.h>
17 #include <linux/reboot.h>
18
19 #define RSTMGR_REG_WR_ACCESS_OFFSET 0
20 #define RSTMGR_REG_CHIP_SOFT_RST_OFFSET 4
21
22 #define RSTMGR_WR_PASSWORD 0xa5a5
23 #define RSTMGR_WR_PASSWORD_SHIFT 8
24 #define RSTMGR_WR_ACCESS_ENABLE 1
25
26 static void __iomem *kona_reset_base;
27
kona_reset_handler(struct notifier_block * this,unsigned long mode,void * cmd)28 static int kona_reset_handler(struct notifier_block *this,
29 unsigned long mode, void *cmd)
30 {
31 /*
32 * A soft reset is triggered by writing a 0 to bit 0 of the soft reset
33 * register. To write to that register we must first write the password
34 * and the enable bit in the write access enable register.
35 */
36 writel((RSTMGR_WR_PASSWORD << RSTMGR_WR_PASSWORD_SHIFT) |
37 RSTMGR_WR_ACCESS_ENABLE,
38 kona_reset_base + RSTMGR_REG_WR_ACCESS_OFFSET);
39 writel(0, kona_reset_base + RSTMGR_REG_CHIP_SOFT_RST_OFFSET);
40
41 return NOTIFY_DONE;
42 }
43
44 static struct notifier_block kona_reset_nb = {
45 .notifier_call = kona_reset_handler,
46 .priority = 128,
47 };
48
kona_reset_probe(struct platform_device * pdev)49 static int kona_reset_probe(struct platform_device *pdev)
50 {
51 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52
53 kona_reset_base = devm_ioremap_resource(&pdev->dev, res);
54 if (IS_ERR(kona_reset_base))
55 return PTR_ERR(kona_reset_base);
56
57 return register_restart_handler(&kona_reset_nb);
58 }
59
60 static const struct of_device_id of_match[] = {
61 { .compatible = "brcm,bcm21664-resetmgr" },
62 {},
63 };
64
65 static struct platform_driver bcm_kona_reset_driver = {
66 .probe = kona_reset_probe,
67 .driver = {
68 .name = "brcm-kona-reset",
69 .of_match_table = of_match,
70 },
71 };
72
73 builtin_platform_driver(bcm_kona_reset_driver);
74