Analyze the sys/power/state and perform sleep and wake-up for S3C2416, states3c2416

Source: Internet
Author: User

Analyze the sys/power/state and perform sleep and wake-up for S3C2416, states3c2416

Environment: PC: debian-7.6.0 arm cpu: S3C2416 Linux-Kernel: 3.6.0 (FriendlyARM) U-boot: 1.3.4

I. Problem Source

As needed, add the sleep interruption and wake-up functions on the S3C2416, so I will check that Linux supports the S3C2416 sleep mode:
Cat/sys/power/state
After the command is executed, I never imagined that the command was empty and there was no output! That is to say, my kernel currently does not support sleep in any way.
Impossible! Previously, I used the S3C2440 CPU (kernel version Linux_2_6_31) to achieve interrupted sleep and wake-up. The Linux 3.6 Kernel configuration of S3C2416 is based on the Linux 2.6.31 configuration.
Run Linux 2.6.31:

S3C2440-Linux 2.6.31: cat/sys/power/state returns: mem

After a variety of upside down, black and white, all failed attempts, the ghost machine flashed a flash: since it didn't respond after cat, then the cat/sys/power/state function was called from top to bottom, step by step.
If the guiding ideology is ready, debug it with the help of manman.

II, Debugging process
The function that displays cat/sys/power/state execution results is state_show ():
Kernel/power/main. c

Static ssize_t state_show (struct kobject * kobj, struct kobj_attribute * attr, char * buf)
{
Char * s = buf;
Printk ("<0>" [#1] kernel speaking \ n ");
# Ifdef CONFIG_SUSPEND
Printk ("<0>" [#2] kernel speaking \ n ");
Int I;

For (I = 0; I <PM_SUSPEND_MAX; I ++ ){
If (pm_states [I] &Valid_state (I))
S + = sprintf (s, "% s", pm_states [I]);
}
# Endif
......
}

Compile and burn the kernel and run the cat command. The [#2] kernel speaking information indicates that the CONFIG_SUSPEND macro is defined.
The pm_states [] array is also defined in the same file. Next we will look at the valid_state () function ():
Kernel/power/suspend. c
Bool valid_state (suspend_state_t state)
{
Printk ("<0>" "[#3] kernel speaking [suspend_ops-% d] \ n", suspend_ops );
Return suspend_ops & suspend_ops-> valid (state );
}


After testing this function, the suspend_ops pointer is 0. Haha, the reason is found.
Suspend_ops points to the struct platform_suspend_ops struct. For the role of each member, see the appendix blog. The value of suspend_ops is in suspend_set_ops ():
Kernel/power/suspend. c
Void suspend_set_ops (const struct platform_suspend_ops * ops)
{
Lock_system_sleep ();
Suspend_ops = ops;
Unlock_system_sleep ();
}

The call of suspend_set_ops () can be found in the following function ():
Arch/arm/plat-samsung/pm. c
Int _ init initi_pm_init (void)
{
Printk ("S3C Power Management, Copyright 2004 Simtec Electronics \ n ");

Suspend_set_ops (& cloud_pm_ops );
Return 0;
}


The call of initi_pm_init () is performed in the smdk_machine_init () function ():
Void _ init smdk_machine_init (void)
{
......
Initi_pm_init ();
}


While smdk_machine_init () is called on a specific Board. The S3C2416 is the core board of the friendly arm. In mini2451_machine_init ():
Arch/arm/mach-s3c24xx/mach-mini2451.c
Static void _ init mini2451_machine_init (void)
{
# If defined (CONFIG_S3C24XX_SMDK)
Printk ("<0>" [#4] kernel speaking \ n ");
Smdk_machine_init ();
# Endif
}
Note: [#4] The kernel speaking information does not indicate that the CONFIG_S3C24XX_SMDK macro is not defined.
The CONFIG_S3C24XX_SMDK macro is selected by default after MINI2451 is selected for Kernel configuration, but it is commented out by the friendly arm,Kconfig in the current directory:

config MACH_MINI2451bool "MINI2451"#select S3C24XX_SMDKselect S3C_DEV_FBselect S3C_DEV_HSMMCselect S3C_DEV_HSMMC1select S3C_DEV_NANDselect S3C_DEV_USB_HOSTselect S3C2416_SETUP_SDHCIselect WIRELESS_EXTselect WEXT_SPYselect WEXT_PRIVselect AVERAGEhelp  Say Y here if you are using an FriendlyARM MINI2451
3. added the sleep and wake-up functions of the interrupted mode.
1. Modify arch/arm/mach-s3c24xx/Kconfig, remove the comment before the S3C24XX_SMDK Option
2. Modify the arch/arm/mach-s3c24xx/common-smdk.c, remove the stuff outside of initi_pm_init, and add the wake-up interrupt wake-up source.
See kernel Documentation/arm/Samsung-S3C24XX/Suspend.txt for the following modifications

static irqreturn_t button_irq(int irq, void *pw){return IRQ_HANDLED;}void __init smdk_machine_init(void){/* Configure the LEDs (even if we have no LED support)*/#if 0int ret = gpio_request_array(smdk_led_gpios,     ARRAY_SIZE(smdk_led_gpios));if (!WARN_ON(ret < 0))gpio_free_array(smdk_led_gpios, ARRAY_SIZE(smdk_led_gpios));if (machine_is_smdk2443())smdk_nand_info.twrph0 = 50;s3c_nand_set_platdata(&smdk_nand_info);platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs));#endifrequest_irq(IRQ_EINT0, button_irq, IRQF_TRIGGER_FALLING, "IRQ_EINT0", NULL);enable_irq_wake(IRQ_EINT0);s3c_pm_init();}
3. Add file mach-s3c24xx under arch/arm/common-smdk.h directory

/* arch/arm/mach-s3c24xx/common-smdk.h** Copyright (c) 2006 Simtec Electronics* Ben Dooks <ben@simtec.co.uk>** Common code for SMDK2410 and SMDK2440 boards** http://www.fluff.org/ben/smdk2440/** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.*/extern void smdk_machine_init(void);

4. Modify arch/arm/mach-s3c24xx/mach-mini2451.c, add the header file where smdk_machine_init is located, that is, the common-smdk.h
# Include "common-smdk.h"

Iv. S3C2416 sleep wake-up test
Sleep:
Cat/sys/power/state
Return: mem
Echo mem>/sys/power/state


After sleep, IRQ_EINT0 is triggered, and the CPU is restored. Part:


For better testing, you can run a program that outputs incremental data before sleep.In this way, you can intuitively see the wake-up status.


5. Implementation of underlying driver for sleep and wake-up in S3C2416
To be continued...


Vi. Summary
1. Inspiration is very important.
PS: "genius is 1% of inspiration plus 99 percent of sweat." This is only the first half of the sentence. The last half of the sentence is: "But the 1% inspiration is often more important than 99% of sweat ".
Why do I hear only the first half of the sentence, and don't speak out.

2. The correct method is a shortcut. However, a different path can also increase people's posture.

3. the Linux kernel, especially in terms of principles, knows little about it ,,,

4. Attachment: Linux screenshot command: import pic_name
Standard linu sleep and wake-up Mechanism Analysis (I)

Standard linu sleep and wake-up Mechanism Analysis (2)

Standard linu sleep and wakeup Mechanism Analysis (3)
Standard linu sleep and wake-up Mechanism Analysis (IV)

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.