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