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

Commit ce919330 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: qg: Expose cc soc value through power supply property"

parents 041a4fc2 a9bfac93
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2018 The Linux Foundation. All rights reserved.
 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt)	"QG-K: %s: " fmt, __func__
@@ -1807,6 +1807,9 @@ static int qg_psy_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_SOH:
		pval->intval = chip->soh;
		break;
	case POWER_SUPPLY_PROP_CC_SOC:
		rc = qg_get_cc_soc(chip, &pval->intval);
		break;
	default:
		pr_debug("Unsupported property %d\n", psp);
		break;
@@ -1857,6 +1860,7 @@ static enum power_supply_property qg_psy_props[] = {
	POWER_SUPPLY_PROP_ESR_ACTUAL,
	POWER_SUPPLY_PROP_ESR_NOMINAL,
	POWER_SUPPLY_PROP_SOH,
	POWER_SUPPLY_PROP_CC_SOC,
};

static const struct power_supply_desc qg_psy_desc = {
+2 −2
Original line number Diff line number Diff line
@@ -438,8 +438,8 @@ static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node)
	chg->sw_jeita_enabled = of_property_read_bool(node,
				"qcom,sw-jeita-enable");

	chg->pd_not_supported = of_property_read_bool(node,
				"qcom,usb-pd-disable");
	chg->pd_not_supported = chg->pd_not_supported ||
			of_property_read_bool(node, "qcom,usb-pd-disable");

	chg->lpd_disabled = of_property_read_bool(node, "qcom,lpd-disable");

+71 −17
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

#define pr_fmt(fmt) "SMB1390: %s: " fmt, __func__

#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/module.h>
@@ -84,6 +85,16 @@
#define SRC_VOTER		"SRC_VOTER"
#define SWITCHER_TOGGLE_VOTER	"SWITCHER_TOGGLE_VOTER"

