Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2009 Wind River Systems, Inc. |
| 4 | * Tom Rix <Tom.Rix@windriver.com> |
| 5 | * |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 6 | * This work is derived from the linux 2.6.27 kernel source |
| 7 | * To fetch, use the kernel repository |
| 8 | * git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git |
| 9 | * Use the v2.6.27 tag. |
| 10 | * |
| 11 | * Below is the original's header including its copyright |
| 12 | * |
| 13 | * linux/arch/arm/plat-omap/gpio.c |
| 14 | * |
| 15 | * Support functions for OMAP GPIO |
| 16 | * |
| 17 | * Copyright (C) 2003-2005 Nokia Corporation |
| 18 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 19 | */ |
| 20 | #include <common.h> |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 21 | #include <dm.h> |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 22 | #include <fdtdec.h> |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 23 | #include <asm/gpio.h> |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 24 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 25 | #include <linux/errno.h> |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 26 | #include <malloc.h> |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 29 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 30 | #define OMAP_GPIO_DIR_OUT 0 |
| 31 | #define OMAP_GPIO_DIR_IN 1 |
| 32 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 33 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 34 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 35 | #define GPIO_PER_BANK 32 |
| 36 | |
| 37 | struct gpio_bank { |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 38 | /* TODO(sjg@chromium.org): Can we use a struct here? */ |
| 39 | void *base; /* address of registers in physical memory */ |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | #endif |
| 43 | |
Nikita Kiryanov | e3cb9c1 | 2012-11-27 22:40:57 +0000 | [diff] [blame] | 44 | int gpio_is_valid(int gpio) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 45 | { |
Axel Lin | 01a461f | 2013-06-21 18:54:25 +0800 | [diff] [blame] | 46 | return (gpio >= 0) && (gpio < OMAP_MAX_GPIO); |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 49 | static void _set_gpio_direction(const struct gpio_bank *bank, int gpio, |
| 50 | int is_input) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 51 | { |
| 52 | void *reg = bank->base; |
| 53 | u32 l; |
| 54 | |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 55 | reg += OMAP_GPIO_OE; |
| 56 | |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 57 | l = __raw_readl(reg); |
| 58 | if (is_input) |
| 59 | l |= 1 << gpio; |
| 60 | else |
| 61 | l &= ~(1 << gpio); |
| 62 | __raw_writel(l, reg); |
| 63 | } |
| 64 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 65 | /** |
| 66 | * Get the direction of the GPIO by reading the GPIO_OE register |
| 67 | * corresponding to the specified bank. |
| 68 | */ |
| 69 | static int _get_gpio_direction(const struct gpio_bank *bank, int gpio) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 70 | { |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 71 | void *reg = bank->base; |
| 72 | u32 v; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 73 | |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 74 | reg += OMAP_GPIO_OE; |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 75 | |
| 76 | v = __raw_readl(reg); |
| 77 | |
| 78 | if (v & (1 << gpio)) |
| 79 | return OMAP_GPIO_DIR_IN; |
| 80 | else |
| 81 | return OMAP_GPIO_DIR_OUT; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 84 | static void _set_gpio_dataout(const struct gpio_bank *bank, int gpio, |
| 85 | int enable) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 86 | { |
| 87 | void *reg = bank->base; |
| 88 | u32 l = 0; |
| 89 | |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 90 | if (enable) |
| 91 | reg += OMAP_GPIO_SETDATAOUT; |
| 92 | else |
| 93 | reg += OMAP_GPIO_CLEARDATAOUT; |
| 94 | |
| 95 | l = 1 << gpio; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 96 | __raw_writel(l, reg); |
| 97 | } |
| 98 | |
Simon Glass | ba33a3f | 2014-10-22 21:37:08 -0600 | [diff] [blame] | 99 | static int _get_gpio_value(const struct gpio_bank *bank, int gpio) |
| 100 | { |
| 101 | void *reg = bank->base; |
| 102 | int input; |
| 103 | |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 104 | input = _get_gpio_direction(bank, gpio); |
| 105 | switch (input) { |
| 106 | case OMAP_GPIO_DIR_IN: |
| 107 | reg += OMAP_GPIO_DATAIN; |
| 108 | break; |
| 109 | case OMAP_GPIO_DIR_OUT: |
| 110 | reg += OMAP_GPIO_DATAOUT; |
Simon Glass | ba33a3f | 2014-10-22 21:37:08 -0600 | [diff] [blame] | 111 | break; |
| 112 | default: |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | return (__raw_readl(reg) & (1 << gpio)) != 0; |
| 117 | } |
| 118 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 119 | #if !CONFIG_IS_ENABLED(DM_GPIO) |
Tom Rini | 74d6c9a | 2020-06-04 16:01:39 -0400 | [diff] [blame] | 120 | static inline int get_gpio_index(int gpio) |
| 121 | { |
| 122 | return gpio & 0x1f; |
| 123 | } |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 124 | |
Simon Glass | ba33a3f | 2014-10-22 21:37:08 -0600 | [diff] [blame] | 125 | static inline const struct gpio_bank *get_gpio_bank(int gpio) |
| 126 | { |
| 127 | return &omap_gpio_bank[gpio >> 5]; |
| 128 | } |
| 129 | |
| 130 | static int check_gpio(int gpio) |
| 131 | { |
| 132 | if (!gpio_is_valid(gpio)) { |
| 133 | printf("ERROR : check_gpio: invalid GPIO %d\n", gpio); |
| 134 | return -1; |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 139 | /** |
| 140 | * Set value of the specified gpio |
| 141 | */ |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 142 | int gpio_set_value(unsigned gpio, int value) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 143 | { |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 144 | const struct gpio_bank *bank; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 145 | |
| 146 | if (check_gpio(gpio) < 0) |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 147 | return -1; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 148 | bank = get_gpio_bank(gpio); |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 149 | _set_gpio_dataout(bank, get_gpio_index(gpio), value); |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 150 | |
| 151 | return 0; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 154 | /** |
| 155 | * Get value of the specified gpio |
| 156 | */ |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 157 | int gpio_get_value(unsigned gpio) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 158 | { |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 159 | const struct gpio_bank *bank; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 160 | |
| 161 | if (check_gpio(gpio) < 0) |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 162 | return -1; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 163 | bank = get_gpio_bank(gpio); |
Simon Glass | ba33a3f | 2014-10-22 21:37:08 -0600 | [diff] [blame] | 164 | |
| 165 | return _get_gpio_value(bank, get_gpio_index(gpio)); |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 168 | /** |
| 169 | * Set gpio direction as input |
| 170 | */ |
| 171 | int gpio_direction_input(unsigned gpio) |
Joel A Fernandes | 46b9c20 | 2011-09-04 11:10:03 -0500 | [diff] [blame] | 172 | { |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 173 | const struct gpio_bank *bank; |
Joel A Fernandes | 46b9c20 | 2011-09-04 11:10:03 -0500 | [diff] [blame] | 174 | |
| 175 | if (check_gpio(gpio) < 0) |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 176 | return -1; |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 177 | |
Joel A Fernandes | 46b9c20 | 2011-09-04 11:10:03 -0500 | [diff] [blame] | 178 | bank = get_gpio_bank(gpio); |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 179 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); |
| 180 | |
| 181 | return 0; |
Joel A Fernandes | 46b9c20 | 2011-09-04 11:10:03 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 184 | /** |
| 185 | * Set gpio direction as output |
| 186 | */ |
| 187 | int gpio_direction_output(unsigned gpio, int value) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 188 | { |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 189 | const struct gpio_bank *bank; |
| 190 | |
| 191 | if (check_gpio(gpio) < 0) |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 192 | return -1; |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 193 | |
| 194 | bank = get_gpio_bank(gpio); |
| 195 | _set_gpio_dataout(bank, get_gpio_index(gpio), value); |
| 196 | _set_gpio_direction(bank, get_gpio_index(gpio), 0); |
| 197 | |
| 198 | return 0; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 201 | /** |
| 202 | * Request a gpio before using it. |
| 203 | * |
| 204 | * NOTE: Argument 'label' is unused. |
| 205 | */ |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 206 | int gpio_request(unsigned gpio, const char *label) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 207 | { |
| 208 | if (check_gpio(gpio) < 0) |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 209 | return -1; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
Sanjeev Premi | ea2cf55 | 2011-09-08 10:47:25 -0400 | [diff] [blame] | 214 | /** |
| 215 | * Reset and free the gpio after using it. |
| 216 | */ |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 217 | int gpio_free(unsigned gpio) |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 218 | { |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | #else /* new driver model interface CONFIG_DM_GPIO */ |
| 223 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 224 | /* set GPIO pin 'gpio' as an input */ |
| 225 | static int omap_gpio_direction_input(struct udevice *dev, unsigned offset) |
| 226 | { |
| 227 | struct gpio_bank *bank = dev_get_priv(dev); |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 228 | |
| 229 | /* Configure GPIO direction as input. */ |
| 230 | _set_gpio_direction(bank, offset, 1); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /* set GPIO pin 'gpio' as an output, with polarity 'value' */ |
| 236 | static int omap_gpio_direction_output(struct udevice *dev, unsigned offset, |
| 237 | int value) |
| 238 | { |
| 239 | struct gpio_bank *bank = dev_get_priv(dev); |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 240 | |
| 241 | _set_gpio_dataout(bank, offset, value); |
| 242 | _set_gpio_direction(bank, offset, 0); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | /* read GPIO IN value of pin 'gpio' */ |
| 248 | static int omap_gpio_get_value(struct udevice *dev, unsigned offset) |
| 249 | { |
| 250 | struct gpio_bank *bank = dev_get_priv(dev); |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 251 | |
| 252 | return _get_gpio_value(bank, offset); |
| 253 | } |
| 254 | |
| 255 | /* write GPIO OUT value to pin 'gpio' */ |
| 256 | static int omap_gpio_set_value(struct udevice *dev, unsigned offset, |
| 257 | int value) |
| 258 | { |
| 259 | struct gpio_bank *bank = dev_get_priv(dev); |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 260 | |
| 261 | _set_gpio_dataout(bank, offset, value); |
| 262 | |
Joe Hershberger | f8928f1 | 2011-11-11 15:55:36 -0600 | [diff] [blame] | 263 | return 0; |
Tom Rix | dd2d1cc | 2009-05-15 23:48:36 +0200 | [diff] [blame] | 264 | } |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 265 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 266 | static int omap_gpio_get_function(struct udevice *dev, unsigned offset) |
| 267 | { |
| 268 | struct gpio_bank *bank = dev_get_priv(dev); |
| 269 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 270 | /* GPIOF_FUNC is not implemented yet */ |
Axel Lin | bb4ab58 | 2015-01-31 22:23:38 +0800 | [diff] [blame] | 271 | if (_get_gpio_direction(bank, offset) == OMAP_GPIO_DIR_OUT) |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 272 | return GPIOF_OUTPUT; |
| 273 | else |
| 274 | return GPIOF_INPUT; |
| 275 | } |
| 276 | |
| 277 | static const struct dm_gpio_ops gpio_omap_ops = { |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 278 | .direction_input = omap_gpio_direction_input, |
| 279 | .direction_output = omap_gpio_direction_output, |
| 280 | .get_value = omap_gpio_get_value, |
| 281 | .set_value = omap_gpio_set_value, |
| 282 | .get_function = omap_gpio_get_function, |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | static int omap_gpio_probe(struct udevice *dev) |
| 286 | { |
| 287 | struct gpio_bank *bank = dev_get_priv(dev); |
| 288 | struct omap_gpio_platdata *plat = dev_get_platdata(dev); |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 289 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Adam Ford | 22f2e93 | 2018-06-11 20:05:38 -0500 | [diff] [blame] | 290 | char name[18], *str; |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 291 | |
Adam Ford | e387e45 | 2018-08-17 14:37:58 -0500 | [diff] [blame] | 292 | sprintf(name, "gpio@%4x_", (unsigned int)plat->base); |
Adam Ford | 22f2e93 | 2018-06-11 20:05:38 -0500 | [diff] [blame] | 293 | str = strdup(name); |
| 294 | if (!str) |
| 295 | return -ENOMEM; |
| 296 | uc_priv->bank_name = str; |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 297 | uc_priv->gpio_count = GPIO_PER_BANK; |
| 298 | bank->base = (void *)plat->base; |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 302 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 303 | static int omap_gpio_bind(struct udevice *dev) |
| 304 | { |
Simon Glass | 87f4cb7 | 2017-09-17 16:54:52 -0600 | [diff] [blame] | 305 | struct omap_gpio_platdata *plat = dev_get_platdata(dev); |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 306 | fdt_addr_t base_addr; |
| 307 | |
| 308 | if (plat) |
| 309 | return 0; |
| 310 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 311 | base_addr = dev_read_addr(dev); |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 312 | if (base_addr == FDT_ADDR_T_NONE) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 313 | return -EINVAL; |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * TODO: |
| 317 | * When every board is converted to driver model and DT is |
| 318 | * supported, this can be done by auto-alloc feature, but |
| 319 | * not using calloc to alloc memory for platdata. |
Simon Glass | 87f4cb7 | 2017-09-17 16:54:52 -0600 | [diff] [blame] | 320 | * |
| 321 | * For example am33xx_gpio uses platform data rather than device tree. |
| 322 | * |
| 323 | * NOTE: DO NOT COPY this code if you are using device tree. |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 324 | */ |
| 325 | plat = calloc(1, sizeof(*plat)); |
| 326 | if (!plat) |
| 327 | return -ENOMEM; |
| 328 | |
| 329 | plat->base = base_addr; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 330 | plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL); |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 331 | dev->platdata = plat; |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 332 | |
| 333 | return 0; |
| 334 | } |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 335 | #endif |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 336 | |
Adam Ford | 49b7776 | 2018-08-20 20:27:48 -0500 | [diff] [blame] | 337 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Tom Rini | 7bc2bca | 2015-07-31 19:55:09 -0400 | [diff] [blame] | 338 | static const struct udevice_id omap_gpio_ids[] = { |
| 339 | { .compatible = "ti,omap3-gpio" }, |
| 340 | { .compatible = "ti,omap4-gpio" }, |
| 341 | { .compatible = "ti,am4372-gpio" }, |
| 342 | { } |
| 343 | }; |
| 344 | |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 345 | static int omap_gpio_ofdata_to_platdata(struct udevice *dev) |
| 346 | { |
| 347 | struct omap_gpio_platdata *plat = dev_get_platdata(dev); |
| 348 | fdt_addr_t addr; |
| 349 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 350 | addr = dev_read_addr(dev); |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 351 | if (addr == FDT_ADDR_T_NONE) |
| 352 | return -EINVAL; |
| 353 | |
| 354 | plat->base = addr; |
| 355 | return 0; |
| 356 | } |
| 357 | #endif |
| 358 | |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 359 | U_BOOT_DRIVER(gpio_omap) = { |
| 360 | .name = "gpio_omap", |
| 361 | .id = UCLASS_GPIO, |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 362 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Adam Ford | 49b7776 | 2018-08-20 20:27:48 -0500 | [diff] [blame] | 363 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 364 | .of_match = omap_gpio_ids, |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 365 | .ofdata_to_platdata = of_match_ptr(omap_gpio_ofdata_to_platdata), |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 366 | .platdata_auto_alloc_size = sizeof(struct omap_gpio_platdata), |
Adam Ford | 49b7776 | 2018-08-20 20:27:48 -0500 | [diff] [blame] | 367 | #endif |
Adam Ford | 1ac4c1b | 2018-06-10 09:29:51 -0500 | [diff] [blame] | 368 | #else |
| 369 | .bind = omap_gpio_bind, |
| 370 | #endif |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 371 | .ops = &gpio_omap_ops, |
| 372 | .probe = omap_gpio_probe, |
| 373 | .priv_auto_alloc_size = sizeof(struct gpio_bank), |
Bin Meng | b508ee5 | 2018-10-24 06:36:30 -0700 | [diff] [blame] | 374 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Faiz Abbas | c16d716 | 2018-03-15 21:11:34 +0530 | [diff] [blame] | 375 | .flags = DM_FLAG_PRE_RELOC, |
Bin Meng | b508ee5 | 2018-10-24 06:36:30 -0700 | [diff] [blame] | 376 | #endif |
Simon Glass | 1a96d7f | 2014-10-22 21:37:09 -0600 | [diff] [blame] | 377 | }; |
| 378 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 379 | #endif /* !DM_GPIO */ |