Path: blob/master/drivers/input/misc/88pm860x_onkey.c
15109 views
/*1* 88pm860x_onkey.c - Marvell 88PM860x ONKEY driver2*3* Copyright (C) 2009-2010 Marvell International Ltd.4* Haojian Zhuang <[email protected]>5*6* This file is subject to the terms and conditions of the GNU General7* Public License. See the file "COPYING" in the main directory of this8* archive for more details.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920#include <linux/kernel.h>21#include <linux/module.h>22#include <linux/platform_device.h>23#include <linux/i2c.h>24#include <linux/input.h>25#include <linux/interrupt.h>26#include <linux/mfd/88pm860x.h>27#include <linux/slab.h>2829#define PM8607_WAKEUP 0x0b3031#define LONG_ONKEY_EN (1 << 1)32#define ONKEY_STATUS (1 << 0)3334struct pm860x_onkey_info {35struct input_dev *idev;36struct pm860x_chip *chip;37struct i2c_client *i2c;38struct device *dev;39int irq;40};4142/* 88PM860x gives us an interrupt when ONKEY is held */43static irqreturn_t pm860x_onkey_handler(int irq, void *data)44{45struct pm860x_onkey_info *info = data;46int ret;4748ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2);49ret &= ONKEY_STATUS;50input_report_key(info->idev, KEY_POWER, ret);51input_sync(info->idev);5253/* Enable 8-second long onkey detection */54pm860x_set_bits(info->i2c, PM8607_WAKEUP, 3, LONG_ONKEY_EN);55return IRQ_HANDLED;56}5758static int __devinit pm860x_onkey_probe(struct platform_device *pdev)59{60struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);61struct pm860x_onkey_info *info;62int irq, ret;6364irq = platform_get_irq(pdev, 0);65if (irq < 0) {66dev_err(&pdev->dev, "No IRQ resource!\n");67return -EINVAL;68}6970info = kzalloc(sizeof(struct pm860x_onkey_info), GFP_KERNEL);71if (!info)72return -ENOMEM;73info->chip = chip;74info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;75info->dev = &pdev->dev;76info->irq = irq;7778info->idev = input_allocate_device();79if (!info->idev) {80dev_err(chip->dev, "Failed to allocate input dev\n");81ret = -ENOMEM;82goto out;83}8485info->idev->name = "88pm860x_on";86info->idev->phys = "88pm860x_on/input0";87info->idev->id.bustype = BUS_I2C;88info->idev->dev.parent = &pdev->dev;89info->idev->evbit[0] = BIT_MASK(EV_KEY);90info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);9192ret = input_register_device(info->idev);93if (ret) {94dev_err(chip->dev, "Can't register input device: %d\n", ret);95goto out_reg;96}9798ret = request_threaded_irq(info->irq, NULL, pm860x_onkey_handler,99IRQF_ONESHOT, "onkey", info);100if (ret < 0) {101dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",102info->irq, ret);103goto out_irq;104}105106platform_set_drvdata(pdev, info);107return 0;108109out_irq:110input_unregister_device(info->idev);111kfree(info);112return ret;113114out_reg:115input_free_device(info->idev);116out:117kfree(info);118return ret;119}120121static int __devexit pm860x_onkey_remove(struct platform_device *pdev)122{123struct pm860x_onkey_info *info = platform_get_drvdata(pdev);124125free_irq(info->irq, info);126input_unregister_device(info->idev);127kfree(info);128return 0;129}130131static struct platform_driver pm860x_onkey_driver = {132.driver = {133.name = "88pm860x-onkey",134.owner = THIS_MODULE,135},136.probe = pm860x_onkey_probe,137.remove = __devexit_p(pm860x_onkey_remove),138};139140static int __init pm860x_onkey_init(void)141{142return platform_driver_register(&pm860x_onkey_driver);143}144module_init(pm860x_onkey_init);145146static void __exit pm860x_onkey_exit(void)147{148platform_driver_unregister(&pm860x_onkey_driver);149}150module_exit(pm860x_onkey_exit);151152MODULE_DESCRIPTION("Marvell 88PM860x ONKEY driver");153MODULE_AUTHOR("Haojian Zhuang <[email protected]>");154MODULE_LICENSE("GPL");155156157