rpi3: gpio: Simplify GPIO setup

There is really no reason to use and pass around a struct when its only
member is the (fixed) base address.

Remove the struct and just use the base address on its own inside the
GPIO driver. Then set the base address automatically.

This simplifies GPIO setup for users, which now don't need to deal with
zeroing a struct and setting the base address anymore.

Change-Id: I3060f7859e3f8ef9a24cc8fb38307b5da943f127
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
Andre Przywara 2020-03-11 16:10:40 +00:00
parent f9ea3a6291
commit 0d92745e10
3 changed files with 5 additions and 26 deletions

View File

@ -11,7 +11,7 @@
#include <drivers/delay_timer.h>
#include <drivers/rpi3/gpio/rpi3_gpio.h>
static struct rpi3_gpio_params rpi3_gpio_params;
static uintptr_t reg_base;
static int rpi3_gpio_get_direction(int gpio);
static void rpi3_gpio_set_direction(int gpio, int direction);
@ -43,7 +43,6 @@ static const gpio_ops_t rpi3_gpio_ops = {
int rpi3_gpio_get_select(int gpio)
{
int ret;
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 10;
int shift = 3 * (gpio % 10);
uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN);
@ -69,7 +68,6 @@ int rpi3_gpio_get_select(int gpio)
*/
void rpi3_gpio_set_select(int gpio, int fsel)
{
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 10;
int shift = 3 * (gpio % 10);
uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN);
@ -106,7 +104,6 @@ static void rpi3_gpio_set_direction(int gpio, int direction)
static int rpi3_gpio_get_value(int gpio)
{
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32;
int shift = gpio % 32;
uintptr_t reg_lev = reg_base + RPI3_GPIO_GPLEV(regN);
@ -119,7 +116,6 @@ static int rpi3_gpio_get_value(int gpio)
static void rpi3_gpio_set_value(int gpio, int value)
{
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32;
int shift = gpio % 32;
uintptr_t reg_set = reg_base + RPI3_GPIO_GPSET(regN);
@ -137,7 +133,6 @@ static void rpi3_gpio_set_value(int gpio, int value)
static void rpi3_gpio_set_pull(int gpio, int pull)
{
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32;
int shift = gpio % 32;
uintptr_t reg_pud = reg_base + RPI3_GPIO_GPPUD;
@ -161,9 +156,8 @@ static void rpi3_gpio_set_pull(int gpio, int pull)
mmio_write_32(reg_pud, 0x0);
}
void rpi3_gpio_init(struct rpi3_gpio_params *params)
void rpi3_gpio_init(void)
{
assert(params != 0);
memcpy(&rpi3_gpio_params, params, sizeof(struct rpi3_gpio_params));
reg_base = RPI3_GPIO_BASE;
gpio_init(&rpi3_gpio_ops);
}

View File

@ -11,11 +11,7 @@
#include <stdint.h>
#include <drivers/gpio.h>
struct rpi3_gpio_params {
uintptr_t reg_base;
};
void rpi3_gpio_init(struct rpi3_gpio_params *params);
void rpi3_gpio_init(void);
int rpi3_gpio_get_select(int gpio);
void rpi3_gpio_set_select(int gpio, int fsel);

View File

@ -24,17 +24,6 @@
/* Data structure which holds the extents of the trusted SRAM for BL2 */
static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
/* rpi3 GPIO setup function. */
static void rpi3_gpio_setup(void)
{
struct rpi3_gpio_params params;
memset(&params, 0, sizeof(struct rpi3_gpio_params));
params.reg_base = RPI3_GPIO_BASE;
rpi3_gpio_init(&params);
}
/* Data structure which holds the MMC info */
static struct mmc_device_info mmc_info;
@ -68,7 +57,7 @@ void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
generic_delay_timer_init();
/* Setup GPIO driver */
rpi3_gpio_setup();
rpi3_gpio_init();
/* Setup the BL2 memory layout */
bl2_tzram_layout = *mem_layout;