developer | b7ba14b | 2019-05-02 20:24:50 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, MediaTek Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef MT_GPIO_H |
| 8 | #define MT_GPIO_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <plat/common/common_def.h> |
| 12 | |
| 13 | /* Error Code No. */ |
| 14 | #define RSUCCESS 0 |
| 15 | #define ERACCESS 1 |
| 16 | #define ERINVAL 2 |
| 17 | #define ERWRAPPER 3 |
| 18 | #define MAX_GPIO_PIN MT_GPIO_BASE_MAX |
| 19 | |
| 20 | /* Enumeration for GPIO pin */ |
| 21 | typedef enum GPIO_PIN { |
| 22 | GPIO_UNSUPPORTED = -1, |
| 23 | |
| 24 | GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, |
| 25 | GPIO8, GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, |
| 26 | GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, |
| 27 | GPIO24, GPIO25, GPIO26, GPIO27, GPIO28, GPIO29, GPIO30, GPIO31, |
| 28 | GPIO32, GPIO33, GPIO34, GPIO35, GPIO36, GPIO37, GPIO38, GPIO39, |
| 29 | GPIO40, GPIO41, GPIO42, GPIO43, GPIO44, GPIO45, GPIO46, GPIO47, |
| 30 | GPIO48, GPIO49, GPIO50, GPIO51, GPIO52, GPIO53, GPIO54, GPIO55, |
| 31 | GPIO56, GPIO57, GPIO58, GPIO59, GPIO60, GPIO61, GPIO62, GPIO63, |
| 32 | GPIO64, GPIO65, GPIO66, GPIO67, GPIO68, GPIO69, GPIO70, GPIO71, |
| 33 | GPIO72, GPIO73, GPIO74, GPIO75, GPIO76, GPIO77, GPIO78, GPIO79, |
| 34 | GPIO80, GPIO81, GPIO82, GPIO83, GPIO84, GPIO85, GPIO86, GPIO87, |
| 35 | GPIO88, GPIO89, GPIO90, GPIO91, GPIO92, GPIO93, GPIO94, GPIO95, |
| 36 | GPIO96, GPIO97, GPIO98, GPIO99, GPIO100, GPIO101, GPIO102, GPIO103, |
| 37 | GPIO104, GPIO105, GPIO106, GPIO107, GPIO108, GPIO109, GPIO110, GPIO111, |
| 38 | GPIO112, GPIO113, GPIO114, GPIO115, GPIO116, GPIO117, GPIO118, GPIO119, |
| 39 | GPIO120, GPIO121, GPIO122, GPIO123, GPIO124, GPIO125, GPIO126, GPIO127, |
| 40 | GPIO128, GPIO129, GPIO130, GPIO131, GPIO132, GPIO133, GPIO134, GPIO135, |
| 41 | GPIO136, GPIO137, GPIO138, GPIO139, GPIO140, GPIO141, GPIO142, GPIO143, |
| 42 | GPIO144, GPIO145, GPIO146, GPIO147, GPIO148, GPIO149, GPIO150, GPIO151, |
| 43 | GPIO152, GPIO153, GPIO154, GPIO155, GPIO156, GPIO157, GPIO158, GPIO159, |
| 44 | GPIO160, GPIO161, GPIO162, GPIO163, GPIO164, GPIO165, GPIO166, GPIO167, |
| 45 | GPIO168, GPIO169, GPIO170, GPIO171, GPIO172, GPIO173, GPIO174, GPIO175, |
| 46 | GPIO176, GPIO177, GPIO178, GPIO179, |
| 47 | MT_GPIO_BASE_MAX |
| 48 | } GPIO_PIN; |
| 49 | |
| 50 | /* GPIO MODE CONTROL VALUE*/ |
| 51 | typedef enum { |
| 52 | GPIO_MODE_UNSUPPORTED = -1, |
| 53 | GPIO_MODE_GPIO = 0, |
| 54 | GPIO_MODE_00 = 0, |
| 55 | GPIO_MODE_01, |
| 56 | GPIO_MODE_02, |
| 57 | GPIO_MODE_03, |
| 58 | GPIO_MODE_04, |
| 59 | GPIO_MODE_05, |
| 60 | GPIO_MODE_06, |
| 61 | GPIO_MODE_07, |
| 62 | |
| 63 | GPIO_MODE_MAX, |
| 64 | GPIO_MODE_DEFAULT = GPIO_MODE_00, |
| 65 | } GPIO_MODE; |
| 66 | |
| 67 | /* GPIO DIRECTION */ |
| 68 | typedef enum { |
| 69 | GPIO_DIR_UNSUPPORTED = -1, |
| 70 | GPIO_DIR_OUT = 0, |
| 71 | GPIO_DIR_IN = 1, |
| 72 | GPIO_DIR_MAX, |
| 73 | GPIO_DIR_DEFAULT = GPIO_DIR_IN, |
| 74 | } GPIO_DIR; |
| 75 | |
| 76 | /* GPIO PULL ENABLE*/ |
| 77 | typedef enum { |
| 78 | GPIO_PULL_EN_UNSUPPORTED = -1, |
| 79 | GPIO_PULL_DISABLE = 0, |
| 80 | GPIO_PULL_ENABLE = 1, |
| 81 | GPIO_PULL_ENABLE_R0 = 2, |
| 82 | GPIO_PULL_ENABLE_R1 = 3, |
| 83 | GPIO_PULL_ENABLE_R0R1 = 4, |
| 84 | |
| 85 | GPIO_PULL_EN_MAX, |
| 86 | GPIO_PULL_EN_DEFAULT = GPIO_PULL_ENABLE, |
| 87 | } GPIO_PULL_EN; |
| 88 | |
| 89 | /* GPIO PULL-UP/PULL-DOWN*/ |
| 90 | typedef enum { |
| 91 | GPIO_PULL_UNSUPPORTED = -1, |
| 92 | GPIO_PULL_NONE = 0, |
| 93 | GPIO_PULL_UP = 1, |
| 94 | GPIO_PULL_DOWN = 2, |
| 95 | GPIO_PULL_MAX, |
| 96 | GPIO_PULL_DEFAULT = GPIO_PULL_DOWN |
| 97 | } GPIO_PULL; |
| 98 | |
| 99 | /* GPIO OUTPUT */ |
| 100 | typedef enum { |
| 101 | GPIO_OUT_UNSUPPORTED = -1, |
| 102 | GPIO_OUT_ZERO = 0, |
| 103 | GPIO_OUT_ONE = 1, |
| 104 | |
| 105 | GPIO_OUT_MAX, |
| 106 | GPIO_OUT_DEFAULT = GPIO_OUT_ZERO, |
| 107 | GPIO_DATA_OUT_DEFAULT = GPIO_OUT_ZERO, /*compatible with DCT*/ |
| 108 | } GPIO_OUT; |
| 109 | |
| 110 | /* GPIO INPUT */ |
| 111 | typedef enum { |
| 112 | GPIO_IN_UNSUPPORTED = -1, |
| 113 | GPIO_IN_ZERO = 0, |
| 114 | GPIO_IN_ONE = 1, |
| 115 | |
| 116 | GPIO_IN_MAX, |
| 117 | } GPIO_IN; |
| 118 | |
| 119 | typedef struct { |
| 120 | uint32_t val; |
| 121 | uint32_t set; |
| 122 | uint32_t rst; |
| 123 | uint32_t _align1; |
| 124 | } VAL_REGS; |
| 125 | |
| 126 | typedef struct { |
| 127 | VAL_REGS dir[6]; /*0x0000 ~ 0x005F: 96 bytes */ |
| 128 | uint8_t rsv00[160]; /*0x0060 ~ 0x00FF: 160 bytes */ |
| 129 | VAL_REGS dout[6]; /*0x0100 ~ 0x015F: 96 bytes */ |
| 130 | uint8_t rsv01[160]; /*0x0160 ~ 0x01FF: 160 bytes */ |
| 131 | VAL_REGS din[6]; /*0x0200 ~ 0x025F: 96 bytes */ |
| 132 | uint8_t rsv02[160]; /*0x0260 ~ 0x02FF: 160 bytes */ |
| 133 | VAL_REGS mode[23]; /*0x0300 ~ 0x046F: 368 bytes */ |
| 134 | } GPIO_REGS; |
| 135 | |
| 136 | /* GPIO Driver interface */ |
| 137 | /*direction*/ |
| 138 | void mt_set_gpio_dir(int gpio, int direction); |
| 139 | int mt_get_gpio_dir(int gpio); |
| 140 | |
| 141 | /*pull select*/ |
| 142 | void mt_set_gpio_pull(int gpio, int pull); |
| 143 | int mt_get_gpio_pull(int gpio); |
| 144 | |
| 145 | /*input/output*/ |
| 146 | void mt_set_gpio_out(int gpio, int value); |
| 147 | int mt_get_gpio_out(int gpio); |
| 148 | int mt_get_gpio_in(int gpio); |
| 149 | |
| 150 | /*mode control*/ |
| 151 | void mt_set_gpio_mode(int gpio, int mode); |
| 152 | int mt_get_gpio_mode(int gpio); |
| 153 | |
| 154 | #endif /* MT_GPIO_H */ |