coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpigen.h>
4 #include <console/console.h>
5 #include <soc/gpio.h>
6 
7 static 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, "Pin %d should be smaller than"
11  " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
12  return -1;
13  }
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;
19  }
20  /* op (gpio_num) */
22  acpigen_write_integer(gpio_num);
23  return 0;
24 }
25 
26 static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
27 {
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;
32  }
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;
38  }
39  /* Store (op (gpio_num), Local0) */
41  acpigen_soc_gpio_op(op, gpio_num);
43  return 0;
44 }
45 
46 int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
47 {
48  return acpigen_soc_get_gpio_state("\\_SB.GRXS", gpio_num);
49 }
50 
51 int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
52 {
53  return acpigen_soc_get_gpio_state("\\_SB.GTXS", gpio_num);
54 }
55 
56 int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
57 {
58  return acpigen_soc_gpio_op("\\_SB.STXS", gpio_num);
59 }
60 
61 int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
62 {
63  return acpigen_soc_gpio_op("\\_SB.CTXS", gpio_num);
64 }
void acpigen_emit_namestring(const char *namepath)
Definition: acpigen.c:275
void acpigen_write_store(void)
Definition: acpigen.c:1333
void acpigen_write_integer(uint64_t data)
Definition: acpigen.c:136
void acpigen_emit_byte(unsigned char b)
Definition: acpigen.c:61
#define printk(level,...)
Definition: stdlib.h:16
@ LOCAL0_OP
Definition: acpigen.h:81
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
#define SOC_GPIO_TOTAL_PINS
Definition: gpio.h:18
int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
Definition: gpio.c:51
int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
Definition: gpio.c:61
static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
Definition: gpio.c:7
int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
Definition: gpio.c:46
int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
Definition: gpio.c:56
static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
Definition: gpio.c:26
#define AMD_GPIO_FIRST_REMOTE_GPIO_NUMBER
Definition: gpio_defs.h:79