static int pm_go_sleep(int arg) { unsigned long flags; sleep_jiffy = 0; #ifdef CONFIG_NO_USB_SUSPEND_RESUME return 0; #endif if ((can_sleep && (!ipc_is_active()) && (!periodic_wake)) || arg) { local_irq_save(flags); if (pm_send_all(PM_SUSPEND, (void *)3) == 0) { ezx_i2c_pm_suspend(); wmmx_ohci_suspend_call(); if (!irq_pending()) { if(usb_host_suspended) UP3OCR = 0x3; pm_do_suspend(CPUMODE_SLEEP); clear_dpcsr(); } APM_DPRINTK("resume\n"); ezx_i2c_pm_resume(); pm_send_all(PM_RESUME, (void *)0); check_wakeup(); } local_irq_restore(flags); } return 0; }
/* * Send us to sleep. */ static int sysctl_pm_do_suspend(void) { int retval; retval = pm_send_all(PM_SUSPEND, (void *)3); if (retval == 0) { retval = pm_do_suspend(); pm_send_all(PM_RESUME, (void *)0); } return retval; }
/* * Send us to sleep. */ static int sysctl_pm_do_suspend(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *fpos) { int mode; if (*lenp <= 0) return -EIO; mode = user_atoi(buffer, *lenp); switch (mode) { case 1: return pm_do_suspend(); case 5: return pm_do_bus_sleep(); default: return -EINVAL; } }
/* * Send us to sleep. */ static int sysctl_pm_do_suspend(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *fpos) { int retval, mode; if (*lenp <= 0) return -EIO; mode = user_atoi(buffer, *lenp); if ((mode != 1) && (mode != 5)) return -EINVAL; if (retval == 0) { if (mode == 5) retval = pm_do_bus_sleep(); else retval = pm_do_suspend(); } return retval; }
/* * Send us to sleep. */ static int sysctl_pm_do_suspend(ctl_table *ctl, int write, struct file *filp, void __user *buffer, size_t *lenp, loff_t *fpos) { int retval, mode; if (*lenp <= 0) return -EIO; mode = user_atoi(buffer, *lenp); if ((mode != 1) && (mode != 5)) return -EINVAL; retval = pm_send_all(PM_SUSPEND, (void *)3); if (retval == 0) { if (mode == 5) retval = pm_do_bus_sleep(); else retval = pm_do_suspend(); pm_send_all(PM_RESUME, (void *)0); } return retval; }
static int do_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) { struct apm_user * as; struct pm_dev * pm; struct ipm_config conf; as = filp->private_data; if (check_apm_user(as, "ioctl")) return -EIO; memset(&conf, 0, sizeof(conf)); switch (cmd) { case APM_IOC_SUSPEND: pm_do_suspend(CPUMODE_SLEEP); break; case APM_IOC_SET_WAKEUP: if ((pm = pm_find((pm_dev_t)arg,NULL)) == NULL) return -EINVAL; pm_send(pm,PM_SET_WAKEUP,NULL); break; case APM_IOC_SLEEP: pm_go_sleep(arg); break; case APM_IOC_SET_SPROF_WIN: sleep_to = arg * HZ; APM_DPRINTK("do_ioctl: sleep timeout %ld\n", arg); break; case APM_IOC_WAKEUP_ENABLE: PWER |= arg; APM_DPRINTK("do_ioctl: enable wakeup source:PWER=0x%x\n", PWER); break; case APM_IOC_WAKEUP_DISABLE: PWER &= ~arg; APM_DPRINTK("do_ioctl: disable wakeup source:PWER=0x%x\n", PWER); break; case APM_IOC_POWEROFF: APM_DPRINTK("do_ioctl: do power off\n"); /* here all device should response ok */ pm_send_all(PM_SUSPEND, (void *)3); pm_do_poweroff(); pm_send_all(PM_RESUME, (void *)0); break; case APM_IOC_RESET_BP: APM_DPRINTK("do_ioctl: reset bp\n"); GPCR(GPIO_BB_RESET) = GPIO_bit(GPIO_BB_RESET); mdelay(1); GPSR(GPIO_BB_RESET) = GPIO_bit(GPIO_BB_RESET); break; case APM_IOC_USEROFF_ENABLE: APM_DPRINTK("do_ioctl: useroff support enable\n"); user_off_available = (int)arg; break; case APM_IOC_NOTIFY_BP: break; case APM_IOC_REFLASH: cpu_proc_fin(); *(unsigned long *)(phys_to_virt(FLAG_ADDR)) = REFLASH_FLAG; // power_ic_periph_set_usb_pull_up(0); //LIN mdelay(1000); //LIN let GPIO control the connectivity #include <linux/power_ic.h> set_GPIO_mode(GPIO_USB_READY|GPIO_OUT); clr_GPIO(GPIO_USB_READY); power_ic_periph_set_usb_pull_up(0); mdelay(10); power_ic_set_reg_bit(POWER_IC_REG_EOC_CONN_CONTROL,19,1);//LIN set USB_CNTRL(bit19) to disable emu control mdelay(1000); //LIN power_ic_periph_set_usb_pull_up(1); /* Initialize the watchdog and let it fire */ OWER = OWER_WME; OSSR = OSSR_M3; OSMR3 = OSCR + CLOCK_TICK_RATE/100; /* ... in 10 ms */ MDREFR |= MDREFR_SLFRSH; while(1); break; case APM_IOC_PASSTHRU: cpu_proc_fin(); *(unsigned long *)(phys_to_virt(FLAG_ADDR)) = PASS_THRU_FLAG; power_ic_periph_set_usb_pull_up(0); mdelay(1000); power_ic_periph_set_usb_pull_up(1); /* Initialize the watchdog and let it fire */ OWER = OWER_WME; OSSR = OSSR_M3; OSMR3 = OSCR + CLOCK_TICK_RATE/100; /* ... in 10 ms */ MDREFR |= MDREFR_SLFRSH; while(1); break; case APM_IOC_SET_IPROF_WIN: /* set profile window size */ break; case APM_IOC_STARTPMU: if( pipm_start_pmu !=NULL ) pipm_start_pmu(); break; case APM_IOC_GET_IPM_CONFIG: get_ipm_config(&conf); return (copy_to_user((void *)arg, &conf,sizeof(conf)))? -EFAULT:0; break; case APM_IOC_SET_IPM_CONFIG: if(copy_from_user(&conf,(void *)arg,sizeof(conf))) return -EFAULT; return set_ipm_config(&conf); break; default: return -EINVAL; } return 0; }