183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
20753bc2dSmaxims@google.com /*
30753bc2dSmaxims@google.com * Copyright 2017 Google, Inc
40753bc2dSmaxims@google.com */
50753bc2dSmaxims@google.com
60753bc2dSmaxims@google.com #include <common.h>
70753bc2dSmaxims@google.com #include <dm.h>
80753bc2dSmaxims@google.com #include <errno.h>
90753bc2dSmaxims@google.com #include <wdt.h>
100753bc2dSmaxims@google.com #include <dm/device-internal.h>
110753bc2dSmaxims@google.com #include <dm/lists.h>
120753bc2dSmaxims@google.com
wdt_start(struct udevice * dev,u64 timeout_ms,ulong flags)13ffdec300SAndy Shevchenko int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
140753bc2dSmaxims@google.com {
150753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
160753bc2dSmaxims@google.com
170753bc2dSmaxims@google.com if (!ops->start)
180753bc2dSmaxims@google.com return -ENOSYS;
190753bc2dSmaxims@google.com
20ffdec300SAndy Shevchenko return ops->start(dev, timeout_ms, flags);
210753bc2dSmaxims@google.com }
220753bc2dSmaxims@google.com
wdt_stop(struct udevice * dev)230753bc2dSmaxims@google.com int wdt_stop(struct udevice *dev)
240753bc2dSmaxims@google.com {
250753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
260753bc2dSmaxims@google.com
270753bc2dSmaxims@google.com if (!ops->stop)
280753bc2dSmaxims@google.com return -ENOSYS;
290753bc2dSmaxims@google.com
300753bc2dSmaxims@google.com return ops->stop(dev);
310753bc2dSmaxims@google.com }
320753bc2dSmaxims@google.com
wdt_reset(struct udevice * dev)330753bc2dSmaxims@google.com int wdt_reset(struct udevice *dev)
340753bc2dSmaxims@google.com {
350753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
360753bc2dSmaxims@google.com
370753bc2dSmaxims@google.com if (!ops->reset)
380753bc2dSmaxims@google.com return -ENOSYS;
390753bc2dSmaxims@google.com
400753bc2dSmaxims@google.com return ops->reset(dev);
410753bc2dSmaxims@google.com }
420753bc2dSmaxims@google.com
wdt_expire_now(struct udevice * dev,ulong flags)430753bc2dSmaxims@google.com int wdt_expire_now(struct udevice *dev, ulong flags)
440753bc2dSmaxims@google.com {
450753bc2dSmaxims@google.com int ret = 0;
460753bc2dSmaxims@google.com const struct wdt_ops *ops;
470753bc2dSmaxims@google.com
48b71e0c1aSAndy Shevchenko debug("WDT Resetting: %lu\n", flags);
490753bc2dSmaxims@google.com ops = device_get_ops(dev);
500753bc2dSmaxims@google.com if (ops->expire_now) {
510753bc2dSmaxims@google.com return ops->expire_now(dev, flags);
520753bc2dSmaxims@google.com } else {
530753bc2dSmaxims@google.com if (!ops->start)
540753bc2dSmaxims@google.com return -ENOSYS;
550753bc2dSmaxims@google.com
560753bc2dSmaxims@google.com ret = ops->start(dev, 1, flags);
570753bc2dSmaxims@google.com if (ret < 0)
580753bc2dSmaxims@google.com return ret;
590753bc2dSmaxims@google.com
600753bc2dSmaxims@google.com hang();
610753bc2dSmaxims@google.com }
620753bc2dSmaxims@google.com
630753bc2dSmaxims@google.com return ret;
640753bc2dSmaxims@google.com }
650753bc2dSmaxims@google.com
wdt_post_bind(struct udevice * dev)66*f238b3f0SMichal Simek static int wdt_post_bind(struct udevice *dev)
67*f238b3f0SMichal Simek {
68*f238b3f0SMichal Simek #if defined(CONFIG_NEEDS_MANUAL_RELOC)
69*f238b3f0SMichal Simek struct wdt_ops *ops = (struct wdt_ops *)device_get_ops(dev);
70*f238b3f0SMichal Simek static int reloc_done;
71*f238b3f0SMichal Simek
72*f238b3f0SMichal Simek if (!reloc_done) {
73*f238b3f0SMichal Simek if (ops->start)
74*f238b3f0SMichal Simek ops->start += gd->reloc_off;
75*f238b3f0SMichal Simek if (ops->stop)
76*f238b3f0SMichal Simek ops->stop += gd->reloc_off;
77*f238b3f0SMichal Simek if (ops->reset)
78*f238b3f0SMichal Simek ops->reset += gd->reloc_off;
79*f238b3f0SMichal Simek if (ops->expire_now)
80*f238b3f0SMichal Simek ops->expire_now += gd->reloc_off;
81*f238b3f0SMichal Simek
82*f238b3f0SMichal Simek reloc_done++;
83*f238b3f0SMichal Simek }
84*f238b3f0SMichal Simek #endif
85*f238b3f0SMichal Simek return 0;
86*f238b3f0SMichal Simek }
87*f238b3f0SMichal Simek
880753bc2dSmaxims@google.com UCLASS_DRIVER(wdt) = {
890753bc2dSmaxims@google.com .id = UCLASS_WDT,
909713fac1SMichal Simek .name = "watchdog",
919713fac1SMichal Simek .flags = DM_UC_FLAG_SEQ_ALIAS,
92*f238b3f0SMichal Simek .post_bind = wdt_post_bind,
930753bc2dSmaxims@google.com };
94