summaryrefslogtreecommitdiff
path: root/arch/arm/mach-omap2/pad_wkup.c
blob: 021c5ff97376cf934a424c0597c9c6f1a6a55a8c (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * OMAP3 Pad Wakeup Handler
 *
 * Copyright (C) 2014-2008 Motorola, LLC.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/err.h>
#include <linux/wakeup_reason.h>

#include "soc.h"
#include "common.h"
#include "mux34xx.h"
#include "prm3xxx.h"
#include "iomap.h"

#include "pad_wkup.h"

#define WAKEUPEVENT		0x8000
struct offmode_wkup {
	struct list_head node;
	u32 irq;
	u32 pad;
	u32 pad_shift;
	bool handle; /* if true generate irq otherwise for debug only */
};
LIST_HEAD(offmode_wkup_list);

static void omap_register_pad_wkup(struct device *dev, u32 pad, u32 irq,
		bool handle)
{
	struct offmode_wkup *wkup;

	pr_info("register pad (0x%04x, %u, %d)\n", pad, irq, handle);

	wkup = devm_kzalloc(dev, sizeof(struct offmode_wkup), GFP_KERNEL);
	if (wkup) {
		wkup->irq = irq;
		wkup->pad = pad & 0xFFFFFFFC;
		wkup->pad_shift = pad % 4 ? 16 : 0;
		wkup->handle = handle;
		list_add_tail(&wkup->node, &offmode_wkup_list);
	}
}

static inline int is_pad_wkup(const struct offmode_wkup *wkup)
{
	int pad = __raw_readl(
		OMAP2_L4_IO_ADDRESS(OMAP3_CONTROL_PADCONF_MUX_PBASE)+ wkup->pad);
	pad = pad >> wkup->pad_shift;

	return (pad & WAKEUPEVENT) ? 1 : 0;
}

/* prcm_handle_pad_wkup:
 *
 *   map i/o pad wkup bits to interrupts.  The primary function is
 *   to generate interrupts.  If the handle flag is set, then generate
 *   interrupt.  If the wkup bit is set on multiple pads, interrupts
 *   are generated for all.   The secondary function is to log the
 *   Typically there should only be one wakeup event, but if there
 *   are multiple wakeup reasons, only the first in the list will be
 *   anointed "the" wakeup reason and logged.  This means the order
 *   items are listed in the device tree will control which irq
 *   wins in the case of a tie.
 */
void prcm_handle_pad_wkup(void)
{
	struct offmode_wkup *wkup;
	int wkup_irq = -1;

	list_for_each_entry(wkup, &offmode_wkup_list, node) {
		if (is_pad_wkup(wkup)) {
			pr_info("%s IRQ = %d\n", __func__, wkup->irq);
			if (wkup_irq < 0)
				wkup_irq = wkup->irq;
			if (wkup->handle)
				generic_handle_irq(wkup->irq);
		}
	}
	if (wkup_irq >= 0)
		log_wakeup_reason(wkup_irq);

}

#ifdef CONFIG_OMAP3_PAD_WKUP_IO
static irqreturn_t omap3_pad_wkup_handle_irq(int irq, void *unused)
{
	prcm_handle_pad_wkup();

	return IRQ_HANDLED;
}
#endif

static int omap3_pad_wkup_probe(struct platform_device *pdev)
{
	struct device_node *node = pdev->dev.of_node;
	int ndx = 0;
	uint32_t pad, irq, handle;
	int ret = 0;

	if (!node)
		return -ENODEV;

	do {
		if (of_property_read_u32_index(node, "ti,pad_irq", ndx, &pad))
			break;
		ndx++;
		if (of_property_read_u32_index(node, "ti,pad_irq", ndx, &irq))
			break;
		ndx++;
		if (of_property_read_u32_index(node, "ti,pad_irq", ndx,
				&handle))
			break;
		ndx++;
		omap_register_pad_wkup(&pdev->dev, pad, irq, handle);
	} while (1);

#ifdef CONFIG_OMAP3_PAD_WKUP_IO
	if (ndx > 1) {
		dev_info(&pdev->dev, "request pad_wkup_io\n");
		ret = request_irq(omap_prcm_event_to_irq("io"),
				omap3_pad_wkup_handle_irq,
				IRQF_SHARED | IRQF_NO_SUSPEND,
				"pad_wkup_io", &pdev->dev);

		if (ret)
			pr_warning("wkup: Failed to setup pad_wkup_io irq %d\n",
				ret);
	}
#endif

	return ret;
}

static int omap3_pad_wkup_remove(struct platform_device *pdev)
{
	return 0;
}

static const struct of_device_id omap3_pad_wkup_table[] = {
	{ .compatible = "ti,pad-wkup", },
	{ },
};
MODULE_DEVICE_TABLE(of, omap3_pad_wkup_table);

static struct platform_driver omap3_pad_wkup_driver = {
	.probe = omap3_pad_wkup_probe,
	.remove = omap3_pad_wkup_remove,
	.driver = {
		.name = "omap3_pad_wkup",
		.owner = THIS_MODULE,
		.of_match_table = omap3_pad_wkup_table,
	},
};

static int __init omap_pad_wkup_init(void)
{
	return platform_driver_register(&omap3_pad_wkup_driver);
}
omap_late_initcall(omap_pad_wkup_init);