cbe_powerbutton.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * driver for powerbutton on IBM cell blades
  3. *
  4. * (C) Copyright IBM Corp. 2005-2008
  5. *
  6. * Author: Christian Krafft <krafft@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/input.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/pmi.h>
  25. #include <asm/prom.h>
  26. static struct input_dev *button_dev;
  27. static struct platform_device *button_pdev;
  28. static void cbe_powerbutton_handle_pmi(pmi_message_t pmi_msg)
  29. {
  30. BUG_ON(pmi_msg.type != PMI_TYPE_POWER_BUTTON);
  31. input_report_key(button_dev, KEY_POWER, 1);
  32. input_sync(button_dev);
  33. input_report_key(button_dev, KEY_POWER, 0);
  34. input_sync(button_dev);
  35. }
  36. static struct pmi_handler cbe_pmi_handler = {
  37. .type = PMI_TYPE_POWER_BUTTON,
  38. .handle_pmi_message = cbe_powerbutton_handle_pmi,
  39. };
  40. static int __init cbe_powerbutton_init(void)
  41. {
  42. int ret = 0;
  43. struct input_dev *dev;
  44. if (!machine_is_compatible("IBM,CBPLUS-1.0")) {
  45. printk(KERN_ERR "%s: Not a cell blade.\n", __func__);
  46. ret = -ENODEV;
  47. goto out;
  48. }
  49. dev = input_allocate_device();
  50. if (!dev) {
  51. ret = -ENOMEM;
  52. printk(KERN_ERR "%s: Not enough memory.\n", __func__);
  53. goto out;
  54. }
  55. set_bit(EV_KEY, dev->evbit);
  56. set_bit(KEY_POWER, dev->keybit);
  57. dev->name = "Power Button";
  58. dev->id.bustype = BUS_HOST;
  59. /* this makes the button look like an acpi power button
  60. * no clue whether anyone relies on that though */
  61. dev->id.product = 0x02;
  62. dev->phys = "LNXPWRBN/button/input0";
  63. button_pdev = platform_device_register_simple("power_button", 0, NULL, 0);
  64. if (IS_ERR(button_pdev)) {
  65. ret = PTR_ERR(button_pdev);
  66. goto out_free_input;
  67. }
  68. dev->dev.parent = &button_pdev->dev;
  69. ret = input_register_device(dev);
  70. if (ret) {
  71. printk(KERN_ERR "%s: Failed to register device\n", __func__);
  72. goto out_free_pdev;
  73. }
  74. button_dev = dev;
  75. ret = pmi_register_handler(&cbe_pmi_handler);
  76. if (ret) {
  77. printk(KERN_ERR "%s: Failed to register with pmi.\n", __func__);
  78. goto out_free_pdev;
  79. }
  80. goto out;
  81. out_free_pdev:
  82. platform_device_unregister(button_pdev);
  83. out_free_input:
  84. input_free_device(dev);
  85. out:
  86. return ret;
  87. }
  88. static void __exit cbe_powerbutton_exit(void)
  89. {
  90. pmi_unregister_handler(&cbe_pmi_handler);
  91. platform_device_unregister(button_pdev);
  92. input_free_device(button_dev);
  93. }
  94. module_init(cbe_powerbutton_init);
  95. module_exit(cbe_powerbutton_exit);
  96. MODULE_LICENSE("GPL");
  97. MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");