xref: /openbmc/linux/drivers/watchdog/rti_wdt.c (revision 278002edb19bce2c628fafb0af936e77000f3a5b)
12d63908bSTero Kristo // SPDX-License-Identifier: GPL-2.0
22d63908bSTero Kristo /*
32d63908bSTero Kristo  * Watchdog driver for the K3 RTI module
42d63908bSTero Kristo  *
52d63908bSTero Kristo  * (c) Copyright 2019-2020 Texas Instruments Inc.
62d63908bSTero Kristo  * All rights reserved.
72d63908bSTero Kristo  */
82d63908bSTero Kristo 
92d63908bSTero Kristo #include <linux/clk.h>
102d63908bSTero Kristo #include <linux/device.h>
112d63908bSTero Kristo #include <linux/err.h>
122d63908bSTero Kristo #include <linux/io.h>
132d63908bSTero Kristo #include <linux/kernel.h>
142d63908bSTero Kristo #include <linux/mod_devicetable.h>
152d63908bSTero Kristo #include <linux/module.h>
162d63908bSTero Kristo #include <linux/moduleparam.h>
17f20ca595SLi Hua Qian #include <linux/of.h>
18f20ca595SLi Hua Qian #include <linux/of_address.h>
192d63908bSTero Kristo #include <linux/platform_device.h>
202d63908bSTero Kristo #include <linux/pm_runtime.h>
212d63908bSTero Kristo #include <linux/types.h>
222d63908bSTero Kristo #include <linux/watchdog.h>
232d63908bSTero Kristo 
242d63908bSTero Kristo #define DEFAULT_HEARTBEAT 60
252d63908bSTero Kristo 
262d63908bSTero Kristo /* Max heartbeat is calculated at 32kHz source clock */
272d63908bSTero Kristo #define MAX_HEARTBEAT	1000
282d63908bSTero Kristo 
292d63908bSTero Kristo /* Timer register set definition */
302d63908bSTero Kristo #define RTIDWDCTRL	0x90
312d63908bSTero Kristo #define RTIDWDPRLD	0x94
322d63908bSTero Kristo #define RTIWDSTATUS	0x98
332d63908bSTero Kristo #define RTIWDKEY	0x9c
342d63908bSTero Kristo #define RTIDWDCNTR	0xa0
352d63908bSTero Kristo #define RTIWWDRXCTRL	0xa4
362d63908bSTero Kristo #define RTIWWDSIZECTRL	0xa8
372d63908bSTero Kristo 
382d63908bSTero Kristo #define RTIWWDRX_NMI	0xa
392d63908bSTero Kristo 
402d63908bSTero Kristo #define RTIWWDSIZE_50P		0x50
415527483fSTero Kristo #define RTIWWDSIZE_25P		0x500
425527483fSTero Kristo #define RTIWWDSIZE_12P5		0x5000
435527483fSTero Kristo #define RTIWWDSIZE_6P25		0x50000
445527483fSTero Kristo #define RTIWWDSIZE_3P125	0x500000
452d63908bSTero Kristo 
462d63908bSTero Kristo #define WDENABLE_KEY	0xa98559da
472d63908bSTero Kristo 
482d63908bSTero Kristo #define WDKEY_SEQ0		0xe51a
492d63908bSTero Kristo #define WDKEY_SEQ1		0xa35c
502d63908bSTero Kristo 
512d63908bSTero Kristo #define WDT_PRELOAD_SHIFT	13
522d63908bSTero Kristo 
532d63908bSTero Kristo #define WDT_PRELOAD_MAX		0xfff
542d63908bSTero Kristo 
552d63908bSTero Kristo #define DWDST			BIT(1)
562d63908bSTero Kristo 
57f20ca595SLi Hua Qian #define PON_REASON_SOF_NUM	0xBBBBCCCC
58f20ca595SLi Hua Qian #define PON_REASON_MAGIC_NUM	0xDDDDDDDD
59f20ca595SLi Hua Qian #define PON_REASON_EOF_NUM	0xCCCCBBBB
60f20ca595SLi Hua Qian #define RESERVED_MEM_MIN_SIZE	12
61f20ca595SLi Hua Qian 
628b732150SJudith Mendez #define MAX_HW_ERROR		250
638b732150SJudith Mendez 
64*7015d9d4SAlexander Sverdlin static int heartbeat;
652d63908bSTero Kristo 
662d63908bSTero Kristo /*
672d63908bSTero Kristo  * struct to hold data for each WDT device
682d63908bSTero Kristo  * @base - base io address of WD device
692d63908bSTero Kristo  * @freq - source clock frequency of WDT
702d63908bSTero Kristo  * @wdd  - hold watchdog device as is in WDT core
712d63908bSTero Kristo  */
722d63908bSTero Kristo struct rti_wdt_device {
732d63908bSTero Kristo 	void __iomem		*base;
742d63908bSTero Kristo 	unsigned long		freq;
752d63908bSTero Kristo 	struct watchdog_device	wdd;
762d63908bSTero Kristo };
772d63908bSTero Kristo 
rti_wdt_start(struct watchdog_device * wdd)782d63908bSTero Kristo static int rti_wdt_start(struct watchdog_device *wdd)
792d63908bSTero Kristo {
802d63908bSTero Kristo 	u32 timer_margin;
812d63908bSTero Kristo 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
82f2c13661SVignesh Raghavendra 	int ret;
83f2c13661SVignesh Raghavendra 
84f2c13661SVignesh Raghavendra 	ret = pm_runtime_resume_and_get(wdd->parent);
85f2c13661SVignesh Raghavendra 	if (ret)
86f2c13661SVignesh Raghavendra 		return ret;
872d63908bSTero Kristo 
882d63908bSTero Kristo 	/* set timeout period */
892d63908bSTero Kristo 	timer_margin = (u64)wdd->timeout * wdt->freq;
902d63908bSTero Kristo 	timer_margin >>= WDT_PRELOAD_SHIFT;
912d63908bSTero Kristo 	if (timer_margin > WDT_PRELOAD_MAX)
922d63908bSTero Kristo 		timer_margin = WDT_PRELOAD_MAX;
932d63908bSTero Kristo 	writel_relaxed(timer_margin, wdt->base + RTIDWDPRLD);
942d63908bSTero Kristo 
952d63908bSTero Kristo 	/*
962d63908bSTero Kristo 	 * RTI only supports a windowed mode, where the watchdog can only
972d63908bSTero Kristo 	 * be petted during the open window; not too early or not too late.
982d63908bSTero Kristo 	 * The HW configuration options only allow for the open window size
992d63908bSTero Kristo 	 * to be 50% or less than that; we obviouly want to configure the open
1005527483fSTero Kristo 	 * window as large as possible so we select the 50% option.
1012d63908bSTero Kristo 	 */
1028b732150SJudith Mendez 	wdd->min_hw_heartbeat_ms = 520 * wdd->timeout + MAX_HW_ERROR;
1032d63908bSTero Kristo 
1042d63908bSTero Kristo 	/* Generate NMI when wdt expires */
1052d63908bSTero Kristo 	writel_relaxed(RTIWWDRX_NMI, wdt->base + RTIWWDRXCTRL);
1062d63908bSTero Kristo 
1072d63908bSTero Kristo 	/* Open window size 50%; this is the largest window size available */
1082d63908bSTero Kristo 	writel_relaxed(RTIWWDSIZE_50P, wdt->base + RTIWWDSIZECTRL);
1092d63908bSTero Kristo 
1102d63908bSTero Kristo 	readl_relaxed(wdt->base + RTIWWDSIZECTRL);
1112d63908bSTero Kristo 
1122d63908bSTero Kristo 	/* enable watchdog */
1132d63908bSTero Kristo 	writel_relaxed(WDENABLE_KEY, wdt->base + RTIDWDCTRL);
1142d63908bSTero Kristo 	return 0;
1152d63908bSTero Kristo }
1162d63908bSTero Kristo 
rti_wdt_ping(struct watchdog_device * wdd)1172d63908bSTero Kristo static int rti_wdt_ping(struct watchdog_device *wdd)
1182d63908bSTero Kristo {
1192d63908bSTero Kristo 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
1202d63908bSTero Kristo 
1212d63908bSTero Kristo 	/* put watchdog in service state */
1222d63908bSTero Kristo 	writel_relaxed(WDKEY_SEQ0, wdt->base + RTIWDKEY);
1232d63908bSTero Kristo 	/* put watchdog in active state */
1242d63908bSTero Kristo 	writel_relaxed(WDKEY_SEQ1, wdt->base + RTIWDKEY);
1252d63908bSTero Kristo 
1262d63908bSTero Kristo 	return 0;
1272d63908bSTero Kristo }
1282d63908bSTero Kristo 
rti_wdt_setup_hw_hb(struct watchdog_device * wdd,u32 wsize)1295527483fSTero Kristo static int rti_wdt_setup_hw_hb(struct watchdog_device *wdd, u32 wsize)
1305527483fSTero Kristo {
1315527483fSTero Kristo 	/*
1325527483fSTero Kristo 	 * RTI only supports a windowed mode, where the watchdog can only
1335527483fSTero Kristo 	 * be petted during the open window; not too early or not too late.
1345527483fSTero Kristo 	 * The HW configuration options only allow for the open window size
1355527483fSTero Kristo 	 * to be 50% or less than that.
1368b732150SJudith Mendez 	 * To avoid any glitches, we accommodate 2% + max hardware error
1378b732150SJudith Mendez 	 * safety margin.
1385527483fSTero Kristo 	 */
1395527483fSTero Kristo 	switch (wsize) {
1405527483fSTero Kristo 	case RTIWWDSIZE_50P:
1418b732150SJudith Mendez 		/* 50% open window => 52% min heartbeat */
1428b732150SJudith Mendez 		wdd->min_hw_heartbeat_ms = 520 * heartbeat + MAX_HW_ERROR;
1435527483fSTero Kristo 		break;
1445527483fSTero Kristo 
1455527483fSTero Kristo 	case RTIWWDSIZE_25P:
1468b732150SJudith Mendez 		/* 25% open window => 77% min heartbeat */
1478b732150SJudith Mendez 		wdd->min_hw_heartbeat_ms = 770 * heartbeat + MAX_HW_ERROR;
1485527483fSTero Kristo 		break;
1495527483fSTero Kristo 
1505527483fSTero Kristo 	case RTIWWDSIZE_12P5:
1518b732150SJudith Mendez 		/* 12.5% open window => 89.5% min heartbeat */
1528b732150SJudith Mendez 		wdd->min_hw_heartbeat_ms = 895 * heartbeat + MAX_HW_ERROR;
1535527483fSTero Kristo 		break;
1545527483fSTero Kristo 
1555527483fSTero Kristo 	case RTIWWDSIZE_6P25:
1568b732150SJudith Mendez 		/* 6.5% open window => 95.5% min heartbeat */
1578b732150SJudith Mendez 		wdd->min_hw_heartbeat_ms = 955 * heartbeat + MAX_HW_ERROR;
1585527483fSTero Kristo 		break;
1595527483fSTero Kristo 
1605527483fSTero Kristo 	case RTIWWDSIZE_3P125:
1618b732150SJudith Mendez 		/* 3.125% open window => 98.9% min heartbeat */
1628b732150SJudith Mendez 		wdd->min_hw_heartbeat_ms = 989 * heartbeat + MAX_HW_ERROR;
1635527483fSTero Kristo 		break;
1645527483fSTero Kristo 
1655527483fSTero Kristo 	default:
1665527483fSTero Kristo 		return -EINVAL;
1675527483fSTero Kristo 	}
1685527483fSTero Kristo 
1695527483fSTero Kristo 	return 0;
1705527483fSTero Kristo }
1715527483fSTero Kristo 
rti_wdt_get_timeleft_ms(struct watchdog_device * wdd)1725527483fSTero Kristo static unsigned int rti_wdt_get_timeleft_ms(struct watchdog_device *wdd)
1732d63908bSTero Kristo {
1742d63908bSTero Kristo 	u64 timer_counter;
1752d63908bSTero Kristo 	u32 val;
1762d63908bSTero Kristo 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
1772d63908bSTero Kristo 
1782d63908bSTero Kristo 	/* if timeout has occurred then return 0 */
1792d63908bSTero Kristo 	val = readl_relaxed(wdt->base + RTIWDSTATUS);
1802d63908bSTero Kristo 	if (val & DWDST)
1812d63908bSTero Kristo 		return 0;
1822d63908bSTero Kristo 
1832d63908bSTero Kristo 	timer_counter = readl_relaxed(wdt->base + RTIDWDCNTR);
1842d63908bSTero Kristo 
1855527483fSTero Kristo 	timer_counter *= 1000;
1865527483fSTero Kristo 
1872d63908bSTero Kristo 	do_div(timer_counter, wdt->freq);
1882d63908bSTero Kristo 
1892d63908bSTero Kristo 	return timer_counter;
1902d63908bSTero Kristo }
1912d63908bSTero Kristo 
rti_wdt_get_timeleft(struct watchdog_device * wdd)1925527483fSTero Kristo static unsigned int rti_wdt_get_timeleft(struct watchdog_device *wdd)
1935527483fSTero Kristo {
1945527483fSTero Kristo 	return rti_wdt_get_timeleft_ms(wdd) / 1000;
1955527483fSTero Kristo }
1965527483fSTero Kristo 
1972d63908bSTero Kristo static const struct watchdog_info rti_wdt_info = {
1982d63908bSTero Kristo 	.options = WDIOF_KEEPALIVEPING,
1992d63908bSTero Kristo 	.identity = "K3 RTI Watchdog",
2002d63908bSTero Kristo };
2012d63908bSTero Kristo 
2022d63908bSTero Kristo static const struct watchdog_ops rti_wdt_ops = {
2032d63908bSTero Kristo 	.owner		= THIS_MODULE,
2042d63908bSTero Kristo 	.start		= rti_wdt_start,
2052d63908bSTero Kristo 	.ping		= rti_wdt_ping,
2062d63908bSTero Kristo 	.get_timeleft	= rti_wdt_get_timeleft,
2072d63908bSTero Kristo };
2082d63908bSTero Kristo 
rti_wdt_probe(struct platform_device * pdev)2092d63908bSTero Kristo static int rti_wdt_probe(struct platform_device *pdev)
2102d63908bSTero Kristo {
2112d63908bSTero Kristo 	int ret = 0;
2122d63908bSTero Kristo 	struct device *dev = &pdev->dev;
2132d63908bSTero Kristo 	struct watchdog_device *wdd;
2142d63908bSTero Kristo 	struct rti_wdt_device *wdt;
2152d63908bSTero Kristo 	struct clk *clk;
2165527483fSTero Kristo 	u32 last_ping = 0;
217f20ca595SLi Hua Qian 	struct device_node *node;
218f20ca595SLi Hua Qian 	u32 reserved_mem_size;
219f20ca595SLi Hua Qian 	struct resource res;
220f20ca595SLi Hua Qian 	u32 *vaddr;
221f20ca595SLi Hua Qian 	u64 paddr;
2222d63908bSTero Kristo 
2232d63908bSTero Kristo 	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
2242d63908bSTero Kristo 	if (!wdt)
2252d63908bSTero Kristo 		return -ENOMEM;
2262d63908bSTero Kristo 
2272d63908bSTero Kristo 	clk = clk_get(dev, NULL);
228d342951bSKrzysztof Kozlowski 	if (IS_ERR(clk))
229d342951bSKrzysztof Kozlowski 		return dev_err_probe(dev, PTR_ERR(clk), "failed to get clock\n");
2302d63908bSTero Kristo 
2312d63908bSTero Kristo 	wdt->freq = clk_get_rate(clk);
2322d63908bSTero Kristo 
2332d63908bSTero Kristo 	clk_put(clk);
2342d63908bSTero Kristo 
2352d63908bSTero Kristo 	if (!wdt->freq) {
2362d63908bSTero Kristo 		dev_err(dev, "Failed to get fck rate.\n");
2372d63908bSTero Kristo 		return -EINVAL;
2382d63908bSTero Kristo 	}
2392d63908bSTero Kristo 
2402d63908bSTero Kristo 	pm_runtime_enable(dev);
241a1f136fdSye xingchen 	ret = pm_runtime_resume_and_get(dev);
242b3ac0c58SMiaoqian Lin 	if (ret < 0) {
243d055ef3aSMiaoqian Lin 		pm_runtime_disable(&pdev->dev);
244d342951bSKrzysztof Kozlowski 		return dev_err_probe(dev, ret, "runtime pm failed\n");
2458711071eSZhang Qilong 	}
2462d63908bSTero Kristo 
2472d63908bSTero Kristo 	platform_set_drvdata(pdev, wdt);
2482d63908bSTero Kristo 
2492d63908bSTero Kristo 	wdd = &wdt->wdd;
2502d63908bSTero Kristo 	wdd->info = &rti_wdt_info;
2512d63908bSTero Kristo 	wdd->ops = &rti_wdt_ops;
2522d63908bSTero Kristo 	wdd->min_timeout = 1;
2532d63908bSTero Kristo 	wdd->max_hw_heartbeat_ms = (WDT_PRELOAD_MAX << WDT_PRELOAD_SHIFT) /
2542d63908bSTero Kristo 		wdt->freq * 1000;
255*7015d9d4SAlexander Sverdlin 	wdd->timeout = DEFAULT_HEARTBEAT;
2562d63908bSTero Kristo 	wdd->parent = dev;
2572d63908bSTero Kristo 
2582d63908bSTero Kristo 	watchdog_set_drvdata(wdd, wdt);
2592d63908bSTero Kristo 	watchdog_set_nowayout(wdd, 1);
2602d63908bSTero Kristo 	watchdog_set_restart_priority(wdd, 128);
2612d63908bSTero Kristo 
262b3220bdeSCai Huoqing 	wdt->base = devm_platform_ioremap_resource(pdev, 0);
2632d63908bSTero Kristo 	if (IS_ERR(wdt->base)) {
2642d63908bSTero Kristo 		ret = PTR_ERR(wdt->base);
2652d63908bSTero Kristo 		goto err_iomap;
2662d63908bSTero Kristo 	}
2672d63908bSTero Kristo 
2685527483fSTero Kristo 	if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) {
269c83f6438SJan Kiszka 		int preset_heartbeat;
2705527483fSTero Kristo 		u32 time_left_ms;
2715527483fSTero Kristo 		u64 heartbeat_ms;
2725527483fSTero Kristo 		u32 wsize;
2735527483fSTero Kristo 
2745527483fSTero Kristo 		set_bit(WDOG_HW_RUNNING, &wdd->status);
2755527483fSTero Kristo 		time_left_ms = rti_wdt_get_timeleft_ms(wdd);
2765527483fSTero Kristo 		heartbeat_ms = readl(wdt->base + RTIDWDPRLD);
2775527483fSTero Kristo 		heartbeat_ms <<= WDT_PRELOAD_SHIFT;
2785527483fSTero Kristo 		heartbeat_ms *= 1000;
2795527483fSTero Kristo 		do_div(heartbeat_ms, wdt->freq);
280c83f6438SJan Kiszka 		preset_heartbeat = heartbeat_ms + 500;
281c83f6438SJan Kiszka 		preset_heartbeat /= 1000;
282c83f6438SJan Kiszka 		if (preset_heartbeat != heartbeat)
2835527483fSTero Kristo 			dev_warn(dev, "watchdog already running, ignoring heartbeat config!\n");
2845527483fSTero Kristo 
285c83f6438SJan Kiszka 		heartbeat = preset_heartbeat;
2865527483fSTero Kristo 
2875527483fSTero Kristo 		wsize = readl(wdt->base + RTIWWDSIZECTRL);
2885527483fSTero Kristo 		ret = rti_wdt_setup_hw_hb(wdd, wsize);
2895527483fSTero Kristo 		if (ret) {
2905527483fSTero Kristo 			dev_err(dev, "bad window size.\n");
2915527483fSTero Kristo 			goto err_iomap;
2925527483fSTero Kristo 		}
2935527483fSTero Kristo 
2945527483fSTero Kristo 		last_ping = heartbeat_ms - time_left_ms;
2955527483fSTero Kristo 		if (time_left_ms > heartbeat_ms) {
2965527483fSTero Kristo 			dev_warn(dev, "time_left > heartbeat? Assuming last ping just before now.\n");
2975527483fSTero Kristo 			last_ping = 0;
2985527483fSTero Kristo 		}
2995527483fSTero Kristo 	}
3005527483fSTero Kristo 
301f20ca595SLi Hua Qian 	node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
302f20ca595SLi Hua Qian 	if (node) {
303f20ca595SLi Hua Qian 		ret = of_address_to_resource(node, 0, &res);
304f20ca595SLi Hua Qian 		if (ret) {
305f20ca595SLi Hua Qian 			dev_err(dev, "No memory address assigned to the region.\n");
306f20ca595SLi Hua Qian 			goto err_iomap;
307f20ca595SLi Hua Qian 		}
308f20ca595SLi Hua Qian 
309f20ca595SLi Hua Qian 		/*
310f20ca595SLi Hua Qian 		 * If reserved memory is defined for watchdog reset cause.
311f20ca595SLi Hua Qian 		 * Readout the Power-on(PON) reason and pass to bootstatus.
312f20ca595SLi Hua Qian 		 */
313f20ca595SLi Hua Qian 		paddr = res.start;
314f20ca595SLi Hua Qian 		reserved_mem_size = resource_size(&res);
315f20ca595SLi Hua Qian 		if (reserved_mem_size < RESERVED_MEM_MIN_SIZE) {
316f20ca595SLi Hua Qian 			dev_err(dev, "The size of reserved memory is too small.\n");
317f20ca595SLi Hua Qian 			ret = -EINVAL;
318f20ca595SLi Hua Qian 			goto err_iomap;
319f20ca595SLi Hua Qian 		}
320f20ca595SLi Hua Qian 
321f20ca595SLi Hua Qian 		vaddr = memremap(paddr, reserved_mem_size, MEMREMAP_WB);
322f20ca595SLi Hua Qian 		if (!vaddr) {
323f20ca595SLi Hua Qian 			dev_err(dev, "Failed to map memory-region.\n");
324f20ca595SLi Hua Qian 			ret = -ENOMEM;
325f20ca595SLi Hua Qian 			goto err_iomap;
326f20ca595SLi Hua Qian 		}
327f20ca595SLi Hua Qian 
328f20ca595SLi Hua Qian 		if (vaddr[0] == PON_REASON_SOF_NUM &&
329f20ca595SLi Hua Qian 		    vaddr[1] == PON_REASON_MAGIC_NUM &&
330f20ca595SLi Hua Qian 		    vaddr[2] == PON_REASON_EOF_NUM) {
331f20ca595SLi Hua Qian 			wdd->bootstatus |= WDIOF_CARDRESET;
332f20ca595SLi Hua Qian 		}
333f20ca595SLi Hua Qian 		memset(vaddr, 0, reserved_mem_size);
334f20ca595SLi Hua Qian 		memunmap(vaddr);
335f20ca595SLi Hua Qian 	}
336f20ca595SLi Hua Qian 
3375527483fSTero Kristo 	watchdog_init_timeout(wdd, heartbeat, dev);
3385527483fSTero Kristo 
3392d63908bSTero Kristo 	ret = watchdog_register_device(wdd);
3402d63908bSTero Kristo 	if (ret) {
3412d63908bSTero Kristo 		dev_err(dev, "cannot register watchdog device\n");
3422d63908bSTero Kristo 		goto err_iomap;
3432d63908bSTero Kristo 	}
3442d63908bSTero Kristo 
3455527483fSTero Kristo 	if (last_ping)
3465527483fSTero Kristo 		watchdog_set_last_hw_keepalive(wdd, last_ping);
3475527483fSTero Kristo 
348f2c13661SVignesh Raghavendra 	if (!watchdog_hw_running(wdd))
349f2c13661SVignesh Raghavendra 		pm_runtime_put_sync(&pdev->dev);
350f2c13661SVignesh Raghavendra 
3512d63908bSTero Kristo 	return 0;
3522d63908bSTero Kristo 
3532d63908bSTero Kristo err_iomap:
3542d63908bSTero Kristo 	pm_runtime_put_sync(&pdev->dev);
355d5b29c2cSTero Kristo 	pm_runtime_disable(&pdev->dev);
3562d63908bSTero Kristo 
3572d63908bSTero Kristo 	return ret;
3582d63908bSTero Kristo }
3592d63908bSTero Kristo 
rti_wdt_remove(struct platform_device * pdev)3604ead88bfSUwe Kleine-König static void rti_wdt_remove(struct platform_device *pdev)
3612d63908bSTero Kristo {
3622d63908bSTero Kristo 	struct rti_wdt_device *wdt = platform_get_drvdata(pdev);
3632d63908bSTero Kristo 
3642d63908bSTero Kristo 	watchdog_unregister_device(&wdt->wdd);
365f2c13661SVignesh Raghavendra 
366f2c13661SVignesh Raghavendra 	if (!pm_runtime_suspended(&pdev->dev))
3672d63908bSTero Kristo 		pm_runtime_put(&pdev->dev);
368f2c13661SVignesh Raghavendra 
369d5b29c2cSTero Kristo 	pm_runtime_disable(&pdev->dev);
3702d63908bSTero Kristo }
3712d63908bSTero Kristo 
3722d63908bSTero Kristo static const struct of_device_id rti_wdt_of_match[] = {
3732d63908bSTero Kristo 	{ .compatible = "ti,j7-rti-wdt", },
3742d63908bSTero Kristo 	{},
3752d63908bSTero Kristo };
3762d63908bSTero Kristo MODULE_DEVICE_TABLE(of, rti_wdt_of_match);
3772d63908bSTero Kristo 
3782d63908bSTero Kristo static struct platform_driver rti_wdt_driver = {
3792d63908bSTero Kristo 	.driver = {
3802d63908bSTero Kristo 		.name = "rti-wdt",
3812d63908bSTero Kristo 		.of_match_table = rti_wdt_of_match,
3822d63908bSTero Kristo 	},
3832d63908bSTero Kristo 	.probe = rti_wdt_probe,
3844ead88bfSUwe Kleine-König 	.remove_new = rti_wdt_remove,
3852d63908bSTero Kristo };
3862d63908bSTero Kristo 
3872d63908bSTero Kristo module_platform_driver(rti_wdt_driver);
3882d63908bSTero Kristo 
3892d63908bSTero Kristo MODULE_AUTHOR("Tero Kristo <t-kristo@ti.com>");
3902d63908bSTero Kristo MODULE_DESCRIPTION("K3 RTI Watchdog Driver");
3912d63908bSTero Kristo 
3922d63908bSTero Kristo module_param(heartbeat, int, 0);
3932d63908bSTero Kristo MODULE_PARM_DESC(heartbeat,
3942d63908bSTero Kristo 		 "Watchdog heartbeat period in seconds from 1 to "
3952d63908bSTero Kristo 		 __MODULE_STRING(MAX_HEARTBEAT) ", default "
3962d63908bSTero Kristo 		 __MODULE_STRING(DEFAULT_HEARTBEAT));
3972d63908bSTero Kristo 
3982d63908bSTero Kristo MODULE_LICENSE("GPL");
3992d63908bSTero Kristo MODULE_ALIAS("platform:rti-wdt");
400