• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * via-pmu event device for reporting some events that come through the PMU
3  *
4  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
5  *
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14  * NON INFRINGEMENT.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  *
21  */
22 
23 #include <linux/input.h>
24 #include <linux/adb.h>
25 #include <linux/pmu.h>
26 #include "via-pmu-event.h"
27 
28 static struct input_dev *pmu_input_dev;
29 
via_pmu_event_init(void)30 static int __init via_pmu_event_init(void)
31 {
32 	int err;
33 
34 	/* do other models report button/lid status? */
35 	if (pmu_get_model() != PMU_KEYLARGO_BASED)
36 		return -ENODEV;
37 
38 	pmu_input_dev = input_allocate_device();
39 	if (!pmu_input_dev)
40 		return -ENOMEM;
41 
42 	pmu_input_dev->name = "PMU";
43 	pmu_input_dev->id.bustype = BUS_HOST;
44 	pmu_input_dev->id.vendor = 0x0001;
45 	pmu_input_dev->id.product = 0x0001;
46 	pmu_input_dev->id.version = 0x0100;
47 
48 	set_bit(EV_KEY, pmu_input_dev->evbit);
49 	set_bit(EV_SW, pmu_input_dev->evbit);
50 	set_bit(KEY_POWER, pmu_input_dev->keybit);
51 	set_bit(SW_LID, pmu_input_dev->swbit);
52 
53 	err = input_register_device(pmu_input_dev);
54 	if (err)
55 		input_free_device(pmu_input_dev);
56 	return err;
57 }
58 
via_pmu_event(int key,int down)59 void via_pmu_event(int key, int down)
60 {
61 
62 	if (unlikely(!pmu_input_dev))
63 		return;
64 
65 	switch (key) {
66 	case PMU_EVT_POWER:
67 		input_report_key(pmu_input_dev, KEY_POWER, down);
68 		break;
69 	case PMU_EVT_LID:
70 		input_report_switch(pmu_input_dev, SW_LID, down);
71 		break;
72 	default:
73 		/* no such key handled */
74 		return;
75 	}
76 
77 	input_sync(pmu_input_dev);
78 }
79 
80 late_initcall(via_pmu_event_init);
81