Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Pin Function Controller GPIO driver. |
| 3 | * |
| 4 | * Copyright (C) 2008 Magnus Damm |
| 5 | * Copyright (C) 2009 - 2012 Paul Mundt |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file "COPYING" in the main directory of this archive |
| 9 | * for more details. |
| 10 | */ |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 11 | |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 13 | |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 14 | #include <linux/device.h> |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 15 | #include <linux/gpio.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 16 | #include <linux/init.h> |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 17 | #include <linux/module.h> |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 18 | #include <linux/pinctrl/consumer.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/spinlock.h> |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 21 | |
Laurent Pinchart | f916513 | 2012-12-15 23:50:44 +0100 | [diff] [blame] | 22 | #include "core.h" |
| 23 | |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 24 | struct sh_pfc_chip { |
| 25 | struct sh_pfc *pfc; |
| 26 | struct gpio_chip gpio_chip; |
| 27 | }; |
| 28 | |
| 29 | static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc) |
| 30 | { |
| 31 | return container_of(gc, struct sh_pfc_chip, gpio_chip); |
| 32 | } |
| 33 | |
| 34 | static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc) |
| 35 | { |
| 36 | return gpio_to_pfc_chip(gc)->pfc; |
| 37 | } |
| 38 | |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 39 | static void gpio_get_data_reg(struct sh_pfc *pfc, unsigned int gpio, |
| 40 | struct pinmux_data_reg **dr, unsigned int *bit) |
| 41 | { |
| 42 | struct sh_pfc_pin *gpiop = sh_pfc_get_pin(pfc, gpio); |
| 43 | |
| 44 | *dr = pfc->info->data_regs |
| 45 | + ((gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT); |
| 46 | *bit = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; |
| 47 | } |
| 48 | |
| 49 | static void gpio_setup_data_reg(struct sh_pfc *pfc, unsigned gpio) |
| 50 | { |
| 51 | struct sh_pfc_pin *gpiop = &pfc->info->pins[gpio]; |
| 52 | struct pinmux_data_reg *data_reg; |
| 53 | int k, n; |
| 54 | |
| 55 | k = 0; |
| 56 | while (1) { |
| 57 | data_reg = pfc->info->data_regs + k; |
| 58 | |
| 59 | if (!data_reg->reg_width) |
| 60 | break; |
| 61 | |
| 62 | data_reg->mapped_reg = sh_pfc_phys_to_virt(pfc, data_reg->reg); |
| 63 | |
| 64 | for (n = 0; n < data_reg->reg_width; n++) { |
| 65 | if (data_reg->enum_ids[n] == gpiop->enum_id) { |
| 66 | gpiop->flags &= ~PINMUX_FLAG_DREG; |
| 67 | gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT); |
| 68 | gpiop->flags &= ~PINMUX_FLAG_DBIT; |
| 69 | gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT); |
| 70 | return; |
| 71 | } |
| 72 | } |
| 73 | k++; |
| 74 | } |
| 75 | |
| 76 | BUG(); |
| 77 | } |
| 78 | |
| 79 | static void gpio_setup_data_regs(struct sh_pfc *pfc) |
| 80 | { |
| 81 | struct pinmux_data_reg *drp; |
| 82 | int k; |
| 83 | |
| 84 | for (k = 0; k < pfc->info->nr_pins; k++) { |
| 85 | if (pfc->info->pins[k].enum_id == 0) |
| 86 | continue; |
| 87 | |
| 88 | gpio_setup_data_reg(pfc, k); |
| 89 | } |
| 90 | |
| 91 | k = 0; |
| 92 | while (1) { |
| 93 | drp = pfc->info->data_regs + k; |
| 94 | |
| 95 | if (!drp->reg_width) |
| 96 | break; |
| 97 | |
| 98 | drp->reg_shadow = sh_pfc_read_raw_reg(drp->mapped_reg, |
| 99 | drp->reg_width); |
| 100 | k++; |
| 101 | } |
| 102 | } |
| 103 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 104 | /* ----------------------------------------------------------------------------- |
| 105 | * Pin GPIOs |
| 106 | */ |
| 107 | |
| 108 | static int gpio_pin_request(struct gpio_chip *gc, unsigned offset) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 109 | { |
Laurent Pinchart | 0b73ee5 | 2013-02-14 22:12:11 +0100 | [diff] [blame] | 110 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
Laurent Pinchart | 934cb02 | 2013-02-14 22:35:09 +0100 | [diff] [blame] | 111 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); |
Laurent Pinchart | 0b73ee5 | 2013-02-14 22:12:11 +0100 | [diff] [blame] | 112 | |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 113 | if (pin == NULL || pin->enum_id == 0) |
Laurent Pinchart | 0b73ee5 | 2013-02-14 22:12:11 +0100 | [diff] [blame] | 114 | return -EINVAL; |
| 115 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 116 | return pinctrl_request_gpio(offset); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 119 | static void gpio_pin_free(struct gpio_chip *gc, unsigned offset) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 120 | { |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 121 | return pinctrl_free_gpio(offset); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 122 | } |
| 123 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 124 | static void gpio_pin_set_value(struct sh_pfc *pfc, unsigned offset, int value) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 125 | { |
Laurent Pinchart | 0b73ee5 | 2013-02-14 22:12:11 +0100 | [diff] [blame] | 126 | struct pinmux_data_reg *dr; |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 127 | unsigned long pos; |
| 128 | unsigned int bit; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 129 | |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 130 | gpio_get_data_reg(pfc, offset, &dr, &bit); |
| 131 | |
| 132 | pos = dr->reg_width - (bit + 1); |
| 133 | |
| 134 | if (value) |
| 135 | set_bit(pos, &dr->reg_shadow); |
| 136 | else |
| 137 | clear_bit(pos, &dr->reg_shadow); |
| 138 | |
| 139 | sh_pfc_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 142 | static int gpio_pin_direction_input(struct gpio_chip *gc, unsigned offset) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 143 | { |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 144 | return pinctrl_gpio_direction_input(offset); |
| 145 | } |
| 146 | |
| 147 | static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset, |
| 148 | int value) |
| 149 | { |
| 150 | gpio_pin_set_value(gpio_to_pfc(gc), offset, value); |
| 151 | |
| 152 | return pinctrl_gpio_direction_output(offset); |
| 153 | } |
| 154 | |
| 155 | static int gpio_pin_get(struct gpio_chip *gc, unsigned offset) |
| 156 | { |
| 157 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
Laurent Pinchart | 0b73ee5 | 2013-02-14 22:12:11 +0100 | [diff] [blame] | 158 | struct pinmux_data_reg *dr; |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 159 | unsigned long pos; |
| 160 | unsigned int bit; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 161 | |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 162 | gpio_get_data_reg(pfc, offset, &dr, &bit); |
| 163 | |
| 164 | pos = dr->reg_width - (bit + 1); |
| 165 | |
| 166 | return (sh_pfc_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 167 | } |
| 168 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 169 | static void gpio_pin_set(struct gpio_chip *gc, unsigned offset, int value) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 170 | { |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 171 | gpio_pin_set_value(gpio_to_pfc(gc), offset, value); |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 172 | } |
| 173 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 174 | static int gpio_pin_to_irq(struct gpio_chip *gc, unsigned offset) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 175 | { |
| 176 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
Laurent Pinchart | c07f54f | 2013-01-03 14:12:14 +0100 | [diff] [blame] | 177 | int i, k; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 178 | |
Laurent Pinchart | c07f54f | 2013-01-03 14:12:14 +0100 | [diff] [blame] | 179 | for (i = 0; i < pfc->info->gpio_irq_size; i++) { |
| 180 | unsigned short *gpios = pfc->info->gpio_irq[i].gpios; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 181 | |
Laurent Pinchart | c07f54f | 2013-01-03 14:12:14 +0100 | [diff] [blame] | 182 | for (k = 0; gpios[k]; k++) { |
| 183 | if (gpios[k] == offset) |
| 184 | return pfc->info->gpio_irq[i].irq; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | return -ENOSYS; |
| 189 | } |
| 190 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 191 | static void gpio_pin_setup(struct sh_pfc_chip *chip) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 192 | { |
| 193 | struct sh_pfc *pfc = chip->pfc; |
| 194 | struct gpio_chip *gc = &chip->gpio_chip; |
| 195 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 196 | gc->request = gpio_pin_request; |
| 197 | gc->free = gpio_pin_free; |
| 198 | gc->direction_input = gpio_pin_direction_input; |
| 199 | gc->get = gpio_pin_get; |
| 200 | gc->direction_output = gpio_pin_direction_output; |
| 201 | gc->set = gpio_pin_set; |
| 202 | gc->to_irq = gpio_pin_to_irq; |
| 203 | |
| 204 | gc->label = pfc->info->name; |
| 205 | gc->dev = pfc->dev; |
| 206 | gc->owner = THIS_MODULE; |
| 207 | gc->base = 0; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 208 | gc->ngpio = pfc->nr_pins; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* ----------------------------------------------------------------------------- |
| 212 | * Function GPIOs |
| 213 | */ |
| 214 | |
| 215 | static int gpio_function_request(struct gpio_chip *gc, unsigned offset) |
| 216 | { |
| 217 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 218 | unsigned int mark = pfc->info->func_gpios[offset].enum_id; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 219 | unsigned long flags; |
| 220 | int ret = -EINVAL; |
| 221 | |
| 222 | pr_notice_once("Use of GPIO API for function requests is deprecated, convert to pinctrl\n"); |
| 223 | |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 224 | if (mark == 0) |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 225 | return ret; |
| 226 | |
| 227 | spin_lock_irqsave(&pfc->lock, flags); |
| 228 | |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 229 | if (sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_DRYRUN)) |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 230 | goto done; |
| 231 | |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 232 | if (sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_REQ)) |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 233 | goto done; |
| 234 | |
| 235 | ret = 0; |
| 236 | |
| 237 | done: |
| 238 | spin_unlock_irqrestore(&pfc->lock, flags); |
| 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | static void gpio_function_free(struct gpio_chip *gc, unsigned offset) |
| 243 | { |
| 244 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 245 | unsigned int mark = pfc->info->func_gpios[offset].enum_id; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 246 | unsigned long flags; |
| 247 | |
| 248 | spin_lock_irqsave(&pfc->lock, flags); |
| 249 | |
Laurent Pinchart | a68fdca | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 250 | sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_FREE); |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 251 | |
| 252 | spin_unlock_irqrestore(&pfc->lock, flags); |
| 253 | } |
| 254 | |
| 255 | static void gpio_function_setup(struct sh_pfc_chip *chip) |
| 256 | { |
| 257 | struct sh_pfc *pfc = chip->pfc; |
| 258 | struct gpio_chip *gc = &chip->gpio_chip; |
| 259 | |
| 260 | gc->request = gpio_function_request; |
| 261 | gc->free = gpio_function_free; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 262 | |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 263 | gc->label = pfc->info->name; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 264 | gc->owner = THIS_MODULE; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 265 | gc->base = pfc->nr_pins; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 266 | gc->ngpio = pfc->info->nr_func_gpios; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 267 | } |
| 268 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 269 | /* ----------------------------------------------------------------------------- |
| 270 | * Register/unregister |
| 271 | */ |
| 272 | |
| 273 | static struct sh_pfc_chip * |
| 274 | sh_pfc_add_gpiochip(struct sh_pfc *pfc, void(*setup)(struct sh_pfc_chip *)) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 275 | { |
| 276 | struct sh_pfc_chip *chip; |
| 277 | int ret; |
| 278 | |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 279 | chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 280 | if (unlikely(!chip)) |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 281 | return ERR_PTR(-ENOMEM); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 282 | |
| 283 | chip->pfc = pfc; |
| 284 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 285 | setup(chip); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 286 | |
| 287 | ret = gpiochip_add(&chip->gpio_chip); |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 288 | if (unlikely(ret < 0)) |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 289 | return ERR_PTR(ret); |
| 290 | |
| 291 | pr_info("%s handling gpio %u -> %u\n", |
| 292 | chip->gpio_chip.label, chip->gpio_chip.base, |
| 293 | chip->gpio_chip.base + chip->gpio_chip.ngpio - 1); |
| 294 | |
| 295 | return chip; |
| 296 | } |
| 297 | |
| 298 | int sh_pfc_register_gpiochip(struct sh_pfc *pfc) |
| 299 | { |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 300 | const struct pinmux_range *ranges; |
| 301 | struct pinmux_range def_range; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 302 | struct sh_pfc_chip *chip; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 303 | unsigned int nr_ranges; |
| 304 | unsigned int i; |
Laurent Pinchart | 247127f | 2013-03-08 00:45:12 +0100 | [diff] [blame] | 305 | int ret; |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 306 | |
Laurent Pinchart | 41f1219 | 2013-02-15 02:04:55 +0100 | [diff] [blame^] | 307 | gpio_setup_data_regs(pfc); |
| 308 | |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 309 | /* Register the real GPIOs chip. */ |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 310 | chip = sh_pfc_add_gpiochip(pfc, gpio_pin_setup); |
| 311 | if (IS_ERR(chip)) |
| 312 | return PTR_ERR(chip); |
Laurent Pinchart | 6f6a4a6 | 2012-12-15 23:50:46 +0100 | [diff] [blame] | 313 | |
| 314 | pfc->gpio = chip; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 315 | |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 316 | /* Register the GPIO to pin mappings. */ |
| 317 | if (pfc->info->ranges == NULL) { |
| 318 | def_range.begin = 0; |
| 319 | def_range.end = pfc->info->nr_pins - 1; |
| 320 | ranges = &def_range; |
| 321 | nr_ranges = 1; |
| 322 | } else { |
| 323 | ranges = pfc->info->ranges; |
| 324 | nr_ranges = pfc->info->nr_ranges; |
| 325 | } |
Laurent Pinchart | 247127f | 2013-03-08 00:45:12 +0100 | [diff] [blame] | 326 | |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 327 | for (i = 0; i < nr_ranges; ++i) { |
| 328 | const struct pinmux_range *range = &ranges[i]; |
| 329 | |
| 330 | ret = gpiochip_add_pin_range(&chip->gpio_chip, |
| 331 | dev_name(pfc->dev), |
| 332 | range->begin, range->begin, |
| 333 | range->end - range->begin + 1); |
| 334 | if (ret < 0) |
| 335 | return ret; |
| 336 | } |
| 337 | |
| 338 | /* Register the function GPIOs chip. */ |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 339 | chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup); |
| 340 | if (IS_ERR(chip)) |
| 341 | return PTR_ERR(chip); |
| 342 | |
| 343 | pfc->func = chip; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 344 | |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Laurent Pinchart | 6f6a4a6 | 2012-12-15 23:50:46 +0100 | [diff] [blame] | 348 | int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 349 | { |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 350 | int err; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 351 | int ret; |
| 352 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 353 | ret = gpiochip_remove(&pfc->gpio->gpio_chip); |
| 354 | err = gpiochip_remove(&pfc->func->gpio_chip); |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 355 | |
Laurent Pinchart | 1688381 | 2012-12-06 14:49:25 +0100 | [diff] [blame] | 356 | return ret < 0 ? ret : err; |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 357 | } |