009-v6.3-02-watchdog-mt7621-wdt-avoid-ralink-architecture-depend.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From ff8ec4ac39ad413b580d611dbf68e1d8a82eba56 Mon Sep 17 00:00:00 2001
  2. From: Sergio Paracuellos <[email protected]>
  3. Date: Tue, 14 Feb 2023 11:39:36 +0100
  4. Subject: [PATCH 2/2] watchdog: mt7621-wdt: avoid ralink architecture dependent code
  5. MT7621 SoC has a system controller node. Watchdog need to access to reset
  6. status register. Ralink architecture and related driver are old and from
  7. the beggining they are using some architecture dependent operations for
  8. accessing this shared registers through 'asm/mach-ralink/ralink_regs.h'
  9. header file. However this is not ideal from a driver perspective which can
  10. just access to the system controller registers in an arch independent way
  11. using regmap syscon APIs. Update Kconfig accordingly to select new added
  12. dependencies and allow driver to be compile tested.
  13. Signed-off-by: Sergio Paracuellos <[email protected]>
  14. Reviewed-by: Guenter Roeck <[email protected]>
  15. Link: https://lore.kernel.org/r/[email protected]
  16. Signed-off-by: Guenter Roeck <[email protected]>
  17. Signed-off-by: Wim Van Sebroeck <[email protected]>
  18. ---
  19. drivers/watchdog/Kconfig | 4 +++-
  20. drivers/watchdog/mt7621_wdt.c | 22 +++++++++++++++++-----
  21. 2 files changed, 20 insertions(+), 6 deletions(-)
  22. --- a/drivers/watchdog/Kconfig
  23. +++ b/drivers/watchdog/Kconfig
  24. @@ -1799,7 +1799,9 @@ config RALINK_WDT
  25. config MT7621_WDT
  26. tristate "Mediatek SoC watchdog"
  27. select WATCHDOG_CORE
  28. - depends on SOC_MT7620 || SOC_MT7621
  29. + select REGMAP_MMIO
  30. + select MFD_SYSCON
  31. + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST
  32. help
  33. Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer.
  34. --- a/drivers/watchdog/mt7621_wdt.c
  35. +++ b/drivers/watchdog/mt7621_wdt.c
  36. @@ -15,8 +15,8 @@
  37. #include <linux/moduleparam.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/mod_devicetable.h>
  40. -
  41. -#include <asm/mach-ralink/ralink_regs.h>
  42. +#include <linux/mfd/syscon.h>
  43. +#include <linux/regmap.h>
  44. #define SYSC_RSTSTAT 0x38
  45. #define WDT_RST_CAUSE BIT(1)
  46. @@ -34,6 +34,7 @@
  47. struct mt7621_wdt_data {
  48. void __iomem *base;
  49. struct reset_control *rst;
  50. + struct regmap *sysc;
  51. struct watchdog_device wdt;
  52. };
  53. @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchd
  54. return 0;
  55. }
  56. -static int mt7621_wdt_bootcause(void)
  57. +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d)
  58. {
  59. - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
  60. + u32 val;
  61. +
  62. + regmap_read(d->sysc, SYSC_RSTSTAT, &val);
  63. + if (val & WDT_RST_CAUSE)
  64. return WDIOF_CARDRESET;
  65. return 0;
  66. @@ -134,6 +138,7 @@ static const struct watchdog_ops mt7621_
  67. static int mt7621_wdt_probe(struct platform_device *pdev)
  68. {
  69. + struct device_node *np = pdev->dev.of_node;
  70. struct device *dev = &pdev->dev;
  71. struct watchdog_device *mt7621_wdt;
  72. struct mt7621_wdt_data *drvdata;
  73. @@ -143,6 +148,13 @@ static int mt7621_wdt_probe(struct platf
  74. if (!drvdata)
  75. return -ENOMEM;
  76. + drvdata->sysc = syscon_regmap_lookup_by_phandle(np, "mediatek,sysctl");
  77. + if (IS_ERR(drvdata->sysc)) {
  78. + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc");
  79. + if (IS_ERR(drvdata->sysc))
  80. + return PTR_ERR(drvdata->sysc);
  81. + }
  82. +
  83. drvdata->base = devm_platform_ioremap_resource(pdev, 0);
  84. if (IS_ERR(drvdata->base))
  85. return PTR_ERR(drvdata->base);
  86. @@ -158,7 +170,7 @@ static int mt7621_wdt_probe(struct platf
  87. mt7621_wdt->max_timeout = 0xfffful / 1000;
  88. mt7621_wdt->parent = dev;
  89. - mt7621_wdt->bootstatus = mt7621_wdt_bootcause();
  90. + mt7621_wdt->bootstatus = mt7621_wdt_bootcause(drvdata);
  91. watchdog_init_timeout(mt7621_wdt, mt7621_wdt->max_timeout, dev);
  92. watchdog_set_nowayout(mt7621_wdt, nowayout);