1 // SPDX-License-Identifier: GPL-2.0
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
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
;
24 l
= __raw_readw(PA_DBSW
);
26 /* Nothing to do if there's no state change */
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);
43 /* Clear the switch IRQs */
45 __raw_writew(l
, PA_DBSW
);
47 return IRQ_RETVAL(ret
);
50 static struct resource psw_resources
[] = {
53 .flags
= IORESOURCE_IRQ
,
57 static struct push_switch_platform_info s2_platform_data
= {
60 .irq_flags
= IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
62 .irq_handler
= psw_irq_handler
,
65 static struct platform_device s2_switch_device
= {
66 .name
= "push-switch",
68 .num_resources
= ARRAY_SIZE(psw_resources
),
69 .resource
= psw_resources
,
71 .platform_data
= &s2_platform_data
,
75 static struct push_switch_platform_info s3_platform_data
= {
78 .irq_flags
= IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
80 .irq_handler
= psw_irq_handler
,
83 static struct platform_device s3_switch_device
= {
84 .name
= "push-switch",
86 .num_resources
= ARRAY_SIZE(psw_resources
),
87 .resource
= psw_resources
,
89 .platform_data
= &s3_platform_data
,
93 static struct push_switch_platform_info s4_platform_data
= {
96 .irq_flags
= IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
98 .irq_handler
= psw_irq_handler
,
101 static struct platform_device s4_switch_device
= {
102 .name
= "push-switch",
104 .num_resources
= ARRAY_SIZE(psw_resources
),
105 .resource
= psw_resources
,
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
);