rcar-rst.c 3.4 KB

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