| 1 |
|
| 2 |
|
| 3 |
#include <device/mmio.h> |
| 4 |
#include <gpio.h> |
| 5 |
|
| 6 |
static void gpio_set_spec_pull_pupd(gpio_t gpio, enum pull_enable enable, |
| 7 |
enum pull_select select) |
| 8 |
{ |
| 9 |
void *reg1; |
| 10 |
void *reg2; |
| 11 |
int bit = gpio.bit; |
| 12 |
|
| 13 |
reg1 = gpio_find_reg_addr(gpio) + gpio.offset; |
| 14 |
reg2 = reg1 + (gpio.base & 0xf0); |
| 15 |
|
| 16 |
if (enable == GPIO_PULL_ENABLE) { |
| 17 |
if (select == GPIO_PULL_DOWN) |
| 18 |
setbits32(reg1, BIT(bit)); |
| 19 |
else |
| 20 |
clrbits32(reg1, BIT(bit)); |
| 21 |
} |
| 22 |
|
| 23 |
if (enable == GPIO_PULL_ENABLE) { |
| 24 |
setbits32(reg2, BIT(bit)); |
| 25 |
} else { |
| 26 |
clrbits32(reg2, BIT(bit)); |
| 27 |
clrbits32(reg2 + 0x010, BIT(bit)); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
static void gpio_set_pull_pu_pd(gpio_t gpio, enum pull_enable enable, |
| 32 |
enum pull_select select) |
| 33 |
{ |
| 34 |
void *reg1; |
| 35 |
void *reg2; |
| 36 |
int bit = gpio.bit; |
| 37 |
|
| 38 |
reg1 = gpio_find_reg_addr(gpio) + gpio.offset; |
| 39 |
reg2 = reg1 - (gpio.base & 0xf0); |
| 40 |
|
| 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)); |
| 48 |
} |
| 49 |
} else { |
| 50 |
clrbits32(reg1, BIT(bit)); |
| 51 |
clrbits32(reg2, BIT(bit)); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
void gpio_set_pull(gpio_t gpio, enum pull_enable enable, |
| 56 |
enum pull_select select) |
| 57 |
{ |
| 58 |
if (gpio.flag) |
| 59 |
gpio_set_spec_pull_pupd(gpio, enable, select); |
| 60 |
else |
| 61 |
gpio_set_pull_pu_pd(gpio, enable, select); |
| 62 |
} |