162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2011 Calxeda, Inc.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef _MACH_HIGHBANK__SYSREGS_H_
662306a36Sopenharmony_ci#define _MACH_HIGHBANK__SYSREGS_H_
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/io.h>
962306a36Sopenharmony_ci#include <linux/smp.h>
1062306a36Sopenharmony_ci#include <asm/smp_plat.h>
1162306a36Sopenharmony_ci#include <asm/smp_scu.h>
1262306a36Sopenharmony_ci#include "core.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciextern void __iomem *sregs_base;
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define HB_SREG_A9_PWR_REQ		0xf00
1762306a36Sopenharmony_ci#define HB_SREG_A9_BOOT_STAT		0xf04
1862306a36Sopenharmony_ci#define HB_SREG_A9_BOOT_DATA		0xf08
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define HB_PWR_SUSPEND			0
2162306a36Sopenharmony_ci#define HB_PWR_SOFT_RESET		1
2262306a36Sopenharmony_ci#define HB_PWR_HARD_RESET		2
2362306a36Sopenharmony_ci#define HB_PWR_SHUTDOWN			3
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define SREG_CPU_PWR_CTRL(c)		(0x200 + ((c) * 4))
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistatic inline void highbank_set_core_pwr(void)
2862306a36Sopenharmony_ci{
2962306a36Sopenharmony_ci	int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(smp_processor_id()), 0);
3062306a36Sopenharmony_ci	if (scu_base_addr)
3162306a36Sopenharmony_ci		scu_power_mode(scu_base_addr, SCU_PM_POWEROFF);
3262306a36Sopenharmony_ci	else
3362306a36Sopenharmony_ci		writel_relaxed(1, sregs_base + SREG_CPU_PWR_CTRL(cpu));
3462306a36Sopenharmony_ci}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistatic inline void highbank_clear_core_pwr(void)
3762306a36Sopenharmony_ci{
3862306a36Sopenharmony_ci	int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(smp_processor_id()), 0);
3962306a36Sopenharmony_ci	if (scu_base_addr)
4062306a36Sopenharmony_ci		scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
4162306a36Sopenharmony_ci	else
4262306a36Sopenharmony_ci		writel_relaxed(0, sregs_base + SREG_CPU_PWR_CTRL(cpu));
4362306a36Sopenharmony_ci}
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cistatic inline void highbank_set_pwr_suspend(void)
4662306a36Sopenharmony_ci{
4762306a36Sopenharmony_ci	writel(HB_PWR_SUSPEND, sregs_base + HB_SREG_A9_PWR_REQ);
4862306a36Sopenharmony_ci	highbank_set_core_pwr();
4962306a36Sopenharmony_ci}
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistatic inline void highbank_set_pwr_shutdown(void)
5262306a36Sopenharmony_ci{
5362306a36Sopenharmony_ci	writel(HB_PWR_SHUTDOWN, sregs_base + HB_SREG_A9_PWR_REQ);
5462306a36Sopenharmony_ci	highbank_set_core_pwr();
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistatic inline void highbank_set_pwr_soft_reset(void)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci	writel(HB_PWR_SOFT_RESET, sregs_base + HB_SREG_A9_PWR_REQ);
6062306a36Sopenharmony_ci	highbank_set_core_pwr();
6162306a36Sopenharmony_ci}
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistatic inline void highbank_set_pwr_hard_reset(void)
6462306a36Sopenharmony_ci{
6562306a36Sopenharmony_ci	writel(HB_PWR_HARD_RESET, sregs_base + HB_SREG_A9_PWR_REQ);
6662306a36Sopenharmony_ci	highbank_set_core_pwr();
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic inline void highbank_clear_pwr_request(void)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	writel(~0UL, sregs_base + HB_SREG_A9_PWR_REQ);
7262306a36Sopenharmony_ci	highbank_clear_core_pwr();
7362306a36Sopenharmony_ci}
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#endif
76