]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/gpio/s5p_gpio.c
sizes.h - consolidate for all architectures
[karo-tx-uboot.git] / drivers / gpio / s5p_gpio.c
index 47f321392791cfc093c6f6b14b8433c500f7e032..11a0472c695eeb4c9aeae1e663a7a62e186ff411 100644 (file)
@@ -2,26 +2,18 @@
  * (C) Copyright 2009 Samsung Electronics
  * Minkyu Kang <mk7.kang@samsung.com>
  *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
 
+#define S5P_GPIO_GET_BANK(x)   ((x >> S5P_GPIO_BANK_SHIFT) \
+                               & S5P_GPIO_BANK_MASK)
+
+#define S5P_GPIO_GET_PIN(x)    (x & S5P_GPIO_PIN_MASK)
+
 #define CON_MASK(x)            (0xf << ((x) << 2))
 #define CON_SFR(x, v)          ((v) << ((x) << 2))
 
@@ -48,15 +40,8 @@ void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg)
 
 void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en)
 {
-       unsigned int value;
-
        s5p_gpio_cfg_pin(bank, gpio, GPIO_OUTPUT);
-
-       value = readl(&bank->dat);
-       value &= ~DAT_MASK(gpio);
-       if (en)
-               value |= DAT_SET(gpio);
-       writel(value, &bank->dat);
+       s5p_gpio_set_value(bank, gpio, en);
 }
 
 void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio)
@@ -144,15 +129,15 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
 
 struct s5p_gpio_bank *s5p_gpio_get_bank(unsigned gpio)
 {
-       int bank = gpio / GPIO_PER_BANK;
-       bank *= sizeof(struct s5p_gpio_bank);
+       unsigned bank = S5P_GPIO_GET_BANK(gpio);
+       unsigned base = s5p_gpio_base(gpio);
 
-       return (struct s5p_gpio_bank *) (s5p_gpio_base(gpio) + bank);
+       return (struct s5p_gpio_bank *)(base + bank);
 }
 
 int s5p_gpio_get_pin(unsigned gpio)
 {
-       return gpio % GPIO_PER_BANK;
+       return S5P_GPIO_GET_PIN(gpio);
 }
 
 /* Common GPIO API */