Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Atmel PIO4 device driver |
| 4 | * |
| 5 | * Copyright (C) 2015 Atmel Corporation |
| 6 | * Wenyou.Yang <wenyou.yang@atmel.com> |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 7 | */ |
| 8 | #include <common.h> |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 9 | #include <clk.h> |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 10 | #include <dm.h> |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 11 | #include <fdtdec.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 16 | #include <mach/gpio.h> |
| 17 | #include <mach/atmel_pio4.h> |
| 18 | |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 21 | static struct atmel_pio4_port *atmel_pio4_port_base(u32 port) |
| 22 | { |
| 23 | struct atmel_pio4_port *base = NULL; |
| 24 | |
| 25 | switch (port) { |
| 26 | case AT91_PIO_PORTA: |
| 27 | base = (struct atmel_pio4_port *)ATMEL_BASE_PIOA; |
| 28 | break; |
| 29 | case AT91_PIO_PORTB: |
| 30 | base = (struct atmel_pio4_port *)ATMEL_BASE_PIOB; |
| 31 | break; |
| 32 | case AT91_PIO_PORTC: |
| 33 | base = (struct atmel_pio4_port *)ATMEL_BASE_PIOC; |
| 34 | break; |
| 35 | case AT91_PIO_PORTD: |
| 36 | base = (struct atmel_pio4_port *)ATMEL_BASE_PIOD; |
| 37 | break; |
| 38 | default: |
| 39 | printf("Error: Atmel PIO4: Failed to get PIO base of port#%d!\n", |
| 40 | port); |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | return base; |
| 45 | } |
| 46 | |
| 47 | static int atmel_pio4_config_io_func(u32 port, u32 pin, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 48 | u32 func, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 49 | { |
| 50 | struct atmel_pio4_port *port_base; |
| 51 | u32 reg, mask; |
| 52 | |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 53 | if (pin >= ATMEL_PIO_NPINS_PER_BANK) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 54 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 55 | |
| 56 | port_base = atmel_pio4_port_base(port); |
| 57 | if (!port_base) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 58 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 59 | |
| 60 | mask = 1 << pin; |
| 61 | reg = func; |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 62 | reg |= config; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 63 | |
| 64 | writel(mask, &port_base->mskr); |
| 65 | writel(reg, &port_base->cfgr); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 70 | int atmel_pio4_set_gpio(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 71 | { |
| 72 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 73 | ATMEL_PIO_CFGR_FUNC_GPIO, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 74 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 75 | } |
| 76 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 77 | int atmel_pio4_set_a_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 78 | { |
| 79 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 80 | ATMEL_PIO_CFGR_FUNC_PERIPH_A, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 81 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 84 | int atmel_pio4_set_b_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 85 | { |
| 86 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 87 | ATMEL_PIO_CFGR_FUNC_PERIPH_B, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 88 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 89 | } |
| 90 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 91 | int atmel_pio4_set_c_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 92 | { |
| 93 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 94 | ATMEL_PIO_CFGR_FUNC_PERIPH_C, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 95 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 96 | } |
| 97 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 98 | int atmel_pio4_set_d_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 99 | { |
| 100 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 101 | ATMEL_PIO_CFGR_FUNC_PERIPH_D, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 102 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 103 | } |
| 104 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 105 | int atmel_pio4_set_e_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 106 | { |
| 107 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 108 | ATMEL_PIO_CFGR_FUNC_PERIPH_E, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 109 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 110 | } |
| 111 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 112 | int atmel_pio4_set_f_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 113 | { |
| 114 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 115 | ATMEL_PIO_CFGR_FUNC_PERIPH_F, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 116 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 119 | int atmel_pio4_set_g_periph(u32 port, u32 pin, u32 config) |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 120 | { |
| 121 | return atmel_pio4_config_io_func(port, pin, |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 122 | ATMEL_PIO_CFGR_FUNC_PERIPH_G, |
Ludovic Desroches | 8650491 | 2018-04-24 10:16:01 +0300 | [diff] [blame] | 123 | config); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | int atmel_pio4_set_pio_output(u32 port, u32 pin, u32 value) |
| 127 | { |
| 128 | struct atmel_pio4_port *port_base; |
| 129 | u32 reg, mask; |
| 130 | |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 131 | if (pin >= ATMEL_PIO_NPINS_PER_BANK) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 132 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 133 | |
| 134 | port_base = atmel_pio4_port_base(port); |
| 135 | if (!port_base) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 136 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 137 | |
| 138 | mask = 0x01 << pin; |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 139 | reg = ATMEL_PIO_CFGR_FUNC_GPIO | ATMEL_PIO_DIR_MASK; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 140 | |
| 141 | writel(mask, &port_base->mskr); |
| 142 | writel(reg, &port_base->cfgr); |
| 143 | |
| 144 | if (value) |
| 145 | writel(mask, &port_base->sodr); |
| 146 | else |
| 147 | writel(mask, &port_base->codr); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int atmel_pio4_get_pio_input(u32 port, u32 pin) |
| 153 | { |
| 154 | struct atmel_pio4_port *port_base; |
| 155 | u32 reg, mask; |
| 156 | |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 157 | if (pin >= ATMEL_PIO_NPINS_PER_BANK) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 158 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 159 | |
| 160 | port_base = atmel_pio4_port_base(port); |
| 161 | if (!port_base) |
Simon Glass | f44b4bf | 2017-09-17 16:54:53 -0600 | [diff] [blame] | 162 | return -EINVAL; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 163 | |
| 164 | mask = 0x01 << pin; |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 165 | reg = ATMEL_PIO_CFGR_FUNC_GPIO; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 166 | |
| 167 | writel(mask, &port_base->mskr); |
| 168 | writel(reg, &port_base->cfgr); |
| 169 | |
| 170 | return (readl(&port_base->pdsr) & mask) ? 1 : 0; |
| 171 | } |
| 172 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 173 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 174 | |
| 175 | struct atmel_pioctrl_data { |
| 176 | u32 nbanks; |
| 177 | }; |
| 178 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 179 | struct atmel_pio4_plat { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 180 | struct atmel_pio4_port *reg_base; |
| 181 | }; |
| 182 | |
| 183 | static struct atmel_pio4_port *atmel_pio4_bank_base(struct udevice *dev, |
| 184 | u32 bank) |
| 185 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 186 | struct atmel_pio4_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 187 | struct atmel_pio4_port *port_base = |
| 188 | (struct atmel_pio4_port *)((u32)plat->reg_base + |
| 189 | ATMEL_PIO_BANK_OFFSET * bank); |
| 190 | |
| 191 | return port_base; |
| 192 | } |
| 193 | |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 194 | static int atmel_pio4_direction_input(struct udevice *dev, unsigned offset) |
| 195 | { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 196 | u32 bank = ATMEL_PIO_BANK(offset); |
| 197 | u32 line = ATMEL_PIO_LINE(offset); |
| 198 | struct atmel_pio4_port *port_base = atmel_pio4_bank_base(dev, bank); |
| 199 | u32 mask = BIT(line); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 200 | |
| 201 | writel(mask, &port_base->mskr); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 202 | |
| 203 | clrbits_le32(&port_base->cfgr, |
| 204 | ATMEL_PIO_CFGR_FUNC_MASK | ATMEL_PIO_DIR_MASK); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int atmel_pio4_direction_output(struct udevice *dev, |
| 210 | unsigned offset, int value) |
| 211 | { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 212 | u32 bank = ATMEL_PIO_BANK(offset); |
| 213 | u32 line = ATMEL_PIO_LINE(offset); |
| 214 | struct atmel_pio4_port *port_base = atmel_pio4_bank_base(dev, bank); |
| 215 | u32 mask = BIT(line); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 216 | |
| 217 | writel(mask, &port_base->mskr); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 218 | |
| 219 | clrsetbits_le32(&port_base->cfgr, |
| 220 | ATMEL_PIO_CFGR_FUNC_MASK, ATMEL_PIO_DIR_MASK); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 221 | |
| 222 | if (value) |
| 223 | writel(mask, &port_base->sodr); |
| 224 | else |
| 225 | writel(mask, &port_base->codr); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static int atmel_pio4_get_value(struct udevice *dev, unsigned offset) |
| 231 | { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 232 | u32 bank = ATMEL_PIO_BANK(offset); |
| 233 | u32 line = ATMEL_PIO_LINE(offset); |
| 234 | struct atmel_pio4_port *port_base = atmel_pio4_bank_base(dev, bank); |
| 235 | u32 mask = BIT(line); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 236 | |
| 237 | return (readl(&port_base->pdsr) & mask) ? 1 : 0; |
| 238 | } |
| 239 | |
| 240 | static int atmel_pio4_set_value(struct udevice *dev, |
| 241 | unsigned offset, int value) |
| 242 | { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 243 | u32 bank = ATMEL_PIO_BANK(offset); |
| 244 | u32 line = ATMEL_PIO_LINE(offset); |
| 245 | struct atmel_pio4_port *port_base = atmel_pio4_bank_base(dev, bank); |
| 246 | u32 mask = BIT(line); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 247 | |
| 248 | if (value) |
| 249 | writel(mask, &port_base->sodr); |
| 250 | else |
| 251 | writel(mask, &port_base->codr); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int atmel_pio4_get_function(struct udevice *dev, unsigned offset) |
| 257 | { |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 258 | u32 bank = ATMEL_PIO_BANK(offset); |
| 259 | u32 line = ATMEL_PIO_LINE(offset); |
| 260 | struct atmel_pio4_port *port_base = atmel_pio4_bank_base(dev, bank); |
| 261 | u32 mask = BIT(line); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 262 | |
| 263 | writel(mask, &port_base->mskr); |
| 264 | |
| 265 | return (readl(&port_base->cfgr) & |
Wenyou Yang | 312bf89 | 2016-07-20 17:16:25 +0800 | [diff] [blame] | 266 | ATMEL_PIO_DIR_MASK) ? GPIOF_OUTPUT : GPIOF_INPUT; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static const struct dm_gpio_ops atmel_pio4_ops = { |
| 270 | .direction_input = atmel_pio4_direction_input, |
| 271 | .direction_output = atmel_pio4_direction_output, |
| 272 | .get_value = atmel_pio4_get_value, |
| 273 | .set_value = atmel_pio4_set_value, |
| 274 | .get_function = atmel_pio4_get_function, |
| 275 | }; |
| 276 | |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 277 | static int atmel_pio4_bind(struct udevice *dev) |
| 278 | { |
Simon Glass | 292796f | 2017-05-17 17:18:06 -0600 | [diff] [blame] | 279 | return dm_scan_fdt_dev(dev); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 280 | } |
| 281 | |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 282 | static int atmel_pio4_probe(struct udevice *dev) |
| 283 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 284 | struct atmel_pio4_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 285 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 286 | struct atmel_pioctrl_data *pioctrl_data; |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 287 | struct clk clk; |
| 288 | fdt_addr_t addr_base; |
| 289 | u32 nbanks; |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 290 | int ret; |
| 291 | |
| 292 | ret = clk_get_by_index(dev, 0, &clk); |
| 293 | if (ret) |
| 294 | return ret; |
| 295 | |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 296 | ret = clk_enable(&clk); |
| 297 | if (ret) |
| 298 | return ret; |
| 299 | |
| 300 | clk_free(&clk); |
| 301 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 302 | addr_base = dev_read_addr(dev); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 303 | if (addr_base == FDT_ADDR_T_NONE) |
| 304 | return -EINVAL; |
| 305 | |
| 306 | plat->reg_base = (struct atmel_pio4_port *)addr_base; |
| 307 | |
| 308 | pioctrl_data = (struct atmel_pioctrl_data *)dev_get_driver_data(dev); |
| 309 | nbanks = pioctrl_data->nbanks; |
| 310 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 311 | uc_priv->bank_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), |
| 312 | NULL); |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 313 | uc_priv->gpio_count = nbanks * ATMEL_PIO_NPINS_PER_BANK; |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 318 | /* |
| 319 | * The number of banks can be different from a SoC to another one. |
| 320 | * We can have up to 16 banks. |
| 321 | */ |
| 322 | static const struct atmel_pioctrl_data atmel_sama5d2_pioctrl_data = { |
| 323 | .nbanks = 4, |
| 324 | }; |
| 325 | |
| 326 | static const struct udevice_id atmel_pio4_ids[] = { |
| 327 | { |
| 328 | .compatible = "atmel,sama5d2-gpio", |
| 329 | .data = (ulong)&atmel_sama5d2_pioctrl_data, |
| 330 | }, |
| 331 | {} |
| 332 | }; |
| 333 | |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 334 | U_BOOT_DRIVER(gpio_atmel_pio4) = { |
| 335 | .name = "gpio_atmel_pio4", |
| 336 | .id = UCLASS_GPIO, |
| 337 | .ops = &atmel_pio4_ops, |
| 338 | .probe = atmel_pio4_probe, |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 339 | .bind = atmel_pio4_bind, |
| 340 | .of_match = atmel_pio4_ids, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 341 | .plat_auto = sizeof(struct atmel_pio4_plat), |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 342 | }; |
Wenyou Yang | 0b97152 | 2016-07-20 17:16:26 +0800 | [diff] [blame] | 343 | |
Wenyou Yang | 5a09d13 | 2015-11-04 14:25:13 +0800 | [diff] [blame] | 344 | #endif |