tree: Remove unused <assert.h>
[coreboot.git] / src / soc / mediatek / common / gpio_op.c
bloba45e54390c03a681e8006891b9698a216e473d4d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
4 #include <gpio.h>
6 static void gpio_set_spec_pull_pupd(gpio_t gpio, enum pull_enable enable,
7 enum pull_select select)
9 void *reg1;
10 void *reg2;
11 int bit = gpio.bit;
13 reg1 = gpio_find_reg_addr(gpio) + gpio.offset;
14 reg2 = reg1 + (gpio.base & 0xf0);
16 if (enable == GPIO_PULL_ENABLE) {
17 if (select == GPIO_PULL_DOWN)
18 setbits32(reg1, BIT(bit));
19 else
20 clrbits32(reg1, BIT(bit));
23 if (enable == GPIO_PULL_ENABLE) {
24 setbits32(reg2, BIT(bit));
25 } else {
26 clrbits32(reg2, BIT(bit));
27 clrbits32(reg2 + 0x010, BIT(bit));
31 static void gpio_set_pull_pu_pd(gpio_t gpio, enum pull_enable enable,
32 enum pull_select select)
34 void *reg1;
35 void *reg2;
36 int bit = gpio.bit;
38 reg1 = gpio_find_reg_addr(gpio) + gpio.offset;
39 reg2 = reg1 - (gpio.base & 0xf0);
41 if (enable == GPIO_PULL_ENABLE) {
42 if (select == GPIO_PULL_DOWN) {
43 clrbits32(reg1, BIT(bit));
44 setbits32(reg2, BIT(bit));
45 } else {
46 clrbits32(reg2, BIT(bit));
47 setbits32(reg1, BIT(bit));
49 } else {
50 clrbits32(reg1, BIT(bit));
51 clrbits32(reg2, BIT(bit));
55 void gpio_set_pull(gpio_t gpio, enum pull_enable enable,
56 enum pull_select select)
58 if (gpio.flag)
59 gpio_set_spec_pull_pupd(gpio, enable, select);
60 else
61 gpio_set_pull_pu_pd(gpio, enable, select);