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)  * Suspend/resume support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright 2009  MontaVista Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Author: Anton Vorontsov <avorontsov@ru.mvista.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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct pmc_regs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	__be32 devdisr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	__be32 devdisr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	__be32 :32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	__be32 :32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	__be32 pmcsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define PMCSR_SLP	(1 << 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct device *pmc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct pmc_regs __iomem *pmc_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int pmc_suspend_enter(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	setbits32(&pmc_regs->pmcsr, PMCSR_SLP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	/* At this point, the CPU is asleep. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	/* Upon resume, wait for SLP bit to be clear. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 				 10000, 10) ? 0 : -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		dev_err(pmc_dev, "tired waiting for SLP bit to clear\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return ret;
^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 int pmc_suspend_valid(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	if (state != PM_SUSPEND_STANDBY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static const struct platform_suspend_ops pmc_suspend_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	.valid = pmc_suspend_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	.enter = pmc_suspend_enter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int pmc_probe(struct platform_device *ofdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	pmc_regs = of_iomap(ofdev->dev.of_node, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	if (!pmc_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	pmc_dev = &ofdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	suspend_set_ops(&pmc_suspend_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static const struct of_device_id pmc_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	{ .compatible = "fsl,mpc8548-pmc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	{ .compatible = "fsl,mpc8641d-pmc", },
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static struct platform_driver pmc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		.name = "fsl-pmc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 		.of_match_table = pmc_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	.probe = pmc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) builtin_platform_driver(pmc_driver);