Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8562c44 authored by Gerard Huang's avatar Gerard Huang Committed by Wy Chuang
Browse files

[ALPS05468999] Charger: Fixing issue and sync patches



[Detail]
1. Fixing the issue KPOC did not power off after cable plugged out.
2. Refine the checking Rp level to select charger current.
3. Adding the Non-Standard charger type handling.

MTK-Commit-Id: 49d6b1207fa5196ba87bb2999f4abeb723addfa1

Change-Id: I54796ee1b674af635dec58083c560cbdf514a114
Signed-off-by: default avatarGerard Huang <Gerard.Huang@mediatek.com>
CR-Id: ALPS05468999
Feature: Charger
parent 7f63e755
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -564,6 +564,7 @@ static inline void typec_unattached_cc_entry(struct tcpc_device *tcpc_dev)
			break;
		default:
			TYPEC_NEW_STATE(typec_unattached_snk);
			tcpc_dev->typec_remote_rp_level = typec_get_cc_res();
			tcpci_set_cc(tcpc_dev, TYPEC_CC_DRP);
			typec_enable_low_power_mode(tcpc_dev, TYPEC_CC_DRP);
			break;
+66 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <linux/regmap.h>
#include <linux/power_supply.h>
#include <mtk_musb.h>
#include <linux/reboot.h>

/* ============================================================ */
/* pmic control start*/
@@ -88,10 +89,20 @@ struct mtk_charger_type {

	int first_connect;
	int bc12_active;
	u32 bootmode;
	u32 boottype;
};

struct tag_bootmode {
	u32 size;
	u32 tag;
	u32 bootmode;
	u32 boottype;
};

static enum power_supply_property chr_type_properties[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_TYPE,
	POWER_SUPPLY_PROP_USB_TYPE,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
};
@@ -568,6 +579,21 @@ static void do_charger_detection_work(struct work_struct *data)
	pr_notice("%s: chrdet:%d\n", __func__, chrdet);
	if (chrdet)
		do_charger_detect(info, chrdet);
	else {
		hw_bc11_done(info);
		/* 8 = KERNEL_POWER_OFF_CHARGING_BOOT */
		/* 9 = LOW_POWER_OFF_CHARGING_BOOT */
		if (info->bootmode == 8 || info->bootmode == 9) {
			pr_info("%s: Unplug Charger/USB\n", __func__);

#ifndef CONFIG_TCPC_CLASS
			pr_info("%s: system_state=%d\n", __func__,
				system_state);
			if (system_state != SYSTEM_POWER_OFF)
				kernel_power_off();
#endif
		}
	}
}


@@ -580,7 +606,21 @@ irqreturn_t chrdet_int_handler(int irq, void *data)
		PMIC_RGS_CHRDET_ADDR,
		PMIC_RGS_CHRDET_MASK,
		PMIC_RGS_CHRDET_SHIFT);
	if (!chrdet) {
		hw_bc11_done(info);
		/* 8 = KERNEL_POWER_OFF_CHARGING_BOOT */
		/* 9 = LOW_POWER_OFF_CHARGING_BOOT */
		if (info->bootmode == 8 || info->bootmode == 9) {
			pr_info("%s: Unplug Charger/USB\n", __func__);

#ifndef CONFIG_TCPC_CLASS
			pr_info("%s: system_state=%d\n", __func__,
				system_state);
			if (system_state != SYSTEM_POWER_OFF)
				kernel_power_off();
#endif
		}
	}
	pr_notice("%s: chrdet:%d\n", __func__, chrdet);
	do_charger_detect(info, chrdet);

@@ -716,6 +756,30 @@ static char *mt6357_charger_supplied_to[] = {
	"mtk-master-charger"
};

static int check_boot_mode(struct mtk_charger_type *info, struct device *dev)
{
	struct device_node *boot_node = NULL;
	struct tag_bootmode *tag = NULL;

	boot_node = of_parse_phandle(dev->of_node, "bootmode", 0);
	if (!boot_node)
		pr_notice("%s: failed to get boot mode phandle\n", __func__);
	else {
		tag = (struct tag_bootmode *)of_get_property(boot_node,
							"atag,boot", NULL);
		if (!tag)
			pr_notice("%s: failed to get atag,boot\n", __func__);
		else {
			pr_notice("%s: size:0x%x tag:0x%x bootmode:0x%x boottype:0x%x\n",
				__func__, tag->size, tag->tag,
				tag->bootmode, tag->boottype);
			info->bootmode = tag->bootmode;
			info->boottype = tag->boottype;
		}
	}
	return 0;
}

