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

Commit 35b37218 authored by Guru Das Srinagesh's avatar Guru Das Srinagesh
Browse files

pwm: pwm-qti-lpg: Handle nvmem device lookup failure properly



Due to commit 95b65195 ("nvmem: core: Always reference the device
returned by nvmem_device_get()") failures in nvmem device lookup return
-EPROBE_DEFER instead of NULL. This causes probe failure of the
pwm-qti-lpg driver when pwm devices are defined in the device tree
without nvmem nodes, which is undesirable.

Fix this by attempting to get the nvmem device only if it is present.

Change-Id: Ifa136bb9b78e4b9e0894854768e9a6cc060d5261
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent f22a034b
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt) "%s: " fmt, __func__
@@ -1277,22 +1277,16 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip)
	if (!chip->lut)
		return -ENOMEM;

	if (of_find_property(chip->dev->of_node, "nvmem", NULL)) {
		chip->sdam_nvmem = devm_nvmem_device_get(chip->dev, "ppg_sdam");
		if (IS_ERR_OR_NULL(chip->sdam_nvmem)) {
		if (PTR_ERR(chip->sdam_nvmem) == -EPROBE_DEFER)
			return -EPROBE_DEFER;

		addr = of_get_address(chip->dev->of_node, 1, NULL, NULL);
		if (!addr) {
			pr_debug("NO LUT address assigned\n");
			devm_kfree(chip->dev, chip->lut);
			chip->lut = NULL;
			return 0;
			rc = PTR_ERR(chip->sdam_nvmem);
			if (rc != -EPROBE_DEFER)
				dev_err(chip->dev, "Read nvmem device failed, rc=%d\n",
					rc);
			return rc;
		}

		chip->lut->reg_base = be32_to_cpu(*addr);
		max_count = LPG_LUT_COUNT_MAX;
	} else {
		chip->use_sdam = true;
		chip->pbs_dev_node = of_parse_phandle(chip->dev->of_node,
				"qcom,pbs-client", 0);
@@ -1311,6 +1305,17 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip)
		}

		max_count = SDAM_LUT_COUNT_MAX;
	} else {
		addr = of_get_address(chip->dev->of_node, 1, NULL, NULL);
		if (!addr) {
			pr_debug("NO LUT address assigned\n");
			devm_kfree(chip->dev, chip->lut);
			chip->lut = NULL;
			return 0;
		}

		chip->lut->reg_base = be32_to_cpu(*addr);
		max_count = LPG_LUT_COUNT_MAX;
	}

	chip->lut->chip = chip;