Beispiel #1
0
void set_charger_factory_mode()
{
    struct i2c_client *client = miniabb_i2c_client;
    u8 data;

    data = 0x91; //CHG_CURR_1000mA|EOC_LVL_10PER;
    i2c_smbus_write_byte_data(client,CHG_CTRL2, data);
    data = i2c_smbus_read_word_data(client,CHG_CTRL2);

    miniabb_is_PTM = 1;

    charger_enable();

    printk("[Miniabb] FACTORY charging :  0x%02x \n",data);
}
Beispiel #2
0
void set_charger_start_mode(int value)
{
    struct i2c_client *client = miniabb_i2c_client;
    u8 data;

    // current/EOC LEVEL setting
    if(value == CHG_TA) {
        data = 0x61; //CHG_CURR_700mA|EOC_LVL_10PER;
    } 
    else {
        data = 0x21; //CHG_CURR_400mA|EOC_LVL_10PER;
    }
    i2c_smbus_write_byte_data(client,CHG_CTRL2, data);

    charger_enable();

    printk("[Miniabb] Charging Current %dmA\n",value);
}
void set_charger_factory_mode()
{
    struct i2c_client *client = miniabb_i2c_client;
    u8 data;

    /*                                                                                                */
#if 0
    /* kisung.song : 4.35V setting (CHG_VSET)  */
    data = 0x91|CHG_VSET; //CHG_CURR_1000mA|EOC_LVL_10PER;
    i2c_smbus_write_byte_data(client,CHG_CTRL2, data);
    data = i2c_smbus_read_word_data(client,CHG_CTRL2);

    miniabb_is_PTM = 1;

    charger_enable();
#endif
    /*                                                                                                */

    printk("[Miniabb] FACTORY charging :  0x%02x \n",data);
}
void set_charger_start_mode(CHG_TYPE chg_type)
{
    struct i2c_client *client = miniabb_i2c_client;
    u8 data;

    /*                                                                                                */
    if (miniabb_is_PTM == MINI_ABB_NORMAL_MODE)
    {
        /* kisung.song : current/EOC LEVEL setting, 4.35V setting (CHG_VSET)*/
        switch(chg_type) {
        case CHG_TA :
            data = CHG_CURR_700mA | CHG_VSET | EOC_LVL_20PER;
            break;
        case CHG_600 :
            data = CHG_CURR_600mA | CHG_VSET | EOC_LVL_10PER;
            break;
        case CHG_500 :
            data = CHG_CURR_500mA | CHG_VSET | EOC_LVL_10PER;
            break;
        case CHG_USB :
            data = CHG_CURR_400mA | CHG_VSET | EOC_LVL_33PER;
            break;
        case CHG_100 :
            data = CHG_CURR_100mA | CHG_VSET | EOC_LVL_10PER;
            break;
        case CHG_90 :
            data = CHG_CURR_90mA | CHG_VSET | EOC_LVL_10PER;
            break;
        default :
            data = CHG_CURR_400mA | CHG_VSET | EOC_LVL_33PER;
            break;
        }

        i2c_smbus_write_byte_data(client,CHG_CTRL2, data);

        charger_enable();
    }
    printk("[Miniabb] Charging Current %dmA\n",chg_type);
    /*                                                                                                */

}
void set_charger_start_mode(int value)
{
    struct i2c_client *client = miniabb_i2c_client;
    u8 data;

    /*                                                                                                */
    if (miniabb_is_PTM == MINI_ABB_NORMAL_MODE)
    {
        /* kisung.song : current/EOC LEVEL setting, 4.35V setting (CHG_VSET)*/
        if(value == CHG_TA) {
            data = 0x63|CHG_VSET; //CHG_CURR_700mA|EOC_LVL_20PER;
        }
        else {
            data = 0x25|CHG_VSET; //CHG_CURR_400mA|EOC_LVL_33PER;
        }
        i2c_smbus_write_byte_data(client,CHG_CTRL2, data);

        charger_enable();
    }
    printk("[Miniabb] Charging Current %dmA\n",value);
    /*                                                                                                */

}
static void charge_loop(uint16_t *batt_soc, int emergency_charge)
{
	enum charge_level_t charge_level, charge_level_new;
	int tick = 0;
	uint16_t voltage = 0;
	u8 pwron;
	int microvolts, ret;
	int action = READ_BATTERY; // initially we wan't to read the battery status

	charge_level = charger_detect();
	charger_enable(charge_level, emergency_charge);
	// and we wan't to display a charge status image
	display_image_charging(*batt_soc, charge_level);

	while ((*batt_soc < SOC_THRESH_MIN || emergency_charge) &&
			charge_level != CHARGE_DISABLE) {	
		if (action & READ_BATTERY) {
			ret = max17042_soc(batt_soc);
		
			if (ret) {
				printf("Failed to read battery capacity, reason: %d\n", ret);
				if (!emergency_charge) {
					break;
				}
			}

			ret = max17042_voltage(&voltage);

			if (ret) {
				printf("Failed to read battery voltage, reason: %d\n", ret);

				if (!emergency_charge) {
					break;
				}
			}
		
			microvolts = voltage*625;
			printf("Charging... %hu%% (%d uV)\n", *batt_soc, microvolts);

			// If microvolts isn't 0 then we can talk to the gas gauge
			// and we no longer need to emergency charge
			emergency_charge = (microvolts <= 0);

			charge_level_new = charger_detect();

			if (charge_level != charge_level_new) {
				// to avoid re-writing the GPIOs all the time
				charge_level = charge_level_new;
				charger_enable(charge_level, emergency_charge);
			}
		}

		if (action & UPDATE_DISPLAY) {
			pwron = 0;
			if (twl6030_hw_status(&pwron)) {
				printf("Failed to read twl6030 hw_status\n");
			}

			// if button is pressed turn on screen
			if ((pwron & STS_PWRON) != STS_PWRON) {
				display_image_charging(*batt_soc, charge_level);
			} else if (lcd_is_on) {
				// if not turn off screen
				lcd_disable();
				lcd_is_on = 0;
			}
		}

		// each tick is 200 ms
		udelay(1000 * 200);
		++tick; // tick will overflow in approx. 4971 days
		action = get_charge_action(tick);
	}

	if (charge_level != CHARGE_DISABLE) {
		charger_enable(CHARGE_DISABLE, emergency_charge);
	}
}