blob: c24c2a9da6dcc674076ac36cfd09c35bf5ef11f4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroyc0bc2a72018-03-16 17:21:01 +01002/*
3 * Copyright 2017 CS Systemes d'Information
Christophe Leroyc0bc2a72018-03-16 17:21:01 +01004 */
5
6#include <common.h>
Christophe Leroy749c9aa2018-11-21 08:51:45 +00007#include <dm.h>
8#include <wdt.h>
Christophe Leroyc0bc2a72018-03-16 17:21:01 +01009#include <mpc8xx.h>
10#include <asm/cpm_8xx.h>
11#include <asm/io.h>
12
Christophe Leroyc0bc2a72018-03-16 17:21:01 +010013void hw_watchdog_reset(void)
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 Leroy749c9aa2018-11-21 08:51:45 +000021#ifdef CONFIG_WDT_MPC8xx
22static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
23{
24 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
25
26 out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR);
27
28 if (!(in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE))
29 return -EBUSY;
30 return 0;
31
32}
33
34static int mpc8xx_wdt_stop(struct udevice *dev)
35{
36 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
37
38 out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & ~SYPCR_SWE);
39
40 if (in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE)
41 return -EBUSY;
42 return 0;
43}
44
45static int mpc8xx_wdt_reset(struct udevice *dev)
46{
47 hw_watchdog_reset();
48
49 return 0;
50}
51
52static const struct wdt_ops mpc8xx_wdt_ops = {
53 .start = mpc8xx_wdt_start,
54 .reset = mpc8xx_wdt_reset,
55 .stop = mpc8xx_wdt_stop,
56};
57
58static const struct udevice_id mpc8xx_wdt_ids[] = {
59 { .compatible = "fsl,pq1-wdt" },
60 {}
61};
62
63U_BOOT_DRIVER(wdt_mpc8xx) = {
64 .name = "wdt_mpc8xx",
65 .id = UCLASS_WDT,
66 .of_match = mpc8xx_wdt_ids,
67 .ops = &mpc8xx_wdt_ops,
68};
69#endif /* CONFIG_WDT_MPC8xx */