gpio-exynos4.c 7.81 KB
Newer Older
1
/* linux/arch/arm/mach-exynos4/gpiolib.c
2
 *
3
 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
4 5
 *		http://www.samsung.com
 *
6
 * EXYNOS4 - GPIOlib support
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/gpio.h>

#include <mach/map.h>

#include <plat/gpio-core.h>
#include <plat/gpio-cfg.h>
#include <plat/gpio-cfg-helpers.h>

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
int s3c_gpio_setpull_exynos4(struct s3c_gpio_chip *chip,
				unsigned int off, s3c_gpio_pull_t pull)
{
	if (pull == S3C_GPIO_PULL_UP)
		pull = 3;

	return s3c_gpio_setpull_updown(chip, off, pull);
}

s3c_gpio_pull_t s3c_gpio_getpull_exynos4(struct s3c_gpio_chip *chip,
						unsigned int off)
{
	s3c_gpio_pull_t pull;

	pull = s3c_gpio_getpull_updown(chip, off);
	if (pull == 3)
		pull = S3C_GPIO_PULL_UP;

	return pull;
}

45 46
static struct s3c_gpio_cfg gpio_cfg = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
47 48
	.set_pull	= s3c_gpio_setpull_exynos4,
	.get_pull	= s3c_gpio_getpull_exynos4,
49 50 51 52
};

static struct s3c_gpio_cfg gpio_cfg_noint = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
53 54
	.set_pull	= s3c_gpio_setpull_exynos4,
	.get_pull	= s3c_gpio_getpull_exynos4,
55 56 57 58 59 60 61 62 63 64 65 66
};

/*
 * Following are the gpio banks in v310.
 *
 * The 'config' member when left to NULL, is initialized to the default
 * structure gpio_cfg in the init function below.
 *
 * The 'base' member is also initialized in the init function below.
 * Note: The initialization of 'base' member of s3c_gpio_chip structure
 * uses the above macro and depends on the banks being listed in order here.
 */
67
static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
68 69
	{
		.chip	= {
70 71
			.base	= EXYNOS4_GPA0(0),
			.ngpio	= EXYNOS4_GPIO_A0_NR,
72 73 74 75
			.label	= "GPA0",
		},
	}, {
		.chip	= {
76 77
			.base	= EXYNOS4_GPA1(0),
			.ngpio	= EXYNOS4_GPIO_A1_NR,
78 79 80 81
			.label	= "GPA1",
		},
	}, {
		.chip	= {
82 83
			.base	= EXYNOS4_GPB(0),
			.ngpio	= EXYNOS4_GPIO_B_NR,
84 85 86 87
			.label	= "GPB",
		},
	}, {
		.chip	= {
88 89
			.base	= EXYNOS4_GPC0(0),
			.ngpio	= EXYNOS4_GPIO_C0_NR,
90 91 92 93
			.label	= "GPC0",
		},
	}, {
		.chip	= {
94 95
			.base	= EXYNOS4_GPC1(0),
			.ngpio	= EXYNOS4_GPIO_C1_NR,
96 97 98 99
			.label	= "GPC1",
		},
	}, {
		.chip	= {
100 101
			.base	= EXYNOS4_GPD0(0),
			.ngpio	= EXYNOS4_GPIO_D0_NR,
102 103 104 105
			.label	= "GPD0",
		},
	}, {
		.chip	= {
106 107
			.base	= EXYNOS4_GPD1(0),
			.ngpio	= EXYNOS4_GPIO_D1_NR,
108 109 110 111
			.label	= "GPD1",
		},
	}, {
		.chip	= {
112 113
			.base	= EXYNOS4_GPE0(0),
			.ngpio	= EXYNOS4_GPIO_E0_NR,
114 115 116 117
			.label	= "GPE0",
		},
	}, {
		.chip	= {
118 119
			.base	= EXYNOS4_GPE1(0),
			.ngpio	= EXYNOS4_GPIO_E1_NR,
120 121 122 123
			.label	= "GPE1",
		},
	}, {
		.chip	= {
124 125
			.base	= EXYNOS4_GPE2(0),
			.ngpio	= EXYNOS4_GPIO_E2_NR,
126 127 128 129
			.label	= "GPE2",
		},
	}, {
		.chip	= {
130 131
			.base	= EXYNOS4_GPE3(0),
			.ngpio	= EXYNOS4_GPIO_E3_NR,
132 133 134 135
			.label	= "GPE3",
		},
	}, {
		.chip	= {
136 137
			.base	= EXYNOS4_GPE4(0),
			.ngpio	= EXYNOS4_GPIO_E4_NR,
138 139 140 141
			.label	= "GPE4",
		},
	}, {
		.chip	= {
142 143
			.base	= EXYNOS4_GPF0(0),
			.ngpio	= EXYNOS4_GPIO_F0_NR,
144 145 146 147
			.label	= "GPF0",
		},
	}, {
		.chip	= {
148 149
			.base	= EXYNOS4_GPF1(0),
			.ngpio	= EXYNOS4_GPIO_F1_NR,
150 151 152 153
			.label	= "GPF1",
		},
	}, {
		.chip	= {
154 155
			.base	= EXYNOS4_GPF2(0),
			.ngpio	= EXYNOS4_GPIO_F2_NR,
156 157 158 159
			.label	= "GPF2",
		},
	}, {
		.chip	= {
160 161
			.base	= EXYNOS4_GPF3(0),
			.ngpio	= EXYNOS4_GPIO_F3_NR,
162 163 164 165 166
			.label	= "GPF3",
		},
	},
};

