Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 |
| 3 | * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de> |
| 4 | * |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 5 | * Copyright (C) 2011 |
| 6 | * Stefano Babic, DENX Software Engineering, <sbabic@denx.de> |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 9 | */ |
| 10 | #include <common.h> |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | #include <dm.h> |
| 13 | #include <malloc.h> |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 14 | #include <asm/arch/imx-regs.h> |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 15 | #include <asm/gpio.h> |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 17 | |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 18 | enum mxc_gpio_direction { |
| 19 | MXC_GPIO_DIRECTION_IN, |
| 20 | MXC_GPIO_DIRECTION_OUT, |
| 21 | }; |
| 22 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 23 | #define GPIO_PER_BANK 32 |
| 24 | |
| 25 | struct mxc_gpio_plat { |
Peng Fan | 637a769 | 2015-02-10 14:46:33 +0800 | [diff] [blame] | 26 | int bank_index; |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 27 | struct gpio_regs *regs; |
| 28 | }; |
| 29 | |
| 30 | struct mxc_bank_info { |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 31 | struct gpio_regs *regs; |
| 32 | }; |
| 33 | |
| 34 | #ifndef CONFIG_DM_GPIO |
Vikram Narayanan | 8d28c21 | 2012-04-10 04:26:08 +0000 | [diff] [blame] | 35 | #define GPIO_TO_PORT(n) (n / 32) |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 36 | |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 37 | /* GPIO port description */ |
| 38 | static unsigned long gpio_ports[] = { |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 39 | [0] = GPIO1_BASE_ADDR, |
| 40 | [1] = GPIO2_BASE_ADDR, |
| 41 | [2] = GPIO3_BASE_ADDR, |
trem | e71c39d | 2012-08-25 05:30:33 +0000 | [diff] [blame] | 42 | #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ |
Troy Kisky | 5ea6d7c | 2012-10-23 10:57:47 +0000 | [diff] [blame] | 43 | defined(CONFIG_MX53) || defined(CONFIG_MX6) |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 44 | [3] = GPIO4_BASE_ADDR, |
| 45 | #endif |
Troy Kisky | 5ea6d7c | 2012-10-23 10:57:47 +0000 | [diff] [blame] | 46 | #if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) |
Liu Hui-R64343 | 01643ec | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 47 | [4] = GPIO5_BASE_ADDR, |
Peng Fan | f2753b0 | 2015-07-20 19:28:31 +0800 | [diff] [blame] | 48 | #ifndef CONFIG_MX6UL |
Liu Hui-R64343 | 01643ec | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 49 | [5] = GPIO6_BASE_ADDR, |
trem | e71c39d | 2012-08-25 05:30:33 +0000 | [diff] [blame] | 50 | #endif |
Peng Fan | f2753b0 | 2015-07-20 19:28:31 +0800 | [diff] [blame] | 51 | #endif |
Troy Kisky | 5ea6d7c | 2012-10-23 10:57:47 +0000 | [diff] [blame] | 52 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
Peng Fan | f2753b0 | 2015-07-20 19:28:31 +0800 | [diff] [blame] | 53 | #ifndef CONFIG_MX6UL |
Liu Hui-R64343 | 01643ec | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 54 | [6] = GPIO7_BASE_ADDR, |
| 55 | #endif |
Peng Fan | f2753b0 | 2015-07-20 19:28:31 +0800 | [diff] [blame] | 56 | #endif |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 59 | static int mxc_gpio_direction(unsigned int gpio, |
| 60 | enum mxc_gpio_direction direction) |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 61 | { |
Vikram Narayanan | be28255 | 2012-04-10 04:26:20 +0000 | [diff] [blame] | 62 | unsigned int port = GPIO_TO_PORT(gpio); |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 63 | struct gpio_regs *regs; |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 64 | u32 l; |
| 65 | |
| 66 | if (port >= ARRAY_SIZE(gpio_ports)) |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 67 | return -1; |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 68 | |
| 69 | gpio &= 0x1f; |
| 70 | |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 71 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 72 | |
| 73 | l = readl(®s->gpio_dir); |
| 74 | |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 75 | switch (direction) { |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 76 | case MXC_GPIO_DIRECTION_OUT: |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 77 | l |= 1 << gpio; |
| 78 | break; |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 79 | case MXC_GPIO_DIRECTION_IN: |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 80 | l &= ~(1 << gpio); |
| 81 | } |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 82 | writel(l, ®s->gpio_dir); |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 87 | int gpio_set_value(unsigned gpio, int value) |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 88 | { |
Vikram Narayanan | be28255 | 2012-04-10 04:26:20 +0000 | [diff] [blame] | 89 | unsigned int port = GPIO_TO_PORT(gpio); |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 90 | struct gpio_regs *regs; |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 91 | u32 l; |
| 92 | |
| 93 | if (port >= ARRAY_SIZE(gpio_ports)) |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 94 | return -1; |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 95 | |
| 96 | gpio &= 0x1f; |
| 97 | |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 98 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 99 | |
| 100 | l = readl(®s->gpio_dr); |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 101 | if (value) |
| 102 | l |= 1 << gpio; |
| 103 | else |
| 104 | l &= ~(1 << gpio); |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 105 | writel(l, ®s->gpio_dr); |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 106 | |
| 107 | return 0; |
Guennadi Liakhovetski | b30de3c | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 108 | } |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 109 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 110 | int gpio_get_value(unsigned gpio) |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 111 | { |
Vikram Narayanan | be28255 | 2012-04-10 04:26:20 +0000 | [diff] [blame] | 112 | unsigned int port = GPIO_TO_PORT(gpio); |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 113 | struct gpio_regs *regs; |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 114 | u32 val; |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 115 | |
| 116 | if (port >= ARRAY_SIZE(gpio_ports)) |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 117 | return -1; |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 118 | |
| 119 | gpio &= 0x1f; |
| 120 | |
Stefano Babic | c4ea142 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 121 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 122 | |
Benoît Thébaudeau | 5dafa45 | 2012-08-20 10:55:41 +0000 | [diff] [blame] | 123 | val = (readl(®s->gpio_psr) >> gpio) & 0x01; |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 124 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 125 | return val; |
Stefano Babic | 7d27cd0 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 126 | } |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 127 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 128 | int gpio_request(unsigned gpio, const char *label) |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 129 | { |
Vikram Narayanan | be28255 | 2012-04-10 04:26:20 +0000 | [diff] [blame] | 130 | unsigned int port = GPIO_TO_PORT(gpio); |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 131 | if (port >= ARRAY_SIZE(gpio_ports)) |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 132 | return -1; |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 136 | int gpio_free(unsigned gpio) |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 137 | { |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 138 | return 0; |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 141 | int gpio_direction_input(unsigned gpio) |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 142 | { |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 143 | return mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_IN); |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Joe Hershberger | 365d607 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 146 | int gpio_direction_output(unsigned gpio, int value) |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 147 | { |
Dirk Behme | 04c79cb | 2013-07-15 15:58:27 +0200 | [diff] [blame] | 148 | int ret = gpio_set_value(gpio, value); |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 149 | |
| 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | |
Dirk Behme | 04c79cb | 2013-07-15 15:58:27 +0200 | [diff] [blame] | 153 | return mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_OUT); |
Stefano Babic | d8e0ca8 | 2011-08-21 10:45:44 +0200 | [diff] [blame] | 154 | } |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 155 | #endif |
| 156 | |
| 157 | #ifdef CONFIG_DM_GPIO |
Peng Fan | 99c0ae1 | 2015-02-10 14:46:34 +0800 | [diff] [blame] | 158 | #include <fdtdec.h> |
| 159 | DECLARE_GLOBAL_DATA_PTR; |
| 160 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 161 | static int mxc_gpio_is_output(struct gpio_regs *regs, int offset) |
| 162 | { |
| 163 | u32 val; |
| 164 | |
| 165 | val = readl(®s->gpio_dir); |
| 166 | |
| 167 | return val & (1 << offset) ? 1 : 0; |
| 168 | } |
| 169 | |
| 170 | static void mxc_gpio_bank_direction(struct gpio_regs *regs, int offset, |
| 171 | enum mxc_gpio_direction direction) |
| 172 | { |
| 173 | u32 l; |
| 174 | |
| 175 | l = readl(®s->gpio_dir); |
| 176 | |
| 177 | switch (direction) { |
| 178 | case MXC_GPIO_DIRECTION_OUT: |
| 179 | l |= 1 << offset; |
| 180 | break; |
| 181 | case MXC_GPIO_DIRECTION_IN: |
| 182 | l &= ~(1 << offset); |
| 183 | } |
| 184 | writel(l, ®s->gpio_dir); |
| 185 | } |
| 186 | |
| 187 | static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset, |
| 188 | int value) |
| 189 | { |
| 190 | u32 l; |
| 191 | |
| 192 | l = readl(®s->gpio_dr); |
| 193 | if (value) |
| 194 | l |= 1 << offset; |
| 195 | else |
| 196 | l &= ~(1 << offset); |
| 197 | writel(l, ®s->gpio_dr); |
| 198 | } |
| 199 | |
| 200 | static int mxc_gpio_bank_get_value(struct gpio_regs *regs, int offset) |
| 201 | { |
| 202 | return (readl(®s->gpio_psr) >> offset) & 0x01; |
| 203 | } |
| 204 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 205 | /* set GPIO pin 'gpio' as an input */ |
| 206 | static int mxc_gpio_direction_input(struct udevice *dev, unsigned offset) |
| 207 | { |
| 208 | struct mxc_bank_info *bank = dev_get_priv(dev); |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 209 | |
| 210 | /* Configure GPIO direction as input. */ |
| 211 | mxc_gpio_bank_direction(bank->regs, offset, MXC_GPIO_DIRECTION_IN); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* set GPIO pin 'gpio' as an output, with polarity 'value' */ |
| 217 | static int mxc_gpio_direction_output(struct udevice *dev, unsigned offset, |
| 218 | int value) |
| 219 | { |
| 220 | struct mxc_bank_info *bank = dev_get_priv(dev); |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 221 | |
| 222 | /* Configure GPIO output value. */ |
| 223 | mxc_gpio_bank_set_value(bank->regs, offset, value); |
| 224 | |
| 225 | /* Configure GPIO direction as output. */ |
| 226 | mxc_gpio_bank_direction(bank->regs, offset, MXC_GPIO_DIRECTION_OUT); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | /* read GPIO IN value of pin 'gpio' */ |
| 232 | static int mxc_gpio_get_value(struct udevice *dev, unsigned offset) |
| 233 | { |
| 234 | struct mxc_bank_info *bank = dev_get_priv(dev); |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 235 | |
| 236 | return mxc_gpio_bank_get_value(bank->regs, offset); |
| 237 | } |
| 238 | |
| 239 | /* write GPIO OUT value to pin 'gpio' */ |
| 240 | static int mxc_gpio_set_value(struct udevice *dev, unsigned offset, |
| 241 | int value) |
| 242 | { |
| 243 | struct mxc_bank_info *bank = dev_get_priv(dev); |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 244 | |
| 245 | mxc_gpio_bank_set_value(bank->regs, offset, value); |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 250 | static int mxc_gpio_get_function(struct udevice *dev, unsigned offset) |
| 251 | { |
| 252 | struct mxc_bank_info *bank = dev_get_priv(dev); |
| 253 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 254 | /* GPIOF_FUNC is not implemented yet */ |
| 255 | if (mxc_gpio_is_output(bank->regs, offset)) |
| 256 | return GPIOF_OUTPUT; |
| 257 | else |
| 258 | return GPIOF_INPUT; |
| 259 | } |
| 260 | |
| 261 | static const struct dm_gpio_ops gpio_mxc_ops = { |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 262 | .direction_input = mxc_gpio_direction_input, |
| 263 | .direction_output = mxc_gpio_direction_output, |
| 264 | .get_value = mxc_gpio_get_value, |
| 265 | .set_value = mxc_gpio_set_value, |
| 266 | .get_function = mxc_gpio_get_function, |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 267 | }; |
| 268 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 269 | static int mxc_gpio_probe(struct udevice *dev) |
| 270 | { |
| 271 | struct mxc_bank_info *bank = dev_get_priv(dev); |
| 272 | struct mxc_gpio_plat *plat = dev_get_platdata(dev); |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 273 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 274 | int banknum; |
| 275 | char name[18], *str; |
| 276 | |
Peng Fan | 637a769 | 2015-02-10 14:46:33 +0800 | [diff] [blame] | 277 | banknum = plat->bank_index; |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 278 | sprintf(name, "GPIO%d_", banknum + 1); |
| 279 | str = strdup(name); |
| 280 | if (!str) |
| 281 | return -ENOMEM; |
| 282 | uc_priv->bank_name = str; |
| 283 | uc_priv->gpio_count = GPIO_PER_BANK; |
| 284 | bank->regs = plat->regs; |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
Peng Fan | 99c0ae1 | 2015-02-10 14:46:34 +0800 | [diff] [blame] | 289 | static int mxc_gpio_bind(struct udevice *dev) |
| 290 | { |
| 291 | struct mxc_gpio_plat *plat = dev->platdata; |
| 292 | fdt_addr_t addr; |
| 293 | |
| 294 | /* |
| 295 | * If platdata already exsits, directly return. |
| 296 | * Actually only when DT is not supported, platdata |
| 297 | * is statically initialized in U_BOOT_DEVICES.Here |
| 298 | * will return. |
| 299 | */ |
| 300 | if (plat) |
| 301 | return 0; |
| 302 | |
| 303 | addr = dev_get_addr(dev); |
| 304 | if (addr == FDT_ADDR_T_NONE) |
| 305 | return -ENODEV; |
| 306 | |
| 307 | /* |
| 308 | * TODO: |
| 309 | * When every board is converted to driver model and DT is supported, |
| 310 | * this can be done by auto-alloc feature, but not using calloc |
| 311 | * to alloc memory for platdata. |
| 312 | */ |
| 313 | plat = calloc(1, sizeof(*plat)); |
| 314 | if (!plat) |
| 315 | return -ENOMEM; |
| 316 | |
| 317 | plat->regs = (struct gpio_regs *)addr; |
| 318 | plat->bank_index = dev->req_seq; |
| 319 | dev->platdata = plat; |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static const struct udevice_id mxc_gpio_ids[] = { |
| 325 | { .compatible = "fsl,imx35-gpio" }, |
| 326 | { } |
| 327 | }; |
| 328 | |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 329 | U_BOOT_DRIVER(gpio_mxc) = { |
| 330 | .name = "gpio_mxc", |
| 331 | .id = UCLASS_GPIO, |
| 332 | .ops = &gpio_mxc_ops, |
| 333 | .probe = mxc_gpio_probe, |
| 334 | .priv_auto_alloc_size = sizeof(struct mxc_bank_info), |
Peng Fan | 99c0ae1 | 2015-02-10 14:46:34 +0800 | [diff] [blame] | 335 | .of_match = mxc_gpio_ids, |
| 336 | .bind = mxc_gpio_bind, |
| 337 | }; |
| 338 | |
Masahiro Yamada | 0f92582 | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 339 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Peng Fan | 99c0ae1 | 2015-02-10 14:46:34 +0800 | [diff] [blame] | 340 | static const struct mxc_gpio_plat mxc_plat[] = { |
| 341 | { 0, (struct gpio_regs *)GPIO1_BASE_ADDR }, |
| 342 | { 1, (struct gpio_regs *)GPIO2_BASE_ADDR }, |
| 343 | { 2, (struct gpio_regs *)GPIO3_BASE_ADDR }, |
| 344 | #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ |
| 345 | defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 346 | { 3, (struct gpio_regs *)GPIO4_BASE_ADDR }, |
| 347 | #endif |
| 348 | #if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 349 | { 4, (struct gpio_regs *)GPIO5_BASE_ADDR }, |
| 350 | { 5, (struct gpio_regs *)GPIO6_BASE_ADDR }, |
| 351 | #endif |
| 352 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 353 | { 6, (struct gpio_regs *)GPIO7_BASE_ADDR }, |
| 354 | #endif |
Simon Glass | 441d0cf | 2014-10-01 19:57:26 -0600 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | U_BOOT_DEVICES(mxc_gpios) = { |
| 358 | { "gpio_mxc", &mxc_plat[0] }, |
| 359 | { "gpio_mxc", &mxc_plat[1] }, |
| 360 | { "gpio_mxc", &mxc_plat[2] }, |
| 361 | #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ |
| 362 | defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 363 | { "gpio_mxc", &mxc_plat[3] }, |
| 364 | #endif |
| 365 | #if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 366 | { "gpio_mxc", &mxc_plat[4] }, |
| 367 | { "gpio_mxc", &mxc_plat[5] }, |
| 368 | #endif |
| 369 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 370 | { "gpio_mxc", &mxc_plat[6] }, |
| 371 | #endif |
| 372 | }; |
| 373 | #endif |
Peng Fan | 99c0ae1 | 2015-02-10 14:46:34 +0800 | [diff] [blame] | 374 | #endif |