gpio-exynos4.c 7.8 KB
Newer Older
G
Grant Likely 已提交
1 2
/*
 * EXYNOS4 - GPIOlib support
J
Jongpill Lee 已提交
3
 *
4
 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
J
Jongpill Lee 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *		http://www.samsung.com
 *
 * 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>

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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;
}

J
Jongpill Lee 已提交
44 45
static struct s3c_gpio_cfg gpio_cfg = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
46 47
	.set_pull	= s3c_gpio_setpull_exynos4,
	.get_pull	= s3c_gpio_getpull_exynos4,
J
Jongpill Lee 已提交
48 49 50 51
};

static struct s3c_gpio_cfg gpio_cfg_noint = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
52 53
	.set_pull	= s3c_gpio_setpull_exynos4,
	.get_pull	= s3c_gpio_getpull_exynos4,
J
Jongpill Lee 已提交
54 55 56 57 58 59 60 61 62 63 64 65
};

/*
 * 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.
 */
66
static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
J
Jongpill Lee 已提交
67 68
	{
		.chip	= {
69 70
			.base	= EXYNOS4_GPA0(0),
			.ngpio	= EXYNOS4_GPIO_A0_NR,
J
Jongpill Lee 已提交
71 72 73 74
			.label	= "GPA0",
		},
	}, {
		.chip	= {
75 76
			.base	= EXYNOS4_GPA1(0),
			.ngpio	= EXYNOS4_GPIO_A1_NR,
J
Jongpill Lee 已提交
77 78 79 80
			.label	= "GPA1",
		},
	}, {
		.chip	= {
81 82
			.base	= EXYNOS4_GPB(0),
			.ngpio	= EXYNOS4_GPIO_B_NR,
J
Jongpill Lee 已提交
83 84 85 86
			.label	= "GPB",
		},
	}, {
		.chip	= {
87 88
			.base	= EXYNOS4_GPC0(0),
			.ngpio	= EXYNOS4_GPIO_C0_NR,
J
Jongpill Lee 已提交
89 90 91 92
			.label	= "GPC0",
		},
	}, {
		.chip	= {
93 94
			.base	= EXYNOS4_GPC1(0),
			.ngpio	= EXYNOS4_GPIO_C1_NR,
J
Jongpill Lee 已提交
95 96 97 98
			.label	= "GPC1",
		},
	}, {
		.chip	= {
99 100
			.base	= EXYNOS4_GPD0(0),
			.ngpio	= EXYNOS4_GPIO_D0_NR,
J
Jongpill Lee 已提交
101 102 103 104
			.label	= "GPD0",
		},
	}, {
		.chip	= {
105 106
			.base	= EXYNOS4_GPD1(0),
			.ngpio	= EXYNOS4_GPIO_D1_NR,
J
Jongpill Lee 已提交
107 108 109 110
			.label	= "GPD1",
		},
	}, {
		.chip	= {
111 112
			.base	= EXYNOS4_GPE0(0),
			.ngpio	= EXYNOS4_GPIO_E0_NR,
J
Jongpill Lee 已提交
113 114 115 116
			.label	= "GPE0",
		},
	}, {
		.chip	= {
117 118
			.base	= EXYNOS4_GPE1(0),
			.ngpio	= EXYNOS4_GPIO_E1_NR,
J
Jongpill Lee 已提交
119 120 121 122
			.label	= "GPE1",
		},
	}, {
		.chip	= {
123 124
			.base	= EXYNOS4_GPE2(0),
			.ngpio	= EXYNOS4_GPIO_E2_NR,
J
Jongpill Lee 已提交
125 126 127 128
			.label	= "GPE2",
		},
	}, {
		.chip	= {
129 130
			.base	= EXYNOS4_GPE3(0),
			.ngpio	= EXYNOS4_GPIO_E3_NR,
J
Jongpill Lee 已提交
131 132 133 134
			.label	= "GPE3",
		},
	}, {
		.chip	= {
135 136
			.base	= EXYNOS4_GPE4(0),
			.ngpio	= EXYNOS4_GPIO_E4_NR,
J
Jongpill Lee 已提交
137 138 139 140
			.label	= "GPE4",
		},
	}, {
		.chip	= {
141 142
			.base	= EXYNOS4_GPF0(0),
			.ngpio	= EXYNOS4_GPIO_F0_NR,
J
Jongpill Lee 已提交
143 144 145 146
			.label	= "GPF0",
		},
	}, {
		.chip	= {
147 148
			.base	= EXYNOS4_GPF1(0),
			.ngpio	= EXYNOS4_GPIO_F1_NR,
J
Jongpill Lee 已提交
149 150 151 152
			.label	= "GPF1",
		},
	}, {
		.chip	= {
153 154
			.base	= EXYNOS4_GPF2(0),
			.ngpio	= EXYNOS4_GPIO_F2_NR,
J
Jongpill Lee 已提交
155 156 157 158
			.label	= "GPF2",
		},
	}, {
		.chip	= {
159 160
			.base	= EXYNOS4_GPF3(0),
			.ngpio	= EXYNOS4_GPIO_F3_NR,
J
Jongpill Lee 已提交
161 162 163 164 165
			.label	= "GPF3",
		},
	},
};

