1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Watchdog timer for PowerPC Book-E systems
9 #include <asm/processor.h>
11 #define WDTP_MASK TCR_WP(0x3f)
13 /* For the specified period, determine the number of seconds
14 * corresponding to the reset time. There will be a watchdog
15 * exception at approximately 3/5 of this time.
17 * The formula to calculate this is given by:
18 * 2.5 * (2^(63-period+1)) / timebase_freq
20 * In order to simplify things, we assume that period is
21 * at least 1. This will still result in a very long timeout.
23 static unsigned long long period_to_sec(unsigned int period)
25 unsigned long long tmp = 1ULL << (64 - period);
26 unsigned long tmp2 = get_tbclk();
28 /* tmp may be a very large number and we don't want to overflow,
29 * so divide the timebase freq instead of multiplying tmp
38 * This procedure will find the highest period which will give a timeout
39 * greater than the one required. e.g. for a bus speed of 66666666 and
40 * and a parameter of 2 secs, then this procedure will return a value of 38.
42 static unsigned int sec_to_period(unsigned int secs)
46 for (period = 63; period > 0; period--) {
47 if (period_to_sec(period) >= secs)
53 static int booke_wdt_reset(struct udevice *dev)
55 mtspr(SPRN_TSR, TSR_ENW | TSR_WIS);
60 static int booke_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
63 unsigned int timeout = DIV_ROUND_UP(timeout_ms, 1000);
65 /* clear status before enabling watchdog */
67 val = mfspr(SPRN_TCR);
69 val |= (TCR_WIE | TCR_WRC(WRC_CHIP) | TCR_WP(sec_to_period(timeout)));
76 static int booke_wdt_stop(struct udevice *dev)
80 val = mfspr(SPRN_TCR);
81 val &= ~(TCR_WIE | WDTP_MASK);
84 /* clear status to make sure nothing is pending */
90 static const struct wdt_ops booke_wdt_ops = {
91 .start = booke_wdt_start,
92 .stop = booke_wdt_stop,
93 .reset = booke_wdt_reset,
96 static const struct udevice_id booke_wdt_ids[] = {
97 { .compatible = "fsl,booke-wdt" },
101 U_BOOT_DRIVER(booke_wdt) = {
104 .of_match = booke_wdt_ids,
105 .ops = &booke_wdt_ops,