linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 6/7] mfd: qcom-smd-rpm: Driver for the Qualcomm RPM over SMD
Date: Wed, 8 Oct 2014 09:40:17 +0100	[thread overview]
Message-ID: <20141008084017.GD20647@lee--X1> (raw)
In-Reply-To: <1412037291-16880-7-git-send-email-bjorn.andersson@sonymobile.com>

On Mon, 29 Sep 2014, Bjorn Andersson wrote:

> Driver for the Resource Power Manager (RPM) found in Qualcomm 8974 based
> devices.
> The driver exposes resources that child drivers can operate on; to
> implementing regulator, clock and bus frequency drivers.
> 
> Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
> ---
> 
> Note that the qcom_rpm_smd_write is equivalent of qcom_rpm_write and there is a
> possibility of re-using at least the clock implementation on top of this. This
> would however require some logic for calling the right implementation so I have
> not done it at this time to keep things as clean as possible.
> 
> An idea for improvement is that in qcom_rpm_smd_write we put the ack_status and
> completion on the stack and register this with idr using the message id, upon
> receiving the interrupt we would find the right client and complete this.
> Allowing for multiple requests to be in flight at any given time.
> 
> I did not implement this because I haven't done any measurements on what kind
> of improvements this could give and it would be a clean iteration ontop of
> this.
> 
>  drivers/mfd/Kconfig              |   14 ++
>  drivers/mfd/Makefile             |    1 +
>  drivers/mfd/qcom-smd-rpm.c       |  299 ++++++++++++++++++++++++++++++++++++++
>  include/linux/mfd/qcom-smd-rpm.h |    9 ++
>  4 files changed, 323 insertions(+)
>  create mode 100644 drivers/mfd/qcom-smd-rpm.c
>  create mode 100644 include/linux/mfd/qcom-smd-rpm.h


> +#define RPM_ERR_INVALID_RESOURCE "resource does not exist"
> +
> +static bool qcom_rpm_msg_is_invalid_resource(struct qcom_rpm_message *msg)
> +{
> +	size_t msg_len = sizeof(RPM_ERR_INVALID_RESOURCE) - 1;
> +
> +	if (msg->length != msg_len)
> +		return false;
> +
> +	if (memcmp(msg->message, RPM_ERR_INVALID_RESOURCE, msg_len))
> +		return false;
> +
> +	return true;
> +}

You can save yourself a hell of a lot of code by just doing:

if (memcmp(msg->message, RPM_ERR_INVALID_RESOURCE,
           min(msg_len, sizeof(RPM_ERR_INVALID_RESOURCE))))

... in qcom_smd_rpm_callback().

[...]

> +static int qcom_smd_rpm_probe(struct qcom_smd_device *sdev)
> +{
> +	const struct of_device_id *match;
> +	struct qcom_smd_rpm *rpm;
> +
> +	rpm = devm_kzalloc(&sdev->dev, sizeof(*rpm), GFP_KERNEL);
> +	if (!rpm)
> +		return -ENOMEM;
> +
> +	rpm->dev = &sdev->dev;
> +	mutex_init(&rpm->lock);
> +	init_completion(&rpm->ack);
> +
> +	match = of_match_device(qcom_smd_rpm_of_match, &sdev->dev);

You need to check the return value here.

> +	rpm->data = match->data;
> +	rpm->rpm_channel = sdev->channel;
> +
> +	dev_set_drvdata(&sdev->dev, rpm);
> +
> +	dev_info(&sdev->dev, "Qualcomm SMD RPM driver probed\n");

Please remove this line.

> +	return of_platform_populate(sdev->dev.of_node, NULL, NULL, &sdev->dev);
> +}
> +
> +static void qcom_smd_rpm_remove(struct qcom_smd_device *sdev)
> +{
> +	dev_set_drvdata(&sdev->dev, NULL);

If you use the proper platform device interface you don't have to do
this.

> +	of_platform_depopulate(&sdev->dev);
> +}
> +
> +static struct qcom_smd_driver qcom_smd_rpm_driver = {
> +	.probe = qcom_smd_rpm_probe,
> +	.remove = qcom_smd_rpm_remove,
> +	.callback = qcom_smd_rpm_callback,
> +	.driver  = {
> +		.name  = "qcom_smd_rpm",
> +		.owner = THIS_MODULE,
> +		.of_match_table = qcom_smd_rpm_of_match,
> +	},
> +};
> +
> +module_qcom_smd_driver(qcom_smd_rpm_driver);

I don't like this.  What's wrong with the existing platform driver
code?

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

  reply	other threads:[~2014-10-08  8:40 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-30  0:34 [RFC 0/7] Qualcomm SMEM, SMD, RPM and regulators Bjorn Andersson
2014-09-30  0:34 ` [RFC 1/7] soc: qcom: Add device tree binding for SMEM Bjorn Andersson
2014-09-30 13:52   ` Kumar Gala
2014-09-30 19:03   ` Stephen Boyd
2014-09-30 20:00     ` Bjorn Andersson
2014-09-30 21:55   ` Suman Anna
2014-09-30  0:34 ` [RFC 2/7] soc: qcom: Add device tree binding for SMD Bjorn Andersson
2014-09-30  0:34 ` [RFC 3/7] mfd: devicetree: bindings: Add Qualcomm SMD based RPM DT binding Bjorn Andersson
2014-09-30 13:46   ` Kumar Gala
2014-09-30 14:37     ` Bjorn Andersson
2014-09-30 23:16       ` Jeffrey Hugo
2014-10-01  0:08         ` Bjorn Andersson
2014-10-08 21:47           ` Jeffrey Hugo
2014-10-24 15:59             ` Bjorn Andersson
2014-09-30  0:34 ` [RFC 4/7] soc: qcom: Add Shared Memory Manager driver Bjorn Andersson
2014-09-30  6:17   ` Kiran Padwal
2014-09-30  6:28     ` Kiran Padwal
2014-09-30 14:15       ` Bjorn Andersson
2014-10-08 21:33   ` Jeffrey Hugo
2014-10-17 14:51     ` Bjorn Andersson
2014-10-26 15:04       ` Andreas Färber
2014-10-28  0:34     ` Bjorn Andersson
2014-09-30  0:34 ` [RFC 5/7] soc: qcom: Add Shared Memory Driver Bjorn Andersson
2014-10-02 22:38   ` Stephen Boyd
2014-10-04  0:02     ` Bjorn Andersson
2014-10-29 14:28   ` Ohad Ben-Cohen
2014-10-30  0:38     ` Bjorn Andersson
2014-10-30 13:34       ` Ohad Ben-Cohen
2014-10-30 15:04         ` Bjorn Andersson
2014-09-30  0:34 ` [RFC 6/7] mfd: qcom-smd-rpm: Driver for the Qualcomm RPM over SMD Bjorn Andersson
2014-10-08  8:40   ` Lee Jones [this message]
2014-10-17 13:55     ` Bjorn Andersson
2014-10-20  7:22       ` Lee Jones
2014-10-24 16:45         ` Bjorn Andersson
2014-09-30  0:34 ` [RFC 7/7] regulator: qcom-smd-rpm: Regulator driver for the Qualcomm RPM Bjorn Andersson
2014-10-01 18:13   ` Mark Brown
2014-09-30 13:49 ` [RFC 0/7] Qualcomm SMEM, SMD, RPM and regulators Kumar Gala
2014-09-30 14:51   ` Bjorn Andersson

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=20141008084017.GD20647@lee--X1 \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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 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).