Lines Matching refs:pc

90 	struct bcm2835_pinctrl *pc;  member
264 static inline u32 bcm2835_gpio_rd(struct bcm2835_pinctrl *pc, unsigned reg) in bcm2835_gpio_rd() argument
266 return readl(pc->base + reg); in bcm2835_gpio_rd()
269 static inline void bcm2835_gpio_wr(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_wr() argument
272 writel(val, pc->base + reg); in bcm2835_gpio_wr()
275 static inline int bcm2835_gpio_get_bit(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_get_bit() argument
279 return (bcm2835_gpio_rd(pc, reg) >> GPIO_REG_SHIFT(bit)) & 1; in bcm2835_gpio_get_bit()
283 static inline void bcm2835_gpio_set_bit(struct bcm2835_pinctrl *pc, in bcm2835_gpio_set_bit() argument
287 bcm2835_gpio_wr(pc, reg, BIT(GPIO_REG_SHIFT(bit))); in bcm2835_gpio_set_bit()
291 struct bcm2835_pinctrl *pc, unsigned pin) in bcm2835_pinctrl_fsel_get() argument
293 u32 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); in bcm2835_pinctrl_fsel_get()
296 dev_dbg(pc->dev, "get %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_get()
303 struct bcm2835_pinctrl *pc, unsigned pin, in bcm2835_pinctrl_fsel_set() argument
306 u32 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); in bcm2835_pinctrl_fsel_set()
309 dev_dbg(pc->dev, "read %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
320 dev_dbg(pc->dev, "trans %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
322 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
328 dev_dbg(pc->dev, "write %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
330 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
350 struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); in bcm2835_gpio_get() local
352 return bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_gpio_get()
363 struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); in bcm2835_gpio_set() local
365 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); in bcm2835_gpio_set()
370 struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); in bcm2835_gpio_to_irq() local
372 return irq_linear_revmap(pc->irq_domain, offset); in bcm2835_gpio_to_irq()
393 struct bcm2835_pinctrl *pc = irqdata->pc; in bcm2835_gpio_irq_handler() local
400 events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4); in bcm2835_gpio_irq_handler()
401 events &= pc->enabled_irq_map[bank]; in bcm2835_gpio_irq_handler()
404 type = pc->irq_type[gpio]; in bcm2835_gpio_irq_handler()
406 generic_handle_irq(irq_linear_revmap(pc->irq_domain, gpio)); in bcm2835_gpio_irq_handler()
411 static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_config() argument
416 value = bcm2835_gpio_rd(pc, reg); in __bcm2835_gpio_irq_config()
421 bcm2835_gpio_wr(pc, reg, value); in __bcm2835_gpio_irq_config()
425 static void bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in bcm2835_gpio_irq_config() argument
428 switch (pc->irq_type[offset]) { in bcm2835_gpio_irq_config()
430 __bcm2835_gpio_irq_config(pc, GPREN0, offset, enable); in bcm2835_gpio_irq_config()
434 __bcm2835_gpio_irq_config(pc, GPFEN0, offset, enable); in bcm2835_gpio_irq_config()
438 __bcm2835_gpio_irq_config(pc, GPREN0, offset, enable); in bcm2835_gpio_irq_config()
439 __bcm2835_gpio_irq_config(pc, GPFEN0, offset, enable); in bcm2835_gpio_irq_config()
443 __bcm2835_gpio_irq_config(pc, GPHEN0, offset, enable); in bcm2835_gpio_irq_config()
447 __bcm2835_gpio_irq_config(pc, GPLEN0, offset, enable); in bcm2835_gpio_irq_config()
454 struct bcm2835_pinctrl *pc = irq_data_get_irq_chip_data(data); in bcm2835_gpio_irq_enable() local
460 spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_enable()
461 set_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_enable()
462 bcm2835_gpio_irq_config(pc, gpio, true); in bcm2835_gpio_irq_enable()
463 spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_enable()
468 struct bcm2835_pinctrl *pc = irq_data_get_irq_chip_data(data); in bcm2835_gpio_irq_disable() local
474 spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_disable()
475 bcm2835_gpio_irq_config(pc, gpio, false); in bcm2835_gpio_irq_disable()
476 clear_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_disable()
477 spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_disable()
480 static int __bcm2835_gpio_irq_set_type_disabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_disabled() argument
490 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_disabled()
500 static int __bcm2835_gpio_irq_set_type_enabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_enabled() argument
505 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
506 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
507 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
512 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
514 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
515 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
516 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
517 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
518 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
519 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
520 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
525 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
527 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; in __bcm2835_gpio_irq_set_type_enabled()
528 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
529 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
530 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
531 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
532 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
533 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
538 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_RISING) { in __bcm2835_gpio_irq_set_type_enabled()
540 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
541 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
542 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
543 } else if (pc->irq_type[offset] == IRQ_TYPE_EDGE_FALLING) { in __bcm2835_gpio_irq_set_type_enabled()
545 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; in __bcm2835_gpio_irq_set_type_enabled()
546 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
547 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
548 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
549 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
550 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
551 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
557 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
558 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
559 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
560 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
572 struct bcm2835_pinctrl *pc = irq_data_get_irq_chip_data(data); in bcm2835_gpio_irq_set_type() local
579 spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
581 if (test_bit(offset, &pc->enabled_irq_map[bank])) in bcm2835_gpio_irq_set_type()
582 ret = __bcm2835_gpio_irq_set_type_enabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
584 ret = __bcm2835_gpio_irq_set_type_disabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
591 spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
598 struct bcm2835_pinctrl *pc = irq_data_get_irq_chip_data(data); in bcm2835_gpio_irq_ack() local
601 bcm2835_gpio_set_bit(pc, GPEDS0, gpio); in bcm2835_gpio_irq_ack()
640 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_pin_dbg_show() local
641 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_pctl_pin_dbg_show()
643 int value = bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_pctl_pin_dbg_show()
644 int irq = irq_find_mapping(pc->irq_domain, offset); in bcm2835_pctl_pin_dbg_show()
648 irq, irq_type_names[pc->irq_type[offset]]); in bcm2835_pctl_pin_dbg_show()
663 static int bcm2835_pctl_dt_node_to_map_func(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_func() argument
670 dev_err(pc->dev, "%s: invalid brcm,function %d\n", in bcm2835_pctl_dt_node_to_map_func()
683 static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_pull() argument
691 dev_err(pc->dev, "%s: invalid brcm,pull %d\n", in bcm2835_pctl_dt_node_to_map_pull()
714 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_dt_node_to_map() local
723 dev_err(pc->dev, "%s: missing brcm,pins property\n", in bcm2835_pctl_dt_node_to_map()
732 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
743 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
750 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
771 dev_err(pc->dev, "%s: invalid brcm,pins value %d\n", in bcm2835_pctl_dt_node_to_map()
782 err = bcm2835_pctl_dt_node_to_map_func(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
792 err = bcm2835_pctl_dt_node_to_map_pull(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
845 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_set() local
847 bcm2835_pinctrl_fsel_set(pc, group_selector, func_selector); in bcm2835_pmx_set()
856 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_gpio_disable_free() local
859 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_pmx_gpio_disable_free()
867 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_gpio_set_direction() local
871 bcm2835_pinctrl_fsel_set(pc, offset, fsel); in bcm2835_pmx_gpio_set_direction()
896 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pinconf_set() local
912 bcm2835_gpio_wr(pc, GPPUD, arg & 3); in bcm2835_pinconf_set()
918 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit)); in bcm2835_pinconf_set()
920 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0); in bcm2835_pinconf_set()
950 struct bcm2835_pinctrl *pc; in bcm2835_pinctrl_probe() local
956 pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); in bcm2835_pinctrl_probe()
957 if (!pc) in bcm2835_pinctrl_probe()
960 platform_set_drvdata(pdev, pc); in bcm2835_pinctrl_probe()
961 pc->dev = dev; in bcm2835_pinctrl_probe()
969 pc->base = devm_ioremap_resource(dev, &iomem); in bcm2835_pinctrl_probe()
970 if (IS_ERR(pc->base)) in bcm2835_pinctrl_probe()
971 return PTR_ERR(pc->base); in bcm2835_pinctrl_probe()
973 pc->gpio_chip = bcm2835_gpio_chip; in bcm2835_pinctrl_probe()
974 pc->gpio_chip.dev = dev; in bcm2835_pinctrl_probe()
975 pc->gpio_chip.of_node = np; in bcm2835_pinctrl_probe()
977 pc->irq_domain = irq_domain_add_linear(np, BCM2835_NUM_GPIOS, in bcm2835_pinctrl_probe()
979 if (!pc->irq_domain) { in bcm2835_pinctrl_probe()
985 int irq = irq_create_mapping(pc->irq_domain, i); in bcm2835_pinctrl_probe()
989 irq_set_chip_data(irq, pc); in bcm2835_pinctrl_probe()
1000 bcm2835_gpio_wr(pc, GPREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1001 bcm2835_gpio_wr(pc, GPFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1002 bcm2835_gpio_wr(pc, GPHEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1003 bcm2835_gpio_wr(pc, GPLEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1004 bcm2835_gpio_wr(pc, GPAREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1005 bcm2835_gpio_wr(pc, GPAFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1008 events = bcm2835_gpio_rd(pc, GPEDS0 + i * 4); in bcm2835_pinctrl_probe()
1010 bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset)); in bcm2835_pinctrl_probe()
1012 pc->irq[i] = irq_of_parse_and_map(np, i); in bcm2835_pinctrl_probe()
1013 pc->irq_data[i].pc = pc; in bcm2835_pinctrl_probe()
1014 pc->irq_data[i].bank = i; in bcm2835_pinctrl_probe()
1015 spin_lock_init(&pc->irq_lock[i]); in bcm2835_pinctrl_probe()
1017 len = strlen(dev_name(pc->dev)) + 16; in bcm2835_pinctrl_probe()
1018 name = devm_kzalloc(pc->dev, len, GFP_KERNEL); in bcm2835_pinctrl_probe()
1021 snprintf(name, len, "%s:bank%d", dev_name(pc->dev), i); in bcm2835_pinctrl_probe()
1023 err = devm_request_irq(dev, pc->irq[i], in bcm2835_pinctrl_probe()
1025 name, &pc->irq_data[i]); in bcm2835_pinctrl_probe()
1027 dev_err(dev, "unable to request IRQ %d\n", pc->irq[i]); in bcm2835_pinctrl_probe()
1032 err = gpiochip_add(&pc->gpio_chip); in bcm2835_pinctrl_probe()
1038 pc->pctl_dev = pinctrl_register(&bcm2835_pinctrl_desc, dev, pc); in bcm2835_pinctrl_probe()
1039 if (!pc->pctl_dev) { in bcm2835_pinctrl_probe()
1040 gpiochip_remove(&pc->gpio_chip); in bcm2835_pinctrl_probe()
1044 pc->gpio_range = bcm2835_pinctrl_gpio_range; in bcm2835_pinctrl_probe()
1045 pc->gpio_range.base = pc->gpio_chip.base; in bcm2835_pinctrl_probe()
1046 pc->gpio_range.gc = &pc->gpio_chip; in bcm2835_pinctrl_probe()
1047 pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); in bcm2835_pinctrl_probe()
1054 struct bcm2835_pinctrl *pc = platform_get_drvdata(pdev); in bcm2835_pinctrl_remove() local
1056 pinctrl_unregister(pc->pctl_dev); in bcm2835_pinctrl_remove()
1057 gpiochip_remove(&pc->gpio_chip); in bcm2835_pinctrl_remove()