コード例 #1
0
static void oled_detection_work(struct work_struct *work)
{
	struct lcd_info *lcd =
		container_of(work, struct lcd_info, oled_detection.work);

	struct file *fp;
	char name[128];
	struct timespec ts;
	struct rtc_time tm;

	int oled_det_level = gpio_get_value(GPIO_OLED_DET);

	dev_info(&lcd->ld->dev, "%s, GPIO_OLED_DET is %s\n", __func__, oled_det_level ? "high" : "low");

	if (!oled_det_level) {
		if (lcd->oled_detection_count < 3) {
			getnstimeofday(&ts);
			rtc_time_to_tm(ts.tv_sec, &tm);
			sprintf(name, "%s%02d-%02d_%02d:%02d:%02d_%02d",
				"/sdcard/", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, lcd->oled_detection_count);
			fp = filp_open(name, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);

			if (IS_ERR_OR_NULL(fp))
				dev_info(&lcd->ld->dev, "fail to create vgh detection log file, %s\n", name);

			schedule_delayed_work(&lcd->oled_detection, msecs_to_jiffies(10));
			lcd->oled_detection_count++;
		} else {
			dev_info(&lcd->ld->dev, "VGH IS NOT OK! LCD SMASH!!!\n");
			getnstimeofday(&ts);
			rtc_time_to_tm(ts.tv_sec, &tm);
			sprintf(name, "%s%02d-%02d_%02d:%02d:%02d_POWEROFF",
				"/sdcard/", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
			fp = filp_open(name, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);

			if (IS_ERR_OR_NULL(fp))
				dev_info(&lcd->ld->dev, "fail to create vgh detection log file, %s\n", name);

			sys_sync();
			kernel_power_off();
		}
	} else
		dev_info(&lcd->ld->dev, "VGH IS OK\n");

}
コード例 #2
0
/*
 * handle_twl6030_vlow() is a threaded BAT_VLOW interrupt handler. BAT_VLOW
 * is a secondary interrupt generated in twl6030_irq_thread().
 */
static irqreturn_t handle_twl6030_vlow(int irq, void *unused)
{
#ifdef CONFIG_TWL60xx_VBAT_LOW_DETECTION
	rk28_send_wakeup_key();
#else
	pr_err("twl6030: BAT_VLOW interrupt; threshold=%dmV\n",
	       2300 + (vbatmin_hi_threshold - 0b110) * 50);
#if 1 /* temporary */
	pr_err("%s: disabling BAT_VLOW interrupt\n", __func__);
	disable_irq_nosync(twl6030_irq_base + TWL_VLOW_INTR_OFFSET);
//	WARN_ON(1);
#else
	pr_emerg("handle_twl6030_vlow: kernel_power_off()\n");
	kernel_power_off();
#endif
#endif
	return IRQ_HANDLED;
}
コード例 #3
0
/**
 * power_down - Shut the machine down for hibernation.
 *
 * Use the platform driver, if configured, to put the system into the sleep
 * state corresponding to hibernation, or try to power it off or reboot,
 * depending on the value of hibernation_mode.
 */
static void power_down(void)
{
#ifdef CONFIG_SUSPEND
	int error;
#endif

	switch (hibernation_mode) {
	case HIBERNATION_REBOOT:
		kernel_restart(NULL);
		break;
	case HIBERNATION_PLATFORM:
		hibernation_platform_enter();
	case HIBERNATION_SHUTDOWN:
		kernel_power_off();
		break;
#ifdef CONFIG_SUSPEND
	case HIBERNATION_SUSPEND:
		error = suspend_devices_and_enter(PM_SUSPEND_MEM);
		if (error) {
			if (hibernation_ops)
				hibernation_mode = HIBERNATION_PLATFORM;
			else
				hibernation_mode = HIBERNATION_SHUTDOWN;
			power_down();
		}
		/*
		 * Restore swap signature.
		 */
		error = swsusp_unmark();
		if (error)
			printk(KERN_ERR "PM: Swap will be unusable! "
			                "Try swapon -a.\n");
		return;
#endif
	}
	kernel_halt();
	/*
	 * Valid image is on the disk, if we continue we risk serious data
	 * corruption after resume.
	 */
	printk(KERN_CRIT "PM: Please power down manually\n");
	while(1);
}
コード例 #4
0
static void cover_work_func(struct work_struct *work)
{
	int cover_status;

    msleep(DELAY_TIME_MSEC);        
    
	cover_status = gpio_get_value(cover_det_int_gpio);

	if(cover_status == 0)
	{
	}
	else
	{
	    #if defined(CONFIG_HW_AUSTIN) 
        final_sync_files();
        #endif
	    kernel_power_off();    			/* Jagan+ ... Jagan- */
	}
}
コード例 #5
0
ファイル: hibernate.c プロジェクト: AlexShiLucky/linux
/**
 * power_down - Shut the machine down for hibernation.
 *
 * Use the platform driver, if configured, to put the system into the sleep
 * state corresponding to hibernation, or try to power it off or reboot,
 * depending on the value of hibernation_mode.
 */
static void power_down(void)
{
#ifdef CONFIG_SUSPEND
	int error;

	if (hibernation_mode == HIBERNATION_SUSPEND) {
		error = suspend_devices_and_enter(PM_SUSPEND_MEM);
		if (error) {
			hibernation_mode = hibernation_ops ?
						HIBERNATION_PLATFORM :
						HIBERNATION_SHUTDOWN;
		} else {
			/* Restore swap signature. */
			error = swsusp_unmark();
			if (error)
				pr_err("Swap will be unusable! Try swapon -a.\n");

			return;
		}
	}
#endif

	switch (hibernation_mode) {
	case HIBERNATION_REBOOT:
		kernel_restart(NULL);
		break;
	case HIBERNATION_PLATFORM:
		hibernation_platform_enter();
		/* Fall through */
	case HIBERNATION_SHUTDOWN:
		if (pm_power_off)
			kernel_power_off();
		break;
	}
	kernel_halt();
	/*
	 * Valid image is on the disk, if we continue we risk serious data
	 * corruption after resume.
	 */
	pr_crit("Power down manually\n");
	while (1)
		cpu_relax();
}
コード例 #6
0
ファイル: sys.c プロジェクト: maraz/linux-2.6
/**
 * orderly_poweroff - Trigger an orderly system poweroff
 * @force: force poweroff if command execution fails
 *
 * This may be called from any context to trigger a system shutdown.
 * If the orderly shutdown fails, it will force an immediate shutdown.
 */
int orderly_poweroff(bool force)
{
	int argc;
	char **argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc);
	static char *envp[] = {
		"HOME=/",
		"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
		NULL
	};
	int ret = -ENOMEM;
	struct subprocess_info *info;

	if (argv == NULL) {
		printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n",
		       __func__, poweroff_cmd);
		goto out;
	}

	info = call_usermodehelper_setup(argv[0], argv, envp);
	if (info == NULL) {
		argv_free(argv);
		goto out;
	}

	call_usermodehelper_setcleanup(info, argv_cleanup);

	ret = call_usermodehelper_exec(info, UMH_NO_WAIT);

  out:
	if (ret && force) {
		printk(KERN_WARNING "Failed to start orderly shutdown: "
		       "forcing the issue\n");

		/* I guess this should try to kick off some daemon to
		   sync and poweroff asap.  Or not even bother syncing
		   if we're doing an emergency shutdown? */
		emergency_sync();
		kernel_power_off();
	}

	return ret;
}
コード例 #7
0
// NOTICE: this function MUST be called under autosleep_lock (in autosleep.c) is locked!!
int mtk_hibernate_via_autosleep(suspend_state_t *autosleep_state)
{
    int err = 0;
    hib_log("entering hibernation state(%d)\n", *autosleep_state);
    err = hibernate();
    if (err) {
        hib_warn("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) {
            kernel_power_off();
            kernel_halt();
            BUG();
        } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) {
            hib_warn("hibernation failed: so changing state(%d->%d) err(%d)\n", *autosleep_state, PM_SUSPEND_MEM, err);
            if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT)
                hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN;
            // userspace recover if hibernation failed
            usr_recover_func(NULL);
            *autosleep_state = PM_SUSPEND_MEM;
            system_is_hibernating = false;
         } else {
            hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n");
            BUG();
        }
    } else {
        if (hybrid_sleep_mode()) {
            hib_warn("hybrid sleep mode so changing state(%d->%d)\n", *autosleep_state, PM_SUSPEND_MEM);
            *autosleep_state = PM_SUSPEND_MEM; //continue suspend to ram if hybrid sleep mode
        } else {
            hib_warn("hibernation succeeded: so changing state(%d->%d) err(%d) \n", *autosleep_state, PM_SUSPEND_ON, err);
            hib_warn("start trigger ipod\n");
            //usr_bootanim_start(NULL);
            //schedule_delayed_work(&usr_restore_work, HZ*0.05);
            usr_restore_func(NULL);
            *autosleep_state = PM_SUSPEND_ON; // if this is not set, it will recursively do hibernating!!
        }
        hib_failed_cnt = 0;
        pm_wake_lock("IPOD_HIB_WAKELOCK");
        system_is_hibernating = false;
    }

    return err;
}
コード例 #8
0
ファイル: hibernate.c プロジェクト: OneOfMany07/fjord-kernel
/**
 * power_down - Shut the machine down for hibernation.
 *
 * Use the platform driver, if configured, to put the system into the sleep
 * state corresponding to hibernation, or try to power it off or reboot,
 * depending on the value of hibernation_mode.
 */
