
һ. ԴڲӰʹõ豸ǰ¾ʡ

8051:
޵Դ6.1MA 32.2MA
еԴ0.27uA 26.7MA
MCUȫʱĵ6.1ma, ledĵ26ma

LinuxӸ:
1. ӲӣӸ豸Щ豸ҲҪ磬ǰҪ
2. ӣҪͳһĿܣѺҪ³ʼ


. u-bootsuspend
u-bootȫ,ĵ83ma
u-boot suspend:ĵ33ma ==>豸ûȫرգ

ģʽķ
    /* 1. GPIO: άLED, ڻCPUҪΪжϹ */
    /* 2. INTMSKж: sleepģʽ,Щֻڻϵͳ,CPUʱINTMSKЩжϹ */ 
    /* 3. ûԴ */
    /* 4. MISCCR[13:12]=11b, ʹUSBģ */
    /* 5. GSTATUS[4:3]ĳֵ, ǿϵͳʱʹ */
    /* 6.  MISCCR[1:0] ʹߵ */
    /* 7.  LCDCON1.ENVID ֹͣLCD */
    /* 8. 2Ĵ: rREFRESH and rCLKCON, ԱTLB
     *    ʹMMUĻ,ĿĿԺ 
     */
    /* 9.  REFRESH[22]=1b,SDRAMself-refresh mode */
    /* 10. ȴSDRAMɹself-refresh mode  */
    /* 11. MISCCR[19:17]=111bԱSDRAMź(SCLK0,SCLK1 and SCKE) */
    /* 12. CLKCONSLEEPλϵͳsleep mode */   


ϵͳķ
    /* 1. ° */
    /* 2.  GSTATUS2[1]жǸλǻ */ 
    /* 3.  MISCCR[19:17]=000b, ͷSDRAMź */
    /* 4. s3c2440memory controller */
    /* 5. ȴSDRAM˳self-refresh mode */
    /* 6. GSTATUS[3:4]ֵǰĺ */

u-boot-1.1.6_jz2440_suspend.patch


nfs 30000000 192.168.1.124:/work/nfs_root/u-boot.bin;protect off all;erase 0 3ffff;cp.b 30000000 0 40000
nfs 30000000 192.168.1.124:/work/nfs_root/u-boot.bin;nand erase bootloader; nand write.jffs2 30000000 bootloader


. Linuxϵͳsuspendʵ
1. suspend
 suspend to ram:
echo mem > /sys/power/state


