st-poweroff.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2014 STMicroelectronics
  3. *
  4. * Power off Restart driver, used in STMicroelectronics devices.
  5. *
  6. * Author: Christophe Kerello <christophe.kerello@st.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/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/reboot.h>
  18. #include <linux/regmap.h>
  19. struct reset_syscfg {
  20. struct regmap *regmap;
  21. /* syscfg used for reset */
  22. unsigned int offset_rst;
  23. unsigned int mask_rst;
  24. /* syscfg used for unmask the reset */
  25. unsigned int offset_rst_msk;
  26. unsigned int mask_rst_msk;
  27. };
  28. /* STiH407 */
  29. #define STIH407_SYSCFG_4000 0x0
  30. #define STIH407_SYSCFG_4008 0x20
  31. static struct reset_syscfg stih407_reset = {
  32. .offset_rst = STIH407_SYSCFG_4000,
  33. .mask_rst = BIT(0),
  34. .offset_rst_msk = STIH407_SYSCFG_4008,
  35. .mask_rst_msk = BIT(0)
  36. };
  37. static struct reset_syscfg *st_restart_syscfg;
  38. static int st_restart(struct notifier_block *this, unsigned long mode,
  39. void *cmd)
  40. {
  41. /* reset syscfg updated */
  42. regmap_update_bits(st_restart_syscfg->regmap,
  43. st_restart_syscfg->offset_rst,
  44. st_restart_syscfg->mask_rst,
  45. 0);
  46. /* unmask the reset */
  47. regmap_update_bits(st_restart_syscfg->regmap,
  48. st_restart_syscfg->offset_rst_msk,
  49. st_restart_syscfg->mask_rst_msk,
  50. 0);
  51. return NOTIFY_DONE;
  52. }
  53. static struct notifier_block st_restart_nb = {
  54. .notifier_call = st_restart,
  55. .priority = 192,
  56. };
  57. static const struct of_device_id st_reset_of_match[] = {
  58. {
  59. .compatible = "st,stih407-restart",
  60. .data = (void *)&stih407_reset,
  61. },
  62. {}
  63. };
  64. static int st_reset_probe(struct platform_device *pdev)
  65. {
  66. struct device_node *np = pdev->dev.of_node;
  67. const struct of_device_id *match;
  68. struct device *dev = &pdev->dev;
  69. match = of_match_device(st_reset_of_match, dev);
  70. if (!match)
  71. return -ENODEV;
  72. st_restart_syscfg = (struct reset_syscfg *)match->data;
  73. st_restart_syscfg->regmap =
  74. syscon_regmap_lookup_by_phandle(np, "st,syscfg");
  75. if (IS_ERR(st_restart_syscfg->regmap)) {
  76. dev_err(dev, "No syscfg phandle specified\n");
  77. return PTR_ERR(st_restart_syscfg->regmap);
  78. }
  79. return register_restart_handler(&st_restart_nb);
  80. }
  81. static struct platform_driver st_reset_driver = {
  82. .probe = st_reset_probe,
  83. .driver = {
  84. .name = "st_reset",
  85. .of_match_table = st_reset_of_match,
  86. },
  87. };
  88. static int __init st_reset_init(void)
  89. {
  90. return platform_driver_register(&st_reset_driver);
  91. }
  92. device_initcall(st_reset_init);
  93. MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
  94. MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
  95. MODULE_LICENSE("GPL v2");