18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * OMAP15xx specific gpio init
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Author:
78c2ecf20Sopenharmony_ci *	Charulatha V <charu@ti.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
108c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any
148c2ecf20Sopenharmony_ci * kind, whether express or implied; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168c2ecf20Sopenharmony_ci * GNU General Public License for more details.
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/gpio.h>
208c2ecf20Sopenharmony_ci#include <linux/platform_data/gpio-omap.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include <mach/irqs.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define OMAP1_MPUIO_VBASE		OMAP1_MPUIO_BASE
258c2ecf20Sopenharmony_ci#define OMAP1510_GPIO_BASE		0xFFFCE000
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* gpio1 */
288c2ecf20Sopenharmony_cistatic struct resource omap15xx_mpu_gpio_resources[] = {
298c2ecf20Sopenharmony_ci	{
308c2ecf20Sopenharmony_ci		.start	= OMAP1_MPUIO_VBASE,
318c2ecf20Sopenharmony_ci		.end	= OMAP1_MPUIO_VBASE + SZ_2K - 1,
328c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
338c2ecf20Sopenharmony_ci	},
348c2ecf20Sopenharmony_ci	{
358c2ecf20Sopenharmony_ci		.start	= INT_MPUIO,
368c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_IRQ,
378c2ecf20Sopenharmony_ci	},
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic struct omap_gpio_reg_offs omap15xx_mpuio_regs = {
418c2ecf20Sopenharmony_ci	.revision       = USHRT_MAX,
428c2ecf20Sopenharmony_ci	.direction	= OMAP_MPUIO_IO_CNTL,
438c2ecf20Sopenharmony_ci	.datain		= OMAP_MPUIO_INPUT_LATCH,
448c2ecf20Sopenharmony_ci	.dataout	= OMAP_MPUIO_OUTPUT,
458c2ecf20Sopenharmony_ci	.irqstatus	= OMAP_MPUIO_GPIO_INT,
468c2ecf20Sopenharmony_ci	.irqenable	= OMAP_MPUIO_GPIO_MASKIT,
478c2ecf20Sopenharmony_ci	.irqenable_inv	= true,
488c2ecf20Sopenharmony_ci	.irqctrl	= OMAP_MPUIO_GPIO_INT_EDGE,
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic struct omap_gpio_platform_data omap15xx_mpu_gpio_config = {
528c2ecf20Sopenharmony_ci	.is_mpuio		= true,
538c2ecf20Sopenharmony_ci	.bank_width		= 16,
548c2ecf20Sopenharmony_ci	.bank_stride		= 1,
558c2ecf20Sopenharmony_ci	.regs			= &omap15xx_mpuio_regs,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct platform_device omap15xx_mpu_gpio = {
598c2ecf20Sopenharmony_ci	.name           = "omap_gpio",
608c2ecf20Sopenharmony_ci	.id             = 0,
618c2ecf20Sopenharmony_ci	.dev            = {
628c2ecf20Sopenharmony_ci		.platform_data = &omap15xx_mpu_gpio_config,
638c2ecf20Sopenharmony_ci	},
648c2ecf20Sopenharmony_ci	.num_resources = ARRAY_SIZE(omap15xx_mpu_gpio_resources),
658c2ecf20Sopenharmony_ci	.resource = omap15xx_mpu_gpio_resources,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* gpio2 */
698c2ecf20Sopenharmony_cistatic struct resource omap15xx_gpio_resources[] = {
708c2ecf20Sopenharmony_ci	{
718c2ecf20Sopenharmony_ci		.start	= OMAP1510_GPIO_BASE,
728c2ecf20Sopenharmony_ci		.end	= OMAP1510_GPIO_BASE + SZ_2K - 1,
738c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
748c2ecf20Sopenharmony_ci	},
758c2ecf20Sopenharmony_ci	{
768c2ecf20Sopenharmony_ci		.start	= INT_GPIO_BANK1,
778c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_IRQ,
788c2ecf20Sopenharmony_ci	},
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic struct omap_gpio_reg_offs omap15xx_gpio_regs = {
828c2ecf20Sopenharmony_ci	.revision	= USHRT_MAX,
838c2ecf20Sopenharmony_ci	.direction	= OMAP1510_GPIO_DIR_CONTROL,
848c2ecf20Sopenharmony_ci	.datain		= OMAP1510_GPIO_DATA_INPUT,
858c2ecf20Sopenharmony_ci	.dataout	= OMAP1510_GPIO_DATA_OUTPUT,
868c2ecf20Sopenharmony_ci	.irqstatus	= OMAP1510_GPIO_INT_STATUS,
878c2ecf20Sopenharmony_ci	.irqenable	= OMAP1510_GPIO_INT_MASK,
888c2ecf20Sopenharmony_ci	.irqenable_inv	= true,
898c2ecf20Sopenharmony_ci	.irqctrl	= OMAP1510_GPIO_INT_CONTROL,
908c2ecf20Sopenharmony_ci	.pinctrl	= OMAP1510_GPIO_PIN_CONTROL,
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic struct omap_gpio_platform_data omap15xx_gpio_config = {
948c2ecf20Sopenharmony_ci	.bank_width		= 16,
958c2ecf20Sopenharmony_ci	.regs                   = &omap15xx_gpio_regs,
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic struct platform_device omap15xx_gpio = {
998c2ecf20Sopenharmony_ci	.name           = "omap_gpio",
1008c2ecf20Sopenharmony_ci	.id             = 1,
1018c2ecf20Sopenharmony_ci	.dev            = {
1028c2ecf20Sopenharmony_ci		.platform_data = &omap15xx_gpio_config,
1038c2ecf20Sopenharmony_ci	},
1048c2ecf20Sopenharmony_ci	.num_resources = ARRAY_SIZE(omap15xx_gpio_resources),
1058c2ecf20Sopenharmony_ci	.resource = omap15xx_gpio_resources,
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/*
1098c2ecf20Sopenharmony_ci * omap15xx_gpio_init needs to be done before
1108c2ecf20Sopenharmony_ci * machine_init functions access gpio APIs.
1118c2ecf20Sopenharmony_ci * Hence omap15xx_gpio_init is a postcore_initcall.
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_cistatic int __init omap15xx_gpio_init(void)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	if (!cpu_is_omap15xx())
1168c2ecf20Sopenharmony_ci		return -EINVAL;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	platform_device_register(&omap15xx_mpu_gpio);
1198c2ecf20Sopenharmony_ci	platform_device_register(&omap15xx_gpio);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	return 0;
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_cipostcore_initcall(omap15xx_gpio_init);
124