blob: 15ee292e7dc09bbd7c6171a0f24154544588a303 [file] [log] [blame]
Eric Lai65b0afe2021-04-09 11:50:48 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpigen.h>
4#include <console/console.h>
5#include <soc/gpio.h>
6
7static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
8{
9 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
10 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
11 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
12 return -1;
13 }
14 /* op (gpio_num) */
15 acpigen_emit_namestring(op);
16 acpigen_write_integer(gpio_num);
17 return 0;
18}
19
20static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
21{
22 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
23 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
24 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
25 return -1;
26 }
27 /* Store (op (gpio_num), Local0) */
28 acpigen_write_store();
29 acpigen_soc_gpio_op(op, gpio_num);
30 acpigen_emit_byte(LOCAL0_OP);
31 return 0;
32}
33
34int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
35{
36 return acpigen_soc_get_gpio_state("\\_SB.GRXS", gpio_num);
37}
38
39int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
40{
41 return acpigen_soc_get_gpio_state("\\_SB.GTXS", gpio_num);
42}
43
44int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
45{
46 return acpigen_soc_gpio_op("\\_SB.STXS", gpio_num);
47}
48
49int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
50{
51 return acpigen_soc_gpio_op("\\_SB.CTXS", gpio_num);
52}