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 #include <device/mmio.h>
3 #include <assert.h>
4 #include <gpio.h>
5 #include <types.h>
6 
7 enum {
9 };
10 
11 static void pos_bit_calc(gpio_t gpio, u32 *pos, u32 *bit)
12 {
13  *pos = gpio.id / MAX_GPIO_REG_BITS;
14  *bit = gpio.id % MAX_GPIO_REG_BITS;
15 }
16 
18  enum pull_select select)
19 {
20  u32 pos;
21  u32 bit;
22  u32 *en_reg, *sel_reg;
23  u32 pin = gpio.id;
24 
25  pos_bit_calc(gpio, &pos, &bit);
26 
27  if (enable == GPIO_PULL_DISABLE) {
28  en_reg = &mtk_gpio->pullen[pos].rst;
29  } else {
30  /* These pins' pulls can't be set through GPIO controller. */
31  assert(pin < 22 || pin > 27);
32  assert(pin < 47 || pin > 56);
33  assert(pin < 57 || pin > 68);
34  assert(pin < 73 || pin > 78);
35  assert(pin < 100 || pin > 105);
36  assert(pin < 119 || pin > 124);
37 
38  en_reg = &mtk_gpio->pullen[pos].set;
39  sel_reg = (select == GPIO_PULL_DOWN) ?
40  (&mtk_gpio->pullsel[pos].rst) :
41  (&mtk_gpio->pullsel[pos].set);
42  write16(sel_reg, 1L << bit);
43  }
44  write16(en_reg, 1L << bit);
45 }
static void write16(void *addr, uint16_t val)
Definition: mmio.h:35
#define assert(statement)
Definition: assert.h:74
pull_enable
Definition: gpio_common.h:11
@ GPIO_PULL_DISABLE
Definition: gpio_common.h:12
pull_select
Definition: gpio_common.h:16
static void pos_bit_calc(gpio_t gpio, u32 *pos, u32 *bit)
Definition: gpio.c:11
@ MAX_GPIO_NUMBER
Definition: gpio.c:8
void gpio_set_pull(gpio_t gpio, enum pull_enable enable, enum pull_select select)
Definition: gpio.c:17
@ MAX_GPIO_REG_BITS
Definition: gpio.h:10
static struct gpio_regs *const mtk_gpio
Definition: gpio.h:347
#define GPIO_PULL_DOWN
Definition: gpio.h:23
uint32_t u32
Definition: stdint.h:51
struct val_regs pullsel[9]
Definition: gpio.h:317
struct val_regs pullen[9]
Definition: gpio.h:315
Definition: pinmux.c:36
uint32_t set
Definition: gpio.h:307
uint32_t rst
Definition: gpio.h:308