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 2008 Openmoko, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright 2004-2008 Simtec Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) //	Ben Dooks <ben@simtec.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //	http://armlinux.simtec.co.uk/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) // S3C common power management (suspend to ram) support.
^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/suspend.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/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/serial_s3c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "regs-clock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "regs-irq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <mach/irqs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "cpu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "pm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "pm-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* for external use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) unsigned long s3c_pm_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* The IRQ ext-int code goes here, it is too small to currently bother
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * with its own file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) unsigned long s3c_irqwake_intmask	= 0xffffffffL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) unsigned long s3c_irqwake_eintmask	= 0xffffffffL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) int s3c_irqext_wake(struct irq_data *data, unsigned int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (!(s3c_irqwake_eintallow & bit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	printk(KERN_INFO "wake %s for irq %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	       state ? "enabled" : "disabled", data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (!state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		s3c_irqwake_eintmask |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		s3c_irqwake_eintmask &= ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) void (*pm_cpu_prep)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) int (*pm_cpu_sleep)(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /* s3c_pm_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * central control for sleep/resume process
^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 int s3c_pm_enter(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* ensure the debug is initialised (if enabled) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	s3c_pm_debug_init_uart();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	S3C_PMDBG("%s(%d)\n", __func__, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* check if we have anything to wake-up with... bad things seem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * to happen if you suspend with no wakeup (system will often
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * require a full power-cycle)
^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) 	if (!of_have_populated_dt() &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	    !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	    !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		printk(KERN_ERR "%s: Aborting sleep\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/* save all necessary core registers not covered by the drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (!of_have_populated_dt()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		samsung_pm_save_gpios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		samsung_pm_saved_gpios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	s3c_pm_save_uarts(soc_is_s3c2410());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	s3c_pm_save_core();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* set the irq configuration for wake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	s3c_pm_configure_extint();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	    s3c_irqwake_intmask, s3c_irqwake_eintmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	s3c_pm_arch_prepare_irqs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* call cpu specific preparation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	pm_cpu_prep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* flush cache back to ram */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	s3c_pm_check_store();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* send the cpu to sleep... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	s3c_pm_arch_stop_clocks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* this will also act as our return point from when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 * we resume as it saves its own register state and restores it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * during the resume.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret = cpu_suspend(0, pm_cpu_sleep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* restore the system state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	s3c_pm_restore_core();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	s3c_pm_restore_uarts(soc_is_s3c2410());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (!of_have_populated_dt()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		samsung_pm_restore_gpios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		s3c_pm_restored_gpios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	s3c_pm_debug_init_uart();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* check what irq (if any) restored the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	s3c_pm_arch_show_resume_irqs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* LEDs should now be 1110 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	s3c_pm_debug_smdkled(1 << 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	s3c_pm_check_restore();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* ok, let's return from sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	S3C_PMDBG("S3C PM Resume (post-restore)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int s3c_pm_prepare(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* prepare check area if configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	s3c_pm_check_prepare();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void s3c_pm_finish(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	s3c_pm_check_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static const struct platform_suspend_ops s3c_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.enter		= s3c_pm_enter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.prepare	= s3c_pm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.finish		= s3c_pm_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.valid		= suspend_valid_only_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* s3c_pm_init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * Attach the power management functions. This should be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * from the board specific initialisation if the board supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int __init s3c_pm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	suspend_set_ops(&s3c_pm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }