Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / platform / x86 / intel_chtdc_ti_pwrbtn.c
blob0df2e82dd24924bd6d92ff74f2434b4eb1f30d64
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Power-button driver for Dollar Cove TI PMIC
4 * Copyright (C) 2014 Intel Corp
5 * Copyright (c) 2017 Takashi Iwai <tiwai@suse.de>
6 */
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);
25 int state;
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));
30 input_sync(input);
33 return IRQ_HANDLED;
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;
41 int irq, err;
43 irq = platform_get_irq(pdev, 0);
44 if (irq < 0)
45 return irq;
46 input = devm_input_allocate_device(dev);
47 if (!input)
48 return -ENOMEM;
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);
54 if (err)
55 return err;
57 dev_set_drvdata(dev, pmic->regmap);
59 err = devm_request_threaded_irq(dev, irq, NULL,
60 chtdc_ti_pwrbtn_interrupt,
61 0, KBUILD_MODNAME, input);
62 if (err)
63 return err;
65 device_init_wakeup(dev, true);
66 dev_pm_set_wake_irq(dev, irq);
67 return 0;
70 static int chtdc_ti_pwrbtn_remove(struct platform_device *pdev)
72 dev_pm_clear_wake_irq(&pdev->dev);
73 device_init_wakeup(&pdev->dev, false);
74 return 0;
77 static const struct platform_device_id chtdc_ti_pwrbtn_id_table[] = {
78 { .name = "chtdc_ti_pwrbtn" },
79 {},
81 MODULE_DEVICE_TABLE(platform, chtdc_ti_pwrbtn_id_table);
83 static struct platform_driver chtdc_ti_pwrbtn_driver = {
84 .driver = {
85 .name = KBUILD_MODNAME,
87 .probe = chtdc_ti_pwrbtn_probe,
88 .remove = chtdc_ti_pwrbtn_remove,
89 .id_table = chtdc_ti_pwrbtn_id_table,
91 module_platform_driver(chtdc_ti_pwrbtn_driver);
93 MODULE_DESCRIPTION("Power-button driver for Dollar Cove TI PMIC");
94 MODULE_LICENSE("GPL v2");