^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * PNX833x Hardware Watchdog Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2008 NXP Semiconductors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Daniel Laird <daniel.j.laird@nxp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Andre McCurdy <andre.mccurdy@nxp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Heavily based upon - IndyDog 0.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * A Hardware Watchdog Device for SGI IP22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * based on softdog.c by Alan Cox <alan@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/mach-pnx833x/pnx833x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define WATCHDOG_TIMEOUT 30 /* 30 sec Maximum timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define WATCHDOG_COUNT_FREQUENCY 68000000U /* Watchdog counts at 68MHZ. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define PNX_WATCHDOG_TIMEOUT (WATCHDOG_TIMEOUT * WATCHDOG_COUNT_FREQUENCY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define PNX_TIMEOUT_VALUE 2040000000U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /** CONFIG block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define PNX833X_CONFIG (0x07000U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define PNX833X_CONFIG_CPU_WATCHDOG (0x54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define PNX833X_CONFIG_CPU_WATCHDOG_COMPARE (0x58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define PNX833X_CONFIG_CPU_COUNTERS_CONTROL (0x1c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /** RESET block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define PNX833X_RESET (0x08000U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define PNX833X_RESET_CONFIG (0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int pnx833x_wdt_alive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Set default timeout in MHZ.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int pnx833x_wdt_timeout = PNX_WATCHDOG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) module_param(pnx833x_wdt_timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_PARM_DESC(timeout, "Watchdog timeout in Mhz. (68Mhz clock), default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __MODULE_STRING(PNX_TIMEOUT_VALUE) "(30 seconds).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define START_DEFAULT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int start_enabled = START_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) module_param(start_enabled, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) MODULE_PARM_DESC(start_enabled, "Watchdog is started on module insertion "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) "(default=" __MODULE_STRING(START_DEFAULT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static void pnx833x_wdt_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Enable watchdog causing reset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) PNX833X_REG(PNX833X_RESET + PNX833X_RESET_CONFIG) |= 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Set timeout.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) PNX833X_CONFIG_CPU_WATCHDOG_COMPARE) = pnx833x_wdt_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Enable watchdog. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) PNX833X_CONFIG_CPU_COUNTERS_CONTROL) |= 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) pr_info("Started watchdog timer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void pnx833x_wdt_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* Disable watchdog causing reset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) PNX833X_REG(PNX833X_RESET + PNX833X_CONFIG) &= 0xFFFFFFFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Disable watchdog.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) PNX833X_CONFIG_CPU_COUNTERS_CONTROL) &= 0xFFFFFFFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) pr_info("Stopped watchdog timer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void pnx833x_wdt_ping(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) PNX833X_CONFIG_CPU_WATCHDOG_COMPARE) = pnx833x_wdt_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Allow only one person to hold it open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static int pnx833x_wdt_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (test_and_set_bit(0, &pnx833x_wdt_alive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (nowayout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) __module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Activate timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (!start_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pnx833x_wdt_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) pnx833x_wdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pr_info("Started watchdog timer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int pnx833x_wdt_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Shut off the timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Lock it in if it's a module and we defined ...NOWAYOUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (!nowayout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) pnx833x_wdt_stop(); /* Turn the WDT off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) clear_bit(0, &pnx833x_wdt_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static ssize_t pnx833x_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* Refresh the timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) pnx833x_wdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static long pnx833x_wdt_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int options, new_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) uint32_t timeout, timeout_left = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .firmware_version = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .identity = "Hardware Watchdog for PNX833x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (copy_to_user((struct watchdog_info *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) &ident, sizeof(ident)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return put_user(0, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (get_user(options, (int *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (options & WDIOS_DISABLECARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pnx833x_wdt_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (options & WDIOS_ENABLECARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) pnx833x_wdt_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pnx833x_wdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (get_user(new_timeout, (int *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) pnx833x_wdt_timeout = new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) PNX833X_CONFIG_CPU_WATCHDOG_COMPARE) = new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return put_user(new_timeout, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) timeout = PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) PNX833X_CONFIG_CPU_WATCHDOG_COMPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return put_user(timeout, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) case WDIOC_GETTIMELEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) timeout_left = PNX833X_REG(PNX833X_CONFIG +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) PNX833X_CONFIG_CPU_WATCHDOG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return put_user(timeout_left, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int pnx833x_wdt_notify_sys(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) unsigned long code, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (code == SYS_DOWN || code == SYS_HALT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pnx833x_wdt_stop(); /* Turn the WDT off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static const struct file_operations pnx833x_wdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .write = pnx833x_wdt_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .unlocked_ioctl = pnx833x_wdt_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .open = pnx833x_wdt_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .release = pnx833x_wdt_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static struct miscdevice pnx833x_wdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .minor = WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .name = "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .fops = &pnx833x_wdt_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static struct notifier_block pnx833x_wdt_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .notifier_call = pnx833x_wdt_notify_sys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int __init watchdog_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int ret, cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Lets check the reason for the reset.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cause = PNX833X_REG(PNX833X_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*If bit 31 is set then watchdog was cause of reset.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (cause & 0x80000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pr_info("The system was previously reset due to the watchdog firing - please investigate...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ret = register_reboot_notifier(&pnx833x_wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) pr_err("cannot register reboot notifier (err=%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ret = misc_register(&pnx833x_wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) WATCHDOG_MINOR, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) unregister_reboot_notifier(&pnx833x_wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) pr_info("Hardware Watchdog Timer for PNX833x: Version 0.1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (start_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pnx833x_wdt_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void __exit watchdog_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) misc_deregister(&pnx833x_wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unregister_reboot_notifier(&pnx833x_wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) module_init(watchdog_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) module_exit(watchdog_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_AUTHOR("Daniel Laird/Andre McCurdy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MODULE_DESCRIPTION("Hardware Watchdog Device for PNX833x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) MODULE_LICENSE("GPL");