1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP16xx specific gpio init
5 * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
8 * Charulatha V <charu@ti.com>
11 #include <linux/gpio.h>
12 #include <linux/platform_data/gpio-omap.h>
13 #include <linux/soc/ti/omap1-io.h>
19 #define OMAP1610_GPIO1_BASE 0xfffbe400
20 #define OMAP1610_GPIO2_BASE 0xfffbec00
21 #define OMAP1610_GPIO3_BASE 0xfffbb400
22 #define OMAP1610_GPIO4_BASE 0xfffbbc00
23 #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
25 /* smart idle, enable wakeup */
26 #define SYSCONFIG_WORD 0x14
29 static struct resource omap16xx_mpu_gpio_resources[] = {
31 .start = OMAP1_MPUIO_VBASE,
32 .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
33 .flags = IORESOURCE_MEM,
37 .flags = IORESOURCE_IRQ,
41 static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
42 .revision = USHRT_MAX,
43 .direction = OMAP_MPUIO_IO_CNTL,
44 .datain = OMAP_MPUIO_INPUT_LATCH,
45 .dataout = OMAP_MPUIO_OUTPUT,
46 .irqstatus = OMAP_MPUIO_GPIO_INT,
47 .irqenable = OMAP_MPUIO_GPIO_MASKIT,
48 .irqenable_inv = true,
49 .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE,
52 static struct omap_gpio_platform_data omap16xx_mpu_gpio_config = {
56 .regs = &omap16xx_mpuio_regs,
59 static struct platform_device omap16xx_mpu_gpio = {
63 .platform_data = &omap16xx_mpu_gpio_config,
65 .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
66 .resource = omap16xx_mpu_gpio_resources,
70 static struct resource omap16xx_gpio1_resources[] = {
72 .start = OMAP1610_GPIO1_BASE,
73 .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
74 .flags = IORESOURCE_MEM,
77 .start = INT_GPIO_BANK1,
78 .flags = IORESOURCE_IRQ,
82 static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
83 .revision = OMAP1610_GPIO_REVISION,
84 .direction = OMAP1610_GPIO_DIRECTION,
85 .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
86 .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
87 .datain = OMAP1610_GPIO_DATAIN,
88 .dataout = OMAP1610_GPIO_DATAOUT,
89 .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
90 .irqenable = OMAP1610_GPIO_IRQENABLE1,
91 .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
92 .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
93 .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
94 .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1,
95 .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2,
98 static struct omap_gpio_platform_data omap16xx_gpio1_config = {
100 .regs = &omap16xx_gpio_regs,
103 static struct platform_device omap16xx_gpio1 = {
107 .platform_data = &omap16xx_gpio1_config,
109 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
110 .resource = omap16xx_gpio1_resources,
114 static struct resource omap16xx_gpio2_resources[] = {
116 .start = OMAP1610_GPIO2_BASE,
117 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
118 .flags = IORESOURCE_MEM,
121 .start = INT_1610_GPIO_BANK2,
122 .flags = IORESOURCE_IRQ,
126 static struct omap_gpio_platform_data omap16xx_gpio2_config = {
128 .regs = &omap16xx_gpio_regs,
131 static struct platform_device omap16xx_gpio2 = {
135 .platform_data = &omap16xx_gpio2_config,
137 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
138 .resource = omap16xx_gpio2_resources,
142 static struct resource omap16xx_gpio3_resources[] = {
144 .start = OMAP1610_GPIO3_BASE,
145 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
146 .flags = IORESOURCE_MEM,
149 .start = INT_1610_GPIO_BANK3,
150 .flags = IORESOURCE_IRQ,
154 static struct omap_gpio_platform_data omap16xx_gpio3_config = {
156 .regs = &omap16xx_gpio_regs,
159 static struct platform_device omap16xx_gpio3 = {
163 .platform_data = &omap16xx_gpio3_config,
165 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
166 .resource = omap16xx_gpio3_resources,
170 static struct resource omap16xx_gpio4_resources[] = {
172 .start = OMAP1610_GPIO4_BASE,
173 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
174 .flags = IORESOURCE_MEM,
177 .start = INT_1610_GPIO_BANK4,
178 .flags = IORESOURCE_IRQ,
182 static struct omap_gpio_platform_data omap16xx_gpio4_config = {
184 .regs = &omap16xx_gpio_regs,
187 static struct platform_device omap16xx_gpio4 = {
191 .platform_data = &omap16xx_gpio4_config,
193 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
194 .resource = omap16xx_gpio4_resources,
197 static struct platform_device *omap16xx_gpio_dev[] __initdata = {
206 * omap16xx_gpio_init needs to be done before
207 * machine_init functions access gpio APIs.
208 * Hence omap16xx_gpio_init is a postcore_initcall.
210 static int __init omap16xx_gpio_init(void)
214 struct resource *res;
215 struct platform_device *pdev;
216 struct omap_gpio_platform_data *pdata;
218 if (!cpu_is_omap16xx())
222 * Enable system clock for GPIO module.
223 * The CAM_CLK_CTRL *is* really the right place.
225 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
228 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++) {
229 pdev = omap16xx_gpio_dev[i];
230 pdata = pdev->dev.platform_data;
232 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
233 if (unlikely(!res)) {
234 dev_err(&pdev->dev, "Invalid mem resource.\n");
238 base = ioremap(res->start, resource_size(res));
239 if (unlikely(!base)) {
240 dev_err(&pdev->dev, "ioremap failed.\n");
244 __raw_writel(SYSCONFIG_WORD, base + OMAP1610_GPIO_SYSCONFIG);
247 platform_device_register(omap16xx_gpio_dev[i]);
252 postcore_initcall(omap16xx_gpio_init);