1 // SPDX-License-Identifier: GPL-2.0
2 /*
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
8 */
9 #include <linux/io.h>
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/platform_device.h>
13 #include <mach/highlander.h>
14 #include <asm/push-switch.h>
15
psw_irq_handler(int irq,void * arg)16 static 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
24 l = __raw_readw(PA_DBSW);
25
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
42 out:
43 /* Clear the switch IRQs */
44 l |= (0x7 << 12);
45 __raw_writew(l, PA_DBSW);
46
47 return IRQ_RETVAL(ret);
48 }
49
50 static struct resource psw_resources[] = {
51 [0] = {
52 .start = IRQ_PSW,
53 .flags = IORESOURCE_IRQ,
54 },
55 };
56
57 static 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
65 static 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
75 static 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
83 static 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
93 static 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
101 static 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
111 static struct platform_device *psw_devices[] = {
112 &s2_switch_device, &s3_switch_device, &s4_switch_device,
113 };
114
psw_init(void)115 static int __init psw_init(void)
116 {
117 return platform_add_devices(psw_devices, ARRAY_SIZE(psw_devices));
118 }
119 module_init(psw_init);
120