From: Krzysztof Kozlowski <krzk@kernel.org>
To: Vignesh Viswanathan <vignesh.viswanathan@oss.qualcomm.com>
Cc: Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Praveenkumar I <praveenkumar.i@oss.qualcomm.com>,
Manikanta Mylavarapu <manikanta.mylavarapu@oss.qualcomm.com>
Subject: Re: [PATCH 2/2] soc: qcom: Add CDSP power management driver
Date: Wed, 20 May 2026 12:50:07 +0200 [thread overview]
Message-ID: <20260520-mottled-space-pony-ac82ac@quoll> (raw)
In-Reply-To: <20260520-cdsp-power-v1-2-85eb9501a1cd@oss.qualcomm.com>
On Wed, May 20, 2026 at 12:35:10AM +0530, Vignesh Viswanathan wrote:
> +/**
> + * cdsp_power_probe() - Probe the CDSP power management driver
> + * @pdev: Platform device
> + *
> + * Acquires the PMIC regulator consumer handles, registers the virtual
> + * cdsp-vdd-cx (and optionally cdsp-vdd-mx) regulator providers, maps the
> + * MPM and RSCC register regions, and registers the DCVS and LPM interrupt
> + * handlers.
> + *
> + * Return: 0 on success, negative error code on failure
> + */
> +static int cdsp_power_probe(struct platform_device *pdev)
> +{
> + struct regulator_config virt_cfg = {};
> + struct cdsp_power_driver *drv;
> + struct regulator_dev *rdev;
> + void __iomem *rscc_base;
> + void __iomem *mpm_base;
> + size_t smem_size;
> + u32 smem_id;
> + int ret;
> +
> + /* Allocate driver context */
> + drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
> + if (!drv)
> + return -ENOMEM;
> +
> + drv->dev = &pdev->dev;
> + mutex_init(&drv->lock);
> + atomic_set(&drv->power_state, CDSP_POWER_ON);
> +
> + /* Get SMEM item ID from device tree */
> + ret = of_property_read_u32(pdev->dev.of_node, "qcom,smem-item", &smem_id);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to get SMEM item ID\n");
> +
> + /* Create SMEM entry for DCVS */
> + ret = qcom_smem_alloc(CDSP_SMEM_NSP_HOST_ID, smem_id, CDSP_SMEM_SIZE);
> + if (ret && ret != -EEXIST)
> + return dev_err_probe(&pdev->dev, ret, "Failed to allocate SMEM\n");
> +
> + /* Get SMEM pointer and validate size */
> + drv->smem = qcom_smem_get(CDSP_SMEM_NSP_HOST_ID, smem_id, &smem_size);
> + if (IS_ERR(drv->smem))
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->smem),
> + "Failed to get SMEM\n");
> +
> + if (smem_size < CDSP_SMEM_SIZE)
> + return dev_err_probe(&pdev->dev, -EINVAL,
> + "SMEM region too small: got %zu, expected %u\n",
> + smem_size, CDSP_SMEM_SIZE);
> +
> + /*
> + * Initialise the SMEM channel header.
> + * Zero the entire region first so all padding and reserved fields
> + * are clean, then fill in the fixed protocol fields.
> + * apss_state is set to 1 last (after wmb) so NSP Q6 only sees a
> + * fully-populated header once APSS is ready.
> + */
> + memset(drv->smem, 0, sizeof(*drv->smem));
> + drv->smem->hdr.magic = CDSP_SMEM_MAGIC;
> + drv->smem->hdr.version = CDSP_SMEM_VERSION;
> + drv->smem->hdr.request_offset = CDSP_SMEM_REQUEST_OFFSET;
> + drv->smem->hdr.request_size = CDSP_SMEM_REQUEST_SIZE;
> + drv->smem->hdr.response_offset = CDSP_SMEM_RESPONSE_OFFSET;
> + drv->smem->hdr.response_size = CDSP_SMEM_RESPONSE_SIZE;
> + /* Signal APSS readiness to NSP Q6 */
> + WRITE_ONCE(drv->smem->hdr.apss_state, 1);
> + /* Ensure SMEM header is fully written before NSP Q6 reads it */
> + wmb();
> +
> + /*
> + * Get voltage regulator consumer handles.
> + * These are the actual NSP_CX and NSP_MX voltage rails.
> + * The virtual regulator ops pass through to these handles.
> + */
> + drv->vdd_cx = devm_regulator_get(&pdev->dev, "vdd-cx");
> + if (IS_ERR(drv->vdd_cx))
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->vdd_cx),
> + "Failed to get vdd-cx regulator\n");
> +
> + drv->vdd_mx = devm_regulator_get_optional(&pdev->dev, "vdd-mx");
> + if (IS_ERR(drv->vdd_mx)) {
> + if (PTR_ERR(drv->vdd_mx) != -ENODEV)
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->vdd_mx),
> + "Failed to get vdd-mx regulator\n");
> + drv->vdd_mx = NULL;
> + dev_dbg(&pdev->dev, "No vdd-mx regulator, MX rail absent on this board\n");
> + }
> +
> + /*
> + * Register virtual regulator provider.
> + *
> + * Expose vdd-cx and vdd-mx virtual regulators so that PAS remoteproc
> + * can consume them via cx-supply / mx-supply DTS properties.
> + * The enable/disable ops pass through to vdd_cx / vdd_mx above,
> + * making CDSP the sole hardware power manager for the NSP subsystem.
> + */
> + virt_cfg.dev = &pdev->dev;
> + virt_cfg.driver_data = drv;
> + virt_cfg.of_node = pdev->dev.of_node;
> +
> + INIT_WORK(&drv->dcvs_work, cdsp_dcvs_work_fn);
> + INIT_WORK(&drv->lpm_work, cdsp_lpm_work_fn);
> +
> + drv->lpm_wq = alloc_ordered_workqueue("cdsp_lpm_wq", 0);
> + if (!drv->lpm_wq) {
> + mbox_free_channel(drv->dcvs_mbox_chan);
> + return dev_err_probe(&pdev->dev,
> + -ENOMEM,
> + "failed to allocate cdsp lpm workqueue\n");
> + }
> +
> + rdev = devm_regulator_register(&pdev->dev,
> + &cdsp_virt_reg_descs[CDSP_VIRT_NSP_CX],
> + &virt_cfg);
> + if (IS_ERR(rdev))
> + return dev_err_probe(&pdev->dev, PTR_ERR(rdev),
> + "Failed to register cdsp-vdd-cx virtual regulator\n");
> +
> + if (drv->vdd_mx) {
> + rdev = devm_regulator_register(&pdev->dev,
> + &cdsp_virt_reg_descs[CDSP_VIRT_NSP_MX],
> + &virt_cfg);
> + if (IS_ERR(rdev))
> + return dev_err_probe(&pdev->dev, PTR_ERR(rdev),
> + "Failed to register cdsp-vdd-mx virtual regulator\n");
> + }
> +
> + /* Register DCVS interrupt */
> + drv->dcvs_irq = platform_get_irq_byname(pdev, "dcvs");
> + if (drv->dcvs_irq < 0)
> + return dev_err_probe(&pdev->dev, drv->dcvs_irq,
> + "Failed to get DCVS IRQ\n");
> +
> + ret = devm_request_threaded_irq(&pdev->dev, drv->dcvs_irq,
> + NULL, cdsp_dcvs_irq_handler,
> + IRQF_ONESHOT, "cdsp-dcvs", drv);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to request DCVS IRQ\n");
> +
> + /* Setup MPM for LPM */
> + mpm_base = devm_platform_ioremap_resource_byname(pdev, "mpm");
> + if (IS_ERR(mpm_base))
> + return dev_err_probe(&pdev->dev, PTR_ERR(mpm_base),
> + "Failed to map MPM registers\n");
> +
> + drv->mpm_regmap = devm_regmap_init_mmio(&pdev->dev, mpm_base, &cdsp_regmap_config);
> + if (IS_ERR(drv->mpm_regmap))
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->mpm_regmap),
> + "Failed to init MPM regmap\n");
> +
> + /* Setup RSCC for power mode detection */
> + rscc_base = devm_platform_ioremap_resource_byname(pdev, "rscc");
> + if (IS_ERR(rscc_base))
> + return dev_err_probe(&pdev->dev, PTR_ERR(rscc_base),
> + "Failed to map RSCC registers\n");
> +
> + drv->rscc_regmap = devm_regmap_init_mmio(&pdev->dev, rscc_base, &cdsp_rscc_regmap_config);
> + if (IS_ERR(drv->rscc_regmap))
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->rscc_regmap),
> + "Failed to init RSCC regmap\n");
> +
> + drv->lpm_irq = platform_get_irq_byname(pdev, "lpm");
> + if (drv->lpm_irq < 0)
> + return dev_err_probe(&pdev->dev, drv->lpm_irq,
> + "Failed to get LPM IRQ\n");
> +
> + ret = devm_request_threaded_irq(&pdev->dev, drv->lpm_irq,
> + NULL, cdsp_lpm_irq_handler,
> + IRQF_ONESHOT, "cdsp-lpm", drv);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to request LPM IRQ\n");
> +
> + /* Setup mbox for DCVS response */
> + drv->dcvs_mbox_client.dev = &pdev->dev;
> + drv->dcvs_mbox_client.knows_txdone = true;
> + drv->dcvs_mbox_chan = mbox_request_channel(&drv->dcvs_mbox_client, 0);
> + if (IS_ERR(drv->dcvs_mbox_chan))
> + return dev_err_probe(&pdev->dev, PTR_ERR(drv->dcvs_mbox_chan),
> + "Failed to get dcvs mbox channel\n");
> +
> + platform_set_drvdata(pdev, drv);
> +
> + dev_dbg(&pdev->dev, "CDSP power driver initialized\n");
Drop. All my comments from your regulator driver apply.
> +
> + return 0;
> +}
Best regards,
Krzysztof
next prev parent reply other threads:[~2026-05-20 10:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 19:05 [PATCH 0/2] Add CDSP Power Manangement Driver Vignesh Viswanathan
2026-05-19 19:05 ` [PATCH 1/2] dt-bindings: soc: qcom: Document CDSP Power Management Vignesh Viswanathan
2026-05-19 19:17 ` sashiko-bot
2026-05-20 9:59 ` Konrad Dybcio
2026-05-26 7:38 ` Vignesh Viswanathan
2026-06-16 12:27 ` Konrad Dybcio
2026-05-20 10:43 ` Krzysztof Kozlowski
2026-05-20 10:46 ` Krzysztof Kozlowski
2026-05-26 7:46 ` Vignesh Viswanathan
2026-05-21 23:29 ` Bjorn Andersson
2026-05-26 7:57 ` Vignesh Viswanathan
2026-06-17 4:39 ` Krzysztof Kozlowski
2026-05-19 19:05 ` [PATCH 2/2] soc: qcom: Add CDSP power management driver Vignesh Viswanathan
2026-05-19 19:43 ` sashiko-bot
2026-05-20 10:50 ` Krzysztof Kozlowski [this message]
2026-05-26 7:49 ` Vignesh Viswanathan
2026-05-22 2:49 ` Bjorn Andersson
2026-05-26 8:00 ` Vignesh Viswanathan
2026-05-20 10:44 ` [PATCH 0/2] Add CDSP Power Manangement Driver Krzysztof Kozlowski
2026-05-26 7:49 ` Vignesh Viswanathan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260520-mottled-space-pony-ac82ac@quoll \
--to=krzk@kernel.org \
--cc=andersson@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manikanta.mylavarapu@oss.qualcomm.com \
--cc=praveenkumar.i@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=vignesh.viswanathan@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox