mb/google/nissa/var/rull: Configure Acoustic noise mitigation
[coreboot2.git] / src / soc / amd / common / block / acpi / gpio.c
blob7e7503bfe594def613dc39b8ad85b64b181ebf78
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpigen.h>
4 #include <console/console.h>
5 #include <gpio.h>
7 static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
9 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
10 printk(BIOS_WARNING, "Pin %d should be smaller than"
11 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
12 return -1;
14 if (SOC_GPIO_TOTAL_PINS >= AMD_GPIO_FIRST_REMOTE_GPIO_NUMBER &&
15 gpio_num >= SOC_GPIO_TOTAL_PINS) {
16 printk(BIOS_WARNING, "Pin %d is a remote GPIO which isn't supported"
17 " yet.\n", gpio_num);
18 return -1;
20 /* op (gpio_num) */
21 acpigen_emit_namestring(op);
22 acpigen_write_integer(gpio_num);
23 return 0;
26 static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
28 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
29 printk(BIOS_WARNING, "Pin %d should be smaller than"
30 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
31 return -1;
33 if (SOC_GPIO_TOTAL_PINS >= AMD_GPIO_FIRST_REMOTE_GPIO_NUMBER &&
34 gpio_num >= SOC_GPIO_TOTAL_PINS) {
35 printk(BIOS_WARNING, "Pin %d is a remote GPIO which isn't supported"
36 " yet.\n", gpio_num);
37 return -1;
39 /* Store (op (gpio_num), Local0) */
40 acpigen_write_store();
41 acpigen_soc_gpio_op(op, gpio_num);
42 acpigen_emit_byte(LOCAL0_OP);
43 return 0;
46 int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
48 return acpigen_soc_get_gpio_state("\\_SB.GRXS", gpio_num);
51 int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
53 return acpigen_soc_get_gpio_state("\\_SB.GTXS", gpio_num);
56 int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
58 return acpigen_soc_gpio_op("\\_SB.STXS", gpio_num);
61 int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
63 return acpigen_soc_gpio_op("\\_SB.CTXS", gpio_num);