static int sh_gpio_to_irq(struct gpio_chip *chip, unsigned offset) { struct pinmux_info *gpioc = chip_to_pinmux(chip); pinmux_enum_t enum_id; pinmux_enum_t *enum_ids; int i, k, pos; pos = 0; enum_id = 0; while (1) { pos = get_gpio_enum_id(gpioc, offset, pos, &enum_id); if (pos <= 0 || !enum_id) break; for (i = 0; i < gpioc->gpio_irq_size; i++) { enum_ids = gpioc->gpio_irq[i].enum_ids; for (k = 0; enum_ids[k]; k++) { if (enum_ids[k] == enum_id) return gpioc->gpio_irq[i].irq; } } } return -ENOSYS; }
static int sh_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { struct pinmux_info *gpioc = chip_to_pinmux(chip); unsigned long flags; int ret; spin_lock_irqsave(&gpio_lock, flags); ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_INPUT); spin_unlock_irqrestore(&gpio_lock, flags); return ret; }
static int sh_gpio_request(struct gpio_chip *chip, unsigned offset) { struct pinmux_info *gpioc = chip_to_pinmux(chip); struct pinmux_data_reg *dummy; unsigned long flags; int i, ret, pinmux_type; ret = -EINVAL; if (!gpioc) goto err_out; spin_lock_irqsave(&gpio_lock, flags); if ((gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE) goto err_unlock; /* setup pin function here if no data is associated with pin */ if (get_data_reg(gpioc, offset, &dummy, &i) != 0) pinmux_type = PINMUX_TYPE_FUNCTION; else pinmux_type = PINMUX_TYPE_GPIO; if (pinmux_type == PINMUX_TYPE_FUNCTION) { if (pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_DRYRUN) != 0) goto err_unlock; if (pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_REQ) != 0) BUG(); } gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; gpioc->gpios[offset].flags |= pinmux_type; ret = 0; err_unlock: spin_unlock_irqrestore(&gpio_lock, flags); err_out: return ret; }
static void sh_gpio_free(struct gpio_chip *chip, unsigned offset) { struct pinmux_info *gpioc = chip_to_pinmux(chip); unsigned long flags; int pinmux_type; if (!gpioc) return; spin_lock_irqsave(&gpio_lock, flags); pinmux_type = gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE; pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_FREE); gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; gpioc->gpios[offset].flags |= PINMUX_TYPE_NONE; spin_unlock_irqrestore(&gpio_lock, flags); }
static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { sh_gpio_set_value(chip_to_pinmux(chip), offset, value); }
static int sh_gpio_get(struct gpio_chip *chip, unsigned offset) { return sh_gpio_get_value(chip_to_pinmux(chip), offset); }