static void power_down(void)
{
	switch (hibernation_mode) {
	case HIBERNATION_REBOOT:
		kernel_restart(NULL);
		break;
	case HIBERNATION_PLATFORM:
		hibernation_platform_enter();
	case HIBERNATION_SHUTDOWN:
		kernel_power_off();
		break;
	}
	kernel_halt();
	/*
	 * Valid image is on the disk, if we continue we risk serious data
	 * corruption after resume.
	 */
	printk(KERN_CRIT "PM: Please power down manually\n");
	while(1);
}
コード例 #9
0
ファイル: reboot.c プロジェクト: ReneNyffenegger/linux
static int __orderly_poweroff(bool force)
{
	int ret;

	ret = run_cmd(poweroff_cmd);

	if (ret && force) {
		pr_warn("Failed to start orderly shutdown: forcing the issue\n");

		/*
		 * I guess this should try to kick off some daemon to sync and
		 * poweroff asap.  Or not even bother syncing if we're doing an
		 * emergency shutdown?
		 */
		emergency_sync();
		kernel_power_off();
	}

	return ret;
}
コード例 #10
0
ファイル: rpc_server_handset.c プロジェクト: ghk/StreakKernel
static void pwrkey_work_func(struct work_struct *work)
{
  unsigned int arg1, arg2;
  int ret;

  printk("[KEY]## %s+\n",__func__);
  arg1 = SMEM_PC_OEM_GET_PWK_RELEASE_STATUS;
  arg2 = 0;
  ret = cust_mproc_comm1(&arg1,&arg2);  
  if(ret)
  {
    printk("[KEY]## %s Key = Unknown\n",__func__);    
  }
  else
  {
    printk("[KEY]## %s Key = %s\n",__func__, arg2==1?"Released":"Pressed");  
    if(arg2 == 0)   
      kernel_power_off("Power Key");
  }
  printk("[KEY]## %s-\n",__func__);
}
コード例 #11
0
static void charger_check_temp_limits(struct charger_info *di)
{
	/* check against temperature limits */
	if (di->gg_temperature_cC < CHARGER_LOW_TEMP_LIMIT || di->gg_temperature_cC > CHARGER_HIGH_TEMP_LIMIT) {
		if (di->temperature_lockout == 0)
			dev_warn(di->dev, "temperature is outside charging limits\n");
		di->temperature_lockout = 1;
	} else {
		di->temperature_lockout = 0;
	}

	/* check against critical temperature limits */
	if (di->gg_temperature_cC < CHARGER_LOW_TEMP_CRITICAL || di->gg_temperature_cC > CHARGER_HIGH_TEMP_CRITICAL) {
		di->temperature_critical_count++;

		if (di->temperature_critical_count >= 2) {
			dev_err(di->dev, "temperature is critical, powering down!!\n");
			kernel_power_off();
		}
	}
}
コード例 #12
0
ファイル: ras.c プロジェクト: 383530895/linux
/*
 * Handle hardware error interrupts.
 *
 * RTAS check-exception is called to collect data on the exception.  If
 * the error is deemed recoverable, we log a warning and return.
 * For nonrecoverable errors, an error is logged and we stop all processing
 * as quickly as possible in order to prevent propagation of the failure.
 */
static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
{
	struct rtas_error_log *rtas_elog;
	int status;
	int fatal;

	spin_lock(&ras_log_buf_lock);

	status = rtas_call(ras_check_exception_token, 6, 1, NULL,
			   RTAS_VECTOR_EXTERNAL_INTERRUPT,
			   virq_to_hw(irq),
			   RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
			   __pa(&ras_log_buf),
				rtas_get_error_log_max());

	rtas_elog = (struct rtas_error_log *)ras_log_buf;

	if (status == 0 &&
	    rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC)
		fatal = 1;
	else
		fatal = 0;

	/* format and print the extended information */
	log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);

	if (fatal) {
		pr_emerg("Fatal hardware error reported by firmware");
		pr_emerg("Check RTAS error log for details");
		pr_emerg("Immediate power off");
		emergency_sync();
		kernel_power_off();
	} else {
		pr_err("Recoverable hardware error reported by firmware");
	}

	spin_unlock(&ras_log_buf_lock);
	return IRQ_HANDLED;
}
コード例 #13
0
static void power_down(suspend_disk_method_t mode)
{
	int error = 0;

	switch(mode) {
	case PM_DISK_PLATFORM:
		kernel_power_off_prepare();
		error = pm_ops->enter(PM_SUSPEND_DISK);
		break;
	case PM_DISK_SHUTDOWN:
		kernel_power_off();
		break;
	case PM_DISK_REBOOT:
		kernel_restart(NULL);
		break;
	}
	kernel_halt();
	/* Valid image is on the disk, if we continue we risk serious data corruption
	   after resume. */
	printk(KERN_CRIT "Please power me down manually\n");
	while(1);
}
コード例 #14
0
static int  __init start_charge_logo_display(void)
{
	union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
	union power_supply_propval val_capacity ={ 100} ;

	printk("start_charge_logo_display\n");

	if(rockchip_boot_mode() == BOOT_MODE_RECOVERY)  //recovery mode
	{
		printk("recovery mode \n");
		return 0;
	}
	if (rk_get_system_battery_status() != POWER_SUPPLY_TYPE_BATTERY)
		val_status.intval = POWER_SUPPLY_STATUS_CHARGING;

	val_capacity.intval = rk_get_system_battery_capacity();
	// low power   and  discharging
#if 0
	if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
	{
		printk("low power\n");
		kernel_power_off();
		while(1);
		return 0;
	}
#endif

	if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
	{
		if (((rockchip_boot_mode() == BOOT_MODE_NORMAL) ||(rockchip_boot_mode() == BOOT_MODE_CHARGE)) && (val_capacity.intval <= pwr_on_thrsd))  
	    {			
			add_bootmode_charger_to_cmdline();
			printk("power in charge mode %d %d  %d\n\n",rockchip_boot_mode(),val_capacity.intval,pwr_on_thrsd);
	   }
	}

	return 0;
} 
コード例 #15
0
// called by echo "disk" > /sys/power/state
int mtk_hibernate(void)
{
    int err = 0;

    hib_log("entering hibernation\n");
    err = hibernate();
    if (err) {
        hib_warn("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) {
            kernel_power_off();
            kernel_halt();
            BUG();
        } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) {
            hib_warn("hibernation failed, suspend to ram instead!\n");
            if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT)
                hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN;
            // userspace recover if hibernation failed
            usr_recover_func(NULL);
            system_is_hibernating = false;
        } else {
            hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n");
            BUG();
        }
    } else {
        if (!hybrid_sleep_mode()) {
            hib_warn("start trigger ipod\n");
            //schedule_delayed_work(&usr_bootanim_start_work, HZ*1.0);
            //schedule_delayed_work(&usr_restore_work, HZ*0.05);
            //usr_bootanim_start(NULL);
            usr_restore_func(NULL);
        }
        hib_failed_cnt = 0;
        pm_wake_lock("IPOD_HIB_WAKELOCK");
        system_is_hibernating = false;
    }

    return err;
}
コード例 #16
0
static void fac_cbl_irq_w(struct work_struct *w)
{
	struct mmi_factory_info *info = container_of(w,
						     struct mmi_factory_info,
						     fac_cbl_irq_work.work);
	int fac_cbl_line = gpio_get_value(info->list[KP_CABLE_INDEX].gpio);
	int fac_cbl_kill_line = gpio_get_value(info->list[KP_KILL_INDEX].gpio);

	if (fac_cbl_line) {
		pr_info("Factory Cable Attached!\n");
		info->factory_cable = 1;
	} else
		if (info->factory_cable) {
			pr_info("Factory Cable Detached!\n");
			if (fac_cbl_kill_line) {
				info->factory_cable = 0;
				pr_info("Factory Kill Disabled!\n");
			} else {
				pr_info("2 sec to power off.\n");
				kernel_power_off();
				return;
			}
		}
}
コード例 #17
0
ファイル: pmic_battery.c プロジェクト: pocketbook/801
int get_battery_mA(void) /* get charging current float into battery */
{
	unsigned short value=0;
	int bat_curr=0;
	int bat_cur=0;
	int chargerState=0;
	bool bPoweroffProcessSign = false;

	pmic_get_batt_current(&value);
	bat_curr = ((value&0x200) ? (value|0xfffffc00) : value);
	bat_curr = (bat_curr*3000)/512;



	 ////wen add ,only for test,
	 if((-bat_curr) >= 0){
		 bat_cur = (-bat_curr);
	 }else{
	 	chargerState =get_charger_state();
		 if(chargerState == 1){
			 bat_cur = 0;
		 }else{
			 ///power off,only executed once
			 ////whether check the battaty voltage ?
			 if((!bPoweroffProcessSign) && (get_battery_mV()< 3400)){
				 pr_notice("Charger current < 0 and Battery voltage < 3.4v, Power off \n");
				// orderly_poweroff(1);
				 kernel_power_off();
				 bPoweroffProcessSign = true;
			 }
		 }
	 }


	return bat_cur;
}
static void mif_sim_fake_shutdown_work(struct work_struct *work)
{
	mif_info("fake shutdown sim changed, device will be reboot\n");
	/*kernel_restart(NULL);*/
	kernel_power_off();
}
コード例 #19
0
static long tcmd_misc_ioctl( struct file *file,
                             unsigned int cmd, unsigned long arg)
{
#ifdef CONFIG_TCMD
    void __user *argp = (void __user *)arg;
    int gpio_enum = -1, irq = -1, gpio_state = -1, rc = 0;

    pr_info("tcmd_misc_ioctl is called");

    switch(cmd)
    {
    case TCMD_IOCTL_SET_REG:
    case TCMD_IOCTL_GET_REG:
    {
        tcmd_reg_arg reg_arg;
        struct regulator *reg_p;
        printk("TCMD_IOCTL_SET_REG or GET");
        if (copy_from_user(&reg_arg, argp, sizeof(tcmd_reg_arg)))
            return -EFAULT;

        reg_p = regulator_get(NULL,reg_arg.name );

        if (IS_ERR(reg_p))
        {
            printk("%s: VREG reg_p get failed\n", __func__);
            reg_p  = NULL;
            return -EFAULT;
        }


        if(cmd == TCMD_IOCTL_GET_REG ) {
            printk("cmd == TCMD_IOCTL_GET_REG ");
            if(TCMD_REG_GET_VOLTAGE  == reg_arg.cmd)
            {   printk("cmd == TCMD_REG_GET_VOLTAGE  ");
                reg_arg.param = regulator_get_voltage(reg_p);
            } else if(TCMD_REG_GET_POWER_MODE  == reg_arg.cmd)
            {
                reg_arg.param = regulator_get_mode(reg_p);
            }
            if(copy_to_user((tcmd_reg_arg  *)argp, &reg_arg, sizeof(tcmd_reg_arg )))
                return -EFAULT;

        }
        else {
            switch(reg_arg.cmd)
            {
            case TCMD_REG_ENABLE :
                printk("TCMD_REGULATOR_ENABLE\n");
                rc = regulator_enable(reg_p);
                if (rc) {
                    pr_info( " regulator_enable failed:%d\n", rc);
                    return rc;
                }
                break;
            case     TCMD_REG_DISABLE:
                printk("TCMD_REGULATOR_DISABLE\n");
                rc = regulator_disable(reg_p);
                if (rc) {
                    pr_info( " regulator_disable failed:%d\n", rc);
                    return rc;
                }
                break;
            case    TCMD_REG_SET_VOLTAGE :
                pr_info("TCMD_REG_SET_VOLTAGE, reg_arg.param= %d\n",reg_arg.param);
                rc = regulator_set_voltage(reg_p, reg_arg.param, reg_arg.param);
                if (rc) {
                    pr_info( " regulator_set_voltage failed:%d\n", rc);
                    return rc;
                }
                break;
            case    TCMD_REG_SET_POWER_MODE :
                pr_info("TCMD_REG_SET_POWER_MODE, reg_arg.param= %d\n",reg_arg.param);
                rc = regulator_set_mode(reg_p, reg_arg.param);
                if (rc) {
                    pr_info( " regulator_set_mode failed:%d\n", rc);
                    return rc;
                }
                break;
            default:
                return -EINVAL;
                break;
            }

        }
        break;
    }
    case TCMD_IOCTL_CHARGER:
    {

        unsigned char charger_enable;
        pr_info("cmd == TCMD_IOCTL_CHARGER");

        if (copy_from_user(&charger_enable, argp, sizeof(unsigned char )))
            return -EFAULT;

        switch(charger_enable)
        {
        case 0:
            rc = qpnp_disable_source_current(true);
            if (rc)
            {
                printk("TCMD :tcmd_driver : qpnp_disable_source_current failed:%d\n", rc);
                return rc;
            }
            break;
        case 1:
            rc = qpnp_set_max_battery_charge_current(true);
            if (rc)
            {
                pr_info("TCMD : tcmd_driver : qpnp_set_max_battery_charge_current(true) failed:%d\n", rc);
                return rc;
            }
            rc = qpnp_disable_source_current(false);
            if (rc)
            {
                pr_info("TCMD : tcmd_driver : qpnp_disable_source_current(false) failed:%d\n", rc);
                return rc;
            }
            printk("TCMD : Enable charging with high current successful");
            break;
        case 2:
            rc = qpnp_set_max_battery_charge_current(false);
            if (rc)
            {
                printk("TCMD : tcmd_driver : qpnp_set_max_battery_charge_current(false) failed:%d\n", rc);
                return rc;
            }
            rc = qpnp_disable_source_current(false);
            if (rc)
            {
                pr_info("TCMD : tcmd_driver : qpnp_disable_source_current(false) failed:%d\n", rc);
                return rc;
            }
            printk("TCMD : Enable charging with low current successful");
            break;
            break;
        default:
            return -EINVAL;
            break;
        }
        break;
    }
    case TCMD_IOCTL_USB_CHRGING:
    {
        unsigned char usb_charger_enable;
        pr_info("TCMD: cmd = TCMD_IOCTL_USB_CHRGING");
        if(copy_from_user(&usb_charger_enable, argp, sizeof(unsigned char)))
            return -EFAULT;

        switch(usb_charger_enable)
        {
        case 0:
            printk("TCMD: tcmd_driver : Disable USB charging\n");
            rc = qpnp_disable_usb_charging(!usb_charger_enable);
            if(rc) {
                printk("TCMD: qpnp-charger disable usb charging failed:%d\n", rc);
                return rc;
            }
            break;
        case 1:
            printk("TCMD: tcmd_driver : Enable USB charging\n");
            rc = qpnp_disable_usb_charging(!usb_charger_enable);
            if(rc) {
                printk("TCMD: qpnp-charger enable usb charging failed:%d\n", rc);
                return rc;
            }
        }
        break;
    }
    case TCMD_IOCTL_CHGPTH_PRIORITY:
    {
        unsigned char charging_path_priority;
        pr_info("TCMD: cmd = TCMD_IOCTL_CHGPTH_PRIORITY\n");
        if(copy_from_user(&charging_path_priority, argp, sizeof(unsigned char)))
            return -EFAULT;

        switch(charging_path_priority)
        {
        case 0:
            printk("TCMD: tcmd_driver : USB_IN priority \n");
            rc = qpnp_chg_priority(charging_path_priority);
            if(rc) {
                printk("TCMD: qpnp_chg_priority USB_IN failed:%d\n", rc);
                return rc;
            }
            break;
        case 1:
            printk("TCMD: tcmd_driver : DC_IN priority \n");
            rc = qpnp_chg_priority(charging_path_priority);
            if(rc) {
                printk("TCMD: qpnp_chg_priority DC_IN failed:%d\n", rc);
                return rc;
            }
        }
        break;
    }
    /*case TCMD_IOCTL_SET_FLASH_LM3559:
    {
    	int flash_lm3559_state;
    	pr_info("TCMD_IOCTL_SET_FLASH_LM3559\n");

    	if(copy_from_user(&flash_lm3559_state, argp, sizeof(int)))
    		return -EFAULT;

    	rc = lm3559_flash_set_led_state(flash_lm3559_state);

    	if(rc){
    		pr_info("Error on calling set_flash_lm3559\n");
    		return rc;
    	}
    	break;
    }*/
    case TCMD_IOCTL_POWER_DOWN:
    {
        pr_info("TCMD_IOCTL_POWER_DOWN\n");
        kernel_power_off();
        break;
    }
    case TCMD_IOCTL_GET_ADC:
    {
        TCMD_QPNP_VADC_CHAN_PARAM  adc_arg;
        //struct qpnp_vadc_chip *vadc;
        int ibat_ua;

        printk("TCMD_IOCTL_GET_ADC");
        if (copy_from_user(&adc_arg, argp, sizeof(TCMD_QPNP_VADC_CHAN_PARAM)))
            return -EFAULT;
        printk("adc_arg.cmd: %d",adc_arg.cmd);
        if(!vchip)
        {
            printk("vchip is NULL\n");
        }
        if (adc_arg.cmd == TCMD_PMIC_ADC_BATTERY_CURRENT) {
            printk("adc_arg.cmd == TCMD_PMIC_ADC_BATTERY_CURRENT");
            rc = tcmd_get_battery_current(&ibat_ua);
            adc_arg.adc_config.physical = ibat_ua;
            adc_arg.adc_config.measurement = adc_arg.adc_config.physical;
        } else {
            rc = qpnp_vadc_read(vchip, adc_arg.cmd, &adc_arg.adc_config);
        }

        if (rc) {
            pr_info("Error on calling qpnp_vadc_read");
            return rc;
        }

        if(copy_to_user((TCMD_QPNP_VADC_CHAN_PARAM *)argp, &adc_arg, sizeof(TCMD_QPNP_VADC_CHAN_PARAM)))
            return -EFAULT;

        break;
    }
    case TCMD_IOCTL_SET_GPIO:
    {
        TCMD_PM8XXX_GPIO_PARAM gpio_arg;

        printk("TCMD_IOCTL_SET_GPIO");
        if (copy_from_user(&gpio_arg, argp, sizeof(TCMD_PM8XXX_GPIO_PARAM)))
            return -EFAULT;
        printk("gpio_arg.cmd: %d",  gpio_arg.cmd);

        rc = pm8xxx_gpio_config(gpio_arg.cmd, &gpio_arg.gpio_config);

        if (rc) {
            pr_info("Error on calling pm8xxx_gpio_config");
            return rc;
        }

        break;
    }
    case TCMD_IOCTL_GET_USB_BAT_CURRENT:
    {
        int rc = -1;
        TCMD_REG_USB_BAT_CURRENT adc_arg;
        printk("TCMD_IOCTL_GET_USB_BAT_CURRENT");
        if (copy_from_user(&adc_arg, argp, sizeof(TCMD_REG_USB_BAT_CURRENT)))
        {
            return -EFAULT;
        }

        qpnp_get_usb_max_current(&adc_arg.usbPresentCurrent);
        rc = qpnp_get_bat_max_current(&adc_arg.batPresentCurrent);

        if(rc < 0)
        {
            return rc;
        }

        if(copy_to_user((TCMD_REG_USB_BAT_CURRENT *)argp, &adc_arg, sizeof(TCMD_REG_USB_BAT_CURRENT)))
            return -EFAULT;

        return rc;
    }
    case TCMD_IOCTL_SET_USB_BAT_CURRENT:
    {
        int rc = -1;
        TCMD_REG_USB_BAT_CURRENT adc_arg;
        printk("TCMD_IOCTL_GET_USB_BAT_CURRENT");
        if (copy_from_user(&adc_arg, argp, sizeof(TCMD_REG_USB_BAT_CURRENT)))
        {
            return -EFAULT;
        }

        rc = qpnp_set_usb_max_current(adc_arg.usbPresentCurrent);
        if(rc < 0)
        {
            return rc;
        }

        rc = qpnp_set_bat_max_current(adc_arg.batPresentCurrent);
        return rc;
    }
    case TCMD_IOCTL_COINCELL_ENABLE_DISABLE:
    {
        int coincell_state;
        pr_info("TCMD_IOCTL_COINCELL_ENABLE_DISABLE\n");
        if(copy_from_user(&coincell_state, argp, sizeof(int)))
            return -EFAULT;
        printk("TCMD:Set charger state entering with value : %d",coincell_state);
        rc = tcmd_qpnp_coincell_set_charger(coincell_state);
        if(rc) {
            pr_info("Error on calling  tcmd_qpnp_coincell_set_charger\n");
            printk("TCMD:Error on calling tcms_qpnp_coincell_set_charger : %d",rc);
            return rc;
        }
        printk("TCMD:Set charger state out with value : %d",rc);
        break;
    }
    case TCMD_IOCTL_SET_COINCELL:
    {
        TCMD_QPNP_CC_CHG_PARAM coincell_arg;
        printk("TCMD_IOCTL_SET_COINCELL");
        if (copy_from_user(&coincell_arg, argp, sizeof(TCMD_QPNP_CC_CHG_PARAM)))
            return -EFAULT;

        //rc = pm8xxx_coincell_chg_config(&coincell_arg);
        printk("\nState - > %d \n Voltage - > %d \n Resistance -> %d \n",coincell_arg.state,coincell_arg.voltage,coincell_arg.resistance);
        if((rc = tcmd_qpnp_coincell_set_charger(coincell_arg.state))) {
            printk("Error in configuring the state : tcmd_qpnp_coincell_set_charger : rc= %d",rc);
            return rc;
        }
        if((rc =  tcmd_qpnp_coincell_set_voltage(coincell_arg.voltage))) {
            printk("Error in configuring Voltage :tcmd_qpnp_coincell_set_voltage: rc= %d",rc);
            return rc;
        }
        if((rc = tcmd_qpnp_coincell_set_resistance(coincell_arg.resistance)))	{
            printk("Error in configuring Resistance :tcmd_qpnp_coincell_set_resistance : rc= %d",rc);
            return rc;
        }

        if (rc) {
            pr_info("Error on calling pm8xxx_coincell_chg_config ");
            printk("value of rc = %d",rc);
            return rc;
        }
        break;
    }
    /*	case TCMD_IOCTL_SET_VIBRATOR:
    	{
    		TCMD_PM8XXX_VIB_PARAM vib_arg;

    		printk("TCMD_IOCTL_SET_VIBRATOR");
    		if (copy_from_user(&vib_arg, argp, sizeof(TCMD_PM8XXX_VIB_PARAM)))
    			return -EFAULT;

    		rc = pm8xxx_vibrator_config(&vib_arg);

    		if (rc) {
    		pr_info("Error on calling pm8xxx_vibrator_config");
    		return rc;
    		}

    		break;

    	}*/

    default:
    {
        struct tcmd_gpio_set_arg gpio_set_arg;

        if (cmd == TCMD_IOCTL_SET_INT) {
            if (copy_from_user(&gpio_set_arg, argp, 2))
                return -EFAULT;
            gpio_enum = gpio_set_arg.gpio;
            gpio_state = gpio_set_arg.gpio_state;
        }
        else if (copy_from_user(&gpio_enum, argp, sizeof(int)))
            return -EFAULT;

        if (gpio_enum < 0)
            return -EINVAL;

        switch (cmd) {
        case TCMD_IOCTL_MASK_INT:
        case TCMD_IOCTL_UNMASK_INT:
            irq = gpio_to_irq(gpio_enum);
            if (irq < 0)
                return -EINVAL;
            break;
        default:
            break;
        }

        switch (cmd) {
        case TCMD_IOCTL_MASK_INT:
            pr_info("tcmd mask interrupt: gpio = %d, irq = %d.\n",
                    gpio_enum, irq);
            disable_irq(irq);
            break;
        case TCMD_IOCTL_UNMASK_INT:
            pr_info("tcmd unmask interrupt: gpio = %d, irq = %d.\n",
                    gpio_enum, irq);
            enable_irq(irq);
            break;
        case TCMD_IOCTL_READ_INT:
            gpio_state = gpio_get_value(gpio_enum);
            pr_info("tcmd interrupt state: gpio = %d -> %d.\n",
                    gpio_enum, gpio_state);
            if (copy_to_user(argp, &gpio_state, sizeof(int)))
                return -EFAULT;
            break;
        case TCMD_IOCTL_SET_INT:
            pr_info("tcmd set interrupt state: gpio = %d -> %d.\n",
                    gpio_enum, gpio_state);
            gpio_set_value(gpio_enum, gpio_state);
            break;
        default:
            return -EINVAL;
        }
        break;
    }//default
    }
#endif
    return 0;
}
コード例 #20
0
ファイル: sys.c プロジェクト: BackupTheBerlios/tew632-brp-svn
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
{
    char buffer[256];

    /* We only trust the superuser with rebooting the system. */
    if (!capable(CAP_SYS_BOOT))
        return -EPERM;

    /* For safety, we require "magic" arguments. */
    if (magic1 != LINUX_REBOOT_MAGIC1 ||
            (magic2 != LINUX_REBOOT_MAGIC2 &&
             magic2 != LINUX_REBOOT_MAGIC2A &&
             magic2 != LINUX_REBOOT_MAGIC2B &&
             magic2 != LINUX_REBOOT_MAGIC2C))
        return -EINVAL;

    lock_kernel();
    switch (cmd) {
    case LINUX_REBOOT_CMD_RESTART:
        kernel_restart(NULL);
        break;

    case LINUX_REBOOT_CMD_CAD_ON:
        C_A_D = 1;
        break;

    case LINUX_REBOOT_CMD_CAD_OFF:
        C_A_D = 0;
        break;

    case LINUX_REBOOT_CMD_HALT:
        kernel_halt();
        unlock_kernel();
        do_exit(0);
        break;

    case LINUX_REBOOT_CMD_POWER_OFF:
        kernel_power_off();
        unlock_kernel();
        do_exit(0);
        break;

    case LINUX_REBOOT_CMD_RESTART2:
        if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
            unlock_kernel();
            return -EFAULT;
        }
        buffer[sizeof(buffer) - 1] = '\0';

        kernel_restart(buffer);
        break;

    case LINUX_REBOOT_CMD_KEXEC:
        kernel_kexec();
        unlock_kernel();
        return -EINVAL;

#ifdef CONFIG_SOFTWARE_SUSPEND
    case LINUX_REBOOT_CMD_SW_SUSPEND:
    {
        int ret = software_suspend();
        unlock_kernel();
        return ret;
    }
#endif

    default:
        unlock_kernel();
        return -EINVAL;
    }
    unlock_kernel();
    return 0;
}
コード例 #21
0
ファイル: sys.c プロジェクト: maraz/linux-2.6
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
{
	char buffer[256];

	/* We only trust the superuser with rebooting the system. */
	if (!capable(CAP_SYS_BOOT))
		return -EPERM;

	/* For safety, we require "magic" arguments. */
	if (magic1 != LINUX_REBOOT_MAGIC1 ||
	    (magic2 != LINUX_REBOOT_MAGIC2 &&
	                magic2 != LINUX_REBOOT_MAGIC2A &&
			magic2 != LINUX_REBOOT_MAGIC2B &&
	                magic2 != LINUX_REBOOT_MAGIC2C))
		return -EINVAL;

	/* Instead of trying to make the power_off code look like
	 * halt when pm_power_off is not set do it the easy way.
	 */
	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
		cmd = LINUX_REBOOT_CMD_HALT;

	lock_kernel();
	switch (cmd) {
	case LINUX_REBOOT_CMD_RESTART:
		kernel_restart(NULL);
		break;

	case LINUX_REBOOT_CMD_CAD_ON:
		C_A_D = 1;
		break;

	case LINUX_REBOOT_CMD_CAD_OFF:
		C_A_D = 0;
		break;

	case LINUX_REBOOT_CMD_HALT:
		kernel_halt();
		unlock_kernel();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_POWER_OFF:
		kernel_power_off();
		unlock_kernel();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_RESTART2:
		if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
			unlock_kernel();
			return -EFAULT;
		}
		buffer[sizeof(buffer) - 1] = '\0';

		kernel_restart(buffer);
		break;

	case LINUX_REBOOT_CMD_KEXEC:
		kernel_kexec();
		unlock_kernel();
		return -EINVAL;

#ifdef CONFIG_HIBERNATION
	case LINUX_REBOOT_CMD_SW_SUSPEND:
		{
			int ret = hibernate();
			unlock_kernel();
			return ret;
		}
#endif

	default:
		unlock_kernel();
		return -EINVAL;
	}
	unlock_kernel();
	return 0;
}
コード例 #22
0
void KRIL_InitCmdHandler(void *ril_cmd, Kril_CAPI2Info_t *capi2_rsp)
{
    KRIL_CmdList_t *pdata = (KRIL_CmdList_t *)ril_cmd;
    ClientInfo_t clientInfo;
    CAPI2_MS_Element_t data;

    if (capi2_rsp != NULL)
    {
        KRIL_DEBUG(DBG_INFO, "handler_state:0x%lX::result:%d\n", pdata->handler_state, capi2_rsp->result);
        
        if(capi2_rsp->result != RESULT_OK)
        {
           pdata->handler_state = BCM_ErrorCAPI2Cmd;
        }
    }

    switch(pdata->handler_state)
    {
        case BCM_SendCAPI2Cmd:
        {
            KrilInit_t *pInitData = (KrilInit_t *)(pdata->ril_cmd->data);

            // if there is a valid IMEI, make appropriate CAPI2 call to set
            // IMEI on CP, otherwise fall through to next init command
            if (pInitData->is_valid_imei)
            {
                KRIL_DEBUG(DBG_INFO, "OTP IMEI:%s\n", pInitData->imei);

#ifdef CONFIG_BRCM_SIM_SECURE_ENABLE
                    // Record IMEI1 infomation  
                    if (FALSE == ProcessImei((UInt8*)pInitData->imei, sImei_Info))
                    {
                        KRIL_DEBUG(DBG_ERROR,"Process IMEI:%s Failed!!!", pInitData->imei);
                        pdata->handler_state = BCM_ErrorCAPI2Cmd;
                        kernel_power_off();
                    }
#endif //CONFIG_BRCM_SIM_SECURE_ENABLE

                memset(&data, 0, sizeof(CAPI2_MS_Element_t));
                memcpy(data.data_u.imeidata, pInitData->imei, IMEI_DIGITS);
                data.inElemType = MS_LOCAL_PHCTRL_ELEM_IMEI;
                CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
                CAPI2_MsDbApi_SetElement(&clientInfo, &data);
                pdata->handler_state = BCM_SET_HSDPA_PHY_CATEGORY;
                break;
            }
#ifdef CONFIG_BRCM_SIM_SECURE_ENABLE 
            else
            {
                // For secure boot, the IMEI is important inform for verifying SIM lock data.
                KRIL_DEBUG(DBG_ERROR, "IMEI is invalid. Error!!!\n");
                kernel_power_off();
            }
#endif //CONFIG_BRCM_SIM_SECURE_ENABLE 

            // if OTP IMEI passed from URIL is not valid, we skip the
            // CAPI2_MS_SetElement() call and fall through to execute the
            // next CAPI2 init call instead...
        }
         
	case BCM_SET_HSDPA_PHY_CATEGORY:
		{
			struct file *filp;
			mm_segment_t fs;
			int ret;
			int hsdpa_phy_cat = 8;

			filp = filp_open("/data/hsdpa.dat",  O_RDWR|O_SYNC, 0);
			if (IS_ERR(filp))
			{
				// Do not set hsdpa phy category value. just go next case. (Normal operaton)
				pdata->handler_state = BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS;
			}
			else
			{
				// hsdpa phy category is changed to do Vodafone test			
				fs = get_fs();
				set_fs(get_ds());
				ret = filp->f_op->read(filp, (char __user *)&hsdpa_phy_cat, sizeof(hsdpa_phy_cat), &filp->f_pos);
				set_fs(fs);
				filp_close(filp, NULL);

				KRIL_DEBUG(DBG_ERROR,"BCM_SET_HSDPA_PHY_CATEGORY\n");
				CAPI2_SYSPARM_SetHSDPAPHYCategory(GetNewTID(), GetClientID(), hsdpa_phy_cat );
	        	pdata->handler_state = BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS;
	        	break;
			}
		}

        case BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS:
        {
            memset((UInt8*)&data, 0, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SMS_ELEM_CLIENT_HANDLE_MT_SMS;
            data.data_u.bData = TRUE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SMS_SetSmsReadStatusChangeMode;
            break;
        }

        case BCM_SMS_SetSmsReadStatusChangeMode:
        {
            CAPI2_SMS_SetSmsReadStatusChangeMode(GetNewTID(), GetClientID(), FALSE);
            pdata->handler_state = BCM_SYS_SetFilteredEventMask;
            break;
        }

        case BCM_SYS_SetFilteredEventMask:
        {
            UInt16 filterList[]={MSG_RSSI_IND, MSG_CELL_INFO_IND, MSG_LCS_RRC_UE_STATE_IND, 
                                 MSG_DATE_TIMEZONE_IND, MSG_DATA_SUSPEND_IND, 
                                 MSG_DATA_RESUME_IND, MSG_CAPI2_AT_RESPONSE_IND, 
                                 MSG_UE_3G_STATUS_IND};
            CAPI2_SYS_SetFilteredEventMask(GetNewTID(), GetClientID(), &filterList[0], sizeof(filterList)/sizeof(UInt16), SYS_AP_DEEP_SLEEP_MSG_FILTER);
            pdata->handler_state = BCM_SYS_SetRssiThreshold;
            break;
        }

        case BCM_SYS_SetRssiThreshold:
        {
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_PhoneCtrlApi_SetRssiThreshold(&clientInfo, g_RSSIThreshold, 20, g_RSSIThreshold, 20);
            pdata->handler_state = BCM_TIMEZONE_SetTZUpdateMode;
            break;
        }

        case BCM_TIMEZONE_SetTZUpdateMode:
        {
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_NetRegApi_SetTZUpdateMode(&clientInfo, TIMEZONE_UPDATEMODE_NO_TZ_UPDATE);
            pdata->handler_state = BCM_SATK_SetTermProfile;
            break;
        }

        case BCM_SATK_SetTermProfile:
        {
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_SatkApi_SetTermProfile(&clientInfo, terminal_profile_data,
                sizeof(terminal_profile_data)/sizeof(UInt8));
            pdata->handler_state = BCM_SATK_SETUP_CALL_CTR;
            break;
        }

        case BCM_SATK_SETUP_CALL_CTR:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_SETUP_CALL_CTR;
#ifdef OEM_RIL_ENABLE
            data.data_u.bData = FALSE;
            pdata->handler_state = BCM_SATK_SEND_SS_CTR;
#else
            data.data_u.bData = TRUE;
            pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG;
#endif
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SATK_ICON_DISP_SUPPORTED;
            break;
        }

        case BCM_SATK_ICON_DISP_SUPPORTED:
        {
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_ICON_DISP_SUPPORTED;
            data.data_u.bData = TRUE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
#ifdef OEM_RIL_ENABLE
			pdata->handler_state = BCM_SATK_SEND_SS_CTR;  
#else
            pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG;            
#endif
            break;
        }

#ifdef OEM_RIL_ENABLE
        case BCM_SATK_SEND_SS_CTR:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_SEND_SS_CTR;
            data.data_u.bData = FALSE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SATK_SEND_USSD_CTR;
            break;
        }
        case BCM_SATK_SEND_USSD_CTR:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_SEND_USSD_CTR;
            data.data_u.bData = FALSE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SATK_SEND_SMS_CTR;
            break;
        }
        case BCM_SATK_SEND_SMS_CTR:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_SEND_SMS_CTR;
            data.data_u.bData = FALSE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SATK_SEND_ENABLE_7BIT_CONVERSIONS;
            break;
        }

        case BCM_SATK_SEND_ENABLE_7BIT_CONVERSIONS:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_ENABLE_7BIT_CONVERSIONS;
            data.data_u.bData = FALSE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SATK_SEND_SETUP_EVENT_LIST_CTR;
            break;
        }
        case BCM_SATK_SEND_SETUP_EVENT_LIST_CTR:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SATK_ELEM_SETUP_EVENT_LIST_CTR;
            data.data_u.bData = FALSE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_CFG_SIM_LOCK_SUPPORTED;
            break;
        }

         case BCM_CFG_SIM_LOCK_SUPPORTED:
        {
            CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_CFG_ELEM_SIM_LOCK_SUPPORTED ;
            data.data_u.bData = TRUE;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG;
            break;
        }


