gpio-exynos4.c 7.3 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 *		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>

static struct s3c_gpio_cfg gpio_cfg = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
	.set_pull	= s3c_gpio_setpull_updown,
	.get_pull	= s3c_gpio_getpull_updown,
};

static struct s3c_gpio_cfg gpio_cfg_noint = {
	.set_config	= s3c_gpio_setcfg_s3c64xx_4bit,
	.set_pull	= s3c_gpio_setpull_updown,
	.get_pull	= s3c_gpio_getpull_updown,
};

/*
 * 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.
 */
45
static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
J
Jongpill Lee 已提交
46 47
	{
		.chip	= {
48 49
			.base	= EXYNOS4_GPA0(0),
			.ngpio	= EXYNOS4_GPIO_A0_NR,
J
Jongpill Lee 已提交
50 51 52 53
			.label	= "GPA0",
		},
	}, {
		.chip	= {
54 55
			.base	= EXYNOS4_GPA1(0),
			.ngpio	= EXYNOS4_GPIO_A1_NR,
J
Jongpill Lee 已提交
56 57 58 59
			.label	= "GPA1",
		},
	}, {
		.chip	= {
60 61
			.base	= EXYNOS4_GPB(0),
			.ngpio	= EXYNOS4_GPIO_B_NR,
J
Jongpill Lee 已提交
62 63 64 65
			.label	= "GPB",
		},
	}, {
		.chip	= {
66 67
			.base	= EXYNOS4_GPC0(0),
			.ngpio	= EXYNOS4_GPIO_C0_NR,
J
Jongpill Lee 已提交
68 69 70 71
			.label	= "GPC0",
		},
	}, {
		.chip	= {
72 73
			.base	= EXYNOS4_GPC1(0),
			.ngpio	= EXYNOS4_GPIO_C1_NR,
J
Jongpill Lee 已提交
74 75 76 77
			.label	= "GPC1",
		},
	}, {
		.chip	= {
78 79
			.base	= EXYNOS4_GPD0(0),
			.ngpio	= EXYNOS4_GPIO_D0_NR,
J
Jongpill Lee 已提交
80 81 82 83
			.label	= "GPD0",
		},
	}, {
		.chip	= {
84 85
			.base	= EXYNOS4_GPD1(0),
			.ngpio	= EXYNOS4_GPIO_D1_NR,
J
Jongpill Lee 已提交
86 87 88 89
			.label	= "GPD1",
		},
	}, {
		.chip	= {
90 91
			.base	= EXYNOS4_GPE0(0),
			.ngpio	= EXYNOS4_GPIO_E0_NR,
J
Jongpill Lee 已提交
92 93 94 95
			.label	= "GPE0",
		},
	}, {
		.chip	= {
96 97
			.base	= EXYNOS4_GPE1(0),
			.ngpio	= EXYNOS4_GPIO_E1_NR,
J
Jongpill Lee 已提交
98 99 100 101
			.label	= "GPE1",
		},
	}, {
		.chip	= {
102 103
			.base	= EXYNOS4_GPE2(0),
			.ngpio	= EXYNOS4_GPIO_E2_NR,
J
Jongpill Lee 已提交
104 105 106 107
			.label	= "GPE2",
		},
	}, {
		.chip	= {
108 109
			.base	= EXYNOS4_GPE3(0),
			.ngpio	= EXYNOS4_GPIO_E3_NR,
J
Jongpill Lee 已提交
110 111 112 113
			.label	= "GPE3",
		},
	}, {
		.chip	= {
114 115
			.base	= EXYNOS4_GPE4(0),
			.ngpio	= EXYNOS4_GPIO_E4_NR,
J
Jongpill Lee 已提交
116 117 118 119
			.label	= "GPE4",
		},
	}, {
		.chip	= {
120 121
			.base	= EXYNOS4_GPF0(0),
			.ngpio	= EXYNOS4_GPIO_F0_NR,
J
Jongpill Lee 已提交
122 123 124 125
			.label	= "GPF0",
		},
	}, {
		.chip	= {
126 127
			.base	= EXYNOS4_GPF1(0),
			.ngpio	= EXYNOS4_GPIO_F1_NR,
J
Jongpill Lee 已提交
128 129 130 131
			.label	= "GPF1",
		},
	}, {
		.chip	= {
132 133
			.base	= EXYNOS4_GPF2(0),
			.ngpio	= EXYNOS4_GPIO_F2_NR,
J
Jongpill Lee 已提交
134 135 136 137
			.label	= "GPF2",
		},
	}, {
		.chip	= {
138 139
			.base	= EXYNOS4_GPF3(0),
			.ngpio	= EXYNOS4_GPIO_F3_NR,
J
Jongpill Lee 已提交
140 141 142 143 144
			.label	= "GPF3",
		},
	},
};

