2 * Power button driver for Medfield.
4 * Copyright (C) 2010 Intel Corp
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/slab.h>
24 #include <linux/platform_device.h>
25 #include <linux/input.h>
26 #include <asm/intel_scu_ipc.h>
28 #define DRIVER_NAME "msic_power_btn"
30 #define MSIC_IRQ_STAT 0x02
31 #define MSIC_IRQ_PB (1 << 0)
32 #define MSIC_PB_CONFIG 0x3e
33 #define MSIC_PB_STATUS 0x3f
34 #define MSIC_PB_LEVEL (1 << 3) /* 1 - release, 0 - press */
37 struct input_dev *input;
41 static irqreturn_t mfld_pb_isr(int irq, void *dev_id)
43 struct mfld_pb_priv *priv = dev_id;
47 ret = intel_scu_ipc_ioread8(MSIC_PB_STATUS, &pbstat);
51 input_event(priv->input, EV_KEY, KEY_POWER, !(pbstat & MSIC_PB_LEVEL));
52 input_sync(priv->input);
57 static int __devinit mfld_pb_probe(struct platform_device *pdev)
59 struct mfld_pb_priv *priv;
60 struct input_dev *input;
64 irq = platform_get_irq(pdev, 0);
68 priv = kzalloc(sizeof(struct mfld_pb_priv), GFP_KERNEL);
69 input = input_allocate_device();
70 if (!priv || !input) {
78 input->name = pdev->name;
79 input->phys = "power-button/input0";
80 input->id.bustype = BUS_HOST;
81 input->dev.parent = &pdev->dev;
83 input_set_capability(input, EV_KEY, KEY_POWER);
85 error = request_threaded_irq(priv->irq, NULL, mfld_pb_isr,
86 0, DRIVER_NAME, priv);
89 "unable to request irq %d for mfld power button\n",
94 error = input_register_device(input);
97 "unable to register input dev, error %d\n", error);
101 platform_set_drvdata(pdev, priv);
105 free_irq(priv->irq, priv);
107 input_free_device(input);
112 static int __devexit mfld_pb_remove(struct platform_device *pdev)
114 struct mfld_pb_priv *priv = platform_get_drvdata(pdev);
116 free_irq(priv->irq, priv);
117 input_unregister_device(priv->input);
120 platform_set_drvdata(pdev, NULL);
124 static struct platform_driver mfld_pb_driver = {
127 .owner = THIS_MODULE,
129 .probe = mfld_pb_probe,
130 .remove = __devexit_p(mfld_pb_remove),
133 static int __init mfld_pb_init(void)
135 return platform_driver_register(&mfld_pb_driver);
137 module_init(mfld_pb_init);
139 static void __exit mfld_pb_exit(void)
141 platform_driver_unregister(&mfld_pb_driver);
143 module_exit(mfld_pb_exit);
145 MODULE_AUTHOR("Hong Liu <hong.liu@intel.com>");
146 MODULE_DESCRIPTION("Intel Medfield Power Button Driver");
147 MODULE_LICENSE("GPL v2");
148 MODULE_ALIAS("platform:" DRIVER_NAME);