166
static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
J
Jongpill Lee 已提交
167 168
	{
		.chip	= {
169 170
			.base	= EXYNOS4_GPJ0(0),
			.ngpio	= EXYNOS4_GPIO_J0_NR,
J
Jongpill Lee 已提交
171 172 173 174
			.label	= "GPJ0",
		},
	}, {
		.chip	= {
175 176
			.base	= EXYNOS4_GPJ1(0),
			.ngpio	= EXYNOS4_GPIO_J1_NR,
J
Jongpill Lee 已提交
177 178 179 180
			.label	= "GPJ1",
		},
	}, {
		.chip	= {
181 182
			.base	= EXYNOS4_GPK0(0),
			.ngpio	= EXYNOS4_GPIO_K0_NR,
J
Jongpill Lee 已提交
183 184 185 186
			.label	= "GPK0",
		},
	}, {
		.chip	= {
187 188
			.base	= EXYNOS4_GPK1(0),
			.ngpio	= EXYNOS4_GPIO_K1_NR,
J
Jongpill Lee 已提交
189 190 191 192
			.label	= "GPK1",
		},
	}, {
		.chip	= {
193 194
			.base	= EXYNOS4_GPK2(0),
			.ngpio	= EXYNOS4_GPIO_K2_NR,
J
Jongpill Lee 已提交
195 196 197 198
			.label	= "GPK2",
		},
	}, {
		.chip	= {
199 200
			.base	= EXYNOS4_GPK3(0),
			.ngpio	= EXYNOS4_GPIO_K3_NR,
J
Jongpill Lee 已提交
201 202 203 204
			.label	= "GPK3",
		},
	}, {
		.chip	= {
205 206
			.base	= EXYNOS4_GPL0(0),
			.ngpio	= EXYNOS4_GPIO_L0_NR,
J
Jongpill Lee 已提交
207 208 209 210
			.label	= "GPL0",
		},
	}, {
		.chip	= {
211 212
			.base	= EXYNOS4_GPL1(0),
			.ngpio	= EXYNOS4_GPIO_L1_NR,
J
Jongpill Lee 已提交
213 214 215 216
			.label	= "GPL1",
		},
	}, {
		.chip	= {
217 218
			.base	= EXYNOS4_GPL2(0),
			.ngpio	= EXYNOS4_GPIO_L2_NR,
J
Jongpill Lee 已提交
219 220
			.label	= "GPL2",
		},
221 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
	}, {
		.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",
		},
J
Jongpill Lee 已提交
270 271 272 273 274
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC00),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(0),
		.chip	= {
275 276
			.base	= EXYNOS4_GPX0(0),
			.ngpio	= EXYNOS4_GPIO_X0_NR,
J
Jongpill Lee 已提交
277 278 279 280 281 282 283 284
			.label	= "GPX0",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC20),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(8),
		.chip	= {
285 286
			.base	= EXYNOS4_GPX1(0),
			.ngpio	= EXYNOS4_GPIO_X1_NR,
J
Jongpill Lee 已提交
287 288 289 290 291 292 293 294
			.label	= "GPX1",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC40),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(16),
		.chip	= {
295 296
			.base	= EXYNOS4_GPX2(0),
			.ngpio	= EXYNOS4_GPIO_X2_NR,
J
Jongpill Lee 已提交
297 298 299 300 301 302 303 304
			.label	= "GPX2",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC60),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(24),
		.chip	= {
305 306
			.base	= EXYNOS4_GPX3(0),
			.ngpio	= EXYNOS4_GPIO_X3_NR,
J
Jongpill Lee 已提交
307 308 309 310 311 312
			.label	= "GPX3",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	},
};

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

323
static __init int exynos4_gpiolib_init(void)
J
Jongpill Lee 已提交
324 325 326
{
	struct s3c_gpio_chip *chip;
	int i;
327
	int group = 0;
J
Jongpill Lee 已提交
328 329 330 331
	int nr_chips;

	/* GPIO part 1 */

332 333
	chip = exynos4_gpio_part1_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
J
Jongpill Lee 已提交
334 335

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

345
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
J
Jongpill Lee 已提交
346 347 348

	/* GPIO part 2 */

349 350
	chip = exynos4_gpio_part2_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
J
Jongpill Lee 已提交
351 352

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

362
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
J
Jongpill Lee 已提交
363 364 365

	/* GPIO part 3 */

366 367
	chip = exynos4_gpio_part3_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
J
Jongpill Lee 已提交
368 369

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

379
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
380 381
	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);
J
Jongpill Lee 已提交
382 383 384

	return 0;
}
385
core_initcall(exynos4_gpiolib_init);