blob: d445c54f74e4403b14ac6a686ae0a0d3da7d60f0 [file] [log] [blame]
Kuninori Morimotoaaf91282018-12-28 00:31:46 -08001// SPDX-License-Identifier: GPL-2.0
Paul Mundt9daa0c22006-11-24 11:24:39 +09002/*
3 * arch/sh/boards/renesas/r7780rp/psw.c
4 *
5 * push switch support for RDBRP-1/RDBREVRP-1 debug boards.
6 *
7 * Copyright (C) 2006 Paul Mundt
Paul Mundt9daa0c22006-11-24 11:24:39 +09008 */
9#include <linux/io.h>
Paul Gortmaker0bbad242015-05-01 20:02:31 -040010#include <linux/module.h>
Paul Mundt9daa0c22006-11-24 11:24:39 +090011#include <linux/interrupt.h>
12#include <linux/platform_device.h>
Paul Mundt7639a452008-10-20 13:02:48 +090013#include <mach/highlander.h>
Paul Mundt9daa0c22006-11-24 11:24:39 +090014#include <asm/push-switch.h>
15
16static irqreturn_t psw_irq_handler(int irq, void *arg)
17{
18 struct platform_device *pdev = arg;
19 struct push_switch *psw = platform_get_drvdata(pdev);
20 struct push_switch_platform_info *psw_info = pdev->dev.platform_data;
21 unsigned int l, mask;
22 int ret = 0;
23
Paul Mundt9d56dd32010-01-26 12:58:40 +090024 l = __raw_readw(PA_DBSW);
Paul Mundt9daa0c22006-11-24 11:24:39 +090025
26 /* Nothing to do if there's no state change */
27 if (psw->state) {
28 ret = 1;
29 goto out;
30 }
31
32 mask = l & 0x70;
33 /* Figure out who raised it */
34 if (mask & (1 << psw_info->bit)) {
35 psw->state = !!(mask & (1 << psw_info->bit));
36 if (psw->state) /* debounce */
37 mod_timer(&psw->debounce, jiffies + 50);
38
39 ret = 1;
40 }
41
42out:
43 /* Clear the switch IRQs */
44 l |= (0x7 << 12);
Paul Mundt9d56dd32010-01-26 12:58:40 +090045 __raw_writew(l, PA_DBSW);
Paul Mundt9daa0c22006-11-24 11:24:39 +090046
47 return IRQ_RETVAL(ret);
48}
49
50static struct resource psw_resources[] = {
51 [0] = {
52 .start = IRQ_PSW,
53 .flags = IORESOURCE_IRQ,
54 },
55};
56
57static struct push_switch_platform_info s2_platform_data = {
58 .name = "s2",
59 .bit = 6,
60 .irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
61 IRQF_SHARED,
62 .irq_handler = psw_irq_handler,
63};
64
65static struct platform_device s2_switch_device = {
66 .name = "push-switch",
67 .id = 0,
68 .num_resources = ARRAY_SIZE(psw_resources),
69 .resource = psw_resources,
70 .dev = {
71 .platform_data = &s2_platform_data,
72 },
73};
74
75static struct push_switch_platform_info s3_platform_data = {
76 .name = "s3",
77 .bit = 5,
78 .irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
79 IRQF_SHARED,
80 .irq_handler = psw_irq_handler,
81};
82
83static struct platform_device s3_switch_device = {
84 .name = "push-switch",
85 .id = 1,
86 .num_resources = ARRAY_SIZE(psw_resources),
87 .resource = psw_resources,
88 .dev = {
89 .platform_data = &s3_platform_data,
90 },
91};
92
93static struct push_switch_platform_info s4_platform_data = {
94 .name = "s4",
95 .bit = 4,
96 .irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
97 IRQF_SHARED,
98 .irq_handler = psw_irq_handler,
99};
100
101static struct platform_device s4_switch_device = {
102 .name = "push-switch",
103 .id = 2,
104 .num_resources = ARRAY_SIZE(psw_resources),
105 .resource = psw_resources,
106 .dev = {
107 .platform_data = &s4_platform_data,
108 },
109};
110
111static struct platform_device *psw_devices[] = {
112 &s2_switch_device, &s3_switch_device, &s4_switch_device,
113};
114
115static int __init psw_init(void)
116{
117 return platform_add_devices(psw_devices, ARRAY_SIZE(psw_devices));
118}
119module_init(psw_init);