rcar-rst.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * R-Car Gen1 RESET/WDT, R-Car Gen2, Gen3, and RZ/G RST Driver
  3. *
  4. * Copyright (C) 2016 Glider bvba
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/err.h>
  11. #include <linux/io.h>
  12. #include <linux/of_address.h>
  13. #include <linux/soc/renesas/rcar-rst.h>
  14. #define WDTRSTCR_RESET 0xA55A0002
  15. #define WDTRSTCR 0x0054
  16. static int rcar_rst_enable_wdt_reset(void __iomem *base)
  17. {
  18. iowrite32(WDTRSTCR_RESET, base + WDTRSTCR);
  19. return 0;
  20. }
  21. struct rst_config {
  22. unsigned int modemr; /* Mode Monitoring Register Offset */
  23. int (*configure)(void *base); /* Platform specific configuration */
  24. };
  25. static const struct rst_config rcar_rst_gen1 __initconst = {
  26. .modemr = 0x20,
  27. };
  28. static const struct rst_config rcar_rst_gen2 __initconst = {
  29. .modemr = 0x60,
  30. .configure = rcar_rst_enable_wdt_reset,
  31. };
  32. static const struct rst_config rcar_rst_gen3 __initconst = {
  33. .modemr = 0x60,
  34. };
  35. static const struct of_device_id rcar_rst_matches[] __initconst = {
  36. /* RZ/G is handled like R-Car Gen2 */
  37. { .compatible = "renesas,r8a7743-rst", .data = &rcar_rst_gen2 },
  38. { .compatible = "renesas,r8a7745-rst", .data = &rcar_rst_gen2 },
  39. /* R-Car Gen1 */
  40. { .compatible = "renesas,r8a7778-reset-wdt", .data = &rcar_rst_gen1 },
  41. { .compatible = "renesas,r8a7779-reset-wdt", .data = &rcar_rst_gen1 },
  42. /* R-Car Gen2 */
  43. { .compatible = "renesas,r8a7790-rst", .data = &rcar_rst_gen2 },
  44. { .compatible = "renesas,r8a7791-rst", .data = &rcar_rst_gen2 },
  45. { .compatible = "renesas,r8a7792-rst", .data = &rcar_rst_gen2 },
  46. { .compatible = "renesas,r8a7793-rst", .data = &rcar_rst_gen2 },
  47. { .compatible = "renesas,r8a7794-rst", .data = &rcar_rst_gen2 },
  48. /* R-Car Gen3 */
  49. { .compatible = "renesas,r8a7795-rst", .data = &rcar_rst_gen3 },
  50. { .compatible = "renesas,r8a7796-rst", .data = &rcar_rst_gen3 },
  51. { .compatible = "renesas,r8a77965-rst", .data = &rcar_rst_gen3 },
  52. { .compatible = "renesas,r8a77970-rst", .data = &rcar_rst_gen3 },
  53. { .compatible = "renesas,r8a77980-rst", .data = &rcar_rst_gen3 },
  54. { .compatible = "renesas,r8a77995-rst", .data = &rcar_rst_gen3 },
  55. { /* sentinel */ }
  56. };
  57. static void __iomem *rcar_rst_base __initdata;
  58. static u32 saved_mode __initdata;
  59. static int __init rcar_rst_init(void)
  60. {
  61. const struct of_device_id *match;
  62. const struct rst_config *cfg;
  63. struct device_node *np;
  64. void __iomem *base;
  65. int error = 0;
  66. np = of_find_matching_node_and_match(NULL, rcar_rst_matches, &match);
  67. if (!np)
  68. return -ENODEV;
  69. base = of_iomap(np, 0);
  70. if (!base) {
  71. pr_warn("%pOF: Cannot map regs\n", np);
  72. error = -ENOMEM;
  73. goto out_put;
  74. }
  75. rcar_rst_base = base;
  76. cfg = match->data;
  77. saved_mode = ioread32(base + cfg->modemr);
  78. if (cfg->configure) {
  79. error = cfg->configure(base);
  80. if (error) {
  81. pr_warn("%pOF: Cannot run SoC specific configuration\n",
  82. np);
  83. goto out_put;
  84. }
  85. }
  86. pr_debug("%pOF: MODE = 0x%08x\n", np, saved_mode);
  87. out_put:
  88. of_node_put(np);
  89. return error;
  90. }
  91. int __init rcar_rst_read_mode_pins(u32 *mode)
  92. {
  93. int error;
  94. if (!rcar_rst_base) {
  95. error = rcar_rst_init();
  96. if (error)
  97. return error;
  98. }
  99. *mode = saved_mode;
  100. return 0;
  101. }