Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License v2 |
| 5 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson |
| 6 | * |
| 7 | * AB8500 Power-On Key handler |
| 8 | */ |
| 9 | |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 10 | #include <linux/device.h> |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/input.h> |
| 15 | #include <linux/interrupt.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 16 | #include <linux/mfd/abx500/ab8500.h> |
Lee Jones | 03ecd22 | 2012-06-12 00:21:47 -0700 | [diff] [blame] | 17 | #include <linux/of.h> |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 18 | #include <linux/slab.h> |
| 19 | |
| 20 | /** |
| 21 | * struct ab8500_ponkey - ab8500 ponkey information |
| 22 | * @input_dev: pointer to input device |
| 23 | * @ab8500: ab8500 parent |
| 24 | * @irq_dbf: irq number for falling transition |
| 25 | * @irq_dbr: irq number for rising transition |
| 26 | */ |
| 27 | struct ab8500_ponkey { |
| 28 | struct input_dev *idev; |
| 29 | struct ab8500 *ab8500; |
| 30 | int irq_dbf; |
| 31 | int irq_dbr; |
| 32 | }; |
| 33 | |
| 34 | /* AB8500 gives us an interrupt when ONKEY is held */ |
| 35 | static irqreturn_t ab8500_ponkey_handler(int irq, void *data) |
| 36 | { |
| 37 | struct ab8500_ponkey *ponkey = data; |
| 38 | |
| 39 | if (irq == ponkey->irq_dbf) |
| 40 | input_report_key(ponkey->idev, KEY_POWER, true); |
| 41 | else if (irq == ponkey->irq_dbr) |
| 42 | input_report_key(ponkey->idev, KEY_POWER, false); |
| 43 | |
| 44 | input_sync(ponkey->idev); |
| 45 | |
| 46 | return IRQ_HANDLED; |
| 47 | } |
| 48 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 49 | static int ab8500_ponkey_probe(struct platform_device *pdev) |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 50 | { |
| 51 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
| 52 | struct ab8500_ponkey *ponkey; |
| 53 | struct input_dev *input; |
| 54 | int irq_dbf, irq_dbr; |
| 55 | int error; |
| 56 | |
| 57 | irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF"); |
| 58 | if (irq_dbf < 0) { |
| 59 | dev_err(&pdev->dev, "No IRQ for ONKEY_DBF, error=%d\n", irq_dbf); |
| 60 | return irq_dbf; |
| 61 | } |
| 62 | |
| 63 | irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR"); |
| 64 | if (irq_dbr < 0) { |
| 65 | dev_err(&pdev->dev, "No IRQ for ONKEY_DBR, error=%d\n", irq_dbr); |
| 66 | return irq_dbr; |
| 67 | } |
| 68 | |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 69 | ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey), |
| 70 | GFP_KERNEL); |
| 71 | if (!ponkey) |
| 72 | return -ENOMEM; |
| 73 | |
| 74 | input = devm_input_allocate_device(&pdev->dev); |
| 75 | if (!input) |
| 76 | return -ENOMEM; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 77 | |
| 78 | ponkey->idev = input; |
| 79 | ponkey->ab8500 = ab8500; |
Dmitry Torokhov | 527df5f | 2012-09-19 10:23:18 -0700 | [diff] [blame] | 80 | ponkey->irq_dbf = irq_dbf; |
| 81 | ponkey->irq_dbr = irq_dbr; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 82 | |
| 83 | input->name = "AB8500 POn(PowerOn) Key"; |
| 84 | input->dev.parent = &pdev->dev; |
| 85 | |
| 86 | input_set_capability(input, EV_KEY, KEY_POWER); |
| 87 | |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 88 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf, |
| 89 | ab8500_ponkey_handler, 0, |
| 90 | "ab8500-ponkey-dbf", ponkey); |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 91 | if (error < 0) { |
| 92 | dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", |
| 93 | ponkey->irq_dbf, error); |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 94 | return error; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 97 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr, |
| 98 | ab8500_ponkey_handler, 0, |
| 99 | "ab8500-ponkey-dbr", ponkey); |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 100 | if (error < 0) { |
| 101 | dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", |
| 102 | ponkey->irq_dbr, error); |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 103 | return error; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | error = input_register_device(ponkey->idev); |
| 107 | if (error) { |
| 108 | dev_err(ab8500->dev, "Can't register input device: %d\n", error); |
Himangi Saraogi | 7b961d5 | 2014-05-29 00:23:39 -0700 | [diff] [blame] | 109 | return error; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | platform_set_drvdata(pdev, ponkey); |
| 113 | return 0; |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Lee Jones | 03ecd22 | 2012-06-12 00:21:47 -0700 | [diff] [blame] | 116 | #ifdef CONFIG_OF |
| 117 | static const struct of_device_id ab8500_ponkey_match[] = { |
| 118 | { .compatible = "stericsson,ab8500-ponkey", }, |
| 119 | {} |
| 120 | }; |
Luis de Bethencourt | e4dbe79 | 2015-09-03 10:49:17 -0700 | [diff] [blame] | 121 | MODULE_DEVICE_TABLE(of, ab8500_ponkey_match); |
Lee Jones | 03ecd22 | 2012-06-12 00:21:47 -0700 | [diff] [blame] | 122 | #endif |
| 123 | |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 124 | static struct platform_driver ab8500_ponkey_driver = { |
| 125 | .driver = { |
| 126 | .name = "ab8500-poweron-key", |
Lee Jones | 03ecd22 | 2012-06-12 00:21:47 -0700 | [diff] [blame] | 127 | .of_match_table = of_match_ptr(ab8500_ponkey_match), |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 128 | }, |
| 129 | .probe = ab8500_ponkey_probe, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 130 | }; |
JJ Ding | 840a746 | 2011-11-29 11:08:40 -0800 | [diff] [blame] | 131 | module_platform_driver(ab8500_ponkey_driver); |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 132 | |
| 133 | MODULE_LICENSE("GPL v2"); |
| 134 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); |
| 135 | MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver"); |