Lines Matching +full:reg +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-or-later
45 * @offset_timer: Maps an offset to an @timer_users index, or zero if disabled
212 const enum aspeed_gpio_reg reg) in bank_reg() argument
214 switch (reg) { in bank_reg()
216 return gpio->base + bank->val_regs + GPIO_VAL_VALUE; in bank_reg()
218 return gpio->base + bank->rdata_reg; in bank_reg()
220 return gpio->base + bank->val_regs + GPIO_VAL_DIR; in bank_reg()
222 return gpio->base + bank->irq_regs + GPIO_IRQ_ENABLE; in bank_reg()
224 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE0; in bank_reg()
226 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE1; in bank_reg()
228 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2; in bank_reg()
230 return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS; in bank_reg()
232 return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL1; in bank_reg()
234 return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL2; in bank_reg()
236 return gpio->base + bank->tolerance_regs; in bank_reg()
238 return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_0; in bank_reg()
240 return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_1; in bank_reg()
253 static const struct aspeed_gpio_bank *to_bank(unsigned int offset) in to_bank() argument
255 unsigned int bank = GPIO_BANK(offset); in to_bank()
263 return !(props->input || props->output); in is_bank_props_sentinel()
267 struct aspeed_gpio *gpio, unsigned int offset) in find_bank_props() argument
269 const struct aspeed_bank_props *props = gpio->config->props; in find_bank_props()
272 if (props->bank == GPIO_BANK(offset)) in find_bank_props()
280 static inline bool have_gpio(struct aspeed_gpio *gpio, unsigned int offset) in have_gpio() argument
282 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_gpio()
283 const struct aspeed_gpio_bank *bank = to_bank(offset); in have_gpio()
284 unsigned int group = GPIO_OFFSET(offset) / 8; in have_gpio()
286 return bank->names[group][0] != '\0' && in have_gpio()
287 (!props || ((props->input | props->output) & GPIO_BIT(offset))); in have_gpio()
290 static inline bool have_input(struct aspeed_gpio *gpio, unsigned int offset) in have_input() argument
292 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_input()
294 return !props || (props->input & GPIO_BIT(offset)); in have_input()
300 static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset) in have_output() argument
302 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_output()
304 return !props || (props->output & GPIO_BIT(offset)); in have_output()
313 u32 bit, reg; in aspeed_gpio_change_cmd_source() local
323 reg = ioread32(c1); in aspeed_gpio_change_cmd_source()
325 reg |= bit; in aspeed_gpio_change_cmd_source()
327 reg &= ~bit; in aspeed_gpio_change_cmd_source()
328 iowrite32(reg, c1); in aspeed_gpio_change_cmd_source()
331 reg = ioread32(c0); in aspeed_gpio_change_cmd_source()
333 reg |= bit; in aspeed_gpio_change_cmd_source()
335 reg &= ~bit; in aspeed_gpio_change_cmd_source()
336 iowrite32(reg, c0); in aspeed_gpio_change_cmd_source()
340 unsigned int offset) in aspeed_gpio_copro_request() argument
342 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_request()
344 if (!copro_ops || !gpio->cf_copro_bankmap) in aspeed_gpio_copro_request()
346 if (!gpio->cf_copro_bankmap[offset >> 3]) in aspeed_gpio_copro_request()
348 if (!copro_ops->request_access) in aspeed_gpio_copro_request()
352 copro_ops->request_access(copro_data); in aspeed_gpio_copro_request()
355 aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, GPIO_CMDSRC_ARM); in aspeed_gpio_copro_request()
358 gpio->dcache[GPIO_BANK(offset)] = ioread32(bank_reg(gpio, bank, reg_rdata)); in aspeed_gpio_copro_request()
364 unsigned int offset) in aspeed_gpio_copro_release() argument
366 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_release()
368 if (!copro_ops || !gpio->cf_copro_bankmap) in aspeed_gpio_copro_release()
370 if (!gpio->cf_copro_bankmap[offset >> 3]) in aspeed_gpio_copro_release()
372 if (!copro_ops->release_access) in aspeed_gpio_copro_release()
376 aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, in aspeed_gpio_copro_release()
380 copro_ops->release_access(copro_data); in aspeed_gpio_copro_release()
383 static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_get() argument
386 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_get()
388 return !!(ioread32(bank_reg(gpio, bank, reg_val)) & GPIO_BIT(offset)); in aspeed_gpio_get()
391 static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, in __aspeed_gpio_set() argument
395 const struct aspeed_gpio_bank *bank = to_bank(offset); in __aspeed_gpio_set()
397 u32 reg; in __aspeed_gpio_set() local
400 reg = gpio->dcache[GPIO_BANK(offset)]; in __aspeed_gpio_set()
403 reg |= GPIO_BIT(offset); in __aspeed_gpio_set()
405 reg &= ~GPIO_BIT(offset); in __aspeed_gpio_set()
406 gpio->dcache[GPIO_BANK(offset)] = reg; in __aspeed_gpio_set()
408 iowrite32(reg, addr); in __aspeed_gpio_set()
413 static void aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, in aspeed_gpio_set() argument
420 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_set()
421 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_set()
423 __aspeed_gpio_set(gc, offset, val); in aspeed_gpio_set()
426 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_set()
427 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_set()
430 static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_dir_in() argument
433 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_dir_in()
437 u32 reg; in aspeed_gpio_dir_in() local
439 if (!have_input(gpio, offset)) in aspeed_gpio_dir_in()
440 return -ENOTSUPP; in aspeed_gpio_dir_in()
442 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_dir_in()
444 reg = ioread32(addr); in aspeed_gpio_dir_in()
445 reg &= ~GPIO_BIT(offset); in aspeed_gpio_dir_in()
447 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_dir_in()
448 iowrite32(reg, addr); in aspeed_gpio_dir_in()
450 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_dir_in()
452 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_dir_in()
458 unsigned int offset, int val) in aspeed_gpio_dir_out() argument
461 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_dir_out()
465 u32 reg; in aspeed_gpio_dir_out() local
467 if (!have_output(gpio, offset)) in aspeed_gpio_dir_out()
468 return -ENOTSUPP; in aspeed_gpio_dir_out()
470 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_dir_out()
472 reg = ioread32(addr); in aspeed_gpio_dir_out()
473 reg |= GPIO_BIT(offset); in aspeed_gpio_dir_out()
475 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_dir_out()
476 __aspeed_gpio_set(gc, offset, val); in aspeed_gpio_dir_out()
477 iowrite32(reg, addr); in aspeed_gpio_dir_out()
480 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_dir_out()
481 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_dir_out()
486 static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_get_direction() argument
489 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_get_direction()
493 if (!have_input(gpio, offset)) in aspeed_gpio_get_direction()
496 if (!have_output(gpio, offset)) in aspeed_gpio_get_direction()
499 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_get_direction()
501 val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset); in aspeed_gpio_get_direction()
503 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_get_direction()
511 u32 *bit, int *offset) in irqd_to_aspeed_gpio_data() argument
515 *offset = irqd_to_hwirq(d); in irqd_to_aspeed_gpio_data()
520 if (!have_irq(internal, *offset)) in irqd_to_aspeed_gpio_data()
521 return -ENOTSUPP; in irqd_to_aspeed_gpio_data()
524 *bank = to_bank(*offset); in irqd_to_aspeed_gpio_data()
525 *bit = GPIO_BIT(*offset); in irqd_to_aspeed_gpio_data()
536 int rc, offset; in aspeed_gpio_irq_ack() local
540 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_irq_ack()
546 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_irq_ack()
547 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_irq_ack()
552 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_irq_ack()
553 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_irq_ack()
561 u32 reg, bit; in aspeed_gpio_irq_set_mask() local
563 int rc, offset; in aspeed_gpio_irq_set_mask() local
566 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_irq_set_mask()
574 gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); in aspeed_gpio_irq_set_mask()
576 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_irq_set_mask()
577 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_irq_set_mask()
579 reg = ioread32(addr); in aspeed_gpio_irq_set_mask()
581 reg |= bit; in aspeed_gpio_irq_set_mask()
583 reg &= ~bit; in aspeed_gpio_irq_set_mask()
584 iowrite32(reg, addr); in aspeed_gpio_irq_set_mask()
587 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_irq_set_mask()
588 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_irq_set_mask()
592 gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); in aspeed_gpio_irq_set_mask()
610 u32 bit, reg; in aspeed_gpio_set_type() local
616 int rc, offset; in aspeed_gpio_set_type() local
619 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_set_type()
621 return -EINVAL; in aspeed_gpio_set_type()
641 return -EINVAL; in aspeed_gpio_set_type()
644 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_set_type()
645 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_set_type()
648 reg = ioread32(addr); in aspeed_gpio_set_type()
649 reg = (reg & ~bit) | type0; in aspeed_gpio_set_type()
650 iowrite32(reg, addr); in aspeed_gpio_set_type()
653 reg = ioread32(addr); in aspeed_gpio_set_type()
654 reg = (reg & ~bit) | type1; in aspeed_gpio_set_type()
655 iowrite32(reg, addr); in aspeed_gpio_set_type()
658 reg = ioread32(addr); in aspeed_gpio_set_type()
659 reg = (reg & ~bit) | type2; in aspeed_gpio_set_type()
660 iowrite32(reg, addr); in aspeed_gpio_set_type()
663 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_set_type()
664 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_set_type()
677 unsigned long reg; in aspeed_gpio_irq_handler() local
682 banks = DIV_ROUND_UP(gpio->chip.ngpio, 32); in aspeed_gpio_irq_handler()
686 reg = ioread32(bank_reg(data, bank, reg_irq_status)); in aspeed_gpio_irq_handler()
688 for_each_set_bit(p, ®, 32) in aspeed_gpio_irq_handler()
689 generic_handle_domain_irq(gc->irq.domain, i * 32 + p); in aspeed_gpio_irq_handler()
700 const struct aspeed_bank_props *props = gpio->config->props; in aspeed_init_irq_valid_mask()
703 unsigned int offset; in aspeed_init_irq_valid_mask() local
704 const unsigned long int input = props->input; in aspeed_init_irq_valid_mask()
707 for_each_clear_bit(offset, &input, 32) { in aspeed_init_irq_valid_mask()
708 unsigned int i = props->bank * 32 + offset; in aspeed_init_irq_valid_mask()
710 if (i >= gpio->chip.ngpio) in aspeed_init_irq_valid_mask()
721 unsigned int offset, bool enable) in aspeed_gpio_reset_tolerance() argument
729 treg = bank_reg(gpio, to_bank(offset), reg_tolerance); in aspeed_gpio_reset_tolerance()
731 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_reset_tolerance()
732 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_reset_tolerance()
737 val |= GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
739 val &= ~GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
744 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_reset_tolerance()
745 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_reset_tolerance()
750 static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_request() argument
752 if (!have_gpio(gpiochip_get_data(chip), offset)) in aspeed_gpio_request()
753 return -ENODEV; in aspeed_gpio_request()
755 return pinctrl_gpio_request(chip, offset); in aspeed_gpio_request()
758 static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_free() argument
760 pinctrl_gpio_free(chip, offset); in aspeed_gpio_free()
770 rate = clk_get_rate(gpio->clk); in usecs_to_cycles()
772 return -ENOTSUPP; in usecs_to_cycles()
778 return -ERANGE; in usecs_to_cycles()
786 /* Call under gpio->lock */
788 unsigned int offset, unsigned int timer) in register_allocated_timer() argument
790 if (WARN(gpio->offset_timer[offset] != 0, in register_allocated_timer()
791 "Offset %d already allocated timer %d\n", in register_allocated_timer()
792 offset, gpio->offset_timer[offset])) in register_allocated_timer()
793 return -EINVAL; in register_allocated_timer()
795 if (WARN(gpio->timer_users[timer] == UINT_MAX, in register_allocated_timer()
797 return -EPERM; in register_allocated_timer()
799 gpio->offset_timer[offset] = timer; in register_allocated_timer()
800 gpio->timer_users[timer]++; in register_allocated_timer()
805 /* Call under gpio->lock */
807 unsigned int offset) in unregister_allocated_timer() argument
809 if (WARN(gpio->offset_timer[offset] == 0, in unregister_allocated_timer()
810 "No timer allocated to offset %d\n", offset)) in unregister_allocated_timer()
811 return -EINVAL; in unregister_allocated_timer()
813 if (WARN(gpio->timer_users[gpio->offset_timer[offset]] == 0, in unregister_allocated_timer()
815 gpio->offset_timer[offset])) in unregister_allocated_timer()
816 return -EINVAL; in unregister_allocated_timer()
818 gpio->timer_users[gpio->offset_timer[offset]]--; in unregister_allocated_timer()
819 gpio->offset_timer[offset] = 0; in unregister_allocated_timer()
824 /* Call under gpio->lock */
826 unsigned int offset) in timer_allocation_registered() argument
828 return gpio->offset_timer[offset] > 0; in timer_allocation_registered()
831 /* Call under gpio->lock */
832 static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset, in configure_timer() argument
835 const struct aspeed_gpio_bank *bank = to_bank(offset); in configure_timer()
836 const u32 mask = GPIO_BIT(offset); in configure_timer()
845 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); in configure_timer()
849 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); in configure_timer()
852 static int enable_debounce(struct gpio_chip *chip, unsigned int offset, in enable_debounce() argument
861 if (!gpio->clk) in enable_debounce()
862 return -EINVAL; in enable_debounce()
866 dev_warn(chip->parent, "Failed to convert %luus to cycles at %luHz: %d\n", in enable_debounce()
867 usecs, clk_get_rate(gpio->clk), rc); in enable_debounce()
871 raw_spin_lock_irqsave(&gpio->lock, flags); in enable_debounce()
873 if (timer_allocation_registered(gpio, offset)) { in enable_debounce()
874 rc = unregister_allocated_timer(gpio, offset); in enable_debounce()
883 cycles = ioread32(gpio->base + debounce_timers[i]); in enable_debounce()
895 for (j = 1; j < ARRAY_SIZE(gpio->timer_users); j++) { in enable_debounce()
896 if (gpio->timer_users[j] == 0) in enable_debounce()
900 if (j == ARRAY_SIZE(gpio->timer_users)) { in enable_debounce()
901 dev_warn(chip->parent, in enable_debounce()
905 rc = -EPERM; in enable_debounce()
908 * We already adjusted the accounting to remove @offset in enable_debounce()
910 * the hardware so @offset has timers disabled for in enable_debounce()
913 configure_timer(gpio, offset, 0); in enable_debounce()
919 iowrite32(requested_cycles, gpio->base + debounce_timers[i]); in enable_debounce()
923 rc = -EINVAL; in enable_debounce()
927 register_allocated_timer(gpio, offset, i); in enable_debounce()
928 configure_timer(gpio, offset, i); in enable_debounce()
931 raw_spin_unlock_irqrestore(&gpio->lock, flags); in enable_debounce()
936 static int disable_debounce(struct gpio_chip *chip, unsigned int offset) in disable_debounce() argument
942 raw_spin_lock_irqsave(&gpio->lock, flags); in disable_debounce()
944 rc = unregister_allocated_timer(gpio, offset); in disable_debounce()
946 configure_timer(gpio, offset, 0); in disable_debounce()
948 raw_spin_unlock_irqrestore(&gpio->lock, flags); in disable_debounce()
953 static int set_debounce(struct gpio_chip *chip, unsigned int offset, in set_debounce() argument
958 if (!have_debounce(gpio, offset)) in set_debounce()
959 return -ENOTSUPP; in set_debounce()
962 return enable_debounce(chip, offset, usecs); in set_debounce()
964 return disable_debounce(chip, offset); in set_debounce()
967 static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, in aspeed_gpio_set_config() argument
974 return set_debounce(chip, offset, arg); in aspeed_gpio_set_config()
978 return pinctrl_gpio_set_config(chip, offset, config); in aspeed_gpio_set_config()
981 /* Return -ENOTSUPP to trigger emulation, as per datasheet */ in aspeed_gpio_set_config()
982 return -ENOTSUPP; in aspeed_gpio_set_config()
984 return aspeed_gpio_reset_tolerance(chip, offset, arg); in aspeed_gpio_set_config()
986 return -ENOTSUPP; in aspeed_gpio_set_config()
990 * aspeed_gpio_copro_set_ops - Sets the callbacks used for handshaking with
1005 * aspeed_gpio_copro_grab_gpio - Mark a GPIO used by the coprocessor. The entire
1009 * @vreg_offset: If non-NULL, returns the value register offset in the GPIO space
1010 * @dreg_offset: If non-NULL, returns the data latch register offset in the GPIO space
1011 * @bit: If non-NULL, returns the bit number of the GPIO in the registers
1018 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_grab_gpio() local
1019 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_grab_gpio()
1022 if (!gpio->cf_copro_bankmap) in aspeed_gpio_copro_grab_gpio()
1023 gpio->cf_copro_bankmap = kzalloc(gpio->chip.ngpio >> 3, GFP_KERNEL); in aspeed_gpio_copro_grab_gpio()
1024 if (!gpio->cf_copro_bankmap) in aspeed_gpio_copro_grab_gpio()
1025 return -ENOMEM; in aspeed_gpio_copro_grab_gpio()
1026 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_grab_gpio()
1027 return -EINVAL; in aspeed_gpio_copro_grab_gpio()
1028 bindex = offset >> 3; in aspeed_gpio_copro_grab_gpio()
1030 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_copro_grab_gpio()
1033 if (gpio->cf_copro_bankmap[bindex] == 0xff) { in aspeed_gpio_copro_grab_gpio()
1034 rc = -EIO; in aspeed_gpio_copro_grab_gpio()
1037 gpio->cf_copro_bankmap[bindex]++; in aspeed_gpio_copro_grab_gpio()
1040 if (gpio->cf_copro_bankmap[bindex] == 1) in aspeed_gpio_copro_grab_gpio()
1045 *vreg_offset = bank->val_regs; in aspeed_gpio_copro_grab_gpio()
1047 *dreg_offset = bank->rdata_reg; in aspeed_gpio_copro_grab_gpio()
1049 *bit = GPIO_OFFSET(offset); in aspeed_gpio_copro_grab_gpio()
1051 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_copro_grab_gpio()
1057 * aspeed_gpio_copro_release_gpio - Unmark a GPIO used by the coprocessor.
1064 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_release_gpio() local
1065 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_release_gpio()
1068 if (!gpio->cf_copro_bankmap) in aspeed_gpio_copro_release_gpio()
1069 return -ENXIO; in aspeed_gpio_copro_release_gpio()
1071 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_release_gpio()
1072 return -EINVAL; in aspeed_gpio_copro_release_gpio()
1073 bindex = offset >> 3; in aspeed_gpio_copro_release_gpio()
1075 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_gpio_copro_release_gpio()
1078 if (gpio->cf_copro_bankmap[bindex] == 0) { in aspeed_gpio_copro_release_gpio()
1079 rc = -EIO; in aspeed_gpio_copro_release_gpio()
1082 gpio->cf_copro_bankmap[bindex]--; in aspeed_gpio_copro_release_gpio()
1085 if (gpio->cf_copro_bankmap[bindex] == 0) in aspeed_gpio_copro_release_gpio()
1089 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_gpio_copro_release_gpio()
1099 int rc, offset; in aspeed_gpio_irq_print_chip() local
1101 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_irq_print_chip()
1105 seq_printf(p, dev_name(gpio->dev)); in aspeed_gpio_irq_print_chip()
1128 { 6, 0x0000000f, 0x0fffff0f }, /* Y/Z/AA/AB, two 4-GPIO holes */
1133 /* 220 for simplicity, really 216 with two 4-GPIO holes, four at end */
1139 { 6, 0x0fffffff, 0x0fffffff }, /* Y/Z/AA/AB, 4-GPIO hole */
1145 /* 232 for simplicity, actual number is 228 (4-GPIO hole in GPIOAB) */
1165 { .compatible = "aspeed,ast2400-gpio", .data = &ast2400_config, },
1166 { .compatible = "aspeed,ast2500-gpio", .data = &ast2500_config, },
1167 { .compatible = "aspeed,ast2600-gpio", .data = &ast2600_config, },
1180 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); in aspeed_gpio_probe()
1182 return -ENOMEM; in aspeed_gpio_probe()
1184 gpio->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_gpio_probe()
1185 if (IS_ERR(gpio->base)) in aspeed_gpio_probe()
1186 return PTR_ERR(gpio->base); in aspeed_gpio_probe()
1188 gpio->dev = &pdev->dev; in aspeed_gpio_probe()
1190 raw_spin_lock_init(&gpio->lock); in aspeed_gpio_probe()
1192 gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node); in aspeed_gpio_probe()
1194 return -EINVAL; in aspeed_gpio_probe()
1196 gpio->clk = devm_clk_get_enabled(&pdev->dev, NULL); in aspeed_gpio_probe()
1197 if (IS_ERR(gpio->clk)) { in aspeed_gpio_probe()
1198 dev_warn(&pdev->dev, in aspeed_gpio_probe()
1200 gpio->clk = NULL; in aspeed_gpio_probe()
1203 gpio->config = gpio_id->data; in aspeed_gpio_probe()
1205 gpio->chip.parent = &pdev->dev; in aspeed_gpio_probe()
1206 err = of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpio); in aspeed_gpio_probe()
1207 gpio->chip.ngpio = (u16) ngpio; in aspeed_gpio_probe()
1209 gpio->chip.ngpio = gpio->config->nr_gpios; in aspeed_gpio_probe()
1210 gpio->chip.direction_input = aspeed_gpio_dir_in; in aspeed_gpio_probe()
1211 gpio->chip.direction_output = aspeed_gpio_dir_out; in aspeed_gpio_probe()
1212 gpio->chip.get_direction = aspeed_gpio_get_direction; in aspeed_gpio_probe()
1213 gpio->chip.request = aspeed_gpio_request; in aspeed_gpio_probe()
1214 gpio->chip.free = aspeed_gpio_free; in aspeed_gpio_probe()
1215 gpio->chip.get = aspeed_gpio_get; in aspeed_gpio_probe()
1216 gpio->chip.set = aspeed_gpio_set; in aspeed_gpio_probe()
1217 gpio->chip.set_config = aspeed_gpio_set_config; in aspeed_gpio_probe()
1218 gpio->chip.label = dev_name(&pdev->dev); in aspeed_gpio_probe()
1219 gpio->chip.base = -1; in aspeed_gpio_probe()
1222 banks = DIV_ROUND_UP(gpio->chip.ngpio, 32); in aspeed_gpio_probe()
1223 gpio->dcache = devm_kcalloc(&pdev->dev, in aspeed_gpio_probe()
1225 if (!gpio->dcache) in aspeed_gpio_probe()
1226 return -ENOMEM; in aspeed_gpio_probe()
1235 gpio->dcache[i] = ioread32(addr); in aspeed_gpio_probe()
1246 gpio->irq = irq; in aspeed_gpio_probe()
1247 girq = &gpio->chip.irq; in aspeed_gpio_probe()
1250 girq->parent_handler = aspeed_gpio_irq_handler; in aspeed_gpio_probe()
1251 girq->num_parents = 1; in aspeed_gpio_probe()
1252 girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), GFP_KERNEL); in aspeed_gpio_probe()
1253 if (!girq->parents) in aspeed_gpio_probe()
1254 return -ENOMEM; in aspeed_gpio_probe()
1255 girq->parents[0] = gpio->irq; in aspeed_gpio_probe()
1256 girq->default_type = IRQ_TYPE_NONE; in aspeed_gpio_probe()
1257 girq->handler = handle_bad_irq; in aspeed_gpio_probe()
1258 girq->init_valid_mask = aspeed_init_irq_valid_mask; in aspeed_gpio_probe()
1260 gpio->offset_timer = in aspeed_gpio_probe()
1261 devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL); in aspeed_gpio_probe()
1262 if (!gpio->offset_timer) in aspeed_gpio_probe()
1263 return -ENOMEM; in aspeed_gpio_probe()
1265 rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); in aspeed_gpio_probe()