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)  * Copyright (c) 2014, National Instruments Corp. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Driver for NI Ettus Research USRP E3x0 Button Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static irqreturn_t e3x0_button_release_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct input_dev *idev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	input_report_key(idev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static irqreturn_t e3x0_button_press_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct input_dev *idev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	input_report_key(idev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	pm_wakeup_event(idev->dev.parent, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int __maybe_unused e3x0_button_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		enable_irq_wake(platform_get_irq_byname(pdev, "press"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int __maybe_unused e3x0_button_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		disable_irq_wake(platform_get_irq_byname(pdev, "press"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static SIMPLE_DEV_PM_OPS(e3x0_button_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			 e3x0_button_suspend, e3x0_button_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static int e3x0_button_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int irq_press, irq_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	irq_press = platform_get_irq_byname(pdev, "press");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (irq_press < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return irq_press;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	irq_release = platform_get_irq_byname(pdev, "release");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (irq_release < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return irq_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	input->name = "NI Ettus Research USRP E3x0 Button Driver";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	input->phys = "e3x0_button/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	input->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	input_set_capability(input, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	error = devm_request_irq(&pdev->dev, irq_press,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				 e3x0_button_press_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				 "e3x0-button", input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		dev_err(&pdev->dev, "Failed to request 'press' IRQ#%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			irq_press, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	error = devm_request_irq(&pdev->dev, irq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				 e3x0_button_release_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				 "e3x0-button", input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		dev_err(&pdev->dev, "Failed to request 'release' IRQ#%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			irq_release, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dev_err(&pdev->dev, "Can't register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	device_init_wakeup(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static const struct of_device_id e3x0_button_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	{ .compatible = "ettus,e3x0-button", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_DEVICE_TABLE(of, e3x0_button_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static struct platform_driver e3x0_button_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		.name	= "e3x0-button",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		.of_match_table = of_match_ptr(e3x0_button_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		.pm	= &e3x0_button_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.probe		= e3x0_button_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) module_platform_driver(e3x0_button_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) MODULE_AUTHOR("Moritz Fischer <moritz.fischer@ettus.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_DESCRIPTION("NI Ettus Research USRP E3x0 Button driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) MODULE_ALIAS("platform:e3x0-button");