state_store (kernel/power/main.c)
    pm_suspend (kernel/power/suspend.c)
        enter_state (kernel/power/suspend.c)
            suspend_prepare (kernel/power/suspend.c)
                pm_prepare_console (kernel/power/console.c)
                    pm_notifier_call_chain(PM_SUSPEND_PREPARE); (kernel/power/main.c)  // ֪ͨй"Ϣ"
                    suspend_freeze_processes (kernel/power/power.h) // APPں߳
            suspend_devices_and_enter (kernel/power/suspend.c) // 豸״̬
                suspend_ops->begin  // ƽ̨صĴbeginȥ          
                suspend_console (kernel/power/suspend.c)
                dpm_suspend_start(PMSG_SUSPEND); (drivers/base/power/main.c)
                    dpm_prepare(state);  (drivers/base/power/main.c)
                        dmp_listеÿһ豸,device_prepare(dev, state);
                                ڸ豸,dev->pm_domain->ops.prepare 
                                                   dev->type->pm->prepare       
                                                   dev->class->pm->prepare      
                                                   dev->bus->pm->prepare        
                                                   dev->driver->pm->prepare
                    dpm_suspend(state); (drivers/base/power/main.c)  // ø豸
                        dpm_prepared_listеÿһ豸,device_suspend(dev);
                            __device_suspend(dev, pm_transition, false);
                                ڸ豸,dev->pm_domain->ops.suspend  
                                                   dev->type->pm->suspend       
                                                   dev->class->pm->suspend      
                                                   dev->bus->pm->suspend        
                                                   dev->driver->pm->suspend

                    suspend_enter(state, &wakeup) (kernel/power/suspend.c)
                        suspend_ops->prepare // s3c_pm_prepare
                        dpm_suspend_end(PMSG_SUSPEND);       (drivers/base/power/main.c) 
                            dpm_suspend_late(state); (drivers/base/power/main.c) 
                                dpm_suspended_listеÿһ豸,device_suspend_late(dev, state);
                                   ڸ豸,dev->pm_domain->ops.suspend_late      
                                                           dev->type->pm->suspend_late      
                                                           dev->class->pm->suspend_late     
                                                           dev->bus->pm->suspend_late       
                                                           dev->driver->pm->suspend_late
                            dpm_suspend_noirq
                                dpm_late_early_listеÿһ豸,device_suspend_noirq(dev, state);
                                   ڸ豸,dev->pm_domain->ops.suspend_noirq      
                                                           dev->type->pm->suspend_noirq      
                                                           dev->class->pm->suspend_noirq     
                                                           dev->bus->pm->suspend_noirq       
                                                           dev->driver->pm->suspend_noirq                                                          
                        suspend_ops->prepare_late() //         
                        disable_nonboot_cpus();     
                        arch_suspend_disable_irqs();
                        syscore_suspend
                        suspend_ops->enter(state);  // s3c_pm_enter (arch\arm\plat-samsung\pm.c)                                                   
                            ......
                            pm_cpu_prep // s3c2410_pm_prepare (arch\arm\mach-s3c24xx\pm-s3c2410.c)
                                GSTATUS3 = s3c_cpu_resume
                                
                            ......  
                            cpu_suspend(0, pm_cpu_sleep); // arch\arm\kernel\sleep.S
                                pm_cpu_sleep (arch\arm\mach-s3c24xx\pm-s3c2410.c) // s3c2410_cpu_suspend
                                    s3c2410_cpu_suspend (arch\arm\mach-s3c24xx\sleep-s3c2410.S)
                            ߹      
                            
                            濪ʼѹ
                            , u-boot, ȡGSTATUS3, ִs3c_cpu_resume 
                            .....
                            s3c_pm_restore_core
                        syscore_resume
                        arch_suspend_enable_irqs
                        enable_nonboot_cpus
                        suspend_ops->wake
                        dpm_resume_start(PMSG_RESUME);  
                            dpm_resume_noirq(state);
                                dpm_noirq_listеÿһ豸,device_resume_noirq(dev, state);
                                    ڸ豸,dev->pm_domain->ops.resume_noirq      
                                                           dev->type->pm->resume_noirq       
                                                           dev->class->pm->resume_noirq      
                                                           dev->bus->pm->resume_noirq        
                                                           dev->driver->pm->resume_noirq
                            dpm_resume_early(state);
                                dpm_late_early_listеÿһ豸,device_resume_early(dev, state);
                                    ڸ豸,dev->pm_domain->ops.resume_early      
                                                           dev->type->pm->resume_early       
                                                           dev->class->pm->resume_early      
                                                           dev->bus->pm->resume_early        
                                                           dev->driver->pm->resume_early
                            suspend_ops->finish()
                                s3c_pm_finish
                                            
                dpm_resume_end(PMSG_RESUME);
                    dpm_resume(state);
                        dpm_suspended_listеÿһ豸,device_resume(dev, state, false);
                            ڸ豸,dev->pm_domain->ops.resume     
                                                   dev->type->pm->resume       
                                                   dev->class->pm->resume      
                                                   dev->bus->pm->resume        
                                                   dev->driver->pm->resume
                    dpm_complete(state);
                        dpm_prepared_listеÿһ豸,device_complete(dev, state);
                            ڸ豸,dev->pm_domain->ops.complete     
                                                   dev->type->pm->complete       
                                                   dev->class->pm->complete      
                                                   dev->bus->pm->complete        
                                                   dev->driver->pm->complete
                        
                resume_console();
            suspend_finish();
                suspend_thaw_processes();
                pm_notifier_call_chain(PM_POST_SUSPEND);
                pm_restore_console();
            //ûռ  


صĵԴĵù:
: prepare>suspend>suspend_late>suspend_noirq
: resume_noirq>resume_early>resume-->complete

    
ο:
ʵ: LinuxԴ(6)_Generic PM֮Suspend 
http://www.wowotech.net/linux_kenrel/suspend_and_resume.html

