int smb345_config_thermal_charging(int temp, int volt, int rule) { struct i2c_client *client = charger->client; int ret = 0, retval, setting = 0; int BAT_Mid_Temp = BAT_Mid_Temp_Wired; if (rule == THERMAL_RULE1) BAT_Mid_Temp = BAT_Mid_Temp_Wired; else if (rule == THERMAL_RULE2) BAT_Mid_Temp = BAT_Mid_Temp_Wireless; smb345_config_thermal_limit(); SMB_NOTICE("temp=%d, volt=%d\n", temp, volt); ret = smb345_volatile_writes(client, smb345_ENABLE_WRITE); if (ret < 0) { dev_err(&client->dev, "%s() charger enable write error..\n", __func__); goto error; } /*control float voltage*/ retval = smb345_read(client, smb345_FLOAT_VLTG); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_FLOAT_VLTG); goto error; } setting = retval & FLOAT_VOLT_MASK; if (temp <= BAT_Mid_Temp || (temp > BAT_Mid_Temp && volt > FLOAT_VOLT_LOW_DECIMAL) || temp > BAT_Hot_Limit) { if (setting != FLOAT_VOLT_43V) { setting = retval & (~FLOAT_VOLT_MASK); setting |= FLOAT_VOLT_43V; SMB_NOTICE("Set Float Volt, retval=%x setting=%x\n", retval, setting); ret = smb345_write(client, smb345_FLOAT_VLTG, setting); if (ret < 0) { dev_err(&client->dev, "%s(): Failed in writing 0x%02x to register" "0x%02x\n", __func__, setting, smb345_FLOAT_VLTG); goto error; } } else SMB_NOTICE("Bypass set Float Volt=%x\n", retval); } else { if (setting != FLOAT_VOLT_LOW) { setting = retval & (~FLOAT_VOLT_MASK); setting |= FLOAT_VOLT_LOW; SMB_NOTICE("Set Float Volt, retval=%x setting=%x\n", retval, setting); ret = smb345_write(client, smb345_FLOAT_VLTG, setting); if (ret < 0) { dev_err(&client->dev, "%s(): Failed in writing 0x%02x to register" "0x%02x\n", __func__, setting, smb345_FLOAT_VLTG); goto error; } } else SMB_NOTICE("Bypass set Float Volt=%x\n", retval); } /*charger enable/disable*/ retval = smb345_read(client, smb345_PIN_CTRL); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_PIN_CTRL); goto error; } setting = retval & ENABLE_PIN_CTRL_MASK; if (temp < BAT_Cold_Limit || temp > BAT_Hot_Limit || (temp > BAT_Mid_Temp && volt > FLOAT_VOLT_LOW_DECIMAL)) { if (setting != 0x40) { SMB_NOTICE("Charger disable\n"); smb345_charger_enable(false); } else SMB_NOTICE("Bypass charger disable\n"); } else { if (setting != 0x60) { SMB_NOTICE("Charger enable\n"); smb345_charger_enable(true); } else { /*interrupt status*/ retval = smb345_read(client, smb345_INTR_STS_B); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_INTR_STS_B); goto error; } if ((retval & BAT_OVER_VOLT_MASK) == 0x40) { SMB_NOTICE("disable then enable charger to recover bat over-volt\n"); smb345_charger_enable(false); smb345_charger_enable(true); } else SMB_NOTICE("Bypass charger enable\n"); } } ret = smb345_volatile_writes(client, smb345_DISABLE_WRITE); if (ret < 0) { dev_err(&client->dev, "%s() charger enable write error..\n", __func__); goto error; } error: return ret; }
int smb345_config_thermal_charging(int temp, int volt, int rule) { struct i2c_client *client = charger->client; int ret = 0, retval, setting = 0; int BAT_Mid_Temp = BAT_Mid_Temp_Wired; /*Charger float voltage for normal temperature conditions. Default 4.3V.*/ int flt_volt_43 = FLOAT_VOLT_43V; /*Charger float voltage for high temperature conditions. Default 4.1V.*/ int flt_volt_low = FLOAT_VOLT_LOW; flt_volt_43 = (float_volt_setting - 3500) / 20; if(flt_volt_43 < 0 || flt_volt_43 > FLOAT_VOLT_43V) { SMB_NOTICE("BUG: Invalid float voltage setting calculated: %d\n", flt_volt_43); flt_volt_43 = FLOAT_VOLT_43V; } if(flt_volt_low > flt_volt_43) flt_volt_low = flt_volt_43; if (rule == THERMAL_RULE1) BAT_Mid_Temp = BAT_Mid_Temp_Wired; else if (rule == THERMAL_RULE2) BAT_Mid_Temp = BAT_Mid_Temp_Wireless; mdelay(100); smb345_config_thermal_limit(); SMB_NOTICE("temp=%d, volt=%d\n", temp, volt); ret = smb345_volatile_writes(client, smb345_ENABLE_WRITE); if (ret < 0) { dev_err(&client->dev, "%s() charger enable write error..\n", __func__); goto error; } /*control float voltage*/ retval = smb345_read(client, smb345_FLOAT_VLTG); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_FLOAT_VLTG); goto error; } setting = retval & FLOAT_VOLT_MASK; if (temp <= BAT_Mid_Temp || (temp > BAT_Mid_Temp && volt > FLOAT_VOLT_LOW_DECIMAL) || temp > BAT_Hot_Limit) { if (setting != flt_volt_43) { setting = retval & (~FLOAT_VOLT_MASK); setting |= flt_volt_43; SMB_NOTICE("Set Float Volt, retval=%x setting=%x V=%dmV\n", retval, setting, float_volt_setting); ret = smb345_write(client, smb345_FLOAT_VLTG, setting); if (ret < 0) { dev_err(&client->dev, "%s(): Failed in writing 0x%02x to register" "0x%02x\n", __func__, setting, smb345_FLOAT_VLTG); goto error; } } else SMB_NOTICE("Bypass set Float Volt setting=%x V=%dmV\n", retval, float_volt_setting); } else { if (setting != flt_volt_low) { setting = retval & (~FLOAT_VOLT_MASK); setting |= flt_volt_low; SMB_NOTICE("Set Float Volt, retval=%x setting=%x\n", retval, setting); ret = smb345_write(client, smb345_FLOAT_VLTG, setting); if (ret < 0) { dev_err(&client->dev, "%s(): Failed in writing 0x%02x to register" "0x%02x\n", __func__, setting, smb345_FLOAT_VLTG); goto error; } } else SMB_NOTICE("Bypass set Float Volt=%x\n", retval); } /*charger enable/disable*/ retval = smb345_read(client, smb345_PIN_CTRL); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_PIN_CTRL); goto error; } setting = retval & ENABLE_PIN_CTRL_MASK; if (temp < BAT_Cold_Limit || temp > BAT_Hot_Limit || (temp > BAT_Mid_Temp && volt > FLOAT_VOLT_LOW_DECIMAL)) { if (setting != 0x40) { SMB_NOTICE("Charger disable\n"); smb345_charger_enable(false); } else SMB_NOTICE("Bypass charger disable\n"); } else { if (setting != 0x60) { SMB_NOTICE("Charger enable\n"); smb345_charger_enable(true); } else { /*interrupt status*/ retval = smb345_read(client, smb345_INTR_STS_B); if (retval < 0) { dev_err(&client->dev, "%s(): Failed in reading 0x%02x", __func__, smb345_INTR_STS_B); goto error; } if ((retval & BAT_OVER_VOLT_MASK) == 0x40) { SMB_NOTICE("disable then enable charger to recover bat over-volt\n"); smb345_charger_enable(false); smb345_charger_enable(true); } else SMB_NOTICE("Bypass charger enable\n"); } } ret = smb345_volatile_writes(client, smb345_DISABLE_WRITE); if (ret < 0) { dev_err(&client->dev, "%s() charger enable write error..\n", __func__); goto error; } error: return ret; }