#endif


        case BCM_SS_SET_ENABLE_OLD_SS_MSG:
        {
            // enabled sending of "old" supp svcs messages
            // NOTE: this should go away when we move to the new SS apis
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SS_ELEM_ENABLE_OLD_SS_MSG;
            data.data_u.u8Data = 1;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SS_SET_ELEM_FDN_CHECK;
            break;
        }
                
        case BCM_SS_SET_ELEM_FDN_CHECK:
        {
            // enable FDN check for SS dialing
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
            data.inElemType = MS_LOCAL_SS_ELEM_FDN_CHECK;
            data.data_u.u8Data = 1;
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_MsDbApi_SetElement(&clientInfo, &data);
            pdata->handler_state = BCM_SET_SupportedRATandBand;
            break;
        }

        case BCM_SET_SupportedRATandBand:
        {
            KrilInit_t *pInitData = (KrilInit_t *)(pdata->ril_cmd->data);
            KRIL_SetPreferredNetworkType(pInitData->networktype);
            KRIL_SetBandMode(pInitData->band);
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            KRIL_DEBUG(DBG_INFO,"BCM_SET_SupportedRATandBand network type %d\n", pInitData->networktype);
            KRIL_DEBUG(DBG_INFO,"BCM_SET_SupportedRATandBand band %d conv band %d\n", pInitData->band, ConvertBandMode(pInitData->band));
            //TODO jw check this new api last two extra parameter.
            CAPI2_NetRegApi_SetSupportedRATandBand(&clientInfo, ConvertNetworkType(pInitData->networktype), ConvertBandMode(pInitData->band), ConvertNetworkType(pInitData->networktype), ConvertBandMode(pInitData->band) );

            //++ JSHAN Attach for next power on
		vGprsAttachMode = pInitData->gprs_attach_init;
		if (vGprsAttachMode == 1 || vGprsAttachMode == 2)
			pdata->handler_state = BCM_SET_AttachMode;
		else 
			pdata->handler_state = BCM_SET_RADIO_OFF;
		//-- JSHAN Attach for next power on
            break;
        }

	//++ JSHAN Attach for next power on
	case BCM_SET_AttachMode:
	{
		CAPI2_MS_Element_t data;
            memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t));
		data.inElemType = MS_LOCAL_PHCTRL_ELEM_ATTACH_MODE;
            data.data_u.u8Data = vGprsAttachMode;
		CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
		CAPI2_MsDbApi_SetElement ( &clientInfo,&data);
            pdata->handler_state = BCM_SET_RADIO_OFF;
            break;
        }
	//-- JSHAN Attach for next power on

        case BCM_SET_RADIO_OFF:
        {
            // For flight mode power up battery ADC & deep sleep issue (MobC00131482), set the initial CP state to RADIO_OFF.
            // If MS is powered up in normal mode, Android framework will send RIL_REQUEST_RADIO_POWER to RIL.
            CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
            CAPI2_PhoneCtrlApi_ProcessNoRfReq(&clientInfo);
            pdata->handler_state = BCM_RESPCAPI2Cmd;
            break;
        }
                
        case BCM_RESPCAPI2Cmd:
        {
            pdata->handler_state = BCM_FinishCAPI2Cmd;
            break;
        }

        default:
        {
            KRIL_DEBUG(DBG_ERROR,"Error handler_state:0x%lX\n", pdata->handler_state);
            pdata->handler_state = BCM_ErrorCAPI2Cmd;
            break;
        }
    }
}
コード例 #23
0
ファイル: poweroff.c プロジェクト: mikeberkelaar/grhardened
static void do_poweroff(struct work_struct *dummy)
{
	kernel_power_off();
}
コード例 #24
0
ファイル: reboot.c プロジェクト: ReneNyffenegger/linux
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
		void __user *, arg)
{
	struct pid_namespace *pid_ns = task_active_pid_ns(current);
	char buffer[256];
	int ret = 0;

	/* We only trust the superuser with rebooting the system. */
	if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT))
		return -EPERM;

	/* For safety, we require "magic" arguments. */
	if (magic1 != LINUX_REBOOT_MAGIC1 ||
			(magic2 != LINUX_REBOOT_MAGIC2 &&
			magic2 != LINUX_REBOOT_MAGIC2A &&
			magic2 != LINUX_REBOOT_MAGIC2B &&
			magic2 != LINUX_REBOOT_MAGIC2C))
		return -EINVAL;

	/*
	 * If pid namespaces are enabled and the current task is in a child
	 * pid_namespace, the command is handled by reboot_pid_ns() which will
	 * call do_exit().
	 */
	ret = reboot_pid_ns(pid_ns, cmd);
	if (ret)
		return ret;

	/* Instead of trying to make the power_off code look like
	 * halt when pm_power_off is not set do it the easy way.
	 */
	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
		cmd = LINUX_REBOOT_CMD_HALT;

	mutex_lock(&reboot_mutex);
	switch (cmd) {
	case LINUX_REBOOT_CMD_RESTART:
		kernel_restart(NULL);
		break;

	case LINUX_REBOOT_CMD_CAD_ON:
		C_A_D = 1;
		break;

	case LINUX_REBOOT_CMD_CAD_OFF:
		C_A_D = 0;
		break;

	case LINUX_REBOOT_CMD_HALT:
		kernel_halt();
		do_exit(0);
		panic("cannot halt");

	case LINUX_REBOOT_CMD_POWER_OFF:
		kernel_power_off();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_RESTART2:
		ret = strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1);
		if (ret < 0) {
			ret = -EFAULT;
			break;
		}
		buffer[sizeof(buffer) - 1] = '\0';

		kernel_restart(buffer);
		break;

