From 7af4ac8772a8f9af40f998671e6d09f5de137854 Mon Sep 17 00:00:00 2001 From: Radu Rendec Date: Thu, 26 Oct 2017 17:10:13 +0100 Subject: watchdog: i6300esb: use the watchdog subsystem Change the i6300esb driver to use the watchdog subsystem instead of the legacy watchdog API. This is mainly just getting rid of the "write" and "ioctl" methods and part of the watchdog control logic (which are all implemented by the watchdog subsystem). Even though the watchdog subsystem supports registering and handling multiple watchdog devices at the same time, the i6300esb driver still has a limitation of only one i6300esb device due to some global variable usage that comes from the original design. However, the driver can now coexist with other watchdog devices (supported by different drivers). Signed-off-by: Radu Rendec Reviewed-by: Guenter Roeck Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck --- drivers/watchdog/i6300esb.c | 232 +++++++++----------------------------------- 1 file changed, 47 insertions(+), 185 deletions(-) (limited to 'drivers/watchdog') diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c index d7befd58b391..4f4287d83c21 100644 --- a/drivers/watchdog/i6300esb.c +++ b/drivers/watchdog/i6300esb.c @@ -21,6 +21,8 @@ * Version 0.02 * 20050210 David Härdeman * Ported driver to kernel 2.6 + * 20171016 Radu Rendec + * Change driver to use the watchdog subsystem */ /* @@ -44,7 +46,6 @@ /* Module and version information */ #define ESB_VERSION "0.05" #define ESB_MODULE_NAME "i6300ESB timer" -#define ESB_DRIVER_NAME ESB_MODULE_NAME ", v" ESB_VERSION /* PCI configuration registers */ #define ESB_CONFIG_REG 0x60 /* Config register */ @@ -76,11 +77,7 @@ /* internal variables */ static void __iomem *BASEADDR; -static DEFINE_SPINLOCK(esb_lock); /* Guards the hardware */ -static unsigned long timer_alive; static struct pci_dev *esb_pci; -static unsigned short triggered; /* The status of the watchdog upon boot */ -static char esb_expect_close; /* We can only use 1 card due to the /dev/watchdog restriction */ static int cards_found; @@ -88,7 +85,7 @@ static int cards_found; /* module parameters */ /* 30 sec default heartbeat (1 < heartbeat < 2*1023) */ #define WATCHDOG_HEARTBEAT 30 -static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ +static int heartbeat; /* in seconds */ module_param(heartbeat, int, 0); MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1dev, "failed to enable device\n"); goto err_devput; } if (pci_request_region(pdev, 0, ESB_MODULE_NAME)) { - pr_err("failed to request region\n"); + dev_err(&pdev->dev, "failed to request region\n"); goto err_disable; } BASEADDR = pci_ioremap_bar(pdev, 0); if (BASEADDR == NULL) { /* Something's wrong here, BASEADDR has to be set */ - pr_err("failed to get BASEADDR\n"); + dev_err(&pdev->dev, "failed to get BASEADDR\n"); goto err_release; } @@ -396,7 +270,7 @@ static void esb_initdevice(void) /* Check that the WDT isn't already locked */ pci_read_config_byte(esb_pci, ESB_LOCK_REG, &val1); if (val1 & ESB_WDT_LOCK) - pr_warn("nowayout already set\n"); + dev_warn(&esb_pci->dev, "nowayout already set\n"); /* Set the timer to watchdog mode and disable it for now */ pci_write_config_byte(esb_pci, ESB_LOCK_REG, 0x00); @@ -405,14 +279,14 @@ static void esb_initdevice(void) esb_unlock_registers(); val2 = readw(ESB_RELOAD_REG); if (val2 & ESB_WDT_TIMEOUT) - triggered = WDIOF_CARDRESET; + esb_dev.bootstatus = WDIOF_CARDRESET; /* Reset WDT_TIMEOUT flag and timers */ esb_unlock_registers(); writew((ESB_WDT_TIMEOUT | ESB_WDT_RELOAD), ESB_RELOAD_REG); /* And set the correct timeout value */ - esb_timer_set_heartbeat(heartbeat); + esb_timer_set_heartbeat(&esb_dev, esb_dev.timeout); } static int esb_probe(struct pci_dev *pdev, @@ -434,26 +308,25 @@ static int esb_probe(struct pci_dev *pdev, if (!esb_getdevice(pdev) || esb_pci == NULL) return -ENODEV; - /* Check that the heartbeat value is within it's range; - if not reset to the default */ - if (heartbeat < 0x1 || heartbeat > 2 * 0x03ff) { - heartbeat = WATCHDOG_HEARTBEAT; - pr_info("heartbeat value must be 1dev, + "cannot register watchdog device (err=%d)\n", ret); goto err_unmap; } - pr_info("initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", - BASEADDR, heartbeat, nowayout); + dev_info(&pdev->dev, + "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", + BASEADDR, esb_dev.timeout, nowayout); return 0; err_unmap: @@ -466,29 +339,18 @@ err_unmap: static void esb_remove(struct pci_dev *pdev) { - /* Stop the timer before we leave */ - if (!nowayout) - esb_timer_stop(); - - /* Deregister */ - misc_deregister(&esb_miscdev); + watchdog_unregister_device(&esb_dev); iounmap(BASEADDR); pci_release_region(esb_pci, 0); pci_disable_device(esb_pci); esb_pci = NULL; } -static void esb_shutdown(struct pci_dev *pdev) -{ - esb_timer_stop(); -} - static struct pci_driver esb_driver = { .name = ESB_MODULE_NAME, .id_table = esb_pci_tbl, .probe = esb_probe, .remove = esb_remove, - .shutdown = esb_shutdown, }; module_pci_driver(esb_driver); -- cgit v1.2.3-59-g8ed1b