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)  * Retu power button driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Copyright (C) 2004-2010 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Original code written by Ari Saastamoinen, Juha Yrjölä and Felipe Balbi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Rewritten by Aaro Koskinen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * Public License. See the file "COPYING" in the main directory of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  * archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)  * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mfd/retu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define RETU_STATUS_PWRONX (1 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static irqreturn_t retu_pwrbutton_irq(int irq, void *_pwr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	struct input_dev *idev = _pwr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	struct retu_dev *rdev = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	bool state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	state = !(retu_read(rdev, RETU_REG_STATUS) & RETU_STATUS_PWRONX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	input_report_key(idev, KEY_POWER, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int retu_pwrbutton_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	idev = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	idev->name = "retu-pwrbutton";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	idev->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	input_set_capability(idev, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	input_set_drvdata(idev, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	error = devm_request_threaded_irq(&pdev->dev, irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 					  NULL, retu_pwrbutton_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 					  IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 					  "retu-pwrbutton", idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	error = input_register_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static struct platform_driver retu_pwrbutton_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	.probe		= retu_pwrbutton_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		.name	= "retu-pwrbutton",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) module_platform_driver(retu_pwrbutton_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) MODULE_ALIAS("platform:retu-pwrbutton");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) MODULE_DESCRIPTION("Retu Power Button");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) MODULE_AUTHOR("Ari Saastamoinen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_AUTHOR("Felipe Balbi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_LICENSE("GPL");