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)  * Power off driver for ams AS3722 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Author: Laxman Dewangan <ldewangan@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/mfd/as3722.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.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) struct as3722_poweroff {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	struct as3722 *as3722;
^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) static struct as3722_poweroff *as3722_pm_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static void as3722_pm_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (!as3722_pm_poweroff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		pr_err("AS3722 poweroff is not initialised\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	ret = as3722_update_bits(as3722_pm_poweroff->as3722,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 		AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		dev_err(as3722_pm_poweroff->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 			"RESET_CONTROL_REG update failed, %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int as3722_poweroff_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	struct as3722_poweroff *as3722_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	struct device_node *np = pdev->dev.parent->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	if (!of_property_read_bool(np, "ams,system-power-controller"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	if (!as3722_poweroff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	as3722_poweroff->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	as3722_pm_poweroff = as3722_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	if (!pm_power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		pm_power_off = as3722_pm_power_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int as3722_poweroff_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	if (pm_power_off == as3722_pm_power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		pm_power_off = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	as3722_pm_poweroff = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct platform_driver as3722_poweroff_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 		.name = "as3722-power-off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	.probe = as3722_poweroff_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	.remove = as3722_poweroff_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) module_platform_driver(as3722_poweroff_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) MODULE_ALIAS("platform:as3722-power-off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) MODULE_LICENSE("GPL v2");