2 * Copyright (c) 2011, Google, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/kernel.h>
16 #include <linux/gpio.h>
17 #include <linux/init.h>
20 #include <mach/gpio-tegra.h>
21 #include <mach/irqs.h>
23 #include "gpio-names.h"
26 /* TODO: We could populate the other table from this one at runtime
27 * instead of always searching twice */
28 static int tegra_gpio_wakes[] = {
39 [10] = TEGRA_GPIO_PAA1,
40 [11] = TEGRA_GPIO_PW3,
41 [12] = TEGRA_GPIO_PW2,
42 [13] = TEGRA_GPIO_PY6,
43 [14] = TEGRA_GPIO_PV6,
44 [15] = TEGRA_GPIO_PJ7,
48 [19] = -EINVAL, /* TEGRA_USB1_VBUS, */
49 [20] = -EINVAL, /* TEGRA_USB3_VBUS, */
50 [21] = -EINVAL, /* TEGRA_USB1_ID, */
51 [22] = -EINVAL, /* TEGRA_USB3_ID, */
52 [23] = TEGRA_GPIO_PI5,
53 [24] = TEGRA_GPIO_PV2,
54 [25] = TEGRA_GPIO_PS4,
55 [26] = TEGRA_GPIO_PS5,
56 [27] = TEGRA_GPIO_PS0,
57 [28] = TEGRA_GPIO_PQ6,
58 [29] = TEGRA_GPIO_PQ7,
59 [30] = TEGRA_GPIO_PN2,
62 static int tegra_wake_event_irq[] = {
63 [0] = -EAGAIN, /* Search the GPIO table */
81 [18] = INT_EXTERNAL_PMU,
82 [19] = -EINVAL, /* TEGRA_USB1_VBUS, */
83 [20] = -EINVAL, /* TEGRA_USB3_VBUS, */
84 [21] = -EINVAL, /* TEGRA_USB1_ID, */
85 [22] = -EINVAL, /* TEGRA_USB3_ID, */
96 int tegra_irq_to_wake(int irq)
99 static int last_wake = -1;
101 for (i = 0; i < ARRAY_SIZE(tegra_wake_event_irq); i++)
102 if (tegra_wake_event_irq[i] == irq)
105 for (i = 0; i < ARRAY_SIZE(tegra_gpio_wakes); i++)
106 if (gpio_to_irq(tegra_gpio_wakes[i]) == irq)
109 /* Two level wake irq search for gpio based wakeups -
110 * 1. check for GPIO irq(based on tegra_wake_event_irq table)
111 * e.g. for a board, wake7 based on GPIO PU6 and irq==358 done first
112 * 2. check for gpio bank irq assuming search for GPIO irq
113 * preceded this search.
114 * e.g. in this step check for gpio bank irq GPIO6 irq==119
116 if (last_wake < 0 || last_wake >= ARRAY_SIZE(tegra_gpio_wakes))
119 if (tegra_gpio_get_bank_int_nr(tegra_gpio_wakes[last_wake]) == irq)
129 int tegra_wake_to_irq(int wake)
136 if (wake >= ARRAY_SIZE(tegra_wake_event_irq))
139 ret = tegra_wake_event_irq[wake];
141 ret = gpio_to_irq(tegra_gpio_wakes[wake]);