]> git.sur5r.net Git - u-boot/blobdiff - drivers/gpio/s5p_gpio.c
drivers: move some drivers to drivers/Makefile
[u-boot] / drivers / gpio / s5p_gpio.c
index 1edf9a26a2f660dcbcdd0f6d3555b9b08ffcdc60..7eeb96d19ff0daad96bfd4ff546bd090048ff73a 100644 (file)
@@ -2,25 +2,12 @@
  * (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/arch/gpio.h>
+#include <asm/gpio.h>
 
 #define CON_MASK(x)            (0xf << ((x) << 2))
 #define CON_SFR(x, v)          ((v) << ((x) << 2))
@@ -48,15 +35,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)
@@ -142,46 +122,57 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
        writel(value, &bank->drv);
 }
 
-struct s5p_gpio_bank *s5p_gpio_get_bank(int nr)
+struct s5p_gpio_bank *s5p_gpio_get_bank(unsigned gpio)
 {
-       int bank = nr / GPIO_PER_BANK;
+       int bank;
+       unsigned g = gpio - s5p_gpio_part_max(gpio);
+
+       bank = g / GPIO_PER_BANK;
        bank *= sizeof(struct s5p_gpio_bank);
+       return (struct s5p_gpio_bank *) (s5p_gpio_base(gpio) + bank);
+}
 
-       return (struct s5p_gpio_bank *) (s5p_gpio_base(nr) + bank);
+int s5p_gpio_get_pin(unsigned gpio)
+{
+       return gpio % GPIO_PER_BANK;
 }
 
-int s5p_gpio_get_pin(int nr)
+/* Common GPIO API */
+
+int gpio_request(unsigned gpio, const char *label)
 {
-       return nr % GPIO_PER_BANK;
+       return 0;
 }
 
-int gpio_request(int gpio, const char *label)
+int gpio_free(unsigned gpio)
 {
        return 0;
 }
 
-int gpio_direction_input(int nr)
+int gpio_direction_input(unsigned gpio)
 {
-       s5p_gpio_direction_input(s5p_gpio_get_bank(nr),
-                               s5p_gpio_get_pin(nr));
+       s5p_gpio_direction_input(s5p_gpio_get_bank(gpio),
+                               s5p_gpio_get_pin(gpio));
        return 0;
 }
 
-int gpio_direction_output(int nr, int value)
+int gpio_direction_output(unsigned gpio, int value)
 {
-       s5p_gpio_direction_output(s5p_gpio_get_bank(nr),
-                                s5p_gpio_get_pin(nr), value);
+       s5p_gpio_direction_output(s5p_gpio_get_bank(gpio),
+                                s5p_gpio_get_pin(gpio), value);
        return 0;
 }
 
-int gpio_get_value(int nr)
+int gpio_get_value(unsigned gpio)
 {
-       return (int) s5p_gpio_get_value(s5p_gpio_get_bank(nr),
-                                      s5p_gpio_get_pin(nr));
+       return (int) s5p_gpio_get_value(s5p_gpio_get_bank(gpio),
+                                      s5p_gpio_get_pin(gpio));
 }
 
-void gpio_set_value(int nr, int value)
+int gpio_set_value(unsigned gpio, int value)
 {
-       s5p_gpio_set_value(s5p_gpio_get_bank(nr),
-                         s5p_gpio_get_pin(nr), value);
+       s5p_gpio_set_value(s5p_gpio_get_bank(gpio),
+                         s5p_gpio_get_pin(gpio), value);
+
+       return 0;
 }