2 * 88pm860x_onkey.c - Marvell 88PM860x ONKEY driver
4 * Copyright (C) 2009-2010 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file "COPYING" in the main directory of this
9 * archive for more details.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <linux/i2c.h>
25 #include <linux/input.h>
26 #include <linux/interrupt.h>
27 #include <linux/mfd/88pm860x.h>
28 #include <linux/slab.h>
30 #define PM8607_WAKEUP 0x0b
32 #define LONG_ONKEY_EN (1 << 1)
33 #define ONKEY_STATUS (1 << 0)
35 struct pm860x_onkey_info
{
36 struct input_dev
*idev
;
37 struct pm860x_chip
*chip
;
38 struct i2c_client
*i2c
;
43 /* 88PM860x gives us an interrupt when ONKEY is held */
44 static irqreturn_t
pm860x_onkey_handler(int irq
, void *data
)
46 struct pm860x_onkey_info
*info
= data
;
49 ret
= pm860x_reg_read(info
->i2c
, PM8607_STATUS_2
);
51 input_report_key(info
->idev
, KEY_POWER
, ret
);
52 input_sync(info
->idev
);
54 /* Enable 8-second long onkey detection */
55 pm860x_set_bits(info
->i2c
, PM8607_WAKEUP
, 3, LONG_ONKEY_EN
);
59 static int __devinit
pm860x_onkey_probe(struct platform_device
*pdev
)
61 struct pm860x_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
62 struct pm860x_onkey_info
*info
;
65 irq
= platform_get_irq(pdev
, 0);
67 dev_err(&pdev
->dev
, "No IRQ resource!\n");
71 info
= kzalloc(sizeof(struct pm860x_onkey_info
), GFP_KERNEL
);
75 info
->i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client
: chip
->companion
;
76 info
->dev
= &pdev
->dev
;
79 info
->idev
= input_allocate_device();
81 dev_err(chip
->dev
, "Failed to allocate input dev\n");
86 info
->idev
->name
= "88pm860x_on";
87 info
->idev
->phys
= "88pm860x_on/input0";
88 info
->idev
->id
.bustype
= BUS_I2C
;
89 info
->idev
->dev
.parent
= &pdev
->dev
;
90 info
->idev
->evbit
[0] = BIT_MASK(EV_KEY
);
91 info
->idev
->keybit
[BIT_WORD(KEY_POWER
)] = BIT_MASK(KEY_POWER
);
93 ret
= input_register_device(info
->idev
);
95 dev_err(chip
->dev
, "Can't register input device: %d\n", ret
);
99 ret
= request_threaded_irq(info
->irq
, NULL
, pm860x_onkey_handler
,
100 IRQF_ONESHOT
, "onkey", info
);
102 dev_err(chip
->dev
, "Failed to request IRQ: #%d: %d\n",
107 platform_set_drvdata(pdev
, info
);
111 input_unregister_device(info
->idev
);
116 input_free_device(info
->idev
);
122 static int __devexit
pm860x_onkey_remove(struct platform_device
*pdev
)
124 struct pm860x_onkey_info
*info
= platform_get_drvdata(pdev
);
126 free_irq(info
->irq
, info
);
127 input_unregister_device(info
->idev
);
132 static struct platform_driver pm860x_onkey_driver
= {
134 .name
= "88pm860x-onkey",
135 .owner
= THIS_MODULE
,
137 .probe
= pm860x_onkey_probe
,
138 .remove
= __devexit_p(pm860x_onkey_remove
),
140 module_platform_driver(pm860x_onkey_driver
);
142 MODULE_DESCRIPTION("Marvell 88PM860x ONKEY driver");
143 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
144 MODULE_LICENSE("GPL");