#ifdef CONFIG_KEXEC_CORE
	case LINUX_REBOOT_CMD_KEXEC:
		ret = kernel_kexec();
		break;
#endif

#ifdef CONFIG_HIBERNATION
	case LINUX_REBOOT_CMD_SW_SUSPEND:
		ret = hibernate();
		break;
#endif

	default:
		ret = -EINVAL;
		break;
	}
	mutex_unlock(&reboot_mutex);
	return ret;
}
コード例 #25
0
static int tegra_battery_get_property(struct power_supply *psy,
	enum power_supply_property psp, union power_supply_propval *val)
{
	NvU8 name[BATTERY_INFO_NAME_LEN] = {0};
	int technology = 0;
	NvU8 state = 0;

	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
		if (!NvOdmBatteryGetBatteryStatus(batt_dev->hOdmBattDev,
			NvOdmBatteryInst_Main, &state))
			return -ENODEV;

		if (state == NVODM_BATTERY_STATUS_UNKNOWN) {
			batt_dev->present = NV_FALSE;
			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
		} else if (state == NVODM_BATTERY_STATUS_NO_BATTERY) {
			batt_dev->present = NV_FALSE;
			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
		} else if (state & NVODM_BATTERY_STATUS_CHARGING) {
			batt_dev->present = NV_TRUE;
			val->intval = POWER_SUPPLY_STATUS_CHARGING;
		} else if (state & NVODM_BATTERY_STATUS_DISCHARGING) {
			batt_dev->present = NV_TRUE;
			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
		} else if (state & NVODM_BATTERY_STATUS_IDLE) {
			batt_dev->present = NV_TRUE;
			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
		}

