pcf50633-input.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* NXP PCF50633 Input Driver
  2. *
  3. * (C) 2006-2008 by Openmoko, Inc.
  4. * Author: Balaji Rao <balajirrao@openmoko.org>
  5. * All rights reserved.
  6. *
  7. * Broken down from monstrous PCF50633 driver mainly by
  8. * Harald Welte, Andy Green and Werner Almesberger
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/input.h>
  21. #include <linux/slab.h>
  22. #include <linux/mfd/pcf50633/core.h>
  23. #define PCF50633_OOCSTAT_ONKEY 0x01
  24. #define PCF50633_REG_OOCSTAT 0x12
  25. #define PCF50633_REG_OOCMODE 0x10
  26. struct pcf50633_input {
  27. struct pcf50633 *pcf;
  28. struct input_dev *input_dev;
  29. };
  30. static void
  31. pcf50633_input_irq(int irq, void *data)
  32. {
  33. struct pcf50633_input *input;
  34. int onkey_released;
  35. input = data;
  36. /* We report only one event depending on the key press status */
  37. onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT)
  38. & PCF50633_OOCSTAT_ONKEY;
  39. if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
  40. input_report_key(input->input_dev, KEY_POWER, 1);
  41. else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
  42. input_report_key(input->input_dev, KEY_POWER, 0);
  43. input_sync(input->input_dev);
  44. }
  45. static int pcf50633_input_probe(struct platform_device *pdev)
  46. {
  47. struct pcf50633_input *input;
  48. struct input_dev *input_dev;
  49. int ret;
  50. input = kzalloc(sizeof(*input), GFP_KERNEL);
  51. if (!input)
  52. return -ENOMEM;
  53. input_dev = input_allocate_device();
  54. if (!input_dev) {
  55. kfree(input);
  56. return -ENOMEM;
  57. }
  58. platform_set_drvdata(pdev, input);
  59. input->pcf = dev_to_pcf50633(pdev->dev.parent);
  60. input->input_dev = input_dev;
  61. input_dev->name = "PCF50633 PMU events";
  62. input_dev->id.bustype = BUS_I2C;
  63. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
  64. set_bit(KEY_POWER, input_dev->keybit);
  65. ret = input_register_device(input_dev);
  66. if (ret) {
  67. input_free_device(input_dev);
  68. kfree(input);
  69. return ret;
  70. }
  71. pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYR,
  72. pcf50633_input_irq, input);
  73. pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYF,
  74. pcf50633_input_irq, input);
  75. return 0;
  76. }
  77. static int pcf50633_input_remove(struct platform_device *pdev)
  78. {
  79. struct pcf50633_input *input = platform_get_drvdata(pdev);
  80. pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR);
  81. pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF);
  82. input_unregister_device(input->input_dev);
  83. kfree(input);
  84. return 0;
  85. }
  86. static struct platform_driver pcf50633_input_driver = {
  87. .driver = {
  88. .name = "pcf50633-input",
  89. },
  90. .probe = pcf50633_input_probe,
  91. .remove = pcf50633_input_remove,
  92. };
  93. module_platform_driver(pcf50633_input_driver);
  94. MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
  95. MODULE_DESCRIPTION("PCF50633 input driver");
  96. MODULE_LICENSE("GPL");
  97. MODULE_ALIAS("platform:pcf50633-input");