251-v6.8-watchdog-mediatek-mt7988-add-wdt-support.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. From 137c9e08e5e542d58aa606b0bb4f0990117309a0 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Mon, 20 Nov 2023 18:22:31 +0000
  4. Subject: [PATCH] watchdog: mediatek: mt7988: add wdt support
  5. Add support for watchdog and reset generator unit of the MediaTek
  6. MT7988 SoC.
  7. Signed-off-by: Daniel Golle <[email protected]>
  8. Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
  9. Reviewed-by: Guenter Roeck <[email protected]>
  10. Link: https://lore.kernel.org/r/c0cf5f701801cce60470853fa15f1d9dced78c4f.1700504385.git.daniel@makrotopia.org
  11. Signed-off-by: Guenter Roeck <[email protected]>
  12. Signed-off-by: Wim Van Sebroeck <[email protected]>
  13. ---
  14. drivers/watchdog/mtk_wdt.c | 42 ++++++++++++++++++++++++++++++++++++++
  15. 1 file changed, 42 insertions(+)
  16. --- a/drivers/watchdog/mtk_wdt.c
  17. +++ b/drivers/watchdog/mtk_wdt.c
  18. @@ -58,9 +58,13 @@
  19. #define WDT_SWSYSRST 0x18U
  20. #define WDT_SWSYS_RST_KEY 0x88000000
  21. +#define WDT_SWSYSRST_EN 0xfc
  22. +
  23. #define DRV_NAME "mtk-wdt"
  24. #define DRV_VERSION "1.0"
  25. +#define MT7988_TOPRGU_SW_RST_NUM 24
  26. +
  27. static bool nowayout = WATCHDOG_NOWAYOUT;
  28. static unsigned int timeout;
  29. @@ -71,10 +75,12 @@ struct mtk_wdt_dev {
  30. struct reset_controller_dev rcdev;
  31. bool disable_wdt_extrst;
  32. bool reset_by_toprgu;
  33. + bool has_swsysrst_en;
  34. };
  35. struct mtk_wdt_data {
  36. int toprgu_sw_rst_num;
  37. + bool has_swsysrst_en;
  38. };
  39. static const struct mtk_wdt_data mt2712_data = {
  40. @@ -89,6 +95,11 @@ static const struct mtk_wdt_data mt7986_
  41. .toprgu_sw_rst_num = MT7986_TOPRGU_SW_RST_NUM,
  42. };
  43. +static const struct mtk_wdt_data mt7988_data = {
  44. + .toprgu_sw_rst_num = MT7988_TOPRGU_SW_RST_NUM,
  45. + .has_swsysrst_en = true,
  46. +};
  47. +
  48. static const struct mtk_wdt_data mt8183_data = {
  49. .toprgu_sw_rst_num = MT8183_TOPRGU_SW_RST_NUM,
  50. };
  51. @@ -109,6 +120,28 @@ static const struct mtk_wdt_data mt8195_
  52. .toprgu_sw_rst_num = MT8195_TOPRGU_SW_RST_NUM,
  53. };
  54. +/**
  55. + * toprgu_reset_sw_en_unlocked() - enable/disable software control for reset bit
  56. + * @data: Pointer to instance of driver data.
  57. + * @id: Bit number identifying the reset to be enabled or disabled.
  58. + * @enable: If true, enable software control for that bit, disable otherwise.
  59. + *
  60. + * Context: The caller must hold lock of struct mtk_wdt_dev.
  61. + */
  62. +static void toprgu_reset_sw_en_unlocked(struct mtk_wdt_dev *data,
  63. + unsigned long id, bool enable)
  64. +{
  65. + u32 tmp;
  66. +
  67. + tmp = readl(data->wdt_base + WDT_SWSYSRST_EN);
  68. + if (enable)
  69. + tmp |= BIT(id);
  70. + else
  71. + tmp &= ~BIT(id);
  72. +
  73. + writel(tmp, data->wdt_base + WDT_SWSYSRST_EN);
  74. +}
  75. +
  76. static int toprgu_reset_update(struct reset_controller_dev *rcdev,
  77. unsigned long id, bool assert)
  78. {
  79. @@ -119,6 +152,9 @@ static int toprgu_reset_update(struct re
  80. spin_lock_irqsave(&data->lock, flags);
  81. + if (assert && data->has_swsysrst_en)
  82. + toprgu_reset_sw_en_unlocked(data, id, true);
  83. +
  84. tmp = readl(data->wdt_base + WDT_SWSYSRST);
  85. if (assert)
  86. tmp |= BIT(id);
  87. @@ -127,6 +163,9 @@ static int toprgu_reset_update(struct re
  88. tmp |= WDT_SWSYS_RST_KEY;
  89. writel(tmp, data->wdt_base + WDT_SWSYSRST);
  90. + if (!assert && data->has_swsysrst_en)
  91. + toprgu_reset_sw_en_unlocked(data, id, false);
  92. +
  93. spin_unlock_irqrestore(&data->lock, flags);
  94. return 0;
  95. @@ -406,6 +445,8 @@ static int mtk_wdt_probe(struct platform
  96. wdt_data->toprgu_sw_rst_num);
  97. if (err)
  98. return err;
  99. +
  100. + mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
  101. }
  102. mtk_wdt->disable_wdt_extrst =
  103. @@ -444,6 +485,7 @@ static const struct of_device_id mtk_wdt
  104. { .compatible = "mediatek,mt6589-wdt" },
  105. { .compatible = "mediatek,mt6795-wdt", .data = &mt6795_data },
  106. { .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
  107. + { .compatible = "mediatek,mt7988-wdt", .data = &mt7988_data },
  108. { .compatible = "mediatek,mt8183-wdt", .data = &mt8183_data },
  109. { .compatible = "mediatek,mt8186-wdt", .data = &mt8186_data },
  110. { .compatible = "mediatek,mt8188-wdt", .data = &mt8188_data },