167
static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
168 169
	{
		.chip	= {
170 171
			.base	= EXYNOS4_GPJ0(0),
			.ngpio	= EXYNOS4_GPIO_J0_NR,
172 173 174 175
			.label	= "GPJ0",
		},
	}, {
		.chip	= {
176 177
			.base	= EXYNOS4_GPJ1(0),
			.ngpio	= EXYNOS4_GPIO_J1_NR,
178 179 180 181
			.label	= "GPJ1",
		},
	}, {
		.chip	= {
182 183
			.base	= EXYNOS4_GPK0(0),
			.ngpio	= EXYNOS4_GPIO_K0_NR,
184 185 186 187
			.label	= "GPK0",
		},
	}, {
		.chip	= {
188 189
			.base	= EXYNOS4_GPK1(0),
			.ngpio	= EXYNOS4_GPIO_K1_NR,
190 191 192 193
			.label	= "GPK1",
		},
	}, {
		.chip	= {
194 195
			.base	= EXYNOS4_GPK2(0),
			.ngpio	= EXYNOS4_GPIO_K2_NR,
196 197 198 199
			.label	= "GPK2",
		},
	}, {
		.chip	= {
200 201
			.base	= EXYNOS4_GPK3(0),
			.ngpio	= EXYNOS4_GPIO_K3_NR,
202 203 204 205
			.label	= "GPK3",
		},
	}, {
		.chip	= {
206 207
			.base	= EXYNOS4_GPL0(0),
			.ngpio	= EXYNOS4_GPIO_L0_NR,
208 209 210 211
			.label	= "GPL0",
		},
	}, {
		.chip	= {
212 213
			.base	= EXYNOS4_GPL1(0),
			.ngpio	= EXYNOS4_GPIO_L1_NR,
214 215 216 217
			.label	= "GPL1",
		},
	}, {
		.chip	= {
218 219
			.base	= EXYNOS4_GPL2(0),
			.ngpio	= EXYNOS4_GPIO_L2_NR,
220 221
			.label	= "GPL2",
		},
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY0(0),
			.ngpio	= EXYNOS4_GPIO_Y0_NR,
			.label	= "GPY0",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY1(0),
			.ngpio	= EXYNOS4_GPIO_Y1_NR,
			.label	= "GPY1",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY2(0),
			.ngpio	= EXYNOS4_GPIO_Y2_NR,
			.label	= "GPY2",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY3(0),
			.ngpio	= EXYNOS4_GPIO_Y3_NR,
			.label	= "GPY3",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY4(0),
			.ngpio	= EXYNOS4_GPIO_Y4_NR,
			.label	= "GPY4",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY5(0),
			.ngpio	= EXYNOS4_GPIO_Y5_NR,
			.label	= "GPY5",
		},
	}, {
		.config	= &gpio_cfg_noint,
		.chip	= {
			.base	= EXYNOS4_GPY6(0),
			.ngpio	= EXYNOS4_GPIO_Y6_NR,
			.label	= "GPY6",
		},
271 272 273 274 275
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC00),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(0),
		.chip	= {
276 277
			.base	= EXYNOS4_GPX0(0),
			.ngpio	= EXYNOS4_GPIO_X0_NR,
278 279 280 281 282 283 284 285
			.label	= "GPX0",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC20),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(8),
		.chip	= {
286 287
			.base	= EXYNOS4_GPX1(0),
			.ngpio	= EXYNOS4_GPIO_X1_NR,
288 289 290 291 292 293 294 295
			.label	= "GPX1",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC40),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(16),
		.chip	= {
296 297
			.base	= EXYNOS4_GPX2(0),
			.ngpio	= EXYNOS4_GPIO_X2_NR,
298 299 300 301 302 303 304 305
			.label	= "GPX2",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC60),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(24),
		.chip	= {
306 307
			.base	= EXYNOS4_GPX3(0),
			.ngpio	= EXYNOS4_GPIO_X3_NR,
308 309 310 311 312 313
			.label	= "GPX3",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	},
};

