xref: /openbmc/linux/arch/arm/mach-omap1/gpio15xx.c (revision 3db55767)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * OMAP15xx specific gpio init
4  *
5  * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
6  *
7  * Author:
8  *	Charulatha V <charu@ti.com>
9  */
10 
11 #include <linux/gpio.h>
12 #include <linux/platform_data/gpio-omap.h>
13 #include <linux/soc/ti/omap1-soc.h>
14 #include <asm/irq.h>
15 
16 #include "irqs.h"
17 
18 #define OMAP1_MPUIO_VBASE		OMAP1_MPUIO_BASE
19 #define OMAP1510_GPIO_BASE		0xFFFCE000
20 
21 /* gpio1 */
22 static struct resource omap15xx_mpu_gpio_resources[] = {
23 	{
24 		.start	= OMAP1_MPUIO_VBASE,
25 		.end	= OMAP1_MPUIO_VBASE + SZ_2K - 1,
26 		.flags	= IORESOURCE_MEM,
27 	},
28 	{
29 		.start	= INT_MPUIO,
30 		.flags	= IORESOURCE_IRQ,
31 	},
32 };
33 
34 static struct omap_gpio_reg_offs omap15xx_mpuio_regs = {
35 	.revision       = USHRT_MAX,
36 	.direction	= OMAP_MPUIO_IO_CNTL,
37 	.datain		= OMAP_MPUIO_INPUT_LATCH,
38 	.dataout	= OMAP_MPUIO_OUTPUT,
39 	.irqstatus	= OMAP_MPUIO_GPIO_INT,
40 	.irqenable	= OMAP_MPUIO_GPIO_MASKIT,
41 	.irqenable_inv	= true,
42 	.irqctrl	= OMAP_MPUIO_GPIO_INT_EDGE,
43 };
44 
45 static struct omap_gpio_platform_data omap15xx_mpu_gpio_config = {
46 	.is_mpuio		= true,
47 	.bank_width		= 16,
48 	.bank_stride		= 1,
49 	.regs			= &omap15xx_mpuio_regs,
50 };
51 
52 static struct platform_device omap15xx_mpu_gpio = {
53 	.name           = "omap_gpio",
54 	.id             = 0,
55 	.dev            = {
56 		.platform_data = &omap15xx_mpu_gpio_config,
57 	},
58 	.num_resources = ARRAY_SIZE(omap15xx_mpu_gpio_resources),
59 	.resource = omap15xx_mpu_gpio_resources,
60 };
61 
62 /* gpio2 */
63 static struct resource omap15xx_gpio_resources[] = {
64 	{
65 		.start	= OMAP1510_GPIO_BASE,
66 		.end	= OMAP1510_GPIO_BASE + SZ_2K - 1,
67 		.flags	= IORESOURCE_MEM,
68 	},
69 	{
70 		.start	= INT_GPIO_BANK1,
71 		.flags	= IORESOURCE_IRQ,
72 	},
73 };
74 
75 static struct omap_gpio_reg_offs omap15xx_gpio_regs = {
76 	.revision	= USHRT_MAX,
77 	.direction	= OMAP1510_GPIO_DIR_CONTROL,
78 	.datain		= OMAP1510_GPIO_DATA_INPUT,
79 	.dataout	= OMAP1510_GPIO_DATA_OUTPUT,
80 	.irqstatus	= OMAP1510_GPIO_INT_STATUS,
81 	.irqenable	= OMAP1510_GPIO_INT_MASK,
82 	.irqenable_inv	= true,
83 	.irqctrl	= OMAP1510_GPIO_INT_CONTROL,
84 	.pinctrl	= OMAP1510_GPIO_PIN_CONTROL,
85 };
86 
87 static struct omap_gpio_platform_data omap15xx_gpio_config = {
88 	.bank_width		= 16,
89 	.regs                   = &omap15xx_gpio_regs,
90 };
91 
92 static struct platform_device omap15xx_gpio = {
93 	.name           = "omap_gpio",
94 	.id             = 1,
95 	.dev            = {
96 		.platform_data = &omap15xx_gpio_config,
97 	},
98 	.num_resources = ARRAY_SIZE(omap15xx_gpio_resources),
99 	.resource = omap15xx_gpio_resources,
100 };
101 
102 /*
103  * omap15xx_gpio_init needs to be done before
104  * machine_init functions access gpio APIs.
105  * Hence omap15xx_gpio_init is a postcore_initcall.
106  */
107 static int __init omap15xx_gpio_init(void)
108 {
109 	if (!cpu_is_omap15xx())
110 		return -EINVAL;
111 
112 	platform_device_register(&omap15xx_mpu_gpio);
113 	platform_device_register(&omap15xx_gpio);
114 
115 	return 0;
116 }
117 postcore_initcall(omap15xx_gpio_init);
118