1 // SPDX-License-Identifier: GPL-2.0
3 * Power-button driver for Dollar Cove TI PMIC
4 * Copyright (C) 2014 Intel Corp
5 * Copyright (c) 2017 Takashi Iwai <tiwai@suse.de>
8 #include <linux/input.h>
9 #include <linux/interrupt.h>
10 #include <linux/device.h>
11 #include <linux/mfd/intel_soc_pmic.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_wakeirq.h>
15 #include <linux/slab.h>
17 #define CHTDC_TI_SIRQ_REG 0x3
18 #define SIRQ_PWRBTN_REL BIT(0)
20 static irqreturn_t
chtdc_ti_pwrbtn_interrupt(int irq
, void *dev_id
)
22 struct input_dev
*input
= dev_id
;
23 struct device
*dev
= input
->dev
.parent
;
24 struct regmap
*regmap
= dev_get_drvdata(dev
);
27 if (!regmap_read(regmap
, CHTDC_TI_SIRQ_REG
, &state
)) {
28 dev_dbg(dev
, "SIRQ_REG=0x%x\n", state
);
29 input_report_key(input
, KEY_POWER
, !(state
& SIRQ_PWRBTN_REL
));
36 static int chtdc_ti_pwrbtn_probe(struct platform_device
*pdev
)
38 struct device
*dev
= &pdev
->dev
;
39 struct intel_soc_pmic
*pmic
= dev_get_drvdata(dev
->parent
);
40 struct input_dev
*input
;
43 irq
= platform_get_irq(pdev
, 0);
46 input
= devm_input_allocate_device(dev
);
49 input
->name
= pdev
->name
;
50 input
->phys
= "power-button/input0";
51 input
->id
.bustype
= BUS_HOST
;
52 input_set_capability(input
, EV_KEY
, KEY_POWER
);
53 err
= input_register_device(input
);
57 dev_set_drvdata(dev
, pmic
->regmap
);
59 err
= devm_request_threaded_irq(dev
, irq
, NULL
,
60 chtdc_ti_pwrbtn_interrupt
,
61 IRQF_ONESHOT
, KBUILD_MODNAME
, input
);
65 device_init_wakeup(dev
, true);
66 dev_pm_set_wake_irq(dev
, irq
);
70 static void chtdc_ti_pwrbtn_remove(struct platform_device
*pdev
)
72 dev_pm_clear_wake_irq(&pdev
->dev
);
73 device_init_wakeup(&pdev
->dev
, false);
76 static const struct platform_device_id chtdc_ti_pwrbtn_id_table
[] = {
77 { .name
= "chtdc_ti_pwrbtn" },
80 MODULE_DEVICE_TABLE(platform
, chtdc_ti_pwrbtn_id_table
);
82 static struct platform_driver chtdc_ti_pwrbtn_driver
= {
84 .name
= KBUILD_MODNAME
,
86 .probe
= chtdc_ti_pwrbtn_probe
,
87 .remove
= chtdc_ti_pwrbtn_remove
,
88 .id_table
= chtdc_ti_pwrbtn_id_table
,
90 module_platform_driver(chtdc_ti_pwrbtn_driver
);
92 MODULE_DESCRIPTION("Power-button driver for Dollar Cove TI PMIC");
93 MODULE_LICENSE("GPL v2");