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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Generic Syscon Poweroff Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015, National Instruments Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Moritz Fischer <moritz.fischer@ettus.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct regmap *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static void syscon_poweroff(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	/* Issue the poweroff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	regmap_update_bits(map, offset, mask, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	mdelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	pr_emerg("Unable to poweroff system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int syscon_poweroff_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	char symname[KSYM_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int mask_err, value_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (IS_ERR(map)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		dev_err(&pdev->dev, "unable to get syscon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return PTR_ERR(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (of_property_read_u32(pdev->dev.of_node, "offset", &offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		dev_err(&pdev->dev, "unable to read 'offset'");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	value_err = of_property_read_u32(pdev->dev.of_node, "value", &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	mask_err = of_property_read_u32(pdev->dev.of_node, "mask", &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (value_err && mask_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		dev_err(&pdev->dev, "unable to read 'value' and 'mask'");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -EINVAL;
^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) 	if (value_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		/* support old binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		value = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		mask = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	} else if (mask_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		/* support value without mask*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		mask = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (pm_power_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		lookup_symbol_name((ulong)pm_power_off, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		"pm_power_off already claimed %p %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		pm_power_off, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	pm_power_off = syscon_poweroff;
^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 int syscon_poweroff_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (pm_power_off == syscon_poweroff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		pm_power_off = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static const struct of_device_id syscon_poweroff_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{ .compatible = "syscon-poweroff" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static struct platform_driver syscon_poweroff_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.probe = syscon_poweroff_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.remove = syscon_poweroff_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		.name = "syscon-poweroff",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.of_match_table = syscon_poweroff_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int __init syscon_poweroff_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return platform_driver_register(&syscon_poweroff_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) device_initcall(syscon_poweroff_register);