Commit 0d92745e authored by Andre Przywara's avatar Andre Przywara
Browse files

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: default avatarAndre Przywara <andre.przywara@arm.com>
parent f9ea3a62
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <drivers/delay_timer.h> #include <drivers/delay_timer.h>
#include <drivers/rpi3/gpio/rpi3_gpio.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 int rpi3_gpio_get_direction(int gpio);
static void rpi3_gpio_set_direction(int gpio, int direction); static void rpi3_gpio_set_direction(int gpio, int direction);
...@@ -43,7 +43,6 @@ static const gpio_ops_t rpi3_gpio_ops = { ...@@ -43,7 +43,6 @@ static const gpio_ops_t rpi3_gpio_ops = {
int rpi3_gpio_get_select(int gpio) int rpi3_gpio_get_select(int gpio)
{ {
int ret; int ret;
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 10; int regN = gpio / 10;
int shift = 3 * (gpio % 10); int shift = 3 * (gpio % 10);
uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN); uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN);
...@@ -69,7 +68,6 @@ int rpi3_gpio_get_select(int gpio) ...@@ -69,7 +68,6 @@ int rpi3_gpio_get_select(int gpio)
*/ */
void rpi3_gpio_set_select(int gpio, int fsel) void rpi3_gpio_set_select(int gpio, int fsel)
{ {
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 10; int regN = gpio / 10;
int shift = 3 * (gpio % 10); int shift = 3 * (gpio % 10);
uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN); uintptr_t reg_sel = reg_base + RPI3_GPIO_GPFSEL(regN);
...@@ -106,7 +104,6 @@ static void rpi3_gpio_set_direction(int gpio, int direction) ...@@ -106,7 +104,6 @@ static void rpi3_gpio_set_direction(int gpio, int direction)
static int rpi3_gpio_get_value(int gpio) static int rpi3_gpio_get_value(int gpio)
{ {
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32; int regN = gpio / 32;
int shift = gpio % 32; int shift = gpio % 32;
uintptr_t reg_lev = reg_base + RPI3_GPIO_GPLEV(regN); uintptr_t reg_lev = reg_base + RPI3_GPIO_GPLEV(regN);
...@@ -119,7 +116,6 @@ static int rpi3_gpio_get_value(int gpio) ...@@ -119,7 +116,6 @@ static int rpi3_gpio_get_value(int gpio)
static void rpi3_gpio_set_value(int gpio, int value) static void rpi3_gpio_set_value(int gpio, int value)
{ {
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32; int regN = gpio / 32;
int shift = gpio % 32; int shift = gpio % 32;
uintptr_t reg_set = reg_base + RPI3_GPIO_GPSET(regN); uintptr_t reg_set = reg_base + RPI3_GPIO_GPSET(regN);
...@@ -137,7 +133,6 @@ static void rpi3_gpio_set_value(int gpio, int value) ...@@ -137,7 +133,6 @@ static void rpi3_gpio_set_value(int gpio, int value)
static void rpi3_gpio_set_pull(int gpio, int pull) static void rpi3_gpio_set_pull(int gpio, int pull)
{ {
uintptr_t reg_base = rpi3_gpio_params.reg_base;
int regN = gpio / 32; int regN = gpio / 32;
int shift = gpio % 32; int shift = gpio % 32;
uintptr_t reg_pud = reg_base + RPI3_GPIO_GPPUD; uintptr_t reg_pud = reg_base + RPI3_GPIO_GPPUD;
...@@ -161,9 +156,8 @@ static void rpi3_gpio_set_pull(int gpio, int pull) ...@@ -161,9 +156,8 @@ static void rpi3_gpio_set_pull(int gpio, int pull)
mmio_write_32(reg_pud, 0x0); mmio_write_32(reg_pud, 0x0);
} }
void rpi3_gpio_init(struct rpi3_gpio_params *params) void rpi3_gpio_init(void)
{ {
assert(params != 0); reg_base = RPI3_GPIO_BASE;
memcpy(&rpi3_gpio_params, params, sizeof(struct rpi3_gpio_params));
gpio_init(&rpi3_gpio_ops); gpio_init(&rpi3_gpio_ops);
} }
...@@ -11,11 +11,7 @@ ...@@ -11,11 +11,7 @@
#include <stdint.h> #include <stdint.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
struct rpi3_gpio_params { void rpi3_gpio_init(void);
uintptr_t reg_base;
};
void rpi3_gpio_init(struct rpi3_gpio_params *params);
int rpi3_gpio_get_select(int gpio); int rpi3_gpio_get_select(int gpio);
void rpi3_gpio_set_select(int gpio, int fsel); void rpi3_gpio_set_select(int gpio, int fsel);
......
...@@ -24,17 +24,6 @@ ...@@ -24,17 +24,6 @@
/* Data structure which holds the extents of the trusted SRAM for BL2 */ /* Data structure which holds the extents of the trusted SRAM for BL2 */
static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); 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 */ /* Data structure which holds the MMC info */
static struct mmc_device_info 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, ...@@ -68,7 +57,7 @@ void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
generic_delay_timer_init(); generic_delay_timer_init();
/* Setup GPIO driver */ /* Setup GPIO driver */
rpi3_gpio_setup(); rpi3_gpio_init();
/* Setup the BL2 memory layout */ /* Setup the BL2 memory layout */
bl2_tzram_layout = *mem_layout; bl2_tzram_layout = *mem_layout;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment