xref: /openbmc/linux/arch/sh/boards/mach-landisk/psw.c (revision aaf9128a)
1aaf9128aSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
2da2014a2SPaul Mundt /*
3da2014a2SPaul Mundt  * arch/sh/boards/landisk/psw.c
4da2014a2SPaul Mundt  *
5da2014a2SPaul Mundt  * push switch support for LANDISK and USL-5P
6da2014a2SPaul Mundt  *
7da2014a2SPaul Mundt  * Copyright (C) 2006-2007  Paul Mundt
8da2014a2SPaul Mundt  * Copyright (C) 2007  kogiidena
9da2014a2SPaul Mundt  */
10da2014a2SPaul Mundt #include <linux/io.h>
11da2014a2SPaul Mundt #include <linux/init.h>
12da2014a2SPaul Mundt #include <linux/interrupt.h>
13da2014a2SPaul Mundt #include <linux/platform_device.h>
140764bff4SPaul Mundt #include <mach-landisk/mach/iodata_landisk.h>
15da2014a2SPaul Mundt #include <asm/push-switch.h>
16da2014a2SPaul Mundt 
psw_irq_handler(int irq,void * arg)17da2014a2SPaul Mundt static irqreturn_t psw_irq_handler(int irq, void *arg)
18da2014a2SPaul Mundt {
19da2014a2SPaul Mundt 	struct platform_device *pdev = arg;
20da2014a2SPaul Mundt 	struct push_switch *psw = platform_get_drvdata(pdev);
21da2014a2SPaul Mundt 	struct push_switch_platform_info *psw_info = pdev->dev.platform_data;
22da2014a2SPaul Mundt 	unsigned int sw_value;
23da2014a2SPaul Mundt 	int ret = 0;
24da2014a2SPaul Mundt 
259d56dd3bSPaul Mundt 	sw_value = (0x0ff & (~__raw_readb(PA_STATUS)));
26da2014a2SPaul Mundt 
27da2014a2SPaul Mundt 	/* Nothing to do if there's no state change */
28da2014a2SPaul Mundt 	if (psw->state) {
29da2014a2SPaul Mundt 		ret = 1;
30da2014a2SPaul Mundt 		goto out;
31da2014a2SPaul Mundt 	}
32da2014a2SPaul Mundt 
33da2014a2SPaul Mundt 	/* Figure out who raised it */
34da2014a2SPaul Mundt 	if (sw_value & (1 << psw_info->bit)) {
35da2014a2SPaul Mundt 		psw->state = 1;
36da2014a2SPaul Mundt 		mod_timer(&psw->debounce, jiffies + 50);
37da2014a2SPaul Mundt 		ret = 1;
38da2014a2SPaul Mundt 	}
39da2014a2SPaul Mundt 
40da2014a2SPaul Mundt out:
41da2014a2SPaul Mundt 	/* Clear the switch IRQs */
429d56dd3bSPaul Mundt 	__raw_writeb(0x00, PA_PWRINT_CLR);
43da2014a2SPaul Mundt 
44da2014a2SPaul Mundt 	return IRQ_RETVAL(ret);
45da2014a2SPaul Mundt }
46da2014a2SPaul Mundt 
47da2014a2SPaul Mundt static struct resource psw_power_resources[] = {
48da2014a2SPaul Mundt 	[0] = {
49da2014a2SPaul Mundt 		.start = IRQ_POWER,
50da2014a2SPaul Mundt 		.flags = IORESOURCE_IRQ,
51da2014a2SPaul Mundt        },
52da2014a2SPaul Mundt };
53da2014a2SPaul Mundt 
54da2014a2SPaul Mundt static struct resource psw_usl5p_resources[] = {
55da2014a2SPaul Mundt 	[0] = {
56da2014a2SPaul Mundt 		.start = IRQ_BUTTON,
57da2014a2SPaul Mundt 		.flags = IORESOURCE_IRQ,
58da2014a2SPaul Mundt 	},
59da2014a2SPaul Mundt };
60da2014a2SPaul Mundt 
61da2014a2SPaul Mundt static struct push_switch_platform_info psw_power_platform_data = {
62da2014a2SPaul Mundt 	.name		= "psw_power",
63da2014a2SPaul Mundt 	.bit		= 4,
64da2014a2SPaul Mundt 	.irq_flags	= IRQF_SHARED,
65da2014a2SPaul Mundt 	.irq_handler	= psw_irq_handler,
66da2014a2SPaul Mundt };
67da2014a2SPaul Mundt 
68da2014a2SPaul Mundt static struct push_switch_platform_info psw1_platform_data = {
69da2014a2SPaul Mundt 	.name		= "psw1",
70da2014a2SPaul Mundt 	.bit		= 0,
71da2014a2SPaul Mundt 	.irq_flags	= IRQF_SHARED,
72da2014a2SPaul Mundt 	.irq_handler	= psw_irq_handler,
73da2014a2SPaul Mundt };
74da2014a2SPaul Mundt 
75da2014a2SPaul Mundt static struct push_switch_platform_info psw2_platform_data = {
76da2014a2SPaul Mundt 	.name		= "psw2",
77da2014a2SPaul Mundt 	.bit		= 2,
78da2014a2SPaul Mundt 	.irq_flags	= IRQF_SHARED,
79da2014a2SPaul Mundt 	.irq_handler	= psw_irq_handler,
80da2014a2SPaul Mundt };
81da2014a2SPaul Mundt 
82da2014a2SPaul Mundt static struct push_switch_platform_info psw3_platform_data = {
83da2014a2SPaul Mundt 	.name		= "psw3",
84da2014a2SPaul Mundt 	.bit		= 1,
85da2014a2SPaul Mundt 	.irq_flags	= IRQF_SHARED,
86da2014a2SPaul Mundt 	.irq_handler	= psw_irq_handler,
87da2014a2SPaul Mundt };
88da2014a2SPaul Mundt 
89da2014a2SPaul Mundt static struct platform_device psw_power_switch_device = {
90da2014a2SPaul Mundt 	.name		= "push-switch",
91da2014a2SPaul Mundt 	.id		= 0,
92da2014a2SPaul Mundt 	.num_resources	= ARRAY_SIZE(psw_power_resources),
93da2014a2SPaul Mundt 	.resource	= psw_power_resources,
94da2014a2SPaul Mundt 	.dev		= {
95da2014a2SPaul Mundt 		.platform_data = &psw_power_platform_data,
96da2014a2SPaul Mundt 	},
97da2014a2SPaul Mundt };
98da2014a2SPaul Mundt 
99da2014a2SPaul Mundt static struct platform_device psw1_switch_device = {
100da2014a2SPaul Mundt 	.name		= "push-switch",
101da2014a2SPaul Mundt 	.id		= 1,
102da2014a2SPaul Mundt 	.num_resources	= ARRAY_SIZE(psw_usl5p_resources),
103da2014a2SPaul Mundt 	.resource	= psw_usl5p_resources,
104da2014a2SPaul Mundt 	.dev		= {
105da2014a2SPaul Mundt 		.platform_data = &psw1_platform_data,
106da2014a2SPaul Mundt 	},
107da2014a2SPaul Mundt };
108da2014a2SPaul Mundt 
109da2014a2SPaul Mundt static struct platform_device psw2_switch_device = {
110da2014a2SPaul Mundt 	.name		= "push-switch",
111da2014a2SPaul Mundt 	.id		= 2,
112da2014a2SPaul Mundt 	.num_resources	= ARRAY_SIZE(psw_usl5p_resources),
113da2014a2SPaul Mundt 	.resource	= psw_usl5p_resources,
114da2014a2SPaul Mundt 	.dev		= {
115da2014a2SPaul Mundt 		.platform_data = &psw2_platform_data,
116da2014a2SPaul Mundt 	},
117da2014a2SPaul Mundt };
118da2014a2SPaul Mundt 
119da2014a2SPaul Mundt static struct platform_device psw3_switch_device = {
120da2014a2SPaul Mundt 	.name		= "push-switch",
121da2014a2SPaul Mundt 	.id		= 3,
122da2014a2SPaul Mundt 	.num_resources	= ARRAY_SIZE(psw_usl5p_resources),
123da2014a2SPaul Mundt 	.resource	= psw_usl5p_resources,
124da2014a2SPaul Mundt 	.dev = {
125da2014a2SPaul Mundt 		.platform_data = &psw3_platform_data,
126da2014a2SPaul Mundt 	},
127da2014a2SPaul Mundt };
128da2014a2SPaul Mundt 
129da2014a2SPaul Mundt static struct platform_device *psw_devices[] = {
130da2014a2SPaul Mundt 	&psw_power_switch_device,
131da2014a2SPaul Mundt 	&psw1_switch_device,
132da2014a2SPaul Mundt 	&psw2_switch_device,
133da2014a2SPaul Mundt 	&psw3_switch_device,
134da2014a2SPaul Mundt };
135da2014a2SPaul Mundt 
psw_init(void)136da2014a2SPaul Mundt static int __init psw_init(void)
137da2014a2SPaul Mundt {
138da2014a2SPaul Mundt 	return platform_add_devices(psw_devices, ARRAY_SIZE(psw_devices));
139da2014a2SPaul Mundt }
140b205118bSPaul Gortmaker device_initcall(psw_init);
141