0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/device.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/input.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/mfd/abx500/ab8500.h>
0017 #include <linux/of.h>
0018 #include <linux/slab.h>
0019
0020
0021
0022
0023
0024
0025
0026
0027 struct ab8500_ponkey {
0028 struct input_dev *idev;
0029 struct ab8500 *ab8500;
0030 int irq_dbf;
0031 int irq_dbr;
0032 };
0033
0034
0035 static irqreturn_t ab8500_ponkey_handler(int irq, void *data)
0036 {
0037 struct ab8500_ponkey *ponkey = data;
0038
0039 if (irq == ponkey->irq_dbf)
0040 input_report_key(ponkey->idev, KEY_POWER, true);
0041 else if (irq == ponkey->irq_dbr)
0042 input_report_key(ponkey->idev, KEY_POWER, false);
0043
0044 input_sync(ponkey->idev);
0045
0046 return IRQ_HANDLED;
0047 }
0048
0049 static int ab8500_ponkey_probe(struct platform_device *pdev)
0050 {
0051 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
0052 struct ab8500_ponkey *ponkey;
0053 struct input_dev *input;
0054 int irq_dbf, irq_dbr;
0055 int error;
0056
0057 irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF");
0058 if (irq_dbf < 0)
0059 return irq_dbf;
0060
0061 irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR");
0062 if (irq_dbr < 0)
0063 return irq_dbr;
0064
0065 ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
0066 GFP_KERNEL);
0067 if (!ponkey)
0068 return -ENOMEM;
0069
0070 input = devm_input_allocate_device(&pdev->dev);
0071 if (!input)
0072 return -ENOMEM;
0073
0074 ponkey->idev = input;
0075 ponkey->ab8500 = ab8500;
0076 ponkey->irq_dbf = irq_dbf;
0077 ponkey->irq_dbr = irq_dbr;
0078
0079 input->name = "AB8500 POn(PowerOn) Key";
0080 input->dev.parent = &pdev->dev;
0081
0082 input_set_capability(input, EV_KEY, KEY_POWER);
0083
0084 error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
0085 ab8500_ponkey_handler, 0,
0086 "ab8500-ponkey-dbf", ponkey);
0087 if (error < 0) {
0088 dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
0089 ponkey->irq_dbf, error);
0090 return error;
0091 }
0092
0093 error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
0094 ab8500_ponkey_handler, 0,
0095 "ab8500-ponkey-dbr", ponkey);
0096 if (error < 0) {
0097 dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
0098 ponkey->irq_dbr, error);
0099 return error;
0100 }
0101
0102 error = input_register_device(ponkey->idev);
0103 if (error) {
0104 dev_err(ab8500->dev, "Can't register input device: %d\n", error);
0105 return error;
0106 }
0107
0108 return 0;
0109 }
0110
0111 #ifdef CONFIG_OF
0112 static const struct of_device_id ab8500_ponkey_match[] = {
0113 { .compatible = "stericsson,ab8500-ponkey", },
0114 {}
0115 };
0116 MODULE_DEVICE_TABLE(of, ab8500_ponkey_match);
0117 #endif
0118
0119 static struct platform_driver ab8500_ponkey_driver = {
0120 .driver = {
0121 .name = "ab8500-poweron-key",
0122 .of_match_table = of_match_ptr(ab8500_ponkey_match),
0123 },
0124 .probe = ab8500_ponkey_probe,
0125 };
0126 module_platform_driver(ab8500_ponkey_driver);
0127
0128 MODULE_LICENSE("GPL v2");
0129 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
0130 MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");