arm: tegra: Tegra12x wake table created
[linux-3.10.git] / arch / arm / mach-tegra / wakeups-t12x.c
1 /*
2  * Copyright (c) 2012, NVIDIA Corporation.
3  *
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.
8  *
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
12  * more details.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/gpio.h>
17 #include <linux/init.h>
18 #include <linux/io.h>
19
20 #include <mach/irqs.h>
21 #include <mach/gpio-tegra.h>
22
23 #include "gpio-names.h"
24 #include "iomap.h"
25
26 static int tegra_gpio_wakes[] = {
27         -EINVAL,                                /* wake0 */
28         TEGRA_GPIO_PV1,                         /* wake1 */
29         -EINVAL,                                /* wake2 */
30         -EINVAL,                                /* wake3 */
31         -EINVAL,                                /* wake4 */
32         -EINVAL,                                /* wake5 */
33         TEGRA_GPIO_PU5,                         /* wake6 */
34         TEGRA_GPIO_PU6,                         /* wake7 */
35         TEGRA_GPIO_PC7,                         /* wake8 */
36         TEGRA_GPIO_PS2,                         /* wake9 */
37         -EINVAL,                                /* wake10 */
38         TEGRA_GPIO_PW3,                         /* wake11 */
39         TEGRA_GPIO_PW2,                         /* wake12 */
40         -EINVAL,                                /* wake13 */
41         TEGRA_GPIO_PDD3,                        /* wake14 */
42         -EINVAL,                                /* wake15 */
43         -EINVAL,                                /* wake16 */
44         -EINVAL,                                /* wake17 */
45         -EINVAL,                                /* wake18 */
46         -EINVAL,                                /* wake19 */
47         -EINVAL,                                /* wake20 */
48         -EINVAL,                                /* wake21 */
49         -EINVAL,                                /* wake22 */
50         TEGRA_GPIO_PI5,                         /* wake23 */
51         TEGRA_GPIO_PV0,                         /* wake24 */
52         -EINVAL,                                /* wake25 */
53         -EINVAL,                                /* wake26 */
54         TEGRA_GPIO_PS0,                         /* wake27 */
55         -EINVAL,                                /* wake28 */
56         -EINVAL,                                /* wake29 */
57         -EINVAL,                                /* wake30 */
58         -EINVAL,                                /* wake31 */
59         -EINVAL,                                /* wake32 */
60         TEGRA_GPIO_PJ0,                         /* wake33 */
61         TEGRA_GPIO_PK2,                         /* wake34 */
62         TEGRA_GPIO_PI6,                         /* wake35 */
63         -EINVAL,                                /* wake36 */
64         -EINVAL,                                /* wake37 */
65         -EINVAL,                                /* wake38 */
66         -EINVAL,                                /* wake39 */
67         -EINVAL,                                /* wake40 */
68         -EINVAL,                                /* wake41 */
69         -EINVAL,                                /* wake42 */
70         -EINVAL,                                /* wake43 */
71         -EINVAL,                                /* wake44 */
72         TEGRA_GPIO_PBB6,                        /* wake45 */
73         -EINVAL,                                /* wake46 */
74         TEGRA_GPIO_PT6,                         /* wake47 */
75         -EINVAL,                                /* wake48 */
76         TEGRA_GPIO_PR7,                         /* wake49 */
77         TEGRA_GPIO_PR4,                         /* wake50 */
78         TEGRA_GPIO_PQ0,                         /* wake51 */
79         -EINVAL,                                /* wake52 */
80         -EINVAL,                                /* wake53 */
81         TEGRA_GPIO_PQ5,                         /* wake54 */
82         -EINVAL,                                /* wake55 */
83         TEGRA_GPIO_PV2,                         /* wake56 */
84         -EINVAL,                                /* wake57 */
85         -EINVAL,                                /* wake58 */
86 };
87
88 static int tegra_wake_event_irq[] = {
89         INT_USB2, /* ULPI DATA4 */              /* wake0 */
90         -EAGAIN,                                /* wake1 */
91         -EAGAIN,                                /* wake2 */
92         INT_SDMMC3, /* SDMMC3 DAT1 */           /* wake3 */
93         INT_HDMI, /* HDMI INT */                /* wake4 */
94         -EAGAIN,                                /* wake5 */
95         -EAGAIN,                                /* wake6 */
96         -EAGAIN,                                /* wake7 */
97         -EAGAIN,                                /* wake8 */
98         INT_UARTC, /* UART3 RXD */              /* wake9 */
99         INT_SDMMC4, /* SDMMC4 DAT1 */           /* wake10 */
100         -EAGAIN,                                /* wake11 */
101         -EAGAIN,                                /* wake12 */
102         INT_SDMMC1, /* SDMMC1 DAT1 */           /* wake13 */
103         -EAGAIN,                                /* wake14 */
104         -EAGAIN, /* !!!FIXME!!! INT_THERMAL */  /* wake15 */
105         INT_RTC,                                /* wake16 */
106         INT_KBC,                                /* wake17 */
107         INT_EXTERNAL_PMU,                       /* wake18 */
108         INT_USB,                                /* wake19 */
109         -EINVAL,                                /* wake20 */
110         INT_USB,                                /* wake21 */
111         -EINVAL,                                /* wake22 */
112         -EAGAIN,                                /* wake23 */
113         -EAGAIN,                                /* wake24 */
114         -EAGAIN,                                /* wake25 */
115         -EAGAIN,                                /* wake26 */
116         -EAGAIN,                                /* wake27 */
117         -EAGAIN,                                /* wake28 */
118         -EAGAIN,                                /* wake29 */
119         INT_AUDIO_CLUSTER, /* I2S0 SDATA OUT */         /* wake30 */
120         -EINVAL,                                /* wake31 */
121         INT_USB2, /* ULPI DATA3 */              /* wake32 */
122         -EAGAIN,                                /* wake33 */
123         -EAGAIN,                                /* wake34 */
124         -EAGAIN,                                /* wake35 */
125         -EAGAIN,                                /* wake36 */
126         -EINVAL, /* TEGRA_USB3_VBUS, */         /* wake37 */
127         -EINVAL, /* TEGRA_USB3_ID, */           /* wake38 */
128         INT_USB, /* TEGRA_USB1_UTMIP, */        /* wake39 */
129         -EINVAL,                                /* wake40 */
130         INT_USB3, /* TEGRA_USB3_UTMIP, */       /* wake41 */
131         INT_USB, /* USB1 UHSIC PHY */           /* wake42 */
132         INT_USB3, /* USB3 UHSIC PHY */          /* wake43 */
133         INT_I2C, /* I2C1 DAT */         /* wake44 */
134         -EAGAIN,                                /* wake45 */
135         INT_I2C5, /* PWR I2C DAT */             /* wake46 */
136         INT_I2C2, /* I2C2 DAT */                /* wake47 */
137         INT_I2C3, /* I2C3 DAT */                /* wake48 */
138         -EAGAIN,                                /* wake49 */
139         -EAGAIN,                                /* wake50 */
140         INT_KBC, /* KBC11 */                    /* wake51 */
141         INT_HDMI, /* HDMI CEC */                /* wake52 */
142         INT_I2C3, /* I2C3 CLK */                /* wake53 */
143         -EAGAIN,                                /* wake54 */
144         INT_UARTC, /* UART3 CTS */              /* wake55 */
145         INT_SDMMC3, /* SDMMC3 CD */             /* wake56 */
146         INT_USB, /* TEGRA_USB1_VBUS_EN1, */     /* wake57 */
147         -EAGAIN, /* !!!FIXME!!! */
148 /* was: INT_XUSB_PADCTL */ /* XUSB superspeed wake */   /* wake58 */
149 };
150
151 static int last_gpio = -1;
152
153 int tegra_gpio_to_wake(int gpio)
154 {
155         int i;
156
157         for (i = 0; i < ARRAY_SIZE(tegra_gpio_wakes); i++) {
158                 if (tegra_gpio_wakes[i] == gpio) {
159                         pr_info("gpio wake%d for gpio=%d\n", i, gpio);
160                         last_gpio = i;
161                         return i;
162                 }
163         }
164
165         return -EINVAL;
166 }
167
168 int tegra_irq_to_wake(int irq)
169 {
170         int i;
171         int ret = -EINVAL;
172
173         for (i = 0; i < ARRAY_SIZE(tegra_wake_event_irq); i++) {
174                 if (tegra_wake_event_irq[i] == irq) {
175                         pr_info("Wake%d for irq=%d\n", i, irq);
176                         ret = i;
177                         goto out;
178                 }
179         }
180
181         /* The gpio set_wake code bubbles the set_wake call up to the irq
182          * set_wake code. This insures that the nested irq set_wake call
183          * succeeds, even though it doesn't have to do any pm setup for the
184          * bank.
185          *
186          * This is very fragile - there's no locking, so two callers could
187          * cause issues with this.
188          */
189         if (last_gpio < 0)
190                 goto out;
191
192         if (tegra_gpio_get_bank_int_nr(tegra_gpio_wakes[last_gpio]) == irq) {
193                 pr_info("gpio bank wake found: wake%d for irq=%d\n", i, irq);
194                 ret = last_gpio;
195         }
196
197 out:
198         return ret;
199 }
200
201 int tegra_wake_to_irq(int wake)
202 {
203         int ret;
204
205         if (wake < 0)
206                 return -EINVAL;
207
208         if (wake >= ARRAY_SIZE(tegra_wake_event_irq))
209                 return -EINVAL;
210
211         ret = tegra_wake_event_irq[wake];
212         if (ret == -EAGAIN) {
213                 ret = tegra_gpio_wakes[wake];
214                 if (ret != -EINVAL)
215                         ret = gpio_to_irq(ret);
216         }
217
218         return ret;
219 }
220
221 int tegra_disable_wake_source(int wake)
222 {
223         if (wake >= ARRAY_SIZE(tegra_wake_event_irq))
224                 return -EINVAL;
225
226         tegra_wake_event_irq[wake] = -EINVAL;
227         return 0;
228 }