1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * (C) Copyright 2009 Samsung Electronics
4 * Minkyu Kang <mk7.kang@samsung.com>
7 #ifndef __ASM_ARCH_GPIO_H
8 #define __ASM_ARCH_GPIO_H
11 struct s5p_gpio_bank {
17 unsigned int pdn_pull;
18 unsigned char res1[8];
21 /* A list of valid GPIO numbers for the asm-generic/gpio.h interface */
22 enum s5pc100_gpio_pin {
296 S5PC100_GPIO_MAX_PORT
299 enum s5pc110_gpio_pin {
717 S5PC110_GPIO_MAX_PORT
721 unsigned int reg_addr; /* Address of register for this part */
722 unsigned int max_gpio; /* Maximum GPIO in this part */
725 #define S5PC100_GPIO_NUM_PARTS 1
726 static struct gpio_info s5pc100_gpio_data[S5PC100_GPIO_NUM_PARTS] = {
727 { S5PC100_GPIO_BASE, S5PC100_GPIO_MAX_PORT },
730 #define S5PC110_GPIO_NUM_PARTS 1
731 static struct gpio_info s5pc110_gpio_data[S5PC110_GPIO_NUM_PARTS] = {
732 { S5PC110_GPIO_BASE, S5PC110_GPIO_MAX_PORT },
735 static inline struct gpio_info *get_gpio_data(void)
737 if (cpu_is_s5pc100())
738 return s5pc100_gpio_data;
739 else if (cpu_is_s5pc110())
740 return s5pc110_gpio_data;
745 static inline unsigned int get_bank_num(void)
747 if (cpu_is_s5pc100())
748 return S5PC100_GPIO_NUM_PARTS;
749 else if (cpu_is_s5pc110())
750 return S5PC110_GPIO_NUM_PARTS;
756 * This structure helps mapping symbolic GPIO names into indices from
757 * exynos5_gpio_pin/exynos5420_gpio_pin enums.
759 * By convention, symbolic GPIO name is defined as follows:
761 * g[p]<bank><set><bit>, where
763 * <bank> - a single character bank name, as defined by the SOC
764 * <set> - a single digit set number
765 * <bit> - bit number within the set (in 0..7 range).
767 * <set><bit> essentially form an octal number of the GPIO pin within the bank
768 * space. On the 5420 architecture some banks' sets do not start not from zero
769 * ('d' starts from 1 and 'j' starts from 4). To compensate for that and
770 * maintain flat number space withoout holes, those banks use offsets to be
771 * deducted from the pin number.
773 struct gpio_name_num_table {
774 char bank; /* bank name symbol */
775 u8 bank_size; /* total number of pins in the bank */
776 char bank_offset; /* offset of the first bank's pin */
777 unsigned int base; /* index of the first bank's pin in the enum */
780 #define GPIO_PER_BANK 8
781 #define GPIO_ENTRY(name, base, top, offset) { name, top - base, offset, base }
782 static const struct gpio_name_num_table s5pc100_gpio_table[] = {
783 GPIO_ENTRY('a', S5PC100_GPIO_A00, S5PC100_GPIO_B0, 0),
784 GPIO_ENTRY('b', S5PC100_GPIO_B0, S5PC100_GPIO_C0, 0),
785 GPIO_ENTRY('c', S5PC100_GPIO_C0, S5PC100_GPIO_D0, 0),
786 GPIO_ENTRY('d', S5PC100_GPIO_D0, S5PC100_GPIO_E00, 0),
787 GPIO_ENTRY('e', S5PC100_GPIO_E00, S5PC100_GPIO_F00, 0),
788 GPIO_ENTRY('f', S5PC100_GPIO_F00, S5PC100_GPIO_G00, 0),
789 GPIO_ENTRY('g', S5PC100_GPIO_G00, S5PC100_GPIO_I0, 0),
790 GPIO_ENTRY('i', S5PC100_GPIO_I0, S5PC100_GPIO_J00, 0),
791 GPIO_ENTRY('j', S5PC100_GPIO_J00, S5PC100_GPIO_K00, 0),
792 GPIO_ENTRY('k', S5PC100_GPIO_K00, S5PC100_GPIO_L00, 0),
793 GPIO_ENTRY('l', S5PC100_GPIO_L00, S5PC100_GPIO_H00, 0),
794 GPIO_ENTRY('h', S5PC100_GPIO_H00, S5PC100_GPIO_MAX_PORT, 0),
798 static const struct gpio_name_num_table s5pc110_gpio_table[] = {
799 GPIO_ENTRY('a', S5PC110_GPIO_A00, S5PC110_GPIO_B0, 0),
800 GPIO_ENTRY('b', S5PC110_GPIO_B0, S5PC110_GPIO_C00, 0),
801 GPIO_ENTRY('c', S5PC110_GPIO_C00, S5PC110_GPIO_D00, 0),
802 GPIO_ENTRY('d', S5PC110_GPIO_D00, S5PC110_GPIO_E00, 0),
803 GPIO_ENTRY('e', S5PC110_GPIO_E00, S5PC110_GPIO_F00, 0),
804 GPIO_ENTRY('f', S5PC110_GPIO_F00, S5PC110_GPIO_G00, 0),
805 GPIO_ENTRY('g', S5PC110_GPIO_G00, S5PC110_GPIO_I0, 0),
806 GPIO_ENTRY('i', S5PC110_GPIO_I0, S5PC110_GPIO_J00, 0),
807 GPIO_ENTRY('j', S5PC110_GPIO_J00, S5PC110_GPIO_MP010, 0),
808 GPIO_ENTRY('h', S5PC110_GPIO_H00, S5PC110_GPIO_MAX_PORT, 0),
813 void gpio_cfg_pin(int gpio, int cfg);
814 void gpio_set_pull(int gpio, int mode);
815 void gpio_set_drv(int gpio, int mode);
816 void gpio_set_rate(int gpio, int mode);
817 int s5p_gpio_get_pin(unsigned gpio);
819 /* GPIO pins per bank */
820 #define GPIO_PER_BANK 8
823 /* Pin configurations */
824 #define S5P_GPIO_INPUT 0x0
825 #define S5P_GPIO_OUTPUT 0x1
826 #define S5P_GPIO_IRQ 0xf
827 #define S5P_GPIO_FUNC(x) (x)
830 #define S5P_GPIO_PULL_NONE 0x0
831 #define S5P_GPIO_PULL_DOWN 0x1
832 #define S5P_GPIO_PULL_UP 0x2
834 /* Drive Strength level */
835 #define S5P_GPIO_DRV_1X 0x0
836 #define S5P_GPIO_DRV_3X 0x1
837 #define S5P_GPIO_DRV_2X 0x2
838 #define S5P_GPIO_DRV_4X 0x3
839 #define S5P_GPIO_DRV_FAST 0x0
840 #define S5P_GPIO_DRV_SLOW 0x1