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