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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (C) 2018 Spreadtrum Communications Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Copyright (C) 2018 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/kernel.h>
^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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/syscore_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define SC27XX_PWR_PD_HW	0xc2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define SC27XX_PWR_OFF_EN	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define SC27XX_SLP_CTRL		0xdf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define SC27XX_LDO_XTL_EN	BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * On Spreadtrum platform, we need power off system through external SC27xx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * which is not fast io access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * So before stopping other cores, we need release other cores' resource by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  * taking cpus down to avoid racing regmap or spi mutex lock when poweroff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  * system through PMIC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void sc27xx_poweroff_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	for_each_online_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		if (cpu != smp_processor_id())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 			remove_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static struct syscore_ops poweroff_syscore_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	.shutdown = sc27xx_poweroff_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static void sc27xx_poweroff_do_poweroff(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	/* Disable the external subsys connection's power firstly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
^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 int sc27xx_poweroff_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	if (regmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	regmap = dev_get_regmap(pdev->dev.parent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	if (!regmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	pm_power_off = sc27xx_poweroff_do_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	register_syscore_ops(&poweroff_syscore_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static struct platform_driver sc27xx_poweroff_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	.probe = sc27xx_poweroff_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		.name = "sc27xx-poweroff",
^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) module_platform_driver(sc27xx_poweroff_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) MODULE_DESCRIPTION("Power off driver for SC27XX PMIC Device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) MODULE_AUTHOR("Baolin Wang <baolin.wang@unisoc.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) MODULE_LICENSE("GPL v2");