1 // SPDX-License-Identifier: GPL-2.0-only
3 * Marvell 88PM80x ONKEY driver
5 * Copyright (C) 2012 Marvell International Ltd.
6 * Haojian Zhuang <haojian.zhuang@marvell.com>
7 * Qiao Zhou <zhouqiao@marvell.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/input.h>
13 #include <linux/mfd/88pm80x.h>
14 #include <linux/regmap.h>
15 #include <linux/slab.h>
17 #define PM800_LONG_ONKEY_EN (1 << 0)
18 #define PM800_LONG_KEY_DELAY (8) /* 1 .. 16 seconds */
19 #define PM800_LONKEY_PRESS_TIME ((PM800_LONG_KEY_DELAY-1) << 4)
20 #define PM800_LONKEY_PRESS_TIME_MASK (0xF0)
21 #define PM800_SW_PDOWN (1 << 5)
23 struct pm80x_onkey_info
{
24 struct input_dev
*idev
;
25 struct pm80x_chip
*pm80x
;
30 /* 88PM80x gives us an interrupt when ONKEY is held */
31 static irqreturn_t
pm80x_onkey_handler(int irq
, void *data
)
33 struct pm80x_onkey_info
*info
= data
;
37 ret
= regmap_read(info
->map
, PM800_STATUS_1
, &val
);
39 dev_err(info
->idev
->dev
.parent
, "failed to read status: %d\n", ret
);
42 val
&= PM800_ONKEY_STS1
;
44 input_report_key(info
->idev
, KEY_POWER
, val
);
45 input_sync(info
->idev
);
50 static SIMPLE_DEV_PM_OPS(pm80x_onkey_pm_ops
, pm80x_dev_suspend
,
53 static int pm80x_onkey_probe(struct platform_device
*pdev
)
56 struct pm80x_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
57 struct pm80x_onkey_info
*info
;
60 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
66 info
->irq
= platform_get_irq(pdev
, 0);
72 info
->map
= info
->pm80x
->regmap
;
74 dev_err(&pdev
->dev
, "no regmap!\n");
79 info
->idev
= input_allocate_device();
81 dev_err(&pdev
->dev
, "Failed to allocate input dev\n");
86 info
->idev
->name
= "88pm80x_on";
87 info
->idev
->phys
= "88pm80x_on/input0";
88 info
->idev
->id
.bustype
= BUS_I2C
;
89 info
->idev
->dev
.parent
= &pdev
->dev
;
90 info
->idev
->evbit
[0] = BIT_MASK(EV_KEY
);
91 __set_bit(KEY_POWER
, info
->idev
->keybit
);
93 err
= pm80x_request_irq(info
->pm80x
, info
->irq
, pm80x_onkey_handler
,
94 IRQF_ONESHOT
, "onkey", info
);
96 dev_err(&pdev
->dev
, "Failed to request IRQ: #%d: %d\n",
101 err
= input_register_device(info
->idev
);
103 dev_err(&pdev
->dev
, "Can't register input device: %d\n", err
);
107 platform_set_drvdata(pdev
, info
);
109 /* Enable long onkey detection */
110 regmap_update_bits(info
->map
, PM800_RTC_MISC4
, PM800_LONG_ONKEY_EN
,
111 PM800_LONG_ONKEY_EN
);
112 /* Set 8-second interval */
113 regmap_update_bits(info
->map
, PM800_RTC_MISC3
,
114 PM800_LONKEY_PRESS_TIME_MASK
,
115 PM800_LONKEY_PRESS_TIME
);
117 device_init_wakeup(&pdev
->dev
, 1);
121 pm80x_free_irq(info
->pm80x
, info
->irq
, info
);
123 input_free_device(info
->idev
);
129 static void pm80x_onkey_remove(struct platform_device
*pdev
)
131 struct pm80x_onkey_info
*info
= platform_get_drvdata(pdev
);
133 pm80x_free_irq(info
->pm80x
, info
->irq
, info
);
134 input_unregister_device(info
->idev
);
138 static struct platform_driver pm80x_onkey_driver
= {
140 .name
= "88pm80x-onkey",
141 .pm
= &pm80x_onkey_pm_ops
,
143 .probe
= pm80x_onkey_probe
,
144 .remove
= pm80x_onkey_remove
,
147 module_platform_driver(pm80x_onkey_driver
);
149 MODULE_LICENSE("GPL");
150 MODULE_DESCRIPTION("Marvell 88PM80x ONKEY driver");
151 MODULE_AUTHOR("Qiao Zhou <zhouqiao@marvell.com>");
152 MODULE_ALIAS("platform:88pm80x-onkey");