Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * OMAP16xx specific gpio init |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 5 | * |
| 6 | * Author: |
| 7 | * Charulatha V <charu@ti.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation version 2. |
| 12 | * |
| 13 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 14 | * kind, whether express or implied; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/gpio.h> |
Tony Lindgren | 4b25408 | 2012-08-30 15:37:24 -0700 | [diff] [blame] | 20 | #include <linux/platform_data/gpio-omap.h> |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 21 | |
| 22 | #define OMAP1610_GPIO1_BASE 0xfffbe400 |
| 23 | #define OMAP1610_GPIO2_BASE 0xfffbec00 |
| 24 | #define OMAP1610_GPIO3_BASE 0xfffbb400 |
| 25 | #define OMAP1610_GPIO4_BASE 0xfffbbc00 |
| 26 | #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE |
| 27 | |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 28 | /* smart idle, enable wakeup */ |
| 29 | #define SYSCONFIG_WORD 0x14 |
| 30 | |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 31 | /* mpu gpio */ |
| 32 | static struct __initdata resource omap16xx_mpu_gpio_resources[] = { |
| 33 | { |
| 34 | .start = OMAP1_MPUIO_VBASE, |
| 35 | .end = OMAP1_MPUIO_VBASE + SZ_2K - 1, |
| 36 | .flags = IORESOURCE_MEM, |
| 37 | }, |
| 38 | { |
| 39 | .start = INT_MPUIO, |
| 40 | .flags = IORESOURCE_IRQ, |
| 41 | }, |
| 42 | }; |
| 43 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 44 | static struct omap_gpio_reg_offs omap16xx_mpuio_regs = { |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 45 | .revision = USHRT_MAX, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 46 | .direction = OMAP_MPUIO_IO_CNTL, |
| 47 | .datain = OMAP_MPUIO_INPUT_LATCH, |
| 48 | .dataout = OMAP_MPUIO_OUTPUT, |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 49 | .irqstatus = OMAP_MPUIO_GPIO_INT, |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 50 | .irqenable = OMAP_MPUIO_GPIO_MASKIT, |
| 51 | .irqenable_inv = true, |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 52 | .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 55 | static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = { |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 56 | .is_mpuio = true, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 57 | .bank_width = 16, |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 58 | .bank_stride = 1, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 59 | .regs = &omap16xx_mpuio_regs, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
Janusz Krzysztofik | 07ad6ab | 2011-07-04 03:56:15 -0700 | [diff] [blame] | 62 | static struct platform_device omap16xx_mpu_gpio = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 63 | .name = "omap_gpio", |
| 64 | .id = 0, |
| 65 | .dev = { |
| 66 | .platform_data = &omap16xx_mpu_gpio_config, |
| 67 | }, |
| 68 | .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources), |
| 69 | .resource = omap16xx_mpu_gpio_resources, |
| 70 | }; |
| 71 | |
| 72 | /* gpio1 */ |
| 73 | static struct __initdata resource omap16xx_gpio1_resources[] = { |
| 74 | { |
| 75 | .start = OMAP1610_GPIO1_BASE, |
| 76 | .end = OMAP1610_GPIO1_BASE + SZ_2K - 1, |
| 77 | .flags = IORESOURCE_MEM, |
| 78 | }, |
| 79 | { |
| 80 | .start = INT_GPIO_BANK1, |
| 81 | .flags = IORESOURCE_IRQ, |
| 82 | }, |
| 83 | }; |
| 84 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 85 | static struct omap_gpio_reg_offs omap16xx_gpio_regs = { |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 86 | .revision = OMAP1610_GPIO_REVISION, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 87 | .direction = OMAP1610_GPIO_DIRECTION, |
| 88 | .set_dataout = OMAP1610_GPIO_SET_DATAOUT, |
| 89 | .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT, |
| 90 | .datain = OMAP1610_GPIO_DATAIN, |
| 91 | .dataout = OMAP1610_GPIO_DATAOUT, |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 92 | .irqstatus = OMAP1610_GPIO_IRQSTATUS1, |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 93 | .irqenable = OMAP1610_GPIO_IRQENABLE1, |
| 94 | .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1, |
| 95 | .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1, |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 96 | .wkup_en = OMAP1610_GPIO_WAKEUPENABLE, |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 97 | .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1, |
| 98 | .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 101 | static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 102 | .bank_width = 16, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 103 | .regs = &omap16xx_gpio_regs, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
Janusz Krzysztofik | 07ad6ab | 2011-07-04 03:56:15 -0700 | [diff] [blame] | 106 | static struct platform_device omap16xx_gpio1 = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 107 | .name = "omap_gpio", |
| 108 | .id = 1, |
| 109 | .dev = { |
| 110 | .platform_data = &omap16xx_gpio1_config, |
| 111 | }, |
| 112 | .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources), |
| 113 | .resource = omap16xx_gpio1_resources, |
| 114 | }; |
| 115 | |
| 116 | /* gpio2 */ |
| 117 | static struct __initdata resource omap16xx_gpio2_resources[] = { |
| 118 | { |
| 119 | .start = OMAP1610_GPIO2_BASE, |
| 120 | .end = OMAP1610_GPIO2_BASE + SZ_2K - 1, |
| 121 | .flags = IORESOURCE_MEM, |
| 122 | }, |
| 123 | { |
| 124 | .start = INT_1610_GPIO_BANK2, |
| 125 | .flags = IORESOURCE_IRQ, |
| 126 | }, |
| 127 | }; |
| 128 | |
| 129 | static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 130 | .bank_width = 16, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 131 | .regs = &omap16xx_gpio_regs, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
Janusz Krzysztofik | 07ad6ab | 2011-07-04 03:56:15 -0700 | [diff] [blame] | 134 | static struct platform_device omap16xx_gpio2 = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 135 | .name = "omap_gpio", |
| 136 | .id = 2, |
| 137 | .dev = { |
| 138 | .platform_data = &omap16xx_gpio2_config, |
| 139 | }, |
| 140 | .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources), |
| 141 | .resource = omap16xx_gpio2_resources, |
| 142 | }; |
| 143 | |
| 144 | /* gpio3 */ |
| 145 | static struct __initdata resource omap16xx_gpio3_resources[] = { |
| 146 | { |
| 147 | .start = OMAP1610_GPIO3_BASE, |
| 148 | .end = OMAP1610_GPIO3_BASE + SZ_2K - 1, |
| 149 | .flags = IORESOURCE_MEM, |
| 150 | }, |
| 151 | { |
| 152 | .start = INT_1610_GPIO_BANK3, |
| 153 | .flags = IORESOURCE_IRQ, |
| 154 | }, |
| 155 | }; |
| 156 | |
| 157 | static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 158 | .bank_width = 16, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 159 | .regs = &omap16xx_gpio_regs, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
Janusz Krzysztofik | 07ad6ab | 2011-07-04 03:56:15 -0700 | [diff] [blame] | 162 | static struct platform_device omap16xx_gpio3 = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 163 | .name = "omap_gpio", |
| 164 | .id = 3, |
| 165 | .dev = { |
| 166 | .platform_data = &omap16xx_gpio3_config, |
| 167 | }, |
| 168 | .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources), |
| 169 | .resource = omap16xx_gpio3_resources, |
| 170 | }; |
| 171 | |
| 172 | /* gpio4 */ |
| 173 | static struct __initdata resource omap16xx_gpio4_resources[] = { |
| 174 | { |
| 175 | .start = OMAP1610_GPIO4_BASE, |
| 176 | .end = OMAP1610_GPIO4_BASE + SZ_2K - 1, |
| 177 | .flags = IORESOURCE_MEM, |
| 178 | }, |
| 179 | { |
| 180 | .start = INT_1610_GPIO_BANK4, |
| 181 | .flags = IORESOURCE_IRQ, |
| 182 | }, |
| 183 | }; |
| 184 | |
| 185 | static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 186 | .bank_width = 16, |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 187 | .regs = &omap16xx_gpio_regs, |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
Janusz Krzysztofik | 07ad6ab | 2011-07-04 03:56:15 -0700 | [diff] [blame] | 190 | static struct platform_device omap16xx_gpio4 = { |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 191 | .name = "omap_gpio", |
| 192 | .id = 4, |
| 193 | .dev = { |
| 194 | .platform_data = &omap16xx_gpio4_config, |
| 195 | }, |
| 196 | .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources), |
| 197 | .resource = omap16xx_gpio4_resources, |
| 198 | }; |
| 199 | |
| 200 | static struct __initdata platform_device * omap16xx_gpio_dev[] = { |
| 201 | &omap16xx_mpu_gpio, |
| 202 | &omap16xx_gpio1, |
| 203 | &omap16xx_gpio2, |
| 204 | &omap16xx_gpio3, |
| 205 | &omap16xx_gpio4, |
| 206 | }; |
| 207 | |
| 208 | /* |
| 209 | * omap16xx_gpio_init needs to be done before |
| 210 | * machine_init functions access gpio APIs. |
| 211 | * Hence omap16xx_gpio_init is a postcore_initcall. |
| 212 | */ |
| 213 | static int __init omap16xx_gpio_init(void) |
| 214 | { |
| 215 | int i; |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 216 | void __iomem *base; |
| 217 | struct resource *res; |
| 218 | struct platform_device *pdev; |
| 219 | struct omap_gpio_platform_data *pdata; |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 220 | |
| 221 | if (!cpu_is_omap16xx()) |
| 222 | return -EINVAL; |
| 223 | |
Tony Lindgren | 63325ff | 2012-02-24 10:34:33 -0800 | [diff] [blame] | 224 | /* |
| 225 | * Enable system clock for GPIO module. |
| 226 | * The CAM_CLK_CTRL *is* really the right place. |
| 227 | */ |
| 228 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, |
| 229 | ULPD_CAM_CLK_CTRL); |
| 230 | |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 231 | for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++) { |
| 232 | pdev = omap16xx_gpio_dev[i]; |
| 233 | pdata = pdev->dev.platform_data; |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 234 | |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 235 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 236 | if (unlikely(!res)) { |
| 237 | dev_err(&pdev->dev, "Invalid mem resource.\n"); |
| 238 | return -ENODEV; |
| 239 | } |
| 240 | |
| 241 | base = ioremap(res->start, resource_size(res)); |
| 242 | if (unlikely(!base)) { |
| 243 | dev_err(&pdev->dev, "ioremap failed.\n"); |
| 244 | return -ENOMEM; |
| 245 | } |
| 246 | |
| 247 | __raw_writel(SYSCONFIG_WORD, base + OMAP1610_GPIO_SYSCONFIG); |
| 248 | iounmap(base); |
| 249 | |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 250 | platform_device_register(omap16xx_gpio_dev[i]); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 251 | } |
Varadarajan, Charulatha | 87fe622 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | postcore_initcall(omap16xx_gpio_init); |