blob: daf5019d0170f3234ae110777596b108ae00dd5f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese4a269f22016-07-19 07:45:46 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roese4a269f22016-07-19 07:45:46 +02004 */
5
6#include <common.h>
7#include <nuvoton_nct6102d.h>
8#include <asm/io.h>
9#include <asm/pnp_def.h>
10
11static void superio_outb(int reg, int val)
12{
13 outb(reg, NCT_EFER);
14 outb(val, NCT_EFDR);
15}
16
17static inline int superio_inb(int reg)
18{
19 outb(reg, NCT_EFER);
20 return inb(NCT_EFDR);
21}
22
23static int superio_enter(void)
24{
25 outb(NCT_ENTRY_KEY, NCT_EFER); /* Enter extended function mode */
26 outb(NCT_ENTRY_KEY, NCT_EFER); /* Again according to manual */
27
28 return 0;
29}
30
31static void superio_select(int ld)
32{
33 superio_outb(NCT_LD_SELECT_REG, ld);
34}
35
36static void superio_exit(void)
37{
38 outb(NCT_EXIT_KEY, NCT_EFER); /* Leave extended function mode */
39}
40
41/*
42 * The Nuvoton NCT6102D starts per default after reset with both,
43 * the internal watchdog and the internal legacy UART enabled. This
44 * code provides a function to disable the watchdog.
45 */
46int nct6102d_wdt_disable(void)
47{
48 superio_enter();
49 /* Select logical device for WDT */
50 superio_select(NCT6102D_LD_WDT);
51 superio_outb(NCT6102D_WDT_TIMEOUT, 0x00);
52 superio_exit();
53
54 return 0;
55}