Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / platform / x86 / intel_chtdc_ti_pwrbtn.c
blob38b8e7cfe88c06a68fa351b7048247324fc89e31
1 /*
2 * Power-button driver for Dollar Cove TI PMIC
3 * Copyright (C) 2014 Intel Corp
4 * Copyright (c) 2017 Takashi Iwai <tiwai@suse.de>
5 */
7 #include <linux/input.h>
8 #include <linux/interrupt.h>
9 #include <linux/device.h>
10 #include <linux/mfd/intel_soc_pmic.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_wakeirq.h>
14 #include <linux/slab.h>
16 #define CHTDC_TI_SIRQ_REG 0x3
17 #define SIRQ_PWRBTN_REL BIT(0)
19 static irqreturn_t chtdc_ti_pwrbtn_interrupt(int irq, void *dev_id)
21 struct input_dev *input = dev_id;
22 struct device *dev = input->dev.parent;
23 struct regmap *regmap = dev_get_drvdata(dev);
24 int state;
26 if (!regmap_read(regmap, CHTDC_TI_SIRQ_REG, &state)) {
27 dev_dbg(dev, "SIRQ_REG=0x%x\n", state);
28 input_report_key(input, KEY_POWER, !(state & SIRQ_PWRBTN_REL));
29 input_sync(input);
32 return IRQ_HANDLED;
35 static int chtdc_ti_pwrbtn_probe(struct platform_device *pdev)
37 struct device *dev = &pdev->dev;
38 struct intel_soc_pmic *pmic = dev_get_drvdata(dev->parent);
39 struct input_dev *input;
40 int irq, err;
42 irq = platform_get_irq(pdev, 0);
43 if (irq < 0)
44 return irq;
45 input = devm_input_allocate_device(dev);
46 if (!input)
47 return -ENOMEM;
48 input->name = pdev->name;
49 input->phys = "power-button/input0";
50 input->id.bustype = BUS_HOST;
51 input_set_capability(input, EV_KEY, KEY_POWER);
52 err = input_register_device(input);
53 if (err)
54 return err;
56 dev_set_drvdata(dev, pmic->regmap);
58 err = devm_request_threaded_irq(dev, irq, NULL,
59 chtdc_ti_pwrbtn_interrupt,
60 0, KBUILD_MODNAME, input);
61 if (err)
62 return err;
64 device_init_wakeup(dev, true);
65 dev_pm_set_wake_irq(dev, irq);
66 return 0;
69 static int chtdc_ti_pwrbtn_remove(struct platform_device *pdev)
71 dev_pm_clear_wake_irq(&pdev->dev);
72 device_init_wakeup(&pdev->dev, false);
73 return 0;
76 static const struct platform_device_id chtdc_ti_pwrbtn_id_table[] = {
77 { .name = "chtdc_ti_pwrbtn" },
78 {},
80 MODULE_DEVICE_TABLE(platform, chtdc_ti_pwrbtn_id_table);
82 static struct platform_driver chtdc_ti_pwrbtn_driver = {
83 .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");