18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Author: Huacai Chen <chenhuacai@loongson.cn>
48c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Corporation Limited
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef __ASM_MACH_LOONGSON64_LOONGSON_H
88c2ecf20Sopenharmony_ci#define __ASM_MACH_LOONGSON64_LOONGSON_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/init.h>
118c2ecf20Sopenharmony_ci#include <linux/io.h>
128c2ecf20Sopenharmony_ci#include <linux/irq.h>
138c2ecf20Sopenharmony_ci#include <linux/pci.h>
148c2ecf20Sopenharmony_ci#include <asm/addrspace.h>
158c2ecf20Sopenharmony_ci#include <asm/bootinfo.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciextern const struct plat_smp_ops loongson3_smp_ops;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define LOONGSON_REG(x) \
208c2ecf20Sopenharmony_ci	(*(volatile u32 *)((char *)TO_UNCACHE(LOONGSON_REG_BASE) + (x)))
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define LOONGSON_LIO_BASE	0x18000000
238c2ecf20Sopenharmony_ci#define LOONGSON_LIO_SIZE	0x00100000	/* 1M */
248c2ecf20Sopenharmony_ci#define LOONGSON_LIO_TOP	(LOONGSON_LIO_BASE+LOONGSON_LIO_SIZE-1)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_BASE	0x1c000000
278c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_SIZE	0x02000000	/* 32M */
288c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_TOP	(LOONGSON_BOOT_BASE+LOONGSON_BOOT_SIZE-1)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define LOONGSON_REG_BASE	0x1fe00000
318c2ecf20Sopenharmony_ci#define LOONGSON_REG_SIZE	0x00100000	/* 1M */
328c2ecf20Sopenharmony_ci#define LOONGSON_REG_TOP	(LOONGSON_REG_BASE+LOONGSON_REG_SIZE-1)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* GPIO Regs - r/w */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define LOONGSON_GPIODATA		LOONGSON_REG(0x11c)
378c2ecf20Sopenharmony_ci#define LOONGSON_GPIOIE			LOONGSON_REG(0x120)
388c2ecf20Sopenharmony_ci#define LOONGSON_REG_GPIO_BASE          (LOONGSON_REG_BASE + 0x11c)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define MAX_PACKAGES 16
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define xconf_readl(addr) readl(addr)
438c2ecf20Sopenharmony_ci#define xconf_readq(addr) readq(addr)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic inline void xconf_writel(u32 val, volatile void __iomem *addr)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	asm volatile (
488c2ecf20Sopenharmony_ci	"	st.w	%[v], %[hw], 0	\n"
498c2ecf20Sopenharmony_ci	"	ld.b	$r0, %[hw], 0	\n"
508c2ecf20Sopenharmony_ci	:
518c2ecf20Sopenharmony_ci	: [hw] "r" (addr), [v] "r" (val)
528c2ecf20Sopenharmony_ci	);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic inline void xconf_writeq(u64 val64, volatile void __iomem *addr)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	asm volatile (
588c2ecf20Sopenharmony_ci	"	st.d	%[v], %[hw], 0	\n"
598c2ecf20Sopenharmony_ci	"	ld.b	$r0, %[hw], 0	\n"
608c2ecf20Sopenharmony_ci	:
618c2ecf20Sopenharmony_ci	: [hw] "r" (addr),  [v] "r" (val64)
628c2ecf20Sopenharmony_ci	);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* ============== LS7A registers =============== */
668c2ecf20Sopenharmony_ci#define LS7A_PCH_REG_BASE		0x10000000UL
678c2ecf20Sopenharmony_ci/* LPC regs */
688c2ecf20Sopenharmony_ci#define LS7A_LPC_REG_BASE		(LS7A_PCH_REG_BASE + 0x00002000)
698c2ecf20Sopenharmony_ci/* CHIPCFG regs */
708c2ecf20Sopenharmony_ci#define LS7A_CHIPCFG_REG_BASE		(LS7A_PCH_REG_BASE + 0x00010000)
718c2ecf20Sopenharmony_ci/* MISC reg base */
728c2ecf20Sopenharmony_ci#define LS7A_MISC_REG_BASE		(LS7A_PCH_REG_BASE + 0x00080000)
738c2ecf20Sopenharmony_ci/* ACPI regs */
748c2ecf20Sopenharmony_ci#define LS7A_ACPI_REG_BASE		(LS7A_MISC_REG_BASE + 0x00050000)
758c2ecf20Sopenharmony_ci/* RTC regs */
768c2ecf20Sopenharmony_ci#define LS7A_RTC_REG_BASE		(LS7A_MISC_REG_BASE + 0x00050100)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define LS7A_DMA_CFG			(volatile void *)TO_UNCACHE(LS7A_CHIPCFG_REG_BASE + 0x041c)
798c2ecf20Sopenharmony_ci#define LS7A_DMA_NODE_SHF		8
808c2ecf20Sopenharmony_ci#define LS7A_DMA_NODE_MASK		0x1F00
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define LS7A_INT_MASK_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x020)
838c2ecf20Sopenharmony_ci#define LS7A_INT_EDGE_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x060)
848c2ecf20Sopenharmony_ci#define LS7A_INT_CLEAR_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x080)
858c2ecf20Sopenharmony_ci#define LS7A_INT_HTMSI_EN_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x040)
868c2ecf20Sopenharmony_ci#define LS7A_INT_ROUTE_ENTRY_REG	(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x100)
878c2ecf20Sopenharmony_ci#define LS7A_INT_HTMSI_VEC_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x200)
888c2ecf20Sopenharmony_ci#define LS7A_INT_STATUS_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x3a0)
898c2ecf20Sopenharmony_ci#define LS7A_INT_POL_REG		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x3e0)
908c2ecf20Sopenharmony_ci#define LS7A_LPC_INT_CTL		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2000)
918c2ecf20Sopenharmony_ci#define LS7A_LPC_INT_ENA		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2004)
928c2ecf20Sopenharmony_ci#define LS7A_LPC_INT_STS		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2008)
938c2ecf20Sopenharmony_ci#define LS7A_LPC_INT_CLR		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x200c)
948c2ecf20Sopenharmony_ci#define LS7A_LPC_INT_POL		(volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2010)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define LS7A_PMCON_SOC_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x000)
978c2ecf20Sopenharmony_ci#define LS7A_PMCON_RESUME_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x004)
988c2ecf20Sopenharmony_ci#define LS7A_PMCON_RTC_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x008)
998c2ecf20Sopenharmony_ci#define LS7A_PM1_EVT_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x00c)
1008c2ecf20Sopenharmony_ci#define LS7A_PM1_ENA_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x010)
1018c2ecf20Sopenharmony_ci#define LS7A_PM1_CNT_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x014)
1028c2ecf20Sopenharmony_ci#define LS7A_PM1_TMR_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x018)
1038c2ecf20Sopenharmony_ci#define LS7A_P_CNT_REG			(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x01c)
1048c2ecf20Sopenharmony_ci#define LS7A_GPE0_STS_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x028)
1058c2ecf20Sopenharmony_ci#define LS7A_GPE0_ENA_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x02c)
1068c2ecf20Sopenharmony_ci#define LS7A_RST_CNT_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x030)
1078c2ecf20Sopenharmony_ci#define LS7A_WD_SET_REG			(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x034)
1088c2ecf20Sopenharmony_ci#define LS7A_WD_TIMER_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x038)
1098c2ecf20Sopenharmony_ci#define LS7A_THSENS_CNT_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x04c)
1108c2ecf20Sopenharmony_ci#define LS7A_GEN_RTC_1_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x050)
1118c2ecf20Sopenharmony_ci#define LS7A_GEN_RTC_2_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x054)
1128c2ecf20Sopenharmony_ci#define LS7A_DPM_CFG_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x400)
1138c2ecf20Sopenharmony_ci#define LS7A_DPM_STS_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x404)
1148c2ecf20Sopenharmony_ci#define LS7A_DPM_CNT_REG		(volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x408)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_citypedef enum {
1178c2ecf20Sopenharmony_ci	ACPI_PCI_HOTPLUG_STATUS	= 1 << 1,
1188c2ecf20Sopenharmony_ci	ACPI_CPU_HOTPLUG_STATUS	= 1 << 2,
1198c2ecf20Sopenharmony_ci	ACPI_MEM_HOTPLUG_STATUS	= 1 << 3,
1208c2ecf20Sopenharmony_ci	ACPI_POWERBUTTON_STATUS	= 1 << 8,
1218c2ecf20Sopenharmony_ci	ACPI_RTC_WAKE_STATUS	= 1 << 10,
1228c2ecf20Sopenharmony_ci	ACPI_PCI_WAKE_STATUS	= 1 << 14,
1238c2ecf20Sopenharmony_ci	ACPI_ANY_WAKE_STATUS	= 1 << 15,
1248c2ecf20Sopenharmony_ci} AcpiEventStatusBits;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define HT1LO_OFFSET		0xe0000000000UL
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* PCI Configration Space Base */
1298c2ecf20Sopenharmony_ci#define MCFG_EXT_PCICFG_BASE		0xefe00000000UL
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* REG ACCESS*/
1328c2ecf20Sopenharmony_ci#define ls7a_readb(addr)	(*(volatile unsigned char  *)TO_UNCACHE(addr))
1338c2ecf20Sopenharmony_ci#define ls7a_readw(addr)	(*(volatile unsigned short *)TO_UNCACHE(addr))
1348c2ecf20Sopenharmony_ci#define ls7a_readl(addr)	(*(volatile unsigned int   *)TO_UNCACHE(addr))
1358c2ecf20Sopenharmony_ci#define ls7a_readq(addr)	(*(volatile unsigned long  *)TO_UNCACHE(addr))
1368c2ecf20Sopenharmony_ci#define ls7a_writeb(val, addr)	*(volatile unsigned char  *)TO_UNCACHE(addr) = (val)
1378c2ecf20Sopenharmony_ci#define ls7a_writew(val, addr)	*(volatile unsigned short *)TO_UNCACHE(addr) = (val)
1388c2ecf20Sopenharmony_ci#define ls7a_writel(val, addr)	*(volatile unsigned int   *)TO_UNCACHE(addr) = (val)
1398c2ecf20Sopenharmony_ci#define ls7a_writeq(val, addr)	*(volatile unsigned long  *)TO_UNCACHE(addr) = (val)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_civoid enable_gpe_wakeup(void);
1428c2ecf20Sopenharmony_civoid enable_pci_wakeup(void);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#endif /* __ASM_MACH_LOONGSON64_LOONGSON_H */
145