Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * via-pmu event device for reporting some events that come through the PMU
0003  *
0004  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful, but
0012  * WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0014  * NON INFRINGEMENT.  See the GNU General Public License for more
0015  * details.
0016  *
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
0020  *
0021  */
0022 
0023 #include <linux/input.h>
0024 #include <linux/adb.h>
0025 #include <linux/pmu.h>
0026 #include "via-pmu-event.h"
0027 
0028 static struct input_dev *pmu_input_dev;
0029 
0030 static int __init via_pmu_event_init(void)
0031 {
0032     int err;
0033 
0034     /* do other models report button/lid status? */
0035     if (pmu_get_model() != PMU_KEYLARGO_BASED)
0036         return -ENODEV;
0037 
0038     pmu_input_dev = input_allocate_device();
0039     if (!pmu_input_dev)
0040         return -ENOMEM;
0041 
0042     pmu_input_dev->name = "PMU";
0043     pmu_input_dev->id.bustype = BUS_HOST;
0044     pmu_input_dev->id.vendor = 0x0001;
0045     pmu_input_dev->id.product = 0x0001;
0046     pmu_input_dev->id.version = 0x0100;
0047 
0048     set_bit(EV_KEY, pmu_input_dev->evbit);
0049     set_bit(EV_SW, pmu_input_dev->evbit);
0050     set_bit(KEY_POWER, pmu_input_dev->keybit);
0051     set_bit(SW_LID, pmu_input_dev->swbit);
0052 
0053     err = input_register_device(pmu_input_dev);
0054     if (err)
0055         input_free_device(pmu_input_dev);
0056     return err;
0057 }
0058 
0059 void via_pmu_event(int key, int down)
0060 {
0061 
0062     if (unlikely(!pmu_input_dev))
0063         return;
0064 
0065     switch (key) {
0066     case PMU_EVT_POWER:
0067         input_report_key(pmu_input_dev, KEY_POWER, down);
0068         break;
0069     case PMU_EVT_LID:
0070         input_report_switch(pmu_input_dev, SW_LID, down);
0071         break;
0072     default:
0073         /* no such key handled */
0074         return;
0075     }
0076 
0077     input_sync(pmu_input_dev);
0078 }
0079 
0080 late_initcall(via_pmu_event_init);