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

Commit 9ee43ead authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Guru Das Srinagesh
Browse files

power: smb1390-psy: add support to expose chip version



Add support to read chip version from rev-id peripheral and
expose it to userspace via power_supply property.

Change-Id: Ic522ec7dd7e6849f9f599cfba07e22c59878ce84
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent 3b313491
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/qpnp/qpnp-revid.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
@@ -130,6 +131,7 @@ struct smb1390 {
	struct notifier_block	nb;
	struct wakeup_source	*cp_ws;
	struct dentry		*dfs_root;
	struct pmic_revid_data	*pmic_rev_id;

	/* work structs */
	struct work_struct	status_change_work;
@@ -687,6 +689,7 @@ static enum power_supply_property smb1390_charge_pump_props[] = {
	POWER_SUPPLY_PROP_CP_TOGGLE_SWITCHER,
	POWER_SUPPLY_PROP_CP_IRQ_STATUS,
	POWER_SUPPLY_PROP_CP_ILIM,
	POWER_SUPPLY_PROP_CHIP_VERSION,
};

static int smb1390_get_prop(struct power_supply *psy,
@@ -758,6 +761,9 @@ static int smb1390_get_prop(struct power_supply *psy,
			val->intval = ((status & CFG_ILIM_MASK) * 100000)
					+ 500000;
		break;
	case POWER_SUPPLY_PROP_CHIP_VERSION:
		val->intval = chip->pmic_rev_id->rev4;
		break;
	default:
		smb1390_dbg(chip, PR_MISC, "charge pump power supply get prop %d not supported\n",
			prop);
@@ -1023,8 +1029,28 @@ static void smb1390_create_debugfs(struct smb1390 *chip)
static int smb1390_probe(struct platform_device *pdev)
{
	struct smb1390 *chip;
	struct device_node *revid_dev_node;
	struct pmic_revid_data *pmic_rev_id;
	int rc;

	revid_dev_node = of_parse_phandle(pdev->dev.of_node,
					  "qcom,pmic-revid", 0);
	if (!revid_dev_node) {
		pr_err("Missing qcom,pmic-revid property\n");
		return -EINVAL;
	}

	pmic_rev_id = get_revid_data(revid_dev_node);
	of_node_put(revid_dev_node);
	if (IS_ERR_OR_NULL(pmic_rev_id)) {
		/*
		 * the revid peripheral must be registered, any failure
		 * here only indicates that the rev-id module has not
		 * probed yet.
		 */
		return -EPROBE_DEFER;
	}

	chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
		return -ENOMEM;
@@ -1033,6 +1059,7 @@ static int smb1390_probe(struct platform_device *pdev)
	spin_lock_init(&chip->status_change_lock);
	mutex_init(&chip->die_chan_lock);
	chip->die_temp = -ENODATA;
	chip->pmic_rev_id = pmic_rev_id;
	platform_set_drvdata(pdev, chip);

	chip->regmap = dev_get_regmap(chip->dev->parent, NULL);
@@ -1087,8 +1114,8 @@ static int smb1390_probe(struct platform_device *pdev)

	smb1390_create_debugfs(chip);

	pr_debug("smb1390 probed successfully\n");

	pr_debug("smb1390 probed successfully chip_version=%d\n",
			chip->pmic_rev_id->rev4);
	return 0;

out_notifier: