From: Konrad Dybcio <konrad.dybcio@linaro.org>
To: Anjelique Melendez <quic_amelende@quicinc.com>,
pavel@ucw.cz, lee@kernel.org, thierry.reding@gmail.com,
robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, agross@kernel.org, andersson@kernel.org
Cc: luca.weiss@fairphone.com, u.kleine-koenig@pengutronix.de,
quic_subbaram@quicinc.com, linux-leds@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v2 3/7] soc: qcom: add QCOM PBS driver
Date: Wed, 26 Jul 2023 17:36:08 +0200 [thread overview]
Message-ID: <de3b4739-5446-c1ab-571f-a36c4aff5e0f@linaro.org> (raw)
In-Reply-To: <20230725193423.25047-4-quic_amelende@quicinc.com>
On 25.07.2023 21:34, Anjelique Melendez wrote:
> Add the Qualcomm PBS (Programmable Boot Sequencer) driver. The QCOM PBS
> driver supports configuring software PBS trigger events through PBS RAM
> on Qualcomm Technologies, Inc (QTI) PMICs.
>
> Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
> ---
[...]
> +
> + u32 base;
> +};
> +
> +static int qcom_pbs_read(struct pbs_dev *pbs, u32 address, u8 *val)
> +{
> + int ret;
> +
> + address += pbs->base;
Any reason not to just keep the base address in struct pbs_dev and use
normal regmap r/w helpers?
[...]
> +
> +static int qcom_pbs_wait_for_ack(struct pbs_dev *pbs, u8 bit_pos)
> +{
> + u16 retries = 2000, delay = 1000;
> + int ret;
> + u8 val;
> +
> + while (retries--) {
> + ret = qcom_pbs_read(pbs, PBS_CLIENT_SCRATCH2, &val);
> + if (ret < 0)
> + return ret;
> +
> + if (val == 0xFF) {
This should be a constant, not a magic value
> + /* PBS error - clear SCRATCH2 register */
> + ret = qcom_pbs_write(pbs, PBS_CLIENT_SCRATCH2, 0);
> + if (ret < 0)
> + return ret;
> +
> + dev_err(pbs->dev, "NACK from PBS for bit %u\n", bit_pos);
> + return -EINVAL;
> + }
> +
> + if (val & BIT(bit_pos)) {
> + dev_dbg(pbs->dev, "PBS sequence for bit %u executed!\n", bit_pos);
> + break;
> + }
> +
> + usleep_range(delay, delay + 100);
So worst case scenario this will wait for over 2 seconds?
> + }
> +
> + if (!retries) {
> + dev_err(pbs->dev, "Timeout for PBS ACK/NACK for bit %u\n", bit_pos);
> + return -ETIMEDOUT;
> + }
> +
> + return 0;
return 0 instead of break above?
> +}
> +
> +/**
> + * qcom_pbs_trigger_event() - Trigger the PBS RAM sequence
> + * @pbs: Pointer to PBS device
> + * @bitmap: bitmap
> + *
> + * This function is used to trigger the PBS RAM sequence to be
> + * executed by the client driver.
> + *
> + * The PBS trigger sequence involves
> + * 1. setting the PBS sequence bit in PBS_CLIENT_SCRATCH1
> + * 2. Initiating the SW PBS trigger
> + * 3. Checking the equivalent bit in PBS_CLIENT_SCRATCH2 for the
> + * completion of the sequence.
> + * 4. If PBS_CLIENT_SCRATCH2 == 0xFF, the PBS sequence failed to execute
> + *
> + * Returns: 0 on success, < 0 on failure
> + */
> +int qcom_pbs_trigger_event(struct pbs_dev *pbs, u8 bitmap)
> +{
> + u8 val, mask;
> + u16 bit_pos;
> + int ret;
> +
> + if (!bitmap) {
> + dev_err(pbs->dev, "Invalid bitmap passed by client\n");
> + return -EINVAL;
> + }
> +
> + if (IS_ERR_OR_NULL(pbs))
> + return -EINVAL;
> +
> + mutex_lock(&pbs->lock);
> + ret = qcom_pbs_read(pbs, PBS_CLIENT_SCRATCH2, &val);
> + if (ret < 0)
> + goto out;
> +
> + if (val == 0xFF) {
> + /* PBS error - clear SCRATCH2 register */
> + ret = qcom_pbs_write(pbs, PBS_CLIENT_SCRATCH2, 0);
> + if (ret < 0)
> + goto out;
> + }
> +
> + for (bit_pos = 0; bit_pos < 8; bit_pos++) {
> + if (bitmap & BIT(bit_pos)) {
> + /*
> + * Clear the PBS sequence bit position in
> + * PBS_CLIENT_SCRATCH2 mask register.
> + */
Don't think the "in the X register" parts are useful.
> + ret = qcom_pbs_masked_write(pbs, PBS_CLIENT_SCRATCH2, BIT(bit_pos), 0);
> + if (ret < 0)
> + goto error;
> +
> + /*
> + * Set the PBS sequence bit position in
> + * PBS_CLIENT_SCRATCH1 register.
> + */
> + val = mask = BIT(bit_pos);
You're using mask/val for half the function calls..
Stick with one approach.
[...]
> +struct pbs_dev *get_pbs_client_device(struct device *dev)
> +{
> + struct device_node *pbs_dev_node;
> + struct platform_device *pdev;
> + struct pbs_dev *pbs;
> +
> + pbs_dev_node = of_parse_phandle(dev->of_node, "qcom,pbs", 0);
> + if (!pbs_dev_node) {
> + dev_err(dev, "Missing qcom,pbs property\n");
> + return ERR_PTR(-ENODEV);
> + }
> +
> + pdev = of_find_device_by_node(pbs_dev_node);
> + if (!pdev) {
> + dev_err(dev, "Unable to find PBS dev_node\n");
> + pbs = ERR_PTR(-EPROBE_DEFER);
> + goto out;
> + }
> +
> + pbs = platform_get_drvdata(pdev);
> + if (!pbs) {
This check seems unnecessary, the PBS driver would have had to fail
probing if set_drvdata never got called.
Konrad
next prev parent reply other threads:[~2023-07-26 15:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 19:34 [PATCH v2 0/7] Add support for LUT PPG Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 1/7] dt-bindings: soc: qcom: Add qcom-pbs bindings Anjelique Melendez
2023-07-25 20:49 ` Rob Herring
2023-07-26 7:53 ` Krzysztof Kozlowski
2023-07-31 18:19 ` Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 2/7] dt-bindings: leds: leds-qcom-lpg: Add support for LPG PPG Anjelique Melendez
2023-08-03 0:25 ` Rob Herring
2023-08-07 20:03 ` Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 3/7] soc: qcom: add QCOM PBS driver Anjelique Melendez
2023-07-26 15:36 ` Konrad Dybcio [this message]
2023-07-31 19:22 ` Bjorn Andersson
2023-08-01 18:48 ` Anjelique Melendez
2023-07-27 5:06 ` Dan Carpenter
2023-07-31 18:25 ` Trilok Soni
2023-07-25 19:34 ` [PATCH v2 4/7] leds: rgb: leds-qcom-lpg: Add support for PPG through single SDAM Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 5/7] leds: rgb: leds-qcom-lpg: Update PMI632 lpg_data to support PPG Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 6/7] leds: rgb: leds-qcom-lpg: Support two-nvmem PPG Scheme Anjelique Melendez
2023-07-25 19:34 ` [PATCH v2 7/7] leds: rgb: Update PM8350C lpg_data to support " Anjelique Melendez
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=de3b4739-5446-c1ab-571f-a36c4aff5e0f@linaro.org \
--to=konrad.dybcio@linaro.org \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=luca.weiss@fairphone.com \
--cc=pavel@ucw.cz \
--cc=quic_amelende@quicinc.com \
--cc=quic_subbaram@quicinc.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).