Linux Kernel support for the S3C2410 sleep mode

Source: Internet
Author: User
Tags apm

Linux Kernel support for the S3C2410 sleep mode

I. S3C2410 supports four Power Supply Modes

(1) Normal Mode

Maximum power consumption. you can disable the clock of a specific controller to reduce power consumption.

(2) Slow Mode

In this mode, there can be no internal PLL, and the power consumption depends on the frequency of the external clock.

(3) idle mode

Fclk is shut down, mainly because of CPU core power saving. Can be awakened by any external interruption

(4) power_off Mode

In addition to the processor wake-up logic unit, the processor does not consume any power. You can use Eint [] or RTC alarm interrupt to wake up the system.

II. Introduction to various power-saving modes of S3C2410

(1) Slow mode (slow)

Set slow_bit of clkslow to 1

(2) idle)

Clkcon [2] is set to 1 and then enters

(3) power-down mode (power_off)

Clkcon [3] is set to 1

 

Iii. Preparations before S3C2410 enters the power-down mode

1. Set Reasonable gpio for power-down mode

2. Block all interrupts in the interrupt shield register.

3. Reasonably configure the wake-up source, including real-time clock

4. Suspend USB. Miscr [] = 11b

5. Store the sleep return address or data that is not lost in the power-down mode in gstatus3, 4

6. Configure miscr [1:0] to pull the data bus

7. Disable LCD

8. Read refresh, clkcon, and miscr registers to populate TLB.

8th points may be a little difficult to understand. You need to explain it:

The reason is that you need to suspend the SDRAM before entering the power-down mode. After the SDRAM is suspended, you also need to operate the refresh, clkcon, and miscr special function registers. The addresses of these registers may be virtual addresses, this requires corresponding entries in TLB. If not, you need to fetch the corresponding page table from the SDRAM. At this time, the SDRAM has been suspended. To prevent this problem, you can read the address to be accessed before suspending the SDRAM, in this way, the corresponding page table items will be retained in the TLB, and the access to refresh, clkcon, and miscr will not require the support of SDRAM.

9. set refresh [22] = 1b to enable the self-Refresh mode for the SDRAM.

10. Wait for the Self-refresh of SDRAM to be effective.

11. Set miscr [] = 111b to enable the signal (sclk0, sclk1 and scke) of the SDRAM to be protected in power_of mode.

12. Set clkcon to enter the power_off mode.

Iv. Wake-up process in power-down mode of S3C2410

1. Wake up the source system to generate an internal reset signal

2. After the system is reset, test whether gstatus2 [2] is indeed awakened from power_off mode.

3. Set miscr [] = 000b to release the SDRAM signal protection

4. Configure the SDRAM Controller

5. Wait until the SDRAM is automatically refreshed and released

6. Read the values of gstatus3 and 4 and use them to return to the program location before sleep.

Note: To wake up the system using an external interrupt Eint [], you must keep the nbatt_flt High.

V. Configure 2.6.26.5 kernel to support S3C2410 Power Management

 

Vi. Linux system's support for the power-down mode of S3C2410

(1) kernel interface driver File

The/Drivers/Char/Linux-2.6.26.5 of the apm-emulation.c Kernel provides an entry function for the system to sleep. In earlier versions, the interface file is arch/ARM/kernel/APM. C.

(2) kernel files related to preparation before entering sleep

Kernel/power/console. c

This file provides functions to sleep or shut down all system processes.

Drivers/base/power/suspend. c

This file enables all devices to drive the suspend function.

(3) enter the settings related file before sleep

ARCH/ARM/mach-s3c2410/PM. c

(4) program files before sleep

ARCH/ARM/mach-s3c2410/sleep. s

(5) The Sleeping wake-up part is in uboot.

CPU/ARM920T/start. s

(6) Assembly segment program files related to the wake-up phase in the kernel

ARCH/ARM/mach-s3c2410/sleep. s

VII. Implementation Method

The specific implementation principle can be obtained by reading the relevant documents above. How to achieve system sleep and Wakeup

(1) kernel Modification Process

Set the sleep wake-up interrupt source based on the actual hardware situation. My system is to interrupt 0-3 as the wake-up source. So let the kernel allow external interruption of the EINT0--3 to wake it up. The kernel version is 2.6.26.5. By default, the system allows eint0.eint15 and irq_rtc as the wake-up source for interruption.

The numbers of initial_irqwake_intmask and initialqwake_eintmask are shielding codes. To enable external interruption of the EINT0--3 as a wake-up source,

To be modified:

ARCH/ARM/plat-s3c24xx/IRQ. c

Unsigned long initi_irqwake_intmask = 0 xffffffffl;

Is:

Unsigned long initi_irqwake_intmask = 0xfffffff0l;

(2) Modify U-boot

The system will run the reset program after sleep, of course, U-boot. To enable the wake-up system to resume normal operation and enter the pre-sleep running position, you need to modify the U-boot

