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

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

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

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

	/* GPIO part 1 */

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

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

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

	/* GPIO part 2 */

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

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

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

	/* GPIO part 3 */

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

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

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

	return 0;
}
365
core_initcall(exynos4_gpiolib_init);