漰Ľӿ: LinuxԴ(4)_Power Management Interface
http://www.wowotech.net/linux_kenrel/pm_interface.html
        
                    
                                

power_attr(state);

static struct kobj_attribute state_attr = { \
    .attr   = {             \
        .name = __stringify("state"),   \
        .mode = 0644,           \
    },                  \
    .show   = state_show,           \
    .store  =state_store,       \
}



arch\arm\plat-samsung\pm.c
s3c_pm_init
    suspend_set_ops(&s3c_pm_ops);
        suspend_ops = ops   


2. ޸ں˻ʹsuspend
ûԴ: GPIOŹжϹ, Ĵʽ

޸ں:
a. ͨs3c_irq_wake޸s3c_irqwake_intmasks3c_irqwake_eintmaskʾԴĸ
b. ҪԼGPIOжϹ,Ĵʽ

int0,1,2,3
eint4,5,...15

ǵİ: request_irq֮s3c_irq_wakes3c_irqext_wake

2.1 ֱ޸ں: s3c_irqwake_intmasks3c_irqwake_eintmask, GPIO

2.2 ޸İ,request_irq֮irq_set_irq_wake

2.1
ѹ¹PATH
sudo tar xjf arm-linux-gcc-4.3.2.tar.bz2 -C /
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/usr/local/arm/4.3.2/bin

ں:
tar xjf linux-3.4.2.tar.bz2 
cd linux-3.4.2
patch -p1 < ../linux-3.4.2_alsa_wm8976_uda1341_jz2440_mini2440_tq2440.patch
cp config_wm8976_jz2440 .config
make menuconfig

޸arch\arm\plat-samsung\pm.c

unsigned long s3c_irqwake_intmask   = 0xfffffffa;
unsigned long s3c_irqwake_eintmask  = 0xfffff7ff;