#define smb1390_dbg(chip, reason, fmt, ...)				\
	do {								\
		if (chip->debug_mask & (reason))			\
			pr_info("SMB1390: %s: " fmt, __func__,		\
				##__VA_ARGS__);				\
		else							\
			pr_debug("SMB1390: %s: " fmt, __func__,		\
				##__VA_ARGS__);				\
	} while (0)

enum {
	SWITCHER_OFF_WINDOW_IRQ = 0,
	SWITCHER_OFF_FAULT_IRQ,
@@ -101,6 +112,14 @@ enum {
	SMB_PIN_EN,
};

enum print_reason {
	PR_INTERRUPT		= BIT(0),
	PR_REGISTER		= BIT(1),
	PR_INFO			= BIT(2),
	PR_EXT_DEPENDENCY	= BIT(3),
	PR_MISC			= BIT(4),
};

struct smb1390_iio {
	struct iio_channel	*die_temp_chan;
};
@@ -110,6 +129,7 @@ struct smb1390 {
	struct regmap		*regmap;
	struct notifier_block	nb;
	struct wakeup_source	*cp_ws;
	struct dentry		*dfs_root;

	/* work structs */
	struct work_struct	status_change_work;
@@ -140,6 +160,7 @@ struct smb1390 {
	bool			switcher_enabled;
	int			die_temp;
	bool			suspended;
	u32			debug_mask;
};

struct smb_irq {
@@ -166,7 +187,8 @@ static int smb1390_masked_write(struct smb1390 *chip, int reg, int mask,
{
	int rc;

	pr_debug("Writing 0x%02x to 0x%04x with mask 0x%02x\n", val, reg, mask);
	smb1390_dbg(chip, PR_REGISTER, "Writing 0x%02x to 0x%04x with mask 0x%02x\n",
			val, reg, mask);
	rc = regmap_update_bits(chip->regmap, reg, mask, val);
	if (rc < 0)
		pr_err("Couldn't write 0x%02x to 0x%04x with mask 0x%02x\n",
@@ -180,7 +202,7 @@ static bool is_psy_voter_available(struct smb1390 *chip)
	if (!chip->batt_psy) {
		chip->batt_psy = power_supply_get_by_name("battery");
		if (!chip->batt_psy) {
			pr_debug("Couldn't find battery psy\n");
			smb1390_dbg(chip, PR_EXT_DEPENDENCY, "Couldn't find battery psy\n");
			return false;
		}
	}
@@ -188,7 +210,7 @@ static bool is_psy_voter_available(struct smb1390 *chip)
	if (!chip->usb_psy) {
		chip->usb_psy = power_supply_get_by_name("usb");
		if (!chip->usb_psy) {
			pr_debug("Couldn't find usb psy\n");
			smb1390_dbg(chip, PR_EXT_DEPENDENCY, "Couldn't find usb psy\n");
			return false;
		}
	}
@@ -196,7 +218,7 @@ static bool is_psy_voter_available(struct smb1390 *chip)
	if (!chip->dc_psy) {
		chip->dc_psy = power_supply_get_by_name("dc");
		if (!chip->dc_psy) {
			pr_debug("Couldn't find dc psy\n");
			smb1390_dbg(chip, PR_EXT_DEPENDENCY, "Couldn't find dc psy\n");
			return false;
		}
	}
@@ -204,7 +226,7 @@ static bool is_psy_voter_available(struct smb1390 *chip)
	if (!chip->fcc_votable) {
		chip->fcc_votable = find_votable("FCC");
		if (!chip->fcc_votable) {
			pr_debug("Couldn't find FCC votable\n");
			smb1390_dbg(chip, PR_EXT_DEPENDENCY, "Couldn't find FCC votable\n");
			return false;
		}
	}
@@ -212,13 +234,13 @@ static bool is_psy_voter_available(struct smb1390 *chip)
	if (!chip->fv_votable) {
		chip->fv_votable = find_votable("FV");
		if (!chip->fv_votable) {
			pr_debug("Couldn't find FV votable\n");
			smb1390_dbg(chip, PR_EXT_DEPENDENCY, "Couldn't find FV votable\n");
			return false;
		}
	}

	if (!chip->disable_votable) {
		pr_debug("Couldn't find CP DISABLE votable\n");
		smb1390_dbg(chip, PR_MISC, "Couldn't find CP DISABLE votable\n");
		return false;
	}

@@ -254,7 +276,8 @@ static int smb1390_get_cp_en_status(struct smb1390 *chip, int id, bool *enable)
		*enable = !!(status & EN_PIN_OUT2_BIT);
		break;
	default:
		pr_debug("cp_en status %d is not supported\n", id);
		smb1390_dbg(chip, PR_MISC, "cp_en status %d is not supported\n",
				id);
		rc = -EINVAL;
		break;
	}
@@ -270,7 +293,8 @@ static irqreturn_t default_irq_handler(int irq, void *data)

	for (i = 0; i < NUM_IRQS; ++i) {
		if (irq == chip->irqs[i]) {
			pr_debug("%s IRQ triggered\n", smb_irqs[i].name);
			smb1390_dbg(chip, PR_INTERRUPT, "%s IRQ triggered\n",
				smb_irqs[i].name);
			chip->irq_status |= 1 << i;
		}
	}
@@ -471,10 +495,11 @@ static int smb1390_ilim_vote_cb(struct votable *votable, void *data,

	/* ILIM less than 1A is not accurate; disable charging */
	if (ilim_uA < 1000000) {
		pr_debug("ILIM %duA is too low to allow charging\n", ilim_uA);
		smb1390_dbg(chip, PR_INFO, "ILIM %duA is too low to allow charging\n",
			ilim_uA);
		vote(chip->disable_votable, ILIM_VOTER, true, 0);
	} else {
		pr_debug("ILIM set to %duA\n", ilim_uA);
		smb1390_dbg(chip, PR_INFO, "ILIM set to %duA\n", ilim_uA);
		vote(chip->disable_votable, ILIM_VOTER, false, 0);
	}

@@ -621,7 +646,7 @@ static void smb1390_taper_work(struct work_struct *work)

		if (get_effective_result(chip->fv_votable) >
						chip->taper_entry_fv) {
			pr_debug("Float voltage increased. Exiting taper\n");
			smb1390_dbg(chip, PR_INFO, "Float voltage increased. Exiting taper\n");
			goto out;
		} else {
			chip->taper_entry_fv =
@@ -631,7 +656,8 @@ static void smb1390_taper_work(struct work_struct *work)
		if (pval.intval == POWER_SUPPLY_CHARGE_TYPE_TAPER) {
			fcc_uA = get_effective_result(chip->fcc_votable)
								- 100000;
			pr_debug("taper work reducing FCC to %duA\n", fcc_uA);
			smb1390_dbg(chip, PR_INFO, "taper work reducing FCC to %duA\n",
				fcc_uA);
			vote(chip->fcc_votable, CP_VOTER, true, fcc_uA);

			if (fcc_uA < 2000000) {
@@ -640,13 +666,13 @@ static void smb1390_taper_work(struct work_struct *work)
				goto out;
			}
		} else {
			pr_debug("In fast charging. Wait for next taper\n");
			smb1390_dbg(chip, PR_INFO, "In fast charging. Wait for next taper\n");
		}

		msleep(500);
	}
out:
	pr_debug("taper work exit\n");
	smb1390_dbg(chip, PR_INFO, "taper work exit\n");
	vote(chip->fcc_votable, CP_VOTER, false, 0);
	chip->taper_work_running = false;
}
@@ -733,7 +759,7 @@ static int smb1390_get_prop(struct power_supply *psy,
					+ 500000;
		break;
	default:
		pr_debug("charge pump power supply get prop %d not supported\n",
		smb1390_dbg(chip, PR_MISC, "charge pump power supply get prop %d not supported\n",
			prop);
		return -EINVAL;
	}
@@ -760,7 +786,7 @@ static int smb1390_set_prop(struct power_supply *psy,
		chip->irq_status = val->intval;
		break;
	default:
		pr_debug("charge pump power supply set prop %d not supported\n",
		smb1390_dbg(chip, PR_MISC, "charge pump power supply set prop %d not supported\n",
			prop);
		return -EINVAL;
	}
@@ -969,6 +995,31 @@ static int smb1390_request_interrupts(struct smb1390 *chip)
	return rc;
}

#ifdef CONFIG_DEBUG_FS
static void smb1390_create_debugfs(struct smb1390 *chip)
{
	struct dentry *entry;

	chip->dfs_root = debugfs_create_dir("smb1390_charger_psy", NULL);
	if (IS_ERR_OR_NULL(chip->dfs_root)) {
		pr_err("Failed to create debugfs directory, rc=%ld\n",
					(long)chip->dfs_root);
		return;
	}

	entry = debugfs_create_u32("debug_mask", 0600, chip->dfs_root,
			&chip->debug_mask);
	if (IS_ERR_OR_NULL(entry)) {
		pr_err("Failed to create debug_mask, rc=%ld\n", (long)entry);
		debugfs_remove_recursive(chip->dfs_root);
	}
}
#else
static void smb1390_create_debugfs(struct smb1390 *chip)
{
}
#endif

static int smb1390_probe(struct platform_device *pdev)
{
	struct smb1390 *chip;
@@ -1034,7 +1085,10 @@ static int smb1390_probe(struct platform_device *pdev)
		goto out_notifier;
	}

	smb1390_create_debugfs(chip);

	pr_debug("smb1390 probed successfully\n");

	return 0;

out_notifier:
+19 −4
Original line number Diff line number Diff line
@@ -904,7 +904,7 @@ void smblib_hvdcp_detect_enable(struct smb_charger *chg, bool enable)
	int rc;
	u8 mask;

	if (chg->hvdcp_disable)
	if (chg->hvdcp_disable || chg->pd_not_supported)
		return;

	mask = HVDCP_AUTH_ALG_EN_CFG_BIT | HVDCP_EN_BIT;
@@ -3376,7 +3376,7 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
				    union power_supply_propval *val)
{
	union power_supply_propval pval = {0, };
	int rc = 0;
	int rc = 0, buck_scale = 1, boost_scale = 1;

	if (chg->iio.usbin_i_chan) {
		rc = iio_read_channel_processed(chg->iio.usbin_i_chan,
@@ -3389,10 +3389,24 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
		/*
		 * For PM8150B, scaling factor = reciprocal of
		 * 0.2V/A in Buck mode, 0.4V/A in Boost mode.
		 * For PMI632, scaling factor = reciprocal of
		 * 0.4V/A in Buck mode, 0.8V/A in Boost mode.
		 */
		switch (chg->smb_version) {
		case PMI632_SUBTYPE:
			buck_scale = 40;
			boost_scale = 80;
			break;
		default:
			buck_scale = 20;
			boost_scale = 40;
			break;
		}

		if (chg->otg_present || smblib_get_prop_dfp_mode(chg) !=
				POWER_SUPPLY_TYPEC_NONE) {
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100, 40);
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100,
								boost_scale);
			return rc;
		}

@@ -3407,7 +3421,8 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
		if (!pval.intval)
			val->intval = 0;
		else
			val->intval *= 5;
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100,
								buck_scale);
	} else {
		val->intval = 0;
		rc = -ENODATA;