314
static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
315 316
	{
		.chip	= {
317 318
			.base	= EXYNOS4_GPZ(0),
			.ngpio	= EXYNOS4_GPIO_Z_NR,
319 320 321 322 323
			.label	= "GPZ",
		},
	},
};

324
static __init int exynos4_gpiolib_init(void)
325 326 327
{
	struct s3c_gpio_chip *chip;
	int i;
328
	int group = 0;
329 330 331 332
	int nr_chips;

	/* GPIO part 1 */

333 334
	chip = exynos4_gpio_part1_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
335 336

	for (i = 0; i < nr_chips; i++, chip++) {
337
		if (chip->config == NULL) {
338
			chip->config = &gpio_cfg;
339 340 341
			/* Assign the GPIO interrupt group */
			chip->group = group++;
		}
342 343 344 345
		if (chip->base == NULL)
			chip->base = S5P_VA_GPIO1 + (i) * 0x20;
	}

346
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
347 348 349

	/* GPIO part 2 */

350 351
	chip = exynos4_gpio_part2_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
352 353

	for (i = 0; i < nr_chips; i++, chip++) {
354
		if (chip->config == NULL) {
355
			chip->config = &gpio_cfg;
356 357 358
			/* Assign the GPIO interrupt group */
			chip->group = group++;
		}
359 360 361 362
		if (chip->base == NULL)
			chip->base = S5P_VA_GPIO2 + (i) * 0x20;
	}

363
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
364 365 366

	/* GPIO part 3 */

367 368
	chip = exynos4_gpio_part3_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
369 370

	for (i = 0; i < nr_chips; i++, chip++) {
371
		if (chip->config == NULL) {
372
			chip->config = &gpio_cfg;
373 374 375
			/* Assign the GPIO interrupt group */
			chip->group = group++;
		}
376 377 378 379
		if (chip->base == NULL)
			chip->base = S5P_VA_GPIO3 + (i) * 0x20;
	}

380
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
381 382
	s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
	s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
383 384 385

	return 0;
}
386
core_initcall(exynos4_gpiolib_init);