Merge tag 'locking-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / sh / boards / mach-highlander / psw.c
blobd445c54f74e4403b14ac6a686ae0a0d3da7d60f0
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/boards/renesas/r7780rp/psw.c
5 * push switch support for RDBRP-1/RDBREVRP-1 debug boards.
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>
16 static irqreturn_t psw_irq_handler(int irq, void *arg)
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;
24 l = __raw_readw(PA_DBSW);
26 /* Nothing to do if there's no state change */
27 if (psw->state) {
28 ret = 1;
29 goto out;
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);
39 ret = 1;
42 out:
43 /* Clear the switch IRQs */
44 l |= (0x7 << 12);
45 __raw_writew(l, PA_DBSW);
47 return IRQ_RETVAL(ret);
50 static struct resource psw_resources[] = {
51 [0] = {
52 .start = IRQ_PSW,
53 .flags = IORESOURCE_IRQ,
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,
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,
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,
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,
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,
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,
111 static struct platform_device *psw_devices[] = {
112 &s2_switch_device, &s3_switch_device, &s4_switch_device,
115 static int __init psw_init(void)
117 return platform_add_devices(psw_devices, ARRAY_SIZE(psw_devices));
119 module_init(psw_init);