18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2011 Calxeda, Inc.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _MACH_HIGHBANK__SYSREGS_H_
68c2ecf20Sopenharmony_ci#define _MACH_HIGHBANK__SYSREGS_H_
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/io.h>
98c2ecf20Sopenharmony_ci#include <linux/smp.h>
108c2ecf20Sopenharmony_ci#include <asm/smp_plat.h>
118c2ecf20Sopenharmony_ci#include <asm/smp_scu.h>
128c2ecf20Sopenharmony_ci#include "core.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern void __iomem *sregs_base;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define HB_SREG_A9_PWR_REQ		0xf00
178c2ecf20Sopenharmony_ci#define HB_SREG_A9_BOOT_STAT		0xf04
188c2ecf20Sopenharmony_ci#define HB_SREG_A9_BOOT_DATA		0xf08
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define HB_PWR_SUSPEND			0
218c2ecf20Sopenharmony_ci#define HB_PWR_SOFT_RESET		1
228c2ecf20Sopenharmony_ci#define HB_PWR_HARD_RESET		2
238c2ecf20Sopenharmony_ci#define HB_PWR_SHUTDOWN			3
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define SREG_CPU_PWR_CTRL(c)		(0x200 + ((c) * 4))
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline void highbank_set_core_pwr(void)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(smp_processor_id()), 0);
308c2ecf20Sopenharmony_ci	if (scu_base_addr)
318c2ecf20Sopenharmony_ci		scu_power_mode(scu_base_addr, SCU_PM_POWEROFF);
328c2ecf20Sopenharmony_ci	else
338c2ecf20Sopenharmony_ci		writel_relaxed(1, sregs_base + SREG_CPU_PWR_CTRL(cpu));
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic inline void highbank_clear_core_pwr(void)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(smp_processor_id()), 0);
398c2ecf20Sopenharmony_ci	if (scu_base_addr)
408c2ecf20Sopenharmony_ci		scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
418c2ecf20Sopenharmony_ci	else
428c2ecf20Sopenharmony_ci		writel_relaxed(0, sregs_base + SREG_CPU_PWR_CTRL(cpu));
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic inline void highbank_set_pwr_suspend(void)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	writel(HB_PWR_SUSPEND, sregs_base + HB_SREG_A9_PWR_REQ);
488c2ecf20Sopenharmony_ci	highbank_set_core_pwr();
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic inline void highbank_set_pwr_shutdown(void)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	writel(HB_PWR_SHUTDOWN, sregs_base + HB_SREG_A9_PWR_REQ);
548c2ecf20Sopenharmony_ci	highbank_set_core_pwr();
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic inline void highbank_set_pwr_soft_reset(void)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	writel(HB_PWR_SOFT_RESET, sregs_base + HB_SREG_A9_PWR_REQ);
608c2ecf20Sopenharmony_ci	highbank_set_core_pwr();
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline void highbank_set_pwr_hard_reset(void)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	writel(HB_PWR_HARD_RESET, sregs_base + HB_SREG_A9_PWR_REQ);
668c2ecf20Sopenharmony_ci	highbank_set_core_pwr();
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline void highbank_clear_pwr_request(void)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	writel(~0UL, sregs_base + HB_SREG_A9_PWR_REQ);
728c2ecf20Sopenharmony_ci	highbank_clear_core_pwr();
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#endif
76