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