Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / platform / mips / rs780e-acpi.c
blob5b8f9cc32589375154f9e6e20b3279a9671977a0
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 #include <linux/of.h>
7 #include <linux/platform_device.h>
9 static unsigned long acpi_iobase;
11 #define ACPI_PM_EVT_BLK (acpi_iobase + 0x00) /* 4 bytes */
12 #define ACPI_PM_CNT_BLK (acpi_iobase + 0x04) /* 2 bytes */
13 #define ACPI_PMA_CNT_BLK (acpi_iobase + 0x0F) /* 1 byte */
14 #define ACPI_PM_TMR_BLK (acpi_iobase + 0x18) /* 4 bytes */
15 #define ACPI_GPE0_BLK (acpi_iobase + 0x10) /* 8 bytes */
16 #define ACPI_END (acpi_iobase + 0x80)
18 #define PM_INDEX 0xCD6
19 #define PM_DATA 0xCD7
20 #define PM2_INDEX 0xCD0
21 #define PM2_DATA 0xCD1
23 static void pmio_write_index(u16 index, u8 reg, u8 value)
25 outb(reg, index);
26 outb(value, index + 1);
29 static u8 pmio_read_index(u16 index, u8 reg)
31 outb(reg, index);
32 return inb(index + 1);
35 static void pm_iowrite(u8 reg, u8 value)
37 pmio_write_index(PM_INDEX, reg, value);
40 static u8 pm_ioread(u8 reg)
42 return pmio_read_index(PM_INDEX, reg);
45 static void pm2_iowrite(u8 reg, u8 value)
47 pmio_write_index(PM2_INDEX, reg, value);
50 static u8 pm2_ioread(u8 reg)
52 return pmio_read_index(PM2_INDEX, reg);
55 static void acpi_hw_clear_status(void)
57 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);
64 /* GPEStatus: Clear all generated events */
65 outl(inl(ACPI_GPE0_BLK), ACPI_GPE0_BLK);
68 static void acpi_registers_setup(void)
70 u32 value;
72 /* PM Status Base */
73 pm_iowrite(0x20, ACPI_PM_EVT_BLK & 0xff);
74 pm_iowrite(0x21, ACPI_PM_EVT_BLK >> 8);
76 /* PM Control Base */
77 pm_iowrite(0x22, ACPI_PM_CNT_BLK & 0xff);
78 pm_iowrite(0x23, ACPI_PM_CNT_BLK >> 8);
80 /* GPM Base */
81 pm_iowrite(0x28, ACPI_GPE0_BLK & 0xff);
82 pm_iowrite(0x29, ACPI_GPE0_BLK >> 8);
84 /* ACPI End */
85 pm_iowrite(0x2e, ACPI_END & 0xff);
86 pm_iowrite(0x2f, ACPI_END >> 8);
88 /* IO Decode: When AcpiDecodeEnable set, South-Bridge uses the contents
89 * of the PM registers at index 0x20~0x2B to decode ACPI I/O address. */
90 pm_iowrite(0x0e, 1 << 3);
92 /* SCI_EN set */
93 outw(1, ACPI_PM_CNT_BLK);
95 /* Enable to generate SCI */
96 pm_iowrite(0x10, pm_ioread(0x10) | 1);
98 /* GPM3/GPM9 enable */
99 value = inl(ACPI_GPE0_BLK + 4);
100 outl(value | (1 << 14) | (1 << 22), ACPI_GPE0_BLK + 4);
102 /* Set GPM9 as input */
103 pm_iowrite(0x8d, pm_ioread(0x8d) & (~(1 << 1)));
105 /* Set GPM9 as non-output */
106 pm_iowrite(0x94, pm_ioread(0x94) | (1 << 3));
108 /* GPM3 config ACPI trigger SCIOUT */
109 pm_iowrite(0x33, pm_ioread(0x33) & (~(3 << 4)));
111 /* GPM9 config ACPI trigger SCIOUT */
112 pm_iowrite(0x3d, pm_ioread(0x3d) & (~(3 << 2)));
114 /* GPM3 config falling edge trigger */
115 pm_iowrite(0x37, pm_ioread(0x37) & (~(1 << 6)));
117 /* No wait for STPGNT# in ACPI Sx state */
118 pm_iowrite(0x7c, pm_ioread(0x7c) | (1 << 6));
120 /* Set GPM3 pull-down enable */
121 value = pm2_ioread(0xf6);
122 value |= ((1 << 7) | (1 << 3));
123 pm2_iowrite(0xf6, value);
125 /* Set GPM9 pull-down enable */
126 value = pm2_ioread(0xf8);
127 value |= ((1 << 5) | (1 << 1));
128 pm2_iowrite(0xf8, value);
131 static int rs780e_acpi_probe(struct platform_device *pdev)
133 struct resource *res;
135 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
136 if (!res)
137 return -ENODEV;
139 /* SCI interrupt need acpi space, allocate here */
140 if (!request_region(res->start, resource_size(res), "acpi")) {
141 pr_err("RS780E-ACPI: Failed to request IO Region\n");
142 return -EBUSY;
145 acpi_iobase = res->start;
147 acpi_registers_setup();
148 acpi_hw_clear_status();
150 return 0;
153 static const struct of_device_id rs780e_acpi_match[] = {
154 { .compatible = "loongson,rs780e-acpi" },
158 static struct platform_driver rs780e_acpi_driver = {
159 .probe = rs780e_acpi_probe,
160 .driver = {
161 .name = "RS780E-ACPI",
162 .of_match_table = rs780e_acpi_match,
165 builtin_platform_driver(rs780e_acpi_driver);