޸arch\arm\plat-s3c24xx\pm.c  /* ʵ鷢ֲ޸ļҲɹ,ԭUBOOTѾGPIO,жϴ */
    if (!irqstate) {
        if (pinstate == S3C2410_GPIO_IRQ)
            S3C_PMDBG("Leaving IRQ %d (pin %d) as is\n", irq, pin);
+       else{           
+           s3c_gpio_cfgpin(pin, S3C2410_GPIO_IRQ);
+       }
        /* ôʽ */
    } else {

make uImage && cp arch/arm/boot/uImage /work/nfs_root

sudo tar xjf fs_mini_mdev_new.tar.bz2 -C /work/nfs_root/

ʹں
set bootcmd 'nfs 30000000 192.168.1.124:/work/nfs_root/uImage; bootm 30000000'
set bootargs console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.1.124:/work/nfs_root/fs_mini_mdev_new ip=192.168.1.17

ԣ
cat /sys/power/state
echo mem > /sys/power/state



2.2 , request_irqirq_set_irq_wakeָԴ

3. ޸ֵ֧Դ
a. ֪ͨnotifier:
ڶAPP֮ǰ,ʹpm_notifier_call_chain(PM_SUSPEND_PREPARE)֪ͨ
APP֮,ʹpm_notifier_call_chain(PM_POST_SUSPEND)֪ͨ

ʱҪ,ʹregister_pm_notifierעһnotifier

b. suspend, resume
b.1 һͬplatform_device, platform_driver
b.2 Ϸ:platform_driverʵsuspend,resumeԱ
    ·:platform_driverdriverpmṹ, ʵsuspend,resumeԱ

LCD, ںȥ CONFIG_FRAMEBUFFER_CONSOLE, -ѺLCDϵͼ
ӦҲͨAPPֹFramebufferconsole 

ϵͳ״̬LCDʱ, ĵ240mA
ʱ, ĵ50mA



ƪ:
http://blog.csdn.net/bingqingsuimeng/article/details/7935414
http://www.wowotech.net/linux_kenrel/suspend_and_resume.html


. runtime PM (Runtime Power Management)
1. runtime PM
̬ش򿪻ر豸ĵԴ?򵥵ķ:
,openд򿪵Դ,closeйرյԴ

һȱ: APPʹø豸ʱɸ
ʹüֵ: ü0ʱ򿪵Դ, 0ʱرյԴ

ioctl: alsa

runtime PMֻṩ, :
1. Ӽ/ټ
2. ʹruntime pm

ںʾ: drivers\input\misc\bma150.c
pm_runtime_enable / pm_runtime_disable    : ʹ/ֹruntime PM, ޸disable_depth
pm_runtime_get_sync / pm_runtime_put_sync : /Сֵ, 豸resumesuspend״̬

dev_pm_opsṩ3ص: runtime_suspend, runtime_resume, runtime_idle

̷:
pm_runtime_get_sync
    __pm_runtime_resume(dev, RPM_GET_PUT);
        atomic_inc(&dev->power.usage_count);  // ʹü
        rpm_resume(dev, rpmflags);            // resume豸
            if (dev->power.disable_depth > 0) retval = -EACCES; // ñֵΪ1,Ҫʹruntime PM, Ҫpm_runtime_enable
            
            if (!dev->power.timer_autosuspends) // Ϊֹ豸Ƶؿ,timer_autosuspends
                    pm_runtime_deactivate_timer(dev);
            
            if (dev->power.runtime_status == RPM_ACTIVE) { // 豸ѾRPM_ACTIVE,ûҪٴresume,ֱӷ
            
            // 豸RPM_RESUMING/RPM_SUSPENDING, ȴò
            
            // Increment the parent's usage counter and resume it if necessary
            
            // resume豸: ǰ4Ϊ subsystem-level callback
            callback = dev->pm_domain->ops.runtime_resume; 
            callback = dev->type->pm->runtime_resume;      
            callback = dev->class->pm->runtime_resume;     
            callback = dev->bus->pm->runtime_resume;       
            
            callback = dev->driver->pm->runtime_resume;
            
            retval = rpm_callback(callback, dev);
            
            // ɹʱ,׵child_count1
            if (parent)
                atomic_inc(&parent->power.child_count);
            
            // 
            wake_up_all(&dev->power.wait_queue);
            
            // resumeʧ, 豸idle״̬
            if (!retval)
                rpm_idle(dev, RPM_ASYNC);
            
pm_runtime_put_sync
    __pm_runtime_idle(dev, RPM_GET_PUT);
        atomic_dec_and_test(&dev->power.usage_count)  // Сʹü
        rpm_idle(dev, rpmflags);                      // 豸idle״̬
            rpm_check_suspend_allowed(dev);   // Ƿ豸suspend״̬
                if (dev->power.disable_depth > 0) //ʧ
                if (atomic_read(&dev->power.usage_count) > 0) // ǰʹü0,ʧ
                if (!pm_children_suspended(dev))   // ĺӲȫsuspended, ʧ
        if (dev->power.runtime_status != RPM_ACTIVE) // 豸ͲRPM_ACTIVE,ֱӷ
        
        // idleص: ǰ4subsystem-level callback
        callback = dev->pm_domain->ops.runtime_idle; 
        callback = dev->type->pm->runtime_idle;      
        callback = dev->class->pm->runtime_idle;     
        callback = dev->bus->pm->runtime_idle;       
        
        callback = dev->driver->pm->runtime_idle;
        
        __rpm_callback(callback, dev);
        
        wake_up_all(&dev->power.wait_queue);

bma150.c : i2c_bus_type -> pm_generic_runtime_idle -> pm_runtime_suspend -> __pm_runtime_suspend(dev, 0);
           -> rpm_suspend(dev, rpmflags);
豸ṩruntime_idle, ջruntime_suspend

ʹruntime PM:
1. ṩӿ, APP
2. echo on >  /sys/devices/.../power/control   // control_store -> pm_runtime_forbid(dev); :
                                                      atomic_inc(&dev->power.usage_count);
                                                      rpm_resume(dev, 0);
                                                      
   echo auto >  /sys/devices/.../power/control // control_store -> pm_runtime_allow(dev); :
                                                     atomic_dec_and_test(&dev->power.usage_count)
                                                     rpm_idle(dev, RPM_AUTO);

2. ޸ʹ
ô޸?
οںʾ: drivers\input\misc\bma150.c
2.1 dev_pm_opsṩ3ص: runtime_suspend, runtime_resume, runtime_idle
2.2 runtime PM,Ĭ״̬豸״̬suspended, Ӳ״̬,Ҫpm_runtime_set_active()޸״̬
    Ȼpm_runtime_enable()ʹruntime PM    
    һprobe
2.3 ڶӦϵͳýӿ: pm_runtime_get_sync / pm_runtime_put_sync : /Сֵ, 豸resumesuspend״̬
2.4 removepm_runtime_disable()

ǰ: ں֧runtime PM
make menuconfig
Power management options  --->
	[*] Run-time PM core functionality


ʹ:
1. 
echo on >  /sys/devices/platform/mylcd/power/control
echo auto >  /sys/devices/platform/mylcd/power/control

2. ڶӦϵͳýӿ: pm_runtime_get_sync / pm_runtime_put_sync 


3. autosuspend: 豸Ƶؿ,ʹautosuspend
: ִpm_runtime_use_autosuspendautosuspend,
        put豸ʱ, ִ2:
	pm_runtime_mark_last_busy(&lcd_dev.dev);
	pm_runtime_put_sync_autosuspend(&lcd_dev.dev);

ûռ, ִʱֵ:      
echo 2000 > /sys/devices/platform/mylcd/power/autosuspend_delay_ms


:
http://blog.csdn.net/bingqingsuimeng/article/category/1228414
http://os.chinaunix.net/a2006/0519/1002/000001002210.shtml
http://www.ednchina.com/ART_44010_29_0_TA_eeda337e_3.HTM?jumpto=view_welcomead_1408610592294

ģ
http://blog.csdn.net/bingqingsuimeng/article/details/7935414
http://blog.csdn.net/bingqingsuimeng/article/details/8197912
http://blog.sina.com.cn/s/blog_a6559d920101i52j.html

LinuxԴ(1)_ܹ
http://www.wowotech.net/linux_kenrel/pm_architecture.html

LinuxԴ(4)_Power Management Interface
http://www.wowotech.net/linux_kenrel/pm_interface.html

LinuxԴ(6)_Generic PM֮Suspend
http://www.wowotech.net/linux_kenrel/suspend_and_resume.html


LinuxʱIO豸Դ---PM  (runtime power manager)
http://blog.sina.com.cn/s/blog_533074eb0101dnm2.html


Run-time PM 
http://blog.csdn.net/bingqingsuimeng/article/details/7935440

Դ֮regulator 
http://blog.csdn.net/bingqingsuimeng/article/details/8216782


linuxں˶S3C2410˯ģʽ֧ (úܺ!)
http://blog.csdn.net/hongtao_liu/article/details/4208988

s3c2440 ʡģʽ(úܺ!)
http://blog.chinaunix.net/uid-517401-id-1641576.html

http://www.linuxforum.net/forum/showflat.php?Board=embedded&Number=725416

 s3c2440 ʡģʽ
http://blog.chinaunix.net/uid-517401-id-1641576.html





e:\kernel_projects\linux-3.4.2\linux-3.4.2\drivers\input\misc\Bma150.c



e:\kernel_projects\linux-3.4.2\linux-3.4.2\drivers\input\misc\Mpu3050.c


pm_runtime_set_active
pm_runtime_enable

pm_runtime_set_autosuspend_delay

pm_runtime_get
pm_runtime_put

pm_runtime_disable
pm_runtime_set_suspended

struct dev_pm_info:

pm_runtime_allow/pm_runtime_forbid runtime_auto

  unsigned int runtime_auto;
    - if set, indicates that the user space has allowed the device driver to
      power manage the device at run time via the /sys/devices/.../power/control
      interface; it may only be modified with the help of the pm_runtime_allow()
      and pm_runtime_forbid() helper functions

The user space can effectively disallow the driver of the device to power manage
it at run time by changing the value of its /sys/devices/.../power/control
attribute to "on", which causes pm_runtime_forbid() to be called.  In principle,
this mechanism may also be used by the driver to effectively turn off the
runtime power management of the device until the user space turns it on.
Namely, during the initialization the driver can make sure that the runtime PM
status of the device is 'active' and call pm_runtime_forbid().  It should be
noted, however, that if the user space has already intentionally changed the
value of /sys/devices/.../power/control to "auto" to allow the driver to power
manage the device at run time, the driver may confuse it by using
pm_runtime_forbid() this way.

      