Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Retu power button driver.
0003  *
0004  * Copyright (C) 2004-2010 Nokia Corporation
0005  *
0006  * Original code written by Ari Saastamoinen, Juha Yrjölä and Felipe Balbi.
0007  * Rewritten by Aaro Koskinen.
0008  *
0009  * This file is subject to the terms and conditions of the GNU General
0010  * Public License. See the file "COPYING" in the main directory of this
0011  * archive for more details.
0012  *
0013  * This program is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0016  * GNU General Public License for more details.
0017  */
0018 
0019 #include <linux/irq.h>
0020 #include <linux/slab.h>
0021 #include <linux/errno.h>
0022 #include <linux/input.h>
0023 #include <linux/kernel.h>
0024 #include <linux/module.h>
0025 #include <linux/mfd/retu.h>
0026 #include <linux/interrupt.h>
0027 #include <linux/platform_device.h>
0028 
0029 #define RETU_STATUS_PWRONX (1 << 5)
0030 
0031 static irqreturn_t retu_pwrbutton_irq(int irq, void *_pwr)
0032 {
0033     struct input_dev *idev = _pwr;
0034     struct retu_dev *rdev = input_get_drvdata(idev);
0035     bool state;
0036 
0037     state = !(retu_read(rdev, RETU_REG_STATUS) & RETU_STATUS_PWRONX);
0038     input_report_key(idev, KEY_POWER, state);
0039     input_sync(idev);
0040 
0041     return IRQ_HANDLED;
0042 }
0043 
0044 static int retu_pwrbutton_probe(struct platform_device *pdev)
0045 {
0046     struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent);
0047     struct input_dev *idev;
0048     int irq;
0049     int error;
0050 
0051     irq = platform_get_irq(pdev, 0);
0052     if (irq < 0)
0053         return irq;
0054 
0055     idev = devm_input_allocate_device(&pdev->dev);
0056     if (!idev)
0057         return -ENOMEM;
0058 
0059     idev->name = "retu-pwrbutton";
0060     idev->dev.parent = &pdev->dev;
0061 
0062     input_set_capability(idev, EV_KEY, KEY_POWER);
0063     input_set_drvdata(idev, rdev);
0064 
0065     error = devm_request_threaded_irq(&pdev->dev, irq,
0066                       NULL, retu_pwrbutton_irq,
0067                       IRQF_ONESHOT,
0068                       "retu-pwrbutton", idev);
0069     if (error)
0070         return error;
0071 
0072     error = input_register_device(idev);
0073     if (error)
0074         return error;
0075 
0076     return 0;
0077 }
0078 
0079 static struct platform_driver retu_pwrbutton_driver = {
0080     .probe      = retu_pwrbutton_probe,
0081     .driver     = {
0082         .name   = "retu-pwrbutton",
0083     },
0084 };
0085 module_platform_driver(retu_pwrbutton_driver);
0086 
0087 MODULE_ALIAS("platform:retu-pwrbutton");
0088 MODULE_DESCRIPTION("Retu Power Button");
0089 MODULE_AUTHOR("Ari Saastamoinen");
0090 MODULE_AUTHOR("Felipe Balbi");
0091 MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
0092 MODULE_LICENSE("GPL");