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()
691 unsigned int offset; in aspeed_init_irq_valid_mask() local
695 for_each_clear_bit(offset, &input, 32) { in aspeed_init_irq_valid_mask()
696 unsigned int i = props->bank * 32 + offset; in aspeed_init_irq_valid_mask()
709 unsigned int offset, bool enable) in aspeed_gpio_reset_tolerance() argument
717 treg = bank_reg(gpio, to_bank(offset), reg_tolerance); in aspeed_gpio_reset_tolerance()
720 copro = aspeed_gpio_copro_request(gpio, offset); in aspeed_gpio_reset_tolerance()
725 val |= GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
727 val &= ~GPIO_BIT(offset); in aspeed_gpio_reset_tolerance()
732 aspeed_gpio_copro_release(gpio, offset); in aspeed_gpio_reset_tolerance()
738 static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_request() argument
740 if (!have_gpio(gpiochip_get_data(chip), offset)) in aspeed_gpio_request()
743 return pinctrl_gpio_request(chip->base + offset); in aspeed_gpio_request()
746 static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset) in aspeed_gpio_free() argument
748 pinctrl_gpio_free(chip->base + offset); in aspeed_gpio_free()
776 unsigned int offset, unsigned int timer) in register_allocated_timer() argument
778 if (WARN(gpio->offset_timer[offset] != 0, in register_allocated_timer()
780 offset, gpio->offset_timer[offset])) in register_allocated_timer()
787 gpio->offset_timer[offset] = timer; in register_allocated_timer()
795 unsigned int offset) in unregister_allocated_timer() argument
797 if (WARN(gpio->offset_timer[offset] == 0, in unregister_allocated_timer()
798 "No timer allocated to offset %d\n", offset)) in unregister_allocated_timer()
801 if (WARN(gpio->timer_users[gpio->offset_timer[offset]] == 0, in unregister_allocated_timer()
803 gpio->offset_timer[offset])) in unregister_allocated_timer()
806 gpio->timer_users[gpio->offset_timer[offset]]--; in unregister_allocated_timer()
807 gpio->offset_timer[offset] = 0; in unregister_allocated_timer()
814 unsigned int offset) in timer_allocation_registered() argument
816 return gpio->offset_timer[offset] > 0; in timer_allocation_registered()
820 static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset, in configure_timer() argument
823 const struct aspeed_gpio_bank *bank = to_bank(offset); in configure_timer()
824 const u32 mask = GPIO_BIT(offset); in configure_timer()
833 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); in configure_timer()
837 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); in configure_timer()
840 static int enable_debounce(struct gpio_chip *chip, unsigned int offset, in enable_debounce() argument
861 if (timer_allocation_registered(gpio, offset)) { in enable_debounce()
862 rc = unregister_allocated_timer(gpio, offset); in enable_debounce()
901 configure_timer(gpio, offset, 0); in enable_debounce()
915 register_allocated_timer(gpio, offset, i); in enable_debounce()
916 configure_timer(gpio, offset, i); in enable_debounce()
924 static int disable_debounce(struct gpio_chip *chip, unsigned int offset) in disable_debounce() argument
932 rc = unregister_allocated_timer(gpio, offset); in disable_debounce()
934 configure_timer(gpio, offset, 0); in disable_debounce()
941 static int set_debounce(struct gpio_chip *chip, unsigned int offset, in set_debounce() argument
946 if (!have_debounce(gpio, offset)) in set_debounce()
950 return enable_debounce(chip, offset, usecs); in set_debounce()
952 return disable_debounce(chip, offset); in set_debounce()
955 static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, in aspeed_gpio_set_config() argument
962 return set_debounce(chip, offset, arg); in aspeed_gpio_set_config()
966 return pinctrl_gpio_set_config(offset, config); in aspeed_gpio_set_config()
972 return aspeed_gpio_reset_tolerance(chip, offset, arg); in aspeed_gpio_set_config()
1006 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_grab_gpio() local
1007 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_grab_gpio()
1014 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_grab_gpio()
1016 bindex = offset >> 3; in aspeed_gpio_copro_grab_gpio()
1037 *bit = GPIO_OFFSET(offset); in aspeed_gpio_copro_grab_gpio()
1052 int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); in aspeed_gpio_copro_release_gpio() local
1053 const struct aspeed_gpio_bank *bank = to_bank(offset); in aspeed_gpio_copro_release_gpio()
1059 if (offset < 0 || offset > gpio->chip.ngpio) in aspeed_gpio_copro_release_gpio()
1061 bindex = offset >> 3; in aspeed_gpio_copro_release_gpio()