keystone-reset.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * TI keystone reboot driver
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated. http://www.ti.com/
  5. *
  6. * Author: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/reboot.h>
  15. #include <linux/regmap.h>
  16. #include <asm/system_misc.h>
  17. #include <linux/mfd/syscon.h>
  18. #include <linux/of_platform.h>
  19. #define RSTYPE_RG 0x0
  20. #define RSCTRL_RG 0x4
  21. #define RSCFG_RG 0x8
  22. #define RSISO_RG 0xc
  23. #define RSCTRL_KEY_MASK 0x0000ffff
  24. #define RSCTRL_RESET_MASK BIT(16)
  25. #define RSCTRL_KEY 0x5a69
  26. #define RSMUX_OMODE_MASK 0xe
  27. #define RSMUX_OMODE_RESET_ON 0xa
  28. #define RSMUX_OMODE_RESET_OFF 0x0
  29. #define RSMUX_LOCK_MASK 0x1
  30. #define RSMUX_LOCK_SET 0x1
  31. #define RSCFG_RSTYPE_SOFT 0x300f
  32. #define RSCFG_RSTYPE_HARD 0x0
  33. #define WDT_MUX_NUMBER 0x4
  34. static int rspll_offset;
  35. static struct regmap *pllctrl_regs;
  36. /**
  37. * rsctrl_enable_rspll_write - enable access to RSCTRL, RSCFG
  38. * To be able to access to RSCTRL, RSCFG registers
  39. * we have to write a key before
  40. */
  41. static inline int rsctrl_enable_rspll_write(void)
  42. {
  43. return regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
  44. RSCTRL_KEY_MASK, RSCTRL_KEY);
  45. }
  46. static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
  47. {
  48. /* enable write access to RSTCTRL */
  49. rsctrl_enable_rspll_write();
  50. /* reset the SOC */
  51. regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
  52. RSCTRL_RESET_MASK, 0);
  53. }
  54. static struct of_device_id rsctrl_of_match[] = {
  55. {.compatible = "ti,keystone-reset", },
  56. {},
  57. };
  58. static int rsctrl_probe(struct platform_device *pdev)
  59. {
  60. int i;
  61. int ret;
  62. u32 val;
  63. unsigned int rg;
  64. u32 rsmux_offset;
  65. struct regmap *devctrl_regs;
  66. struct device *dev = &pdev->dev;
  67. struct device_node *np = dev->of_node;
  68. if (!np)
  69. return -ENODEV;
  70. /* get regmaps */
  71. pllctrl_regs = syscon_regmap_lookup_by_phandle(np, "ti,syscon-pll");
  72. if (IS_ERR(pllctrl_regs))
  73. return PTR_ERR(pllctrl_regs);
  74. devctrl_regs = syscon_regmap_lookup_by_phandle(np, "ti,syscon-dev");
  75. if (IS_ERR(devctrl_regs))
  76. return PTR_ERR(devctrl_regs);
  77. ret = of_property_read_u32_index(np, "ti,syscon-pll", 1, &rspll_offset);
  78. if (ret) {
  79. dev_err(dev, "couldn't read the reset pll offset!\n");
  80. return -EINVAL;
  81. }
  82. ret = of_property_read_u32_index(np, "ti,syscon-dev", 1, &rsmux_offset);
  83. if (ret) {
  84. dev_err(dev, "couldn't read the rsmux offset!\n");
  85. return -EINVAL;
  86. }
  87. /* set soft/hard reset */
  88. val = of_property_read_bool(np, "ti,soft-reset");
  89. val = val ? RSCFG_RSTYPE_SOFT : RSCFG_RSTYPE_HARD;
  90. ret = rsctrl_enable_rspll_write();
  91. if (ret)
  92. return ret;
  93. ret = regmap_write(pllctrl_regs, rspll_offset + RSCFG_RG, val);
  94. if (ret)
  95. return ret;
  96. arm_pm_restart = rsctrl_restart;
  97. /* disable a reset isolation for all module clocks */
  98. ret = regmap_write(pllctrl_regs, rspll_offset + RSISO_RG, 0);
  99. if (ret)
  100. return ret;
  101. /* enable a reset for watchdogs from wdt-list */
  102. for (i = 0; i < WDT_MUX_NUMBER; i++) {
  103. ret = of_property_read_u32_index(np, "ti,wdt-list", i, &val);
  104. if (ret == -EOVERFLOW && !i) {
  105. dev_err(dev, "ti,wdt-list property has to contain at"
  106. "least one entry\n");
  107. return -EINVAL;
  108. } else if (ret) {
  109. break;
  110. }
  111. if (val >= WDT_MUX_NUMBER) {
  112. dev_err(dev, "ti,wdt-list property can contain"
  113. "only numbers < 4\n");
  114. return -EINVAL;
  115. }
  116. rg = rsmux_offset + val * 4;
  117. ret = regmap_update_bits(devctrl_regs, rg, RSMUX_OMODE_MASK,
  118. RSMUX_OMODE_RESET_ON |
  119. RSMUX_LOCK_SET);
  120. if (ret)
  121. return ret;
  122. }
  123. return 0;
  124. }
  125. static struct platform_driver rsctrl_driver = {
  126. .probe = rsctrl_probe,
  127. .driver = {
  128. .owner = THIS_MODULE,
  129. .name = KBUILD_MODNAME,
  130. .of_match_table = rsctrl_of_match,
  131. },
  132. };
  133. module_platform_driver(rsctrl_driver);
  134. MODULE_AUTHOR("Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>");
  135. MODULE_DESCRIPTION("Texas Instruments keystone reset driver");
  136. MODULE_LICENSE("GPL v2");
  137. MODULE_ALIAS("platform:" KBUILD_MODNAME);