diff options
author | Sam Lewis <sam.vr.lewis@gmail.com> | 2020-08-03 20:18:29 +1000 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2020-08-19 07:17:37 +0000 |
commit | ad7b2e23ab5954f150a4b2f62378f1e7133e56c9 (patch) | |
tree | 545ce0a7cbf0eb2aa034a45d136ac0998339741f /src/soc/ti/am335x/gpio.c | |
parent | cb287987a1750577e4471d3a474391a2c25321ab (diff) |
cpu/ti/am335x: Move from cpu to soc in tree
The AM335X is a SoC, so should be in the soc tree.
This moves all the existing am335x code to soc/ and updates any
references. It also adds a soc.c file as required for the ramstage.
Change-Id: Ic1ccb0e9b9c24a8b211b723b5f4cc26cdd0eaaab
Signed-off-by: Sam Lewis <sam.vr.lewis@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/44378
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Diffstat (limited to 'src/soc/ti/am335x/gpio.c')
-rw-r--r-- | src/soc/ti/am335x/gpio.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/soc/ti/am335x/gpio.c b/src/soc/ti/am335x/gpio.c new file mode 100644 index 0000000000..d3d3581f86 --- /dev/null +++ b/src/soc/ti/am335x/gpio.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <device/mmio.h> +#include <console/console.h> +#include <soc/ti/am335x/gpio.h> +#include <stdint.h> + +static struct am335x_gpio_regs *gpio_regs_and_bit(unsigned int gpio, + uint32_t *bit) +{ + unsigned int bank = gpio / AM335X_GPIO_BITS_PER_BANK; + + if (bank >= ARRAY_SIZE(am335x_gpio_banks)) { + printk(BIOS_ERR, "Bad gpio index %d.\n", gpio); + return NULL; + } + *bit = 1 << (gpio % 32); + return am335x_gpio_banks[bank]; +} + +void am335x_disable_gpio_irqs(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(am335x_gpio_banks); i++) + write32(&am335x_gpio_banks[i]->irqstatus_clr_0, 0xffffffff); +} + +int gpio_direction_input(unsigned int gpio) +{ + uint32_t bit; + struct am335x_gpio_regs *regs = gpio_regs_and_bit(gpio, &bit); + + if (!regs) + return -1; + setbits32(®s->oe, bit); + return 0; +} + +int gpio_direction_output(unsigned int gpio, int value) +{ + uint32_t bit; + struct am335x_gpio_regs *regs = gpio_regs_and_bit(gpio, &bit); + + if (!regs) + return -1; + if (value) + write32(®s->setdataout, bit); + else + write32(®s->cleardataout, bit); + clrbits32(®s->oe, bit); + return 0; +} + +int gpio_get_value(unsigned int gpio) +{ + uint32_t bit; + struct am335x_gpio_regs *regs = gpio_regs_and_bit(gpio, &bit); + + if (!regs) + return -1; + return (read32(®s->datain) & bit) ? 1 : 0; +} + +int gpio_set_value(unsigned int gpio, int value) +{ + uint32_t bit; + struct am335x_gpio_regs *regs = gpio_regs_and_bit(gpio, &bit); + + if (!regs) + return -1; + if (value) + write32(®s->setdataout, bit); + else + write32(®s->cleardataout, bit); + return 0; +} |