Path: blob/master/arch/powerpc/platforms/cell/cbe_powerbutton.c
10818 views
/*1* driver for powerbutton on IBM cell blades2*3* (C) Copyright IBM Corp. 2005-20084*5* Author: Christian Krafft <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2, or (at your option)10* any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.20*/2122#include <linux/input.h>23#include <linux/platform_device.h>24#include <asm/pmi.h>25#include <asm/prom.h>2627static struct input_dev *button_dev;28static struct platform_device *button_pdev;2930static void cbe_powerbutton_handle_pmi(pmi_message_t pmi_msg)31{32BUG_ON(pmi_msg.type != PMI_TYPE_POWER_BUTTON);3334input_report_key(button_dev, KEY_POWER, 1);35input_sync(button_dev);36input_report_key(button_dev, KEY_POWER, 0);37input_sync(button_dev);38}3940static struct pmi_handler cbe_pmi_handler = {41.type = PMI_TYPE_POWER_BUTTON,42.handle_pmi_message = cbe_powerbutton_handle_pmi,43};4445static int __init cbe_powerbutton_init(void)46{47int ret = 0;48struct input_dev *dev;4950if (!of_machine_is_compatible("IBM,CBPLUS-1.0")) {51printk(KERN_ERR "%s: Not a cell blade.\n", __func__);52ret = -ENODEV;53goto out;54}5556dev = input_allocate_device();57if (!dev) {58ret = -ENOMEM;59printk(KERN_ERR "%s: Not enough memory.\n", __func__);60goto out;61}6263set_bit(EV_KEY, dev->evbit);64set_bit(KEY_POWER, dev->keybit);6566dev->name = "Power Button";67dev->id.bustype = BUS_HOST;6869/* this makes the button look like an acpi power button70* no clue whether anyone relies on that though */71dev->id.product = 0x02;72dev->phys = "LNXPWRBN/button/input0";7374button_pdev = platform_device_register_simple("power_button", 0, NULL, 0);75if (IS_ERR(button_pdev)) {76ret = PTR_ERR(button_pdev);77goto out_free_input;78}7980dev->dev.parent = &button_pdev->dev;81ret = input_register_device(dev);82if (ret) {83printk(KERN_ERR "%s: Failed to register device\n", __func__);84goto out_free_pdev;85}8687button_dev = dev;8889ret = pmi_register_handler(&cbe_pmi_handler);90if (ret) {91printk(KERN_ERR "%s: Failed to register with pmi.\n", __func__);92goto out_free_pdev;93}9495goto out;9697out_free_pdev:98platform_device_unregister(button_pdev);99out_free_input:100input_free_device(dev);101out:102return ret;103}104105static void __exit cbe_powerbutton_exit(void)106{107pmi_unregister_handler(&cbe_pmi_handler);108platform_device_unregister(button_pdev);109input_free_device(button_dev);110}111112module_init(cbe_powerbutton_init);113module_exit(cbe_powerbutton_exit);114115MODULE_LICENSE("GPL");116MODULE_AUTHOR("Christian Krafft <[email protected]>");117118119