Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / power / reset / axxia-reset.c
1 /*
2  * Reset driver for Axxia devices
3  *
4  * Copyright (C) 2014 LSI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 and
8  * only version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 #include <linux/init.h>
17 #include <linux/err.h>
18 #include <linux/io.h>
19 #include <linux/kernel.h>
20 #include <linux/mfd/syscon.h>
21 #include <linux/module.h>
22 #include <linux/notifier.h>
23 #include <linux/of.h>
24 #include <linux/platform_device.h>
25 #include <linux/reboot.h>
26 #include <linux/regmap.h>
27
28 #define SC_CRIT_WRITE_KEY       0x1000
29 #define SC_LATCH_ON_RESET       0x1004
30 #define SC_RESET_CONTROL        0x1008
31 #define   RSTCTL_RST_ZERO       (1<<3)
32 #define   RSTCTL_RST_FAB        (1<<2)
33 #define   RSTCTL_RST_CHIP       (1<<1)
34 #define   RSTCTL_RST_SYS        (1<<0)
35 #define SC_EFUSE_INT_STATUS     0x180c
36 #define   EFUSE_READ_DONE       (1<<31)
37
38 static struct regmap *syscon;
39
40 static int axxia_restart_handler(struct notifier_block *this,
41                                  unsigned long mode, void *cmd)
42 {
43         /* Access Key (0xab) */
44         regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab);
45         /* Select internal boot from 0xffff0000 */
46         regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040);
47         /* Assert ResetReadDone (to avoid hanging in boot ROM) */
48         regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE);
49         /* Assert chip reset */
50         regmap_update_bits(syscon, SC_RESET_CONTROL,
51                            RSTCTL_RST_CHIP, RSTCTL_RST_CHIP);
52
53         return NOTIFY_DONE;
54 }
55
56 static struct notifier_block axxia_restart_nb = {
57         .notifier_call = axxia_restart_handler,
58         .priority = 128,
59 };
60
61 static int axxia_reset_probe(struct platform_device *pdev)
62 {
63         struct device *dev = &pdev->dev;
64         int err;
65
66         syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
67         if (IS_ERR(syscon)) {
68                 pr_err("%s: syscon lookup failed\n", dev->of_node->name);
69                 return PTR_ERR(syscon);
70         }
71
72         err = register_restart_handler(&axxia_restart_nb);
73         if (err)
74                 dev_err(dev, "cannot register restart handler (err=%d)\n", err);
75
76         return err;
77 }
78
79 static const struct of_device_id of_axxia_reset_match[] = {
80         { .compatible = "lsi,axm55xx-reset", },
81         {},
82 };
83 MODULE_DEVICE_TABLE(of, of_axxia_reset_match);
84
85 static struct platform_driver axxia_reset_driver = {
86         .probe = axxia_reset_probe,
87         .driver = {
88                 .name = "axxia-reset",
89                 .of_match_table = of_match_ptr(of_axxia_reset_match),
90         },
91 };
92
93 static int __init axxia_reset_init(void)
94 {
95         return platform_driver_register(&axxia_reset_driver);
96 }
97 device_initcall(axxia_reset_init);