1 // SPDX-License-Identifier: GPL-2.0
3 * Power-button driver for Basin Cove PMIC
5 * Copyright (c) 2019, Intel Corporation.
6 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
9 #include <linux/input.h>
10 #include <linux/interrupt.h>
11 #include <linux/device.h>
12 #include <linux/mfd/intel_soc_pmic.h>
13 #include <linux/mfd/intel_soc_pmic_mrfld.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_wakeirq.h>
17 #include <linux/slab.h>
19 #define BCOVE_PBSTATUS 0x27
20 #define BCOVE_PBSTATUS_PBLVL BIT(4) /* 1 - release, 0 - press */
22 static irqreturn_t
mrfld_pwrbtn_interrupt(int irq
, void *dev_id
)
24 struct input_dev
*input
= dev_id
;
25 struct device
*dev
= input
->dev
.parent
;
26 struct regmap
*regmap
= dev_get_drvdata(dev
);
30 ret
= regmap_read(regmap
, BCOVE_PBSTATUS
, &state
);
34 dev_dbg(dev
, "PBSTATUS=0x%x\n", state
);
35 input_report_key(input
, KEY_POWER
, !(state
& BCOVE_PBSTATUS_PBLVL
));
38 regmap_update_bits(regmap
, BCOVE_MIRQLVL1
, BCOVE_LVL1_PWRBTN
, 0);
42 static int mrfld_pwrbtn_probe(struct platform_device
*pdev
)
44 struct device
*dev
= &pdev
->dev
;
45 struct intel_soc_pmic
*pmic
= dev_get_drvdata(dev
->parent
);
46 struct input_dev
*input
;
49 irq
= platform_get_irq(pdev
, 0);
53 input
= devm_input_allocate_device(dev
);
56 input
->name
= pdev
->name
;
57 input
->phys
= "power-button/input0";
58 input
->id
.bustype
= BUS_HOST
;
59 input
->dev
.parent
= dev
;
60 input_set_capability(input
, EV_KEY
, KEY_POWER
);
61 ret
= input_register_device(input
);
65 dev_set_drvdata(dev
, pmic
->regmap
);
67 ret
= devm_request_threaded_irq(dev
, irq
, NULL
, mrfld_pwrbtn_interrupt
,
68 IRQF_ONESHOT
| IRQF_SHARED
, pdev
->name
,
73 regmap_update_bits(pmic
->regmap
, BCOVE_MIRQLVL1
, BCOVE_LVL1_PWRBTN
, 0);
74 regmap_update_bits(pmic
->regmap
, BCOVE_MPBIRQ
, BCOVE_PBIRQ_PBTN
, 0);
76 device_init_wakeup(dev
, true);
77 dev_pm_set_wake_irq(dev
, irq
);
81 static void mrfld_pwrbtn_remove(struct platform_device
*pdev
)
83 struct device
*dev
= &pdev
->dev
;
85 dev_pm_clear_wake_irq(dev
);
86 device_init_wakeup(dev
, false);
89 static const struct platform_device_id mrfld_pwrbtn_id_table
[] = {
90 { .name
= "mrfld_bcove_pwrbtn" },
93 MODULE_DEVICE_TABLE(platform
, mrfld_pwrbtn_id_table
);
95 static struct platform_driver mrfld_pwrbtn_driver
= {
97 .name
= "mrfld_bcove_pwrbtn",
99 .probe
= mrfld_pwrbtn_probe
,
100 .remove
= mrfld_pwrbtn_remove
,
101 .id_table
= mrfld_pwrbtn_id_table
,
103 module_platform_driver(mrfld_pwrbtn_driver
);
105 MODULE_DESCRIPTION("Power-button driver for Basin Cove PMIC");
106 MODULE_LICENSE("GPL v2");