Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Allwinner A1X SoCs pinctrl driver. |
| 3 | * |
| 4 | * Copyright (C) 2012 Maxime Ripard |
| 5 | * |
| 6 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/io.h> |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 14 | #include <linux/clk.h> |
Linus Walleij | 88057d6 | 2015-12-08 22:40:43 +0100 | [diff] [blame] | 15 | #include <linux/gpio/driver.h> |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 16 | #include <linux/irqdomain.h> |
Chen-Yu Tsai | 905a511 | 2014-02-11 00:22:37 +0800 | [diff] [blame] | 17 | #include <linux/irqchip/chained_irq.h> |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/of.h> |
| 20 | #include <linux/of_address.h> |
| 21 | #include <linux/of_device.h> |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 22 | #include <linux/of_irq.h> |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 23 | #include <linux/pinctrl/consumer.h> |
| 24 | #include <linux/pinctrl/machine.h> |
| 25 | #include <linux/pinctrl/pinctrl.h> |
| 26 | #include <linux/pinctrl/pinconf-generic.h> |
| 27 | #include <linux/pinctrl/pinmux.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/slab.h> |
| 30 | |
Maxime Ripard | 5f91077 | 2014-04-18 18:53:02 +0200 | [diff] [blame] | 31 | #include "../core.h" |
Hans de Goede | ef6d24c | 2015-03-08 22:13:57 +0100 | [diff] [blame] | 32 | #include "../../gpio/gpiolib.h" |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 33 | #include "pinctrl-sunxi.h" |
Maxime Ripard | eaa3d84 | 2013-01-18 22:30:35 +0100 | [diff] [blame] | 34 | |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 35 | static struct irq_chip sunxi_pinctrl_edge_irq_chip; |
| 36 | static struct irq_chip sunxi_pinctrl_level_irq_chip; |
| 37 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 38 | static struct sunxi_pinctrl_group * |
| 39 | sunxi_pinctrl_find_group_by_name(struct sunxi_pinctrl *pctl, const char *group) |
| 40 | { |
| 41 | int i; |
| 42 | |
| 43 | for (i = 0; i < pctl->ngroups; i++) { |
| 44 | struct sunxi_pinctrl_group *grp = pctl->groups + i; |
| 45 | |
| 46 | if (!strcmp(grp->name, group)) |
| 47 | return grp; |
| 48 | } |
| 49 | |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | static struct sunxi_pinctrl_function * |
| 54 | sunxi_pinctrl_find_function_by_name(struct sunxi_pinctrl *pctl, |
| 55 | const char *name) |
| 56 | { |
| 57 | struct sunxi_pinctrl_function *func = pctl->functions; |
| 58 | int i; |
| 59 | |
| 60 | for (i = 0; i < pctl->nfunctions; i++) { |
| 61 | if (!func[i].name) |
| 62 | break; |
| 63 | |
| 64 | if (!strcmp(func[i].name, name)) |
| 65 | return func + i; |
| 66 | } |
| 67 | |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | static struct sunxi_desc_function * |
| 72 | sunxi_pinctrl_desc_find_function_by_name(struct sunxi_pinctrl *pctl, |
| 73 | const char *pin_name, |
| 74 | const char *func_name) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | for (i = 0; i < pctl->desc->npins; i++) { |
| 79 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 80 | |
| 81 | if (!strcmp(pin->pin.name, pin_name)) { |
| 82 | struct sunxi_desc_function *func = pin->functions; |
| 83 | |
| 84 | while (func->name) { |
| 85 | if (!strcmp(func->name, func_name)) |
| 86 | return func; |
| 87 | |
| 88 | func++; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return NULL; |
| 94 | } |
| 95 | |
Maxime Ripard | 814d4f2 | 2013-06-08 12:05:43 +0200 | [diff] [blame] | 96 | static struct sunxi_desc_function * |
| 97 | sunxi_pinctrl_desc_find_function_by_pin(struct sunxi_pinctrl *pctl, |
| 98 | const u16 pin_num, |
| 99 | const char *func_name) |
| 100 | { |
| 101 | int i; |
| 102 | |
| 103 | for (i = 0; i < pctl->desc->npins; i++) { |
| 104 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 105 | |
| 106 | if (pin->pin.number == pin_num) { |
| 107 | struct sunxi_desc_function *func = pin->functions; |
| 108 | |
| 109 | while (func->name) { |
| 110 | if (!strcmp(func->name, func_name)) |
| 111 | return func; |
| 112 | |
| 113 | func++; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return NULL; |
| 119 | } |
| 120 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 121 | static int sunxi_pctrl_get_groups_count(struct pinctrl_dev *pctldev) |
| 122 | { |
| 123 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 124 | |
| 125 | return pctl->ngroups; |
| 126 | } |
| 127 | |
| 128 | static const char *sunxi_pctrl_get_group_name(struct pinctrl_dev *pctldev, |
| 129 | unsigned group) |
| 130 | { |
| 131 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 132 | |
| 133 | return pctl->groups[group].name; |
| 134 | } |
| 135 | |
| 136 | static int sunxi_pctrl_get_group_pins(struct pinctrl_dev *pctldev, |
| 137 | unsigned group, |
| 138 | const unsigned **pins, |
| 139 | unsigned *num_pins) |
| 140 | { |
| 141 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 142 | |
| 143 | *pins = (unsigned *)&pctl->groups[group].pin; |
| 144 | *num_pins = 1; |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 150 | struct device_node *node, |
| 151 | struct pinctrl_map **map, |
| 152 | unsigned *num_maps) |
| 153 | { |
| 154 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 155 | unsigned long *pinconfig; |
| 156 | struct property *prop; |
| 157 | const char *function; |
| 158 | const char *group; |
| 159 | int ret, nmaps, i = 0; |
| 160 | u32 val; |
| 161 | |
| 162 | *map = NULL; |
| 163 | *num_maps = 0; |
| 164 | |
| 165 | ret = of_property_read_string(node, "allwinner,function", &function); |
| 166 | if (ret) { |
| 167 | dev_err(pctl->dev, |
| 168 | "missing allwinner,function property in node %s\n", |
| 169 | node->name); |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | |
| 173 | nmaps = of_property_count_strings(node, "allwinner,pins") * 2; |
| 174 | if (nmaps < 0) { |
| 175 | dev_err(pctl->dev, |
| 176 | "missing allwinner,pins property in node %s\n", |
| 177 | node->name); |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL); |
Sachin Kamat | 3efa921 | 2013-07-29 13:49:32 +0530 | [diff] [blame] | 182 | if (!*map) |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 183 | return -ENOMEM; |
| 184 | |
| 185 | of_property_for_each_string(node, "allwinner,pins", prop, group) { |
| 186 | struct sunxi_pinctrl_group *grp = |
| 187 | sunxi_pinctrl_find_group_by_name(pctl, group); |
| 188 | int j = 0, configlen = 0; |
| 189 | |
| 190 | if (!grp) { |
| 191 | dev_err(pctl->dev, "unknown pin %s", group); |
| 192 | continue; |
| 193 | } |
| 194 | |
| 195 | if (!sunxi_pinctrl_desc_find_function_by_name(pctl, |
| 196 | grp->name, |
| 197 | function)) { |
| 198 | dev_err(pctl->dev, "unsupported function %s on pin %s", |
| 199 | function, group); |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | (*map)[i].type = PIN_MAP_TYPE_MUX_GROUP; |
| 204 | (*map)[i].data.mux.group = group; |
| 205 | (*map)[i].data.mux.function = function; |
| 206 | |
| 207 | i++; |
| 208 | |
| 209 | (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP; |
| 210 | (*map)[i].data.configs.group_or_pin = group; |
| 211 | |
| 212 | if (of_find_property(node, "allwinner,drive", NULL)) |
| 213 | configlen++; |
| 214 | if (of_find_property(node, "allwinner,pull", NULL)) |
| 215 | configlen++; |
| 216 | |
| 217 | pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL); |
Sachin Kamat | bd07894 | 2014-05-30 15:50:52 +0530 | [diff] [blame] | 218 | if (!pinconfig) { |
| 219 | kfree(*map); |
| 220 | return -ENOMEM; |
| 221 | } |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 222 | |
| 223 | if (!of_property_read_u32(node, "allwinner,drive", &val)) { |
| 224 | u16 strength = (val + 1) * 10; |
| 225 | pinconfig[j++] = |
| 226 | pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, |
| 227 | strength); |
| 228 | } |
| 229 | |
| 230 | if (!of_property_read_u32(node, "allwinner,pull", &val)) { |
| 231 | enum pin_config_param pull = PIN_CONFIG_END; |
| 232 | if (val == 1) |
| 233 | pull = PIN_CONFIG_BIAS_PULL_UP; |
| 234 | else if (val == 2) |
| 235 | pull = PIN_CONFIG_BIAS_PULL_DOWN; |
| 236 | pinconfig[j++] = pinconf_to_config_packed(pull, 0); |
| 237 | } |
| 238 | |
| 239 | (*map)[i].data.configs.configs = pinconfig; |
| 240 | (*map)[i].data.configs.num_configs = configlen; |
| 241 | |
| 242 | i++; |
| 243 | } |
| 244 | |
| 245 | *num_maps = nmaps; |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static void sunxi_pctrl_dt_free_map(struct pinctrl_dev *pctldev, |
| 251 | struct pinctrl_map *map, |
| 252 | unsigned num_maps) |
| 253 | { |
| 254 | int i; |
| 255 | |
| 256 | for (i = 0; i < num_maps; i++) { |
| 257 | if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) |
| 258 | kfree(map[i].data.configs.configs); |
| 259 | } |
| 260 | |
| 261 | kfree(map); |
| 262 | } |
| 263 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 264 | static const struct pinctrl_ops sunxi_pctrl_ops = { |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 265 | .dt_node_to_map = sunxi_pctrl_dt_node_to_map, |
| 266 | .dt_free_map = sunxi_pctrl_dt_free_map, |
| 267 | .get_groups_count = sunxi_pctrl_get_groups_count, |
| 268 | .get_group_name = sunxi_pctrl_get_group_name, |
| 269 | .get_group_pins = sunxi_pctrl_get_group_pins, |
| 270 | }; |
| 271 | |
| 272 | static int sunxi_pconf_group_get(struct pinctrl_dev *pctldev, |
| 273 | unsigned group, |
| 274 | unsigned long *config) |
| 275 | { |
| 276 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 277 | |
| 278 | *config = pctl->groups[group].config; |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev, |
| 284 | unsigned group, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 285 | unsigned long *configs, |
| 286 | unsigned num_configs) |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 287 | { |
| 288 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 289 | struct sunxi_pinctrl_group *g = &pctl->groups[group]; |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 290 | unsigned long flags; |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 291 | unsigned pin = g->pin - pctl->desc->pin_base; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 292 | u32 val, mask; |
| 293 | u16 strength; |
| 294 | u8 dlevel; |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 295 | int i; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 296 | |
Linus Walleij | 6ad30ce | 2013-08-29 09:46:30 +0200 | [diff] [blame] | 297 | spin_lock_irqsave(&pctl->lock, flags); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 298 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 299 | for (i = 0; i < num_configs; i++) { |
| 300 | switch (pinconf_to_config_param(configs[i])) { |
| 301 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 302 | strength = pinconf_to_config_argument(configs[i]); |
Linus Walleij | 07b7eb9 | 2013-08-29 19:17:13 +0200 | [diff] [blame] | 303 | if (strength > 40) { |
| 304 | spin_unlock_irqrestore(&pctl->lock, flags); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 305 | return -EINVAL; |
Linus Walleij | 07b7eb9 | 2013-08-29 19:17:13 +0200 | [diff] [blame] | 306 | } |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 307 | /* |
| 308 | * We convert from mA to what the register expects: |
| 309 | * 0: 10mA |
| 310 | * 1: 20mA |
| 311 | * 2: 30mA |
| 312 | * 3: 40mA |
| 313 | */ |
| 314 | dlevel = strength / 10 - 1; |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 315 | val = readl(pctl->membase + sunxi_dlevel_reg(pin)); |
| 316 | mask = DLEVEL_PINS_MASK << sunxi_dlevel_offset(pin); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 317 | writel((val & ~mask) |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 318 | | dlevel << sunxi_dlevel_offset(pin), |
| 319 | pctl->membase + sunxi_dlevel_reg(pin)); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 320 | break; |
| 321 | case PIN_CONFIG_BIAS_PULL_UP: |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 322 | val = readl(pctl->membase + sunxi_pull_reg(pin)); |
| 323 | mask = PULL_PINS_MASK << sunxi_pull_offset(pin); |
| 324 | writel((val & ~mask) | 1 << sunxi_pull_offset(pin), |
| 325 | pctl->membase + sunxi_pull_reg(pin)); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 326 | break; |
| 327 | case PIN_CONFIG_BIAS_PULL_DOWN: |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 328 | val = readl(pctl->membase + sunxi_pull_reg(pin)); |
| 329 | mask = PULL_PINS_MASK << sunxi_pull_offset(pin); |
| 330 | writel((val & ~mask) | 2 << sunxi_pull_offset(pin), |
| 331 | pctl->membase + sunxi_pull_reg(pin)); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 332 | break; |
| 333 | default: |
| 334 | break; |
| 335 | } |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 336 | /* cache the config value */ |
| 337 | g->config = configs[i]; |
| 338 | } /* for each config */ |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 339 | |
Linus Walleij | 6ad30ce | 2013-08-29 09:46:30 +0200 | [diff] [blame] | 340 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 345 | static const struct pinconf_ops sunxi_pconf_ops = { |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 346 | .pin_config_group_get = sunxi_pconf_group_get, |
| 347 | .pin_config_group_set = sunxi_pconf_group_set, |
| 348 | }; |
| 349 | |
| 350 | static int sunxi_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) |
| 351 | { |
| 352 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 353 | |
| 354 | return pctl->nfunctions; |
| 355 | } |
| 356 | |
| 357 | static const char *sunxi_pmx_get_func_name(struct pinctrl_dev *pctldev, |
| 358 | unsigned function) |
| 359 | { |
| 360 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 361 | |
| 362 | return pctl->functions[function].name; |
| 363 | } |
| 364 | |
| 365 | static int sunxi_pmx_get_func_groups(struct pinctrl_dev *pctldev, |
| 366 | unsigned function, |
| 367 | const char * const **groups, |
| 368 | unsigned * const num_groups) |
| 369 | { |
| 370 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 371 | |
| 372 | *groups = pctl->functions[function].groups; |
| 373 | *num_groups = pctl->functions[function].ngroups; |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static void sunxi_pmx_set(struct pinctrl_dev *pctldev, |
| 379 | unsigned pin, |
| 380 | u8 config) |
| 381 | { |
| 382 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 383 | unsigned long flags; |
| 384 | u32 val, mask; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 385 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 386 | spin_lock_irqsave(&pctl->lock, flags); |
| 387 | |
Chen-Yu Tsai | b4575c6 | 2014-05-22 23:20:55 +0800 | [diff] [blame] | 388 | pin -= pctl->desc->pin_base; |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 389 | val = readl(pctl->membase + sunxi_mux_reg(pin)); |
| 390 | mask = MUX_PINS_MASK << sunxi_mux_offset(pin); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 391 | writel((val & ~mask) | config << sunxi_mux_offset(pin), |
| 392 | pctl->membase + sunxi_mux_reg(pin)); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 393 | |
| 394 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 397 | static int sunxi_pmx_set_mux(struct pinctrl_dev *pctldev, |
| 398 | unsigned function, |
| 399 | unsigned group) |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 400 | { |
| 401 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 402 | struct sunxi_pinctrl_group *g = pctl->groups + group; |
| 403 | struct sunxi_pinctrl_function *func = pctl->functions + function; |
| 404 | struct sunxi_desc_function *desc = |
| 405 | sunxi_pinctrl_desc_find_function_by_name(pctl, |
| 406 | g->name, |
| 407 | func->name); |
| 408 | |
| 409 | if (!desc) |
| 410 | return -EINVAL; |
| 411 | |
| 412 | sunxi_pmx_set(pctldev, g->pin, desc->muxval); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 417 | static int |
| 418 | sunxi_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 419 | struct pinctrl_gpio_range *range, |
| 420 | unsigned offset, |
| 421 | bool input) |
| 422 | { |
| 423 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 424 | struct sunxi_desc_function *desc; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 425 | const char *func; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 426 | |
| 427 | if (input) |
| 428 | func = "gpio_in"; |
| 429 | else |
| 430 | func = "gpio_out"; |
| 431 | |
Maxime Ripard | 814d4f2 | 2013-06-08 12:05:43 +0200 | [diff] [blame] | 432 | desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, offset, func); |
| 433 | if (!desc) |
| 434 | return -EINVAL; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 435 | |
| 436 | sunxi_pmx_set(pctldev, offset, desc->muxval); |
| 437 | |
Maxime Ripard | 814d4f2 | 2013-06-08 12:05:43 +0200 | [diff] [blame] | 438 | return 0; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 441 | static const struct pinmux_ops sunxi_pmx_ops = { |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 442 | .get_functions_count = sunxi_pmx_get_funcs_cnt, |
| 443 | .get_function_name = sunxi_pmx_get_func_name, |
| 444 | .get_function_groups = sunxi_pmx_get_func_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 445 | .set_mux = sunxi_pmx_set_mux, |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 446 | .gpio_set_direction = sunxi_pmx_gpio_set_direction, |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 447 | }; |
| 448 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 449 | static int sunxi_pinctrl_gpio_direction_input(struct gpio_chip *chip, |
| 450 | unsigned offset) |
| 451 | { |
| 452 | return pinctrl_gpio_direction_input(chip->base + offset); |
| 453 | } |
| 454 | |
| 455 | static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 456 | { |
Linus Walleij | 88057d6 | 2015-12-08 22:40:43 +0100 | [diff] [blame] | 457 | struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 458 | u32 reg = sunxi_data_reg(offset); |
| 459 | u8 index = sunxi_data_offset(offset); |
Hans de Goede | ef6d24c | 2015-03-08 22:13:57 +0100 | [diff] [blame] | 460 | u32 set_mux = pctl->desc->irq_read_needs_mux && |
| 461 | test_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); |
Krzysztof Adamski | be2d107 | 2016-02-09 15:58:49 +0100 | [diff] [blame^] | 462 | u32 pin = offset + chip->base; |
Hans de Goede | ef6d24c | 2015-03-08 22:13:57 +0100 | [diff] [blame] | 463 | u32 val; |
| 464 | |
| 465 | if (set_mux) |
Krzysztof Adamski | be2d107 | 2016-02-09 15:58:49 +0100 | [diff] [blame^] | 466 | sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_INPUT); |
Hans de Goede | ef6d24c | 2015-03-08 22:13:57 +0100 | [diff] [blame] | 467 | |
| 468 | val = (readl(pctl->membase + reg) >> index) & DATA_PINS_MASK; |
| 469 | |
| 470 | if (set_mux) |
Krzysztof Adamski | be2d107 | 2016-02-09 15:58:49 +0100 | [diff] [blame^] | 471 | sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_IRQ); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 472 | |
Linus Walleij | 39e24ac | 2015-12-21 16:40:27 +0100 | [diff] [blame] | 473 | return !!val; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 476 | static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip, |
| 477 | unsigned offset, int value) |
| 478 | { |
Linus Walleij | 88057d6 | 2015-12-08 22:40:43 +0100 | [diff] [blame] | 479 | struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 480 | u32 reg = sunxi_data_reg(offset); |
| 481 | u8 index = sunxi_data_offset(offset); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 482 | unsigned long flags; |
| 483 | u32 regval; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 484 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 485 | spin_lock_irqsave(&pctl->lock, flags); |
| 486 | |
| 487 | regval = readl(pctl->membase + reg); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 488 | |
Maxime Ripard | df7b34f | 2013-07-25 12:41:16 +0200 | [diff] [blame] | 489 | if (value) |
| 490 | regval |= BIT(index); |
| 491 | else |
| 492 | regval &= ~(BIT(index)); |
| 493 | |
| 494 | writel(regval, pctl->membase + reg); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 495 | |
| 496 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Chen-Yu Tsai | fa8cf57 | 2014-01-16 14:34:23 +0800 | [diff] [blame] | 499 | static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip, |
| 500 | unsigned offset, int value) |
| 501 | { |
| 502 | sunxi_pinctrl_gpio_set(chip, offset, value); |
| 503 | return pinctrl_gpio_direction_output(chip->base + offset); |
| 504 | } |
| 505 | |
Maxime Ripard | a0d7209 | 2013-02-03 12:10:11 +0100 | [diff] [blame] | 506 | static int sunxi_pinctrl_gpio_of_xlate(struct gpio_chip *gc, |
| 507 | const struct of_phandle_args *gpiospec, |
| 508 | u32 *flags) |
| 509 | { |
| 510 | int pin, base; |
| 511 | |
| 512 | base = PINS_PER_BANK * gpiospec->args[0]; |
| 513 | pin = base + gpiospec->args[1]; |
| 514 | |
Chen-Yu Tsai | 343f132 | 2014-07-15 01:24:37 +0800 | [diff] [blame] | 515 | if (pin > gc->ngpio) |
Maxime Ripard | a0d7209 | 2013-02-03 12:10:11 +0100 | [diff] [blame] | 516 | return -EINVAL; |
| 517 | |
| 518 | if (flags) |
| 519 | *flags = gpiospec->args[2]; |
| 520 | |
| 521 | return pin; |
| 522 | } |
| 523 | |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 524 | static int sunxi_pinctrl_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
| 525 | { |
Linus Walleij | 88057d6 | 2015-12-08 22:40:43 +0100 | [diff] [blame] | 526 | struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 527 | struct sunxi_desc_function *desc; |
Chen-Yu Tsai | 343f132 | 2014-07-15 01:24:37 +0800 | [diff] [blame] | 528 | unsigned pinnum = pctl->desc->pin_base + offset; |
Chen-Yu Tsai | 0d3bafa | 2014-07-01 00:04:59 +0800 | [diff] [blame] | 529 | unsigned irqnum; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 530 | |
Axel Lin | c9e3b2d | 2013-08-30 16:31:25 +0800 | [diff] [blame] | 531 | if (offset >= chip->ngpio) |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 532 | return -ENXIO; |
| 533 | |
Chen-Yu Tsai | 343f132 | 2014-07-15 01:24:37 +0800 | [diff] [blame] | 534 | desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, pinnum, "irq"); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 535 | if (!desc) |
| 536 | return -EINVAL; |
| 537 | |
Chen-Yu Tsai | 0d3bafa | 2014-07-01 00:04:59 +0800 | [diff] [blame] | 538 | irqnum = desc->irqbank * IRQ_PER_BANK + desc->irqnum; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 539 | |
Linus Walleij | 58383c7 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 540 | dev_dbg(chip->parent, "%s: request IRQ for GPIO %d, return %d\n", |
Chen-Yu Tsai | 0d3bafa | 2014-07-01 00:04:59 +0800 | [diff] [blame] | 541 | chip->label, offset + chip->base, irqnum); |
| 542 | |
| 543 | return irq_find_mapping(pctl->domain, irqnum); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 544 | } |
| 545 | |
Hans de Goede | fea6d8e | 2014-06-29 16:11:00 +0200 | [diff] [blame] | 546 | static int sunxi_pinctrl_irq_request_resources(struct irq_data *d) |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 547 | { |
| 548 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
Hans de Goede | fea6d8e | 2014-06-29 16:11:00 +0200 | [diff] [blame] | 549 | struct sunxi_desc_function *func; |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 550 | int ret; |
Hans de Goede | fea6d8e | 2014-06-29 16:11:00 +0200 | [diff] [blame] | 551 | |
| 552 | func = sunxi_pinctrl_desc_find_function_by_pin(pctl, |
| 553 | pctl->irq_array[d->hwirq], "irq"); |
| 554 | if (!func) |
| 555 | return -EINVAL; |
| 556 | |
Alexandre Courbot | e3a2e87 | 2014-10-23 17:27:07 +0900 | [diff] [blame] | 557 | ret = gpiochip_lock_as_irq(pctl->chip, |
Chen-Yu Tsai | 343f132 | 2014-07-15 01:24:37 +0800 | [diff] [blame] | 558 | pctl->irq_array[d->hwirq] - pctl->desc->pin_base); |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 559 | if (ret) { |
| 560 | dev_err(pctl->dev, "unable to lock HW IRQ %lu for IRQ\n", |
| 561 | irqd_to_hwirq(d)); |
| 562 | return ret; |
| 563 | } |
| 564 | |
Hans de Goede | fea6d8e | 2014-06-29 16:11:00 +0200 | [diff] [blame] | 565 | /* Change muxing to INT mode */ |
| 566 | sunxi_pmx_set(pctl->pctl_dev, pctl->irq_array[d->hwirq], func->muxval); |
| 567 | |
| 568 | return 0; |
| 569 | } |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 570 | |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 571 | static void sunxi_pinctrl_irq_release_resources(struct irq_data *d) |
| 572 | { |
| 573 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
| 574 | |
Alexandre Courbot | e3a2e87 | 2014-10-23 17:27:07 +0900 | [diff] [blame] | 575 | gpiochip_unlock_as_irq(pctl->chip, |
| 576 | pctl->irq_array[d->hwirq] - pctl->desc->pin_base); |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 577 | } |
| 578 | |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 579 | static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type) |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 580 | { |
| 581 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
| 582 | u32 reg = sunxi_irq_cfg_reg(d->hwirq); |
| 583 | u8 index = sunxi_irq_cfg_offset(d->hwirq); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 584 | unsigned long flags; |
Maxime Ripard | 2aaaddf | 2013-08-04 12:38:47 +0200 | [diff] [blame] | 585 | u32 regval; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 586 | u8 mode; |
| 587 | |
| 588 | switch (type) { |
| 589 | case IRQ_TYPE_EDGE_RISING: |
| 590 | mode = IRQ_EDGE_RISING; |
| 591 | break; |
| 592 | case IRQ_TYPE_EDGE_FALLING: |
| 593 | mode = IRQ_EDGE_FALLING; |
| 594 | break; |
| 595 | case IRQ_TYPE_EDGE_BOTH: |
| 596 | mode = IRQ_EDGE_BOTH; |
| 597 | break; |
| 598 | case IRQ_TYPE_LEVEL_HIGH: |
| 599 | mode = IRQ_LEVEL_HIGH; |
| 600 | break; |
| 601 | case IRQ_TYPE_LEVEL_LOW: |
| 602 | mode = IRQ_LEVEL_LOW; |
| 603 | break; |
| 604 | default: |
| 605 | return -EINVAL; |
| 606 | } |
| 607 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 608 | spin_lock_irqsave(&pctl->lock, flags); |
| 609 | |
Maxime Ripard | a0d6de9 | 2015-07-20 14:41:11 +0200 | [diff] [blame] | 610 | if (type & IRQ_TYPE_LEVEL_MASK) |
Thomas Gleixner | b9a5ec33 | 2015-09-16 12:32:40 +0200 | [diff] [blame] | 611 | irq_set_chip_handler_name_locked(d, &sunxi_pinctrl_level_irq_chip, |
| 612 | handle_fasteoi_irq, NULL); |
Maxime Ripard | a0d6de9 | 2015-07-20 14:41:11 +0200 | [diff] [blame] | 613 | else |
Thomas Gleixner | b9a5ec33 | 2015-09-16 12:32:40 +0200 | [diff] [blame] | 614 | irq_set_chip_handler_name_locked(d, &sunxi_pinctrl_edge_irq_chip, |
| 615 | handle_edge_irq, NULL); |
Maxime Ripard | a0d6de9 | 2015-07-20 14:41:11 +0200 | [diff] [blame] | 616 | |
Maxime Ripard | 2aaaddf | 2013-08-04 12:38:47 +0200 | [diff] [blame] | 617 | regval = readl(pctl->membase + reg); |
Hans de Goede | d82f940 | 2014-02-17 22:19:43 +0100 | [diff] [blame] | 618 | regval &= ~(IRQ_CFG_IRQ_MASK << index); |
Maxime Ripard | 2aaaddf | 2013-08-04 12:38:47 +0200 | [diff] [blame] | 619 | writel(regval | (mode << index), pctl->membase + reg); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 620 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 621 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
Maxime Ripard | 645ec71 | 2014-06-05 15:26:00 +0200 | [diff] [blame] | 626 | static void sunxi_pinctrl_irq_ack(struct irq_data *d) |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 627 | { |
| 628 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 629 | u32 status_reg = sunxi_irq_status_reg(d->hwirq); |
| 630 | u8 status_idx = sunxi_irq_status_offset(d->hwirq); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 631 | |
| 632 | /* Clear the IRQ */ |
| 633 | writel(1 << status_idx, pctl->membase + status_reg); |
| 634 | } |
| 635 | |
| 636 | static void sunxi_pinctrl_irq_mask(struct irq_data *d) |
| 637 | { |
| 638 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
| 639 | u32 reg = sunxi_irq_ctrl_reg(d->hwirq); |
| 640 | u8 idx = sunxi_irq_ctrl_offset(d->hwirq); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 641 | unsigned long flags; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 642 | u32 val; |
| 643 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 644 | spin_lock_irqsave(&pctl->lock, flags); |
| 645 | |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 646 | /* Mask the IRQ */ |
| 647 | val = readl(pctl->membase + reg); |
| 648 | writel(val & ~(1 << idx), pctl->membase + reg); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 649 | |
| 650 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void sunxi_pinctrl_irq_unmask(struct irq_data *d) |
| 654 | { |
| 655 | struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 656 | u32 reg = sunxi_irq_ctrl_reg(d->hwirq); |
| 657 | u8 idx = sunxi_irq_ctrl_offset(d->hwirq); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 658 | unsigned long flags; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 659 | u32 val; |
| 660 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 661 | spin_lock_irqsave(&pctl->lock, flags); |
| 662 | |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 663 | /* Unmask the IRQ */ |
| 664 | val = readl(pctl->membase + reg); |
| 665 | writel(val | (1 << idx), pctl->membase + reg); |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 666 | |
| 667 | spin_unlock_irqrestore(&pctl->lock, flags); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Hans de Goede | d61e23e | 2014-06-29 16:11:02 +0200 | [diff] [blame] | 670 | static void sunxi_pinctrl_irq_ack_unmask(struct irq_data *d) |
| 671 | { |
| 672 | sunxi_pinctrl_irq_ack(d); |
| 673 | sunxi_pinctrl_irq_unmask(d); |
| 674 | } |
| 675 | |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 676 | static struct irq_chip sunxi_pinctrl_edge_irq_chip = { |
Maxime Ripard | fb5b778 | 2015-07-20 14:41:12 +0200 | [diff] [blame] | 677 | .name = "sunxi_pio_edge", |
Maxime Ripard | 645ec71 | 2014-06-05 15:26:00 +0200 | [diff] [blame] | 678 | .irq_ack = sunxi_pinctrl_irq_ack, |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 679 | .irq_mask = sunxi_pinctrl_irq_mask, |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 680 | .irq_unmask = sunxi_pinctrl_irq_unmask, |
Hans de Goede | fea6d8e | 2014-06-29 16:11:00 +0200 | [diff] [blame] | 681 | .irq_request_resources = sunxi_pinctrl_irq_request_resources, |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 682 | .irq_release_resources = sunxi_pinctrl_irq_release_resources, |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 683 | .irq_set_type = sunxi_pinctrl_irq_set_type, |
Chen-Yu Tsai | 578c0a8 | 2014-06-29 16:10:59 +0200 | [diff] [blame] | 684 | .flags = IRQCHIP_SKIP_SET_WAKE, |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 685 | }; |
| 686 | |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 687 | static struct irq_chip sunxi_pinctrl_level_irq_chip = { |
Maxime Ripard | fb5b778 | 2015-07-20 14:41:12 +0200 | [diff] [blame] | 688 | .name = "sunxi_pio_level", |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 689 | .irq_eoi = sunxi_pinctrl_irq_ack, |
| 690 | .irq_mask = sunxi_pinctrl_irq_mask, |
| 691 | .irq_unmask = sunxi_pinctrl_irq_unmask, |
Hans de Goede | d61e23e | 2014-06-29 16:11:02 +0200 | [diff] [blame] | 692 | /* Define irq_enable / disable to avoid spurious irqs for drivers |
| 693 | * using these to suppress irqs while they clear the irq source */ |
| 694 | .irq_enable = sunxi_pinctrl_irq_ack_unmask, |
| 695 | .irq_disable = sunxi_pinctrl_irq_mask, |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 696 | .irq_request_resources = sunxi_pinctrl_irq_request_resources, |
Chen-Yu Tsai | f83549d | 2014-07-15 01:24:36 +0800 | [diff] [blame] | 697 | .irq_release_resources = sunxi_pinctrl_irq_release_resources, |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 698 | .irq_set_type = sunxi_pinctrl_irq_set_type, |
| 699 | .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_EOI_THREADED | |
| 700 | IRQCHIP_EOI_IF_HANDLED, |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 701 | }; |
| 702 | |
Maxime Ripard | d8323c6 | 2015-07-27 14:41:57 +0200 | [diff] [blame] | 703 | static int sunxi_pinctrl_irq_of_xlate(struct irq_domain *d, |
| 704 | struct device_node *node, |
| 705 | const u32 *intspec, |
| 706 | unsigned int intsize, |
| 707 | unsigned long *out_hwirq, |
| 708 | unsigned int *out_type) |
| 709 | { |
Hans de Goede | 8297992 | 2015-10-16 09:46:11 +0200 | [diff] [blame] | 710 | struct sunxi_pinctrl *pctl = d->host_data; |
Maxime Ripard | d8323c6 | 2015-07-27 14:41:57 +0200 | [diff] [blame] | 711 | struct sunxi_desc_function *desc; |
| 712 | int pin, base; |
| 713 | |
| 714 | if (intsize < 3) |
| 715 | return -EINVAL; |
| 716 | |
| 717 | base = PINS_PER_BANK * intspec[0]; |
Hans de Goede | 8297992 | 2015-10-16 09:46:11 +0200 | [diff] [blame] | 718 | pin = pctl->desc->pin_base + base + intspec[1]; |
Maxime Ripard | d8323c6 | 2015-07-27 14:41:57 +0200 | [diff] [blame] | 719 | |
Hans de Goede | 8297992 | 2015-10-16 09:46:11 +0200 | [diff] [blame] | 720 | desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, pin, "irq"); |
Maxime Ripard | d8323c6 | 2015-07-27 14:41:57 +0200 | [diff] [blame] | 721 | if (!desc) |
| 722 | return -EINVAL; |
| 723 | |
| 724 | *out_hwirq = desc->irqbank * PINS_PER_BANK + desc->irqnum; |
| 725 | *out_type = intspec[2]; |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static struct irq_domain_ops sunxi_pinctrl_irq_domain_ops = { |
| 731 | .xlate = sunxi_pinctrl_irq_of_xlate, |
| 732 | }; |
| 733 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 734 | static void sunxi_pinctrl_irq_handler(struct irq_desc *desc) |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 735 | { |
Thomas Gleixner | eeef97b | 2015-07-13 01:55:27 +0200 | [diff] [blame] | 736 | unsigned int irq = irq_desc_get_irq(desc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 737 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 738 | struct sunxi_pinctrl *pctl = irq_desc_get_handler_data(desc); |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 739 | unsigned long bank, reg, val; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 740 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 741 | for (bank = 0; bank < pctl->desc->irq_banks; bank++) |
| 742 | if (irq == pctl->irq[bank]) |
| 743 | break; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 744 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 745 | if (bank == pctl->desc->irq_banks) |
| 746 | return; |
| 747 | |
| 748 | reg = sunxi_irq_status_reg_from_bank(bank); |
| 749 | val = readl(pctl->membase + reg); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 750 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 751 | if (val) { |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 752 | int irqoffset; |
| 753 | |
Chen-Yu Tsai | 905a511 | 2014-02-11 00:22:37 +0800 | [diff] [blame] | 754 | chained_irq_enter(chip, desc); |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 755 | for_each_set_bit(irqoffset, &val, IRQ_PER_BANK) { |
| 756 | int pin_irq = irq_find_mapping(pctl->domain, |
| 757 | bank * IRQ_PER_BANK + irqoffset); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 758 | generic_handle_irq(pin_irq); |
| 759 | } |
Chen-Yu Tsai | 905a511 | 2014-02-11 00:22:37 +0800 | [diff] [blame] | 760 | chained_irq_exit(chip, desc); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 764 | static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl, |
| 765 | const char *name) |
| 766 | { |
| 767 | struct sunxi_pinctrl_function *func = pctl->functions; |
| 768 | |
| 769 | while (func->name) { |
| 770 | /* function already there */ |
| 771 | if (strcmp(func->name, name) == 0) { |
| 772 | func->ngroups++; |
| 773 | return -EEXIST; |
| 774 | } |
| 775 | func++; |
| 776 | } |
| 777 | |
| 778 | func->name = name; |
| 779 | func->ngroups = 1; |
| 780 | |
| 781 | pctl->nfunctions++; |
| 782 | |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static int sunxi_pinctrl_build_state(struct platform_device *pdev) |
| 787 | { |
| 788 | struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev); |
| 789 | int i; |
| 790 | |
| 791 | pctl->ngroups = pctl->desc->npins; |
| 792 | |
| 793 | /* Allocate groups */ |
| 794 | pctl->groups = devm_kzalloc(&pdev->dev, |
| 795 | pctl->ngroups * sizeof(*pctl->groups), |
| 796 | GFP_KERNEL); |
| 797 | if (!pctl->groups) |
| 798 | return -ENOMEM; |
| 799 | |
| 800 | for (i = 0; i < pctl->desc->npins; i++) { |
| 801 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 802 | struct sunxi_pinctrl_group *group = pctl->groups + i; |
| 803 | |
| 804 | group->name = pin->pin.name; |
| 805 | group->pin = pin->pin.number; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * We suppose that we won't have any more functions than pins, |
| 810 | * we'll reallocate that later anyway |
| 811 | */ |
| 812 | pctl->functions = devm_kzalloc(&pdev->dev, |
| 813 | pctl->desc->npins * sizeof(*pctl->functions), |
| 814 | GFP_KERNEL); |
| 815 | if (!pctl->functions) |
| 816 | return -ENOMEM; |
| 817 | |
| 818 | /* Count functions and their associated groups */ |
| 819 | for (i = 0; i < pctl->desc->npins; i++) { |
| 820 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 821 | struct sunxi_desc_function *func = pin->functions; |
| 822 | |
| 823 | while (func->name) { |
Chen-Yu Tsai | d54e9a2 | 2014-05-26 09:47:56 +0200 | [diff] [blame] | 824 | /* Create interrupt mapping while we're at it */ |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 825 | if (!strcmp(func->name, "irq")) { |
| 826 | int irqnum = func->irqnum + func->irqbank * IRQ_PER_BANK; |
| 827 | pctl->irq_array[irqnum] = pin->pin.number; |
| 828 | } |
| 829 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 830 | sunxi_pinctrl_add_function(pctl, func->name); |
| 831 | func++; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | pctl->functions = krealloc(pctl->functions, |
| 836 | pctl->nfunctions * sizeof(*pctl->functions), |
| 837 | GFP_KERNEL); |
| 838 | |
| 839 | for (i = 0; i < pctl->desc->npins; i++) { |
| 840 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 841 | struct sunxi_desc_function *func = pin->functions; |
| 842 | |
| 843 | while (func->name) { |
| 844 | struct sunxi_pinctrl_function *func_item; |
| 845 | const char **func_grp; |
| 846 | |
| 847 | func_item = sunxi_pinctrl_find_function_by_name(pctl, |
| 848 | func->name); |
| 849 | if (!func_item) |
| 850 | return -EINVAL; |
| 851 | |
| 852 | if (!func_item->groups) { |
| 853 | func_item->groups = |
| 854 | devm_kzalloc(&pdev->dev, |
| 855 | func_item->ngroups * sizeof(*func_item->groups), |
| 856 | GFP_KERNEL); |
| 857 | if (!func_item->groups) |
| 858 | return -ENOMEM; |
| 859 | } |
| 860 | |
| 861 | func_grp = func_item->groups; |
| 862 | while (*func_grp) |
| 863 | func_grp++; |
| 864 | |
| 865 | *func_grp = pin->pin.name; |
| 866 | func++; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
Maxime Ripard | 2284ba6 | 2014-04-18 20:10:41 +0200 | [diff] [blame] | 873 | int sunxi_pinctrl_init(struct platform_device *pdev, |
| 874 | const struct sunxi_pinctrl_desc *desc) |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 875 | { |
| 876 | struct device_node *node = pdev->dev.of_node; |
Maxime Ripard | ba6764d | 2014-05-22 16:25:27 +0200 | [diff] [blame] | 877 | struct pinctrl_desc *pctrl_desc; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 878 | struct pinctrl_pin_desc *pins; |
| 879 | struct sunxi_pinctrl *pctl; |
Maxime Ripard | 4409caf | 2014-04-26 21:59:50 +0200 | [diff] [blame] | 880 | struct resource *res; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 881 | int i, ret, last_pin; |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 882 | struct clk *clk; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 883 | |
| 884 | pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); |
| 885 | if (!pctl) |
| 886 | return -ENOMEM; |
| 887 | platform_set_drvdata(pdev, pctl); |
| 888 | |
Maxime Ripard | 1bee963 | 2013-08-04 12:38:48 +0200 | [diff] [blame] | 889 | spin_lock_init(&pctl->lock); |
| 890 | |
Maxime Ripard | 4409caf | 2014-04-26 21:59:50 +0200 | [diff] [blame] | 891 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 892 | pctl->membase = devm_ioremap_resource(&pdev->dev, res); |
| 893 | if (IS_ERR(pctl->membase)) |
| 894 | return PTR_ERR(pctl->membase); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 895 | |
Maxime Ripard | ba6764d | 2014-05-22 16:25:27 +0200 | [diff] [blame] | 896 | pctl->dev = &pdev->dev; |
Maxime Ripard | 2284ba6 | 2014-04-18 20:10:41 +0200 | [diff] [blame] | 897 | pctl->desc = desc; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 898 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 899 | pctl->irq_array = devm_kcalloc(&pdev->dev, |
| 900 | IRQ_PER_BANK * pctl->desc->irq_banks, |
| 901 | sizeof(*pctl->irq_array), |
| 902 | GFP_KERNEL); |
| 903 | if (!pctl->irq_array) |
| 904 | return -ENOMEM; |
| 905 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 906 | ret = sunxi_pinctrl_build_state(pdev); |
| 907 | if (ret) { |
| 908 | dev_err(&pdev->dev, "dt probe failed: %d\n", ret); |
| 909 | return ret; |
| 910 | } |
| 911 | |
| 912 | pins = devm_kzalloc(&pdev->dev, |
| 913 | pctl->desc->npins * sizeof(*pins), |
| 914 | GFP_KERNEL); |
| 915 | if (!pins) |
| 916 | return -ENOMEM; |
| 917 | |
| 918 | for (i = 0; i < pctl->desc->npins; i++) |
| 919 | pins[i] = pctl->desc->pins[i].pin; |
| 920 | |
Maxime Ripard | ba6764d | 2014-05-22 16:25:27 +0200 | [diff] [blame] | 921 | pctrl_desc = devm_kzalloc(&pdev->dev, |
| 922 | sizeof(*pctrl_desc), |
| 923 | GFP_KERNEL); |
| 924 | if (!pctrl_desc) |
| 925 | return -ENOMEM; |
| 926 | |
| 927 | pctrl_desc->name = dev_name(&pdev->dev); |
| 928 | pctrl_desc->owner = THIS_MODULE; |
| 929 | pctrl_desc->pins = pins; |
| 930 | pctrl_desc->npins = pctl->desc->npins; |
| 931 | pctrl_desc->confops = &sunxi_pconf_ops; |
| 932 | pctrl_desc->pctlops = &sunxi_pctrl_ops; |
| 933 | pctrl_desc->pmxops = &sunxi_pmx_ops; |
| 934 | |
| 935 | pctl->pctl_dev = pinctrl_register(pctrl_desc, |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 936 | &pdev->dev, pctl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 937 | if (IS_ERR(pctl->pctl_dev)) { |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 938 | dev_err(&pdev->dev, "couldn't register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 939 | return PTR_ERR(pctl->pctl_dev); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 942 | pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); |
| 943 | if (!pctl->chip) { |
| 944 | ret = -ENOMEM; |
| 945 | goto pinctrl_error; |
| 946 | } |
| 947 | |
| 948 | last_pin = pctl->desc->pins[pctl->desc->npins - 1].pin.number; |
Boris BREZILLON | d83c82c | 2014-04-10 15:52:43 +0200 | [diff] [blame] | 949 | pctl->chip->owner = THIS_MODULE; |
Jonas Gorski | 98c85d5 | 2015-10-11 17:34:19 +0200 | [diff] [blame] | 950 | pctl->chip->request = gpiochip_generic_request, |
| 951 | pctl->chip->free = gpiochip_generic_free, |
Boris BREZILLON | d83c82c | 2014-04-10 15:52:43 +0200 | [diff] [blame] | 952 | pctl->chip->direction_input = sunxi_pinctrl_gpio_direction_input, |
| 953 | pctl->chip->direction_output = sunxi_pinctrl_gpio_direction_output, |
| 954 | pctl->chip->get = sunxi_pinctrl_gpio_get, |
| 955 | pctl->chip->set = sunxi_pinctrl_gpio_set, |
| 956 | pctl->chip->of_xlate = sunxi_pinctrl_gpio_of_xlate, |
| 957 | pctl->chip->to_irq = sunxi_pinctrl_gpio_to_irq, |
| 958 | pctl->chip->of_gpio_n_cells = 3, |
| 959 | pctl->chip->can_sleep = false, |
| 960 | pctl->chip->ngpio = round_up(last_pin, PINS_PER_BANK) - |
| 961 | pctl->desc->pin_base; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 962 | pctl->chip->label = dev_name(&pdev->dev); |
Linus Walleij | 58383c7 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 963 | pctl->chip->parent = &pdev->dev; |
Boris BREZILLON | d83c82c | 2014-04-10 15:52:43 +0200 | [diff] [blame] | 964 | pctl->chip->base = pctl->desc->pin_base; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 965 | |
Linus Walleij | 88057d6 | 2015-12-08 22:40:43 +0100 | [diff] [blame] | 966 | ret = gpiochip_add_data(pctl->chip, pctl); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 967 | if (ret) |
| 968 | goto pinctrl_error; |
| 969 | |
| 970 | for (i = 0; i < pctl->desc->npins; i++) { |
| 971 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 972 | |
| 973 | ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), |
Chen-Yu Tsai | 343f132 | 2014-07-15 01:24:37 +0800 | [diff] [blame] | 974 | pin->pin.number - pctl->desc->pin_base, |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 975 | pin->pin.number, 1); |
| 976 | if (ret) |
| 977 | goto gpiochip_error; |
| 978 | } |
| 979 | |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 980 | clk = devm_clk_get(&pdev->dev, NULL); |
Wei Yongjun | d72f88a | 2013-05-23 17:32:14 +0800 | [diff] [blame] | 981 | if (IS_ERR(clk)) { |
| 982 | ret = PTR_ERR(clk); |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 983 | goto gpiochip_error; |
Wei Yongjun | d72f88a | 2013-05-23 17:32:14 +0800 | [diff] [blame] | 984 | } |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 985 | |
Boris BREZILLON | 6415093 | 2014-04-10 15:52:40 +0200 | [diff] [blame] | 986 | ret = clk_prepare_enable(clk); |
| 987 | if (ret) |
| 988 | goto gpiochip_error; |
Emilio López | 950707c | 2013-03-22 11:20:40 -0300 | [diff] [blame] | 989 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 990 | pctl->irq = devm_kcalloc(&pdev->dev, |
| 991 | pctl->desc->irq_banks, |
| 992 | sizeof(*pctl->irq), |
| 993 | GFP_KERNEL); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 994 | if (!pctl->irq) { |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 995 | ret = -ENOMEM; |
Maxime Ripard | dc96910 | 2014-04-26 22:28:54 +0200 | [diff] [blame] | 996 | goto clk_error; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 997 | } |
| 998 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 999 | for (i = 0; i < pctl->desc->irq_banks; i++) { |
| 1000 | pctl->irq[i] = platform_get_irq(pdev, i); |
| 1001 | if (pctl->irq[i] < 0) { |
| 1002 | ret = pctl->irq[i]; |
| 1003 | goto clk_error; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | pctl->domain = irq_domain_add_linear(node, |
| 1008 | pctl->desc->irq_banks * IRQ_PER_BANK, |
Maxime Ripard | d8323c6 | 2015-07-27 14:41:57 +0200 | [diff] [blame] | 1009 | &sunxi_pinctrl_irq_domain_ops, |
| 1010 | pctl); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1011 | if (!pctl->domain) { |
| 1012 | dev_err(&pdev->dev, "Couldn't register IRQ domain\n"); |
| 1013 | ret = -ENOMEM; |
Maxime Ripard | dc96910 | 2014-04-26 22:28:54 +0200 | [diff] [blame] | 1014 | goto clk_error; |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 1017 | for (i = 0; i < (pctl->desc->irq_banks * IRQ_PER_BANK); i++) { |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1018 | int irqno = irq_create_mapping(pctl->domain, i); |
| 1019 | |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 1020 | irq_set_chip_and_handler(irqno, &sunxi_pinctrl_edge_irq_chip, |
| 1021 | handle_edge_irq); |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1022 | irq_set_chip_data(irqno, pctl); |
Javier Martinez Canillas | 5c99c0ff | 2015-09-16 10:28:29 +0200 | [diff] [blame] | 1023 | } |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1024 | |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 1025 | for (i = 0; i < pctl->desc->irq_banks; i++) { |
Hans de Goede | f4c51c1 | 2014-06-29 16:11:01 +0200 | [diff] [blame] | 1026 | /* Mask and clear all IRQs before registering a handler */ |
| 1027 | writel(0, pctl->membase + sunxi_irq_ctrl_reg_from_bank(i)); |
| 1028 | writel(0xffffffff, |
| 1029 | pctl->membase + sunxi_irq_status_reg_from_bank(i)); |
| 1030 | |
Thomas Gleixner | ef80e87 | 2015-06-21 20:16:18 +0200 | [diff] [blame] | 1031 | irq_set_chained_handler_and_data(pctl->irq[i], |
| 1032 | sunxi_pinctrl_irq_handler, |
| 1033 | pctl); |
Maxime Ripard | aebdc8a | 2014-06-05 15:26:04 +0200 | [diff] [blame] | 1034 | } |
Maxime Ripard | 60242db | 2013-06-08 12:05:44 +0200 | [diff] [blame] | 1035 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 1036 | dev_info(&pdev->dev, "initialized sunXi PIO driver\n"); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 1037 | |
| 1038 | return 0; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 1039 | |
Boris BREZILLON | e2bddc6 | 2014-04-10 15:52:41 +0200 | [diff] [blame] | 1040 | clk_error: |
| 1041 | clk_disable_unprepare(clk); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 1042 | gpiochip_error: |
abdoulaye berthe | b4e7c55 | 2014-07-12 22:30:13 +0200 | [diff] [blame] | 1043 | gpiochip_remove(pctl->chip); |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame] | 1044 | pinctrl_error: |
| 1045 | pinctrl_unregister(pctl->pctl_dev); |
| 1046 | return ret; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 1047 | } |