ab8500-ponkey.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * Author: Sundar Iyer <[email protected]> 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. * @idev: 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. return irq_dbf;
  52. irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR");
  53. if (irq_dbr < 0)
  54. return irq_dbr;
  55. ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
  56. GFP_KERNEL);
  57. if (!ponkey)
  58. return -ENOMEM;
  59. input = devm_input_allocate_device(&pdev->dev);
  60. if (!input)
  61. return -ENOMEM;
  62. ponkey->idev = input;
  63. ponkey->ab8500 = ab8500;
  64. ponkey->irq_dbf = irq_dbf;
  65. ponkey->irq_dbr = irq_dbr;
  66. input->name = "AB8500 POn(PowerOn) Key";
  67. input->dev.parent = &pdev->dev;
  68. input_set_capability(input, EV_KEY, KEY_POWER);
  69. error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
  70. ab8500_ponkey_handler, 0,
  71. "ab8500-ponkey-dbf", ponkey);
  72. if (error < 0) {
  73. dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
  74. ponkey->irq_dbf, error);
  75. return error;
  76. }
  77. error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
  78. ab8500_ponkey_handler, 0,
  79. "ab8500-ponkey-dbr", ponkey);
  80. if (error < 0) {
  81. dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
  82. ponkey->irq_dbr, error);
  83. return error;
  84. }
  85. error = input_register_device(ponkey->idev);
  86. if (error) {
  87. dev_err(ab8500->dev, "Can't register input device: %d\n", error);
  88. return error;
  89. }
  90. return 0;
  91. }
  92. #ifdef CONFIG_OF
  93. static const struct of_device_id ab8500_ponkey_match[] = {
  94. { .compatible = "stericsson,ab8500-ponkey", },
  95. {}
  96. };
  97. MODULE_DEVICE_TABLE(of, ab8500_ponkey_match);
  98. #endif
  99. static struct platform_driver ab8500_ponkey_driver = {
  100. .driver = {
  101. .name = "ab8500-poweron-key",
  102. .of_match_table = of_match_ptr(ab8500_ponkey_match),
  103. },
  104. .probe = ab8500_ponkey_probe,
  105. };
  106. module_platform_driver(ab8500_ponkey_driver);
  107. MODULE_LICENSE("GPL v2");
  108. MODULE_AUTHOR("Sundar Iyer <[email protected]>");
  109. MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");