cbe_powerbutton.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * driver for powerbutton on IBM cell blades
  4. *
  5. * (C) Copyright IBM Corp. 2005-2008
  6. *
  7. * Author: Christian Krafft <krafft@de.ibm.com>
  8. */
  9. #include <linux/input.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <asm/pmi.h>
  14. static struct input_dev *button_dev;
  15. static struct platform_device *button_pdev;
  16. static void cbe_powerbutton_handle_pmi(pmi_message_t pmi_msg)
  17. {
  18. BUG_ON(pmi_msg.type != PMI_TYPE_POWER_BUTTON);
  19. input_report_key(button_dev, KEY_POWER, 1);
  20. input_sync(button_dev);
  21. input_report_key(button_dev, KEY_POWER, 0);
  22. input_sync(button_dev);
  23. }
  24. static struct pmi_handler cbe_pmi_handler = {
  25. .type = PMI_TYPE_POWER_BUTTON,
  26. .handle_pmi_message = cbe_powerbutton_handle_pmi,
  27. };
  28. static int __init cbe_powerbutton_init(void)
  29. {
  30. int ret = 0;
  31. struct input_dev *dev;
  32. if (!of_machine_is_compatible("IBM,CBPLUS-1.0")) {
  33. printk(KERN_ERR "%s: Not a cell blade.\n", __func__);
  34. ret = -ENODEV;
  35. goto out;
  36. }
  37. dev = input_allocate_device();
  38. if (!dev) {
  39. ret = -ENOMEM;
  40. printk(KERN_ERR "%s: Not enough memory.\n", __func__);
  41. goto out;
  42. }
  43. set_bit(EV_KEY, dev->evbit);
  44. set_bit(KEY_POWER, dev->keybit);
  45. dev->name = "Power Button";
  46. dev->id.bustype = BUS_HOST;
  47. /* this makes the button look like an acpi power button
  48. * no clue whether anyone relies on that though */
  49. dev->id.product = 0x02;
  50. dev->phys = "LNXPWRBN/button/input0";
  51. button_pdev = platform_device_register_simple("power_button", 0, NULL, 0);
  52. if (IS_ERR(button_pdev)) {
  53. ret = PTR_ERR(button_pdev);
  54. goto out_free_input;
  55. }
  56. dev->dev.parent = &button_pdev->dev;
  57. ret = input_register_device(dev);
  58. if (ret) {
  59. printk(KERN_ERR "%s: Failed to register device\n", __func__);
  60. goto out_free_pdev;
  61. }
  62. button_dev = dev;
  63. ret = pmi_register_handler(&cbe_pmi_handler);
  64. if (ret) {
  65. printk(KERN_ERR "%s: Failed to register with pmi.\n", __func__);
  66. goto out_free_pdev;
  67. }
  68. goto out;
  69. out_free_pdev:
  70. platform_device_unregister(button_pdev);
  71. out_free_input:
  72. input_free_device(dev);
  73. out:
  74. return ret;
  75. }
  76. static void __exit cbe_powerbutton_exit(void)
  77. {
  78. pmi_unregister_handler(&cbe_pmi_handler);
  79. platform_device_unregister(button_pdev);
  80. input_free_device(button_dev);
  81. }
  82. module_init(cbe_powerbutton_init);
  83. module_exit(cbe_powerbutton_exit);
  84. MODULE_DESCRIPTION("Driver for powerbutton on IBM cell blades");
  85. MODULE_LICENSE("GPL");
  86. MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");