summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/wakeups.c
blob: a52a4d50c0749ee1df388126427b03f69e0315dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/interrupt.h>

#include <mach/iomap.h>
#include <mach/irqs.h>
#include <mach/gpio.h>

#include "gpio-names.h"
#include "wakeups.h"

extern struct tegra_wake_info *tegra_wake_event_data;
extern unsigned int tegra_wake_event_data_size;

/*
 * FIXME: unable to pass rising and falling
 * flags from usb driver hence using polarity field
 * from wake table to set wake_mask_any
 * for selected usb wake sources - VBUS and ID
 */
static int update_wake_mask(unsigned int index, int flow_type,
	struct wake_mask_types *wake_msk)
{
	int trigger_val;
	/*
	 * set wake function calls with flow_type as -1
	 * set wake type function calls update_wake_mask with
	 * the wake polarity
	 */
	if (flow_type == -1) {
		pr_debug("Wake%d flow_type=%d\n",
			index, flow_type);
		/* use argument wake_mask_hi to return mask */
		wake_msk->wake_mask_hi |= (1ULL << index);
	} else {
		trigger_val = (flow_type & IRQF_TRIGGER_MASK);
		if ((tegra_wake_event_data[index].polarity ==
			POLARITY_EDGE_ANY) ||
			(trigger_val ==
			(IRQF_TRIGGER_RISING |
			IRQF_TRIGGER_FALLING))) {
			pr_debug("Wake%d flow_type=ANY\n", index);
			wake_msk->wake_mask_any |= (1ULL << index);
		} else if ((trigger_val == IRQF_TRIGGER_HIGH) ||
			(trigger_val == IRQF_TRIGGER_RISING)) {
			pr_debug("Wake%d flow_type=HI\n", index);
			wake_msk->wake_mask_hi |= (1ULL << index);
		} else if ((trigger_val == IRQF_TRIGGER_LOW) ||
			(trigger_val == IRQF_TRIGGER_FALLING)) {
			pr_debug("Wake%d flow_type=LO\n", index);
			wake_msk->wake_mask_lo |= (1ULL << index);
		} else {
			pr_err("Error: Wake%d UNKNOWN flow_type=%d\n",
				index, flow_type);
			return -EINVAL;
		}
	}
	return 0;
}

int tegra_irq_to_wake(unsigned int irq, int flow_type,
	struct wake_mask_types *wake_msk)
{
	int i;
	int err;

	wake_msk->wake_mask_hi = 0ULL;
	wake_msk->wake_mask_lo = 0ULL;
	wake_msk->wake_mask_any = 0ULL;
	/*
	 * check for irq based on tegra_wake_event_data table
	 */
	for (i = 0; i < tegra_wake_event_data_size; i++) {
		if (tegra_wake_event_data[i].irq == irq) {
			err = update_wake_mask(i, flow_type, wake_msk);
			if (err)
				return err;
			continue;
		}
	}

	if (wake_msk->wake_mask_hi || wake_msk->wake_mask_lo ||
		wake_msk->wake_mask_any) {
		pr_debug("Enabling wake sources for irq=%d, mask hi=%#llx, lo=%#llx, any=%#llx, flow_type=%d\n",
			irq, wake_msk->wake_mask_hi, wake_msk->wake_mask_lo,
			wake_msk->wake_mask_any, flow_type);
		return 0;
	}
	return -EINVAL;
}

int tegra_wake_to_irq(int wake)
{
	if (wake < 0)
		return -EINVAL;

	if (wake >= tegra_wake_event_data_size)
		return -EINVAL;

	return tegra_wake_event_data[wake].irq;
}

int tegra_disable_wake_source(int wake)
{
	if (wake >= tegra_wake_event_data_size)
		return -EINVAL;

	tegra_wake_event_data[wake].irq = -EINVAL;

	return 0;
}