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) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * h3600 atmel micro companion support, key subdevice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * based on previous kernel 2.4 version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author : Alessandro Gardich <gremlin@gremlin.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author : Linus Walleij <linus.walleij@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mfd/ipaq-micro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct ipaq_micro_keys {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct ipaq_micro *micro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u16 *codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const u16 micro_keycodes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	KEY_RECORD,		/* 1:  Record button			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	KEY_CALENDAR,		/* 2:  Calendar				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	KEY_ADDRESSBOOK,	/* 3:  Contacts (looks like Outlook)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	KEY_MAIL,		/* 4:  Envelope (Q on older iPAQs)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	KEY_HOMEPAGE,		/* 5:  Start (looks like swoopy arrow)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	KEY_UP,			/* 6:  Up				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	KEY_RIGHT,		/* 7:  Right				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	KEY_LEFT,		/* 8:  Left				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	KEY_DOWN,		/* 9:  Down				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void micro_key_receive(void *data, int len, unsigned char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct ipaq_micro_keys *keys = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int key, down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	down = 0x80 & msg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	key  = 0x7f & msg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (key < ARRAY_SIZE(micro_keycodes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		input_report_key(keys->input, keys->codes[key], down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		input_sync(keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void micro_key_start(struct ipaq_micro_keys *keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	spin_lock(&keys->micro->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	keys->micro->key = micro_key_receive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	keys->micro->key_data = keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	spin_unlock(&keys->micro->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static void micro_key_stop(struct ipaq_micro_keys *keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	spin_lock(&keys->micro->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	keys->micro->key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	keys->micro->key_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	spin_unlock(&keys->micro->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int micro_key_open(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct ipaq_micro_keys *keys = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	micro_key_start(keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return 0;
^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) static void micro_key_close(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct ipaq_micro_keys *keys = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	micro_key_stop(keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int micro_key_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct ipaq_micro_keys *keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	keys->micro = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	keys->input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!keys->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	keys->input->keycodesize = sizeof(micro_keycodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	keys->input->keycodemax = ARRAY_SIZE(micro_keycodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	keys->codes = devm_kmemdup(&pdev->dev, micro_keycodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			   keys->input->keycodesize * keys->input->keycodemax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	keys->input->keycode = keys->codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	__set_bit(EV_KEY, keys->input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	for (i = 0; i < ARRAY_SIZE(micro_keycodes); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		__set_bit(micro_keycodes[i], keys->input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	keys->input->name = "h3600 micro keys";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	keys->input->open = micro_key_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	keys->input->close = micro_key_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	input_set_drvdata(keys->input, keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	error = input_register_device(keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	platform_set_drvdata(pdev, keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int __maybe_unused micro_key_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct ipaq_micro_keys *keys = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	micro_key_stop(keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int __maybe_unused micro_key_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct ipaq_micro_keys *keys = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct input_dev *input = keys->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	mutex_lock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		micro_key_start(keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mutex_unlock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static SIMPLE_DEV_PM_OPS(micro_key_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			 micro_key_suspend, micro_key_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static struct platform_driver micro_key_device_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		.name    = "ipaq-micro-keys",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		.pm	= &micro_key_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.probe   = micro_key_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) module_platform_driver(micro_key_device_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) MODULE_DESCRIPTION("driver for iPAQ Atmel micro keys");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) MODULE_ALIAS("platform:ipaq-micro-keys");