Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 Samsung Electronics |
| 3 | * Minkyu Kang <mk7.kang@samsung.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __ASM_ARCH_GPIO_H |
| 9 | #define __ASM_ARCH_GPIO_H |
| 10 | |
| 11 | #ifndef __ASSEMBLY__ |
| 12 | struct s5p_gpio_bank { |
| 13 | unsigned int con; |
| 14 | unsigned int dat; |
| 15 | unsigned int pull; |
| 16 | unsigned int drv; |
| 17 | unsigned int pdn_con; |
| 18 | unsigned int pdn_pull; |
| 19 | unsigned char res1[8]; |
| 20 | }; |
| 21 | |
Chander Kashyap | 4131a77 | 2011-12-06 23:34:12 +0000 | [diff] [blame] | 22 | struct exynos4_gpio_part1 { |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 23 | struct s5p_gpio_bank a0; |
| 24 | struct s5p_gpio_bank a1; |
| 25 | struct s5p_gpio_bank b; |
| 26 | struct s5p_gpio_bank c0; |
| 27 | struct s5p_gpio_bank c1; |
| 28 | struct s5p_gpio_bank d0; |
| 29 | struct s5p_gpio_bank d1; |
| 30 | struct s5p_gpio_bank e0; |
| 31 | struct s5p_gpio_bank e1; |
| 32 | struct s5p_gpio_bank e2; |
| 33 | struct s5p_gpio_bank e3; |
| 34 | struct s5p_gpio_bank e4; |
| 35 | struct s5p_gpio_bank f0; |
| 36 | struct s5p_gpio_bank f1; |
| 37 | struct s5p_gpio_bank f2; |
| 38 | struct s5p_gpio_bank f3; |
| 39 | }; |
| 40 | |
Chander Kashyap | 4131a77 | 2011-12-06 23:34:12 +0000 | [diff] [blame] | 41 | struct exynos4_gpio_part2 { |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 42 | struct s5p_gpio_bank j0; |
| 43 | struct s5p_gpio_bank j1; |
| 44 | struct s5p_gpio_bank k0; |
| 45 | struct s5p_gpio_bank k1; |
| 46 | struct s5p_gpio_bank k2; |
| 47 | struct s5p_gpio_bank k3; |
| 48 | struct s5p_gpio_bank l0; |
| 49 | struct s5p_gpio_bank l1; |
| 50 | struct s5p_gpio_bank l2; |
| 51 | struct s5p_gpio_bank y0; |
| 52 | struct s5p_gpio_bank y1; |
| 53 | struct s5p_gpio_bank y2; |
| 54 | struct s5p_gpio_bank y3; |
| 55 | struct s5p_gpio_bank y4; |
| 56 | struct s5p_gpio_bank y5; |
| 57 | struct s5p_gpio_bank y6; |
| 58 | struct s5p_gpio_bank res1[80]; |
| 59 | struct s5p_gpio_bank x0; |
| 60 | struct s5p_gpio_bank x1; |
| 61 | struct s5p_gpio_bank x2; |
| 62 | struct s5p_gpio_bank x3; |
| 63 | }; |
| 64 | |
Chander Kashyap | 4131a77 | 2011-12-06 23:34:12 +0000 | [diff] [blame] | 65 | struct exynos4_gpio_part3 { |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 66 | struct s5p_gpio_bank z; |
| 67 | }; |
| 68 | |
Chander Kashyap | 252991e | 2012-12-25 20:13:42 +0000 | [diff] [blame] | 69 | struct exynos4x12_gpio_part1 { |
| 70 | struct s5p_gpio_bank a0; |
| 71 | struct s5p_gpio_bank a1; |
| 72 | struct s5p_gpio_bank b; |
| 73 | struct s5p_gpio_bank c0; |
| 74 | struct s5p_gpio_bank c1; |
| 75 | struct s5p_gpio_bank d0; |
| 76 | struct s5p_gpio_bank d1; |
| 77 | struct s5p_gpio_bank res1[0x5]; |
| 78 | struct s5p_gpio_bank f0; |
| 79 | struct s5p_gpio_bank f1; |
| 80 | struct s5p_gpio_bank f2; |
| 81 | struct s5p_gpio_bank f3; |
| 82 | struct s5p_gpio_bank res2[0x2]; |
| 83 | struct s5p_gpio_bank j0; |
| 84 | struct s5p_gpio_bank j1; |
| 85 | }; |
| 86 | |
| 87 | struct exynos4x12_gpio_part2 { |
| 88 | struct s5p_gpio_bank res1[0x2]; |
| 89 | struct s5p_gpio_bank k0; |
| 90 | struct s5p_gpio_bank k1; |
| 91 | struct s5p_gpio_bank k2; |
| 92 | struct s5p_gpio_bank k3; |
| 93 | struct s5p_gpio_bank l0; |
| 94 | struct s5p_gpio_bank l1; |
| 95 | struct s5p_gpio_bank l2; |
| 96 | struct s5p_gpio_bank y0; |
| 97 | struct s5p_gpio_bank y1; |
| 98 | struct s5p_gpio_bank y2; |
| 99 | struct s5p_gpio_bank y3; |
| 100 | struct s5p_gpio_bank y4; |
| 101 | struct s5p_gpio_bank y5; |
| 102 | struct s5p_gpio_bank y6; |
| 103 | struct s5p_gpio_bank res2[0x3]; |
| 104 | struct s5p_gpio_bank m0; |
| 105 | struct s5p_gpio_bank m1; |
| 106 | struct s5p_gpio_bank m2; |
| 107 | struct s5p_gpio_bank m3; |
| 108 | struct s5p_gpio_bank m4; |
| 109 | struct s5p_gpio_bank res3[0x48]; |
| 110 | struct s5p_gpio_bank x0; |
| 111 | struct s5p_gpio_bank x1; |
| 112 | struct s5p_gpio_bank x2; |
| 113 | struct s5p_gpio_bank x3; |
| 114 | }; |
| 115 | |
| 116 | struct exynos4x12_gpio_part3 { |
| 117 | struct s5p_gpio_bank z; |
| 118 | }; |
| 119 | |
| 120 | struct exynos4x12_gpio_part4 { |
| 121 | struct s5p_gpio_bank v0; |
| 122 | struct s5p_gpio_bank v1; |
| 123 | struct s5p_gpio_bank res1[0x1]; |
| 124 | struct s5p_gpio_bank v2; |
| 125 | struct s5p_gpio_bank v3; |
| 126 | struct s5p_gpio_bank res2[0x1]; |
| 127 | struct s5p_gpio_bank v4; |
| 128 | }; |
| 129 | |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 130 | struct exynos5_gpio_part1 { |
| 131 | struct s5p_gpio_bank a0; |
| 132 | struct s5p_gpio_bank a1; |
| 133 | struct s5p_gpio_bank a2; |
| 134 | struct s5p_gpio_bank b0; |
| 135 | struct s5p_gpio_bank b1; |
| 136 | struct s5p_gpio_bank b2; |
| 137 | struct s5p_gpio_bank b3; |
| 138 | struct s5p_gpio_bank c0; |
| 139 | struct s5p_gpio_bank c1; |
| 140 | struct s5p_gpio_bank c2; |
| 141 | struct s5p_gpio_bank c3; |
| 142 | struct s5p_gpio_bank d0; |
| 143 | struct s5p_gpio_bank d1; |
| 144 | struct s5p_gpio_bank y0; |
| 145 | struct s5p_gpio_bank y1; |
| 146 | struct s5p_gpio_bank y2; |
| 147 | struct s5p_gpio_bank y3; |
| 148 | struct s5p_gpio_bank y4; |
| 149 | struct s5p_gpio_bank y5; |
| 150 | struct s5p_gpio_bank y6; |
Rajeshwari Shinde | ab337bc | 2012-07-03 20:02:59 +0000 | [diff] [blame] | 151 | struct s5p_gpio_bank res1[0x3]; |
| 152 | struct s5p_gpio_bank c4; |
| 153 | struct s5p_gpio_bank res2[0x48]; |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 154 | struct s5p_gpio_bank x0; |
| 155 | struct s5p_gpio_bank x1; |
| 156 | struct s5p_gpio_bank x2; |
| 157 | struct s5p_gpio_bank x3; |
| 158 | }; |
| 159 | |
| 160 | struct exynos5_gpio_part2 { |
| 161 | struct s5p_gpio_bank e0; |
| 162 | struct s5p_gpio_bank e1; |
| 163 | struct s5p_gpio_bank f0; |
| 164 | struct s5p_gpio_bank f1; |
| 165 | struct s5p_gpio_bank g0; |
| 166 | struct s5p_gpio_bank g1; |
| 167 | struct s5p_gpio_bank g2; |
| 168 | struct s5p_gpio_bank h0; |
| 169 | struct s5p_gpio_bank h1; |
| 170 | }; |
| 171 | |
| 172 | struct exynos5_gpio_part3 { |
| 173 | struct s5p_gpio_bank v0; |
| 174 | struct s5p_gpio_bank v1; |
Rajeshwari Shinde | ab337bc | 2012-07-03 20:02:59 +0000 | [diff] [blame] | 175 | struct s5p_gpio_bank res1[0x1]; |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 176 | struct s5p_gpio_bank v2; |
| 177 | struct s5p_gpio_bank v3; |
Rajeshwari Shinde | ab337bc | 2012-07-03 20:02:59 +0000 | [diff] [blame] | 178 | struct s5p_gpio_bank res2[0x1]; |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 179 | struct s5p_gpio_bank v4; |
| 180 | }; |
| 181 | |
| 182 | struct exynos5_gpio_part4 { |
| 183 | struct s5p_gpio_bank z; |
| 184 | }; |
| 185 | |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 186 | /* functions */ |
Łukasz Majewski | 4d954cc | 2011-07-15 00:16:22 +0000 | [diff] [blame] | 187 | void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg); |
| 188 | void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en); |
| 189 | void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio); |
| 190 | void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en); |
| 191 | unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio); |
| 192 | void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode); |
| 193 | void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode); |
| 194 | void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode); |
Łukasz Majewski | 1e04cae | 2011-08-22 22:34:58 +0000 | [diff] [blame] | 195 | |
| 196 | /* GPIO pins per bank */ |
| 197 | #define GPIO_PER_BANK 8 |
| 198 | |
Chander Kashyap | 4131a77 | 2011-12-06 23:34:12 +0000 | [diff] [blame] | 199 | #define exynos4_gpio_part1_get_nr(bank, pin) \ |
| 200 | ((((((unsigned int) &(((struct exynos4_gpio_part1 *) \ |
| 201 | EXYNOS4_GPIO_PART1_BASE)->bank)) \ |
| 202 | - EXYNOS4_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ |
Łukasz Majewski | 1e04cae | 2011-08-22 22:34:58 +0000 | [diff] [blame] | 203 | * GPIO_PER_BANK) + pin) |
| 204 | |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 205 | #define EXYNOS4_GPIO_PART1_MAX ((sizeof(struct exynos4_gpio_part1) \ |
Łukasz Majewski | 1e04cae | 2011-08-22 22:34:58 +0000 | [diff] [blame] | 206 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
| 207 | |
Chander Kashyap | 4131a77 | 2011-12-06 23:34:12 +0000 | [diff] [blame] | 208 | #define exynos4_gpio_part2_get_nr(bank, pin) \ |
| 209 | (((((((unsigned int) &(((struct exynos4_gpio_part2 *) \ |
| 210 | EXYNOS4_GPIO_PART2_BASE)->bank)) \ |
| 211 | - EXYNOS4_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 212 | * GPIO_PER_BANK) + pin) + EXYNOS4_GPIO_PART1_MAX) |
| 213 | |
Chander Kashyap | 252991e | 2012-12-25 20:13:42 +0000 | [diff] [blame] | 214 | #define exynos4x12_gpio_part1_get_nr(bank, pin) \ |
| 215 | ((((((unsigned int) &(((struct exynos4x12_gpio_part1 *) \ |
| 216 | EXYNOS4X12_GPIO_PART1_BASE)->bank)) \ |
| 217 | - EXYNOS4X12_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 218 | * GPIO_PER_BANK) + pin) |
| 219 | |
| 220 | #define EXYNOS4X12_GPIO_PART1_MAX ((sizeof(struct exynos4x12_gpio_part1) \ |
| 221 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
| 222 | |
| 223 | #define exynos4x12_gpio_part2_get_nr(bank, pin) \ |
| 224 | (((((((unsigned int) &(((struct exynos4x12_gpio_part2 *) \ |
| 225 | EXYNOS4X12_GPIO_PART2_BASE)->bank)) \ |
| 226 | - EXYNOS4X12_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 227 | * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART1_MAX) |
| 228 | |
| 229 | #define EXYNOS4X12_GPIO_PART2_MAX ((sizeof(struct exynos4x12_gpio_part2) \ |
| 230 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
| 231 | |
| 232 | #define exynos4x12_gpio_part3_get_nr(bank, pin) \ |
| 233 | (((((((unsigned int) &(((struct exynos4x12_gpio_part3 *) \ |
| 234 | EXYNOS4X12_GPIO_PART3_BASE)->bank)) \ |
| 235 | - EXYNOS4X12_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 236 | * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART2_MAX) |
| 237 | |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 238 | #define exynos5_gpio_part1_get_nr(bank, pin) \ |
| 239 | ((((((unsigned int) &(((struct exynos5_gpio_part1 *) \ |
| 240 | EXYNOS5_GPIO_PART1_BASE)->bank)) \ |
| 241 | - EXYNOS5_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 242 | * GPIO_PER_BANK) + pin) |
| 243 | |
| 244 | #define EXYNOS5_GPIO_PART1_MAX ((sizeof(struct exynos5_gpio_part1) \ |
| 245 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
| 246 | |
| 247 | #define exynos5_gpio_part2_get_nr(bank, pin) \ |
| 248 | (((((((unsigned int) &(((struct exynos5_gpio_part2 *) \ |
| 249 | EXYNOS5_GPIO_PART2_BASE)->bank)) \ |
| 250 | - EXYNOS5_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 251 | * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART1_MAX) |
| 252 | |
| 253 | #define EXYNOS5_GPIO_PART2_MAX ((sizeof(struct exynos5_gpio_part2) \ |
| 254 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
| 255 | |
| 256 | #define exynos5_gpio_part3_get_nr(bank, pin) \ |
| 257 | (((((((unsigned int) &(((struct exynos5_gpio_part3 *) \ |
| 258 | EXYNOS5_GPIO_PART3_BASE)->bank)) \ |
| 259 | - EXYNOS5_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \ |
| 260 | * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART2_MAX) |
Łukasz Majewski | 1e04cae | 2011-08-22 22:34:58 +0000 | [diff] [blame] | 261 | |
| 262 | static inline unsigned int s5p_gpio_base(int nr) |
| 263 | { |
Chander Kashyap | 34076a0 | 2012-02-05 23:01:46 +0000 | [diff] [blame] | 264 | if (cpu_is_exynos5()) { |
| 265 | if (nr < EXYNOS5_GPIO_PART1_MAX) |
| 266 | return EXYNOS5_GPIO_PART1_BASE; |
| 267 | else if (nr < EXYNOS5_GPIO_PART2_MAX) |
| 268 | return EXYNOS5_GPIO_PART2_BASE; |
| 269 | else |
| 270 | return EXYNOS5_GPIO_PART3_BASE; |
| 271 | |
| 272 | } else if (cpu_is_exynos4()) { |
| 273 | if (nr < EXYNOS4_GPIO_PART1_MAX) |
| 274 | return EXYNOS4_GPIO_PART1_BASE; |
| 275 | else |
| 276 | return EXYNOS4_GPIO_PART2_BASE; |
| 277 | } |
Łukasz Majewski | 1e04cae | 2011-08-22 22:34:58 +0000 | [diff] [blame] | 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
Łukasz Majewski | d6614b7 | 2012-09-04 21:47:46 +0000 | [diff] [blame] | 282 | static inline unsigned int s5p_gpio_part_max(int nr) |
| 283 | { |
| 284 | if (cpu_is_exynos5()) { |
| 285 | if (nr < EXYNOS5_GPIO_PART1_MAX) |
| 286 | return 0; |
| 287 | else if (nr < EXYNOS5_GPIO_PART2_MAX) |
| 288 | return EXYNOS5_GPIO_PART1_MAX; |
| 289 | else |
| 290 | return EXYNOS5_GPIO_PART2_MAX; |
| 291 | |
| 292 | } else if (cpu_is_exynos4()) { |
Piotr Wilczek | e4a6136 | 2013-05-21 15:39:04 +0200 | [diff] [blame] | 293 | if (proid_is_exynos4412()) { |
| 294 | if (nr < EXYNOS4X12_GPIO_PART1_MAX) |
| 295 | return 0; |
| 296 | else if (nr < EXYNOS4X12_GPIO_PART2_MAX) |
| 297 | return EXYNOS4X12_GPIO_PART1_MAX; |
| 298 | else |
| 299 | return EXYNOS4X12_GPIO_PART2_MAX; |
| 300 | } else { |
| 301 | if (nr < EXYNOS4_GPIO_PART1_MAX) |
| 302 | return 0; |
| 303 | else |
| 304 | return EXYNOS4_GPIO_PART1_MAX; |
| 305 | } |
Łukasz Majewski | d6614b7 | 2012-09-04 21:47:46 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 310 | #endif |
| 311 | |
| 312 | /* Pin configurations */ |
| 313 | #define GPIO_INPUT 0x0 |
| 314 | #define GPIO_OUTPUT 0x1 |
| 315 | #define GPIO_IRQ 0xf |
| 316 | #define GPIO_FUNC(x) (x) |
| 317 | |
| 318 | /* Pull mode */ |
| 319 | #define GPIO_PULL_NONE 0x0 |
| 320 | #define GPIO_PULL_DOWN 0x1 |
Chander Kashyap | b26418c | 2011-04-18 00:08:43 +0000 | [diff] [blame] | 321 | #define GPIO_PULL_UP 0x3 |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 322 | |
| 323 | /* Drive Strength level */ |
| 324 | #define GPIO_DRV_1X 0x0 |
Chander Kashyap | b26418c | 2011-04-18 00:08:43 +0000 | [diff] [blame] | 325 | #define GPIO_DRV_3X 0x1 |
| 326 | #define GPIO_DRV_2X 0x2 |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 327 | #define GPIO_DRV_4X 0x3 |
| 328 | #define GPIO_DRV_FAST 0x0 |
| 329 | #define GPIO_DRV_SLOW 0x1 |
Minkyu Kang | b1b2468 | 2011-01-24 15:22:23 +0900 | [diff] [blame] | 330 | #endif |