Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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