Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Pinmuxed GPIO support for SuperH. |
| 3 | * |
| 4 | * Copyright (C) 2008 Magnus Damm |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 12 | #include <linux/errno.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/clk.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/bitops.h> |
| 21 | #include <linux/gpio.h> |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/ioport.h> |
| 24 | |
| 25 | static void pfc_iounmap(struct pinmux_info *pip) |
| 26 | { |
| 27 | int k; |
| 28 | |
| 29 | for (k = 0; k < pip->num_resources; k++) |
| 30 | if (pip->window[k].virt) |
| 31 | iounmap(pip->window[k].virt); |
| 32 | |
| 33 | kfree(pip->window); |
| 34 | pip->window = NULL; |
| 35 | } |
| 36 | |
| 37 | static int pfc_ioremap(struct pinmux_info *pip) |
| 38 | { |
| 39 | struct resource *res; |
| 40 | int k; |
| 41 | |
| 42 | if (!pip->num_resources) |
| 43 | return 0; |
| 44 | |
| 45 | pip->window = kzalloc(pip->num_resources * sizeof(*pip->window), |
| 46 | GFP_NOWAIT); |
| 47 | if (!pip->window) |
| 48 | goto err1; |
| 49 | |
| 50 | for (k = 0; k < pip->num_resources; k++) { |
| 51 | res = pip->resource + k; |
| 52 | WARN_ON(resource_type(res) != IORESOURCE_MEM); |
| 53 | pip->window[k].phys = res->start; |
| 54 | pip->window[k].size = resource_size(res); |
| 55 | pip->window[k].virt = ioremap_nocache(res->start, |
| 56 | resource_size(res)); |
| 57 | if (!pip->window[k].virt) |
| 58 | goto err2; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | |
| 63 | err2: |
| 64 | pfc_iounmap(pip); |
| 65 | err1: |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | static void __iomem *pfc_phys_to_virt(struct pinmux_info *pip, |
| 70 | unsigned long address) |
| 71 | { |
| 72 | struct pfc_window *window; |
| 73 | int k; |
| 74 | |
| 75 | /* scan through physical windows and convert address */ |
| 76 | for (k = 0; k < pip->num_resources; k++) { |
| 77 | window = pip->window + k; |
| 78 | |
| 79 | if (address < window->phys) |
| 80 | continue; |
| 81 | |
| 82 | if (address >= (window->phys + window->size)) |
| 83 | continue; |
| 84 | |
| 85 | return window->virt + (address - window->phys); |
| 86 | } |
| 87 | |
| 88 | /* no windows defined, register must be 1:1 mapped virt:phys */ |
| 89 | return (void __iomem *)address; |
| 90 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 91 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 92 | static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) |
| 93 | { |
| 94 | if (enum_id < r->begin) |
| 95 | return 0; |
| 96 | |
| 97 | if (enum_id > r->end) |
| 98 | return 0; |
| 99 | |
| 100 | return 1; |
| 101 | } |
| 102 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 103 | static unsigned long gpio_read_raw_reg(void __iomem *mapped_reg, |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 104 | unsigned long reg_width) |
| 105 | { |
| 106 | switch (reg_width) { |
| 107 | case 8: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 108 | return ioread8(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 109 | case 16: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 110 | return ioread16(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 111 | case 32: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 112 | return ioread32(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | BUG(); |
| 116 | return 0; |
| 117 | } |
| 118 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 119 | static void gpio_write_raw_reg(void __iomem *mapped_reg, |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 120 | unsigned long reg_width, |
| 121 | unsigned long data) |
| 122 | { |
| 123 | switch (reg_width) { |
| 124 | case 8: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 125 | iowrite8(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 126 | return; |
| 127 | case 16: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 128 | iowrite16(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 129 | return; |
| 130 | case 32: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 131 | iowrite32(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | |
| 135 | BUG(); |
| 136 | } |
| 137 | |
Magnus Damm | 92554d9 | 2011-12-14 01:00:37 +0900 | [diff] [blame] | 138 | static int gpio_read_bit(struct pinmux_data_reg *dr, |
| 139 | unsigned long in_pos) |
| 140 | { |
| 141 | unsigned long pos; |
| 142 | |
| 143 | pos = dr->reg_width - (in_pos + 1); |
| 144 | |
| 145 | pr_debug("read_bit: addr = %lx, pos = %ld, " |
| 146 | "r_width = %ld\n", dr->reg, pos, dr->reg_width); |
| 147 | |
| 148 | return (gpio_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; |
| 149 | } |
| 150 | |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 151 | static void gpio_write_bit(struct pinmux_data_reg *dr, |
| 152 | unsigned long in_pos, unsigned long value) |
| 153 | { |
| 154 | unsigned long pos; |
| 155 | |
| 156 | pos = dr->reg_width - (in_pos + 1); |
| 157 | |
Paul Mundt | ca6f2d7 | 2009-12-09 15:51:27 +0900 | [diff] [blame] | 158 | pr_debug("write_bit addr = %lx, value = %d, pos = %ld, " |
Paul Mundt | fd2cb0c | 2009-11-30 12:15:04 +0900 | [diff] [blame] | 159 | "r_width = %ld\n", |
| 160 | dr->reg, !!value, pos, dr->reg_width); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 161 | |
| 162 | if (value) |
| 163 | set_bit(pos, &dr->reg_shadow); |
| 164 | else |
| 165 | clear_bit(pos, &dr->reg_shadow); |
| 166 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 167 | gpio_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 168 | } |
| 169 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 170 | static int gpio_read_reg(void __iomem *mapped_reg, unsigned long reg_width, |
| 171 | unsigned long field_width, unsigned long in_pos, |
| 172 | unsigned long reg) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 173 | { |
| 174 | unsigned long data, mask, pos; |
| 175 | |
| 176 | data = 0; |
| 177 | mask = (1 << field_width) - 1; |
| 178 | pos = reg_width - ((in_pos + 1) * field_width); |
| 179 | |
Paul Mundt | fd2cb0c | 2009-11-30 12:15:04 +0900 | [diff] [blame] | 180 | pr_debug("read_reg: addr = %lx, pos = %ld, " |
| 181 | "r_width = %ld, f_width = %ld\n", |
| 182 | reg, pos, reg_width, field_width); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 183 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 184 | data = gpio_read_raw_reg(mapped_reg, reg_width); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 185 | return (data >> pos) & mask; |
| 186 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 187 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 188 | static void gpio_write_reg(void __iomem *mapped_reg, unsigned long reg_width, |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 189 | unsigned long field_width, unsigned long in_pos, |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 190 | unsigned long value, unsigned long reg) |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 191 | { |
| 192 | unsigned long mask, pos; |
| 193 | |
| 194 | mask = (1 << field_width) - 1; |
| 195 | pos = reg_width - ((in_pos + 1) * field_width); |
| 196 | |
Paul Mundt | fd2cb0c | 2009-11-30 12:15:04 +0900 | [diff] [blame] | 197 | pr_debug("write_reg addr = %lx, value = %ld, pos = %ld, " |
| 198 | "r_width = %ld, f_width = %ld\n", |
| 199 | reg, value, pos, reg_width, field_width); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 200 | |
| 201 | mask = ~(mask << pos); |
| 202 | value = value << pos; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 203 | |
| 204 | switch (reg_width) { |
| 205 | case 8: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 206 | iowrite8((ioread8(mapped_reg) & mask) | value, mapped_reg); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 207 | break; |
| 208 | case 16: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 209 | iowrite16((ioread16(mapped_reg) & mask) | value, mapped_reg); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 210 | break; |
| 211 | case 32: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 212 | iowrite32((ioread32(mapped_reg) & mask) | value, mapped_reg); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 213 | break; |
| 214 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 217 | static int setup_data_reg(struct pinmux_info *gpioc, unsigned gpio) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 218 | { |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 219 | struct pinmux_gpio *gpiop = &gpioc->gpios[gpio]; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 220 | struct pinmux_data_reg *data_reg; |
| 221 | int k, n; |
| 222 | |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 223 | if (!enum_in_range(gpiop->enum_id, &gpioc->data)) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 224 | return -1; |
| 225 | |
| 226 | k = 0; |
| 227 | while (1) { |
| 228 | data_reg = gpioc->data_regs + k; |
| 229 | |
| 230 | if (!data_reg->reg_width) |
| 231 | break; |
| 232 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 233 | data_reg->mapped_reg = pfc_phys_to_virt(gpioc, data_reg->reg); |
| 234 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 235 | for (n = 0; n < data_reg->reg_width; n++) { |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 236 | if (data_reg->enum_ids[n] == gpiop->enum_id) { |
| 237 | gpiop->flags &= ~PINMUX_FLAG_DREG; |
| 238 | gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT); |
| 239 | gpiop->flags &= ~PINMUX_FLAG_DBIT; |
| 240 | gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 241 | return 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | k++; |
| 245 | } |
| 246 | |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 247 | BUG(); |
| 248 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 249 | return -1; |
| 250 | } |
| 251 | |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 252 | static void setup_data_regs(struct pinmux_info *gpioc) |
| 253 | { |
| 254 | struct pinmux_data_reg *drp; |
| 255 | int k; |
| 256 | |
| 257 | for (k = gpioc->first_gpio; k <= gpioc->last_gpio; k++) |
| 258 | setup_data_reg(gpioc, k); |
| 259 | |
| 260 | k = 0; |
| 261 | while (1) { |
| 262 | drp = gpioc->data_regs + k; |
| 263 | |
| 264 | if (!drp->reg_width) |
| 265 | break; |
| 266 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 267 | drp->reg_shadow = gpio_read_raw_reg(drp->mapped_reg, |
| 268 | drp->reg_width); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 269 | k++; |
| 270 | } |
| 271 | } |
| 272 | |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 273 | static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio, |
| 274 | struct pinmux_data_reg **drp, int *bitp) |
| 275 | { |
| 276 | struct pinmux_gpio *gpiop = &gpioc->gpios[gpio]; |
| 277 | int k, n; |
| 278 | |
| 279 | if (!enum_in_range(gpiop->enum_id, &gpioc->data)) |
| 280 | return -1; |
| 281 | |
| 282 | k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; |
| 283 | n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; |
| 284 | *drp = gpioc->data_regs + k; |
| 285 | *bitp = n; |
| 286 | return 0; |
| 287 | } |
| 288 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 289 | static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id, |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 290 | struct pinmux_cfg_reg **crp, |
| 291 | int *fieldp, int *valuep, |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 292 | unsigned long **cntp) |
| 293 | { |
| 294 | struct pinmux_cfg_reg *config_reg; |
| 295 | unsigned long r_width, f_width; |
| 296 | int k, n; |
| 297 | |
| 298 | k = 0; |
| 299 | while (1) { |
| 300 | config_reg = gpioc->cfg_regs + k; |
| 301 | |
| 302 | r_width = config_reg->reg_width; |
| 303 | f_width = config_reg->field_width; |
| 304 | |
| 305 | if (!r_width) |
| 306 | break; |
Magnus Damm | c63bcc6 | 2011-10-17 18:01:19 +0900 | [diff] [blame] | 307 | for (n = 0; n < (r_width / f_width) * (1 << f_width); n++) { |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 308 | if (config_reg->enum_ids[n] == enum_id) { |
| 309 | *crp = config_reg; |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 310 | *fieldp = n / (1 << f_width); |
| 311 | *valuep = n % (1 << f_width); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 312 | *cntp = &config_reg->cnt[n / (1 << f_width)]; |
| 313 | return 0; |
| 314 | } |
| 315 | } |
| 316 | k++; |
| 317 | } |
| 318 | |
| 319 | return -1; |
| 320 | } |
| 321 | |
| 322 | static int get_gpio_enum_id(struct pinmux_info *gpioc, unsigned gpio, |
| 323 | int pos, pinmux_enum_t *enum_idp) |
| 324 | { |
| 325 | pinmux_enum_t enum_id = gpioc->gpios[gpio].enum_id; |
| 326 | pinmux_enum_t *data = gpioc->gpio_data; |
| 327 | int k; |
| 328 | |
| 329 | if (!enum_in_range(enum_id, &gpioc->data)) { |
| 330 | if (!enum_in_range(enum_id, &gpioc->mark)) { |
| 331 | pr_err("non data/mark enum_id for gpio %d\n", gpio); |
| 332 | return -1; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (pos) { |
| 337 | *enum_idp = data[pos + 1]; |
| 338 | return pos + 1; |
| 339 | } |
| 340 | |
| 341 | for (k = 0; k < gpioc->gpio_data_size; k++) { |
| 342 | if (data[k] == enum_id) { |
| 343 | *enum_idp = data[k + 1]; |
| 344 | return k + 1; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio); |
| 349 | return -1; |
| 350 | } |
| 351 | |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 352 | static void write_config_reg(struct pinmux_info *gpioc, |
| 353 | struct pinmux_cfg_reg *crp, |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 354 | int field, int value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 355 | { |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 356 | void __iomem *mapped_reg = pfc_phys_to_virt(gpioc, crp->reg); |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 357 | |
| 358 | gpio_write_reg(mapped_reg, crp->reg_width, crp->field_width, |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 359 | field, value, crp->reg); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int check_config_reg(struct pinmux_info *gpioc, |
| 363 | struct pinmux_cfg_reg *crp, |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 364 | int field, int value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 365 | { |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 366 | void __iomem *mapped_reg = pfc_phys_to_virt(gpioc, crp->reg); |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 367 | |
| 368 | if (gpio_read_reg(mapped_reg, crp->reg_width, |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 369 | crp->field_width, field, crp->reg) == value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 370 | return 0; |
| 371 | |
| 372 | return -1; |
| 373 | } |
| 374 | |
| 375 | enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE }; |
| 376 | |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 377 | static int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio, |
| 378 | int pinmux_type, int cfg_mode) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 379 | { |
| 380 | struct pinmux_cfg_reg *cr = NULL; |
| 381 | pinmux_enum_t enum_id; |
| 382 | struct pinmux_range *range; |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 383 | int in_range, pos, field, value; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 384 | unsigned long *cntp; |
| 385 | |
| 386 | switch (pinmux_type) { |
| 387 | |
| 388 | case PINMUX_TYPE_FUNCTION: |
| 389 | range = NULL; |
| 390 | break; |
| 391 | |
| 392 | case PINMUX_TYPE_OUTPUT: |
| 393 | range = &gpioc->output; |
| 394 | break; |
| 395 | |
| 396 | case PINMUX_TYPE_INPUT: |
| 397 | range = &gpioc->input; |
| 398 | break; |
| 399 | |
| 400 | case PINMUX_TYPE_INPUT_PULLUP: |
| 401 | range = &gpioc->input_pu; |
| 402 | break; |
| 403 | |
| 404 | case PINMUX_TYPE_INPUT_PULLDOWN: |
| 405 | range = &gpioc->input_pd; |
| 406 | break; |
| 407 | |
| 408 | default: |
| 409 | goto out_err; |
| 410 | } |
| 411 | |
| 412 | pos = 0; |
| 413 | enum_id = 0; |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 414 | field = 0; |
| 415 | value = 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 416 | while (1) { |
| 417 | pos = get_gpio_enum_id(gpioc, gpio, pos, &enum_id); |
| 418 | if (pos <= 0) |
| 419 | goto out_err; |
| 420 | |
| 421 | if (!enum_id) |
| 422 | break; |
| 423 | |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 424 | /* first check if this is a function enum */ |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 425 | in_range = enum_in_range(enum_id, &gpioc->function); |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 426 | if (!in_range) { |
| 427 | /* not a function enum */ |
| 428 | if (range) { |
| 429 | /* |
| 430 | * other range exists, so this pin is |
| 431 | * a regular GPIO pin that now is being |
| 432 | * bound to a specific direction. |
| 433 | * |
| 434 | * for this case we only allow function enums |
| 435 | * and the enums that match the other range. |
| 436 | */ |
| 437 | in_range = enum_in_range(enum_id, range); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 438 | |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 439 | /* |
| 440 | * special case pass through for fixed |
| 441 | * input-only or output-only pins without |
| 442 | * function enum register association. |
| 443 | */ |
| 444 | if (in_range && enum_id == range->force) |
| 445 | continue; |
| 446 | } else { |
| 447 | /* |
| 448 | * no other range exists, so this pin |
| 449 | * must then be of the function type. |
| 450 | * |
| 451 | * allow function type pins to select |
| 452 | * any combination of function/in/out |
| 453 | * in their MARK lists. |
| 454 | */ |
| 455 | in_range = 1; |
| 456 | } |
Magnus Damm | 42eed42 | 2008-10-22 18:29:17 +0900 | [diff] [blame] | 457 | } |
| 458 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 459 | if (!in_range) |
| 460 | continue; |
| 461 | |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 462 | if (get_config_reg(gpioc, enum_id, &cr, |
| 463 | &field, &value, &cntp) != 0) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 464 | goto out_err; |
| 465 | |
| 466 | switch (cfg_mode) { |
| 467 | case GPIO_CFG_DRYRUN: |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 468 | if (!*cntp || !check_config_reg(gpioc, cr, |
| 469 | field, value)) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 470 | continue; |
| 471 | break; |
| 472 | |
| 473 | case GPIO_CFG_REQ: |
Magnus Damm | ad4a07f | 2011-12-14 01:00:46 +0900 | [diff] [blame^] | 474 | write_config_reg(gpioc, cr, field, value); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 475 | *cntp = *cntp + 1; |
| 476 | break; |
| 477 | |
| 478 | case GPIO_CFG_FREE: |
| 479 | *cntp = *cntp - 1; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | out_err: |
| 486 | return -1; |
| 487 | } |
| 488 | |
| 489 | static DEFINE_SPINLOCK(gpio_lock); |
| 490 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 491 | static struct pinmux_info *chip_to_pinmux(struct gpio_chip *chip) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 492 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 493 | return container_of(chip, struct pinmux_info, chip); |
| 494 | } |
| 495 | |
| 496 | static int sh_gpio_request(struct gpio_chip *chip, unsigned offset) |
| 497 | { |
| 498 | struct pinmux_info *gpioc = chip_to_pinmux(chip); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 499 | struct pinmux_data_reg *dummy; |
| 500 | unsigned long flags; |
| 501 | int i, ret, pinmux_type; |
| 502 | |
| 503 | ret = -EINVAL; |
| 504 | |
| 505 | if (!gpioc) |
| 506 | goto err_out; |
| 507 | |
| 508 | spin_lock_irqsave(&gpio_lock, flags); |
| 509 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 510 | if ((gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 511 | goto err_unlock; |
| 512 | |
| 513 | /* setup pin function here if no data is associated with pin */ |
| 514 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 515 | if (get_data_reg(gpioc, offset, &dummy, &i) != 0) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 516 | pinmux_type = PINMUX_TYPE_FUNCTION; |
| 517 | else |
| 518 | pinmux_type = PINMUX_TYPE_GPIO; |
| 519 | |
| 520 | if (pinmux_type == PINMUX_TYPE_FUNCTION) { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 521 | if (pinmux_config_gpio(gpioc, offset, |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 522 | pinmux_type, |
| 523 | GPIO_CFG_DRYRUN) != 0) |
| 524 | goto err_unlock; |
| 525 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 526 | if (pinmux_config_gpio(gpioc, offset, |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 527 | pinmux_type, |
| 528 | GPIO_CFG_REQ) != 0) |
| 529 | BUG(); |
| 530 | } |
| 531 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 532 | gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; |
| 533 | gpioc->gpios[offset].flags |= pinmux_type; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 534 | |
| 535 | ret = 0; |
| 536 | err_unlock: |
| 537 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 538 | err_out: |
| 539 | return ret; |
| 540 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 541 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 542 | static void sh_gpio_free(struct gpio_chip *chip, unsigned offset) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 543 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 544 | struct pinmux_info *gpioc = chip_to_pinmux(chip); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 545 | unsigned long flags; |
| 546 | int pinmux_type; |
| 547 | |
| 548 | if (!gpioc) |
| 549 | return; |
| 550 | |
| 551 | spin_lock_irqsave(&gpio_lock, flags); |
| 552 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 553 | pinmux_type = gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE; |
| 554 | pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_FREE); |
| 555 | gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; |
| 556 | gpioc->gpios[offset].flags |= PINMUX_TYPE_NONE; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 557 | |
| 558 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 559 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 560 | |
| 561 | static int pinmux_direction(struct pinmux_info *gpioc, |
| 562 | unsigned gpio, int new_pinmux_type) |
| 563 | { |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 564 | int pinmux_type; |
| 565 | int ret = -EINVAL; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 566 | |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 567 | if (!gpioc) |
| 568 | goto err_out; |
| 569 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 570 | pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE; |
| 571 | |
| 572 | switch (pinmux_type) { |
| 573 | case PINMUX_TYPE_GPIO: |
| 574 | break; |
| 575 | case PINMUX_TYPE_OUTPUT: |
| 576 | case PINMUX_TYPE_INPUT: |
| 577 | case PINMUX_TYPE_INPUT_PULLUP: |
| 578 | case PINMUX_TYPE_INPUT_PULLDOWN: |
| 579 | pinmux_config_gpio(gpioc, gpio, pinmux_type, GPIO_CFG_FREE); |
| 580 | break; |
| 581 | default: |
| 582 | goto err_out; |
| 583 | } |
| 584 | |
| 585 | if (pinmux_config_gpio(gpioc, gpio, |
| 586 | new_pinmux_type, |
| 587 | GPIO_CFG_DRYRUN) != 0) |
| 588 | goto err_out; |
| 589 | |
| 590 | if (pinmux_config_gpio(gpioc, gpio, |
| 591 | new_pinmux_type, |
| 592 | GPIO_CFG_REQ) != 0) |
| 593 | BUG(); |
| 594 | |
Magnus Damm | 18801be | 2008-12-25 18:17:09 +0900 | [diff] [blame] | 595 | gpioc->gpios[gpio].flags &= ~PINMUX_FLAG_TYPE; |
| 596 | gpioc->gpios[gpio].flags |= new_pinmux_type; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 597 | |
| 598 | ret = 0; |
| 599 | err_out: |
| 600 | return ret; |
| 601 | } |
| 602 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 603 | static int sh_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 604 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 605 | struct pinmux_info *gpioc = chip_to_pinmux(chip); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 606 | unsigned long flags; |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 607 | int ret; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 608 | |
| 609 | spin_lock_irqsave(&gpio_lock, flags); |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 610 | ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_INPUT); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 611 | spin_unlock_irqrestore(&gpio_lock, flags); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 612 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 613 | return ret; |
| 614 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 615 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 616 | static void sh_gpio_set_value(struct pinmux_info *gpioc, |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 617 | unsigned gpio, int value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 618 | { |
| 619 | struct pinmux_data_reg *dr = NULL; |
| 620 | int bit = 0; |
| 621 | |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 622 | if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 623 | BUG(); |
| 624 | else |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 625 | gpio_write_bit(dr, bit, value); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 626 | } |
| 627 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 628 | static int sh_gpio_direction_output(struct gpio_chip *chip, unsigned offset, |
| 629 | int value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 630 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 631 | struct pinmux_info *gpioc = chip_to_pinmux(chip); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 632 | unsigned long flags; |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 633 | int ret; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 634 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 635 | sh_gpio_set_value(gpioc, offset, value); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 636 | spin_lock_irqsave(&gpio_lock, flags); |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 637 | ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_OUTPUT); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 638 | spin_unlock_irqrestore(&gpio_lock, flags); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 639 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 640 | return ret; |
| 641 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 642 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 643 | static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 644 | { |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 645 | struct pinmux_data_reg *dr = NULL; |
| 646 | int bit = 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 647 | |
Paul Mundt | e8184a4 | 2010-10-04 05:15:20 +0900 | [diff] [blame] | 648 | if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0) |
| 649 | return -EINVAL; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 650 | |
Magnus Damm | 92554d9 | 2011-12-14 01:00:37 +0900 | [diff] [blame] | 651 | return gpio_read_bit(dr, bit); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 652 | } |
| 653 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 654 | static int sh_gpio_get(struct gpio_chip *chip, unsigned offset) |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 655 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 656 | return sh_gpio_get_value(chip_to_pinmux(chip), offset); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 657 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 658 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 659 | static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 660 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 661 | sh_gpio_set_value(chip_to_pinmux(chip), offset, value); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 662 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 663 | |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 664 | static int sh_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
| 665 | { |
| 666 | struct pinmux_info *gpioc = chip_to_pinmux(chip); |
| 667 | pinmux_enum_t enum_id; |
| 668 | pinmux_enum_t *enum_ids; |
| 669 | int i, k, pos; |
| 670 | |
| 671 | pos = 0; |
| 672 | enum_id = 0; |
| 673 | while (1) { |
| 674 | pos = get_gpio_enum_id(gpioc, offset, pos, &enum_id); |
| 675 | if (pos <= 0 || !enum_id) |
| 676 | break; |
| 677 | |
| 678 | for (i = 0; i < gpioc->gpio_irq_size; i++) { |
| 679 | enum_ids = gpioc->gpio_irq[i].enum_ids; |
| 680 | for (k = 0; enum_ids[k]; k++) { |
| 681 | if (enum_ids[k] == enum_id) |
| 682 | return gpioc->gpio_irq[i].irq; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | return -ENOSYS; |
| 688 | } |
| 689 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 690 | int register_pinmux(struct pinmux_info *pip) |
| 691 | { |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 692 | struct gpio_chip *chip = &pip->chip; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 693 | int ret; |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 694 | |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 695 | pr_info("%s handling gpio %d -> %d\n", |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 696 | pip->name, pip->first_gpio, pip->last_gpio); |
| 697 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 698 | ret = pfc_ioremap(pip); |
| 699 | if (ret < 0) |
| 700 | return ret; |
| 701 | |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 702 | setup_data_regs(pip); |
| 703 | |
| 704 | chip->request = sh_gpio_request; |
| 705 | chip->free = sh_gpio_free; |
| 706 | chip->direction_input = sh_gpio_direction_input; |
| 707 | chip->get = sh_gpio_get; |
| 708 | chip->direction_output = sh_gpio_direction_output; |
| 709 | chip->set = sh_gpio_set; |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 710 | chip->to_irq = sh_gpio_to_irq; |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 711 | |
| 712 | WARN_ON(pip->first_gpio != 0); /* needs testing */ |
| 713 | |
| 714 | chip->label = pip->name; |
| 715 | chip->owner = THIS_MODULE; |
| 716 | chip->base = pip->first_gpio; |
| 717 | chip->ngpio = (pip->last_gpio - pip->first_gpio) + 1; |
| 718 | |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 719 | ret = gpiochip_add(chip); |
| 720 | if (ret < 0) |
| 721 | pfc_iounmap(pip); |
| 722 | |
| 723 | return ret; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 724 | } |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 725 | |
| 726 | int unregister_pinmux(struct pinmux_info *pip) |
| 727 | { |
| 728 | pr_info("%s deregistering\n", pip->name); |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 729 | pfc_iounmap(pip); |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 730 | return gpiochip_remove(&pip->chip); |
| 731 | } |