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> |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <wdt.h> |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 9 | #include <mpc8xx.h> |
| 10 | #include <asm/cpm_8xx.h> |
| 11 | #include <asm/io.h> |
| 12 | |
Christophe Leroy | a682560 | 2020-02-20 07:39:51 +0000 | [diff] [blame] | 13 | void hw_watchdog_reset(void) |
Christophe Leroy | c0bc2a7 | 2018-03-16 17:21:01 +0100 | [diff] [blame] | 14 | { |
| 15 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 16 | |
| 17 | out_be16(&immap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */ |
| 18 | out_be16(&immap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */ |
| 19 | } |
| 20 | |
Christophe Leroy | 749c9aa | 2018-11-21 08:51:45 +0000 | [diff] [blame] | 21 | static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, ulong flags) |
| 22 | { |
| 23 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 24 | |
| 25 | out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR); |
| 26 | |
| 27 | if (!(in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE)) |
| 28 | return -EBUSY; |
| 29 | return 0; |
| 30 | |
| 31 | } |
| 32 | |
| 33 | static int mpc8xx_wdt_stop(struct udevice *dev) |
| 34 | { |
| 35 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 36 | |
| 37 | out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & ~SYPCR_SWE); |
| 38 | |
| 39 | if (in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE) |
| 40 | return -EBUSY; |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int mpc8xx_wdt_reset(struct udevice *dev) |
| 45 | { |
| 46 | hw_watchdog_reset(); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static const struct wdt_ops mpc8xx_wdt_ops = { |
| 52 | .start = mpc8xx_wdt_start, |
| 53 | .reset = mpc8xx_wdt_reset, |
| 54 | .stop = mpc8xx_wdt_stop, |
| 55 | }; |
| 56 | |
| 57 | static const struct udevice_id mpc8xx_wdt_ids[] = { |
| 58 | { .compatible = "fsl,pq1-wdt" }, |
| 59 | {} |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DRIVER(wdt_mpc8xx) = { |
| 63 | .name = "wdt_mpc8xx", |
| 64 | .id = UCLASS_WDT, |
| 65 | .of_match = mpc8xx_wdt_ids, |
| 66 | .ops = &mpc8xx_wdt_ops, |
| 67 | }; |