Lines Matching refs:offset
251 static const struct aspeed_gpio_bank *to_bank(unsigned int offset) in to_bank() argument
253 unsigned int bank = GPIO_BANK(offset); in to_bank()
265 struct aspeed_gpio *gpio, unsigned int offset) in find_bank_props() argument
270 if (props->bank == GPIO_BANK(offset)) in find_bank_props()
278 static inline bool have_gpio(struct aspeed_gpio *gpio, unsigned int offset) in have_gpio() argument
280 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_gpio()
281 const struct aspeed_gpio_bank *bank = to_bank(offset); in have_gpio()
282 unsigned int group = GPIO_OFFSET(offset) / 8; in have_gpio()
285 (!props || ((props->input | props->output) & GPIO_BIT(offset))); in have_gpio()
288 static inline bool have_input(struct aspeed_gpio *gpio, unsigned int offset) in have_input() argument
290 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_input()
292 return !props || (props->input & GPIO_BIT(offset)); in have_input()
298 static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset) in have_output() argument
300 const struct aspeed_bank_props *props = find_bank_props(gpio, offset); in have_output()
302 return !props || (props->output & GPIO_BIT(offset)); in have_output()
338 unsigned int offset) in aspeed_gpio_copro_request() argument
340 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_request()
344 if (!gpio->cf_copro_bankmap[offset >> 3]) in aspeed_gpio_copro_request()
353 aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, GPIO_CMDSRC_ARM); in aspeed_gpio_copro_request()
356 gpio->dcache[GPIO_BANK(offset)] = ioread32(bank_reg(gpio, bank, reg_rdata)); in aspeed_gpio_copro_request()
362 unsigned int offset) in aspeed_gpio_copro_release() argument
364 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_release()
368 if (!gpio->cf_copro_bankmap[offset >> 3]) in aspeed_gpio_copro_release()
374 aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, in aspeed_gpio_copro_release()
381 static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_get() argument
384 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_get()
386 return !!(ioread32(bank_reg(gpio, bank, reg_val)) & GPIO_BIT(offset)); in aspeed_gpio_get()
389 static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, in __aspeed_gpio_set() argument
393 const struct aspeed_gpio_bank *bank = to_bank(offset); in __aspeed_gpio_set()
398 reg = gpio->dcache[GPIO_BANK(offset)]; in __aspeed_gpio_set()
401 reg |= GPIO_BIT(offset); in __aspeed_gpio_set()
403 reg &= ~GPIO_BIT(offset); in __aspeed_gpio_set()
404 gpio->dcache[GPIO_BANK(offset)] = reg; in __aspeed_gpio_set()
409 static void aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, in aspeed_gpio_set() argument
417 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_set()
419 __aspeed_gpio_set(gc, offset, val); in aspeed_gpio_set()
422 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_set()
426 static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_dir_in() argument
429 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_dir_in()
435 if (!have_input(gpio, offset)) in aspeed_gpio_dir_in()
441 reg &= ~GPIO_BIT(offset); in aspeed_gpio_dir_in()
443 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_dir_in()
446 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_dir_in()
454 unsigned int offset, int val) in aspeed_gpio_dir_out() argument
457 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_dir_out()
463 if (!have_output(gpio, offset)) in aspeed_gpio_dir_out()
469 reg |= GPIO_BIT(offset); in aspeed_gpio_dir_out()
471 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_dir_out()
472 __aspeed_gpio_set(gc, offset, val); in aspeed_gpio_dir_out()
476 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_dir_out()
482 static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) in aspeed_gpio_get_direction() argument
485 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_get_direction()
489 if (!have_input(gpio, offset)) in aspeed_gpio_get_direction()
492 if (!have_output(gpio, offset)) in aspeed_gpio_get_direction()
497 val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset); in aspeed_gpio_get_direction()
507 u32 *bit, int *offset) in irqd_to_aspeed_gpio_data() argument
511 *offset = irqd_to_hwirq(d); in irqd_to_aspeed_gpio_data()
516 if (!have_irq(internal, *offset)) in irqd_to_aspeed_gpio_data()
520 *bank = to_bank(*offset); in irqd_to_aspeed_gpio_data()
521 *bit = GPIO_BIT(*offset); in irqd_to_aspeed_gpio_data()
532 int rc, offset; in aspeed_gpio_irq_ack() local
536 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_irq_ack()
543 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_irq_ack()
548 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_irq_ack()
559 int rc, offset; in aspeed_gpio_irq_set_mask() local
562 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_irq_set_mask()
569 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_irq_set_mask()
579 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_irq_set_mask()
604 int rc, offset; in aspeed_gpio_set_type() local
607 rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_gpio_set_type()
633 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_set_type()
651 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_set_type()
694 unsigned int offset; in aspeed_init_irq_valid_mask() local
698 for_each_clear_bit(offset, &input, 32) { in aspeed_init_irq_valid_mask()
699 unsigned int i = props->bank * 32 + offset; in aspeed_init_irq_valid_mask()
712 unsigned int offset, bool enable) in aspeed_gpio_reset_tolerance() argument
720 treg = bank_reg(gpio, to_bank(offset), reg_tolerance); in aspeed_gpio_reset_tolerance()
723 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_reset_tolerance()
728 val |= GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
730 val &= ~GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
735 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_reset_tolerance()
741 static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_request() argument
743 if (!have_gpio(gpiochip_get_data(chip), offset)) in aspeed_gpio_request()
746 return pinctrl_gpio_request(chip->base + offset); in aspeed_gpio_request()
749 static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_free() argument
751 pinctrl_gpio_free(chip->base + offset); in aspeed_gpio_free()
779 unsigned int offset, unsigned int timer) in register_allocated_timer() argument
781 if (WARN(gpio->offset_timer[offset] != 0, in register_allocated_timer()
783 offset, gpio->offset_timer[offset])) in register_allocated_timer()
790 gpio->offset_timer[offset] = timer; in register_allocated_timer()
798 unsigned int offset) in unregister_allocated_timer() argument
800 if (WARN(gpio->offset_timer[offset] == 0, in unregister_allocated_timer()
801 "No timer allocated to offset %d\n", offset)) in unregister_allocated_timer()
804 if (WARN(gpio->timer_users[gpio->offset_timer[offset]] == 0, in unregister_allocated_timer()
806 gpio->offset_timer[offset])) in unregister_allocated_timer()
809 gpio->timer_users[gpio->offset_timer[offset]]--; in unregister_allocated_timer()
810 gpio->offset_timer[offset] = 0; in unregister_allocated_timer()
817 unsigned int offset) in timer_allocation_registered() argument
819 return gpio->offset_timer[offset] > 0; in timer_allocation_registered()
823 static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset, in configure_timer() argument
826 const struct aspeed_gpio_bank *bank = to_bank(offset); in configure_timer()
827 const u32 mask = GPIO_BIT(offset); in configure_timer()
836 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); in configure_timer()
840 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); in configure_timer()
843 static int enable_debounce(struct gpio_chip *chip, unsigned int offset, in enable_debounce() argument
864 if (timer_allocation_registered(gpio, offset)) { in enable_debounce()
865 rc = unregister_allocated_timer(gpio, offset); in enable_debounce()
904 configure_timer(gpio, offset, 0); in enable_debounce()
918 register_allocated_timer(gpio, offset, i); in enable_debounce()
919 configure_timer(gpio, offset, i); in enable_debounce()
927 static int disable_debounce(struct gpio_chip *chip, unsigned int offset) in disable_debounce() argument
935 rc = unregister_allocated_timer(gpio, offset); in disable_debounce()
937 configure_timer(gpio, offset, 0); in disable_debounce()
944 static int set_debounce(struct gpio_chip *chip, unsigned int offset, in set_debounce() argument
949 if (!have_debounce(gpio, offset)) in set_debounce()
953 return enable_debounce(chip, offset, usecs); in set_debounce()
955 return disable_debounce(chip, offset); in set_debounce()
958 static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, in aspeed_gpio_set_config() argument
965 return set_debounce(chip, offset, arg); in aspeed_gpio_set_config()
969 return pinctrl_gpio_set_config(chip->base + offset, config); in aspeed_gpio_set_config()
975 return aspeed_gpio_reset_tolerance(chip, offset, arg); in aspeed_gpio_set_config()
1009 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_grab_gpio() local
1010 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_grab_gpio()
1017 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_grab_gpio()
1019 bindex = offset >> 3; in aspeed_gpio_copro_grab_gpio()
1040 *bit = GPIO_OFFSET(offset); in aspeed_gpio_copro_grab_gpio()
1055 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_release_gpio() local
1056 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_release_gpio()
1062 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_release_gpio()
1064 bindex = offset >> 3; in aspeed_gpio_copro_release_gpio()