Alexandru Gagniuc (mr.nuke.me@gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/13316
-gerrit
commit d7830fcaa4ad5adae3af25c08b295d5b68871d24 Author: Alexandru Gagniuc alexandrux.gagniuc@intel.com Date: Thu Oct 22 17:49:15 2015 -0700
soc/apollolake/gpio.c: Take global pad offsets in configure_pad()
This allows a user to use the pad macros in gpio_defs.h, without having to worry in which specific community the pad resides. The early UART driver is also updated to use this new mechanism.
Change-Id: If3755fdb7bded522fac3035904232ae43fd02546 Signed-off-by: Alexandru Gagniuc alexandrux.gagniuc@intel.com --- src/soc/intel/apollolake/gpio.c | 36 ++++++++++++++++++++++++++--- src/soc/intel/apollolake/include/soc/gpio.h | 3 +-- src/soc/intel/apollolake/uart_early.c | 9 +++----- 3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/src/soc/intel/apollolake/gpio.c b/src/soc/intel/apollolake/gpio.c index 2796e42..c60a39c 100644 --- a/src/soc/intel/apollolake/gpio.c +++ b/src/soc/intel/apollolake/gpio.c @@ -13,9 +13,39 @@ #include <soc/gpio.h> #include <soc/iosf.h>
+/* This list must be in order, from highest pad numbers, to lowest pad numbers*/ +static const struct pad_community { + uint16_t first_pad; + uint8_t port; +} gpio_communities[] = { + { + .port = GPIO_SOUTHWEST, + .first_pad = SW_OFFSET, + }, { + .port = GPIO_WEST, + .first_pad = W_OFFSET, + }, { + .port = GPIO_NORTHWEST, + .first_pad = NW_OFFSET, + }, { + .port = GPIO_NORTH, + .first_pad = 0, + } +}; + +static const struct pad_community *gpio_get_community(uint16_t pad) +{ + const struct pad_community *map = gpio_communities; + + while (map->first_pad > pad) + map++; + + return map; +} void gpio_configure_pad(const struct pad_config *cfg) { - uint16_t config_offset = PAD_CFG_OFFSET(cfg->pad); - iosf_write(cfg->community, config_offset, cfg->config[0]); - iosf_write(cfg->community, config_offset + 4, cfg->config[1]); + const struct pad_community *comm = gpio_get_community(cfg->pad); + uint16_t config_offset = PAD_CFG_OFFSET(cfg->pad - comm->first_pad); + iosf_write(comm->port, config_offset, cfg->config[0]); + iosf_write(comm->port, config_offset + 4, cfg->config[1]); } diff --git a/src/soc/intel/apollolake/include/soc/gpio.h b/src/soc/intel/apollolake/include/soc/gpio.h index 5744f72..43a242c 100644 --- a/src/soc/intel/apollolake/include/soc/gpio.h +++ b/src/soc/intel/apollolake/include/soc/gpio.h @@ -17,9 +17,8 @@ #include <soc/gpio_defs.h>
struct pad_config { - uint8_t community; - uint8_t pad; uint32_t config[2]; + uint16_t pad; };
/* diff --git a/src/soc/intel/apollolake/uart_early.c b/src/soc/intel/apollolake/uart_early.c index bc02776..aba23b0 100644 --- a/src/soc/intel/apollolake/uart_early.c +++ b/src/soc/intel/apollolake/uart_early.c @@ -17,16 +17,13 @@
static const struct pad_config uart_tx_pad_configs[] = { { - .community = GPIO_NORTH, - .pad = 39, + .pad = GPIO_39, .config = {PAD_CFG0_DEFAULT_FUNC(1), PAD_CFG1_DEFAULT_NATIVE}, }, { - .community = GPIO_NORTH, - .pad = 42, + .pad = GPIO_42, .config = {PAD_CFG0_DEFAULT_FUNC(1), PAD_CFG1_DEFAULT_NATIVE}, }, { - .community = GPIO_NORTH, - .pad = 47, + .pad = GPIO_47, .config = {PAD_CFG0_DEFAULT_FUNC(1), PAD_CFG1_DEFAULT_NATIVE}, }, };