From ddd2d641feccb40b737560051761615fbccd34ac Mon Sep 17 00:00:00 2001 From: Gokul Sriram Palanisamy Date: Thu, 11 Aug 2016 19:57:23 +0530 Subject: [PATCH] qca: GPIO: Moved GPIO bit value macros to dt-bindings 1. Moved gpio structure declaration to gpio.h 2. Moved gpio configuration bit value macros to dt-bindings Change-Id: I9da1cc3703a92e02cfa86765c8d4afe5321fed35 Signed-off-by: Gokul Sriram Palanisamy --- arch/arm/dts/ipq40xx-dk01.dtsi | 1 + arch/arm/dts/ipq806x-soc.dtsi | 1 + arch/arm/dts/ipq807x-hk01.dtsi | 1 + arch/arm/include/asm/arch-qcom-common/gpio.h | 61 +++--------- drivers/gpio/ipq_gpio.c | 99 ++++++++++---------- include/configs/ipq40xx.h | 4 + include/configs/ipq807x.h | 4 + include/dt-bindings/qcom/gpio-ipq40xx.h | 79 ++++++++++++++++ include/dt-bindings/qcom/gpio-ipq806x.h | 62 ++++++++++++ include/dt-bindings/qcom/gpio-ipq807x.h | 62 ++++++++++++ 10 files changed, 274 insertions(+), 100 deletions(-) create mode 100644 include/dt-bindings/qcom/gpio-ipq40xx.h create mode 100644 include/dt-bindings/qcom/gpio-ipq806x.h create mode 100644 include/dt-bindings/qcom/gpio-ipq807x.h diff --git a/arch/arm/dts/ipq40xx-dk01.dtsi b/arch/arm/dts/ipq40xx-dk01.dtsi index 14ea17e876..617428b786 100644 --- a/arch/arm/dts/ipq40xx-dk01.dtsi +++ b/arch/arm/dts/ipq40xx-dk01.dtsi @@ -12,6 +12,7 @@ */ #include "skeleton.dtsi" +#include / { serial@78af000 { diff --git a/arch/arm/dts/ipq806x-soc.dtsi b/arch/arm/dts/ipq806x-soc.dtsi index ff1736940e..614fbc8cbd 100644 --- a/arch/arm/dts/ipq806x-soc.dtsi +++ b/arch/arm/dts/ipq806x-soc.dtsi @@ -12,6 +12,7 @@ */ #include "skeleton.dtsi" +#include / { diff --git a/arch/arm/dts/ipq807x-hk01.dtsi b/arch/arm/dts/ipq807x-hk01.dtsi index b09106c4bc..4c740cf0d4 100644 --- a/arch/arm/dts/ipq807x-hk01.dtsi +++ b/arch/arm/dts/ipq807x-hk01.dtsi @@ -12,6 +12,7 @@ */ #include "skeleton.dtsi" +#include / { diff --git a/arch/arm/include/asm/arch-qcom-common/gpio.h b/arch/arm/include/asm/arch-qcom-common/gpio.h index 9b60518b43..c896e1388a 100644 --- a/arch/arm/include/asm/arch-qcom-common/gpio.h +++ b/arch/arm/include/asm/arch-qcom-common/gpio.h @@ -31,56 +31,19 @@ #ifndef GPIO_H #define GPIO_H -/* GPIO TLMM: Direction */ -#define GPIO_INPUT 0 -#define GPIO_OUTPUT 1 +struct qca_gpio_config { + unsigned int gpio; + unsigned int func; + unsigned int out; + unsigned int pull; + unsigned int drvstr; + unsigned int oe; + unsigned int vm; + unsigned int od_en; + unsigned int pu_res; +}; -/* GPIO TLMM: Output value */ -#define GPIO_OUT_LOW 0 -#define GPIO_OUT_HIGH 1 - -/* GPIO TLMM: Pullup/Pulldown */ -#define GPIO_NO_PULL 0 -#define GPIO_PULL_DOWN 1 -#define GPIO_PULL_UP 2 -#define GPIO_NOT_DEF 3 - -/* GPIO TLMM: Drive Strength */ -#define GPIO_2MA 0 -#define GPIO_4MA 1 -#define GPIO_6MA 2 -#define GPIO_8MA 3 -#define GPIO_10MA 4 -#define GPIO_12MA 5 -#define GPIO_14MA 6 -#define GPIO_16MA 7 - -/* GPIO TLMM: Status */ -#define GPIO_OE_DISABLE 0 -#define GPIO_OE_ENABLE 1 - -/* GPIO VM */ -#define GPIO_VM_ENABLE 1 -#define GPIO_VM_DISABLE 0 - -/* GPIO OD */ -#define GPIO_OD_ENABLE 1 -#define GPIO_OD_DISABLE 0 - -/* GPIO PULLUP RES */ -#define GPIO_PULL_RES0 0 -#define GPIO_PULL_RES1 1 -#define GPIO_PULL_RES2 2 -#define GPIO_PULL_RES3 3 - -#define GPIO_OUT (1 << 1) -#define GPIO_IN (1 << 0) - -void gpio_tlmm_config(unsigned int gpio, unsigned int func, - unsigned int out, unsigned int pull, - unsigned int drvstr, unsigned int oe, - unsigned int gpio_vm, unsigned int gpio_od_en, - unsigned int gpio_pu_res); +void gpio_tlmm_config(struct qca_gpio_config *gpio_config); void gpio_set_value(unsigned int gpio, unsigned int out); diff --git a/drivers/gpio/ipq_gpio.c b/drivers/gpio/ipq_gpio.c index a03758fd0e..f439b4a6b8 100644 --- a/drivers/gpio/ipq_gpio.c +++ b/drivers/gpio/ipq_gpio.c @@ -15,73 +15,39 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; -static struct qca_gpio_config { - unsigned int gpio; - unsigned int func; - unsigned int out; - unsigned int pull; - unsigned int drvstr; - unsigned int oe; - unsigned int vm; - unsigned int od_en; - unsigned int pu_res; -}gpio_config __attribute__((section(".data"))); - -int qca_gpio_init(int offset) -{ - for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0; - offset = fdt_next_subnode(gd->fdt_blob, offset)) { - - gpio_config.gpio = fdtdec_get_uint(gd->fdt_blob, offset, "gpio", 0); - gpio_config.func = fdtdec_get_uint(gd->fdt_blob, offset, "func", 0); - gpio_config.out = fdtdec_get_uint(gd->fdt_blob, offset, "out", 0); - gpio_config.pull = fdtdec_get_uint(gd->fdt_blob, offset, "pull", 0); - gpio_config.drvstr = fdtdec_get_uint(gd->fdt_blob, offset, "drvstr", 0); - gpio_config.oe = fdtdec_get_uint(gd->fdt_blob, offset, "oe", 0); - gpio_config.vm = fdtdec_get_uint(gd->fdt_blob, offset, "vm", 0); - gpio_config.od_en = fdtdec_get_uint(gd->fdt_blob, offset, "od_en", 0); - gpio_config.pu_res = fdtdec_get_uint(gd->fdt_blob, offset, "pu_res", 0); - - gpio_tlmm_config(gpio_config); - } - return 0; -} - /*********************************************************** * Function description: configure GPIO functinality * Arguments : -* unsigned int gpio - Gpio number -* unsigned int func - Functionality number -* unsigned int dir - direction 0- i/p, 1- o/p -* unsigned int pull - pull up/down, no pull range(0-3) -* unsigned int drvstr - range (0 - 7)-> (2- 16)MA steps of 2 -* unsigned int oe - 0 - Disable, 1- Enable. +* struct qca_gpio_config gpio_config - GPIO Configuration bits * * Return : None ************************************************************/ -void gpio_tlmm_config(struct qca_gpio_config gpio_config) +void gpio_tlmm_config(struct qca_gpio_config *gpio_config) { unsigned int val = 0; - val |= gpio_config.pull; - val |= gpio_config.func << 2; - val |= gpio_config.drvstr << 6; - val |= gpio_config.oe << 9; - val |= gpio_config.vm << 11; - val |= gpio_config.od_en << 12; - val |= gpio_config.pu_res << 13; + val |= gpio_config->pull; + val |= gpio_config->func << 2; + val |= gpio_config->drvstr << 6; + val |= gpio_config->oe << 9; + val |= gpio_config->vm << 11; + val |= gpio_config->od_en << 12; + val |= gpio_config->pu_res << 13; - unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio_config.gpio); + unsigned int *addr = + (unsigned int *)GPIO_CONFIG_ADDR(gpio_config->gpio); writel(val, addr); /* Output value is only relevant if GPIO has been configured for fixed - * output setting - i.e. func == 0 */ - if (gpio_config.func == 0) { - addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio_config.gpio); + * output setting - i.e. func == 0 + */ + if (gpio_config->func == 0) { + addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio_config->gpio); val = readl(addr); - val |= gpio_config.out << 1; + val |= gpio_config->out << 1; writel(val, addr); } @@ -98,3 +64,34 @@ void gpio_set_value(unsigned int gpio, unsigned int out) val |= out << 1; writel(val, addr); } + +int qca_gpio_init(int offset) +{ + struct qca_gpio_config gpio_config; + + for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0; + offset = fdt_next_subnode(gd->fdt_blob, offset)) { + + gpio_config.gpio = fdtdec_get_uint(gd->fdt_blob, + offset, "gpio", 0); + gpio_config.func = fdtdec_get_uint(gd->fdt_blob, + offset, "func", 0); + gpio_config.out = fdtdec_get_uint(gd->fdt_blob, + offset, "out", 0); + gpio_config.pull = fdtdec_get_uint(gd->fdt_blob, + offset, "pull", 0); + gpio_config.drvstr = fdtdec_get_uint(gd->fdt_blob, + offset, "drvstr", 0); + gpio_config.oe = fdtdec_get_uint(gd->fdt_blob, + offset, "oe", 0); + gpio_config.vm = fdtdec_get_uint(gd->fdt_blob, + offset, "vm", 0); + gpio_config.od_en = fdtdec_get_uint(gd->fdt_blob, + offset, "od_en", 0); + gpio_config.pu_res = fdtdec_get_uint(gd->fdt_blob, + offset, "pu_res", 0); + + gpio_tlmm_config(&gpio_config); + } + return 0; +} diff --git a/include/configs/ipq40xx.h b/include/configs/ipq40xx.h index 80c5302fc0..fd79b3b33d 100644 --- a/include/configs/ipq40xx.h +++ b/include/configs/ipq40xx.h @@ -42,6 +42,10 @@ #define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \ sizeof(CONFIG_SYS_PROMPT) + 16) +#define TLMM_BASE 0x01000000 +#define GPIO_CONFIG_ADDR(x) (TLMM_BASE + (x)*0x1000) +#define GPIO_IN_OUT_ADDR(x) (TLMM_BASE + 0x4 + (x)*0x1000) + #define HAVE_BLOCK_DEVICE #define CONFIG_SYS_SDRAM_BASE 0x80000000 #define CONFIG_SYS_TEXT_BASE 0x87300000 diff --git a/include/configs/ipq807x.h b/include/configs/ipq807x.h index 50684b8ffa..0c18d6583d 100644 --- a/include/configs/ipq807x.h +++ b/include/configs/ipq807x.h @@ -86,6 +86,10 @@ #define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \ sizeof(CONFIG_SYS_PROMPT) + 16) +#define TLMM_BASE 0x01000000 +#define GPIO_CONFIG_ADDR(x) (TLMM_BASE + (x)*0x1000) +#define GPIO_IN_OUT_ADDR(x) (TLMM_BASE + 0x4 + (x)*0x1000) + #define CONFIG_SYS_SDRAM_BASE 0x40000000 #define CONFIG_SYS_TEXT_BASE 0x4AD00000 #define CONFIG_SYS_SDRAM_SIZE 0x10000000 diff --git a/include/dt-bindings/qcom/gpio-ipq40xx.h b/include/dt-bindings/qcom/gpio-ipq40xx.h new file mode 100644 index 0000000000..57829d25f9 --- /dev/null +++ b/include/dt-bindings/qcom/gpio-ipq40xx.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011-2012, 2016, The Linux Foundation. All rights reserved. + * Source : APQ8064 LK Boot + * + * 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 Code Aurora Forum, Inc. 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. + */ + +#ifndef __DT_BINDINGS_IPQ40XX_GPIO_H__ +#define __DT_BINDINGS_IPQ40XX_GPIO_H__ + +/* GPIO TLMM: Direction */ +#define GPIO_INPUT 0 +#define GPIO_OUTPUT 1 + +/* GPIO TLMM: Output value */ +#define GPIO_OUT_LOW 0 +#define GPIO_OUT_HIGH 1 + +/* GPIO TLMM: Pullup/Pulldown */ +#define GPIO_NO_PULL 0 +#define GPIO_PULL_DOWN 1 +#define GPIO_PULL_UP 2 +#define GPIO_NOT_DEF 3 + +/* GPIO TLMM: Drive Strength */ +#define GPIO_2MA 0 +#define GPIO_4MA 1 +#define GPIO_6MA 2 +#define GPIO_8MA 3 +#define GPIO_10MA 4 +#define GPIO_12MA 5 +#define GPIO_14MA 6 +#define GPIO_16MA 7 + +/* GPIO TLMM: Status */ +#define GPIO_OE_DISABLE 0 +#define GPIO_OE_ENABLE 1 + +/* GPIO VM */ +#define GPIO_VM_ENABLE 1 +#define GPIO_VM_DISABLE 0 + +/* GPIO OD */ +#define GPIO_OD_ENABLE 1 +#define GPIO_OD_DISABLE 0 + +/* GPIO PULLUP RES */ +#define GPIO_PULL_RES0 0 +#define GPIO_PULL_RES1 1 +#define GPIO_PULL_RES2 2 +#define GPIO_PULL_RES3 3 + +#define GPIO_OUT (1 << 1) +#define GPIO_IN (1 << 0) + +#endif diff --git a/include/dt-bindings/qcom/gpio-ipq806x.h b/include/dt-bindings/qcom/gpio-ipq806x.h new file mode 100644 index 0000000000..9bf461849a --- /dev/null +++ b/include/dt-bindings/qcom/gpio-ipq806x.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011-2012, 2016, The Linux Foundation. All rights reserved. + * Source : APQ8064 LK Boot + * + * 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 Code Aurora Forum, Inc. 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. + */ + +#ifndef __DT_BINDINGS_IPQ806X_GPIO_H__ +#define __DT_BINDINGS_IPQ806X_GPIO_H__ + +/* GPIO TLMM: Direction */ +#define GPIO_INPUT 0 +#define GPIO_OUTPUT 1 + +/* GPIO TLMM: Output value */ +#define GPIO_OUT_LOW 0 +#define GPIO_OUT_HIGH 1 + +/* GPIO TLMM: Pullup/Pulldown */ +#define GPIO_NO_PULL 0 +#define GPIO_PULL_DOWN 1 +#define GPIO_KEEPER 2 +#define GPIO_PULL_UP 3 + +/* GPIO TLMM: Drive Strength */ +#define GPIO_2MA 0 +#define GPIO_4MA 1 +#define GPIO_6MA 2 +#define GPIO_8MA 3 +#define GPIO_10MA 4 +#define GPIO_12MA 5 +#define GPIO_14MA 6 +#define GPIO_16MA 7 + +/* GPIO TLMM: Status */ +#define GPIO_OE_DISABLE 0 +#define GPIO_OE_ENABLE 1 + +#endif diff --git a/include/dt-bindings/qcom/gpio-ipq807x.h b/include/dt-bindings/qcom/gpio-ipq807x.h new file mode 100644 index 0000000000..0377480039 --- /dev/null +++ b/include/dt-bindings/qcom/gpio-ipq807x.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011-2012, 2016, The Linux Foundation. All rights reserved. + * Source : APQ8064 LK Boot + * + * 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 Code Aurora Forum, Inc. 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. + */ + +#ifndef __DT_BINDINGS_IPQ807X_GPIO_H__ +#define __DT_BINDINGS_IPQ807X_GPIO_H__ + +/* GPIO TLMM: Direction */ +#define GPIO_INPUT 0 +#define GPIO_OUTPUT 1 + +/* GPIO TLMM: Output value */ +#define GPIO_OUT_LOW 0 +#define GPIO_OUT_HIGH 1 + +/* GPIO TLMM: Pullup/Pulldown */ +#define GPIO_NO_PULL 0 +#define GPIO_PULL_DOWN 1 +#define GPIO_KEEPER 2 +#define GPIO_PULL_UP 3 + +/* GPIO TLMM: Drive Strength */ +#define GPIO_2MA 0 +#define GPIO_4MA 1 +#define GPIO_6MA 2 +#define GPIO_8MA 3 +#define GPIO_10MA 4 +#define GPIO_12MA 5 +#define GPIO_14MA 6 +#define GPIO_16MA 7 + +/* GPIO TLMM: Status */ +#define GPIO_OE_DISABLE 0 +#define GPIO_OE_ENABLE 1 + +#endif