rk805-pwrkey.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Rockchip RK805 PMIC Power Key driver
  3. *
  4. * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
  5. *
  6. * Author: Joseph Chen <chenjh@rock-chips.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/init.h>
  15. #include <linux/input.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr)
  21. {
  22. struct input_dev *pwr = _pwr;
  23. input_report_key(pwr, KEY_POWER, 1);
  24. input_sync(pwr);
  25. return IRQ_HANDLED;
  26. }
  27. static irqreturn_t pwrkey_rise_irq(int irq, void *_pwr)
  28. {
  29. struct input_dev *pwr = _pwr;
  30. input_report_key(pwr, KEY_POWER, 0);
  31. input_sync(pwr);
  32. return IRQ_HANDLED;
  33. }
  34. static int rk805_pwrkey_probe(struct platform_device *pdev)
  35. {
  36. struct input_dev *pwr;
  37. int fall_irq, rise_irq;
  38. int err;
  39. pwr = devm_input_allocate_device(&pdev->dev);
  40. if (!pwr) {
  41. dev_err(&pdev->dev, "Can't allocate power button\n");
  42. return -ENOMEM;
  43. }
  44. pwr->name = "rk805 pwrkey";
  45. pwr->phys = "rk805_pwrkey/input0";
  46. pwr->id.bustype = BUS_HOST;
  47. input_set_capability(pwr, EV_KEY, KEY_POWER);
  48. fall_irq = platform_get_irq(pdev, 0);
  49. if (fall_irq < 0) {
  50. dev_err(&pdev->dev, "Can't get fall irq: %d\n", fall_irq);
  51. return fall_irq;
  52. }
  53. rise_irq = platform_get_irq(pdev, 1);
  54. if (rise_irq < 0) {
  55. dev_err(&pdev->dev, "Can't get rise irq: %d\n", rise_irq);
  56. return rise_irq;
  57. }
  58. err = devm_request_any_context_irq(&pwr->dev, fall_irq,
  59. pwrkey_fall_irq,
  60. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  61. "rk805_pwrkey_fall", pwr);
  62. if (err < 0) {
  63. dev_err(&pdev->dev, "Can't register fall irq: %d\n", err);
  64. return err;
  65. }
  66. err = devm_request_any_context_irq(&pwr->dev, rise_irq,
  67. pwrkey_rise_irq,
  68. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  69. "rk805_pwrkey_rise", pwr);
  70. if (err < 0) {
  71. dev_err(&pdev->dev, "Can't register rise irq: %d\n", err);
  72. return err;
  73. }
  74. err = input_register_device(pwr);
  75. if (err) {
  76. dev_err(&pdev->dev, "Can't register power button: %d\n", err);
  77. return err;
  78. }
  79. platform_set_drvdata(pdev, pwr);
  80. device_init_wakeup(&pdev->dev, true);
  81. return 0;
  82. }
  83. static struct platform_driver rk805_pwrkey_driver = {
  84. .probe = rk805_pwrkey_probe,
  85. .driver = {
  86. .name = "rk805-pwrkey",
  87. },
  88. };
  89. module_platform_driver(rk805_pwrkey_driver);
  90. MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>");
  91. MODULE_DESCRIPTION("RK805 PMIC Power Key driver");
  92. MODULE_LICENSE("GPL");