From: Boris Lysov <hidden> Date: 2021-01-31 23:56:01
This series adds support for mt6577 watchdog to the:
a) mtk_wdt driver - by bringing support for 16-bit I/O
b) mtk_wdt dt-binding - by declaring compatibility with mt6577
Without these changes user would have to disable watchdog by manually
writing a value to the register, otherwise the device will power off.
Accepting these patches will make ground for submitting additional
changes related to the mainline support of mt6577 (and other compatible
SoCs) in future.
Suggested patches successfully pass all `checkpatch.pl` checks, and they
do not interfere with already supported watchdogs.
Boris Lysov (3):
dt-bindings: watchdog: mediatek: add support for mt6577 SoC
watchdog: mtk_wdt: add support for 16-bit control registers
watchdog: mtk_wdt: declare compatibility with mt6577
.../devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
drivers/watchdog/Kconfig | 9 +++++
drivers/watchdog/mtk_wdt.c | 35 +++++++++++++------
3 files changed, 35 insertions(+), 10 deletions(-)
--
2.20.1
From: Boris Lysov <hidden> Date: 2021-01-31 23:55:26
Add support for Mediatek mt6577 SoC to device tree binding
documentation.
Signed-off-by: Boris Lysov <redacted>
---
Documentation/devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
1 file changed, 1 insertion(+)
@@ -5,6 +5,7 @@ Required properties: - compatible should contain: "mediatek,mt2701-wdt", "mediatek,mt6589-wdt": for MT2701 "mediatek,mt2712-wdt", "mediatek,mt6589-wdt": for MT2712+ "mediatek,mt6577-wdt": for MT6577 "mediatek,mt6589-wdt": for MT6589 "mediatek,mt6797-wdt", "mediatek,mt6589-wdt": for MT6797 "mediatek,mt7622-wdt", "mediatek,mt6589-wdt": for MT7622
From: Rob Herring <robh@kernel.org> Date: 2021-02-09 20:51:17
On Mon, 01 Feb 2021 02:44:23 +0300, Boris Lysov wrote:
Add support for Mediatek mt6577 SoC to device tree binding
documentation.
Signed-off-by: Boris Lysov <redacted>
---
Documentation/devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
1 file changed, 1 insertion(+)
From: Boris Lysov <hidden> Date: 2021-01-31 23:55:26
Add support for 16-bit control registers.
Some old Mediatek SoCs such as mt6577 use 16-bit I/O operations
for controlling watchdog. This commit redefines read/write
functions and some values in mtk_wdt driver depending on the
16-bit register support flag in kernel configuration.
By default, driver still uses 32-bit values and I/O functions, so
currently supported devices are unaffected.
Signed-off-by: Boris Lysov <redacted>
---
drivers/watchdog/Kconfig | 9 +++++++++
drivers/watchdog/mtk_wdt.c | 34 ++++++++++++++++++++++++----------
2 files changed, 33 insertions(+), 10 deletions(-)
Add support for 16-bit control registers.
Some old Mediatek SoCs such as mt6577 use 16-bit I/O operations
for controlling watchdog. This commit redefines read/write
functions and some values in mtk_wdt driver depending on the
16-bit register support flag in kernel configuration.
By default, driver still uses 32-bit values and I/O functions, so
currently supported devices are unaffected.
Signed-off-by: Boris Lysov <redacted>
We can't do this. With this flag enabled, the watchdog won't
support other SoCs, and there is nothing that prevents the flag
from being set for those SoCs.
This has to be handled differently, without configuration
flag. Maybe use regmap for register addresses, and use the
compatible string to determine which regmap settings to use,
or use accessor functions in mtk_wdt_dev.
Guenter
From: Boris Lysov <hidden> Date: 2021-02-02 01:34:54
В Sun, 31 Jan 2021 16:31:09 -0800
Guenter Roeck [off-list ref] пишет:
We can't do this. With this flag enabled, the watchdog won't
support other SoCs, and there is nothing that prevents the flag
from being set for those SoCs.
This has to be handled differently, without configuration
flag. Maybe use regmap for register addresses, [snip],
or use accessor functions in mtk_wdt_dev.
Thank you for reviewing my patch!
I will consider suggested fixes, and I will come up with better solution
in V2. I'm beginner developer, and am still learning.
use the compatible string to determine which regmap settings to use
I think relying on hardcoded "compatible string - settings" pairs in
driver is not good. Whilst most Mediatek watchdogs I've seen use
similar drivers, no one (except Mediatek itself, of course) knows for
sure how many devices use 16-bit mode, and specifying each one in C
code may _theoretically_ bloat it. (well, on the other hand, I've seen
other watchdog drivers with many compatible devices listed in C code,
and they didn't seem bloated at all)
What do you think about implementing a simple boolean flag in
dt-binding for enabling the 16-bit operation mode? Something like
"mediatek,watchdog-16bits" [1] , which the driver would check for in
the `mtk_wdt_probe` and set corresponding regmaps. As result, there
won't be a need for kernel configuration flag, and other watchdogs
would be supported.
Most likely this idea doesn't sound good as I portray it, but I would
still like to hear your opinion about it. Thanks.
References:
[1] Mediatek UART APDMA driver uses similar flag
called `mediatek,dma-33bits`
Documentation/devicetree/bindings/dma/mtk-uart-apdma.txt
В Sun, 31 Jan 2021 16:31:09 -0800
Guenter Roeck [off-list ref] пишет:
quoted
We can't do this. With this flag enabled, the watchdog won't
support other SoCs, and there is nothing that prevents the flag
from being set for those SoCs.
This has to be handled differently, without configuration
flag. Maybe use regmap for register addresses, [snip],
or use accessor functions in mtk_wdt_dev.
Thank you for reviewing my patch!
I will consider suggested fixes, and I will come up with better solution
in V2. I'm beginner developer, and am still learning.
quoted
use the compatible string to determine which regmap settings to use
I think relying on hardcoded "compatible string - settings" pairs in
driver is not good. Whilst most Mediatek watchdogs I've seen use
So you are saying that the existing mediatek watchdog driver is not good ?
Or that it is good for setting the number of supported reset pins,
but not for setting the register width ?
similar drivers, no one (except Mediatek itself, of course) knows for
sure how many devices use 16-bit mode, and specifying each one in C
code may _theoretically_ bloat it. (well, on the other hand, I've seen
other watchdog drivers with many compatible devices listed in C code,
and they didn't seem bloated at all)
What do you think about implementing a simple boolean flag in
dt-binding for enabling the 16-bit operation mode? Something like
"mediatek,watchdog-16bits" [1] , which the driver would check for in
the `mtk_wdt_probe` and set corresponding regmaps. As result, there
won't be a need for kernel configuration flag, and other watchdogs
would be supported.
Most likely this idea doesn't sound good as I portray it, but I would
still like to hear your opinion about it. Thanks.
I don't like it at all, I don't see your problem, and mediatek,dma-33bits
seems to be a completely different scope (all it does is to trigger a couple
of additional writes, not control register width). On the other side,
you would have to sell it to dt maintainers, not to me.
Guenter
References:
[1] Mediatek UART APDMA driver uses similar flag
called `mediatek,dma-33bits`
Documentation/devicetree/bindings/dma/mtk-uart-apdma.txt
В Sun, 31 Jan 2021 16:31:09 -0800
Guenter Roeck [off-list ref] пишет:
quoted
We can't do this. With this flag enabled, the watchdog won't
support other SoCs, and there is nothing that prevents the flag
from being set for those SoCs.
This has to be handled differently, without configuration
flag. Maybe use regmap for register addresses, [snip],
or use accessor functions in mtk_wdt_dev.
Thank you for reviewing my patch!
I will consider suggested fixes, and I will come up with better solution
in V2. I'm beginner developer, and am still learning.
quoted
use the compatible string to determine which regmap settings to use
I think relying on hardcoded "compatible string - settings" pairs in
driver is not good. Whilst most Mediatek watchdogs I've seen use
similar drivers, no one (except Mediatek itself, of course) knows for
sure how many devices use 16-bit mode, and specifying each one in C
code may _theoretically_ bloat it. (well, on the other hand, I've seen
other watchdog drivers with many compatible devices listed in C code,
and they didn't seem bloated at all)
We enable 16 bit access for "mediatek,mt6577-wdt" if we have a new SoC that also
needs 16 bit access, most probably we can just update the binding documentation
by adding the new SoC with a fallback to mt6577:
"mediatek,mt1234-wdt", "mediatek,mt6577-wdt": for MT1234
As no binding to mt1234 is present in the driver, the mt6577 one will be used.
Regards,
Matthias
From: Boris Lysov <hidden> Date: 2021-05-09 21:26:56
This series aims to refactor existing mtk_wdt driver by making some
constants dependent on a particular SoC. It is done because some mtk
watchdogs, while working in same manner, have slightly different
parameters such as specific register unlock key value and an offset of a
particular register field.
This patch set adds support for mt6577 watchdog.
Accepting these patches will make ground for submitting additional
changes related to the mainline support of mt6577 (and other compatible
SoCs) in future.
Proposed patches successfully pass all `checkpatch.pl` checks and don't
yield compiler warnings.
Resulting code has been thoroughly tested multiple times for hours on
real hardware (mt6577, mt6589) to ensure that proposed changes are
working properly.
Changes since v1 [1]:
- a complete rewrite to get rid of the configuration flags which made
the watchdog not support other SoCs; suggested [2] by Guenter Roeck.
[1] https://lore.kernel.org/linux-mediatek/20210131234425.9773-1-arzamas-16@mail.ee/
[2] https://lore.kernel.org/linux-mediatek/050f2f8e-9c3c-10e3-05ef-cd84e949b98f@roeck-us.net/
Boris Lysov (3):
watchdog: mtk_wdt: Refactor code to support more SoCs
dt-bindings: watchdog: mediatek: add support for mt6577 SoC
watchdog: mtk_wdt: add support for mt6577
.../devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
drivers/watchdog/mtk_wdt.c | 88 +++++++++++++++----
2 files changed, 70 insertions(+), 19 deletions(-)
--
2.20.1
From: Boris Lysov <hidden> Date: 2021-05-09 21:26:56
This patch adds support for watchdog used by mt6577 and related SoCs such
as mt6575 and mt8317. These watchdogs are known for having shifted WDT_MODE
and SWSYSRST registers and using different SWSYSRST_KEY value.
Signed-off-by: Boris Lysov <redacted>
---
drivers/watchdog/mtk_wdt.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
From: Boris Lysov <hidden> Date: 2021-05-09 21:26:56
This patch makes some constants SoC-dependent to support more watchdogs
in the future. It adds shifts of WDT_MODE_KEY and SWSYSRST_KEY to
mtk_wdt_data struct. This is done to bring support for various Mediatek
watchdogs which use same register structure but slightly different field
offsets in the UNLOCK_KEY registers. For example, mt6577 watchdog has
WDT_MODE_KEY and SWSYSRST_KEY at [15:8] instead of currently (and only)
supported [31:24].
Moreover, this patch adds SWSYSRST_KEY value to mtk_wdt_data because this
value also depends on specific SoC watchdog, for example mt6577 uses 0x15
instead of 0x88.
Signed-off-by: Boris Lysov <redacted>
---
drivers/watchdog/mtk_wdt.c | 76 ++++++++++++++++++++++++++++----------
1 file changed, 57 insertions(+), 19 deletions(-)
@@ -86,20 +120,20 @@ static int toprgu_reset_update(struct reset_controller_dev *rcdev,{unsignedinttmp;unsignedlongflags;-structmtk_wdt_dev*data=+structmtk_wdt_dev*wdev=container_of(rcdev,structmtk_wdt_dev,rcdev);-spin_lock_irqsave(&data->lock,flags);+spin_lock_irqsave(&wdev->lock,flags);-tmp=readl(data->wdt_base+WDT_SWSYSRST);+tmp=readl(wdev->wdt_base+WDT_SWSYSRST);if(assert)tmp|=BIT(id);elsetmp&=~BIT(id);-tmp|=WDT_SWSYS_RST_KEY;-writel(tmp,data->wdt_base+WDT_SWSYSRST);+tmp|=wdev->data->wdt_swsys_rst_key<<wdev->data->wdt_swsys_rst_key_shift;+writel(tmp,wdev->wdt_base+WDT_SWSYSRST);-spin_unlock_irqrestore(&data->lock,flags);+spin_unlock_irqrestore(&wdev->lock,flags);return0;}
@@ -221,7 +255,7 @@ static int mtk_wdt_stop(struct watchdog_device *wdt_dev)reg=readl(wdt_base+WDT_MODE);reg&=~WDT_MODE_EN;-reg|=WDT_MODE_KEY;+reg|=WDT_MODE_KEY<<mtk_wdt->data->wdt_mode_key_shift;iowrite32(reg,wdt_base+WDT_MODE);return0;
@@ -240,7 +274,7 @@ static int mtk_wdt_start(struct watchdog_device *wdt_dev)reg=ioread32(wdt_base+WDT_MODE);reg&=~(WDT_MODE_IRQ_EN|WDT_MODE_DUAL_EN);-reg|=(WDT_MODE_EN|WDT_MODE_KEY);+reg|=(WDT_MODE_EN|(WDT_MODE_KEY<<mtk_wdt->data->wdt_mode_key_shift));iowrite32(reg,wdt_base+WDT_MODE);return0;
@@ -266,7 +300,6 @@ static int mtk_wdt_probe(struct platform_device *pdev){structdevice*dev=&pdev->dev;structmtk_wdt_dev*mtk_wdt;-conststructmtk_wdt_data*wdt_data;interr;mtk_wdt=devm_kzalloc(dev,sizeof(*mtk_wdt),GFP_KERNEL);
@@ -279,6 +312,12 @@ static int mtk_wdt_probe(struct platform_device *pdev)if(IS_ERR(mtk_wdt->wdt_base))returnPTR_ERR(mtk_wdt->wdt_base);+mtk_wdt->data=of_device_get_match_data(dev);+if(!mtk_wdt->data){+dev_err(dev,"watchdog data is not defined\n");+return-EINVAL;+}+mtk_wdt->wdt_dev.info=&mtk_wdt_info;mtk_wdt->wdt_dev.ops=&mtk_wdt_ops;mtk_wdt->wdt_dev.timeout=WDT_MAX_TIMEOUT;
This patch makes some constants SoC-dependent to support more watchdogs
in the future. It adds shifts of WDT_MODE_KEY and SWSYSRST_KEY to
mtk_wdt_data struct. This is done to bring support for various Mediatek
watchdogs which use same register structure but slightly different field
offsets in the UNLOCK_KEY registers. For example, mt6577 watchdog has
WDT_MODE_KEY and SWSYSRST_KEY at [15:8] instead of currently (and only)
supported [31:24].
Moreover, this patch adds SWSYSRST_KEY value to mtk_wdt_data because this
value also depends on specific SoC watchdog, for example mt6577 uses 0x15
instead of 0x88.
Signed-off-by: Boris Lysov <redacted>
---
drivers/watchdog/mtk_wdt.c | 76 ++++++++++++++++++++++++++++----------
1 file changed, 57 insertions(+), 19 deletions(-)
@@ -86,20 +120,20 @@ static int toprgu_reset_update(struct reset_controller_dev *rcdev,{unsignedinttmp;unsignedlongflags;-structmtk_wdt_dev*data=+structmtk_wdt_dev*wdev=
Please do not rename variables. If you dislike that the name matches the name
of the newly introduced structure element, find a different name for that.
Thanks,
Guenter
Please do not rename variables. If you dislike that the name matches the name
of the newly introduced structure element, find a different name for that.
From: Boris Lysov <hidden> Date: 2021-05-09 21:27:07
Add support for Mediatek mt6577 SoC to device tree binding
documentation.
Signed-off-by: Boris Lysov <redacted>
---
Documentation/devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
1 file changed, 1 insertion(+)
@@ -5,6 +5,7 @@ Required properties: - compatible should contain: "mediatek,mt2701-wdt", "mediatek,mt6589-wdt": for MT2701 "mediatek,mt2712-wdt": for MT2712+ "mediatek,mt6577-wdt": for MT6577 "mediatek,mt6589-wdt": for MT6589 "mediatek,mt6797-wdt", "mediatek,mt6589-wdt": for MT6797 "mediatek,mt7622-wdt", "mediatek,mt6589-wdt": for MT7622
From: Rob Herring <robh@kernel.org> Date: 2021-05-10 16:17:11
On Mon, 10 May 2021 00:17:01 +0300, Boris Lysov wrote:
Add support for Mediatek mt6577 SoC to device tree binding
documentation.
Signed-off-by: Boris Lysov <redacted>
---
Documentation/devicetree/bindings/watchdog/mtk-wdt.txt | 1 +
1 file changed, 1 insertion(+)