watchdog: sunxi: Add A31 watchdog support
Subsystems (2)
v2 cover watchdog: sunxi: Add A31 watchdog support
Hi,
This is v2 of the Allwinner A31 watchdog support series. This series adds support for the watchdog hardware found in Allwinner A31 and later SoCs. These new chips have multiple watchdogs, with separate interrupt lines and registers, but the basic layout and operation is the same. This series is based on Guenter's restart handler series.
Patch 1 prepares the sunxi-wdt driver for varying register offsets tied to compatible strings. Various ioread32/iowrite32 calls have been replaced with readl/writel as well.
Patch 2 adds the sun6i compatible string with accompanying register offset data.
I tested this series on my Cubieboard (sun4i) and A23 tablet (sun8i), which has the same watchdog hardware as the A31 (sun6i). This covers the 2 classes of hardware supported.
After this series is merged, we can remove the power/reset driver for sun6i.
Changes since v1:
- Mention replacing ioread32/iowrite32 calls in patch 1 commit message.
Cheers
ChenYu
Chen-Yu Tsai (2):
watchdog: sunxi: support parameterized compatible strings
watchdog: sunxi: Add A31 watchdog support
drivers/watchdog/sunxi_wdt.c | 111 +++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 25 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 1/2 watchdog: sunxi: support parameterized compatible strings
This patch adds support for hardware parameters tied to compatible strings, so similar hardware can reuse the driver.
This will be used to support the newer watchdog found in A31 and later SoCs. Differences in the new hardware include separate interrupt lines for each watchdog, and corresponding interrupt control/status registers. Watchdog control registers were also slightly rearranged.
Also replace ioread32()/iowrite32() with readl()/writel() in various places changed.
--- drivers/watchdog/sunxi_wdt.c | 101 ++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 25 deletions(-)
drivers/watchdog/sunxi_wdt.c +76 -25
@@ -23,6 +23,7 @@#include <linux/moduleparam.h> #include <linux/notifier.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/reboot.h> #include <linux/types.h>
@@ -30,15 +31,11 @@#define WDT_MAX_TIMEOUT 16#define WDT_MIN_TIMEOUT 1 -#define WDT_MODE_TIMEOUT (n) ((n) << 3) -#define WDT_TIMEOUT_MASK WDT_MODE_TIMEOUT(0x0F) +#define WDT_TIMEOUT_MASK 0x0F -#define WDT_CTRL 0x00#define WDT_CTRL_RELOAD ((1 << 0) | (0x0a57 << 1)) -#define WDT_MODE 0x04#define WDT_MODE_EN (1 << 0) -#define WDT_MODE_RST_EN (1 << 1)#define DRV_NAME "sunxi-wdt"#define DRV_VERSION "1.0"
@@ -46,15 +43,29 @@static bool nowayout =WATCHDOG_NOWAYOUT ;static unsigned int timeout =WDT_MAX_TIMEOUT ; +/* +* This structure stores the register offsets for different variants +* of Allwinner's watchdog hardware. +*/ +struct sunxi_wdt_reg { +u8 wdt_ctrl; +u8 wdt_cfg; +u8 wdt_mode; +u8 wdt_timeout_shift; +u8 wdt_reset_mask; +u8 wdt_reset_val; +}; +struct sunxi_wdt_dev {struct watchdog_device wdt_dev;void __iomem *wdt_base; +const struct sunxi_wdt_reg *wdt_regs;struct notifier_block restart_handler; };/* * wdt_timeout_map maps the watchdog timer interval value in seconds to -* the value of the register WDT_MODE bit 3:6 +* the value of the register WDT_MODE@bits .wdt_timeout_shift ~ +3 * * [timeout seconds] = register value *
@@ -82,19 +93,32 @@ static int sunxi_restart_handle(struct notifier_block *this, unsigned long mode, struct sunxi_wdt_dev, restart_handler);void __iomem *wdt_base = sunxi_wdt->wdt_base; +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs; +u32 val; + +/* Set system reset function */ + val =readl (wdt_base + regs->wdt_cfg); + val &= ~(regs->wdt_reset_mask); + val |= regs->wdt_reset_val; +writel (val, wdt_base + regs->wdt_cfg); -/* Enable timer and set reset bit in the watchdog */ -writel (WDT_MODE_EN |WDT_MODE_RST_EN , wdt_base +WDT_MODE ); +/* Set lowest timeout and enable watchdog */ + val =readl (wdt_base + regs->wdt_mode); + val &= ~(WDT_TIMEOUT_MASK << regs->wdt_timeout_shift); + val |=WDT_MODE_EN ; +writel (val, wdt_base + regs->wdt_mode);/* * Restart the watchdog. The default (and lowest) interval * value for the watchdog is 0.5s. */ -writel (WDT_CTRL_RELOAD , wdt_base +WDT_CTRL ); +writel (WDT_CTRL_RELOAD , wdt_base + regs->wdt_ctrl);while (1 ) {mdelay (5 ); -writel (WDT_MODE_EN |WDT_MODE_RST_EN , wdt_base +WDT_MODE ); + val =readl (wdt_base + regs->wdt_mode); + val |=WDT_MODE_EN ; +writel (val, wdt_base + regs->wdt_mode); }return NOTIFY_DONE ; }
@@ -103,8 +127,9 @@ static int sunxi_wdt_ping(struct watchdog_device *wdt_dev) {struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev);void __iomem *wdt_base = sunxi_wdt->wdt_base; +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs; -iowrite32 (WDT_CTRL_RELOAD , wdt_base +WDT_CTRL ); +writel (WDT_CTRL_RELOAD , wdt_base + regs->wdt_ctrl);return 0 ; }
@@ -114,6 +139,7 @@ static int sunxi_wdt_set_timeout(struct watchdog_device *wdt_dev, {struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev);void __iomem *wdt_base = sunxi_wdt->wdt_base; +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs;u32 reg;if (wdt_timeout_map[timeout] ==0 )
@@ -121,10 +147,10 @@ static int sunxi_wdt_set_timeout(struct watchdog_device *wdt_dev, sunxi_wdt->wdt_dev.timeout = timeout; - reg =ioread32 (wdt_base +WDT_MODE ); - reg &= ~WDT_TIMEOUT_MASK ; - reg |=WDT_MODE_TIMEOUT (wdt_timeout_map[timeout]); -iowrite32 (reg, wdt_base +WDT_MODE ); + reg =readl (wdt_base + regs->wdt_mode); + reg &= ~(WDT_TIMEOUT_MASK << regs->wdt_timeout_shift); + reg |= wdt_timeout_map[timeout] << regs->wdt_timeout_shift; +writel (reg, wdt_base + regs->wdt_mode);sunxi_wdt_ping (wdt_dev);
@@ -135,8 +161,9 @@ static int sunxi_wdt_stop(struct watchdog_device *wdt_dev) {struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev);void __iomem *wdt_base = sunxi_wdt->wdt_base; +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs; -iowrite32 (0 , wdt_base +WDT_MODE ); +writel (0 , wdt_base + regs->wdt_mode);return 0 ; }
@@ -146,6 +173,7 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)u32 reg;struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev);void __iomem *wdt_base = sunxi_wdt->wdt_base; +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs;int ret; ret = sunxi_wdt_set_timeout(&sunxi_wdt->wdt_dev,
@@ -153,9 +181,16 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)if (ret <0 )return ret; - reg =ioread32 (wdt_base +WDT_MODE ); - reg |= (WDT_MODE_RST_EN |WDT_MODE_EN ); -iowrite32 (reg, wdt_base +WDT_MODE ); +/* Set system reset function */ + reg =readl (wdt_base + regs->wdt_cfg); + reg &= ~(regs->wdt_reset_mask); + reg |= ~(regs->wdt_reset_val); +writel (reg, wdt_base + regs->wdt_cfg); + +/* Enable watchdog */ + reg =readl (wdt_base + regs->wdt_mode); + reg |=WDT_MODE_EN ; +writel (reg, wdt_base + regs->wdt_mode);return 0 ; }
@@ -175,9 +210,25 @@ static const struct watchdog_ops sunxi_wdt_ops = { .set_timeout = sunxi_wdt_set_timeout, }; +static const struct sunxi_wdt_reg sun4i_wdt_reg = { + .wdt_ctrl =0x00 , + .wdt_cfg =0x04 , + .wdt_mode =0x04 , + .wdt_timeout_shift =3 , + .wdt_reset_mask =0x02 , + .wdt_reset_val =0x02 , +}; + +static const struct of_device_id sunxi_wdt_dt_ids[] = { + { .compatible ="allwinner,sun4i-a10-wdt" , .data = &sun4i_wdt_reg }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, sunxi_wdt_dt_ids); +static int sunxi_wdt_probe (struct platform_device *pdev) {struct sunxi_wdt_dev *sunxi_wdt; +const struct of_device_id *device;struct resource *res;int err;
@@ -187,6 +238,12 @@ static int sunxi_wdt_probe(struct platform_device *pdev)platform_set_drvdata (pdev, sunxi_wdt); + device =of_match_device (sunxi_wdt_dt_ids, &pdev->dev); +if (!device) +return -ENODEV ; + + sunxi_wdt->wdt_regs = device->data; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); sunxi_wdt->wdt_base =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (sunxi_wdt->wdt_base))
@@ -242,12 +299,6 @@ static void sunxi_wdt_shutdown(struct platform_device *pdev)sunxi_wdt_stop (&sunxi_wdt->wdt_dev); } -static const struct of_device_id sunxi_wdt_dt_ids[] = { - { .compatible ="allwinner,sun4i-a10-wdt" }, - {/* sentinel */ } -}; -MODULE_DEVICE_TABLE (of, sunxi_wdt_dt_ids); -static struct platform_driver sunxi_wdt_driver = { .probe = sunxi_wdt_probe, .remove = sunxi_wdt_remove,
Signature · 1 line
2.1.0
Guenter Roeck
maintainerPATCH v2 1/2 watchdog: sunxi: support parameterized compatible strings
Quoted 9 lines · Chen-Yu Tsai
This patch adds support for hardware parameters tied to compatible strings, so similar hardware can reuse the driver.
This will be used to support the newer watchdog found in A31 and later SoCs. Differences in the new hardware include separate interrupt lines for each watchdog, and corresponding interrupt control/status registers. Watchdog control registers were also slightly rearranged.
Quoted 4 lines
Also replace ioread32()/iowrite32() with readl()/writel() in various places changed.
Signed-off-by Chen-Yu Tsai <[email protected]>
PATCH v2 1/2 watchdog: sunxi: support parameterized compatible strings
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Chen-Yu Tsai
This patch adds support for hardware parameters tied to compatible strings, so similar hardware can reuse the driver.
This will be used to support the newer watchdog found in A31 and later SoCs. Differences in the new hardware include separate interrupt lines for each watchdog, and corresponding interrupt control/status registers. Watchdog control registers were also slightly rearranged.
Quoted 8 lines
Quoted 4 lines
Also replace ioread32()/iowrite32() with readl()/writel() in various places changed.
Signed-off-by Chen-Yu Tsai <[email protected]>Reviewed-by Guenter Roeck <[email protected]>
Hi Guenter,
Are you submitting the restart handler patches for inclusion in 3.18? If so, are you taking any related patches or patches depending on that series?
Thanks
ChenYu
Guenter Roeck
maintainerPATCH v2 1/2 watchdog: sunxi: support parameterized compatible strings
Quoted 18 lines · Chen-Yu Tsai
Quoted 17 lines · Guenter Roeck
Quoted 14 lines · Chen-Yu Tsai
This patch adds support for hardware parameters tied to compatible strings, so similar hardware can reuse the driver.
This will be used to support the newer watchdog found in A31 and later SoCs. Differences in the new hardware include separate interrupt lines for each watchdog, and corresponding interrupt control/status registers. Watchdog control registers were also slightly rearranged.
Also replace ioread32()/iowrite32() with readl()/writel() in various places changed.
Signed-off-by Chen-Yu Tsai <[email protected]>
Quoted 6 lines
Quoted 2 lines
Reviewed-by Guenter Roeck <[email protected]>Hi Guenter,
Are you submitting the restart handler patches for inclusion in 3.18?
Yes, should go in through Andrew's tree or through one of the branches depending on it.
Quoted 3 lines
If so, are you taking any related patches or patches depending on that series?
In general no, but I just sent a pull request pointing to an immutable branch containing the series. Affected maintainers should merge this branch into the affected subject branch(es).
I do have a number of related patches in my watchdog-next branch. I'll send an updated pull request with those to Wim later today.
Thanks,
Guenter
PATCH v2 2/2 watchdog: sunxi: Add A31 watchdog support
In reply to Chen-Yu TsaiThis patch adds support for the watchdog hardware found in A31 and newer SoCs. This new hardware has registers at different offsets, and the system reset control has been split out of the "mode" register into a new "configuration" register.
Differences not supported by this driver include separate interrupt lines for each watchdog, instead of sharing an interrupt line and registers with the timer block.
--- drivers/watchdog/sunxi_wdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/watchdog/sunxi_wdt.c +10 -0
@@ -219,8 +219,18 @@ static const struct sunxi_wdt_reg sun4i_wdt_reg = { .wdt_reset_val = 0x02, }; +static const struct sunxi_wdt_reg sun6i_wdt_reg = { + .wdt_ctrl =0x10 , + .wdt_cfg =0x14 , + .wdt_mode =0x18 , + .wdt_timeout_shift =4 , + .wdt_reset_mask =0x03 , + .wdt_reset_val =0x01 , +}; +static const struct of_device_id sunxi_wdt_dt_ids[] = { { .compatible ="allwinner,sun4i-a10-wdt" , .data = &sun4i_wdt_reg }, + { .compatible ="allwinner,sun6i-a31-wdt" , .data = &sun6i_wdt_reg }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, sunxi_wdt_dt_ids);
Signature · 1 line
2.1.0
Guenter Roeck
maintainerPATCH v2 2/2 watchdog: sunxi: Add A31 watchdog support
Quoted 10 lines · Chen-Yu Tsai
This patch adds support for the watchdog hardware found in A31 and newer SoCs. This new hardware has registers at different offsets, and the system reset control has been split out of the "mode" register into a new "configuration" register.
Differences not supported by this driver include separate interrupt lines for each watchdog, instead of sharing an interrupt line and registers with the timer block.
Signed-off-by Chen-Yu Tsai <[email protected]>
v2 cover watchdog: sunxi: Add A31 watchdog support
In reply to Chen-Yu TsaiHi,
Quoted 19 lines · Chen-Yu Tsai
Hi,
This is v2 of the Allwinner A31 watchdog support series. This series adds support for the watchdog hardware found in Allwinner A31 and later SoCs. These new chips have multiple watchdogs, with separate interrupt lines and registers, but the basic layout and operation is the same. This series is based on Guenter's restart handler series.
Patch 1 prepares the sunxi-wdt driver for varying register offsets tied to compatible strings. Various ioread32/iowrite32 calls have been replaced with readl/writel as well.
Patch 2 adds the sun6i compatible string with accompanying register offset data.
I tested this series on my Cubieboard (sun4i) and A23 tablet (sun8i), which has the same watchdog hardware as the A31 (sun6i). This covers the 2 classes of hardware supported.
Quoted 5 lines
After this series is merged, we can remove the power/reset driver for sun6i.
Changes since v1:
- Mention replacing ioread32/iowrite32 calls in patch 1 commit message.
On the whole series,
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140921/5f1178ab/attachment.sig>