blob: d0e90b8d633f5cbe642c8602a46a60e2a95a0e5b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andrea Scian4bbf3ca2015-03-20 16:00:25 +01002/*
3 * Xilinx Zynq GPIO device driver
4 *
5 * Copyright (C) 2015 DAVE Embedded Systems <devel@dave.eu>
6 *
7 * Most of code taken from linux kernel driver (linux/drivers/gpio/gpio-zynq.c)
8 * Copyright (C) 2009 - 2014 Xilinx, Inc.
Andrea Scian4bbf3ca2015-03-20 16:00:25 +01009 */
10
11#include <common.h>
12#include <asm/gpio.h>
13#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +053016#include <dm.h>
17#include <fdtdec.h>
18
Siva Durga Prasad Paladugu228a1f92016-03-10 16:27:42 +053019/* Maximum banks */
20#define ZYNQ_GPIO_MAX_BANK 4
21
22#define ZYNQ_GPIO_BANK0_NGPIO 32
23#define ZYNQ_GPIO_BANK1_NGPIO 22
24#define ZYNQ_GPIO_BANK2_NGPIO 32
25#define ZYNQ_GPIO_BANK3_NGPIO 32
26
27#define ZYNQ_GPIO_NR_GPIOS (ZYNQ_GPIO_BANK0_NGPIO + \
28 ZYNQ_GPIO_BANK1_NGPIO + \
29 ZYNQ_GPIO_BANK2_NGPIO + \
30 ZYNQ_GPIO_BANK3_NGPIO)
31
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +053032#define ZYNQMP_GPIO_MAX_BANK 6
33
34#define ZYNQMP_GPIO_BANK0_NGPIO 26
35#define ZYNQMP_GPIO_BANK1_NGPIO 26
36#define ZYNQMP_GPIO_BANK2_NGPIO 26
37#define ZYNQMP_GPIO_BANK3_NGPIO 32
38#define ZYNQMP_GPIO_BANK4_NGPIO 32
39#define ZYNQMP_GPIO_BANK5_NGPIO 32
40
41#define ZYNQMP_GPIO_NR_GPIOS 174
42
43#define ZYNQ_GPIO_BANK0_PIN_MIN(str) 0
44#define ZYNQ_GPIO_BANK0_PIN_MAX(str) (ZYNQ_GPIO_BANK0_PIN_MIN(str) + \
45 ZYNQ##str##_GPIO_BANK0_NGPIO - 1)
46#define ZYNQ_GPIO_BANK1_PIN_MIN(str) (ZYNQ_GPIO_BANK0_PIN_MAX(str) + 1)
47#define ZYNQ_GPIO_BANK1_PIN_MAX(str) (ZYNQ_GPIO_BANK1_PIN_MIN(str) + \
48 ZYNQ##str##_GPIO_BANK1_NGPIO - 1)
49#define ZYNQ_GPIO_BANK2_PIN_MIN(str) (ZYNQ_GPIO_BANK1_PIN_MAX(str) + 1)
50#define ZYNQ_GPIO_BANK2_PIN_MAX(str) (ZYNQ_GPIO_BANK2_PIN_MIN(str) + \
51 ZYNQ##str##_GPIO_BANK2_NGPIO - 1)
52#define ZYNQ_GPIO_BANK3_PIN_MIN(str) (ZYNQ_GPIO_BANK2_PIN_MAX(str) + 1)
53#define ZYNQ_GPIO_BANK3_PIN_MAX(str) (ZYNQ_GPIO_BANK3_PIN_MIN(str) + \
54 ZYNQ##str##_GPIO_BANK3_NGPIO - 1)
55#define ZYNQ_GPIO_BANK4_PIN_MIN(str) (ZYNQ_GPIO_BANK3_PIN_MAX(str) + 1)
56#define ZYNQ_GPIO_BANK4_PIN_MAX(str) (ZYNQ_GPIO_BANK4_PIN_MIN(str) + \
57 ZYNQ##str##_GPIO_BANK4_NGPIO - 1)
58#define ZYNQ_GPIO_BANK5_PIN_MIN(str) (ZYNQ_GPIO_BANK4_PIN_MAX(str) + 1)
59#define ZYNQ_GPIO_BANK5_PIN_MAX(str) (ZYNQ_GPIO_BANK5_PIN_MIN(str) + \
60 ZYNQ##str##_GPIO_BANK5_NGPIO - 1)
Siva Durga Prasad Paladugu228a1f92016-03-10 16:27:42 +053061
62/* Register offsets for the GPIO device */
63/* LSW Mask & Data -WO */
64#define ZYNQ_GPIO_DATA_LSW_OFFSET(BANK) (0x000 + (8 * BANK))
65/* MSW Mask & Data -WO */
66#define ZYNQ_GPIO_DATA_MSW_OFFSET(BANK) (0x004 + (8 * BANK))
67/* Data Register-RW */
68#define ZYNQ_GPIO_DATA_RO_OFFSET(BANK) (0x060 + (4 * BANK))
69/* Direction mode reg-RW */
70#define ZYNQ_GPIO_DIRM_OFFSET(BANK) (0x204 + (0x40 * BANK))
71/* Output enable reg-RW */
72#define ZYNQ_GPIO_OUTEN_OFFSET(BANK) (0x208 + (0x40 * BANK))
73/* Interrupt mask reg-RO */
74#define ZYNQ_GPIO_INTMASK_OFFSET(BANK) (0x20C + (0x40 * BANK))
75/* Interrupt enable reg-WO */
76#define ZYNQ_GPIO_INTEN_OFFSET(BANK) (0x210 + (0x40 * BANK))
77/* Interrupt disable reg-WO */
78#define ZYNQ_GPIO_INTDIS_OFFSET(BANK) (0x214 + (0x40 * BANK))
79/* Interrupt status reg-RO */
80#define ZYNQ_GPIO_INTSTS_OFFSET(BANK) (0x218 + (0x40 * BANK))
81/* Interrupt type reg-RW */
82#define ZYNQ_GPIO_INTTYPE_OFFSET(BANK) (0x21C + (0x40 * BANK))
83/* Interrupt polarity reg-RW */
84#define ZYNQ_GPIO_INTPOL_OFFSET(BANK) (0x220 + (0x40 * BANK))
85/* Interrupt on any, reg-RW */
86#define ZYNQ_GPIO_INTANY_OFFSET(BANK) (0x224 + (0x40 * BANK))
87
88/* Disable all interrupts mask */
89#define ZYNQ_GPIO_IXR_DISABLE_ALL 0xFFFFFFFF
90
91/* Mid pin number of a bank */
92#define ZYNQ_GPIO_MID_PIN_NUM 16
93
94/* GPIO upper 16 bit mask */
95#define ZYNQ_GPIO_UPPER_MASK 0xFFFF0000
96
Shubhrajyoti Datta470e5fb2019-09-18 12:10:31 +053097#define PMC_GPIO_NR_GPIOS 116
98#define PMC_GPIO_MAX_BANK 5
99
Vipul Kumarc7824172018-07-20 14:36:49 +0530100struct zynq_gpio_platdata {
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530101 phys_addr_t base;
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530102 const struct zynq_platform_data *p_data;
103};
104
105/**
106 * struct zynq_platform_data - zynq gpio platform data structure
107 * @label: string to store in gpio->label
108 * @ngpio: max number of gpio pins
109 * @max_bank: maximum number of gpio banks
110 * @bank_min: this array represents bank's min pin
111 * @bank_max: this array represents bank's max pin
112 */
113struct zynq_platform_data {
114 const char *label;
115 u16 ngpio;
Michal Simek615900b2018-06-13 13:22:08 +0200116 u32 max_bank;
117 u32 bank_min[ZYNQMP_GPIO_MAX_BANK];
118 u32 bank_max[ZYNQMP_GPIO_MAX_BANK];
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530119};
120
Ashok Reddy Somac8a53072019-09-16 03:35:16 -0600121#define VERSAL_GPIO_NR_GPIOS 58
122#define VERSAL_GPIO_MAX_BANK 4
123
124static const struct zynq_platform_data versal_gpio_def = {
125 .label = "versal_gpio",
126 .ngpio = VERSAL_GPIO_NR_GPIOS,
127 .max_bank = VERSAL_GPIO_MAX_BANK,
128 .bank_min[0] = 0,
129 .bank_max[0] = 25,
130 .bank_min[3] = 26,
131 .bank_max[3] = 57,
132};
133
Shubhrajyoti Datta470e5fb2019-09-18 12:10:31 +0530134static const struct zynq_platform_data pmc_gpio_def = {
135 .label = "pmc_gpio",
136 .ngpio = PMC_GPIO_NR_GPIOS,
137 .max_bank = PMC_GPIO_MAX_BANK,
138 .bank_min[0] = 0,
139 .bank_max[0] = 25,
140 .bank_min[1] = 26,
141 .bank_max[1] = 51,
142 .bank_min[3] = 52,
143 .bank_max[3] = 83,
144 .bank_min[4] = 84,
145 .bank_max[4] = 115,
146};
147
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530148static const struct zynq_platform_data zynqmp_gpio_def = {
149 .label = "zynqmp_gpio",
150 .ngpio = ZYNQMP_GPIO_NR_GPIOS,
151 .max_bank = ZYNQMP_GPIO_MAX_BANK,
152 .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(MP),
153 .bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(MP),
154 .bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(MP),
155 .bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(MP),
156 .bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(MP),
157 .bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(MP),
158 .bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(MP),
159 .bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(MP),
160 .bank_min[4] = ZYNQ_GPIO_BANK4_PIN_MIN(MP),
161 .bank_max[4] = ZYNQ_GPIO_BANK4_PIN_MAX(MP),
162 .bank_min[5] = ZYNQ_GPIO_BANK5_PIN_MIN(MP),
163 .bank_max[5] = ZYNQ_GPIO_BANK5_PIN_MAX(MP),
164};
165
166static const struct zynq_platform_data zynq_gpio_def = {
167 .label = "zynq_gpio",
168 .ngpio = ZYNQ_GPIO_NR_GPIOS,
169 .max_bank = ZYNQ_GPIO_MAX_BANK,
170 .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(),
171 .bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(),
172 .bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(),
173 .bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(),
174 .bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(),
175 .bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(),
176 .bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(),
177 .bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(),
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530178};
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530179
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100180/**
181 * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank
182 * for a given pin in the GPIO device
183 * @pin_num: gpio pin number within the device
184 * @bank_num: an output parameter used to return the bank number of the gpio
185 * pin
186 * @bank_pin_num: an output parameter used to return pin number within a bank
187 * for the given gpio pin
188 *
189 * Returns the bank number and pin offset within the bank.
190 */
191static inline void zynq_gpio_get_bank_pin(unsigned int pin_num,
192 unsigned int *bank_num,
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530193 unsigned int *bank_pin_num,
194 struct udevice *dev)
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100195{
Vipul Kumarc7824172018-07-20 14:36:49 +0530196 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Michal Simek615900b2018-06-13 13:22:08 +0200197 u32 bank;
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530198
Vipul Kumarc7824172018-07-20 14:36:49 +0530199 for (bank = 0; bank < platdata->p_data->max_bank; bank++) {
200 if (pin_num >= platdata->p_data->bank_min[bank] &&
201 pin_num <= platdata->p_data->bank_max[bank]) {
202 *bank_num = bank;
203 *bank_pin_num = pin_num -
204 platdata->p_data->bank_min[bank];
205 return;
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530206 }
207 }
208
Vipul Kumarc7824172018-07-20 14:36:49 +0530209 if (bank >= platdata->p_data->max_bank) {
Michal Simekd05b7942018-07-12 12:30:34 +0200210 printf("Invalid bank and pin num\n");
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100211 *bank_num = 0;
212 *bank_pin_num = 0;
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100213 }
214}
215
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530216static int gpio_is_valid(unsigned gpio, struct udevice *dev)
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100217{
Vipul Kumarc7824172018-07-20 14:36:49 +0530218 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530219
Vipul Kumarc7824172018-07-20 14:36:49 +0530220 return gpio < platdata->p_data->ngpio;
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100221}
222
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530223static int check_gpio(unsigned gpio, struct udevice *dev)
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100224{
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530225 if (!gpio_is_valid(gpio, dev)) {
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100226 printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
227 return -1;
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100228 }
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100229 return 0;
230}
231
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530232static int zynq_gpio_get_value(struct udevice *dev, unsigned gpio)
233{
234 u32 data;
235 unsigned int bank_num, bank_pin_num;
Vipul Kumarc7824172018-07-20 14:36:49 +0530236 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530237
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530238 if (check_gpio(gpio, dev) < 0)
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530239 return -1;
240
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530241 zynq_gpio_get_bank_pin(gpio, &bank_num, &bank_pin_num, dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530242
Vipul Kumarc7824172018-07-20 14:36:49 +0530243 data = readl(platdata->base +
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530244 ZYNQ_GPIO_DATA_RO_OFFSET(bank_num));
245
246 return (data >> bank_pin_num) & 1;
247}
248
249static int zynq_gpio_set_value(struct udevice *dev, unsigned gpio, int value)
250{
251 unsigned int reg_offset, bank_num, bank_pin_num;
Vipul Kumarc7824172018-07-20 14:36:49 +0530252 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530253
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530254 if (check_gpio(gpio, dev) < 0)
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530255 return -1;
256
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530257 zynq_gpio_get_bank_pin(gpio, &bank_num, &bank_pin_num, dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530258
259 if (bank_pin_num >= ZYNQ_GPIO_MID_PIN_NUM) {
260 /* only 16 data bits in bit maskable reg */
261 bank_pin_num -= ZYNQ_GPIO_MID_PIN_NUM;
262 reg_offset = ZYNQ_GPIO_DATA_MSW_OFFSET(bank_num);
263 } else {
264 reg_offset = ZYNQ_GPIO_DATA_LSW_OFFSET(bank_num);
265 }
266
267 /*
268 * get the 32 bit value to be written to the mask/data register where
269 * the upper 16 bits is the mask and lower 16 bits is the data
270 */
271 value = !!value;
272 value = ~(1 << (bank_pin_num + ZYNQ_GPIO_MID_PIN_NUM)) &
273 ((value << bank_pin_num) | ZYNQ_GPIO_UPPER_MASK);
274
Vipul Kumarc7824172018-07-20 14:36:49 +0530275 writel(value, platdata->base + reg_offset);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530276
277 return 0;
278}
279
280static int zynq_gpio_direction_input(struct udevice *dev, unsigned gpio)
281{
282 u32 reg;
283 unsigned int bank_num, bank_pin_num;
Vipul Kumarc7824172018-07-20 14:36:49 +0530284 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530285
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530286 if (check_gpio(gpio, dev) < 0)
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530287 return -1;
288
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530289 zynq_gpio_get_bank_pin(gpio, &bank_num, &bank_pin_num, dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530290
291 /* bank 0 pins 7 and 8 are special and cannot be used as inputs */
292 if (bank_num == 0 && (bank_pin_num == 7 || bank_pin_num == 8))
293 return -1;
294
295 /* clear the bit in direction mode reg to set the pin as input */
Vipul Kumarc7824172018-07-20 14:36:49 +0530296 reg = readl(platdata->base + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530297 reg &= ~BIT(bank_pin_num);
Vipul Kumarc7824172018-07-20 14:36:49 +0530298 writel(reg, platdata->base + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530299
300 return 0;
301}
302
303static int zynq_gpio_direction_output(struct udevice *dev, unsigned gpio,
304 int value)
305{
306 u32 reg;
307 unsigned int bank_num, bank_pin_num;
Vipul Kumarc7824172018-07-20 14:36:49 +0530308 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530309
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530310 if (check_gpio(gpio, dev) < 0)
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530311 return -1;
312
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530313 zynq_gpio_get_bank_pin(gpio, &bank_num, &bank_pin_num, dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530314
315 /* set the GPIO pin as output */
Vipul Kumarc7824172018-07-20 14:36:49 +0530316 reg = readl(platdata->base + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530317 reg |= BIT(bank_pin_num);
Vipul Kumarc7824172018-07-20 14:36:49 +0530318 writel(reg, platdata->base + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530319
320 /* configure the output enable reg for the pin */
Vipul Kumarc7824172018-07-20 14:36:49 +0530321 reg = readl(platdata->base + ZYNQ_GPIO_OUTEN_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530322 reg |= BIT(bank_pin_num);
Vipul Kumarc7824172018-07-20 14:36:49 +0530323 writel(reg, platdata->base + ZYNQ_GPIO_OUTEN_OFFSET(bank_num));
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530324
325 /* set the state of the pin */
Ashok Reddy Somafb0f93a2019-09-11 04:40:11 -0600326 zynq_gpio_set_value(dev, gpio, value);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530327 return 0;
328}
329
Michal Simek514281f2016-03-04 15:56:50 +0100330static int zynq_gpio_get_function(struct udevice *dev, unsigned offset)
331{
332 u32 reg;
333 unsigned int bank_num, bank_pin_num;
Vipul Kumarc7824172018-07-20 14:36:49 +0530334 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Michal Simek514281f2016-03-04 15:56:50 +0100335
336 if (check_gpio(offset, dev) < 0)
337 return -1;
338
339 zynq_gpio_get_bank_pin(offset, &bank_num, &bank_pin_num, dev);
340
341 /* set the GPIO pin as output */
Vipul Kumarc7824172018-07-20 14:36:49 +0530342 reg = readl(platdata->base + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
Michal Simek514281f2016-03-04 15:56:50 +0100343 reg &= BIT(bank_pin_num);
344 if (reg)
345 return GPIOF_OUTPUT;
346 else
347 return GPIOF_INPUT;
348}
349
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530350static const struct dm_gpio_ops gpio_zynq_ops = {
351 .direction_input = zynq_gpio_direction_input,
352 .direction_output = zynq_gpio_direction_output,
353 .get_value = zynq_gpio_get_value,
354 .set_value = zynq_gpio_set_value,
Michal Simek514281f2016-03-04 15:56:50 +0100355 .get_function = zynq_gpio_get_function,
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530356};
357
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530358static const struct udevice_id zynq_gpio_ids[] = {
359 { .compatible = "xlnx,zynq-gpio-1.0",
360 .data = (ulong)&zynq_gpio_def},
361 { .compatible = "xlnx,zynqmp-gpio-1.0",
362 .data = (ulong)&zynqmp_gpio_def},
Ashok Reddy Somac8a53072019-09-16 03:35:16 -0600363 { .compatible = "xlnx,versal-gpio-1.0",
364 .data = (ulong)&versal_gpio_def},
Shubhrajyoti Datta470e5fb2019-09-18 12:10:31 +0530365 { .compatible = "xlnx,pmc-gpio-1.0",
366 .data = (ulong)&pmc_gpio_def },
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530367 { }
368};
369
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530370static int zynq_gpio_probe(struct udevice *dev)
371{
Vipul Kumarc7824172018-07-20 14:36:49 +0530372 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu1904ce52016-03-10 16:27:43 +0530373 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
Michal Simek305f1c52018-08-02 12:58:54 +0200374 const void *label_ptr;
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530375
Michal Simek305f1c52018-08-02 12:58:54 +0200376 label_ptr = dev_read_prop(dev, "label", NULL);
377 if (label_ptr) {
378 uc_priv->bank_name = strdup(label_ptr);
379 if (!uc_priv->bank_name)
380 return -ENOMEM;
381 } else {
382 uc_priv->bank_name = dev->name;
383 }
Michal Simeke4406652018-06-21 13:58:56 +0200384
Vipul Kumarc7824172018-07-20 14:36:49 +0530385 if (platdata->p_data)
386 uc_priv->gpio_count = platdata->p_data->ngpio;
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530387
388 return 0;
389}
390
391static int zynq_gpio_ofdata_to_platdata(struct udevice *dev)
392{
Vipul Kumarc7824172018-07-20 14:36:49 +0530393 struct zynq_gpio_platdata *platdata = dev_get_platdata(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530394
Vipul Kumarc7824172018-07-20 14:36:49 +0530395 platdata->base = (phys_addr_t)dev_read_addr(dev);
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530396
Vipul Kumarc7824172018-07-20 14:36:49 +0530397 platdata->p_data =
398 (struct zynq_platform_data *)dev_get_driver_data(dev);
Michal Simek625bc082018-07-12 10:58:04 +0200399
Andrea Scian4bbf3ca2015-03-20 16:00:25 +0100400 return 0;
401}
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530402
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530403U_BOOT_DRIVER(gpio_zynq) = {
404 .name = "gpio_zynq",
405 .id = UCLASS_GPIO,
406 .ops = &gpio_zynq_ops,
407 .of_match = zynq_gpio_ids,
408 .ofdata_to_platdata = zynq_gpio_ofdata_to_platdata,
409 .probe = zynq_gpio_probe,
Vipul Kumarc7824172018-07-20 14:36:49 +0530410 .platdata_auto_alloc_size = sizeof(struct zynq_gpio_platdata),
Siva Durga Prasad Paladugu6fea9012016-03-10 16:27:38 +0530411};