retu-pwrbutton.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Retu power button driver.
  3. *
  4. * Copyright (C) 2004-2010 Nokia Corporation
  5. *
  6. * Original code written by Ari Saastamoinen, Juha Yrjölä and Felipe Balbi.
  7. * Rewritten by Aaro Koskinen.
  8. *
  9. * This file is subject to the terms and conditions of the GNU General
  10. * Public License. See the file "COPYING" in the main directory of this
  11. * archive for more details.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/irq.h>
  19. #include <linux/slab.h>
  20. #include <linux/errno.h>
  21. #include <linux/input.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/mfd/retu.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/platform_device.h>
  27. #define RETU_STATUS_PWRONX (1 << 5)
  28. static irqreturn_t retu_pwrbutton_irq(int irq, void *_pwr)
  29. {
  30. struct input_dev *idev = _pwr;
  31. struct retu_dev *rdev = input_get_drvdata(idev);
  32. bool state;
  33. state = !(retu_read(rdev, RETU_REG_STATUS) & RETU_STATUS_PWRONX);
  34. input_report_key(idev, KEY_POWER, state);
  35. input_sync(idev);
  36. return IRQ_HANDLED;
  37. }
  38. static int retu_pwrbutton_probe(struct platform_device *pdev)
  39. {
  40. struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent);
  41. struct input_dev *idev;
  42. int irq;
  43. int error;
  44. irq = platform_get_irq(pdev, 0);
  45. if (irq < 0)
  46. return irq;
  47. idev = devm_input_allocate_device(&pdev->dev);
  48. if (!idev)
  49. return -ENOMEM;
  50. idev->name = "retu-pwrbutton";
  51. idev->dev.parent = &pdev->dev;
  52. input_set_capability(idev, EV_KEY, KEY_POWER);
  53. input_set_drvdata(idev, rdev);
  54. error = devm_request_threaded_irq(&pdev->dev, irq,
  55. NULL, retu_pwrbutton_irq,
  56. IRQF_ONESHOT,
  57. "retu-pwrbutton", idev);
  58. if (error)
  59. return error;
  60. error = input_register_device(idev);
  61. if (error)
  62. return error;
  63. return 0;
  64. }
  65. static int retu_pwrbutton_remove(struct platform_device *pdev)
  66. {
  67. return 0;
  68. }
  69. static struct platform_driver retu_pwrbutton_driver = {
  70. .probe = retu_pwrbutton_probe,
  71. .remove = retu_pwrbutton_remove,
  72. .driver = {
  73. .name = "retu-pwrbutton",
  74. },
  75. };
  76. module_platform_driver(retu_pwrbutton_driver);
  77. MODULE_ALIAS("platform:retu-pwrbutton");
  78. MODULE_DESCRIPTION("Retu Power Button");
  79. MODULE_AUTHOR("Ari Saastamoinen");
  80. MODULE_AUTHOR("Felipe Balbi");
  81. MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
  82. MODULE_LICENSE("GPL");