88pm860x_onkey.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * 88pm860x_onkey.c - Marvell 88PM860x ONKEY driver
  3. *
  4. * Copyright (C) 2009-2010 Marvell International Ltd.
  5. * Haojian Zhuang <haojian.zhuang@marvell.com>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file "COPYING" in the main directory of this
  9. * archive for more details.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/i2c.h>
  24. #include <linux/input.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/mfd/88pm860x.h>
  27. #define PM8607_WAKEUP 0x0b
  28. #define LONG_ONKEY_EN (1 << 1)
  29. #define ONKEY_STATUS (1 << 0)
  30. struct pm860x_onkey_info {
  31. struct input_dev *idev;
  32. struct pm860x_chip *chip;
  33. struct i2c_client *i2c;
  34. struct device *dev;
  35. int irq;
  36. };
  37. /* 88PM860x gives us an interrupt when ONKEY is held */
  38. static irqreturn_t pm860x_onkey_handler(int irq, void *data)
  39. {
  40. struct pm860x_onkey_info *info = data;
  41. int ret;
  42. ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2);
  43. ret &= ONKEY_STATUS;
  44. input_report_key(info->idev, KEY_POWER, ret);
  45. input_sync(info->idev);
  46. /* Enable 8-second long onkey detection */
  47. pm860x_set_bits(info->i2c, PM8607_WAKEUP, 3, LONG_ONKEY_EN);
  48. return IRQ_HANDLED;
  49. }
  50. static int __devinit pm860x_onkey_probe(struct platform_device *pdev)
  51. {
  52. struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  53. struct pm860x_onkey_info *info;
  54. int irq, ret;
  55. irq = platform_get_irq(pdev, 0);
  56. if (irq < 0) {
  57. dev_err(&pdev->dev, "No IRQ resource!\n");
  58. return -EINVAL;
  59. }
  60. info = kzalloc(sizeof(struct pm860x_onkey_info), GFP_KERNEL);
  61. if (!info)
  62. return -ENOMEM;
  63. info->chip = chip;
  64. info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  65. info->dev = &pdev->dev;
  66. info->irq = irq + chip->irq_base;
  67. info->idev = input_allocate_device();
  68. if (!info->idev) {
  69. dev_err(chip->dev, "Failed to allocate input dev\n");
  70. ret = -ENOMEM;
  71. goto out;
  72. }
  73. info->idev->name = "88pm860x_on";
  74. info->idev->phys = "88pm860x_on/input0";
  75. info->idev->id.bustype = BUS_I2C;
  76. info->idev->dev.parent = &pdev->dev;
  77. info->irq = irq;
  78. info->idev->evbit[0] = BIT_MASK(EV_KEY);
  79. info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
  80. ret = input_register_device(info->idev);
  81. if (ret) {
  82. dev_err(chip->dev, "Can't register input device: %d\n", ret);
  83. goto out_reg;
  84. }
  85. ret = request_threaded_irq(info->irq, NULL, pm860x_onkey_handler,
  86. IRQF_ONESHOT, "onkey", info);
  87. if (ret < 0) {
  88. dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
  89. info->irq, ret);
  90. goto out_irq;
  91. }
  92. platform_set_drvdata(pdev, info);
  93. return 0;
  94. out_irq:
  95. input_unregister_device(info->idev);
  96. kfree(info);
  97. return ret;
  98. out_reg:
  99. input_free_device(info->idev);
  100. out:
  101. kfree(info);
  102. return ret;
  103. }
  104. static int __devexit pm860x_onkey_remove(struct platform_device *pdev)
  105. {
  106. struct pm860x_onkey_info *info = platform_get_drvdata(pdev);
  107. free_irq(info->irq, info);
  108. input_unregister_device(info->idev);
  109. kfree(info);
  110. return 0;
  111. }
  112. static struct platform_driver pm860x_onkey_driver = {
  113. .driver = {
  114. .name = "88pm860x-onkey",
  115. .owner = THIS_MODULE,
  116. },
  117. .probe = pm860x_onkey_probe,
  118. .remove = __devexit_p(pm860x_onkey_remove),
  119. };
  120. static int __init pm860x_onkey_init(void)
  121. {
  122. return platform_driver_register(&pm860x_onkey_driver);
  123. }
  124. module_init(pm860x_onkey_init);
  125. static void __exit pm860x_onkey_exit(void)
  126. {
  127. platform_driver_unregister(&pm860x_onkey_driver);
  128. }
  129. module_exit(pm860x_onkey_exit);
  130. MODULE_DESCRIPTION("Marvell 88PM860x ONKEY driver");
  131. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  132. MODULE_LICENSE("GPL");