[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1362459259-9733-5-git-send-email-linux@roeck-us.net>
Date: Mon, 4 Mar 2013 20:54:15 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: linux-watchdog@...r.kernel.org
Cc: Wim Van Sebroeck <wim@...ana.be>, linux-kernel@...r.kernel.org,
Guenter Roeck <linux@...ck-us.net>
Subject: [PATCH 4/8] watchdog: w83627hf: Use helper functions to access superio registers
Use helper functions named similar to other drivers to access
superio registers.
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
drivers/watchdog/w83627hf_wdt.c | 97 +++++++++++++++++++++------------------
1 file changed, 52 insertions(+), 45 deletions(-)
diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c
index 6f023e1..8ae71fb 100644
--- a/drivers/watchdog/w83627hf_wdt.c
+++ b/drivers/watchdog/w83627hf_wdt.c
@@ -58,15 +58,32 @@ MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
(same as EFER) */
#define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */
-static void w83627hf_select_wd_register(void)
+#define W83627HF_LD_WDT 0x08
+
+static void superio_outb(int reg, int val)
+{
+ outb(reg, WDT_EFER);
+ outb(val, WDT_EFDR);
+}
+
+static inline int superio_inb(int reg)
+{
+ outb(reg, WDT_EFER);
+ return inb(WDT_EFDR);
+}
+
+static void superio_enter(void)
{
outb_p(0x87, WDT_EFER); /* Enter extended function mode */
outb_p(0x87, WDT_EFER); /* Again according to manual */
- outb_p(0x07, WDT_EFER); /* point to logical device number reg */
- outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */
}
-static void w83627hf_unselect_wd_register(void)
+static void superio_select(int ld)
+{
+ superio_outb(0x07, ld);
+}
+
+static void superio_exit(void)
{
outb_p(0xAA, WDT_EFER); /* Leave extended function mode */
}
@@ -78,58 +95,48 @@ static void w83627hf_init(void)
{
unsigned char t;
- w83627hf_select_wd_register();
-
- outb(0x20, WDT_EFER); /* check chip version */
- t = inb(WDT_EFDR);
+ superio_enter();
+ superio_select(W83627HF_LD_WDT);
+ t = superio_inb(0x20); /* check chip version */
if (t == 0x82) { /* W83627THF */
- outb_p(0x2b, WDT_EFER); /* select GPIO3 */
- t = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */
- outb_p(0x2b, WDT_EFER);
- outb_p(t, WDT_EFDR); /* set GPIO3 to WDT0 */
+ t = (superio_inb(0x2b) & 0xf7);
+ superio_outb(0x2b, t | 0x04); /* set GPIO3 to WDT0 */
} else if (t == 0x88 || t == 0xa0) { /* W83627EHF / W83627DHG */
- outb_p(0x2d, WDT_EFER); /* select GPIO5 */
- t = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */
- outb_p(0x2d, WDT_EFER);
- outb_p(t, WDT_EFDR); /* set GPIO5 to WDT0 */
+ t = superio_inb(0x2d);
+ superio_outb(0x2d, t & ~0x01); /* set GPIO5 to WDT0 */
}
- outb_p(0x30, WDT_EFER); /* select CR30 */
- t = inb(WDT_EFDR);
+ /* set CR30 bit 0 to activate GPIO2 */
+ t = superio_inb(0x30);
if (!(t & 0x01))
- outb_p(t | 0x01, WDT_EFDR); /* set bit 0 to activate GPIO2 */
+ superio_outb(0x30, t | 0x01);
- outb_p(0xF6, WDT_EFER); /* Select CRF6 */
- t = inb_p(WDT_EFDR); /* read CRF6 */
+ t = superio_inb(0xF6);
if (t != 0) {
pr_info("Watchdog already running. Resetting timeout to %d sec\n",
WATCHDOG_TIMEOUT);
- outb_p(WATCHDOG_TIMEOUT, WDT_EFDR); /* Write back to CRF6 */
+ superio_outb(0xf6, WATCHDOG_TIMEOUT);
}
- outb_p(0xF5, WDT_EFER); /* Select CRF5 */
- t = inb_p(WDT_EFDR); /* read CRF5 */
- t &= ~0x0C; /* set second mode & disable keyboard
- turning off watchdog */
- t |= 0x02; /* enable the WDTO# output low pulse
- to the KBRST# pin (PIN60) */
- outb_p(t, WDT_EFDR); /* Write back to CRF5 */
-
- outb_p(0xF7, WDT_EFER); /* Select CRF7 */
- t = inb_p(WDT_EFDR); /* read CRF7 */
- t &= ~0xC0; /* disable keyboard & mouse turning off
- watchdog */
- outb_p(t, WDT_EFDR); /* Write back to CRF7 */
-
- w83627hf_unselect_wd_register();
+ /* set second mode & disable keyboard turning off watchdog */
+ t = superio_inb(0xF5) & ~0x0C;
+ /* enable the WDTO# output low pulse to the KBRST# pin */
+ t |= 0x02;
+ superio_outb(0xF5, t);
+
+ /* disable keyboard & mouse turning off watchdog */
+ t = superio_inb(0xF7) & ~0xC0;
+ superio_outb(0xF7, t);
+
+ superio_exit();
}
static int wdt_set_time(unsigned int timeout)
{
- w83627hf_select_wd_register();
- outb_p(0xF6, WDT_EFER); /* Select CRF6 */
- outb_p(timeout, WDT_EFDR); /* Write Timeout counter to CRF6 */
- w83627hf_unselect_wd_register();
+ superio_enter();
+ superio_select(W83627HF_LD_WDT);
+ superio_outb(0xF6, timeout);
+ superio_exit();
return 0;
}
@@ -155,10 +162,10 @@ static unsigned int wdt_get_time(struct watchdog_device *wdog)
{
unsigned int timeleft;
- w83627hf_select_wd_register();
- outb_p(0xF6, WDT_EFER);
- timeleft = inb(WDT_EFDR);
- w83627hf_unselect_wd_register();
+ superio_enter();
+ superio_select(W83627HF_LD_WDT);
+ timeleft = superio_inb(0xF6);
+ superio_exit();
return timeleft;
}
--
1.7.9.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists