Lines Matching full:pc

252 static inline u32 bcm2835_gpio_rd(struct bcm2835_pinctrl *pc, unsigned reg)  in bcm2835_gpio_rd()  argument
254 return readl(pc->base + reg); in bcm2835_gpio_rd()
257 static inline void bcm2835_gpio_wr(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_wr() argument
260 writel(val, pc->base + reg); in bcm2835_gpio_wr()
263 static inline int bcm2835_gpio_get_bit(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_get_bit() argument
267 return (bcm2835_gpio_rd(pc, reg) >> GPIO_REG_SHIFT(bit)) & 1; in bcm2835_gpio_get_bit()
271 static inline void bcm2835_gpio_set_bit(struct bcm2835_pinctrl *pc, in bcm2835_gpio_set_bit() argument
275 bcm2835_gpio_wr(pc, reg, BIT(GPIO_REG_SHIFT(bit))); in bcm2835_gpio_set_bit()
279 struct bcm2835_pinctrl *pc, unsigned pin) in bcm2835_pinctrl_fsel_get() argument
281 u32 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); in bcm2835_pinctrl_fsel_get()
284 dev_dbg(pc->dev, "get %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_get()
291 struct bcm2835_pinctrl *pc, unsigned pin, in bcm2835_pinctrl_fsel_set() argument
298 spin_lock_irqsave(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
299 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); 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()
315 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
321 dev_dbg(pc->dev, "write %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
323 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
326 spin_unlock_irqrestore(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
331 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_direction_input() local
333 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_gpio_direction_input()
339 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_get() local
341 return bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_gpio_get()
346 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_get_direction() local
347 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_gpio_get_direction()
361 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_set() local
363 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); in bcm2835_gpio_set()
369 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_direction_output() local
371 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); in bcm2835_gpio_direction_output()
372 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_OUT); in bcm2835_gpio_direction_output()
422 static void bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc, in bcm2835_gpio_irq_handle_bank() argument
429 events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4); in bcm2835_gpio_irq_handle_bank()
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()
442 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_handler() local
461 bcm2835_gpio_irq_handle_bank(pc, 0, 0x0fffffff); in bcm2835_gpio_irq_handler()
464 bcm2835_gpio_irq_handle_bank(pc, 0, 0xf0000000); in bcm2835_gpio_irq_handler()
465 bcm2835_gpio_irq_handle_bank(pc, 1, 0x00003fff); in bcm2835_gpio_irq_handler()
468 bcm2835_gpio_irq_handle_bank(pc, 1, 0x003fc000); in bcm2835_gpio_irq_handler()
480 static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_config() argument
485 value = bcm2835_gpio_rd(pc, reg); in __bcm2835_gpio_irq_config()
490 bcm2835_gpio_wr(pc, reg, value); in __bcm2835_gpio_irq_config()
494 static void bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in bcm2835_gpio_irq_config() argument
497 switch (pc->irq_type[offset]) { in bcm2835_gpio_irq_config()
499 __bcm2835_gpio_irq_config(pc, GPREN0, offset, enable); in bcm2835_gpio_irq_config()
503 __bcm2835_gpio_irq_config(pc, GPFEN0, offset, enable); in bcm2835_gpio_irq_config()
507 __bcm2835_gpio_irq_config(pc, GPREN0, offset, enable); in bcm2835_gpio_irq_config()
508 __bcm2835_gpio_irq_config(pc, GPFEN0, offset, enable); in bcm2835_gpio_irq_config()
512 __bcm2835_gpio_irq_config(pc, GPHEN0, offset, enable); in bcm2835_gpio_irq_config()
516 __bcm2835_gpio_irq_config(pc, GPLEN0, offset, enable); in bcm2835_gpio_irq_config()
524 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_unmask() local
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()
534 bcm2835_gpio_irq_config(pc, gpio, true); in bcm2835_gpio_irq_unmask()
535 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_unmask()
541 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_mask() local
547 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_mask()
548 bcm2835_gpio_irq_config(pc, gpio, false); in bcm2835_gpio_irq_mask()
550 bcm2835_gpio_set_bit(pc, GPEDS0, gpio); 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()
557 static int __bcm2835_gpio_irq_set_type_disabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_disabled() argument
567 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_disabled()
577 static int __bcm2835_gpio_irq_set_type_enabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_enabled() argument
582 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
583 bcm2835_gpio_irq_config(pc, offset, false); 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()
592 bcm2835_gpio_irq_config(pc, offset, false); 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()
595 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
596 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
597 bcm2835_gpio_irq_config(pc, offset, true); 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()
605 bcm2835_gpio_irq_config(pc, offset, false); 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()
608 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
609 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
610 bcm2835_gpio_irq_config(pc, offset, true); 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()
618 bcm2835_gpio_irq_config(pc, offset, true); 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()
623 bcm2835_gpio_irq_config(pc, offset, true); 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()
626 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
627 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
628 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
634 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
635 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
636 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
637 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
650 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_set_type() local
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()
660 ret = __bcm2835_gpio_irq_set_type_enabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
662 ret = __bcm2835_gpio_irq_set_type_disabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
669 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
677 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_ack() local
680 bcm2835_gpio_set_bit(pc, GPEDS0, gpio); in bcm2835_gpio_irq_ack()
686 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_set_wake() local
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()
748 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_pin_dbg_show() local
749 struct gpio_chip *chip = &pc->gpio_chip; in bcm2835_pctl_pin_dbg_show()
750 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_pctl_pin_dbg_show()
752 int value = bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_pctl_pin_dbg_show()
757 irq, irq_type_names[pc->irq_type[offset]]); in bcm2835_pctl_pin_dbg_show()
772 static int bcm2835_pctl_dt_node_to_map_func(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_func() argument
779 dev_err(pc->dev, "%pOF: invalid brcm,function %d\n", np, fnum); in bcm2835_pctl_dt_node_to_map_func()
791 static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_pull() argument
799 dev_err(pc->dev, "%pOF: invalid brcm,pull %d\n", np, pull); in bcm2835_pctl_dt_node_to_map_pull()
821 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_dt_node_to_map() local
836 dev_err(pc->dev, "%pOF: missing brcm,pins property\n", np); in bcm2835_pctl_dt_node_to_map()
844 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
855 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
862 dev_err(pc->dev, 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()
894 err = bcm2835_pctl_dt_node_to_map_func(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
904 err = bcm2835_pctl_dt_node_to_map_pull(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
933 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_free() local
934 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_pmx_free()
943 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_pmx_free()
974 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_set() local
976 bcm2835_pinctrl_fsel_set(pc, group_selector, func_selector); in bcm2835_pmx_set()
993 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_gpio_set_direction() local
997 bcm2835_pinctrl_fsel_set(pc, offset, fsel); in bcm2835_pmx_gpio_set_direction()
1016 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pinconf_get() local
1017 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, pin); in bcm2835_pinconf_get()
1027 val = bcm2835_gpio_get_bit(pc, GPLEV0, pin); in bcm2835_pinconf_get()
1038 static void bcm2835_pull_config_set(struct bcm2835_pinctrl *pc, in bcm2835_pull_config_set() argument
1046 bcm2835_gpio_wr(pc, GPPUD, arg & 3); in bcm2835_pull_config_set()
1054 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit)); in bcm2835_pull_config_set()
1056 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0); in bcm2835_pull_config_set()
1063 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pinconf_set() local
1074 bcm2835_pull_config_set(pc, pin, arg); in bcm2835_pinconf_set()
1079 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_OFF); in bcm2835_pinconf_set()
1083 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_DOWN); in bcm2835_pinconf_set()
1087 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_UP); in bcm2835_pinconf_set()
1092 bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin); in bcm2835_pinconf_set()
1113 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2711_pinconf_get() local
1119 val = bcm2835_gpio_rd(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (offset * 4)); in bcm2711_pinconf_get()
1149 static void bcm2711_pull_config_set(struct bcm2835_pinctrl *pc, in bcm2711_pull_config_set() argument
1159 value = bcm2835_gpio_rd(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4)); in bcm2711_pull_config_set()
1162 bcm2835_gpio_wr(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4), value); in bcm2711_pull_config_set()
1169 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2711_pinconf_set() local
1187 bcm2711_pull_config_set(pc, pin, arg); in bcm2711_pinconf_set()
1192 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_NONE); in bcm2711_pinconf_set()
1195 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_DOWN); in bcm2711_pinconf_set()
1198 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_UP); in bcm2711_pinconf_set()
1203 bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin); in bcm2711_pinconf_set()
1290 struct bcm2835_pinctrl *pc; in bcm2835_pinctrl_probe() local
1300 pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); in bcm2835_pinctrl_probe()
1301 if (!pc) in bcm2835_pinctrl_probe()
1304 platform_set_drvdata(pdev, pc); 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()
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()
1333 bcm2835_gpio_wr(pc, GPREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1334 bcm2835_gpio_wr(pc, GPFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1335 bcm2835_gpio_wr(pc, GPHEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1336 bcm2835_gpio_wr(pc, GPLEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1337 bcm2835_gpio_wr(pc, GPAREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1338 bcm2835_gpio_wr(pc, GPAFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1341 events = bcm2835_gpio_rd(pc, GPEDS0 + i * 4); in bcm2835_pinctrl_probe()
1343 bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset)); 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()
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()
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()
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()
1417 IRQF_SHARED, name, pc); in bcm2835_pinctrl_probe()
1420 pc->wake_irq[i]); 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()