aboutsummaryrefslogtreecommitdiff
path: root/src/soc/intel/apollolake/gpio.c
diff options
context:
space:
mode:
authorAndrey Petrov <andrey.petrov@intel.com>2016-02-09 17:02:57 -0800
committerAaron Durbin <adurbin@chromium.org>2016-02-11 21:10:47 +0100
commit57799dcdd1d80e8f1c8f5cd602796c34522bbb15 (patch)
treeb5ad66de4f5f90418b7fecca55e085a4ac523791 /src/soc/intel/apollolake/gpio.c
parent86f6a135a18d8de1c0a02f3c9b8ea2c505056312 (diff)
soc/apollolake: Add minimal GPIO driver
This adds the minimal functionality needed to configure SoC pads. Change-Id: I2e2268eee2b8c822b42a48a95604b0fab86c9833 Signed-off-by: Andrey Petrov <andrey.petrov@intel.com> Reviewed-on: https://review.coreboot.org/13676 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins)
Diffstat (limited to 'src/soc/intel/apollolake/gpio.c')
-rw-r--r--src/soc/intel/apollolake/gpio.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/soc/intel/apollolake/gpio.c b/src/soc/intel/apollolake/gpio.c
new file mode 100644
index 0000000000..33500da558
--- /dev/null
+++ b/src/soc/intel/apollolake/gpio.c
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 Intel Corp.
+ * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#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)
+{
+ 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->config0);
+ iosf_write(comm->port, config_offset + sizeof(uint32_t), cfg->config1);
+}
+
+void gpio_configure_pads(const struct pad_config *cfg, size_t num_pads)
+{
+ uint32_t i;
+
+ for (i = 0; i < num_pads; i++)
+ gpio_configure_pad(cfg + i);
+}