static int mt6357_charger_type_probe(struct platform_device *pdev)
{
	struct mtk_charger_type *info;
@@ -747,6 +811,8 @@ static int mt6357_charger_type_probe(struct platform_device *pdev)
	info->pdev = pdev;
	mutex_init(&info->ops_lock);

	check_boot_mode(info, &pdev->dev);

	info->psy_desc.name = "mtk_charger_type";
	info->psy_desc.type = POWER_SUPPLY_TYPE_UNKNOWN;
	info->psy_desc.properties = chr_type_properties;
+41 −43
Original line number Diff line number Diff line
@@ -196,6 +196,41 @@ static bool select_charging_current_limit(struct mtk_charger *info,
		is_basic = true;
	}

	if (support_fast_charging(info))
		is_basic = false;
	else {
		is_basic = true;
		/* AICL */
		charger_dev_run_aicl(info->chg1_dev,
			&pdata->input_current_limit_by_aicl);
		if (info->enable_dynamic_mivr) {
			if (pdata->input_current_limit_by_aicl >
				info->data.max_dmivr_charger_current)
				pdata->input_current_limit_by_aicl =
					info->data.max_dmivr_charger_current;
		}
		if (is_typec_adapter(info)) {
			if (adapter_dev_get_property(info->pd_adapter, TYPEC_RP_LEVEL)
				== 3000) {
				pdata->input_current_limit = 3000000;
				pdata->charging_current_limit = 3000000;
			} else if (adapter_dev_get_property(info->pd_adapter,
				TYPEC_RP_LEVEL) == 1500) {
				pdata->input_current_limit = 1500000;
				pdata->charging_current_limit = 2000000;
			} else {
				chr_err("type-C: inquire rp error\n");
				pdata->input_current_limit = 500000;
				pdata->charging_current_limit = 500000;
			}

			chr_err("type-C:%d current:%d\n",
				info->pd_type,
				adapter_dev_get_property(info->pd_adapter,
					TYPEC_RP_LEVEL));
		}
	}

	if (info->enable_sw_jeita) {
		if (IS_ENABLED(CONFIG_USBIF_COMPLIANCE)
			&& info->chr_type == POWER_SUPPLY_TYPE_USB)
@@ -252,47 +287,6 @@ static bool select_charging_current_limit(struct mtk_charger *info,
	} else
		info->setting.input_current_limit2 = -1;

	if (info->setting.input_current_limit1 == -1 &&
		info->setting.input_current_limit2 == -1 &&
		info->setting.charging_current_limit1 == -1 &&
		info->setting.charging_current_limit2 == -1)
		info->enable_hv_charging = true;

	if (support_fast_charging(info))
		is_basic = false;
	else {
		is_basic = true;
		/* AICL */
		charger_dev_run_aicl(info->chg1_dev,
			&pdata->input_current_limit_by_aicl);
		if (info->enable_dynamic_mivr) {
			if (pdata->input_current_limit_by_aicl >
				info->data.max_dmivr_charger_current)
				pdata->input_current_limit_by_aicl =
					info->data.max_dmivr_charger_current;
		}
		if (is_typec_adapter(info)) {
			if (adapter_dev_get_property(info->pd_adapter, TYPEC_RP_LEVEL)
				== 3000) {
				pdata->input_current_limit = 3000000;
				pdata->charging_current_limit = 3000000;
			} else if (adapter_dev_get_property(info->pd_adapter,
				TYPEC_RP_LEVEL) == 1500) {
				pdata->input_current_limit = 1500000;
				pdata->charging_current_limit = 2000000;
			} else {
				chr_err("type-C: inquire rp error\n");
				pdata->input_current_limit = 500000;
				pdata->charging_current_limit = 500000;
			}

			chr_err("type-C:%d current:%d\n",
				info->pd_type,
				adapter_dev_get_property(info->pd_adapter,
					TYPEC_RP_LEVEL));
		}
	}

	if (is_basic == true && pdata->input_current_limit_by_aicl != -1) {
		if (pdata->input_current_limit_by_aicl <
		    pdata->input_current_limit)
@@ -371,7 +365,9 @@ static int do_algorithm(struct mtk_charger *info)
			if (alg == NULL)
				continue;

			if (!info->enable_hv_charging) {
			if (!info->enable_hv_charging ||
			    pdata->charging_current_limit == 0 ||
			    pdata->input_current_limit == 0) {
				chg_alg_get_prop(alg, ALG_MAX_VBUS, &val);
				if (val > 5000)
					chg_alg_stop_algo(alg);
@@ -418,7 +414,9 @@ static int do_algorithm(struct mtk_charger *info)
			}
		}
	} else {
		if (info->enable_hv_charging != true) {
		if (info->enable_hv_charging != true ||
		    pdata->charging_current_limit == 0 ||
		    pdata->input_current_limit == 0) {
			for (i = 0; i < MAX_ALG_NO; i++) {
				alg = info->alg[i];
				if (alg == NULL)
+21 −2
Original line number Diff line number Diff line
@@ -493,8 +493,10 @@ static void check_battery_exist(struct mtk_charger *info)

#ifdef FIXME
	if (count >= 3) {
		if (boot_mode == META_BOOT || boot_mode == ADVMETA_BOOT ||
		    boot_mode == ATE_FACTORY_BOOT)
		/*1 = META_BOOT, 5 = ADVMETA_BOOT*/
		/*6 = ATE_FACTORY_BOOT */
		if (boot_mode == 1 || boot_mode == 5 ||
		    boot_mode == 6)
			chr_info("boot_mode = %d, bypass battery check\n",
				boot_mode);
		else {
@@ -1504,6 +1506,22 @@ static bool mtk_is_charger_on(struct mtk_charger *info)
	return true;
}

static void kpoc_power_off_check(struct mtk_charger *info)
{
	unsigned int boot_mode = info->bootmode;
	int vbus = 0;

	/* 8 = KERNEL_POWER_OFF_CHARGING_BOOT */
	/* 9 = LOW_POWER_OFF_CHARGING_BOOT */
	if (boot_mode == 8 || boot_mode == 9) {
		vbus = get_vbus(info);
		if (vbus >= 0 && vbus < 2500 && !mtk_is_charger_on(info)) {
			chr_err("Unplug Charger/USB in KPOC mode, vbus=%d, shutdown\n", vbus);
			kernel_power_off();
		}
	}
}

static char *dump_charger_type(int type)
{
	switch (type) {
@@ -1569,6 +1587,7 @@ static int charger_routine_thread(void *arg)
		check_battery_exist(info);
		check_dynamic_mivr(info);
		charger_check_status(info);
		kpoc_power_off_check(info);

		if (is_disable_charger(info) == false &&
			is_charger_on == true &&