18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * include/asm-sh/cpu-sh2/watchdog.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2003 Paul Mundt
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef __ASM_CPU_SH2_WATCHDOG_H
88c2ecf20Sopenharmony_ci#define __ASM_CPU_SH2_WATCHDOG_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * More SH-2 brilliance .. its not good enough that we can't read
128c2ecf20Sopenharmony_ci * and write the same sizes to WTCNT, now we have to read and write
138c2ecf20Sopenharmony_ci * with different sizes at different addresses for WTCNT _and_ RSTCSR.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * At least on the bright side no one has managed to screw over WTCSR
168c2ecf20Sopenharmony_ci * in this fashion .. yet.
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci/* Register definitions */
198c2ecf20Sopenharmony_ci#define WTCNT		0xfffffe80
208c2ecf20Sopenharmony_ci#define WTCSR		0xfffffe80
218c2ecf20Sopenharmony_ci#define RSTCSR		0xfffffe82
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define WTCNT_R		(WTCNT + 1)
248c2ecf20Sopenharmony_ci#define RSTCSR_R	(RSTCSR + 1)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Bit definitions */
278c2ecf20Sopenharmony_ci#define WTCSR_IOVF	0x80
288c2ecf20Sopenharmony_ci#define WTCSR_WT	0x40
298c2ecf20Sopenharmony_ci#define WTCSR_TME	0x20
308c2ecf20Sopenharmony_ci#define WTCSR_RSTS	0x00
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define RSTCSR_RSTS	0x20
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/**
358c2ecf20Sopenharmony_ci * 	sh_wdt_read_rstcsr - Read from Reset Control/Status Register
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci *	Reads back the RSTCSR value.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_cistatic inline __u8 sh_wdt_read_rstcsr(void)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	/*
428c2ecf20Sopenharmony_ci	 * Same read/write brain-damage as for WTCNT here..
438c2ecf20Sopenharmony_ci	 */
448c2ecf20Sopenharmony_ci	return __raw_readb(RSTCSR_R);
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/**
488c2ecf20Sopenharmony_ci * 	sh_wdt_write_csr - Write to Reset Control/Status Register
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * 	@val: Value to write
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci * 	Writes the given value @val to the lower byte of the control/status
538c2ecf20Sopenharmony_ci * 	register. The upper byte is set manually on each write.
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_rstcsr(__u8 val)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	/*
588c2ecf20Sopenharmony_ci	 * Note: Due to the brain-damaged nature of this register,
598c2ecf20Sopenharmony_ci	 * we can't presently touch the WOVF bit, since the upper byte
608c2ecf20Sopenharmony_ci	 * has to be swapped for this. So just leave it alone..
618c2ecf20Sopenharmony_ci	 */
628c2ecf20Sopenharmony_ci	__raw_writeb((WTCNT_HIGH << 8) | (__u16)val, RSTCSR);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#endif /* __ASM_CPU_SH2_WATCHDOG_H */
668c2ecf20Sopenharmony_ci
67