Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Reset driver for Axxia devices |
| 4 | * |
| 5 | * Copyright (C) 2014 LSI |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/err.h> |
| 9 | #include <linux/io.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/mfd/syscon.h> |
| 12 | #include <linux/module.h> |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 13 | #include <linux/notifier.h> |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 14 | #include <linux/of.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/reboot.h> |
| 17 | #include <linux/regmap.h> |
| 18 | |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 19 | #define SC_CRIT_WRITE_KEY 0x1000 |
| 20 | #define SC_LATCH_ON_RESET 0x1004 |
| 21 | #define SC_RESET_CONTROL 0x1008 |
| 22 | #define RSTCTL_RST_ZERO (1<<3) |
| 23 | #define RSTCTL_RST_FAB (1<<2) |
| 24 | #define RSTCTL_RST_CHIP (1<<1) |
| 25 | #define RSTCTL_RST_SYS (1<<0) |
| 26 | #define SC_EFUSE_INT_STATUS 0x180c |
| 27 | #define EFUSE_READ_DONE (1<<31) |
| 28 | |
| 29 | static struct regmap *syscon; |
| 30 | |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 31 | static int axxia_restart_handler(struct notifier_block *this, |
| 32 | unsigned long mode, void *cmd) |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 33 | { |
| 34 | /* Access Key (0xab) */ |
| 35 | regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab); |
| 36 | /* Select internal boot from 0xffff0000 */ |
| 37 | regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040); |
| 38 | /* Assert ResetReadDone (to avoid hanging in boot ROM) */ |
| 39 | regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE); |
| 40 | /* Assert chip reset */ |
| 41 | regmap_update_bits(syscon, SC_RESET_CONTROL, |
| 42 | RSTCTL_RST_CHIP, RSTCTL_RST_CHIP); |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 43 | |
| 44 | return NOTIFY_DONE; |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 47 | static struct notifier_block axxia_restart_nb = { |
| 48 | .notifier_call = axxia_restart_handler, |
| 49 | .priority = 128, |
| 50 | }; |
| 51 | |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 52 | static int axxia_reset_probe(struct platform_device *pdev) |
| 53 | { |
| 54 | struct device *dev = &pdev->dev; |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 55 | int err; |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 56 | |
| 57 | syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); |
| 58 | if (IS_ERR(syscon)) { |
Rob Herring | e31d0fc | 2018-09-05 11:34:56 -0500 | [diff] [blame] | 59 | pr_err("%pOFn: syscon lookup failed\n", dev->of_node); |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 60 | return PTR_ERR(syscon); |
| 61 | } |
| 62 | |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 63 | err = register_restart_handler(&axxia_restart_nb); |
| 64 | if (err) |
| 65 | dev_err(dev, "cannot register restart handler (err=%d)\n", err); |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 66 | |
Guenter Roeck | fcf01c5 | 2014-09-30 10:48:33 -0700 | [diff] [blame] | 67 | return err; |
Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static const struct of_device_id of_axxia_reset_match[] = { |
| 71 | { .compatible = "lsi,axm55xx-reset", }, |
| 72 | {}, |
| 73 | }; |
| 74 | MODULE_DEVICE_TABLE(of, of_axxia_reset_match); |
| 75 | |
| 76 | static struct platform_driver axxia_reset_driver = { |
| 77 | .probe = axxia_reset_probe, |
| 78 | .driver = { |
| 79 | .name = "axxia-reset", |
| 80 | .of_match_table = of_match_ptr(of_axxia_reset_match), |
| 81 | }, |
| 82 | }; |
| 83 | |
| 84 | static int __init axxia_reset_init(void) |
| 85 | { |
| 86 | return platform_driver_register(&axxia_reset_driver); |
| 87 | } |
| 88 | device_initcall(axxia_reset_init); |