acpi_init.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/io.h>
  3. #include <linux/init.h>
  4. #include <linux/ioport.h>
  5. #include <linux/export.h>
  6. #define SBX00_ACPI_IO_BASE 0x800
  7. #define SBX00_ACPI_IO_SIZE 0x100
  8. #define ACPI_PM_EVT_BLK (SBX00_ACPI_IO_BASE + 0x00) /* 4 bytes */
  9. #define ACPI_PM_CNT_BLK (SBX00_ACPI_IO_BASE + 0x04) /* 2 bytes */
  10. #define ACPI_PMA_CNT_BLK (SBX00_ACPI_IO_BASE + 0x0F) /* 1 byte */
  11. #define ACPI_PM_TMR_BLK (SBX00_ACPI_IO_BASE + 0x18) /* 4 bytes */
  12. #define ACPI_GPE0_BLK (SBX00_ACPI_IO_BASE + 0x10) /* 8 bytes */
  13. #define ACPI_END (SBX00_ACPI_IO_BASE + 0x80)
  14. #define PM_INDEX 0xCD6
  15. #define PM_DATA 0xCD7
  16. #define PM2_INDEX 0xCD0
  17. #define PM2_DATA 0xCD1
  18. /*
  19. * SCI interrupt need acpi space, allocate here
  20. */
  21. static int __init register_acpi_resource(void)
  22. {
  23. request_region(SBX00_ACPI_IO_BASE, SBX00_ACPI_IO_SIZE, "acpi");
  24. return 0;
  25. }
  26. static void pmio_write_index(u16 index, u8 reg, u8 value)
  27. {
  28. outb(reg, index);
  29. outb(value, index + 1);
  30. }
  31. static u8 pmio_read_index(u16 index, u8 reg)
  32. {
  33. outb(reg, index);
  34. return inb(index + 1);
  35. }
  36. void pm_iowrite(u8 reg, u8 value)
  37. {
  38. pmio_write_index(PM_INDEX, reg, value);
  39. }
  40. EXPORT_SYMBOL(pm_iowrite);
  41. u8 pm_ioread(u8 reg)
  42. {
  43. return pmio_read_index(PM_INDEX, reg);
  44. }
  45. EXPORT_SYMBOL(pm_ioread);
  46. void pm2_iowrite(u8 reg, u8 value)
  47. {
  48. pmio_write_index(PM2_INDEX, reg, value);
  49. }
  50. EXPORT_SYMBOL(pm2_iowrite);
  51. u8 pm2_ioread(u8 reg)
  52. {
  53. return pmio_read_index(PM2_INDEX, reg);
  54. }
  55. EXPORT_SYMBOL(pm2_ioread);
  56. static void acpi_hw_clear_status(void)
  57. {
  58. u16 value;
  59. /* PMStatus: Clear WakeStatus/PwrBtnStatus */
  60. value = inw(ACPI_PM_EVT_BLK);
  61. value |= (1 << 8 | 1 << 15);
  62. outw(value, ACPI_PM_EVT_BLK);
  63. /* GPEStatus: Clear all generated events */
  64. outl(inl(ACPI_GPE0_BLK), ACPI_GPE0_BLK);
  65. }
  66. void acpi_registers_setup(void)
  67. {
  68. u32 value;
  69. /* PM Status Base */
  70. pm_iowrite(0x20, ACPI_PM_EVT_BLK & 0xff);
  71. pm_iowrite(0x21, ACPI_PM_EVT_BLK >> 8);
  72. /* PM Control Base */
  73. pm_iowrite(0x22, ACPI_PM_CNT_BLK & 0xff);
  74. pm_iowrite(0x23, ACPI_PM_CNT_BLK >> 8);
  75. /* GPM Base */
  76. pm_iowrite(0x28, ACPI_GPE0_BLK & 0xff);
  77. pm_iowrite(0x29, ACPI_GPE0_BLK >> 8);
  78. /* ACPI End */
  79. pm_iowrite(0x2e, ACPI_END & 0xff);
  80. pm_iowrite(0x2f, ACPI_END >> 8);
  81. /* IO Decode: When AcpiDecodeEnable set, South-Bridge uses the contents
  82. * of the PM registers at index 0x20~0x2B to decode ACPI I/O address. */
  83. pm_iowrite(0x0e, 1 << 3);
  84. /* SCI_EN set */
  85. outw(1, ACPI_PM_CNT_BLK);
  86. /* Enable to generate SCI */
  87. pm_iowrite(0x10, pm_ioread(0x10) | 1);
  88. /* GPM3/GPM9 enable */
  89. value = inl(ACPI_GPE0_BLK + 4);
  90. outl(value | (1 << 14) | (1 << 22), ACPI_GPE0_BLK + 4);
  91. /* Set GPM9 as input */
  92. pm_iowrite(0x8d, pm_ioread(0x8d) & (~(1 << 1)));
  93. /* Set GPM9 as non-output */
  94. pm_iowrite(0x94, pm_ioread(0x94) | (1 << 3));
  95. /* GPM3 config ACPI trigger SCIOUT */
  96. pm_iowrite(0x33, pm_ioread(0x33) & (~(3 << 4)));
  97. /* GPM9 config ACPI trigger SCIOUT */
  98. pm_iowrite(0x3d, pm_ioread(0x3d) & (~(3 << 2)));
  99. /* GPM3 config falling edge trigger */
  100. pm_iowrite(0x37, pm_ioread(0x37) & (~(1 << 6)));
  101. /* No wait for STPGNT# in ACPI Sx state */
  102. pm_iowrite(0x7c, pm_ioread(0x7c) | (1 << 6));
  103. /* Set GPM3 pull-down enable */
  104. value = pm2_ioread(0xf6);
  105. value |= ((1 << 7) | (1 << 3));
  106. pm2_iowrite(0xf6, value);
  107. /* Set GPM9 pull-down enable */
  108. value = pm2_ioread(0xf8);
  109. value |= ((1 << 5) | (1 << 1));
  110. pm2_iowrite(0xf8, value);
  111. }
  112. int __init sbx00_acpi_init(void)
  113. {
  114. register_acpi_resource();
  115. acpi_registers_setup();
  116. acpi_hw_clear_status();
  117. return 0;
  118. }