Anders Berg | 4a315e3 | 2014-05-23 11:08:38 +0200 | [diff] [blame^] | 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/of.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/reboot.h> |
| 25 | #include <linux/regmap.h> |
| 26 | |
| 27 | #include <asm/system_misc.h> |
| 28 | |
| 29 | |
| 30 | #define SC_CRIT_WRITE_KEY 0x1000 |
| 31 | #define SC_LATCH_ON_RESET 0x1004 |
| 32 | #define SC_RESET_CONTROL 0x1008 |
| 33 | #define RSTCTL_RST_ZERO (1<<3) |
| 34 | #define RSTCTL_RST_FAB (1<<2) |
| 35 | #define RSTCTL_RST_CHIP (1<<1) |
| 36 | #define RSTCTL_RST_SYS (1<<0) |
| 37 | #define SC_EFUSE_INT_STATUS 0x180c |
| 38 | #define EFUSE_READ_DONE (1<<31) |
| 39 | |
| 40 | static struct regmap *syscon; |
| 41 | |
| 42 | static void do_axxia_restart(enum reboot_mode reboot_mode, const char *cmd) |
| 43 | { |
| 44 | /* Access Key (0xab) */ |
| 45 | regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab); |
| 46 | /* Select internal boot from 0xffff0000 */ |
| 47 | regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040); |
| 48 | /* Assert ResetReadDone (to avoid hanging in boot ROM) */ |
| 49 | regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE); |
| 50 | /* Assert chip reset */ |
| 51 | regmap_update_bits(syscon, SC_RESET_CONTROL, |
| 52 | RSTCTL_RST_CHIP, RSTCTL_RST_CHIP); |
| 53 | } |
| 54 | |
| 55 | static int axxia_reset_probe(struct platform_device *pdev) |
| 56 | { |
| 57 | struct device *dev = &pdev->dev; |
| 58 | |
| 59 | syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); |
| 60 | if (IS_ERR(syscon)) { |
| 61 | pr_err("%s: syscon lookup failed\n", dev->of_node->name); |
| 62 | return PTR_ERR(syscon); |
| 63 | } |
| 64 | |
| 65 | arm_pm_restart = do_axxia_restart; |
| 66 | |
| 67 | return 0; |
| 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); |