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