		if (!batt_dev->present ) {
			batt_dev->voltage = 0;
			batt_dev->current_ma = 0;
			batt_dev->current_avg  = 0;
			batt_dev->temp = 0;
			batt_dev->percent_remain = 0;
			batt_dev->lifetime = 0;
			batt_dev->consumed = 0;
			batt_dev->capacity = 0;
			batt_dev->capacity_crit = 0;
			batt_dev->capacity_remain = 0;
		}
		else {
			/*
			 * Getting the battery info once here so for the other property
			 * requests there will not be lot of ec req
			 */
			if (tegra_battery_data(NvOdmBatteryInst_Main)) {
				if (batt_dev->percent_remain == 100) {
					val->intval = POWER_SUPPLY_STATUS_FULL;
				}
				//Daniel 20100903, if (batt<=5%) and batt present and discharging, lock suspend.
				if((batt_dev->percent_remain <= 5) && (val->intval == POWER_SUPPLY_STATUS_DISCHARGING)) {
					if(mylock_flag == NV_FALSE) {
						wake_lock(&mylock);
						mylock_flag = NV_TRUE;
						NvOsDebugPrintf("ec_rs batt 5% wake_lock\n");
					}
					//Daniel 20100918, if (batt<=4%) and send batt=0% to trigger shutdown or just call kernel_power_off();.
					if(batt_dev->percent_remain <= 4) {
						NvOsDebugPrintf("ec_rs low_batt_cnt = %d\n", low_batt_cnt);
						batt_dev->percent_remain = 0; //to trigger APP shutdown procedure (workaround, app 5% shutdown isn't ready).
						low_batt_cnt++;
						if(low_batt_cnt > 8) {
							//do it on next battery polling
							NvOsDebugPrintf("ec_rs kernel_power_off.\r\n");
							msleep(500);
							kernel_power_off();
						}
					}
					else
						low_batt_cnt = 0;
				}
				else if(((batt_dev->percent_remain > 5) || (val->intval != POWER_SUPPLY_STATUS_DISCHARGING))) {
					if(mylock_flag == NV_TRUE) {
						wake_unlock(&mylock);
						mylock_flag = NV_FALSE;
						NvOsDebugPrintf("ec_rs batt 5% wake_unlock\n");
					}
				}
			}
		}
		break;

