ab8500-ponkey.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #include <linux/device.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/input.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/mfd/abx500/ab8500.h>
  16. #include <linux/of.h>
  17. #include <linux/slab.h>
  18. /**
  19. * struct ab8500_ponkey - ab8500 ponkey information
  20. * @input_dev: pointer to input device
  21. * @ab8500: ab8500 parent
  22. * @irq_dbf: irq number for falling transition
  23. * @irq_dbr: irq number for rising transition
  24. */
  25. struct ab8500_ponkey {
  26. struct input_dev *idev;
  27. struct ab8500 *ab8500;
  28. int irq_dbf;
  29. int irq_dbr;
  30. };
  31. /* AB8500 gives us an interrupt when ONKEY is held */
  32. static irqreturn_t ab8500_ponkey_handler(int irq, void *data)
  33. {
  34. struct ab8500_ponkey *ponkey = data;
  35. if (irq == ponkey->irq_dbf)
  36. input_report_key(ponkey->idev, KEY_POWER, true);
  37. else if (irq == ponkey->irq_dbr)
  38. input_report_key(ponkey->idev, KEY_POWER, false);
  39. input_sync(ponkey->idev);
  40. return IRQ_HANDLED;
  41. }
  42. static int ab8500_ponkey_probe(struct platform_device *pdev)
  43. {
  44. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  45. struct ab8500_ponkey *ponkey;
  46. struct input_dev *input;
  47. int irq_dbf, irq_dbr;
  48. int error;
  49. irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF");
  50. if (irq_dbf < 0) {
  51. dev_err(&pdev->dev, "No IRQ for ONKEY_DBF, error=%d\n", irq_dbf);
  52. return irq_dbf;
  53. }
  54. irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR");
  55. if (irq_dbr < 0) {
  56. dev_err(&pdev->dev, "No IRQ for ONKEY_DBR, error=%d\n", irq_dbr);
  57. return irq_dbr;
  58. }
  59. ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
  60. GFP_KERNEL);
  61. if (!ponkey)
  62. return -ENOMEM;
  63. input = devm_input_allocate_device(&pdev->dev);
  64. if (!input)
  65. return -ENOMEM;
  66. ponkey->idev = input;
  67. ponkey->ab8500 = ab8500;
  68. ponkey->irq_dbf = irq_dbf;
  69. ponkey->irq_dbr = irq_dbr;
  70. input->name = "AB8500 POn(PowerOn) Key";
  71. input->dev.parent = &pdev->dev;
  72. input_set_capability(input, EV_KEY, KEY_POWER);
  73. error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
  74. ab8500_ponkey_handler, 0,
  75. "ab8500-ponkey-dbf", ponkey);
  76. if (error < 0) {
  77. dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
  78. ponkey->irq_dbf, error);
  79. return error;
  80. }
  81. error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
  82. ab8500_ponkey_handler, 0,
  83. "ab8500-ponkey-dbr", ponkey);
  84. if (error < 0) {
  85. dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
  86. ponkey->irq_dbr, error);
  87. return error;
  88. }
  89. error = input_register_device(ponkey->idev);
  90. if (error) {
  91. dev_err(ab8500->dev, "Can't register input device: %d\n", error);
  92. return error;
  93. }
  94. platform_set_drvdata(pdev, ponkey);
  95. return 0;
  96. }
  97. #ifdef CONFIG_OF
  98. static const struct of_device_id ab8500_ponkey_match[] = {
  99. { .compatible = "stericsson,ab8500-ponkey", },
  100. {}
  101. };
  102. MODULE_DEVICE_TABLE(of, ab8500_ponkey_match);
  103. #endif
  104. static struct platform_driver ab8500_ponkey_driver = {
  105. .driver = {
  106. .name = "ab8500-poweron-key",
  107. .of_match_table = of_match_ptr(ab8500_ponkey_match),
  108. },
  109. .probe = ab8500_ponkey_probe,
  110. };
  111. module_platform_driver(ab8500_ponkey_driver);
  112. MODULE_LICENSE("GPL v2");
  113. MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
  114. MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");