blob: 1cc4abb8a938b16ccc1322a6adcc903bc064b299 [file] [log] [blame]
Tom Warrenb3878b82011-06-17 06:27:28 +00001/*
Allen Martin55d98a12012-08-31 08:30:00 +00002 * NVIDIA Tegra20 GPIO handling.
Tom Warrenc570d7a2012-05-22 12:19:25 +00003 * (C) Copyright 2010-2012
Tom Warrenb3878b82011-06-17 06:27:28 +00004 * NVIDIA Corporation <www.nvidia.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Tom Warrenb3878b82011-06-17 06:27:28 +00007 */
8
9/*
10 * Based on (mostly copied from) kw_gpio.c based Linux 2.6 kernel driver.
11 * Tom Warren (twarren@nvidia.com)
12 */
13
14#include <common.h>
Simon Glassb0461042014-09-03 17:37:03 -060015#include <dm.h>
16#include <malloc.h>
17#include <errno.h>
18#include <fdtdec.h>
Tom Warrenb3878b82011-06-17 06:27:28 +000019#include <asm/io.h>
20#include <asm/bitops.h>
Tom Warrenab371962012-09-19 15:50:56 -070021#include <asm/arch/tegra.h>
Tom Warrenb3878b82011-06-17 06:27:28 +000022#include <asm/gpio.h>
Simon Glassb0461042014-09-03 17:37:03 -060023#include <dm/device-internal.h>
24
25DECLARE_GLOBAL_DATA_PTR;
Tom Warrenb3878b82011-06-17 06:27:28 +000026
27enum {
Tom Warren22562a42012-09-04 17:00:24 -070028 TEGRA_CMD_INFO,
29 TEGRA_CMD_PORT,
30 TEGRA_CMD_OUTPUT,
31 TEGRA_CMD_INPUT,
Tom Warrenb3878b82011-06-17 06:27:28 +000032};
33
Simon Glassb0461042014-09-03 17:37:03 -060034struct tegra_gpio_platdata {
35 struct gpio_ctlr_bank *bank;
36 const char *port_name; /* Name of port, e.g. "B" */
37 int base_gpio; /* Port number for this port (0, 1,.., n-1) */
38};
Tom Warrenb3878b82011-06-17 06:27:28 +000039
Simon Glassb0461042014-09-03 17:37:03 -060040/* Information about each port at run-time */
41struct tegra_port_info {
42 char label[TEGRA_GPIOS_PER_PORT][GPIO_NAME_SIZE];
43 struct gpio_ctlr_bank *bank;
44 int base_gpio; /* Port number for this port (0, 1,.., n-1) */
45};
Tom Warrenb3878b82011-06-17 06:27:28 +000046
Joe Hershbergerf8928f12011-11-11 15:55:36 -060047/* Return config of pin 'gpio' as GPIO (1) or SFPIO (0) */
48static int get_config(unsigned gpio)
Tom Warrenb3878b82011-06-17 06:27:28 +000049{
Joe Hershbergerf8928f12011-11-11 15:55:36 -060050 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
51 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +000052 u32 u;
53 int type;
54
Joe Hershbergerf8928f12011-11-11 15:55:36 -060055 u = readl(&bank->gpio_config[GPIO_PORT(gpio)]);
56 type = (u >> GPIO_BIT(gpio)) & 1;
Tom Warrenb3878b82011-06-17 06:27:28 +000057
58 debug("get_config: port = %d, bit = %d is %s\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -060059 GPIO_FULLPORT(gpio), GPIO_BIT(gpio), type ? "GPIO" : "SFPIO");
Tom Warrenb3878b82011-06-17 06:27:28 +000060
61 return type;
62}
63
Joe Hershbergerf8928f12011-11-11 15:55:36 -060064/* Config pin 'gpio' as GPIO or SFPIO, based on 'type' */
65static void set_config(unsigned gpio, int type)
Tom Warrenb3878b82011-06-17 06:27:28 +000066{
Joe Hershbergerf8928f12011-11-11 15:55:36 -060067 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
68 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +000069 u32 u;
70
71 debug("set_config: port = %d, bit = %d, %s\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -060072 GPIO_FULLPORT(gpio), GPIO_BIT(gpio), type ? "GPIO" : "SFPIO");
Tom Warrenb3878b82011-06-17 06:27:28 +000073
Joe Hershbergerf8928f12011-11-11 15:55:36 -060074 u = readl(&bank->gpio_config[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +000075 if (type) /* GPIO */
Joe Hershbergerf8928f12011-11-11 15:55:36 -060076 u |= 1 << GPIO_BIT(gpio);
Tom Warrenb3878b82011-06-17 06:27:28 +000077 else
Joe Hershbergerf8928f12011-11-11 15:55:36 -060078 u &= ~(1 << GPIO_BIT(gpio));
79 writel(u, &bank->gpio_config[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +000080}
81
Joe Hershbergerf8928f12011-11-11 15:55:36 -060082/* Return GPIO pin 'gpio' direction - 0 = input or 1 = output */
83static int get_direction(unsigned gpio)
Tom Warrenb3878b82011-06-17 06:27:28 +000084{
Joe Hershbergerf8928f12011-11-11 15:55:36 -060085 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
86 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +000087 u32 u;
88 int dir;
89
Joe Hershbergerf8928f12011-11-11 15:55:36 -060090 u = readl(&bank->gpio_dir_out[GPIO_PORT(gpio)]);
91 dir = (u >> GPIO_BIT(gpio)) & 1;
Tom Warrenb3878b82011-06-17 06:27:28 +000092
93 debug("get_direction: port = %d, bit = %d, %s\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -060094 GPIO_FULLPORT(gpio), GPIO_BIT(gpio), dir ? "OUT" : "IN");
Tom Warrenb3878b82011-06-17 06:27:28 +000095
96 return dir;
97}
98
Joe Hershbergerf8928f12011-11-11 15:55:36 -060099/* Config GPIO pin 'gpio' as input or output (OE) as per 'output' */
100static void set_direction(unsigned gpio, int output)
Tom Warrenb3878b82011-06-17 06:27:28 +0000101{
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600102 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
103 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +0000104 u32 u;
105
106 debug("set_direction: port = %d, bit = %d, %s\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600107 GPIO_FULLPORT(gpio), GPIO_BIT(gpio), output ? "OUT" : "IN");
Tom Warrenb3878b82011-06-17 06:27:28 +0000108
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600109 u = readl(&bank->gpio_dir_out[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000110 if (output)
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600111 u |= 1 << GPIO_BIT(gpio);
Tom Warrenb3878b82011-06-17 06:27:28 +0000112 else
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600113 u &= ~(1 << GPIO_BIT(gpio));
114 writel(u, &bank->gpio_dir_out[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000115}
116
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600117/* set GPIO pin 'gpio' output bit as 0 or 1 as per 'high' */
118static void set_level(unsigned gpio, int high)
Tom Warrenb3878b82011-06-17 06:27:28 +0000119{
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600120 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
121 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +0000122 u32 u;
123
124 debug("set_level: port = %d, bit %d == %d\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600125 GPIO_FULLPORT(gpio), GPIO_BIT(gpio), high);
Tom Warrenb3878b82011-06-17 06:27:28 +0000126
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600127 u = readl(&bank->gpio_out[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000128 if (high)
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600129 u |= 1 << GPIO_BIT(gpio);
Tom Warrenb3878b82011-06-17 06:27:28 +0000130 else
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600131 u &= ~(1 << GPIO_BIT(gpio));
132 writel(u, &bank->gpio_out[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000133}
134
Simon Glassb0461042014-09-03 17:37:03 -0600135static int check_reserved(struct udevice *dev, unsigned offset,
136 const char *func)
137{
138 struct tegra_port_info *state = dev_get_priv(dev);
139 struct gpio_dev_priv *uc_priv = dev->uclass_priv;
140
141 if (!*state->label[offset]) {
142 printf("tegra_gpio: %s: error: gpio %s%d not reserved\n",
143 func, uc_priv->bank_name, offset);
144 return -EBUSY;
145 }
146
147 return 0;
148}
149
150/* set GPIO pin 'gpio' as an output, with polarity 'value' */
151int tegra_spl_gpio_direction_output(int gpio, int value)
152{
153 /* Configure as a GPIO */
154 set_config(gpio, 1);
155
156 /* Configure GPIO output value. */
157 set_level(gpio, value);
158
159 /* Configure GPIO direction as output. */
160 set_direction(gpio, 1);
161
162 return 0;
163}
164
Tom Warrenb3878b82011-06-17 06:27:28 +0000165/*
166 * Generic_GPIO primitives.
167 */
168
Simon Glassb0461042014-09-03 17:37:03 -0600169static int tegra_gpio_request(struct udevice *dev, unsigned offset,
170 const char *label)
Tom Warrenb3878b82011-06-17 06:27:28 +0000171{
Simon Glassb0461042014-09-03 17:37:03 -0600172 struct tegra_port_info *state = dev_get_priv(dev);
Tom Warrenb3878b82011-06-17 06:27:28 +0000173
Simon Glassb0461042014-09-03 17:37:03 -0600174 if (*state->label[offset])
175 return -EBUSY;
176
177 strncpy(state->label[offset], label, GPIO_NAME_SIZE);
178 state->label[offset][GPIO_NAME_SIZE - 1] = '\0';
Tom Warrenb3878b82011-06-17 06:27:28 +0000179
180 /* Configure as a GPIO */
Simon Glassb0461042014-09-03 17:37:03 -0600181 set_config(state->base_gpio + offset, 1);
Tom Warrenb3878b82011-06-17 06:27:28 +0000182
183 return 0;
184}
185
Simon Glassb0461042014-09-03 17:37:03 -0600186static int tegra_gpio_free(struct udevice *dev, unsigned offset)
Tom Warrenb3878b82011-06-17 06:27:28 +0000187{
Simon Glassb0461042014-09-03 17:37:03 -0600188 struct tegra_port_info *state = dev_get_priv(dev);
189 int ret;
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600190
Simon Glassb0461042014-09-03 17:37:03 -0600191 ret = check_reserved(dev, offset, __func__);
192 if (ret)
193 return ret;
194 state->label[offset][0] = '\0';
195
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600196 return 0;
Tom Warrenb3878b82011-06-17 06:27:28 +0000197}
198
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600199/* read GPIO OUT value of pin 'gpio' */
Simon Glassb0461042014-09-03 17:37:03 -0600200static int tegra_gpio_get_output_value(unsigned gpio)
Tom Warrenb3878b82011-06-17 06:27:28 +0000201{
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600202 struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
203 struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
Tom Warrenb3878b82011-06-17 06:27:28 +0000204 int val;
205
206 debug("gpio_get_output_value: pin = %d (port %d:bit %d)\n",
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600207 gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio));
Tom Warrenb3878b82011-06-17 06:27:28 +0000208
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600209 val = readl(&bank->gpio_out[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000210
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600211 return (val >> GPIO_BIT(gpio)) & 1;
Tom Warrenb3878b82011-06-17 06:27:28 +0000212}
213
Simon Glassb0461042014-09-03 17:37:03 -0600214
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600215/* set GPIO pin 'gpio' as an input */
Simon Glassb0461042014-09-03 17:37:03 -0600216static int tegra_gpio_direction_input(struct udevice *dev, unsigned offset)
Tom Warrenb3878b82011-06-17 06:27:28 +0000217{
Simon Glassb0461042014-09-03 17:37:03 -0600218 struct tegra_port_info *state = dev_get_priv(dev);
219 int ret;
220
221 ret = check_reserved(dev, offset, __func__);
222 if (ret)
223 return ret;
Tom Warrenb3878b82011-06-17 06:27:28 +0000224
225 /* Configure GPIO direction as input. */
Simon Glassb0461042014-09-03 17:37:03 -0600226 set_direction(state->base_gpio + offset, 0);
Tom Warrenb3878b82011-06-17 06:27:28 +0000227
228 return 0;
229}
230
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600231/* set GPIO pin 'gpio' as an output, with polarity 'value' */
Simon Glassb0461042014-09-03 17:37:03 -0600232static int tegra_gpio_direction_output(struct udevice *dev, unsigned offset,
233 int value)
Tom Warrenb3878b82011-06-17 06:27:28 +0000234{
Simon Glassb0461042014-09-03 17:37:03 -0600235 struct tegra_port_info *state = dev_get_priv(dev);
236 int gpio = state->base_gpio + offset;
237 int ret;
238
239 ret = check_reserved(dev, offset, __func__);
240 if (ret)
241 return ret;
Tom Warrenb3878b82011-06-17 06:27:28 +0000242
243 /* Configure GPIO output value. */
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600244 set_level(gpio, value);
Tom Warrenb3878b82011-06-17 06:27:28 +0000245
246 /* Configure GPIO direction as output. */
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600247 set_direction(gpio, 1);
Tom Warrenb3878b82011-06-17 06:27:28 +0000248
249 return 0;
250}
251
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600252/* read GPIO IN value of pin 'gpio' */
Simon Glassb0461042014-09-03 17:37:03 -0600253static int tegra_gpio_get_value(struct udevice *dev, unsigned offset)
Tom Warrenb3878b82011-06-17 06:27:28 +0000254{
Simon Glassb0461042014-09-03 17:37:03 -0600255 struct tegra_port_info *state = dev_get_priv(dev);
256 int gpio = state->base_gpio + offset;
257 int ret;
Tom Warrenb3878b82011-06-17 06:27:28 +0000258 int val;
259
Simon Glassb0461042014-09-03 17:37:03 -0600260 ret = check_reserved(dev, offset, __func__);
261 if (ret)
262 return ret;
Tom Warrenb3878b82011-06-17 06:27:28 +0000263
Simon Glassb0461042014-09-03 17:37:03 -0600264 debug("%s: pin = %d (port %d:bit %d)\n", __func__,
265 gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio));
266
267 val = readl(&state->bank->gpio_in[GPIO_PORT(gpio)]);
Tom Warrenb3878b82011-06-17 06:27:28 +0000268
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600269 return (val >> GPIO_BIT(gpio)) & 1;
Tom Warrenb3878b82011-06-17 06:27:28 +0000270}
271
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600272/* write GPIO OUT value to pin 'gpio' */
Simon Glassb0461042014-09-03 17:37:03 -0600273static int tegra_gpio_set_value(struct udevice *dev, unsigned offset, int value)
Tom Warrenb3878b82011-06-17 06:27:28 +0000274{
Simon Glassb0461042014-09-03 17:37:03 -0600275 struct tegra_port_info *state = dev_get_priv(dev);
276 int gpio = state->base_gpio + offset;
277 int ret;
278
279 ret = check_reserved(dev, offset, __func__);
280 if (ret)
281 return ret;
282
Tom Warrenb3878b82011-06-17 06:27:28 +0000283 debug("gpio_set_value: pin = %d (port %d:bit %d), value = %d\n",
Simon Glassb0461042014-09-03 17:37:03 -0600284 gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio), value);
Tom Warrenb3878b82011-06-17 06:27:28 +0000285
286 /* Configure GPIO output value. */
Joe Hershbergerf8928f12011-11-11 15:55:36 -0600287 set_level(gpio, value);
288
289 return 0;
Tom Warrenb3878b82011-06-17 06:27:28 +0000290}
291
Stephen Warren4b27bf12014-04-22 14:37:53 -0600292void gpio_config_table(const struct tegra_gpio_config *config, int len)
293{
294 int i;
295
296 for (i = 0; i < len; i++) {
297 switch (config[i].init) {
298 case TEGRA_GPIO_INIT_IN:
299 gpio_direction_input(config[i].gpio);
300 break;
301 case TEGRA_GPIO_INIT_OUT0:
302 gpio_direction_output(config[i].gpio, 0);
303 break;
304 case TEGRA_GPIO_INIT_OUT1:
305 gpio_direction_output(config[i].gpio, 1);
306 break;
307 }
308 set_config(config[i].gpio, 1);
309 }
310}
311
Simon Glassb0461042014-09-03 17:37:03 -0600312static int tegra_gpio_get_function(struct udevice *dev, unsigned offset)
313{
314 struct tegra_port_info *state = dev_get_priv(dev);
315 int gpio = state->base_gpio + offset;
316
317 if (!*state->label[offset])
318 return GPIOF_UNUSED;
319 if (!get_config(gpio))
320 return GPIOF_FUNC;
321 else if (get_direction(gpio))
322 return GPIOF_OUTPUT;
323 else
324 return GPIOF_INPUT;
325}
326
327static int tegra_gpio_get_state(struct udevice *dev, unsigned int offset,
328 char *buf, int bufsize)
329{
330 struct gpio_dev_priv *uc_priv = dev->uclass_priv;
331 struct tegra_port_info *state = dev_get_priv(dev);
332 int gpio = state->base_gpio + offset;
333 const char *label;
334 int is_output;
335 int is_gpio;
336 int size;
337
338 label = state->label[offset];
339 is_gpio = get_config(gpio); /* GPIO, not SFPIO */
340 size = snprintf(buf, bufsize, "%s%d: ",
341 uc_priv->bank_name ? uc_priv->bank_name : "", offset);
342 buf += size;
343 bufsize -= size;
344 if (is_gpio) {
345 is_output = get_direction(gpio);
346
347 snprintf(buf, bufsize, "%s: %d [%c]%s%s",
348 is_output ? "out" : " in",
349 is_output ?
350 tegra_gpio_get_output_value(gpio) :
351 tegra_gpio_get_value(dev, offset),
352 *label ? 'x' : ' ',
353 *label ? " " : "",
354 label);
355 } else {
356 snprintf(buf, bufsize, "sfpio");
357 }
358
359 return 0;
360}
361
362static const struct dm_gpio_ops gpio_tegra_ops = {
363 .request = tegra_gpio_request,
364 .free = tegra_gpio_free,
365 .direction_input = tegra_gpio_direction_input,
366 .direction_output = tegra_gpio_direction_output,
367 .get_value = tegra_gpio_get_value,
368 .set_value = tegra_gpio_set_value,
369 .get_function = tegra_gpio_get_function,
370 .get_state = tegra_gpio_get_state,
371};
372
373/**
374 * Returns the name of a GPIO port
375 *
376 * GPIOs are named A, B, C, ..., Z, AA, BB, CC, ...
377 *
378 * @base_port: Base port number (0, 1..n-1)
379 * @return allocated string containing the name
Tom Warrenb3878b82011-06-17 06:27:28 +0000380 */
Simon Glassb0461042014-09-03 17:37:03 -0600381static char *gpio_port_name(int base_port)
Tom Warrenb3878b82011-06-17 06:27:28 +0000382{
Simon Glassb0461042014-09-03 17:37:03 -0600383 char *name, *s;
Tom Warrenb3878b82011-06-17 06:27:28 +0000384
Simon Glassb0461042014-09-03 17:37:03 -0600385 name = malloc(3);
386 if (name) {
387 s = name;
388 *s++ = 'A' + (base_port % 26);
389 if (base_port >= 26)
390 *s++ = *name;
391 *s = '\0';
Tom Warrenb3878b82011-06-17 06:27:28 +0000392 }
Simon Glassb0461042014-09-03 17:37:03 -0600393
394 return name;
Tom Warrenb3878b82011-06-17 06:27:28 +0000395}
Simon Glassb0461042014-09-03 17:37:03 -0600396
397static const struct udevice_id tegra_gpio_ids[] = {
398 { .compatible = "nvidia,tegra30-gpio" },
399 { .compatible = "nvidia,tegra20-gpio" },
400 { }
401};
402
403static int gpio_tegra_probe(struct udevice *dev)
404{
405 struct gpio_dev_priv *uc_priv = dev->uclass_priv;
406 struct tegra_port_info *priv = dev->priv;
407 struct tegra_gpio_platdata *plat = dev->platdata;
408
409 /* Only child devices have ports */
410 if (!plat)
411 return 0;
412
413 priv->bank = plat->bank;
414 priv->base_gpio = plat->base_gpio;
415
416 uc_priv->gpio_count = TEGRA_GPIOS_PER_PORT;
417 uc_priv->bank_name = plat->port_name;
418
419 return 0;
420}
421
422/**
423 * We have a top-level GPIO device with no actual GPIOs. It has a child
424 * device for each Tegra port.
425 */
426static int gpio_tegra_bind(struct udevice *parent)
427{
428 struct tegra_gpio_platdata *plat = parent->platdata;
429 struct gpio_ctlr *ctlr;
430 int bank_count;
431 int bank;
432 int ret;
433 int len;
434
435 /* If this is a child device, there is nothing to do here */
436 if (plat)
437 return 0;
438
439 /*
440 * This driver does not make use of interrupts, other than to figure
441 * out the number of GPIO banks
442 */
443 if (!fdt_getprop(gd->fdt_blob, parent->of_offset, "interrupts", &len))
444 return -EINVAL;
445 bank_count = len / 3 / sizeof(u32);
446 ctlr = (struct gpio_ctlr *)fdtdec_get_addr(gd->fdt_blob,
447 parent->of_offset, "reg");
448 for (bank = 0; bank < bank_count; bank++) {
449 int port;
450
451 for (port = 0; port < TEGRA_PORTS_PER_BANK; port++) {
452 struct tegra_gpio_platdata *plat;
453 struct udevice *dev;
454 int base_port;
455
456 plat = calloc(1, sizeof(*plat));
457 if (!plat)
458 return -ENOMEM;
459 plat->bank = &ctlr->gpio_bank[bank];
460 base_port = bank * TEGRA_PORTS_PER_BANK + port;
461 plat->base_gpio = TEGRA_GPIOS_PER_PORT * base_port;
462 plat->port_name = gpio_port_name(base_port);
463
464 ret = device_bind(parent, parent->driver,
465 plat->port_name, plat, -1, &dev);
466 if (ret)
467 return ret;
468 dev->of_offset = parent->of_offset;
469 }
470 }
471
472 return 0;
473}
474
475U_BOOT_DRIVER(gpio_tegra) = {
476 .name = "gpio_tegra",
477 .id = UCLASS_GPIO,
478 .of_match = tegra_gpio_ids,
479 .bind = gpio_tegra_bind,
480 .probe = gpio_tegra_probe,
481 .priv_auto_alloc_size = sizeof(struct tegra_port_info),
482 .ops = &gpio_tegra_ops,
483};