ab8500-ponkey.c 3.8 KB

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