18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * include/asm-sh/watchdog.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2003 Paul Mundt 68c2ecf20Sopenharmony_ci * Copyright (C) 2009 Siemens AG 78c2ecf20Sopenharmony_ci * Copyright (C) 2009 Valentin Sitdikov 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef __ASM_SH_WATCHDOG_H 108c2ecf20Sopenharmony_ci#define __ASM_SH_WATCHDOG_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci#include <linux/io.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define WTCNT_HIGH 0x5a 168c2ecf20Sopenharmony_ci#define WTCSR_HIGH 0xa5 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define WTCSR_CKS2 0x04 198c2ecf20Sopenharmony_ci#define WTCSR_CKS1 0x02 208c2ecf20Sopenharmony_ci#define WTCSR_CKS0 0x01 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <cpu/watchdog.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * See cpu-sh2/watchdog.h for explanation of this stupidity.. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#ifndef WTCNT_R 288c2ecf20Sopenharmony_ci# define WTCNT_R WTCNT 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#ifndef WTCSR_R 328c2ecf20Sopenharmony_ci# define WTCSR_R WTCSR 338c2ecf20Sopenharmony_ci#endif 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * CKS0-2 supports a number of clock division ratios. At the time the watchdog 378c2ecf20Sopenharmony_ci * is enabled, it defaults to a 41 usec overflow period .. we overload this to 388c2ecf20Sopenharmony_ci * something a little more reasonable, and really can't deal with anything 398c2ecf20Sopenharmony_ci * lower than WTCSR_CKS_1024, else we drop back into the usec range. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * Clock Division Ratio Overflow Period 428c2ecf20Sopenharmony_ci * -------------------------------------------- 438c2ecf20Sopenharmony_ci * 1/32 (initial value) 41 usecs 448c2ecf20Sopenharmony_ci * 1/64 82 usecs 458c2ecf20Sopenharmony_ci * 1/128 164 usecs 468c2ecf20Sopenharmony_ci * 1/256 328 usecs 478c2ecf20Sopenharmony_ci * 1/512 656 usecs 488c2ecf20Sopenharmony_ci * 1/1024 1.31 msecs 498c2ecf20Sopenharmony_ci * 1/2048 2.62 msecs 508c2ecf20Sopenharmony_ci * 1/4096 5.25 msecs 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define WTCSR_CKS_32 0x00 538c2ecf20Sopenharmony_ci#define WTCSR_CKS_64 0x01 548c2ecf20Sopenharmony_ci#define WTCSR_CKS_128 0x02 558c2ecf20Sopenharmony_ci#define WTCSR_CKS_256 0x03 568c2ecf20Sopenharmony_ci#define WTCSR_CKS_512 0x04 578c2ecf20Sopenharmony_ci#define WTCSR_CKS_1024 0x05 588c2ecf20Sopenharmony_ci#define WTCSR_CKS_2048 0x06 598c2ecf20Sopenharmony_ci#define WTCSR_CKS_4096 0x07 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#if defined(CONFIG_CPU_SUBTYPE_SH7785) || defined(CONFIG_CPU_SUBTYPE_SH7780) 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * sh_wdt_read_cnt - Read from Counter 648c2ecf20Sopenharmony_ci * Reads back the WTCNT value. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_cistatic inline __u32 sh_wdt_read_cnt(void) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci return __raw_readl(WTCNT_R); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/** 728c2ecf20Sopenharmony_ci * sh_wdt_write_cnt - Write to Counter 738c2ecf20Sopenharmony_ci * @val: Value to write 748c2ecf20Sopenharmony_ci * 758c2ecf20Sopenharmony_ci * Writes the given value @val to the lower byte of the timer counter. 768c2ecf20Sopenharmony_ci * The upper byte is set manually on each write. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_cnt(__u32 val) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci __raw_writel((WTCNT_HIGH << 24) | (__u32)val, WTCNT); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/** 848c2ecf20Sopenharmony_ci * sh_wdt_write_bst - Write to Counter 858c2ecf20Sopenharmony_ci * @val: Value to write 868c2ecf20Sopenharmony_ci * 878c2ecf20Sopenharmony_ci * Writes the given value @val to the lower byte of the timer counter. 888c2ecf20Sopenharmony_ci * The upper byte is set manually on each write. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_bst(__u32 val) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci __raw_writel((WTBST_HIGH << 24) | (__u32)val, WTBST); 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * sh_wdt_read_csr - Read from Control/Status Register 968c2ecf20Sopenharmony_ci * 978c2ecf20Sopenharmony_ci * Reads back the WTCSR value. 988c2ecf20Sopenharmony_ci */ 998c2ecf20Sopenharmony_cistatic inline __u32 sh_wdt_read_csr(void) 1008c2ecf20Sopenharmony_ci{ 1018c2ecf20Sopenharmony_ci return __raw_readl(WTCSR_R); 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/** 1058c2ecf20Sopenharmony_ci * sh_wdt_write_csr - Write to Control/Status Register 1068c2ecf20Sopenharmony_ci * @val: Value to write 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * Writes the given value @val to the lower byte of the control/status 1098c2ecf20Sopenharmony_ci * register. The upper byte is set manually on each write. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_csr(__u32 val) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci __raw_writel((WTCSR_HIGH << 24) | (__u32)val, WTCSR); 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci#else 1168c2ecf20Sopenharmony_ci/** 1178c2ecf20Sopenharmony_ci * sh_wdt_read_cnt - Read from Counter 1188c2ecf20Sopenharmony_ci * Reads back the WTCNT value. 1198c2ecf20Sopenharmony_ci */ 1208c2ecf20Sopenharmony_cistatic inline __u8 sh_wdt_read_cnt(void) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci return __raw_readb(WTCNT_R); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/** 1268c2ecf20Sopenharmony_ci * sh_wdt_write_cnt - Write to Counter 1278c2ecf20Sopenharmony_ci * @val: Value to write 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * Writes the given value @val to the lower byte of the timer counter. 1308c2ecf20Sopenharmony_ci * The upper byte is set manually on each write. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_cnt(__u8 val) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci __raw_writew((WTCNT_HIGH << 8) | (__u16)val, WTCNT); 1358c2ecf20Sopenharmony_ci} 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/** 1388c2ecf20Sopenharmony_ci * sh_wdt_read_csr - Read from Control/Status Register 1398c2ecf20Sopenharmony_ci * 1408c2ecf20Sopenharmony_ci * Reads back the WTCSR value. 1418c2ecf20Sopenharmony_ci */ 1428c2ecf20Sopenharmony_cistatic inline __u8 sh_wdt_read_csr(void) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci return __raw_readb(WTCSR_R); 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/** 1488c2ecf20Sopenharmony_ci * sh_wdt_write_csr - Write to Control/Status Register 1498c2ecf20Sopenharmony_ci * @val: Value to write 1508c2ecf20Sopenharmony_ci * 1518c2ecf20Sopenharmony_ci * Writes the given value @val to the lower byte of the control/status 1528c2ecf20Sopenharmony_ci * register. The upper byte is set manually on each write. 1538c2ecf20Sopenharmony_ci */ 1548c2ecf20Sopenharmony_cistatic inline void sh_wdt_write_csr(__u8 val) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci __raw_writew((WTCSR_HIGH << 8) | (__u16)val, WTCSR); 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci#endif /* CONFIG_CPU_SUBTYPE_SH7785 || CONFIG_CPU_SUBTYPE_SH7780 */ 1598c2ecf20Sopenharmony_ci#endif /* __ASM_SH_WATCHDOG_H */ 160