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)  * PXA250/210 Power Management Routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Original code for the SA11x0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Modified for the PXA250 by Nicolas Pitre:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (c) 2002 Monta Vista Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * modify it under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "pm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static unsigned long *sleep_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) int pxa_pm_enter(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	unsigned long sleep_save_checksum = 0, checksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef CONFIG_IWMMXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/* force any iWMMXt context to ram **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (elf_hwcap & HWCAP_IWMMXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		iwmmxt_task_disable(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* skip registers saving for standby */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->save) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		pxa_cpu_pm_fns->save(sleep_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		/* before sleeping, calculate and save a checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			sleep_save_checksum += sleep_save[i];
^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) 	/* *** go zzz *** */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	pxa_cpu_pm_fns->enter(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->restore) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		/* after sleeping, validate the checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			checksum += sleep_save[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		/* if invalid, display message and wait for a hardware reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (checksum != sleep_save_checksum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			lubbock_set_hexled(0xbadbadc5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				pxa_cpu_pm_fns->enter(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		pxa_cpu_pm_fns->restore(sleep_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	pr_debug("*** made it back from resume\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^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) EXPORT_SYMBOL_GPL(pxa_pm_enter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static int pxa_pm_valid(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (pxa_cpu_pm_fns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return pxa_cpu_pm_fns->valid(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) int pxa_pm_prepare(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		ret = pxa_cpu_pm_fns->prepare();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) void pxa_pm_finish(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		pxa_cpu_pm_fns->finish();
^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 const struct platform_suspend_ops pxa_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.valid		= pxa_pm_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.enter		= pxa_pm_enter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.prepare	= pxa_pm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.finish		= pxa_pm_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int __init pxa_pm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (!pxa_cpu_pm_fns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	sleep_save = kmalloc_array(pxa_cpu_pm_fns->save_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				   sizeof(*sleep_save),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!sleep_save)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	suspend_set_ops(&pxa_pm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) device_initcall(pxa_pm_init);