ab8500-ponkey.c 3.6 KB

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