summaryrefslogtreecommitdiff
path: root/src/soc/qualcomm/ipq40xx/gpio.c
diff options
context:
space:
mode:
authorVaradarajan Narayanan <varada@codeaurora.org>2016-03-02 16:57:10 +0530
committerPatrick Georgi <pgeorgi@google.com>2016-05-10 21:34:21 +0200
commita6935c2508c426f30d6bf5bcf4c3130277a0f998 (patch)
treee844bb803e8c069101fdf6ec47017af9dc832713 /src/soc/qualcomm/ipq40xx/gpio.c
parentc84e2fe893e02de3c5d97d26d05462351ac90d91 (diff)
soc/qualcomm/ipq40xx: Initial commit for IPQ40xx SoC support
Copy 'ipq806x' files as a template BUG=chrome-os-partner:49249 TEST=None. Initial code not sure if it will even compile BRANCH=none Original-Commit-Id: dc6a5937953fe61cd4b5a99ca49f9371c4b712d4 Original-Change-Id: If171fcdd3b0561cb6b7dab5f8434de7ef711ea41 Original-Signed-off-by: Varadarajan Narayanan <varada@codeaurora.org> Original-Signed-off-by: Kan Yan <kyan@google.com> Original-Reviewed-on: https://chromium-review.googlesource.com/333178 Original-Commit-Ready: David Hendricks <dhendrix@chromium.org> Original-Tested-by: David Hendricks <dhendrix@chromium.org> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> squashed: soc/qualcomm/ipq40xx: Update ipq806x/storm references Since the files were taken from ipq806x/storm as template. Update those references to reflect ipq40xx/gale. BUG=chrome-os-partner:49249 TEST=None. Initial code not sure if it will even compile BRANCH=none Original-Commit-Id: c6c76d184cc92c09e6826fbdc7d7fac59b2cb69b Original-Change-Id: Ieae1bce25291243b4a6034d37a6949978f318997 Original-Signed-off-by: Varadarajan Narayanan <varada@codeaurora.org> Original-Reviewed-on: https://chromium-review.googlesource.com/333293 Original-Commit-Ready: David Hendricks <dhendrix@chromium.org> Original-Tested-by: David Hendricks <dhendrix@chromium.org> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Change-Id: Ie5794c48131ae562861074b406106734541880d9 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: https://review.coreboot.org/14644 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'src/soc/qualcomm/ipq40xx/gpio.c')
-rw-r--r--src/soc/qualcomm/ipq40xx/gpio.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/soc/qualcomm/ipq40xx/gpio.c b/src/soc/qualcomm/ipq40xx/gpio.c
new file mode 100644
index 0000000000..47c0fcdaa7
--- /dev/null
+++ b/src/soc/qualcomm/ipq40xx/gpio.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <arch/io.h>
+#include <gpio.h>
+#include <soc/iomap.h>
+
+/*******************************************************
+Function description: check for invalid GPIO #
+Arguments :
+gpio_t gpio - Gpio number
+
+Return : GPIO Valid(0)/Invalid(1)
+*******************************************************/
+
+static inline int gpio_not_valid(gpio_t gpio)
+{
+ return (gpio > GPIO_MAX_NUM);
+}
+
+
+/*******************************************************
+Function description: configure GPIO functinality
+Arguments :
+gpio_t gpio - Gpio number
+unsigned func - Functionality number
+unsigned pull - pull up/down, no pull range(0-3)
+unsigned drvstr - range (0 - 7)-> (2- 16)MA steps of 2
+unsigned enable - 0 Disable, 1 - Enable.
+
+Return : None
+*******************************************************/
+
+
+void gpio_tlmm_config_set(gpio_t gpio, unsigned func,
+ unsigned pull, unsigned drvstr,
+ unsigned enable)
+{
+ unsigned val = 0;
+
+ if (gpio_not_valid(gpio))
+ return;
+
+ val |= (pull & GPIO_CFG_PULL_MASK) << GPIO_CFG_PULL_SHIFT;
+ val |= (func & GPIO_CFG_FUNC_MASK) << GPIO_CFG_FUNC_SHIFT;
+ val |= (drvstr & GPIO_CFG_DRV_MASK) << GPIO_CFG_DRV_SHIFT;
+ val |= (enable & GPIO_CFG_OE_MASK) << GPIO_CFG_OE_SHIFT;
+
+ write32(GPIO_CONFIG_ADDR(gpio), val);
+}
+
+/*******************************************************
+Function description: Get GPIO configuration
+Arguments :
+gpio_t gpio - Gpio number
+unsigned *func - Functionality number
+unsigned *pull - pull up/down, no pull range(0-3)
+unsigned *drvstr - range (0 - 7)-> (2- 16)MA steps of 2
+unsigned *enable - 0 - Disable, 1- Enable.
+
+Return : None
+*******************************************************/
+
+
+void gpio_tlmm_config_get(gpio_t gpio, unsigned *func,
+ unsigned *pull, unsigned *drvstr,
+ unsigned *enable)
+{
+ unsigned val;
+ void *addr = GPIO_CONFIG_ADDR(gpio);
+
+ if (gpio_not_valid(gpio))
+ return;
+
+ val = read32(addr);
+
+ *pull = (val >> GPIO_CFG_PULL_SHIFT) & GPIO_CFG_PULL_MASK;
+ *func = (val >> GPIO_CFG_FUNC_SHIFT) & GPIO_CFG_FUNC_MASK;
+ *drvstr = (val >> GPIO_CFG_DRV_SHIFT) & GPIO_CFG_DRV_MASK;
+ *enable = (val >> GPIO_CFG_OE_SHIFT) & GPIO_CFG_OE_MASK;
+}
+
+/*******************************************************
+Function description: get GPIO IO functinality details
+Arguments :
+gpio_t gpio - Gpio number
+unsigned *in - Value of GPIO input
+unsigned *out - Value of GPIO output
+
+Return : None
+*******************************************************/
+int gpio_get(gpio_t gpio)
+{
+ if (gpio_not_valid(gpio))
+ return -1;
+
+
+ return (read32(GPIO_IN_OUT_ADDR(gpio)) >> GPIO_IO_IN_SHIFT) &
+ GPIO_IO_IN_MASK;
+}
+
+void gpio_set(gpio_t gpio, int value)
+{
+ if (gpio_not_valid(gpio))
+ return;
+
+ write32(GPIO_IN_OUT_ADDR(gpio), (value & 1) << GPIO_IO_OUT_SHIFT);
+}
+
+void gpio_input_pulldown(gpio_t gpio)
+{
+ gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
+ GPIO_PULL_DOWN, GPIO_2MA, GPIO_DISABLE);
+}
+
+void gpio_input_pullup(gpio_t gpio)
+{
+ gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
+ GPIO_PULL_UP, GPIO_2MA, GPIO_DISABLE);
+}
+
+void gpio_input(gpio_t gpio)
+{
+ gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
+ GPIO_NO_PULL, GPIO_2MA, GPIO_DISABLE);
+}