1f0745f36SLee Jones /* 2f0745f36SLee Jones * Copyright (C) 2014 STMicroelectronics 3f0745f36SLee Jones * 4f0745f36SLee Jones * Power off Restart driver, used in STMicroelectronics devices. 5f0745f36SLee Jones * 6f0745f36SLee Jones * Author: Christophe Kerello <christophe.kerello@st.com> 7f0745f36SLee Jones * 8f0745f36SLee Jones * This program is free software; you can redistribute it and/or modify 9f0745f36SLee Jones * it under the terms of the GNU General Public License version 2, as 10f0745f36SLee Jones * published by the Free Software Foundation. 11f0745f36SLee Jones */ 12f0745f36SLee Jones 13f0745f36SLee Jones #include <linux/module.h> 14f0745f36SLee Jones #include <linux/of.h> 15f0745f36SLee Jones #include <linux/of_platform.h> 16f0745f36SLee Jones #include <linux/platform_device.h> 17f0745f36SLee Jones #include <linux/mfd/syscon.h> 18f0745f36SLee Jones #include <linux/regmap.h> 19f0745f36SLee Jones 20f0745f36SLee Jones #include <asm/system_misc.h> 21f0745f36SLee Jones 22f0745f36SLee Jones struct reset_syscfg { 23f0745f36SLee Jones struct regmap *regmap; 24f0745f36SLee Jones /* syscfg used for reset */ 25f0745f36SLee Jones unsigned int offset_rst; 26f0745f36SLee Jones unsigned int mask_rst; 27f0745f36SLee Jones /* syscfg used for unmask the reset */ 28f0745f36SLee Jones unsigned int offset_rst_msk; 29f0745f36SLee Jones unsigned int mask_rst_msk; 30f0745f36SLee Jones }; 31f0745f36SLee Jones 32f0745f36SLee Jones /* STiH415 */ 33f0745f36SLee Jones #define STIH415_SYSCFG_11 0x2c 34f0745f36SLee Jones #define STIH415_SYSCFG_15 0x3c 35f0745f36SLee Jones 36f0745f36SLee Jones static struct reset_syscfg stih415_reset = { 37f0745f36SLee Jones .offset_rst = STIH415_SYSCFG_11, 38f0745f36SLee Jones .mask_rst = BIT(0), 39f0745f36SLee Jones .offset_rst_msk = STIH415_SYSCFG_15, 40f0745f36SLee Jones .mask_rst_msk = BIT(0) 41f0745f36SLee Jones }; 42f0745f36SLee Jones 43f0745f36SLee Jones /* STiH416 */ 44f0745f36SLee Jones #define STIH416_SYSCFG_500 0x7d0 45f0745f36SLee Jones #define STIH416_SYSCFG_504 0x7e0 46f0745f36SLee Jones 47f0745f36SLee Jones static struct reset_syscfg stih416_reset = { 48f0745f36SLee Jones .offset_rst = STIH416_SYSCFG_500, 49f0745f36SLee Jones .mask_rst = BIT(0), 50f0745f36SLee Jones .offset_rst_msk = STIH416_SYSCFG_504, 51f0745f36SLee Jones .mask_rst_msk = BIT(0) 52f0745f36SLee Jones }; 53f0745f36SLee Jones 54f0745f36SLee Jones /* STiH407 */ 55f0745f36SLee Jones #define STIH407_SYSCFG_4000 0x0 56f0745f36SLee Jones #define STIH407_SYSCFG_4008 0x20 57f0745f36SLee Jones 58f0745f36SLee Jones static struct reset_syscfg stih407_reset = { 59f0745f36SLee Jones .offset_rst = STIH407_SYSCFG_4000, 60f0745f36SLee Jones .mask_rst = BIT(0), 61f0745f36SLee Jones .offset_rst_msk = STIH407_SYSCFG_4008, 62f0745f36SLee Jones .mask_rst_msk = BIT(0) 63f0745f36SLee Jones }; 64f0745f36SLee Jones 65f0745f36SLee Jones /* STiD127 */ 66f0745f36SLee Jones #define STID127_SYSCFG_700 0x0 67f0745f36SLee Jones #define STID127_SYSCFG_773 0x124 68f0745f36SLee Jones 69f0745f36SLee Jones static struct reset_syscfg stid127_reset = { 70f0745f36SLee Jones .offset_rst = STID127_SYSCFG_773, 71f0745f36SLee Jones .mask_rst = BIT(0), 72f0745f36SLee Jones .offset_rst_msk = STID127_SYSCFG_700, 73f0745f36SLee Jones .mask_rst_msk = BIT(8) 74f0745f36SLee Jones }; 75f0745f36SLee Jones 76f0745f36SLee Jones static struct reset_syscfg *st_restart_syscfg; 77f0745f36SLee Jones 78f0745f36SLee Jones static void st_restart(enum reboot_mode reboot_mode, const char *cmd) 79f0745f36SLee Jones { 80f0745f36SLee Jones /* reset syscfg updated */ 81f0745f36SLee Jones regmap_update_bits(st_restart_syscfg->regmap, 82f0745f36SLee Jones st_restart_syscfg->offset_rst, 83f0745f36SLee Jones st_restart_syscfg->mask_rst, 84f0745f36SLee Jones 0); 85f0745f36SLee Jones 86f0745f36SLee Jones /* unmask the reset */ 87f0745f36SLee Jones regmap_update_bits(st_restart_syscfg->regmap, 88f0745f36SLee Jones st_restart_syscfg->offset_rst_msk, 89f0745f36SLee Jones st_restart_syscfg->mask_rst_msk, 90f0745f36SLee Jones 0); 91f0745f36SLee Jones } 92f0745f36SLee Jones 93f0745f36SLee Jones static struct of_device_id st_reset_of_match[] = { 94f0745f36SLee Jones { 95f0745f36SLee Jones .compatible = "st,stih415-restart", 96f0745f36SLee Jones .data = (void *)&stih415_reset, 97f0745f36SLee Jones }, { 98f0745f36SLee Jones .compatible = "st,stih416-restart", 99f0745f36SLee Jones .data = (void *)&stih416_reset, 100f0745f36SLee Jones }, { 101f0745f36SLee Jones .compatible = "st,stih407-restart", 102f0745f36SLee Jones .data = (void *)&stih407_reset, 103f0745f36SLee Jones }, { 104f0745f36SLee Jones .compatible = "st,stid127-restart", 105f0745f36SLee Jones .data = (void *)&stid127_reset, 106f0745f36SLee Jones }, 107f0745f36SLee Jones {} 108f0745f36SLee Jones }; 109f0745f36SLee Jones 110f0745f36SLee Jones static int st_reset_probe(struct platform_device *pdev) 111f0745f36SLee Jones { 112f0745f36SLee Jones struct device_node *np = pdev->dev.of_node; 113f0745f36SLee Jones const struct of_device_id *match; 114f0745f36SLee Jones struct device *dev = &pdev->dev; 115f0745f36SLee Jones 116f0745f36SLee Jones match = of_match_device(st_reset_of_match, dev); 117f0745f36SLee Jones if (!match) 118f0745f36SLee Jones return -ENODEV; 119f0745f36SLee Jones 120f0745f36SLee Jones st_restart_syscfg = (struct reset_syscfg *)match->data; 121f0745f36SLee Jones 122f0745f36SLee Jones st_restart_syscfg->regmap = 123f0745f36SLee Jones syscon_regmap_lookup_by_phandle(np, "st,syscfg"); 124f0745f36SLee Jones if (IS_ERR(st_restart_syscfg->regmap)) { 125f0745f36SLee Jones dev_err(dev, "No syscfg phandle specified\n"); 126f0745f36SLee Jones return PTR_ERR(st_restart_syscfg->regmap); 127f0745f36SLee Jones } 128f0745f36SLee Jones 129f0745f36SLee Jones arm_pm_restart = st_restart; 130f0745f36SLee Jones 131f0745f36SLee Jones return 0; 132f0745f36SLee Jones } 133f0745f36SLee Jones 134f0745f36SLee Jones static struct platform_driver st_reset_driver = { 135f0745f36SLee Jones .probe = st_reset_probe, 136f0745f36SLee Jones .driver = { 137f0745f36SLee Jones .name = "st_reset", 138f0745f36SLee Jones .of_match_table = st_reset_of_match, 139f0745f36SLee Jones }, 140f0745f36SLee Jones }; 141f0745f36SLee Jones 142f0745f36SLee Jones static int __init st_reset_init(void) 143f0745f36SLee Jones { 144f0745f36SLee Jones return platform_driver_register(&st_reset_driver); 145f0745f36SLee Jones } 146f0745f36SLee Jones 147f0745f36SLee Jones device_initcall(st_reset_init); 148f0745f36SLee Jones 149f0745f36SLee Jones MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>"); 150f0745f36SLee Jones MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver"); 151f0745f36SLee Jones MODULE_LICENSE("GPL v2"); 152