18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * hp6x0 Power Management Routines 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2006 Andriy Skulysh <askulsyh@gmail.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#include <linux/init.h> 88c2ecf20Sopenharmony_ci#include <linux/suspend.h> 98c2ecf20Sopenharmony_ci#include <linux/errno.h> 108c2ecf20Sopenharmony_ci#include <linux/time.h> 118c2ecf20Sopenharmony_ci#include <linux/delay.h> 128c2ecf20Sopenharmony_ci#include <linux/gfp.h> 138c2ecf20Sopenharmony_ci#include <asm/io.h> 148c2ecf20Sopenharmony_ci#include <asm/hd64461.h> 158c2ecf20Sopenharmony_ci#include <asm/bl_bit.h> 168c2ecf20Sopenharmony_ci#include <mach/hp6xx.h> 178c2ecf20Sopenharmony_ci#include <cpu/dac.h> 188c2ecf20Sopenharmony_ci#include <asm/freq.h> 198c2ecf20Sopenharmony_ci#include <asm/watchdog.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define INTR_OFFSET 0x600 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define STBCR 0xffffff82 248c2ecf20Sopenharmony_ci#define STBCR2 0xffffff88 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define STBCR_STBY 0x80 278c2ecf20Sopenharmony_ci#define STBCR_MSTP2 0x04 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define MCR 0xffffff68 308c2ecf20Sopenharmony_ci#define RTCNT 0xffffff70 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define MCR_RMODE 2 338c2ecf20Sopenharmony_ci#define MCR_RFSH 4 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciextern u8 wakeup_start; 368c2ecf20Sopenharmony_ciextern u8 wakeup_end; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic void pm_enter(void) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci u8 stbcr, csr; 418c2ecf20Sopenharmony_ci u16 frqcr, mcr; 428c2ecf20Sopenharmony_ci u32 vbr_new, vbr_old; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci set_bl_bit(); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci /* set wdt */ 478c2ecf20Sopenharmony_ci csr = sh_wdt_read_csr(); 488c2ecf20Sopenharmony_ci csr &= ~WTCSR_TME; 498c2ecf20Sopenharmony_ci csr |= WTCSR_CKS_4096; 508c2ecf20Sopenharmony_ci sh_wdt_write_csr(csr); 518c2ecf20Sopenharmony_ci csr = sh_wdt_read_csr(); 528c2ecf20Sopenharmony_ci sh_wdt_write_cnt(0); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /* disable PLL1 */ 558c2ecf20Sopenharmony_ci frqcr = __raw_readw(FRQCR); 568c2ecf20Sopenharmony_ci frqcr &= ~(FRQCR_PLLEN | FRQCR_PSTBY); 578c2ecf20Sopenharmony_ci __raw_writew(frqcr, FRQCR); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* enable standby */ 608c2ecf20Sopenharmony_ci stbcr = __raw_readb(STBCR); 618c2ecf20Sopenharmony_ci __raw_writeb(stbcr | STBCR_STBY | STBCR_MSTP2, STBCR); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci /* set self-refresh */ 648c2ecf20Sopenharmony_ci mcr = __raw_readw(MCR); 658c2ecf20Sopenharmony_ci __raw_writew(mcr & ~MCR_RFSH, MCR); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci /* set interrupt handler */ 688c2ecf20Sopenharmony_ci asm volatile("stc vbr, %0" : "=r" (vbr_old)); 698c2ecf20Sopenharmony_ci vbr_new = get_zeroed_page(GFP_ATOMIC); 708c2ecf20Sopenharmony_ci udelay(50); 718c2ecf20Sopenharmony_ci memcpy((void*)(vbr_new + INTR_OFFSET), 728c2ecf20Sopenharmony_ci &wakeup_start, &wakeup_end - &wakeup_start); 738c2ecf20Sopenharmony_ci asm volatile("ldc %0, vbr" : : "r" (vbr_new)); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci __raw_writew(0, RTCNT); 768c2ecf20Sopenharmony_ci __raw_writew(mcr | MCR_RFSH | MCR_RMODE, MCR); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci cpu_sleep(); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci asm volatile("ldc %0, vbr" : : "r" (vbr_old)); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci free_page(vbr_new); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /* enable PLL1 */ 858c2ecf20Sopenharmony_ci frqcr = __raw_readw(FRQCR); 868c2ecf20Sopenharmony_ci frqcr |= FRQCR_PSTBY; 878c2ecf20Sopenharmony_ci __raw_writew(frqcr, FRQCR); 888c2ecf20Sopenharmony_ci udelay(50); 898c2ecf20Sopenharmony_ci frqcr |= FRQCR_PLLEN; 908c2ecf20Sopenharmony_ci __raw_writew(frqcr, FRQCR); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci __raw_writeb(stbcr, STBCR); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci clear_bl_bit(); 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic int hp6x0_pm_enter(suspend_state_t state) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci u8 stbcr, stbcr2; 1008c2ecf20Sopenharmony_ci#ifdef CONFIG_HD64461_ENABLER 1018c2ecf20Sopenharmony_ci u8 scr; 1028c2ecf20Sopenharmony_ci u16 hd64461_stbcr; 1038c2ecf20Sopenharmony_ci#endif 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#ifdef CONFIG_HD64461_ENABLER 1068c2ecf20Sopenharmony_ci outb(0, HD64461_PCC1CSCIER); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci scr = inb(HD64461_PCC1SCR); 1098c2ecf20Sopenharmony_ci scr |= HD64461_PCCSCR_VCC1; 1108c2ecf20Sopenharmony_ci outb(scr, HD64461_PCC1SCR); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci hd64461_stbcr = inw(HD64461_STBCR); 1138c2ecf20Sopenharmony_ci hd64461_stbcr |= HD64461_STBCR_SPC1ST; 1148c2ecf20Sopenharmony_ci outw(hd64461_stbcr, HD64461_STBCR); 1158c2ecf20Sopenharmony_ci#endif 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci __raw_writeb(0x1f, DACR); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci stbcr = __raw_readb(STBCR); 1208c2ecf20Sopenharmony_ci __raw_writeb(0x01, STBCR); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci stbcr2 = __raw_readb(STBCR2); 1238c2ecf20Sopenharmony_ci __raw_writeb(0x7f , STBCR2); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci outw(0xf07f, HD64461_SCPUCR); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci pm_enter(); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci outw(0, HD64461_SCPUCR); 1308c2ecf20Sopenharmony_ci __raw_writeb(stbcr, STBCR); 1318c2ecf20Sopenharmony_ci __raw_writeb(stbcr2, STBCR2); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#ifdef CONFIG_HD64461_ENABLER 1348c2ecf20Sopenharmony_ci hd64461_stbcr = inw(HD64461_STBCR); 1358c2ecf20Sopenharmony_ci hd64461_stbcr &= ~HD64461_STBCR_SPC1ST; 1368c2ecf20Sopenharmony_ci outw(hd64461_stbcr, HD64461_STBCR); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci outb(0x4c, HD64461_PCC1CSCIER); 1398c2ecf20Sopenharmony_ci outb(0x00, HD64461_PCC1CSCR); 1408c2ecf20Sopenharmony_ci#endif 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci return 0; 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistatic const struct platform_suspend_ops hp6x0_pm_ops = { 1468c2ecf20Sopenharmony_ci .enter = hp6x0_pm_enter, 1478c2ecf20Sopenharmony_ci .valid = suspend_valid_only_mem, 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic int __init hp6x0_pm_init(void) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci suspend_set_ops(&hp6x0_pm_ops); 1538c2ecf20Sopenharmony_ci return 0; 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cilate_initcall(hp6x0_pm_init); 157