145
static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
J
Jongpill Lee 已提交
146 147
	{
		.chip	= {
148 149
			.base	= EXYNOS4_GPJ0(0),
			.ngpio	= EXYNOS4_GPIO_J0_NR,
J
Jongpill Lee 已提交
150 151 152 153
			.label	= "GPJ0",
		},
	}, {
		.chip	= {
154 155
			.base	= EXYNOS4_GPJ1(0),
			.ngpio	= EXYNOS4_GPIO_J1_NR,
J
Jongpill Lee 已提交
156 157 158 159
			.label	= "GPJ1",
		},
	}, {
		.chip	= {
160 161
			.base	= EXYNOS4_GPK0(0),
			.ngpio	= EXYNOS4_GPIO_K0_NR,
J
Jongpill Lee 已提交
162 163 164 165
			.label	= "GPK0",
		},
	}, {
		.chip	= {
166 167
			.base	= EXYNOS4_GPK1(0),
			.ngpio	= EXYNOS4_GPIO_K1_NR,
J
Jongpill Lee 已提交
168 169 170 171
			.label	= "GPK1",
		},
	}, {
		.chip	= {
172 173
			.base	= EXYNOS4_GPK2(0),
			.ngpio	= EXYNOS4_GPIO_K2_NR,
J
Jongpill Lee 已提交
174 175 176 177
			.label	= "GPK2",
		},
	}, {
		.chip	= {
178 179
			.base	= EXYNOS4_GPK3(0),
			.ngpio	= EXYNOS4_GPIO_K3_NR,
J
Jongpill Lee 已提交
180 181 182 183
			.label	= "GPK3",
		},
	}, {
		.chip	= {
184 185
			.base	= EXYNOS4_GPL0(0),
			.ngpio	= EXYNOS4_GPIO_L0_NR,
J
Jongpill Lee 已提交
186 187 188 189
			.label	= "GPL0",
		},
	}, {
		.chip	= {
190 191
			.base	= EXYNOS4_GPL1(0),
			.ngpio	= EXYNOS4_GPIO_L1_NR,
J
Jongpill Lee 已提交
192 193 194 195
			.label	= "GPL1",
		},
	}, {
		.chip	= {
196 197
			.base	= EXYNOS4_GPL2(0),
			.ngpio	= EXYNOS4_GPIO_L2_NR,
J
Jongpill Lee 已提交
198 199
			.label	= "GPL2",
		},
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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
	}, {
		.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 已提交
249 250 251 252 253
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC00),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(0),
		.chip	= {
254 255
			.base	= EXYNOS4_GPX0(0),
			.ngpio	= EXYNOS4_GPIO_X0_NR,
J
Jongpill Lee 已提交
256 257 258 259 260 261 262 263
			.label	= "GPX0",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC20),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(8),
		.chip	= {
264 265
			.base	= EXYNOS4_GPX1(0),
			.ngpio	= EXYNOS4_GPIO_X1_NR,
J
Jongpill Lee 已提交
266 267 268 269 270 271 272 273
			.label	= "GPX1",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC40),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(16),
		.chip	= {
274 275
			.base	= EXYNOS4_GPX2(0),
			.ngpio	= EXYNOS4_GPIO_X2_NR,
J
Jongpill Lee 已提交
276 277 278 279 280 281 282 283
			.label	= "GPX2",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	}, {
		.base	= (S5P_VA_GPIO2 + 0xC60),
		.config	= &gpio_cfg_noint,
		.irq_base = IRQ_EINT(24),
		.chip	= {
284 285
			.base	= EXYNOS4_GPX3(0),
			.ngpio	= EXYNOS4_GPIO_X3_NR,
J
Jongpill Lee 已提交
286 287 288 289 290 291
			.label	= "GPX3",
			.to_irq	= samsung_gpiolib_to_irq,
		},
	},
};

292
static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
J
Jongpill Lee 已提交
293 294
	{
		.chip	= {
295 296
			.base	= EXYNOS4_GPZ(0),
			.ngpio	= EXYNOS4_GPIO_Z_NR,
J
Jongpill Lee 已提交
297 298 299 300 301
			.label	= "GPZ",
		},
	},
};

302
static __init int exynos4_gpiolib_init(void)
J
Jongpill Lee 已提交
303 304 305
{
	struct s3c_gpio_chip *chip;
	int i;
306
	int group = 0;
J
Jongpill Lee 已提交
307 308 309 310
	int nr_chips;

	/* GPIO part 1 */

311 312
	chip = exynos4_gpio_part1_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
J
Jongpill Lee 已提交
313 314

	for (i = 0; i < nr_chips; i++, chip++) {
315
		if (chip->config == NULL) {
J
Jongpill Lee 已提交
316
			chip->config = &gpio_cfg;
317 318 319
			/* Assign the GPIO interrupt group */
			chip->group = group++;
		}
J
Jongpill Lee 已提交
320 321 322 323
		if (chip->base == NULL)
			chip->base = S5P_VA_GPIO1 + (i) * 0x20;
	}

324
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
J
Jongpill Lee 已提交
325 326 327

	/* GPIO part 2 */

328 329
	chip = exynos4_gpio_part2_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
J
Jongpill Lee 已提交
330 331

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

341
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
J
Jongpill Lee 已提交
342 343 344

	/* GPIO part 3 */

345 346
	chip = exynos4_gpio_part3_4bit;
	nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
J
Jongpill Lee 已提交
347 348

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

358
	samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
359 360
	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 已提交
361 362 363

	return 0;
}
364
core_initcall(exynos4_gpiolib_init);