	case POWER_SUPPLY_PROP_HEALTH:
		if (batt_dev->present)
			val->intval = POWER_SUPPLY_HEALTH_GOOD;
		else
			val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
		break;

	case POWER_SUPPLY_PROP_PRESENT:
		if (!NvOdmBatteryGetBatteryStatus(batt_dev->hOdmBattDev,
			NvOdmBatteryInst_Main, &state))
			return -EINVAL;

		if (state == NVODM_BATTERY_STATUS_UNKNOWN) {
			batt_dev->present = NV_FALSE;
			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
		} else {
			if (state == NVODM_BATTERY_STATUS_NO_BATTERY) {
				 batt_dev->present = NV_FALSE;
				 val->intval = NV_FALSE;
			}

			if (state & (NVODM_BATTERY_STATUS_HIGH |
					NVODM_BATTERY_STATUS_LOW |
					NVODM_BATTERY_STATUS_CRITICAL |
					NVODM_BATTERY_STATUS_CHARGING |
					NVODM_BATTERY_STATUS_DISCHARGING |
					NVODM_BATTERY_STATUS_IDLE)) {
				batt_dev->present = NV_TRUE;
				val->intval = NV_TRUE;
			}
		}
		break;

	case POWER_SUPPLY_PROP_TECHNOLOGY:
		tegra_get_battery_tech(&technology, NvOdmBatteryInst_Main);
		val->intval = technology;
		break;

