2019-05-28 16:57:24 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-09-05 19:18:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2010
|
|
|
|
*
|
|
|
|
* Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
|
|
|
|
*
|
|
|
|
* AB8500 Power-On Key handler
|
|
|
|
*/
|
|
|
|
|
2014-05-29 07:23:39 +00:00
|
|
|
#include <linux/device.h>
|
2010-09-05 19:18:47 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/interrupt.h>
|
2011-12-02 13:16:33 +00:00
|
|
|
#include <linux/mfd/abx500/ab8500.h>
|
2012-06-12 07:21:47 +00:00
|
|
|
#include <linux/of.h>
|
2010-09-05 19:18:47 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ab8500_ponkey - ab8500 ponkey information
|
2020-11-04 19:12:31 +00:00
|
|
|
* @idev: pointer to input device
|
2010-09-05 19:18:47 +00:00
|
|
|
* @ab8500: ab8500 parent
|
|
|
|
* @irq_dbf: irq number for falling transition
|
|
|
|
* @irq_dbr: irq number for rising transition
|
|
|
|
*/
|
|
|
|
struct ab8500_ponkey {
|
|
|
|
struct input_dev *idev;
|
|
|
|
struct ab8500 *ab8500;
|
|
|
|
int irq_dbf;
|
|
|
|
int irq_dbr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* AB8500 gives us an interrupt when ONKEY is held */
|
|
|
|
static irqreturn_t ab8500_ponkey_handler(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct ab8500_ponkey *ponkey = data;
|
|
|
|
|
|
|
|
if (irq == ponkey->irq_dbf)
|
|
|
|
input_report_key(ponkey->idev, KEY_POWER, true);
|
|
|
|
else if (irq == ponkey->irq_dbr)
|
|
|
|
input_report_key(ponkey->idev, KEY_POWER, false);
|
|
|
|
|
|
|
|
input_sync(ponkey->idev);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-11-24 05:38:25 +00:00
|
|
|
static int ab8500_ponkey_probe(struct platform_device *pdev)
|
2010-09-05 19:18:47 +00:00
|
|
|
{
|
|
|
|
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
struct ab8500_ponkey *ponkey;
|
|
|
|
struct input_dev *input;
|
|
|
|
int irq_dbf, irq_dbr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF");
|
2019-08-14 17:46:38 +00:00
|
|
|
if (irq_dbf < 0)
|
2010-09-05 19:18:47 +00:00
|
|
|
return irq_dbf;
|
|
|
|
|
|
|
|
irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR");
|
2019-08-14 17:46:38 +00:00
|
|
|
if (irq_dbr < 0)
|
2010-09-05 19:18:47 +00:00
|
|
|
return irq_dbr;
|
|
|
|
|
2014-05-29 07:23:39 +00:00
|
|
|
ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ponkey)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
input = devm_input_allocate_device(&pdev->dev);
|
|
|
|
if (!input)
|
|
|
|
return -ENOMEM;
|
2010-09-05 19:18:47 +00:00
|
|
|
|
|
|
|
ponkey->idev = input;
|
|
|
|
ponkey->ab8500 = ab8500;
|
2012-09-19 17:23:18 +00:00
|
|
|
ponkey->irq_dbf = irq_dbf;
|
|
|
|
ponkey->irq_dbr = irq_dbr;
|
2010-09-05 19:18:47 +00:00
|
|
|
|
|
|
|
input->name = "AB8500 POn(PowerOn) Key";
|
|
|
|
input->dev.parent = &pdev->dev;
|
|
|
|
|
|
|
|
input_set_capability(input, EV_KEY, KEY_POWER);
|
|
|
|
|
2014-05-29 07:23:39 +00:00
|
|
|
error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
|
|
|
|
ab8500_ponkey_handler, 0,
|
|
|
|
"ab8500-ponkey-dbf", ponkey);
|
2010-09-05 19:18:47 +00:00
|
|
|
if (error < 0) {
|
|
|
|
dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
|
|
|
|
ponkey->irq_dbf, error);
|
2014-05-29 07:23:39 +00:00
|
|
|
return error;
|
2010-09-05 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 07:23:39 +00:00
|
|
|
error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
|
|
|
|
ab8500_ponkey_handler, 0,
|
|
|
|
"ab8500-ponkey-dbr", ponkey);
|
2010-09-05 19:18:47 +00:00
|
|
|
if (error < 0) {
|
|
|
|
dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
|
|
|
|
ponkey->irq_dbr, error);
|
2014-05-29 07:23:39 +00:00
|
|
|
return error;
|
2010-09-05 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error = input_register_device(ponkey->idev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(ab8500->dev, "Can't register input device: %d\n", error);
|
2014-05-29 07:23:39 +00:00
|
|
|
return error;
|
2010-09-05 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-12 07:21:47 +00:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id ab8500_ponkey_match[] = {
|
|
|
|
{ .compatible = "stericsson,ab8500-ponkey", },
|
|
|
|
{}
|
|
|
|
};
|
2015-09-03 17:49:17 +00:00
|
|
|
MODULE_DEVICE_TABLE(of, ab8500_ponkey_match);
|
2012-06-12 07:21:47 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-05 19:18:47 +00:00
|
|
|
static struct platform_driver ab8500_ponkey_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ab8500-poweron-key",
|
2012-06-12 07:21:47 +00:00
|
|
|
.of_match_table = of_match_ptr(ab8500_ponkey_match),
|
2010-09-05 19:18:47 +00:00
|
|
|
},
|
|
|
|
.probe = ab8500_ponkey_probe,
|
|
|
|
};
|
2011-11-29 19:08:40 +00:00
|
|
|
module_platform_driver(ab8500_ponkey_driver);
|
2010-09-05 19:18:47 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
|
|
|
|
MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");
|