Add the following code to the CPU/ARM920T/start. s of uboot. Note: After the SDRAM is initialized, refer to the fourth title of this article, "S3C2410 power-down mode wake-up process"

/* Power manage check if this is a wake-up from sleep */
LDR R1, = 0x5620.b4
LDR r0, [R1]
Tst r0, #0x02
Beq notpoweroff

/***** LED test ****
LDR r0, = 0x56000050
LDR R1, = 0x55555555
STR R1, [R0]
LDR r0, = 0x56000054
LDR R1, = 0x0
STR R1, [R0]
*/

Wakeupstart:
// Clear sleep reset bit
LDR r0, = 0x5620.b4
MoV R1, #0x2
STR R1, [R0]

LDR r0, = 0x56000080 // release the SDRAM signal Protections
LDR R1, = 0x00010330

STR R1, [R0]

LDR r0, = 0x48000024
LDR R1, [R0]
Bic R1, R1, #0x400000
STR R1, [R0]

MoV RR1, #0x1000
1: subs R1, R1, #1 // wait until the selfrefresh is released.
BNE 1b

/*
LDR r0, = 0x56000050
LDR R1, = 0x55555555
STR R1, [R0]
LDR r0, = 0x56000054
LDR R1, = 0x5555
STR R1, [R0]
*/

LDR r0, = 0x5620.b8 // read a return address go to s3c2410_cpu_resume
LDR R1, [R0]
MoV PC, R1 // go to resume to the position before sleep
NOP
NOP
1: B 1b
Notpoweroff:

(3) Compile the test program

# Include <stdio. h>
# Include <sys/types. h>
# Include <sys/IOCTL. h>
# Include <unistd. h>
# Include <fcntl. h>
# Include <Linux/IOCTL. h>
# Define apm_ioc_standby _ IO ('A', 1)
# Define apm_ioc_suspend _ IO ('A', 2)
Int main (void)
{
Int FD;
FD = open ("/dev/apm_bios", o_rdwr );
If (FD <0 ){
Printf ("FD open failed/N ");
Exit (0 );
}
Printf ("/n/dev/apm_bios opened, FD = % d/N", FD );
IOCTL (FD, apm_ioc_suspend );
Close (FD );
Printf ("/dev/apm_bios closed :)/N ");
Return 0;
}

(4) Test Results

#./Test
.....
Sleep: IRQ wakeup masks: fffffff0, fffffff0
Gstatus3 0x30367140
Gstatus4 0x00000000

Go to sleep status. Press the K10 button, that is, stop 0 and wake up the system.

Gpio [0] con 007 fffff => 007 fffff, dat 00000000 => 00000000
Gpio [1] con 00044555 => 00044555, dat 00000540 => 00000540
Gpio [2] con aaaaaaaa => aaaaaaaa, dat 00000000 => 00000000
Gpio [3] con aaaaaaaa => aaaaaaaa, dat 00000000 => 00000000
Gpio [4] con aaaaa6aa => aaaaa6aa, dat export ffc5 => export ffc5
Gpio [5] con kernel 55aa => kernel 55aa, dat kernel 00fe => kernel 00FF
Gpio [6] con ffa5ff30 => ffa5ffba, dat 0000 aced => 0000 aced
Gpio [7] con 002 afaaa => 002 afaaa, dat 000001ff => 000001fb
Post sleep: irqs 0x02000001, 0x00000200
IRQ 16 asserted at resume
Post sleep, preparing to return
S3C2410 PM resume (post-Restore)
S3c2410-sdi s3c2410-sdi: powered down.
S3c24xx-pm: Check if we have anything to wake-up
Disabling IRQ 52 (PIN 192)
Disabling IRQ 53 (PIN 193)
Disabling IRQ 55 (PIN 195)
Dma3: restoring configuration
Timer tcon = 00000000, tcnt a2c1, tcfg 00000200,00000000, USEC 20171eb8
S3c2410-wdt: watchdog disabled.
S3c2410-i2c s3c2410-i2c: slave address 0x10
S3c2410-i2c s3c2410-i2c: Bus frequency set to 390 kHz
S3c2410-nand s3c2410-nand: tacls = 3, 30ns twrph0 = 7 70ns, twrph1 = 3 30ns
S3c2410-sdi s3c2410-sdi: running at 0 kHz (requested: 0 kHz ).
S3c2410-sdi s3c2410-sdi: running at 98 kHz (requested: 97 kHz ).
S3c2410-sdi s3c2410-sdi: running at 98 kHz (requested: 97 kHz ).
S3c2410-sdi s3c2410-sdi: running at 98 kHz (requested: 97 kHz ).
S3c2410-sdi s3c2410-sdi: powered down.
USB usb1: Root hub lost power or was reset
Restarting tasks... done.
/Dev/apm_bios closed
#

At this time, the system resumes normal operation.

Author: Liu Hongtao, senior lecturer of Huaqing vision embedded training center, and arm ATC authorized training lecturer.

This article from csdn blog: http://blog.csdn.net/farsight2009/archive/2009/05/06/4153348.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.