Lines Matching +full:latched +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0+
8 * pinctrl-nomadik.c, please see original file for copyright information
9 * pinctrl-tegra.c, please see original file for copyright information
32 #include <linux/pinctrl/pinconf-generic.h>
39 #include <dt-bindings/pinctrl/bcm2835.h>
41 #define MODULE_NAME "pinctrl-bcm2835"
59 #define GPPUD 0x94 /* Pin Pull-up/down Enable */
60 #define GPPUDCLK0 0x98 /* Pin Pull-up/down Enable Clock */
61 #define GP_GPIO_PUP_PDN_CNTRL_REG0 0xe4 /* 2711 Pin Pull-up/down select */
241 [IRQ_TYPE_EDGE_RISING] = "edge-rising",
242 [IRQ_TYPE_EDGE_FALLING] = "edge-falling",
243 [IRQ_TYPE_EDGE_BOTH] = "edge-both",
244 [IRQ_TYPE_LEVEL_HIGH] = "level-high",
245 [IRQ_TYPE_LEVEL_LOW] = "level-low",
254 return readl(pc->base + reg); in bcm2835_gpio_rd()
260 writel(val, pc->base + reg); in bcm2835_gpio_wr()
284 dev_dbg(pc->dev, "get %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_get()
298 spin_lock_irqsave(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
302 dev_dbg(pc->dev, "read %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
313 dev_dbg(pc->dev, "trans %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
321 dev_dbg(pc->dev, "write %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
326 spin_unlock_irqrestore(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
351 return -EINVAL; in bcm2835_gpio_get_direction()
378 struct device_node *np = dev_of_node(gc->parent); in bcm2835_add_pin_ranges_fallback()
385 gc->ngpio); in bcm2835_add_pin_ranges_fallback()
399 .base = -1,
406 .label = "pinctrl-bcm2711",
416 .base = -1,
431 events &= pc->enabled_irq_map[bank]; in bcm2835_gpio_irq_handle_bank()
434 generic_handle_domain_irq(pc->gpio_chip.irq.domain, in bcm2835_gpio_irq_handle_bank()
449 if (chip->irq.parents[i] == irq) { in bcm2835_gpio_irq_handler()
460 case 0: /* IRQ0 covers GPIOs 0-27 */ in bcm2835_gpio_irq_handler()
463 case 1: /* IRQ1 covers GPIOs 28-45 */ in bcm2835_gpio_irq_handler()
467 case 2: /* IRQ2 covers GPIOs 46-57 */ in bcm2835_gpio_irq_handler()
497 switch (pc->irq_type[offset]) { in bcm2835_gpio_irq_config()
532 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_unmask()
533 set_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_unmask()
535 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_unmask()
547 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_mask()
549 /* Clear events that were latched prior to clearing event sources */ in bcm2835_gpio_irq_mask()
551 clear_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_mask()
552 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_mask()
567 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_disabled()
571 return -EINVAL; in __bcm2835_gpio_irq_set_type_disabled()
582 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
584 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
589 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
591 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
593 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
594 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
596 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
602 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
604 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; in __bcm2835_gpio_irq_set_type_enabled()
606 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
607 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
609 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
615 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_RISING) { in __bcm2835_gpio_irq_set_type_enabled()
617 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
619 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
620 } else if (pc->irq_type[offset] == IRQ_TYPE_EDGE_FALLING) { in __bcm2835_gpio_irq_set_type_enabled()
622 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; in __bcm2835_gpio_irq_set_type_enabled()
624 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
625 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
627 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
634 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
636 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
642 return -EINVAL; in __bcm2835_gpio_irq_set_type_enabled()
657 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
659 if (test_bit(offset, &pc->enabled_irq_map[bank])) in bcm2835_gpio_irq_set_type()
669 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
689 int ret = -EINVAL; in bcm2835_gpio_irq_set_wake()
691 if (!pc->wake_irq) in bcm2835_gpio_irq_set_wake()
704 ret = enable_irq_wake(pc->wake_irq[irqgroup]); in bcm2835_gpio_irq_set_wake()
706 ret = disable_irq_wake(pc->wake_irq[irqgroup]); in bcm2835_gpio_irq_set_wake()
749 struct gpio_chip *chip = &pc->gpio_chip; in bcm2835_pctl_pin_dbg_show()
753 int irq = irq_find_mapping(chip->irq.domain, offset); in bcm2835_pctl_pin_dbg_show()
757 irq, irq_type_names[pc->irq_type[offset]]); in bcm2835_pctl_pin_dbg_show()
779 dev_err(pc->dev, "%pOF: invalid brcm,function %d\n", np, fnum); in bcm2835_pctl_dt_node_to_map_func()
780 return -EINVAL; in bcm2835_pctl_dt_node_to_map_func()
783 map->type = PIN_MAP_TYPE_MUX_GROUP; in bcm2835_pctl_dt_node_to_map_func()
784 map->data.mux.group = bcm2835_gpio_groups[pin]; in bcm2835_pctl_dt_node_to_map_func()
785 map->data.mux.function = bcm2835_functions[fnum]; in bcm2835_pctl_dt_node_to_map_func()
799 dev_err(pc->dev, "%pOF: invalid brcm,pull %d\n", np, pull); in bcm2835_pctl_dt_node_to_map_pull()
800 return -EINVAL; in bcm2835_pctl_dt_node_to_map_pull()
805 return -ENOMEM; in bcm2835_pctl_dt_node_to_map_pull()
808 map->type = PIN_MAP_TYPE_CONFIGS_PIN; in bcm2835_pctl_dt_node_to_map_pull()
809 map->data.configs.group_or_pin = bcm2835_gpio_pins[pin].name; in bcm2835_pctl_dt_node_to_map_pull()
810 map->data.configs.configs = configs; in bcm2835_pctl_dt_node_to_map_pull()
811 map->data.configs.num_configs = 1; in bcm2835_pctl_dt_node_to_map_pull()
836 dev_err(pc->dev, "%pOF: missing brcm,pins property\n", np); in bcm2835_pctl_dt_node_to_map()
837 return -EINVAL; in bcm2835_pctl_dt_node_to_map()
844 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
847 return -EINVAL; in bcm2835_pctl_dt_node_to_map()
850 num_pins = pins->length / 4; in bcm2835_pctl_dt_node_to_map()
851 num_funcs = funcs ? (funcs->length / 4) : 0; in bcm2835_pctl_dt_node_to_map()
852 num_pulls = pulls ? (pulls->length / 4) : 0; in bcm2835_pctl_dt_node_to_map()
855 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
858 return -EINVAL; in bcm2835_pctl_dt_node_to_map()
862 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
865 return -EINVAL; in bcm2835_pctl_dt_node_to_map()
876 return -ENOMEM; in bcm2835_pctl_dt_node_to_map()
882 if (pin >= pc->pctl_desc.npins) { in bcm2835_pctl_dt_node_to_map()
883 dev_err(pc->dev, "%pOF: invalid brcm,pins value %d\n", in bcm2835_pctl_dt_node_to_map()
885 err = -EINVAL; in bcm2835_pctl_dt_node_to_map()
1025 return -EINVAL; in bcm2835_pinconf_get()
1032 return -ENOTSUPP; in bcm2835_pinconf_get()
1090 /* Set output-high or output-low */ in bcm2835_pinconf_set()
1096 return -ENOTSUPP; in bcm2835_pinconf_set()
1124 return -EINVAL; in bcm2711_pinconf_get()
1130 return -EINVAL; in bcm2711_pinconf_get()
1137 return -EINVAL; in bcm2711_pinconf_get()
1201 /* Set output-high or output-low */ in bcm2711_pinconf_set()
1207 return -ENOTSUPP; in bcm2711_pinconf_set()
1231 .name = "pinctrl-bcm2711",
1246 .name = "pinctrl-bcm2711",
1270 .compatible = "brcm,bcm2835-gpio",
1274 .compatible = "brcm,bcm2711-gpio",
1278 .compatible = "brcm,bcm7211-gpio",
1287 struct device *dev = &pdev->dev; in bcm2835_pinctrl_probe()
1288 struct device_node *np = dev->of_node; in bcm2835_pinctrl_probe()
1302 return -ENOMEM; in bcm2835_pinctrl_probe()
1305 pc->dev = dev; in bcm2835_pinctrl_probe()
1313 pc->base = devm_ioremap_resource(dev, &iomem); in bcm2835_pinctrl_probe()
1314 if (IS_ERR(pc->base)) in bcm2835_pinctrl_probe()
1315 return PTR_ERR(pc->base); in bcm2835_pinctrl_probe()
1317 match = of_match_node(bcm2835_pinctrl_match, pdev->dev.of_node); in bcm2835_pinctrl_probe()
1319 return -EINVAL; in bcm2835_pinctrl_probe()
1321 pdata = match->data; in bcm2835_pinctrl_probe()
1322 is_7211 = of_device_is_compatible(np, "brcm,bcm7211-gpio"); in bcm2835_pinctrl_probe()
1324 pc->gpio_chip = *pdata->gpio_chip; in bcm2835_pinctrl_probe()
1325 pc->gpio_chip.parent = dev; in bcm2835_pinctrl_probe()
1327 spin_lock_init(&pc->fsel_lock); in bcm2835_pinctrl_probe()
1345 raw_spin_lock_init(&pc->irq_lock[i]); in bcm2835_pinctrl_probe()
1348 pc->pctl_desc = *pdata->pctl_desc; in bcm2835_pinctrl_probe()
1349 pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc); in bcm2835_pinctrl_probe()
1350 if (IS_ERR(pc->pctl_dev)) { in bcm2835_pinctrl_probe()
1351 gpiochip_remove(&pc->gpio_chip); in bcm2835_pinctrl_probe()
1352 return PTR_ERR(pc->pctl_dev); in bcm2835_pinctrl_probe()
1355 pc->gpio_range = *pdata->gpio_range; in bcm2835_pinctrl_probe()
1356 pc->gpio_range.base = pc->gpio_chip.base; in bcm2835_pinctrl_probe()
1357 pc->gpio_range.gc = &pc->gpio_chip; in bcm2835_pinctrl_probe()
1358 pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); in bcm2835_pinctrl_probe()
1360 girq = &pc->gpio_chip.irq; in bcm2835_pinctrl_probe()
1362 girq->parent_handler = bcm2835_gpio_irq_handler; in bcm2835_pinctrl_probe()
1363 girq->num_parents = BCM2835_NUM_IRQS; in bcm2835_pinctrl_probe()
1364 girq->parents = devm_kcalloc(dev, BCM2835_NUM_IRQS, in bcm2835_pinctrl_probe()
1365 sizeof(*girq->parents), in bcm2835_pinctrl_probe()
1367 if (!girq->parents) { in bcm2835_pinctrl_probe()
1368 err = -ENOMEM; in bcm2835_pinctrl_probe()
1373 pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS, in bcm2835_pinctrl_probe()
1374 sizeof(*pc->wake_irq), in bcm2835_pinctrl_probe()
1376 if (!pc->wake_irq) { in bcm2835_pinctrl_probe()
1377 err = -ENOMEM; in bcm2835_pinctrl_probe()
1384 * since we use one gpiochip to cover all lines - the in bcm2835_pinctrl_probe()
1386 * bank that was firing the IRQ and look up the per-group in bcm2835_pinctrl_probe()
1393 girq->parents[i] = irq_of_parse_and_map(np, i); in bcm2835_pinctrl_probe()
1395 if (!girq->parents[i]) { in bcm2835_pinctrl_probe()
1396 girq->num_parents = i; in bcm2835_pinctrl_probe()
1402 pc->wake_irq[i] = irq_of_parse_and_map(np, i + in bcm2835_pinctrl_probe()
1405 len = strlen(dev_name(pc->dev)) + 16; in bcm2835_pinctrl_probe()
1406 name = devm_kzalloc(pc->dev, len, GFP_KERNEL); in bcm2835_pinctrl_probe()
1408 err = -ENOMEM; in bcm2835_pinctrl_probe()
1412 snprintf(name, len, "%s:bank%d", dev_name(pc->dev), i); in bcm2835_pinctrl_probe()
1415 err = devm_request_irq(dev, pc->wake_irq[i], in bcm2835_pinctrl_probe()
1420 pc->wake_irq[i]); in bcm2835_pinctrl_probe()
1423 girq->default_type = IRQ_TYPE_NONE; in bcm2835_pinctrl_probe()
1424 girq->handler = handle_level_irq; in bcm2835_pinctrl_probe()
1426 err = gpiochip_add_data(&pc->gpio_chip, pc); in bcm2835_pinctrl_probe()
1438 pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range); in bcm2835_pinctrl_probe()