Пример #1
0
void tegra_irq_to_wake(int irq, int *wak_list, int *wak_size)
{
	int i;

	*wak_size = 0;
	for (i = 0; i < ARRAY_SIZE(tegra_wake_event_irq); i++) {
		if (tegra_wake_event_irq[i] == irq) {
			pr_info("Wake %d for irq=%d\n", i, irq);
			wak_list[*wak_size] = i;
			*wak_size = *wak_size + 1;
		}
	}
	if (*wak_size)
		goto out;

	/* The gpio set_wake code bubbles the set_wake call up to the irq
	 * set_wake code. This insures that the nested irq set_wake call
	 * succeeds, even though it doesn't have to do any pm setup for the
	 * bank.
	 *
	 * This is very fragile - there's no locking, so two callers could
	 * cause issues with this.
	 */
	if (last_gpio < 0)
		goto out;

	if (tegra_gpio_get_bank_int_nr(tegra_gpio_wakes[last_gpio]) == irq) {
		pr_info("gpio bank wake found: wake %d for irq=%d\n", i, irq);
		wak_list[*wak_size] = last_gpio;
		*wak_size = 1;
	}

out:
	return;
}
int tegra_irq_to_wake(int irq)
{
	int i;
	int wake_irq;
	int search_gpio;
	static int last_wake = -1;

	/* Two level wake irq search for gpio based wakeups -
	 * 1. check for GPIO irq(based on tegra_wake_event_irq table)
	 * e.g. for a board, wake7 based on GPIO PU6 and irq==358 done first
	 * 2. check for gpio bank irq assuming search for GPIO irq
	 *    preceded this search.
	 * e.g. in this step check for gpio bank irq GPIO6 irq==119
	 */
	for (i = 0; i < ARRAY_SIZE(tegra_wake_event_irq); i++) {
		/* return if step 1 matches */
		if (tegra_wake_event_irq[i] == irq) {
			pr_info("Wake%d for irq=%d\n", i, irq);
			last_wake = i;
			return i;
		}

		/* step 2 below uses saved last_wake from step 1
		 * in previous call */
		search_gpio = irq_to_gpio(
			tegra_wake_event_irq[i]);
		if (search_gpio < 0)
			continue;
		wake_irq = tegra_gpio_get_bank_int_nr(search_gpio);
		if (wake_irq < 0)
			continue;
		if ((last_wake == i) &&
			(wake_irq == irq)) {
			pr_info("gpio bank wake found: wake%d for irq=%d\n",
				i, irq);
			return i;
		}
	}

	return -EINVAL;
}