Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Reset driver for Axxia devices
0004  *
0005  * Copyright (C) 2014 LSI
0006  */
0007 #include <linux/init.h>
0008 #include <linux/err.h>
0009 #include <linux/io.h>
0010 #include <linux/kernel.h>
0011 #include <linux/mfd/syscon.h>
0012 #include <linux/module.h>
0013 #include <linux/notifier.h>
0014 #include <linux/of.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/reboot.h>
0017 #include <linux/regmap.h>
0018 
0019 #define SC_CRIT_WRITE_KEY   0x1000
0020 #define SC_LATCH_ON_RESET   0x1004
0021 #define SC_RESET_CONTROL    0x1008
0022 #define   RSTCTL_RST_ZERO   (1<<3)
0023 #define   RSTCTL_RST_FAB    (1<<2)
0024 #define   RSTCTL_RST_CHIP   (1<<1)
0025 #define   RSTCTL_RST_SYS    (1<<0)
0026 #define SC_EFUSE_INT_STATUS 0x180c
0027 #define   EFUSE_READ_DONE   (1<<31)
0028 
0029 static struct regmap *syscon;
0030 
0031 static int axxia_restart_handler(struct notifier_block *this,
0032                  unsigned long mode, void *cmd)
0033 {
0034     /* Access Key (0xab) */
0035     regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab);
0036     /* Select internal boot from 0xffff0000 */
0037     regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040);
0038     /* Assert ResetReadDone (to avoid hanging in boot ROM) */
0039     regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE);
0040     /* Assert chip reset */
0041     regmap_update_bits(syscon, SC_RESET_CONTROL,
0042                RSTCTL_RST_CHIP, RSTCTL_RST_CHIP);
0043 
0044     return NOTIFY_DONE;
0045 }
0046 
0047 static struct notifier_block axxia_restart_nb = {
0048     .notifier_call = axxia_restart_handler,
0049     .priority = 128,
0050 };
0051 
0052 static int axxia_reset_probe(struct platform_device *pdev)
0053 {
0054     struct device *dev = &pdev->dev;
0055     int err;
0056 
0057     syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
0058     if (IS_ERR(syscon)) {
0059         pr_err("%pOFn: syscon lookup failed\n", dev->of_node);
0060         return PTR_ERR(syscon);
0061     }
0062 
0063     err = register_restart_handler(&axxia_restart_nb);
0064     if (err)
0065         dev_err(dev, "cannot register restart handler (err=%d)\n", err);
0066 
0067     return err;
0068 }
0069 
0070 static const struct of_device_id of_axxia_reset_match[] = {
0071     { .compatible = "lsi,axm55xx-reset", },
0072     {},
0073 };
0074 MODULE_DEVICE_TABLE(of, of_axxia_reset_match);
0075 
0076 static struct platform_driver axxia_reset_driver = {
0077     .probe = axxia_reset_probe,
0078     .driver = {
0079         .name = "axxia-reset",
0080         .of_match_table = of_match_ptr(of_axxia_reset_match),
0081     },
0082 };
0083 
0084 static int __init axxia_reset_init(void)
0085 {
0086     return platform_driver_register(&axxia_reset_driver);
0087 }
0088 device_initcall(axxia_reset_init);