	case POWER_SUPPLY_PROP_CAPACITY:
		val->intval = batt_dev->percent_remain;
		break;

	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
		val->intval = batt_dev->voltage*1000;
		break;

	case POWER_SUPPLY_PROP_CURRENT_NOW:
		val->intval = batt_dev->current_ma;
		break;

	case POWER_SUPPLY_PROP_CURRENT_AVG:
		val->intval = batt_dev->current_avg;
		break;

	case POWER_SUPPLY_PROP_CHARGE_NOW:
		val->intval = batt_dev->capacity_remain;
		break;

	case POWER_SUPPLY_PROP_CHARGE_FULL:
		val->intval = batt_dev->capacity;
		break;

	case POWER_SUPPLY_PROP_CHARGE_EMPTY:
		val->intval = batt_dev->capacity_crit;
		break;

	case POWER_SUPPLY_PROP_TEMP:
		/* returned value is degrees C * 10 */
		//Daniel 20100706, its unit is 0.1 degree-K, not 0.01 degree-C.
		//Daniel 20100707, convert from tenths of a degree-K to tenths of a degree-C.
		//val->intval = batt_dev->temp/10;
		val->intval = batt_dev->temp - 2730;
		break;

	case POWER_SUPPLY_PROP_MODEL_NAME:
		if (!NvOdmBatteryGetModel(batt_dev->hOdmBattDev,
			NvOdmBatteryInst_Main, name))
			return -EINVAL;

		strncpy((char *)val->strval, name, strlen(name));
		break;

	case POWER_SUPPLY_PROP_MANUFACTURER:
		if (!NvOdmBatteryGetManufacturer(batt_dev->hOdmBattDev,
			NvOdmBatteryInst_Main, name))
			return -EINVAL;

		strncpy((char *)val->strval, name, strlen(name));
		break;

	default:
		return -EINVAL;
	}

	return 0;
}
コード例 #26
0
ファイル: power_button.c プロジェクト: robacklin/ts4700
void shutdown_ok(void)
{
	printk("shutdown now\n");
       kernel_power_off();
}
コード例 #27
0
static int rk29_charger_display(struct wm831x_chg *wm831x_chg)
{
	int status;
	struct linux_logo* chargerlogo[8];
	int ret,i;
	
	wm831x_chg->flag_chg = wm831x_read_chg_status(wm831x_chg);
	if(!wm831x_chg->flag_chg)
		return -1;

	while(1)
	{
		wm831x_chg->flag_chg = wm831x_read_chg_status(wm831x_chg);
		if(!wm831x_chg->flag_chg)
			kernel_power_off();

		status = wm831x_read_bat_charging_status(wm831x_chg);

		for(i=0; i<8; i++)
		chargerlogo[i] = g_chargerlogo[i];
	
		if(status == BAT_CHARGING)
		{	
			for(i=get_charger_logo_start_num(wm831x_chg); i<8; i++ )
			{
				wm831x_chg->flag_chg = wm831x_read_chg_status(wm831x_chg);
				if(!wm831x_chg->flag_chg)
				kernel_power_off();
				if(wm831x_chg->flag_bl != 0)
				ret = charger_logo_display(chargerlogo[i]);

				DBG("%s:i=%d\n",__FUNCTION__,i);

				msleep(200);	
				wm831x_check_on_pin(wm831x_chg);
				msleep(200);
				wm831x_check_on_pin(wm831x_chg);

			}
					
		}
		else if(status == BAT_DISCHARGING)
		{
			if(wm831x_chg->flag_bl != 0)
			charger_logo_display(chargerlogo[7]);
			msleep(200);
			wm831x_check_on_pin(wm831x_chg);
			msleep(200);
			wm831x_check_on_pin(wm831x_chg);
		}
		
		//suspend when timeout(about 50*200ms)
		if(wm831x_chg->cnt_disp++ > 50)
		{
			if(wm831x_chg->flag_suspend == 0)
			{
				wm831x_chg->flag_suspend = 1;
				wm831x_chg->cnt_disp = 0;
				wm831x_chg->flag_bl = 0;
				charger_backlight_ctrl(wm831x_chg->flag_bl);
			}
			wm831x_chg->cnt_disp = 0;
		}

		printk("%s,status=%d,cnt_on=%d,cnt_disp=%d\n",__FUNCTION__,status,wm831x_chg->cnt_on,wm831x_chg->cnt_disp);

		//open system if long time press
		if(wm831x_chg->cnt_on > 4)
		{
			wm831x_chg->cnt_on = 0;
			wm831x_chg->flag_bl = 1;
			charger_backlight_ctrl(wm831x_chg->flag_bl);
			wm831x_chg->flag_suspend = 0;
			wm831x_chg->cnt_disp = 0;
			break;
		}	
		
	}

	return 0;

}
コード例 #28
0
static void __toi_power_down(int method)
{
	int error;

	toi_cond_pause(1, test_action_state(TOI_REBOOT) ? "Ready to reboot." :
			"Powering down.");

	if (test_result_state(TOI_ABORTED))
		goto out;

	if (test_action_state(TOI_REBOOT))
		kernel_restart(NULL);

	switch (method) {
	case 0:
		break;
	case 3:
		/*
		 * Re-read the overwritten part of pageset2 to make post-resume
		 * faster.
		 */
		if (read_pageset2(1))
			panic("Attempt to reload pagedir 2 failed. "
					"Try rebooting.");

		pm_prepare_console();

		error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
		if (!error) {
			pm_restore_gfp_mask();
			error = suspend_devices_and_enter(PM_SUSPEND_MEM);
			pm_restrict_gfp_mask();
			if (!error)
				did_suspend_to_both = 1;
		}
		pm_notifier_call_chain(PM_POST_SUSPEND);
		pm_restore_console();

        // jonathan.jmchen: FIXME, Create API to add another wakeup source to power down,
        // if system is idle after xxx (e.g., 5 min) without user interaction!!

		/* Success - we're now post-resume-from-ram */
		if (did_suspend_to_both)
			return;

		/* Failed to suspend to ram - do normal power off */
		break;
	case 4:
		/*
		 * If succeeds, doesn't return. If fails, do a simple
		 * powerdown.
		 */
		hibernation_platform_enter();
		break;
	case 5:
		/* Historic entry only now */
		break;
	}

	if (method && method != 5)
		toi_cond_pause(1,
			"Falling back to alternate power off method.");

	if (test_result_state(TOI_ABORTED))
		goto out;

	kernel_power_off();
	kernel_halt();
	toi_cond_pause(1, "Powerdown failed.");
	while (1)
		cpu_relax();

out:
	if (read_pageset2(1))
		panic("Attempt to reload pagedir 2 failed. Try rebooting.");
	return;
}