1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * driver for powerbutton on IBM cell blades
5 * (C) Copyright IBM Corp. 2005-2008
10 #include <linux/input.h>
11 #include <linux/module.h>
13 #include <linux/platform_device.h>
16 static struct input_dev *button_dev;
17 static struct platform_device *button_pdev;
19 static void cbe_powerbutton_handle_pmi(pmi_message_t pmi_msg)
21 BUG_ON(pmi_msg.type != PMI_TYPE_POWER_BUTTON);
23 input_report_key(button_dev, KEY_POWER, 1);
24 input_sync(button_dev);
25 input_report_key(button_dev, KEY_POWER, 0);
26 input_sync(button_dev);
29 static struct pmi_handler cbe_pmi_handler = {
30 .type = PMI_TYPE_POWER_BUTTON,
31 .handle_pmi_message = cbe_powerbutton_handle_pmi,
34 static int __init cbe_powerbutton_init(void)
37 struct input_dev *dev;
39 if (!of_machine_is_compatible("IBM,CBPLUS-1.0")) {
40 printk(KERN_ERR "%s: Not a cell blade.\n", __func__);
45 dev = input_allocate_device();
48 printk(KERN_ERR "%s: Not enough memory.\n", __func__);
52 set_bit(EV_KEY, dev->evbit);
53 set_bit(KEY_POWER, dev->keybit);
55 dev->name = "Power Button";
56 dev->id.bustype = BUS_HOST;
58 /* this makes the button look like an acpi power button
59 * no clue whether anyone relies on that though */
60 dev->id.product = 0x02;
61 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);
69 dev->dev.parent = &button_pdev->dev;
70 ret = input_register_device(dev);
72 printk(KERN_ERR "%s: Failed to register device\n", __func__);
78 ret = pmi_register_handler(&cbe_pmi_handler);
80 printk(KERN_ERR "%s: Failed to register with pmi.\n", __func__);
87 platform_device_unregister(button_pdev);
89 input_free_device(dev);
94 static void __exit cbe_powerbutton_exit(void)
96 pmi_unregister_handler(&cbe_pmi_handler);
97 platform_device_unregister(button_pdev);
98 input_free_device(button_dev);
101 module_init(cbe_powerbutton_init);
102 module_exit(cbe_powerbutton_exit);
104 MODULE_DESCRIPTION("Driver for powerbutton on IBM cell blades");
105 MODULE_LICENSE("GPL");