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 <device/mmio.h>
4 #include <types.h>
5 #include <gpio.h>
6 
8  uint32_t drive_str, uint32_t enable)
9 {
10  uint32_t reg_val;
11  struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
12 
13  reg_val = ((enable & GPIO_CFG_OE_BMSK) << GPIO_CFG_OE_SHFT) |
14  ((drive_str & GPIO_CFG_DRV_BMSK) << GPIO_CFG_DRV_SHFT) |
17 
18  write32(&regs->cfg, reg_val);
19 }
20 
22 {
23  struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
24  write32(&regs->in_out, (!!value) << GPIO_IO_OUT_SHFT);
25 }
26 
28 {
29  struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
30 
31  return ((read32(&regs->in_out) >> GPIO_IO_IN_SHFT) &
33 }
34 
36 {
39 }
40 
42 {
45 }
46 
48 {
51 }
52 
54 {
58 }
59 
61 {
62  struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
63 
66 
72 }
73 
75 {
76  struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
77 
78  if (!(read32(&regs->intr_status) & GPIO_INTR_STATUS_MASK))
79  return 0;
80 
81  write32(&regs->intr_status, GPIO_INTR_STATUS_DISABLE);
82  return 1;
83 }
pte_t value
Definition: mmu.c:91
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define pull
Definition: asmlib.h:26
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
unsigned int type
Definition: edid.c:57
gpio_irq_type
Definition: gpio_common.h:54
@ GPIO_2MA
Definition: gpio_common.h:70
@ GPIO_INTR_STATUS_DISABLE
Definition: gpio_common.h:50
@ GPIO_INTR_DECT_CTL_MASK
Definition: gpio_common.h:15
@ GPIO_INTR_STATUS_MASK
Definition: gpio_common.h:14
#define GPIO_FUNC_GPIO
Definition: gpio_common.h:9
@ GPIO_IO_OUT_SHFT
Definition: gpio_common.h:45
@ GPIO_IO_IN_SHFT
Definition: gpio_common.h:44
@ GPIO_NO_PULL
Definition: gpio_common.h:62
@ GPIO_CFG_FUNC_SHFT
Definition: gpio_common.h:36
@ GPIO_CFG_DRV_SHFT
Definition: gpio_common.h:37
@ GPIO_CFG_PULL_SHFT
Definition: gpio_common.h:35
@ GPIO_CFG_OE_SHFT
Definition: gpio_common.h:38
@ GPIO_CFG_PULL_BMSK
Definition: gpio_common.h:21
@ GPIO_CFG_DRV_BMSK
Definition: gpio_common.h:23
@ GPIO_CFG_FUNC_BMSK
Definition: gpio_common.h:22
void gpio_set(gpio_t gpio_num, int value)
Definition: gpio.c:174
void gpio_output(gpio_t gpio_num, int value)
Definition: gpio.c:194
int gpio_get(gpio_t gpio_num)
Definition: gpio.c:166
void gpio_input_pullup(gpio_t gpio_num)
Definition: gpio.c:184
void gpio_input_pulldown(gpio_t gpio_num)
Definition: gpio.c:179
void gpio_input(gpio_t gpio_num)
Definition: gpio.c:189
void gpio_input_irq(gpio_t gpio, enum gpio_irq_type type, uint32_t pull)
Definition: gpio.c:65
int gpio_irq_status(gpio_t gpio)
Definition: gpio.c:79
void gpio_configure(gpio_t gpio, uint32_t func, uint32_t pull, uint32_t drive_str, uint32_t enable)
Definition: gpio.c:7
#define GPIO_ENABLE
Definition: gpio.h:38
#define GPIO_DISABLE
Definition: gpio.h:37
#define GPIO_PULL_UP
Definition: gpio.h:24
#define GPIO_PULL_DOWN
Definition: gpio.h:23
#define GPIO_INTR_RAW_STATUS_ENABLE
Definition: gpio.h:32
#define GPIO_CFG_OE_BMSK
Definition: gpio.h:67
#define GPIO_IO_IN_BMSK
Definition: gpio.h:76
#define GPIO_INTR_DECT_CTL_SHIFT
Definition: gpio.h:25
#define GPIO_INTR_RAW_STATUS_EN_SHIFT
Definition: gpio.h:26
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
Definition: pinmux.c:36