Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3391199pxb; Mon, 17 Jan 2022 19:26:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzl48d361PvQf1z94qTVuGigEm51CtgECpPrTyB0D9Je0AEpeX+L0iEJ+Z54pd994gfejoD X-Received: by 2002:a17:902:7d8f:b0:14a:b712:bbfb with SMTP id a15-20020a1709027d8f00b0014ab712bbfbmr8814877plm.63.1642476382624; Mon, 17 Jan 2022 19:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476382; cv=none; d=google.com; s=arc-20160816; b=UfydeyqPPfa00g5h9Msc1Su7rTKEKSk787eJAG/utPeULZtKsDYwFabtLpcVp8bY9A CH9TIgBY77F58PT6YvTvf+/Xo9IFz3ZqJ3OW4n7ySo1IdOn8ooWuiWtMv9xkQ6uHlFZM is5gYqODftGzAyl+BCoynDksEQPNmajcUe8M00woUfZ4iqFSaG/WdGdvcQlAMbs5LAnj l2w9CBB+fbRFBjnPv/Lqh/EK410KvG7tM7BLr/FkeGOBvZBgxeHNs2MuXnwwFZJ7/Cdt 3pB5SCcd57BIm1QhqJ6coW1cllmqn3jaBwCBjT/piTRD3uCU1k/OYo+vO3w2ZmxgGM8B Z2wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nPGgHO0UjkqZsfAA59g735/49gifWJt3woMvpvxcHjc=; b=d2hmoTrYdAswp7S0QY9Vs1OUyuJ7zjWEySNStBw/RknXtdkgUubDjOflDBw8cS1Oui o1Xpb8UMh3BrbJh/k7oh7+lPLvAUnHljQdiUJwJPjaHGWs2YdgTxOOwrDRn4w9LOjFzu C0yy6vQ8ORwn7OBrbbUSA9b0eWaGj3DMrArIr2sY8paH1nHH6hF82tEknABf0cfOFD4x qo7ddmvM1SfTn6+N6ITKNB7+5Qrgu70jk89wOwowgTKqP7tqjFnunrYk1LoMf2na+oh9 nOIUQfUwbQT3eIaszaa6aZB0mk8v8L9k8ElXcI/sxUm8zl+M8HpAcDXXNGg2zk0ohDbE GMdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I8MOJEbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 15si15832414pfl.73.2022.01.17.19.26.11; Mon, 17 Jan 2022 19:26:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I8MOJEbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346378AbiARChk (ORCPT + 99 others); Mon, 17 Jan 2022 21:37:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345787AbiARCcC (ORCPT ); Mon, 17 Jan 2022 21:32:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C503BC06161C; Mon, 17 Jan 2022 18:31:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6264A61127; Tue, 18 Jan 2022 02:31:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F068C36AEF; Tue, 18 Jan 2022 02:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642473076; bh=tSU0MFjA+b37pAV0ewReHHPuyh8v5uxwe8mm5fDoSuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8MOJEbAncTp4DwSkbxRAEZ6+xmElvT1Rwl+AZX6qDY7cdChU6p7zEy/Niu7EHGhR tYRrpnZ1RnAwgWyFaJ34CD6Zka4xqTqqhEYB/qhsYDpQsx3fLYyVBXc3eNgCGjFLUB 2+tQ3e956D8dMlf4U+Bp1x9rPumVyGZmGIbK+kTL6Tj/K6ixcx6VKe6MDWJBe/DHah pRfRmwgtFX0LPO8ylNd8gyjc+1I+zmRpohczI07eABba4Ok16vV14uOItoL0Rk1kTE 7A8YUcuJ+6+FF9Z1plHWEK/Y85m0eQ8UhYnrhPF3N2tAs870pcK5Xq3fThUkZeUfGs ViHugEuh2y2uQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konrad Dybcio , Mark Brown , Sasha Levin , agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, linux-arm-msm@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 204/217] regulator: qcom_smd: Align probe function with rpmh-regulator Date: Mon, 17 Jan 2022 21:19:27 -0500 Message-Id: <20220118021940.1942199-204-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Konrad Dybcio [ Upstream commit 14e2976fbabdacb01335d7f91eeebbc89c67ddb1 ] The RPMh regulator driver is much newer and gets more attention, which in consequence makes it do a few things better. Update qcom_smd-regulator's probe function to mimic what rpmh-regulator does to address a couple of issues: - Probe defer now works correctly, before it used to, well, kinda just die.. This fixes reliable probing on (at least) PM8994, because Linux apparently cannot deal with supply map dependencies yet.. - Regulator data is now matched more sanely: regulator data is matched against each individual regulator node name and throwing an -EINVAL if data is missing, instead of just assuming everything is fine and iterating over all subsequent array members. - status = "disabled" will now work for disabling individual regulators in DT. Previously it didn't seem to do much if anything at all. Signed-off-by: Konrad Dybcio Link: https://lore.kernel.org/r/20211230023442.1123424-1-konrad.dybcio@somainline.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/qcom_smd-regulator.c | 100 +++++++++++++++++-------- 1 file changed, 70 insertions(+), 30 deletions(-) diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c index 8bac024dde8b4..9fc666107a06c 100644 --- a/drivers/regulator/qcom_smd-regulator.c +++ b/drivers/regulator/qcom_smd-regulator.c @@ -9,6 +9,7 @@ #include #include #include +#include #include struct qcom_rpm_reg { @@ -1239,52 +1240,91 @@ static const struct of_device_id rpm_of_match[] = { }; MODULE_DEVICE_TABLE(of, rpm_of_match); -static int rpm_reg_probe(struct platform_device *pdev) +/** + * rpm_regulator_init_vreg() - initialize all attributes of a qcom_smd-regulator + * @vreg: Pointer to the individual qcom_smd-regulator resource + * @dev: Pointer to the top level qcom_smd-regulator PMIC device + * @node: Pointer to the individual qcom_smd-regulator resource + * device node + * @rpm: Pointer to the rpm bus node + * @pmic_rpm_data: Pointer to a null-terminated array of qcom_smd-regulator + * resources defined for the top level PMIC device + * + * Return: 0 on success, errno on failure + */ +static int rpm_regulator_init_vreg(struct qcom_rpm_reg *vreg, struct device *dev, + struct device_node *node, struct qcom_smd_rpm *rpm, + const struct rpm_regulator_data *pmic_rpm_data) { - const struct rpm_regulator_data *reg; - const struct of_device_id *match; - struct regulator_config config = { }; + struct regulator_config config = {}; + const struct rpm_regulator_data *rpm_data; struct regulator_dev *rdev; + int ret; + + for (rpm_data = pmic_rpm_data; rpm_data->name; rpm_data++) + if (of_node_name_eq(node, rpm_data->name)) + break; + + if (!rpm_data->name) { + dev_err(dev, "Unknown regulator %pOFn\n", node); + return -EINVAL; + } + + vreg->dev = dev; + vreg->rpm = rpm; + vreg->type = rpm_data->type; + vreg->id = rpm_data->id; + + memcpy(&vreg->desc, rpm_data->desc, sizeof(vreg->desc)); + vreg->desc.name = rpm_data->name; + vreg->desc.supply_name = rpm_data->supply; + vreg->desc.owner = THIS_MODULE; + vreg->desc.type = REGULATOR_VOLTAGE; + vreg->desc.of_match = rpm_data->name; + + config.dev = dev; + config.of_node = node; + config.driver_data = vreg; + + rdev = devm_regulator_register(dev, &vreg->desc, &config); + if (IS_ERR(rdev)) { + ret = PTR_ERR(rdev); + dev_err(dev, "%pOFn: devm_regulator_register() failed, ret=%d\n", node, ret); + return ret; + } + + return 0; +} + +static int rpm_reg_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + const struct rpm_regulator_data *vreg_data; + struct device_node *node; struct qcom_rpm_reg *vreg; struct qcom_smd_rpm *rpm; + int ret; rpm = dev_get_drvdata(pdev->dev.parent); if (!rpm) { - dev_err(&pdev->dev, "unable to retrieve handle to rpm\n"); + dev_err(&pdev->dev, "Unable to retrieve handle to rpm\n"); return -ENODEV; } - match = of_match_device(rpm_of_match, &pdev->dev); - if (!match) { - dev_err(&pdev->dev, "failed to match device\n"); + vreg_data = of_device_get_match_data(dev); + if (!vreg_data) return -ENODEV; - } - for (reg = match->data; reg->name; reg++) { + for_each_available_child_of_node(dev->of_node, node) { vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); if (!vreg) return -ENOMEM; - vreg->dev = &pdev->dev; - vreg->type = reg->type; - vreg->id = reg->id; - vreg->rpm = rpm; - - memcpy(&vreg->desc, reg->desc, sizeof(vreg->desc)); - - vreg->desc.id = -1; - vreg->desc.owner = THIS_MODULE; - vreg->desc.type = REGULATOR_VOLTAGE; - vreg->desc.name = reg->name; - vreg->desc.supply_name = reg->supply; - vreg->desc.of_match = reg->name; - - config.dev = &pdev->dev; - config.driver_data = vreg; - rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config); - if (IS_ERR(rdev)) { - dev_err(&pdev->dev, "failed to register %s\n", reg->name); - return PTR_ERR(rdev); + ret = rpm_regulator_init_vreg(vreg, dev, node, rpm, vreg_data); + + if (ret < 0) { + of_node_put(node); + return ret; } } -- 2.34.1