コード例 #1
0
/*di->enable_ce = 0,charger enable and display charging status
  di->enable_ce = 1 or USB supply fault,charger disable and display not charging status*/
static void
bq2416x__charge_status(struct bq2416x_device_info *di)
{
	long int events=BQ2416x_START_CHARGING;
	u8 read_reg[8] = {0};
    int battery_capacity = 0;

	bq2416x_read_block(di, &read_reg[0], 0, 2);

	if((read_reg[1] & BQ2416x_FAULT_VBUS_VUVLO) == BQ2416x_FAULT_VBUS_OVP){
		dev_err(di->dev, " POWER_SUPPLY_OVERVOLTAGE = %x\n",read_reg[1]);
		events = POWER_SUPPLY_OVERVOLTAGE;
		blocking_notifier_call_chain(&notifier_list, events, NULL);
		return;
	}

	if ((read_reg[0] & BQ2416x_VUSB_FAULT) == BQ2416x_CHARGING_FROM_USB){
				events = BQ2416x_START_CHARGING;
	}
	else if((di->enable_ce == DISABLE_CE)
		|| ((read_reg[0] & POWER_SUPPLY_STATE_FAULT) == POWER_SUPPLY_STATE_FAULT)){
		dev_err(di->dev, " BQ2416x_NOT_CHARGING \n");
		events = BQ2416x_NOT_CHARGING;
	}

	else if((read_reg[0] & BQ2416x_VUSB_FAULT) == BQ2416x_CHARGE_DONE){
        battery_capacity = bq27510_battery_capacity(g_battery_measure_by_bq27510_device);
        if((!is_bq27510_battery_full(g_battery_measure_by_bq27510_device))||(battery_capacity !=100)){
            dev_info(di->dev, "charge_done_battery_capacity=%d\n",battery_capacity);
            di->hz_mode = 1; /*enable bq2416x charger high impedance mode*/
            bq2416x_write_byte(di, di->control_reg | di->hz_mode, REG_CONTROL_REGISTER);
            di->hz_mode = 0; /*disable bq2416x charger high impedance mode*/
            msleep(700);
            bq2416x_config_control_reg(di);
            events = BQ2416x_START_CHARGING;
        } else{
            events = BQ2416x_CHARGE_DONE;
       }
     }
	else{
	     events=BQ2416x_START_CHARGING;
		dev_dbg(di->dev, "BQ2416x_START_CHARGING !\n");
	}
	if(di->charger_source == POWER_SUPPLY_TYPE_BATTERY){
		return;
	}
	blocking_notifier_call_chain(&notifier_list, events, NULL);
}
コード例 #2
0
static void
bq2416x_charger_update_status(struct bq2416x_device_info *di)
{
	u8 read_reg[8] = {0};

	timer_fault = 0;
	bq2416x_read_block(di, &read_reg[0], 0, 8); 

	if ((read_reg[0] & 0x70) == 0x50)   
		dev_dbg(di->dev, "CHARGE DONE\n");

	if ((read_reg[0] & 0x7) == 0x4) 
		timer_fault = 1;
     
	if (read_reg[0] & 0x7) {
		di->cfg_params = 1;
		dev_err(di->dev, "CHARGER STATUS = %x\n", read_reg[0]);
	}

    if ((read_reg[1] & 0x6) == 0x2) {
        di->hz_mode = 1;
        bq2416x_config_control_reg(di);
        bq2416x_write_byte(di, di->voltage_reg, REG_BATTERY_VOLTAGE);
        dev_err(di->dev, "battery ovp = %x,%x\n", read_reg[1],read_reg[3]);
        msleep(700);
        di->hz_mode = 0;
        bq2416x_config_control_reg(di);
    }

	if (is_bq27510_battery_exist(g_battery_measure_by_bq27510_device)){
		bq2416x__charge_status(di);
	}

	if ((timer_fault == 1) || (di->cfg_params == 1)) {
		bq2416x_write_byte(di, di->control_reg, REG_CONTROL_REGISTER);
		bq2416x_write_byte(di, di->voltage_reg, REG_BATTERY_VOLTAGE);
		bq2416x_write_byte(di, di->current_reg, REG_BATTERY_CURRENT);
		bq2416x_write_byte(di, di->dppm_reg, REG_DPPM_VOLTAGE);
		bq2416x_config_safety_reg(di); 
		di->cfg_params = 0;
	}

	/* reset 32 second timer */
	bq2416x_config_status_reg(di);

	return;
}
コード例 #3
0
static ssize_t bq2416x_show_chargelog(struct device *dev,
				  struct device_attribute *attr,
				  char *buf)
{
        int i = 0;
        u8   read_reg[8] = {0};
        u8   buf_temp[20] = {0};
        struct bq2416x_device_info *di = dev_get_drvdata(dev);
        bq2416x_read_block(di, &read_reg[0], 0, 8);
        for(i=0;i<8;i++)
        {
            sprintf(buf_temp,"0x%-8.2x",read_reg[i]);
            strcat(buf,buf_temp);
        }
        strcat(buf,"\n");
	return strlen(buf);
}
コード例 #4
0
static int bq2416x_charger_event(struct notifier_block *nb, unsigned long event,
				void *_data)
{

	printk("%s,---->enter bq2416x_charger_event\n", __func__);

	struct bq2416x_device_info *di;
	struct charge_params *data;
	u8 read_reg[8] = {0};
	int ret = 0;

	di = container_of(nb, struct bq2416x_device_info, nb);
	data = &di->params;
	di->cfg_params = 1;

	if (event & BQ2416x_CHARGER_FAULT) {
		bq2416x_read_block(di, &read_reg[0], 0, 8);
		ret = read_reg[0] & 0x7F;
		return ret;
	}

	if (data->enable == 0) {
		di->currentmA = data->currentmA;
		di->voltagemV = data->voltagemV;
		di->enable_iterm = data->enable_iterm;
	}
       if ((event & BQ2416x_DEFAULT_USB_CHARGING ) && (di->active == 0)) {
		 di->cin_limit = 500;
	       bq2416x_config_control_reg(di);
	       bq2416x_config_voltage_reg(di);
	       bq2416x_config_current_reg(di);
		bq2416x_config_dppm_voltage_reg(di,di->dppm_voltagemV);	   	
		schedule_delayed_work(&di->bq2416x_charger_work,
						msecs_to_jiffies(0));
		di->active = 1;	   	
       }
	if ((event & BQ2416x_START_AC_CHARGING) && (di->active == 0)) {
		di->cin_limit = 1000;
	       bq2416x_config_control_reg(di);
	       bq2416x_config_voltage_reg(di);
	       bq2416x_config_current_reg(di);
		bq2416x_config_dppm_voltage_reg(di,di->dppm_voltagemV);	
		printk("%s, charging with VAC\n", __func__);	
		schedule_delayed_work(&di->bq2416x_charger_work,
						msecs_to_jiffies(0));
		di->active = 1;
	}
	
	if ((event & BQ2416x_START_USB_CHARGING) && (di->active == 0)) { 
		di->cin_limit = 500;
	       bq2416x_config_control_reg(di);
	       bq2416x_config_voltage_reg(di);
	       bq2416x_config_current_reg(di);
		bq2416x_config_dppm_voltage_reg(di,di->dppm_voltagemV);		
		printk("%s, charging with USB\n", __func__);		
		schedule_delayed_work(&di->bq2416x_charger_work,
						msecs_to_jiffies(0));
		di->active = 1;
	}

	if (event & BQ2416x_STOP_CHARGING) {
		cancel_delayed_work(&di->bq2416x_charger_work);
		di->active = 0;
	}

	if (event & BQ2416x_RESET_TIMER) {
		/* reset 32 second timer */
		bq2416x_config_status_reg(di);
	}

	return ret;
}
コード例 #5
0
static int bq2416x_read_byte(struct bq2416x_device_info *di, u8 *value, u8 reg)
{
	return bq2416x_read_block(di, value, reg, 1);
}
コード例 #6
0
static void
bq2416x_charger_update_status(struct bq2416x_device_info *di)
{
	u8 read_reg[8] = {0};
    long int events=BQ2416x_START_CHARGING;
    static int battery_capacity = 0;

	di->timer_fault = 0;
	bq2416x_read_block(di, &read_reg[0], 0, 8); 

	if((read_reg[1] & BQ2416x_FAULT_VBUS_VUVLO) == BQ2416x_FAULT_VBUS_OVP){
		dev_err(di->dev, "bq2416x charger over voltage = %x\n",read_reg[1]);
		events = POWER_SUPPLY_OVERVOLTAGE;
		blocking_notifier_call_chain(&notifier_list, events, NULL);
	}
   
	if ((read_reg[0] & BQ2416x_CHARGE_FAULT) == BQ2416x_STATUS_CHARGE_DONE){   
		dev_dbg(di->dev, "CHARGE DONE\n");
        battery_capacity = bq27510_battery_capacity(g_battery_measure_by_bq27510_device);
        if (((!is_bq27510_battery_full(g_battery_measure_by_bq27510_device))||(battery_capacity!=100))&& (di->battery_present)){
            dev_info(di->dev, "charge_done_battery_capacity=%d\n",battery_capacity);
            di->hz_mode = EN_HIZ;
			bq2416x_write_byte(di, di->control_reg02 | di->hz_mode, REG_CONTROL_REGISTER_REG02);
            msleep(500);
			di->hz_mode = DIS_HIZ;
            bq2416x_config_control_reg(di);
			events = BQ2416x_START_CHARGING;           
        }else{
            events = BQ2416x_CHARGE_DONE;
        }
        blocking_notifier_call_chain(&notifier_list, events, NULL);
    }

	if ((read_reg[0] & BQ2416x_FAULT_BATTERY) == BQ2416x_FAULT_WATCHDOG_TIMER){ 
		di->timer_fault = 1;
     }

	if ((read_reg[0] & BQ2416x_FAULT_BATTERY) == BQ2416x_FAULT_SAFETY_TIMER) 
		di->timer_fault = 1;
     
	if (read_reg[0] & BQ2416x_FAULT_BATTERY) {
		di->cfg_params = 1;
		dev_err(di->dev, "CHARGER STATUS %x\n", read_reg[0]);
	}

	if ((read_reg[1] & 0x6) == BQ2416x_FAULT_BAT_OVP) {
        gpio_set_value(ENABLE_BQ2416x_CHARGER, 1);
		dev_err(di->dev, "battery ovp = %x,%x\n", read_reg[1],read_reg[3]);
        msleep(1000);
        gpio_set_value(ENABLE_BQ2416x_CHARGER, 0);
	}

	if ((di->timer_fault == 1) || (di->cfg_params == 1)) {
		bq2416x_write_byte(di, di->control_reg02, REG_CONTROL_REGISTER_REG02);
		bq2416x_write_byte(di, di->voltage_reg03, REG_BATTERY_VOLTAGE_REG03);
		bq2416x_write_byte(di, di->current_reg05, REG_BATTERY_CURRENT_REG05);
		bq2416x_write_byte(di, di->dppm_reg06, REG_DPPM_VOLTAGE_REG06);
		bq2416x_config_safety_reg(di); 
		di->cfg_params = 0;
	}

	/* reset 32 second timer */
	bq2416x_config_status_reg(di);

	return;
}