Lines Matching refs:pc

247 static inline u32 bcm2835_gpio_rd(struct bcm2835_pinctrl *pc, unsigned reg)  in bcm2835_gpio_rd()  argument
249 return readl(pc->base + reg); in bcm2835_gpio_rd()
252 static inline void bcm2835_gpio_wr(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_wr() argument
255 writel(val, pc->base + reg); in bcm2835_gpio_wr()
258 static inline int bcm2835_gpio_get_bit(struct bcm2835_pinctrl *pc, unsigned reg, in bcm2835_gpio_get_bit() argument
262 return (bcm2835_gpio_rd(pc, reg) >> GPIO_REG_SHIFT(bit)) & 1; in bcm2835_gpio_get_bit()
266 static inline void bcm2835_gpio_set_bit(struct bcm2835_pinctrl *pc, in bcm2835_gpio_set_bit() argument
270 bcm2835_gpio_wr(pc, reg, BIT(GPIO_REG_SHIFT(bit))); in bcm2835_gpio_set_bit()
274 struct bcm2835_pinctrl *pc, unsigned pin) in bcm2835_pinctrl_fsel_get() argument
276 u32 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); in bcm2835_pinctrl_fsel_get()
279 dev_dbg(pc->dev, "get %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_get()
286 struct bcm2835_pinctrl *pc, unsigned pin, in bcm2835_pinctrl_fsel_set() argument
293 spin_lock_irqsave(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
294 val = bcm2835_gpio_rd(pc, FSEL_REG(pin)); in bcm2835_pinctrl_fsel_set()
297 dev_dbg(pc->dev, "read %08x (%u => %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
308 dev_dbg(pc->dev, "trans %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
310 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
316 dev_dbg(pc->dev, "write %08x (%u <= %s)\n", val, pin, in bcm2835_pinctrl_fsel_set()
318 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); in bcm2835_pinctrl_fsel_set()
321 spin_unlock_irqrestore(&pc->fsel_lock, flags); in bcm2835_pinctrl_fsel_set()
326 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_direction_input() local
328 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_gpio_direction_input()
334 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_get() local
336 return bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_gpio_get()
341 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_get_direction() local
342 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_gpio_get_direction()
356 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_set() local
358 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); in bcm2835_gpio_set()
364 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_direction_output() local
366 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); in bcm2835_gpio_direction_output()
367 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_OUT); in bcm2835_gpio_direction_output()
417 static void bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc, in bcm2835_gpio_irq_handle_bank() argument
424 events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4); in bcm2835_gpio_irq_handle_bank()
426 events &= pc->enabled_irq_map[bank]; in bcm2835_gpio_irq_handle_bank()
429 generic_handle_domain_irq(pc->gpio_chip.irq.domain, in bcm2835_gpio_irq_handle_bank()
437 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_handler() local
456 bcm2835_gpio_irq_handle_bank(pc, 0, 0x0fffffff); in bcm2835_gpio_irq_handler()
459 bcm2835_gpio_irq_handle_bank(pc, 0, 0xf0000000); in bcm2835_gpio_irq_handler()
460 bcm2835_gpio_irq_handle_bank(pc, 1, 0x00003fff); in bcm2835_gpio_irq_handler()
463 bcm2835_gpio_irq_handle_bank(pc, 1, 0x003fc000); in bcm2835_gpio_irq_handler()
475 static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_config() argument
480 value = bcm2835_gpio_rd(pc, reg); in __bcm2835_gpio_irq_config()
485 bcm2835_gpio_wr(pc, reg, value); in __bcm2835_gpio_irq_config()
489 static void bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc, in bcm2835_gpio_irq_config() argument
492 switch (pc->irq_type[offset]) { in bcm2835_gpio_irq_config()
494 __bcm2835_gpio_irq_config(pc, GPREN0, offset, enable); in bcm2835_gpio_irq_config()
498 __bcm2835_gpio_irq_config(pc, GPFEN0, offset, enable); in bcm2835_gpio_irq_config()
502 __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, GPHEN0, offset, enable); in bcm2835_gpio_irq_config()
511 __bcm2835_gpio_irq_config(pc, GPLEN0, offset, enable); in bcm2835_gpio_irq_config()
519 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_unmask() local
527 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_unmask()
528 set_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_unmask()
529 bcm2835_gpio_irq_config(pc, gpio, true); in bcm2835_gpio_irq_unmask()
530 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_unmask()
536 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_mask() local
542 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_mask()
543 bcm2835_gpio_irq_config(pc, gpio, false); in bcm2835_gpio_irq_mask()
545 bcm2835_gpio_set_bit(pc, GPEDS0, gpio); in bcm2835_gpio_irq_mask()
546 clear_bit(offset, &pc->enabled_irq_map[bank]); in bcm2835_gpio_irq_mask()
547 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_mask()
552 static int __bcm2835_gpio_irq_set_type_disabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_disabled() argument
562 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_disabled()
572 static int __bcm2835_gpio_irq_set_type_enabled(struct bcm2835_pinctrl *pc, in __bcm2835_gpio_irq_set_type_enabled() argument
577 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
578 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
579 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
584 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
586 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
587 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
588 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
589 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
590 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
591 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
592 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
597 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_BOTH) { in __bcm2835_gpio_irq_set_type_enabled()
599 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; in __bcm2835_gpio_irq_set_type_enabled()
600 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
601 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
602 } else if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
603 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
604 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
605 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
610 if (pc->irq_type[offset] == IRQ_TYPE_EDGE_RISING) { in __bcm2835_gpio_irq_set_type_enabled()
612 pc->irq_type[offset] = IRQ_TYPE_EDGE_FALLING; in __bcm2835_gpio_irq_set_type_enabled()
613 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
614 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
615 } else if (pc->irq_type[offset] == IRQ_TYPE_EDGE_FALLING) { in __bcm2835_gpio_irq_set_type_enabled()
617 pc->irq_type[offset] = IRQ_TYPE_EDGE_RISING; 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] != type) { in __bcm2835_gpio_irq_set_type_enabled()
621 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
622 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
623 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
629 if (pc->irq_type[offset] != type) { in __bcm2835_gpio_irq_set_type_enabled()
630 bcm2835_gpio_irq_config(pc, offset, false); in __bcm2835_gpio_irq_set_type_enabled()
631 pc->irq_type[offset] = type; in __bcm2835_gpio_irq_set_type_enabled()
632 bcm2835_gpio_irq_config(pc, offset, true); in __bcm2835_gpio_irq_set_type_enabled()
645 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_set_type() local
652 raw_spin_lock_irqsave(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
654 if (test_bit(offset, &pc->enabled_irq_map[bank])) in bcm2835_gpio_irq_set_type()
655 ret = __bcm2835_gpio_irq_set_type_enabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
657 ret = __bcm2835_gpio_irq_set_type_disabled(pc, gpio, type); in bcm2835_gpio_irq_set_type()
664 raw_spin_unlock_irqrestore(&pc->irq_lock[bank], flags); in bcm2835_gpio_irq_set_type()
672 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_ack() local
675 bcm2835_gpio_set_bit(pc, GPEDS0, gpio); in bcm2835_gpio_irq_ack()
681 struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); in bcm2835_gpio_irq_set_wake() local
686 if (!pc->wake_irq) in bcm2835_gpio_irq_set_wake()
699 ret = enable_irq_wake(pc->wake_irq[irqgroup]); in bcm2835_gpio_irq_set_wake()
701 ret = disable_irq_wake(pc->wake_irq[irqgroup]); in bcm2835_gpio_irq_set_wake()
743 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_pin_dbg_show() local
744 struct gpio_chip *chip = &pc->gpio_chip; in bcm2835_pctl_pin_dbg_show()
745 enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); in bcm2835_pctl_pin_dbg_show()
747 int value = bcm2835_gpio_get_bit(pc, GPLEV0, offset); in bcm2835_pctl_pin_dbg_show()
752 irq, irq_type_names[pc->irq_type[offset]]); in bcm2835_pctl_pin_dbg_show()
767 static int bcm2835_pctl_dt_node_to_map_func(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_func() argument
774 dev_err(pc->dev, "%pOF: invalid brcm,function %d\n", np, fnum); in bcm2835_pctl_dt_node_to_map_func()
786 static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc, in bcm2835_pctl_dt_node_to_map_pull() argument
794 dev_err(pc->dev, "%pOF: invalid brcm,pull %d\n", np, pull); in bcm2835_pctl_dt_node_to_map_pull()
816 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pctl_dt_node_to_map() local
831 dev_err(pc->dev, "%pOF: missing brcm,pins property\n", np); in bcm2835_pctl_dt_node_to_map()
839 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
850 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
857 dev_err(pc->dev, in bcm2835_pctl_dt_node_to_map()
877 if (pin >= pc->pctl_desc.npins) { in bcm2835_pctl_dt_node_to_map()
878 dev_err(pc->dev, "%pOF: invalid brcm,pins value %d\n", in bcm2835_pctl_dt_node_to_map()
889 err = bcm2835_pctl_dt_node_to_map_func(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
899 err = bcm2835_pctl_dt_node_to_map_pull(pc, np, pin, in bcm2835_pctl_dt_node_to_map()
928 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_free() local
931 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_pmx_free()
962 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_set() local
964 bcm2835_pinctrl_fsel_set(pc, group_selector, func_selector); in bcm2835_pmx_set()
973 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_gpio_disable_free() local
976 bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); in bcm2835_pmx_gpio_disable_free()
984 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pmx_gpio_set_direction() local
988 bcm2835_pinctrl_fsel_set(pc, offset, fsel); in bcm2835_pmx_gpio_set_direction()
1010 static void bcm2835_pull_config_set(struct bcm2835_pinctrl *pc, in bcm2835_pull_config_set() argument
1018 bcm2835_gpio_wr(pc, GPPUD, arg & 3); in bcm2835_pull_config_set()
1026 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit)); in bcm2835_pull_config_set()
1028 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0); in bcm2835_pull_config_set()
1035 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2835_pinconf_set() local
1046 bcm2835_pull_config_set(pc, pin, arg); in bcm2835_pinconf_set()
1051 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_OFF); in bcm2835_pinconf_set()
1055 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_DOWN); in bcm2835_pinconf_set()
1059 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_UP); in bcm2835_pinconf_set()
1064 bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin); in bcm2835_pinconf_set()
1082 static void bcm2711_pull_config_set(struct bcm2835_pinctrl *pc, in bcm2711_pull_config_set() argument
1092 value = bcm2835_gpio_rd(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4)); in bcm2711_pull_config_set()
1095 bcm2835_gpio_wr(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4), value); in bcm2711_pull_config_set()
1102 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); in bcm2711_pinconf_set() local
1120 bcm2711_pull_config_set(pc, pin, arg); in bcm2711_pinconf_set()
1125 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_NONE); in bcm2711_pinconf_set()
1128 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_DOWN); in bcm2711_pinconf_set()
1131 bcm2711_pull_config_set(pc, pin, BCM2711_PULL_UP); in bcm2711_pinconf_set()
1136 bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin); in bcm2711_pinconf_set()
1222 struct bcm2835_pinctrl *pc; in bcm2835_pinctrl_probe() local
1232 pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); in bcm2835_pinctrl_probe()
1233 if (!pc) in bcm2835_pinctrl_probe()
1236 platform_set_drvdata(pdev, pc); in bcm2835_pinctrl_probe()
1237 pc->dev = dev; in bcm2835_pinctrl_probe()
1245 pc->base = devm_ioremap_resource(dev, &iomem); in bcm2835_pinctrl_probe()
1246 if (IS_ERR(pc->base)) in bcm2835_pinctrl_probe()
1247 return PTR_ERR(pc->base); in bcm2835_pinctrl_probe()
1256 pc->gpio_chip = *pdata->gpio_chip; in bcm2835_pinctrl_probe()
1257 pc->gpio_chip.parent = dev; in bcm2835_pinctrl_probe()
1259 spin_lock_init(&pc->fsel_lock); in bcm2835_pinctrl_probe()
1265 bcm2835_gpio_wr(pc, GPREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1266 bcm2835_gpio_wr(pc, GPFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1267 bcm2835_gpio_wr(pc, GPHEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1268 bcm2835_gpio_wr(pc, GPLEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1269 bcm2835_gpio_wr(pc, GPAREN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1270 bcm2835_gpio_wr(pc, GPAFEN0 + i * 4, 0); in bcm2835_pinctrl_probe()
1273 events = bcm2835_gpio_rd(pc, GPEDS0 + i * 4); in bcm2835_pinctrl_probe()
1275 bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset)); in bcm2835_pinctrl_probe()
1277 raw_spin_lock_init(&pc->irq_lock[i]); in bcm2835_pinctrl_probe()
1280 pc->pctl_desc = *pdata->pctl_desc; in bcm2835_pinctrl_probe()
1281 pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc); in bcm2835_pinctrl_probe()
1282 if (IS_ERR(pc->pctl_dev)) { in bcm2835_pinctrl_probe()
1283 gpiochip_remove(&pc->gpio_chip); in bcm2835_pinctrl_probe()
1284 return PTR_ERR(pc->pctl_dev); in bcm2835_pinctrl_probe()
1287 pc->gpio_range = *pdata->gpio_range; in bcm2835_pinctrl_probe()
1288 pc->gpio_range.base = pc->gpio_chip.base; in bcm2835_pinctrl_probe()
1289 pc->gpio_range.gc = &pc->gpio_chip; in bcm2835_pinctrl_probe()
1290 pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); in bcm2835_pinctrl_probe()
1292 girq = &pc->gpio_chip.irq; in bcm2835_pinctrl_probe()
1305 pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS, in bcm2835_pinctrl_probe()
1306 sizeof(*pc->wake_irq), in bcm2835_pinctrl_probe()
1308 if (!pc->wake_irq) { in bcm2835_pinctrl_probe()
1334 pc->wake_irq[i] = irq_of_parse_and_map(np, i + in bcm2835_pinctrl_probe()
1337 len = strlen(dev_name(pc->dev)) + 16; in bcm2835_pinctrl_probe()
1338 name = devm_kzalloc(pc->dev, len, GFP_KERNEL); in bcm2835_pinctrl_probe()
1344 snprintf(name, len, "%s:bank%d", dev_name(pc->dev), i); in bcm2835_pinctrl_probe()
1347 err = devm_request_irq(dev, pc->wake_irq[i], in bcm2835_pinctrl_probe()
1349 IRQF_SHARED, name, pc); in bcm2835_pinctrl_probe()
1352 pc->wake_irq[i]); in bcm2835_pinctrl_probe()
1358 err = gpiochip_add_data(&pc->gpio_chip, pc); in bcm2835_pinctrl_probe()
1367 pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range); in bcm2835_pinctrl_probe()