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>
27 #include <asm/intel_scu_ipc.h>
29 #define DRIVER_NAME "msic_power_btn"
31 #define MSIC_PB_STATUS 0x3f
32 #define MSIC_PB_LEVEL (1 << 3) /* 1 - release, 0 - press */
34 static irqreturn_t
mfld_pb_isr(int irq
, void *dev_id
)
36 struct input_dev
*input
= dev_id
;
40 ret
= intel_scu_ipc_ioread8(MSIC_PB_STATUS
, &pbstat
);
42 dev_err(input
->dev
.parent
, "Read error %d while reading"
43 " MSIC_PB_STATUS\n", ret
);
45 input_event(input
, EV_KEY
, KEY_POWER
,
46 !(pbstat
& MSIC_PB_LEVEL
));
53 static int __devinit
mfld_pb_probe(struct platform_device
*pdev
)
55 struct input_dev
*input
;
56 int irq
= platform_get_irq(pdev
, 0);
62 input
= input_allocate_device();
64 dev_err(&pdev
->dev
, "Input device allocation error\n");
68 input
->name
= pdev
->name
;
69 input
->phys
= "power-button/input0";
70 input
->id
.bustype
= BUS_HOST
;
71 input
->dev
.parent
= &pdev
->dev
;
73 input_set_capability(input
, EV_KEY
, KEY_POWER
);
75 error
= request_threaded_irq(irq
, NULL
, mfld_pb_isr
, 0,
78 dev_err(&pdev
->dev
, "Unable to request irq %d for mfld power"
83 error
= input_register_device(input
);
85 dev_err(&pdev
->dev
, "Unable to register input dev, error "
90 platform_set_drvdata(pdev
, input
);
96 input_free_device(input
);
100 static int __devexit
mfld_pb_remove(struct platform_device
*pdev
)
102 struct input_dev
*input
= platform_get_drvdata(pdev
);
103 int irq
= platform_get_irq(pdev
, 0);
105 free_irq(irq
, input
);
106 input_unregister_device(input
);
107 platform_set_drvdata(pdev
, NULL
);
112 static struct platform_driver mfld_pb_driver
= {
115 .owner
= THIS_MODULE
,
117 .probe
= mfld_pb_probe
,
118 .remove
= __devexit_p(mfld_pb_remove
),
121 static int __init
mfld_pb_init(void)
123 return platform_driver_register(&mfld_pb_driver
);
125 module_init(mfld_pb_init
);
127 static void __exit
mfld_pb_exit(void)
129 platform_driver_unregister(&mfld_pb_driver
);
131 module_exit(mfld_pb_exit
);
133 MODULE_AUTHOR("Hong Liu <hong.liu@intel.com>");
134 MODULE_DESCRIPTION("Intel Medfield Power Button Driver");
135 MODULE_LICENSE("GPL v2");
136 MODULE_ALIAS("platform:" DRIVER_NAME
);