loongson.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Author: Huacai Chen <[email protected]>
  4. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  5. */
  6. #ifndef __ASM_LOONGSON_H
  7. #define __ASM_LOONGSON_H
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <linux/irq.h>
  11. #include <linux/pci.h>
  12. #include <asm/addrspace.h>
  13. #include <asm/bootinfo.h>
  14. #define LOONGSON_REG(x) \
  15. (*(volatile u32 *)((char *)TO_UNCACHE(LOONGSON_REG_BASE) + (x)))
  16. #define LOONGSON_LIO_BASE 0x18000000
  17. #define LOONGSON_LIO_SIZE 0x00100000 /* 1M */
  18. #define LOONGSON_LIO_TOP (LOONGSON_LIO_BASE+LOONGSON_LIO_SIZE-1)
  19. #define LOONGSON_BOOT_BASE 0x1c000000
  20. #define LOONGSON_BOOT_SIZE 0x02000000 /* 32M */
  21. #define LOONGSON_BOOT_TOP (LOONGSON_BOOT_BASE+LOONGSON_BOOT_SIZE-1)
  22. #define LOONGSON_REG_BASE 0x1fe00000
  23. #define LOONGSON_REG_SIZE 0x00100000 /* 1M */
  24. #define LOONGSON_REG_TOP (LOONGSON_REG_BASE+LOONGSON_REG_SIZE-1)
  25. /* GPIO Regs - r/w */
  26. #define LOONGSON_GPIODATA LOONGSON_REG(0x11c)
  27. #define LOONGSON_GPIOIE LOONGSON_REG(0x120)
  28. #define LOONGSON_REG_GPIO_BASE (LOONGSON_REG_BASE + 0x11c)
  29. #define MAX_PACKAGES 16
  30. #define xconf_readl(addr) readl(addr)
  31. #define xconf_readq(addr) readq(addr)
  32. static inline void xconf_writel(u32 val, volatile void __iomem *addr)
  33. {
  34. asm volatile (
  35. " st.w %[v], %[hw], 0 \n"
  36. " ld.b $zero, %[hw], 0 \n"
  37. :
  38. : [hw] "r" (addr), [v] "r" (val)
  39. );
  40. }
  41. static inline void xconf_writeq(u64 val64, volatile void __iomem *addr)
  42. {
  43. asm volatile (
  44. " st.d %[v], %[hw], 0 \n"
  45. " ld.b $zero, %[hw], 0 \n"
  46. :
  47. : [hw] "r" (addr), [v] "r" (val64)
  48. );
  49. }
  50. /* ============== LS7A registers =============== */
  51. #define LS7A_PCH_REG_BASE 0x10000000UL
  52. /* LPC regs */
  53. #define LS7A_LPC_REG_BASE (LS7A_PCH_REG_BASE + 0x00002000)
  54. /* CHIPCFG regs */
  55. #define LS7A_CHIPCFG_REG_BASE (LS7A_PCH_REG_BASE + 0x00010000)
  56. /* MISC reg base */
  57. #define LS7A_MISC_REG_BASE (LS7A_PCH_REG_BASE + 0x00080000)
  58. /* ACPI regs */
  59. #define LS7A_ACPI_REG_BASE (LS7A_MISC_REG_BASE + 0x00050000)
  60. /* RTC regs */
  61. #define LS7A_RTC_REG_BASE (LS7A_MISC_REG_BASE + 0x00050100)
  62. #define LS7A_DMA_CFG (volatile void *)TO_UNCACHE(LS7A_CHIPCFG_REG_BASE + 0x041c)
  63. #define LS7A_DMA_NODE_SHF 8
  64. #define LS7A_DMA_NODE_MASK 0x1F00
  65. #define LS7A_INT_MASK_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x020)
  66. #define LS7A_INT_EDGE_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x060)
  67. #define LS7A_INT_CLEAR_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x080)
  68. #define LS7A_INT_HTMSI_EN_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x040)
  69. #define LS7A_INT_ROUTE_ENTRY_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x100)
  70. #define LS7A_INT_HTMSI_VEC_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x200)
  71. #define LS7A_INT_STATUS_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x3a0)
  72. #define LS7A_INT_POL_REG (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x3e0)
  73. #define LS7A_LPC_INT_CTL (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2000)
  74. #define LS7A_LPC_INT_ENA (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2004)
  75. #define LS7A_LPC_INT_STS (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2008)
  76. #define LS7A_LPC_INT_CLR (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x200c)
  77. #define LS7A_LPC_INT_POL (volatile void *)TO_UNCACHE(LS7A_PCH_REG_BASE + 0x2010)
  78. #define LS7A_PMCON_SOC_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x000)
  79. #define LS7A_PMCON_RESUME_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x004)
  80. #define LS7A_PMCON_RTC_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x008)
  81. #define LS7A_PM1_EVT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x00c)
  82. #define LS7A_PM1_ENA_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x010)
  83. #define LS7A_PM1_CNT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x014)
  84. #define LS7A_PM1_TMR_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x018)
  85. #define LS7A_P_CNT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x01c)
  86. #define LS7A_GPE0_STS_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x028)
  87. #define LS7A_GPE0_ENA_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x02c)
  88. #define LS7A_RST_CNT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x030)
  89. #define LS7A_WD_SET_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x034)
  90. #define LS7A_WD_TIMER_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x038)
  91. #define LS7A_THSENS_CNT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x04c)
  92. #define LS7A_GEN_RTC_1_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x050)
  93. #define LS7A_GEN_RTC_2_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x054)
  94. #define LS7A_DPM_CFG_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x400)
  95. #define LS7A_DPM_STS_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x404)
  96. #define LS7A_DPM_CNT_REG (volatile void *)TO_UNCACHE(LS7A_ACPI_REG_BASE + 0x408)
  97. typedef enum {
  98. ACPI_PCI_HOTPLUG_STATUS = 1 << 1,
  99. ACPI_CPU_HOTPLUG_STATUS = 1 << 2,
  100. ACPI_MEM_HOTPLUG_STATUS = 1 << 3,
  101. ACPI_POWERBUTTON_STATUS = 1 << 8,
  102. ACPI_RTC_WAKE_STATUS = 1 << 10,
  103. ACPI_PCI_WAKE_STATUS = 1 << 14,
  104. ACPI_ANY_WAKE_STATUS = 1 << 15,
  105. } AcpiEventStatusBits;
  106. #define HT1LO_OFFSET 0xe0000000000UL
  107. /* PCI Configuration Space Base */
  108. #define MCFG_EXT_PCICFG_BASE 0xefe00000000UL
  109. /* REG ACCESS*/
  110. #define ls7a_readb(addr) (*(volatile unsigned char *)TO_UNCACHE(addr))
  111. #define ls7a_readw(addr) (*(volatile unsigned short *)TO_UNCACHE(addr))
  112. #define ls7a_readl(addr) (*(volatile unsigned int *)TO_UNCACHE(addr))
  113. #define ls7a_readq(addr) (*(volatile unsigned long *)TO_UNCACHE(addr))
  114. #define ls7a_writeb(val, addr) *(volatile unsigned char *)TO_UNCACHE(addr) = (val)
  115. #define ls7a_writew(val, addr) *(volatile unsigned short *)TO_UNCACHE(addr) = (val)
  116. #define ls7a_writel(val, addr) *(volatile unsigned int *)TO_UNCACHE(addr) = (val)
  117. #define ls7a_writeq(val, addr) *(volatile unsigned long *)TO_UNCACHE(addr) = (val)
  118. #endif /* __ASM_LOONGSON_H */