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 <gpalan@codeaurora.org>
This commit is contained in:
Gokul Sriram Palanisamy 2016-08-11 19:57:23 +05:30
parent c2a3c549d3
commit ddd2d641fe
10 changed files with 274 additions and 100 deletions

View file

@ -12,6 +12,7 @@
*/
#include "skeleton.dtsi"
#include <dt-bindings/qcom/gpio-ipq40xx.h>
/ {
serial@78af000 {

View file

@ -12,6 +12,7 @@
*/
#include "skeleton.dtsi"
#include <dt-bindings/qcom/gpio-ipq806x.h>
/ {

View file

@ -12,6 +12,7 @@
*/
#include "skeleton.dtsi"
#include <dt-bindings/qcom/gpio-ipq807x.h>
/ {

View file

@ -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);

View file

@ -15,73 +15,39 @@
#include <common.h>
#include <asm/types.h>
#include <fdtdec.h>
#include <asm/arch-qcom-common/gpio.h>
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;
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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