From: Stanimir Varbanov <svarbanov@mm-sol.com>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: Rob Herring <rob.herring@calxeda.com>,
Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Matt Mackall <mpm@selenic.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
linux-kernel@vger.kernel.org, Rob Landley <rob@landley.net>,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 2/2] hwrng: msm: Add PRNG support for MSM SoC's
Date: Fri, 04 Oct 2013 19:31:10 +0300 [thread overview]
Message-ID: <524EED4E.8090505@mm-sol.com> (raw)
In-Reply-To: <524DC4B1.4050100@codeaurora.org>
Hi Stephen,
Thanks for the quick review!
On 10/03/2013 10:25 PM, Stephen Boyd wrote:
> On 10/03/13 07:52, Stanimir Varbanov wrote:
>> +#define PRNG_CONFIG_MASK 0x00000002
>> +#define PRNG_CONFIG_HW_ENABLE BIT(1)
>
> These two are the same so please drop the PRNG_CONFIG_MASK define and
> just use the PRNG_CONFIG_HW_ENABLE define.
>
OK I will drop the mask and rework the code related to it.
>> +#define PRNG_STATUS_DATA_AVAIL BIT(0)
>> +
>> +#define MAX_HW_FIFO_DEPTH 16
>> +#define MAX_HW_FIFO_SIZE (MAX_HW_FIFO_DEPTH * 4)
>> +#define WORD_SZ 4
>> +
>> +struct msm_rng {
>> + void __iomem *base;
>> + struct clk *clk;
>> +};
>> +
>> +static int msm_rng_enable(struct msm_rng *rng, int enable)
>> +{
>> + u32 val;
>> + int ret;
>> +
>> + ret = clk_prepare_enable(rng->clk);
>> + if (ret)
>> + return ret;
>> +
>> + if (enable) {
>> + /* Enable PRNG only if it is not already enabled */
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + if (val & PRNG_CONFIG_HW_ENABLE)
>> + goto already_enabled;
>> +
>> + /* PRNG is not enabled */
>> + val = readl_relaxed(rng->base + PRNG_LFSR_CFG);
>> + val &= ~PRNG_LFSR_CFG_MASK;
>> + val |= PRNG_LFSR_CFG_CLOCKS;
>> + writel(val, rng->base + PRNG_LFSR_CFG);
>> +
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + val &= ~PRNG_CONFIG_MASK;
>> + val |= PRNG_CONFIG_HW_ENABLE;
>> + writel(val, rng->base + PRNG_CONFIG);
>
> This could just be
>
> val = readl_relaxed(rng->base + PRNG_CONFIG);
> val |= PRNG_CONFIG_HW_ENABLE;
> writel(val, rng->base + PRNG_CONFIG);
>
>
>> + } else {
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + val &= ~PRNG_CONFIG_MASK;
>> + writel(val, rng->base + PRNG_CONFIG);
>> + }
>> +
>> +already_enabled:
>> + clk_disable_unprepare(rng->clk);
>> + return 0;
>> +}
>> +
> [...]
>> +static int msm_rng_probe(struct platform_device *pdev)
>> +{
>> + struct msm_rng *rng;
>> + struct device_node *np;
>> + struct resource res;
>> + int ret;
>> +
>> + np = of_node_get(pdev->dev.of_node);
>> + if (!np)
>> + return -ENODEV;
>
> This is unnecessary.
I used this call because CONFIG_OF_DYNAMIC could be enabled at some
time. Isn't that possible? I saw that of_node_get|put is used in .probe
on few places in drivers.
>
>> +
>> + rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
>> + if (!rng) {
>> + ret = -ENOMEM;
>> + goto err_exit;
>> + }
>> +
>> + ret = of_address_to_resource(np, 0, &res);
>> + if (ret)
>> + goto err_exit;
>
> We should just do
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> rng->base = devm_ioremap_resource(&pdev->dev, res);
> if (IS_ERR(rng->base))
> return PTR_ERR(rng->base);
>
>> +
>> + rng->base = devm_ioremap_resource(&pdev->dev, &res);
>> + if (IS_ERR(rng->base)) {
>> + ret = PTR_ERR(rng->base);
>> + goto err_exit;
>> + }
>> +
>> + rng->clk = devm_clk_get(&pdev->dev, "prng");
>> + if (IS_ERR(rng->clk)) {
>> + ret = PTR_ERR(rng->clk);
>> + goto err_exit;
>> + }
>> +
>> + msm_rng_ops.priv = (unsigned long) rng;
>> + ret = hwrng_register(&msm_rng_ops);
>> + if (ret)
>> + dev_err(&pdev->dev, "failed to register hwrng\n");
>> +
>> +err_exit:
>
> Doing all that should make this goto exit path unnecessary.
>
>> + of_node_put(np);
>> + return ret;
>> +}
>> +
>> +static int msm_rng_remove(struct platform_device *pdev)
>> +{
>> + hwrng_unregister(&msm_rng_ops);
>> + return 0;
>> +}
>> +
>> +static struct of_device_id msm_rng_of_match[] = {
>
> const?
>
>> + { .compatible = "qcom,prng", },
>> + {}
>> +};
>> +MODULE_DEVICE_TABLE(of, msm_rng_of_match);
>> +
>> +static struct platform_driver msm_rng_driver = {
>> + .probe = msm_rng_probe,
>> + .remove = msm_rng_remove,
>> + .driver = {
>> + .name = KBUILD_MODNAME,
>> + .owner = THIS_MODULE,
>> + .of_match_table = of_match_ptr(msm_rng_of_match),
>> + }
>> +};
>> +module_platform_driver(msm_rng_driver);
>> +
>> +MODULE_AUTHOR("The Linux Foundation");
>> +MODULE_DESCRIPTION("Qualcomm MSM random number generator driver");
>> +MODULE_LICENSE("GPL v2");
>
>
regards,
Stan
WARNING: multiple messages have this Message-ID (diff)
From: Stanimir Varbanov <svarbanov@mm-sol.com>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: Rob Herring <rob.herring@calxeda.com>,
Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Matt Mackall <mpm@selenic.com>,
Herbert Xu <herbert@gondor.hengli.com.au>,
linux-kernel@vger.kernel.org, Rob Landley <rob@landley.net>,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 2/2] hwrng: msm: Add PRNG support for MSM SoC's
Date: Fri, 04 Oct 2013 19:31:10 +0300 [thread overview]
Message-ID: <524EED4E.8090505@mm-sol.com> (raw)
In-Reply-To: <524DC4B1.4050100@codeaurora.org>
Hi Stephen,
Thanks for the quick review!
On 10/03/2013 10:25 PM, Stephen Boyd wrote:
> On 10/03/13 07:52, Stanimir Varbanov wrote:
>> +#define PRNG_CONFIG_MASK 0x00000002
>> +#define PRNG_CONFIG_HW_ENABLE BIT(1)
>
> These two are the same so please drop the PRNG_CONFIG_MASK define and
> just use the PRNG_CONFIG_HW_ENABLE define.
>
OK I will drop the mask and rework the code related to it.
>> +#define PRNG_STATUS_DATA_AVAIL BIT(0)
>> +
>> +#define MAX_HW_FIFO_DEPTH 16
>> +#define MAX_HW_FIFO_SIZE (MAX_HW_FIFO_DEPTH * 4)
>> +#define WORD_SZ 4
>> +
>> +struct msm_rng {
>> + void __iomem *base;
>> + struct clk *clk;
>> +};
>> +
>> +static int msm_rng_enable(struct msm_rng *rng, int enable)
>> +{
>> + u32 val;
>> + int ret;
>> +
>> + ret = clk_prepare_enable(rng->clk);
>> + if (ret)
>> + return ret;
>> +
>> + if (enable) {
>> + /* Enable PRNG only if it is not already enabled */
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + if (val & PRNG_CONFIG_HW_ENABLE)
>> + goto already_enabled;
>> +
>> + /* PRNG is not enabled */
>> + val = readl_relaxed(rng->base + PRNG_LFSR_CFG);
>> + val &= ~PRNG_LFSR_CFG_MASK;
>> + val |= PRNG_LFSR_CFG_CLOCKS;
>> + writel(val, rng->base + PRNG_LFSR_CFG);
>> +
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + val &= ~PRNG_CONFIG_MASK;
>> + val |= PRNG_CONFIG_HW_ENABLE;
>> + writel(val, rng->base + PRNG_CONFIG);
>
> This could just be
>
> val = readl_relaxed(rng->base + PRNG_CONFIG);
> val |= PRNG_CONFIG_HW_ENABLE;
> writel(val, rng->base + PRNG_CONFIG);
>
>
>> + } else {
>> + val = readl_relaxed(rng->base + PRNG_CONFIG);
>> + val &= ~PRNG_CONFIG_MASK;
>> + writel(val, rng->base + PRNG_CONFIG);
>> + }
>> +
>> +already_enabled:
>> + clk_disable_unprepare(rng->clk);
>> + return 0;
>> +}
>> +
> [...]
>> +static int msm_rng_probe(struct platform_device *pdev)
>> +{
>> + struct msm_rng *rng;
>> + struct device_node *np;
>> + struct resource res;
>> + int ret;
>> +
>> + np = of_node_get(pdev->dev.of_node);
>> + if (!np)
>> + return -ENODEV;
>
> This is unnecessary.
I used this call because CONFIG_OF_DYNAMIC could be enabled at some
time. Isn't that possible? I saw that of_node_get|put is used in .probe
on few places in drivers.
>
>> +
>> + rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
>> + if (!rng) {
>> + ret = -ENOMEM;
>> + goto err_exit;
>> + }
>> +
>> + ret = of_address_to_resource(np, 0, &res);
>> + if (ret)
>> + goto err_exit;
>
> We should just do
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> rng->base = devm_ioremap_resource(&pdev->dev, res);
> if (IS_ERR(rng->base))
> return PTR_ERR(rng->base);
>
>> +
>> + rng->base = devm_ioremap_resource(&pdev->dev, &res);
>> + if (IS_ERR(rng->base)) {
>> + ret = PTR_ERR(rng->base);
>> + goto err_exit;
>> + }
>> +
>> + rng->clk = devm_clk_get(&pdev->dev, "prng");
>> + if (IS_ERR(rng->clk)) {
>> + ret = PTR_ERR(rng->clk);
>> + goto err_exit;
>> + }
>> +
>> + msm_rng_ops.priv = (unsigned long) rng;
>> + ret = hwrng_register(&msm_rng_ops);
>> + if (ret)
>> + dev_err(&pdev->dev, "failed to register hwrng\n");
>> +
>> +err_exit:
>
> Doing all that should make this goto exit path unnecessary.
>
>> + of_node_put(np);
>> + return ret;
>> +}
>> +
>> +static int msm_rng_remove(struct platform_device *pdev)
>> +{
>> + hwrng_unregister(&msm_rng_ops);
>> + return 0;
>> +}
>> +
>> +static struct of_device_id msm_rng_of_match[] = {
>
> const?
>
>> + { .compatible = "qcom,prng", },
>> + {}
>> +};
>> +MODULE_DEVICE_TABLE(of, msm_rng_of_match);
>> +
>> +static struct platform_driver msm_rng_driver = {
>> + .probe = msm_rng_probe,
>> + .remove = msm_rng_remove,
>> + .driver = {
>> + .name = KBUILD_MODNAME,
>> + .owner = THIS_MODULE,
>> + .of_match_table = of_match_ptr(msm_rng_of_match),
>> + }
>> +};
>> +module_platform_driver(msm_rng_driver);
>> +
>> +MODULE_AUTHOR("The Linux Foundation");
>> +MODULE_DESCRIPTION("Qualcomm MSM random number generator driver");
>> +MODULE_LICENSE("GPL v2");
>
>
regards,
Stan
next prev parent reply other threads:[~2013-10-04 16:32 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-03 14:52 [PATCH 0/2] Add support for Qualcomm's PRNG Stanimir Varbanov
2013-10-03 14:52 ` Stanimir Varbanov
2013-10-03 14:52 ` [PATCH 1/2] ARM: DT: msm: Add Qualcomm's PRNG driver binding document Stanimir Varbanov
2013-10-03 14:52 ` Stanimir Varbanov
2013-10-03 14:52 ` [PATCH 2/2] hwrng: msm: Add PRNG support for MSM SoC's Stanimir Varbanov
2013-10-03 14:52 ` Stanimir Varbanov
2013-10-03 19:25 ` Stephen Boyd
2013-10-03 19:25 ` Stephen Boyd
2013-10-04 16:31 ` Stanimir Varbanov [this message]
2013-10-04 16:31 ` Stanimir Varbanov
2013-10-04 16:37 ` Stephen Boyd
2013-10-04 16:37 ` Stephen Boyd
2013-10-09 8:23 ` Stanimir Varbanov
2013-10-09 8:23 ` Stanimir Varbanov
[not found] ` <1380811955-18085-1-git-send-email-svarbanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
2013-10-03 16:51 ` [PATCH 0/2] Add support for Qualcomm's PRNG Theodore Ts'o
2013-10-03 16:51 ` Theodore Ts'o
[not found] ` <20131003165130.GA11974-AKGzg7BKzIDYtjvyW6yDsg@public.gmane.org>
2013-10-04 16:23 ` Stanimir Varbanov
2013-10-04 16:23 ` Stanimir Varbanov
[not found] ` <524EEB96.6040707-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
2013-10-04 18:10 ` Theodore Ts'o
2013-10-04 18:10 ` Theodore Ts'o
2013-10-09 14:46 ` Stanimir Varbanov
2013-10-09 15:07 ` H. Peter Anvin
2013-10-09 16:03 ` Theodore Ts'o
2013-10-09 16:24 ` H. Peter Anvin
2013-10-10 7:46 ` rngd (was: [PATCH 0/2] Add support for Qualcomm's PRNG) Clemens Ladisch
2013-10-10 15:08 ` rngd H. Peter Anvin
2013-10-10 19:48 ` rngd Theodore Ts'o
2013-10-10 10:41 ` [PATCH 0/2] Add support for Qualcomm's PRNG Paul Mackerras
2013-10-10 15:08 ` H. Peter Anvin
2013-10-10 13:47 ` Stanimir Varbanov
2013-10-11 7:05 ` Clemens Ladisch
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=524EED4E.8090505@mm-sol.com \
--to=svarbanov@mm-sol.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mpm@selenic.com \
--cc=pawel.moll@arm.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
--cc=sboyd@codeaurora.org \
--cc=swarren@wwwdotorg.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.