Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 CS Systemes d'Information |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Charles Frey | ea8de98 | 2020-02-19 16:50:15 +0000 | [diff] [blame] | 7 | #include <env.h> |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <wdt.h> |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 10 | #include <mpc8xx.h> |
| 11 | #include <asm/cpm_8xx.h> |
| 12 | #include <asm/io.h> |
| 13 | |
Christophe Leroy | a682560 | 2020-02-20 07:39:51 +0000 | [diff] [blame] | 14 | void hw_watchdog_reset(void) |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 15 | { |
| 16 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 17 | |
| 18 | out_be16(&immap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */ |
| 19 | out_be16(&immap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */ |
| 20 | } |
| 21 | |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 22 | static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, ulong flags) |
| 23 | { |
| 24 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Charles Frey | ea8de98 | 2020-02-19 16:50:15 +0000 | [diff] [blame] | 25 | u32 val = CONFIG_SYS_SYPCR; |
| 26 | const char *mode = env_get("watchdog_mode"); |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 27 | |
Charles Frey | ea8de98 | 2020-02-19 16:50:15 +0000 | [diff] [blame] | 28 | if (strcmp(mode, "off") == 0) |
| 29 | val = val & ~(SYPCR_SWE | SYPCR_SWRI); |
| 30 | else if (strcmp(mode, "nmi") == 0) |
| 31 | val = (val & ~SYPCR_SWRI) | SYPCR_SWE; |
| 32 | |
| 33 | out_be32(&immap->im_siu_conf.sc_sypcr, val); |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 34 | |
| 35 | if (!(in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE)) |
| 36 | return -EBUSY; |
| 37 | return 0; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | static int mpc8xx_wdt_stop(struct udevice *dev) |
| 42 | { |
| 43 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 44 | |
| 45 | out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & ~SYPCR_SWE); |
| 46 | |
| 47 | if (in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE) |
| 48 | return -EBUSY; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int mpc8xx_wdt_reset(struct udevice *dev) |
| 53 | { |
| 54 | hw_watchdog_reset(); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static const struct wdt_ops mpc8xx_wdt_ops = { |
| 60 | .start = mpc8xx_wdt_start, |
| 61 | .reset = mpc8xx_wdt_reset, |
| 62 | .stop = mpc8xx_wdt_stop, |
| 63 | }; |
| 64 | |
| 65 | static const struct udevice_id mpc8xx_wdt_ids[] = { |
| 66 | { .compatible = "fsl,pq1-wdt" }, |
| 67 | {} |
| 68 | }; |
| 69 | |
| 70 | U_BOOT_DRIVER(wdt_mpc8xx) = { |
| 71 | .name = "wdt_mpc8xx", |
| 72 | .id = UCLASS_WDT, |
| 73 | .of_match = mpc8xx_wdt_ids, |
| 74 | .ops = &mpc8xx_wdt_ops, |
| 75 | }; |