Beispiel #1
0
static void twl6030_start_usb_charger(struct twl6030_bci_device_info *di, int mA)
{
	int ret;

	if (!is_battery_present(di)) {
		dev_err(di->dev, "BATTERY NOT DETECTED!\n");
		return;
	}

	if (mA < 50) {
		ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0, CONTROLLER_CTRL1);
		if (ret)
			goto err;
		return;
	}

	twl6030_config_vichrg_reg(di, di->charger_outcurrentmA);
	twl6030_config_cinlimit_reg(di, mA);
	twl6030_config_voreg_reg(di, di->platform_data->max_bat_voltagemV);
	twl6030_config_iterm_reg(di, di->platform_data->termination_currentmA);

	if (mA >= 50) {
		twl6030_set_watchdog(di, di->watchdog_duration);
		/* disable current termination, suspend mode, boost mode, etc */
		twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0, CHARGERUSB_CTRL1);
		ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, CONTROLLER_CTRL1_EN_CHARGER, CONTROLLER_CTRL1);
		if (ret)
			goto err;
	}
	/* printk("battery: CHARGER ON\n"); */
	return;

err:
	pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
}
void get_device_state(struct device_state *s)
{
    s->is_plugged_into_ac = is_plugged_into_ac();
    s->is_plugged_into_usb = is_plugged_into_usb();
    s->is_battery_present = is_battery_present();
    s->is_charging = is_charging();
    s->is_unknown = is_unknown();
    s->charge_level = charge_level();
    s->voltage_level = voltage_level();
}