* [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
@ 2018-09-11 21:34 ` Jolly Shah
0 siblings, 0 replies; 17+ messages in thread
From: Jolly Shah @ 2018-09-11 21:34 UTC (permalink / raw)
To: linux-arm-kernel
From: Rajan Vaja <rajan.vaja@xilinx.com>
Add ZynqMP PM driver. PM driver provides power management
support for ZynqMP.
Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
Signed-off-by: Jolly Shah <jollys@xilinx.com>
---
drivers/soc/xilinx/Kconfig | 11 ++
drivers/soc/xilinx/Makefile | 1 +
drivers/soc/xilinx/zynqmp_power.c | 230 ++++++++++++++++++++++++++++++++++++++
3 files changed, 242 insertions(+)
create mode 100644 drivers/soc/xilinx/zynqmp_power.c
diff --git a/drivers/soc/xilinx/Kconfig b/drivers/soc/xilinx/Kconfig
index 687c8f3..5025e0e 100644
--- a/drivers/soc/xilinx/Kconfig
+++ b/drivers/soc/xilinx/Kconfig
@@ -17,4 +17,15 @@ config XILINX_VCU
To compile this driver as a module, choose M here: the
module will be called xlnx_vcu.
+config ZYNQMP_POWER
+ bool "Enable Xilinx Zynq MPSoC Power Management driver"
+ depends on PM && ARCH_ZYNQMP
+ default y
+ help
+ Say yes to enable power management support for ZyqnMP SoC.
+ This driver uses firmware driver as an interface for power
+ management request to firmware. It registers isr to handle
+ power management callbacks from firmware.
+ If in doubt, say N.
+
endmenu
diff --git a/drivers/soc/xilinx/Makefile b/drivers/soc/xilinx/Makefile
index dee8fd5..428b9db 100644
--- a/drivers/soc/xilinx/Makefile
+++ b/drivers/soc/xilinx/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_XILINX_VCU) += xlnx_vcu.o
+obj-$(CONFIG_ZYNQMP_POWER) += zynqmp_power.o
diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c
new file mode 100644
index 0000000..9071948
--- /dev/null
+++ b/drivers/soc/xilinx/zynqmp_power.c
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Xilinx Zynq MPSoC Power Management
+ *
+ * Copyright (C) 2014-2018 Xilinx, Inc.
+ *
+ * Davorin Mista <davorin.mista@aggios.com>
+ * Jolly Shah <jollys@xilinx.com>
+ * Rajan Vaja <rajan.vaja@xilinx.com>
+ */
+
+#include <linux/mailbox_client.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/suspend.h>
+
+#include <linux/firmware/xlnx-zynqmp.h>
+
+/**
+ * struct zynqmp_pm_work_struct - Wrapper for struct work_struct
+ * @callback_work: Work structure
+ * @args: Callback arguments
+ */
+struct zynqmp_pm_work_struct {
+ struct work_struct callback_work;
+ u32 args[CB_ARG_CNT];
+};
+
+static struct zynqmp_pm_work_struct *zynqmp_pm_init_suspend_work;
+
+enum pm_suspend_mode {
+ PM_SUSPEND_MODE_FIRST = 0,
+ PM_SUSPEND_MODE_STD = PM_SUSPEND_MODE_FIRST,
+ PM_SUSPEND_MODE_POWER_OFF,
+};
+
+#define PM_SUSPEND_MODE_FIRST PM_SUSPEND_MODE_STD
+
+static const char *const suspend_modes[] = {
+ [PM_SUSPEND_MODE_STD] = "standard",
+ [PM_SUSPEND_MODE_POWER_OFF] = "power-off",
+};
+
+static enum pm_suspend_mode suspend_mode = PM_SUSPEND_MODE_STD;
+
+enum pm_api_cb_id {
+ PM_INIT_SUSPEND_CB = 30,
+ PM_ACKNOWLEDGE_CB,
+ PM_NOTIFY_CB,
+};
+
+static void zynqmp_pm_get_callback_data(u32 *buf)
+{
+ zynqmp_pm_invoke_fn(GET_CALLBACK_DATA, 0, 0, 0, 0, buf);
+}
+
+static irqreturn_t zynqmp_pm_isr(int irq, void *data)
+{
+ u32 payload[CB_PAYLOAD_SIZE];
+
+ zynqmp_pm_get_callback_data(payload);
+
+ /* First element is callback API ID, others are callback arguments */
+ if (payload[0] == PM_INIT_SUSPEND_CB) {
+ if (work_pending(&zynqmp_pm_init_suspend_work->callback_work))
+ goto done;
+
+ /* Copy callback arguments into work's structure */
+ memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
+ sizeof(zynqmp_pm_init_suspend_work->args));
+
+ queue_work(system_unbound_wq,
+ &zynqmp_pm_init_suspend_work->callback_work);
+ }
+
+done:
+ return IRQ_HANDLED;
+}
+
+/**
+ * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
+ * @work: Pointer to work_struct
+ *
+ * Bottom-half of PM callback IRQ handler.
+ */
+static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
+{
+ struct zynqmp_pm_work_struct *pm_work =
+ container_of(work, struct zynqmp_pm_work_struct, callback_work);
+
+ if (pm_work->args[0] == ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
+ orderly_poweroff(true);
+ } else if (pm_work->args[0] ==
+ ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
+ pm_suspend(PM_SUSPEND_MEM);
+ } else {
+ pr_err("%s Unsupported InitSuspendCb reason code %d.\n",
+ __func__, pm_work->args[0]);
+ }
+}
+
+static ssize_t suspend_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ char *s = buf;
+ int md;
+
+ for (md = PM_SUSPEND_MODE_FIRST; md < ARRAY_SIZE(suspend_modes); md++)
+ if (suspend_modes[md]) {
+ if (md == suspend_mode)
+ s += sprintf(s, "[%s] ", suspend_modes[md]);
+ else
+ s += sprintf(s, "%s ", suspend_modes[md]);
+ }
+
+ /* Convert last space to newline */
+ if (s != buf)
+ *(s - 1) = '\n';
+ return (s - buf);
+}
+
+static ssize_t suspend_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int md, ret = -EINVAL;
+ const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
+
+ if (!eemi_ops || !eemi_ops->set_suspend_mode)
+ return ret;
+
+ for (md = PM_SUSPEND_MODE_FIRST; md < ARRAY_SIZE(suspend_modes); md++)
+ if (suspend_modes[md] &&
+ sysfs_streq(suspend_modes[md], buf)) {
+ ret = 0;
+ break;
+ }
+
+ if (!ret && md != suspend_mode) {
+ ret = eemi_ops->set_suspend_mode(md);
+ if (likely(!ret))
+ suspend_mode = md;
+ }
+
+ return ret ? ret : count;
+}
+
+static DEVICE_ATTR_RW(suspend_mode);
+
+/**
+ * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
+ * @dev: Pointer to device structure
+ *
+ * Return: 0 on success, negative error code otherwise
+ */
+static int zynqmp_pm_sysfs_init(struct device *dev)
+{
+ return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr);
+}
+
+/**
+ * zynqmp_pm_probe() - Probe existence of the PMU Firmware
+ * and initialize debugfs interface
+ *
+ * @pdev: Pointer to the platform_device structure
+ *
+ * Return: Returns 0 on success, negative error code otherwise
+ */
+static int zynqmp_pm_probe(struct platform_device *pdev)
+{
+ int ret, irq;
+ u32 pm_api_version;
+
+ const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
+
+ if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize)
+ return -ENXIO;
+
+ eemi_ops->init_finalize();
+ eemi_ops->get_api_version(&pm_api_version);
+
+ /* Check PM API version number */
+ if (pm_api_version < ZYNQMP_PM_VERSION)
+ return -ENODEV;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq <= 0)
+ return -ENXIO;
+
+ ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr, IRQF_SHARED,
+ dev_name(&pdev->dev), pdev);
+ if (ret) {
+ dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
+ irq, ret);
+ return ret;
+ }
+
+ zynqmp_pm_init_suspend_work =
+ devm_kzalloc(&pdev->dev, sizeof(struct zynqmp_pm_work_struct),
+ GFP_KERNEL);
+ if (!zynqmp_pm_init_suspend_work)
+ return -ENOMEM;
+
+ INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
+ zynqmp_pm_init_suspend_work_fn);
+
+ ret = zynqmp_pm_sysfs_init(&pdev->dev);
+ if (ret) {
+ dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+static const struct of_device_id pm_of_match[] = {
+ { .compatible = "xlnx,zynqmp-power", },
+ { /* end of table */ },
+};
+MODULE_DEVICE_TABLE(of, pm_of_match);
+
+static struct platform_driver zynqmp_pm_platform_driver = {
+ .probe = zynqmp_pm_probe,
+ .driver = {
+ .name = "zynqmp_power",
+ .of_match_table = pm_of_match,
+ },
+};
+module_platform_driver(zynqmp_pm_platform_driver);
--
2.7.4
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
@ 2018-09-11 21:34 ` Jolly Shah
0 siblings, 0 replies; 17+ messages in thread
From: Jolly Shah @ 2018-09-11 21:34 UTC (permalink / raw)
To: matthias.bgg, andy.gross, shawnguo, geert+renesas,
bjorn.andersson, sean.wang, m.szyprowski, michal.simek, robh+dt,
mark.rutland
Cc: rajanv, devicetree, linux-arm-kernel, linux-kernel, Rajan Vaja,
Jolly Shah
From: Rajan Vaja <rajan.vaja@xilinx.com>
Add ZynqMP PM driver. PM driver provides power management
support for ZynqMP.
Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
Signed-off-by: Jolly Shah <jollys@xilinx.com>
---
drivers/soc/xilinx/Kconfig | 11 ++
drivers/soc/xilinx/Makefile | 1 +
drivers/soc/xilinx/zynqmp_power.c | 230 ++++++++++++++++++++++++++++++++++++++
3 files changed, 242 insertions(+)
create mode 100644 drivers/soc/xilinx/zynqmp_power.c
diff --git a/drivers/soc/xilinx/Kconfig b/drivers/soc/xilinx/Kconfig
index 687c8f3..5025e0e 100644
--- a/drivers/soc/xilinx/Kconfig
+++ b/drivers/soc/xilinx/Kconfig
@@ -17,4 +17,15 @@ config XILINX_VCU
To compile this driver as a module, choose M here: the
module will be called xlnx_vcu.
+config ZYNQMP_POWER
+ bool "Enable Xilinx Zynq MPSoC Power Management driver"
+ depends on PM && ARCH_ZYNQMP
+ default y
+ help
+ Say yes to enable power management support for ZyqnMP SoC.
+ This driver uses firmware driver as an interface for power
+ management request to firmware. It registers isr to handle
+ power management callbacks from firmware.
+ If in doubt, say N.
+
endmenu
diff --git a/drivers/soc/xilinx/Makefile b/drivers/soc/xilinx/Makefile
index dee8fd5..428b9db 100644
--- a/drivers/soc/xilinx/Makefile
+++ b/drivers/soc/xilinx/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_XILINX_VCU) += xlnx_vcu.o
+obj-$(CONFIG_ZYNQMP_POWER) += zynqmp_power.o
diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c
new file mode 100644
index 0000000..9071948
--- /dev/null
+++ b/drivers/soc/xilinx/zynqmp_power.c
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Xilinx Zynq MPSoC Power Management
+ *
+ * Copyright (C) 2014-2018 Xilinx, Inc.
+ *
+ * Davorin Mista <davorin.mista@aggios.com>
+ * Jolly Shah <jollys@xilinx.com>
+ * Rajan Vaja <rajan.vaja@xilinx.com>
+ */
+
+#include <linux/mailbox_client.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/suspend.h>
+
+#include <linux/firmware/xlnx-zynqmp.h>
+
+/**
+ * struct zynqmp_pm_work_struct - Wrapper for struct work_struct
+ * @callback_work: Work structure
+ * @args: Callback arguments
+ */
+struct zynqmp_pm_work_struct {
+ struct work_struct callback_work;
+ u32 args[CB_ARG_CNT];
+};
+
+static struct zynqmp_pm_work_struct *zynqmp_pm_init_suspend_work;
+
+enum pm_suspend_mode {
+ PM_SUSPEND_MODE_FIRST = 0,
+ PM_SUSPEND_MODE_STD = PM_SUSPEND_MODE_FIRST,
+ PM_SUSPEND_MODE_POWER_OFF,
+};
+
+#define PM_SUSPEND_MODE_FIRST PM_SUSPEND_MODE_STD
+
+static const char *const suspend_modes[] = {
+ [PM_SUSPEND_MODE_STD] = "standard",
+ [PM_SUSPEND_MODE_POWER_OFF] = "power-off",
+};
+
+static enum pm_suspend_mode suspend_mode = PM_SUSPEND_MODE_STD;
+
+enum pm_api_cb_id {
+ PM_INIT_SUSPEND_CB = 30,
+ PM_ACKNOWLEDGE_CB,
+ PM_NOTIFY_CB,
+};
+
+static void zynqmp_pm_get_callback_data(u32 *buf)
+{
+ zynqmp_pm_invoke_fn(GET_CALLBACK_DATA, 0, 0, 0, 0, buf);
+}
+
+static irqreturn_t zynqmp_pm_isr(int irq, void *data)
+{
+ u32 payload[CB_PAYLOAD_SIZE];
+
+ zynqmp_pm_get_callback_data(payload);
+
+ /* First element is callback API ID, others are callback arguments */
+ if (payload[0] == PM_INIT_SUSPEND_CB) {
+ if (work_pending(&zynqmp_pm_init_suspend_work->callback_work))
+ goto done;
+
+ /* Copy callback arguments into work's structure */
+ memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
+ sizeof(zynqmp_pm_init_suspend_work->args));
+
+ queue_work(system_unbound_wq,
+ &zynqmp_pm_init_suspend_work->callback_work);
+ }
+
+done:
+ return IRQ_HANDLED;
+}
+
+/**
+ * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
+ * @work: Pointer to work_struct
+ *
+ * Bottom-half of PM callback IRQ handler.
+ */
+static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
+{
+ struct zynqmp_pm_work_struct *pm_work =
+ container_of(work, struct zynqmp_pm_work_struct, callback_work);
+
+ if (pm_work->args[0] == ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
+ orderly_poweroff(true);
+ } else if (pm_work->args[0] ==
+ ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
+ pm_suspend(PM_SUSPEND_MEM);
+ } else {
+ pr_err("%s Unsupported InitSuspendCb reason code %d.\n",
+ __func__, pm_work->args[0]);
+ }
+}
+
+static ssize_t suspend_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ char *s = buf;
+ int md;
+
+ for (md = PM_SUSPEND_MODE_FIRST; md < ARRAY_SIZE(suspend_modes); md++)
+ if (suspend_modes[md]) {
+ if (md == suspend_mode)
+ s += sprintf(s, "[%s] ", suspend_modes[md]);
+ else
+ s += sprintf(s, "%s ", suspend_modes[md]);
+ }
+
+ /* Convert last space to newline */
+ if (s != buf)
+ *(s - 1) = '\n';
+ return (s - buf);
+}
+
+static ssize_t suspend_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int md, ret = -EINVAL;
+ const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
+
+ if (!eemi_ops || !eemi_ops->set_suspend_mode)
+ return ret;
+
+ for (md = PM_SUSPEND_MODE_FIRST; md < ARRAY_SIZE(suspend_modes); md++)
+ if (suspend_modes[md] &&
+ sysfs_streq(suspend_modes[md], buf)) {
+ ret = 0;
+ break;
+ }
+
+ if (!ret && md != suspend_mode) {
+ ret = eemi_ops->set_suspend_mode(md);
+ if (likely(!ret))
+ suspend_mode = md;
+ }
+
+ return ret ? ret : count;
+}
+
+static DEVICE_ATTR_RW(suspend_mode);
+
+/**
+ * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
+ * @dev: Pointer to device structure
+ *
+ * Return: 0 on success, negative error code otherwise
+ */
+static int zynqmp_pm_sysfs_init(struct device *dev)
+{
+ return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr);
+}
+
+/**
+ * zynqmp_pm_probe() - Probe existence of the PMU Firmware
+ * and initialize debugfs interface
+ *
+ * @pdev: Pointer to the platform_device structure
+ *
+ * Return: Returns 0 on success, negative error code otherwise
+ */
+static int zynqmp_pm_probe(struct platform_device *pdev)
+{
+ int ret, irq;
+ u32 pm_api_version;
+
+ const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
+
+ if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize)
+ return -ENXIO;
+
+ eemi_ops->init_finalize();
+ eemi_ops->get_api_version(&pm_api_version);
+
+ /* Check PM API version number */
+ if (pm_api_version < ZYNQMP_PM_VERSION)
+ return -ENODEV;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq <= 0)
+ return -ENXIO;
+
+ ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr, IRQF_SHARED,
+ dev_name(&pdev->dev), pdev);
+ if (ret) {
+ dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
+ irq, ret);
+ return ret;
+ }
+
+ zynqmp_pm_init_suspend_work =
+ devm_kzalloc(&pdev->dev, sizeof(struct zynqmp_pm_work_struct),
+ GFP_KERNEL);
+ if (!zynqmp_pm_init_suspend_work)
+ return -ENOMEM;
+
+ INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
+ zynqmp_pm_init_suspend_work_fn);
+
+ ret = zynqmp_pm_sysfs_init(&pdev->dev);
+ if (ret) {
+ dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+static const struct of_device_id pm_of_match[] = {
+ { .compatible = "xlnx,zynqmp-power", },
+ { /* end of table */ },
+};
+MODULE_DEVICE_TABLE(of, pm_of_match);
+
+static struct platform_driver zynqmp_pm_platform_driver = {
+ .probe = zynqmp_pm_probe,
+ .driver = {
+ .name = "zynqmp_power",
+ .of_match_table = pm_of_match,
+ },
+};
+module_platform_driver(zynqmp_pm_platform_driver);
--
2.7.4
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
2018-09-11 21:34 ` Jolly Shah
@ 2018-09-12 1:10 ` Ahmed S. Darwish
-1 siblings, 0 replies; 17+ messages in thread
From: Ahmed S. Darwish @ 2018-09-12 1:10 UTC (permalink / raw)
To: Jolly Shah
Cc: matthias.bgg, andy.gross, shawnguo, geert+renesas,
bjorn.andersson, sean.wang, m.szyprowski, michal.simek, robh+dt,
mark.rutland, rajanv, devicetree, linux-arm-kernel, linux-kernel,
Rajan Vaja, Jolly Shah
Hi!
[ Thanks a lot for upstreaming this.. ]
On Tue, Sep 11, 2018 at 02:34:57PM -0700, Jolly Shah wrote:
> From: Rajan Vaja <rajan.vaja@xilinx.com>
>
> Add ZynqMP PM driver. PM driver provides power management
> support for ZynqMP.
>
> Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
> Signed-off-by: Jolly Shah <jollys@xilinx.com>
> ---
[...]
> +static irqreturn_t zynqmp_pm_isr(int irq, void *data)
> +{
> + u32 payload[CB_PAYLOAD_SIZE];
> +
> + zynqmp_pm_get_callback_data(payload);
> +
> + /* First element is callback API ID, others are callback arguments */
> + if (payload[0] == PM_INIT_SUSPEND_CB) {
> + if (work_pending(&zynqmp_pm_init_suspend_work->callback_work))
> + goto done;
> +
> + /* Copy callback arguments into work's structure */
> + memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
> + sizeof(zynqmp_pm_init_suspend_work->args));
> +
> + queue_work(system_unbound_wq,
> + &zynqmp_pm_init_suspend_work->callback_work);
We already have devm_request_threaded_irq() which can does this
automatically for us.
Use that method to register the ISR instead, then if there's more
work to do, just do the memcpy and return IRQ_WAKE_THREAD.
> + }
> +
> +done:
> + return IRQ_HANDLED;
> +}
> +
> +/**
> + * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
> + * @work: Pointer to work_struct
> + *
> + * Bottom-half of PM callback IRQ handler.
> + */
> +static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> +{
> + struct zynqmp_pm_work_struct *pm_work =
> + container_of(work, struct zynqmp_pm_work_struct, callback_work);
> +
> + if (pm_work->args[0] == ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
we_really_seem_to_love_long_40_col_names_for_some_reason
> + orderly_poweroff(true);
> + } else if (pm_work->args[0] ==
> + ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
Ditto
[...]
> +/**
> + * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
> + * @dev: Pointer to device structure
> + *
> + * Return: 0 on success, negative error code otherwise
> + */
> +static int zynqmp_pm_sysfs_init(struct device *dev)
> +{
> + return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr);
> +}
> +
Sysfs file is created in platform driver's probe(), but is not
removed anywhere in the code.
What happens if this is built as a module? Am I missing something
obvious?
Moreover, what's the wisdom of creating a one-liner function with
a huge six-line comment that:
a) _purely_ wraps sysfs_create_file(); no extra logic
b) is called only once
c) and not passed as a function pointer anywhere
IMO Such one-liner translators obfuscate the code and review
process with no apparent gain..
> +/**
> + * zynqmp_pm_probe() - Probe existence of the PMU Firmware
> + * and initialize debugfs interface
> + *
> + * @pdev: Pointer to the platform_device structure
> + *
> + * Return: Returns 0 on success, negative error code otherwise
> + */
Again, huge 8-line comment that provide no value.
If anyone wants to know what a platform driver probe() does, he
or she better check the primary references at:
- Documentation/driver-model/platform.txt
- include/linux/platform_device.h
and not the comment above..
> +static int zynqmp_pm_probe(struct platform_device *pdev)
> +{
> + int ret, irq;
> + u32 pm_api_version;
> +
> + const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
> +
> + if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize)
> + return -ENXIO;
> +
> + eemi_ops->init_finalize();
> + eemi_ops->get_api_version(&pm_api_version);
> +
> + /* Check PM API version number */
> + if (pm_api_version < ZYNQMP_PM_VERSION)
> + return -ENODEV;
> +
> + irq = platform_get_irq(pdev, 0);
> + if (irq <= 0)
> + return -ENXIO;
> +
> + ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr, IRQF_SHARED,
> + dev_name(&pdev->dev), pdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
> + irq, ret);
> + return ret;
> + }
> +
> + zynqmp_pm_init_suspend_work =
> + devm_kzalloc(&pdev->dev, sizeof(struct zynqmp_pm_work_struct),
> + GFP_KERNEL);
> + if (!zynqmp_pm_init_suspend_work)
> + return -ENOMEM;
> +
> + INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
> + zynqmp_pm_init_suspend_work_fn);
> +
Let's use devm_request_threaded_irq(). Then we can completely
remove the work_struct, INIT_WORK(), and queuue_work() bits.
> + ret = zynqmp_pm_sysfs_init(&pdev->dev);
> + if (ret) {
> + dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
> + return ret;
> + }
> +
> + return ret;
Just return 0 please. BTW ret was declared without initialization.
> +}
> +
> +static const struct of_device_id pm_of_match[] = {
> + { .compatible = "xlnx,zynqmp-power", },
> + { /* end of table */ },
> +};
> +MODULE_DEVICE_TABLE(of, pm_of_match);
> +
> +static struct platform_driver zynqmp_pm_platform_driver = {
> + .probe = zynqmp_pm_probe,
> + .driver = {
> + .name = "zynqmp_power",
> + .of_match_table = pm_of_match,
> + },
> +};
.remove with a basic sysfs_remove_file() is needed.
Thanks,
--
Darwi
http://darwish.chasingpointers.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
@ 2018-09-12 1:10 ` Ahmed S. Darwish
0 siblings, 0 replies; 17+ messages in thread
From: Ahmed S. Darwish @ 2018-09-12 1:10 UTC (permalink / raw)
To: linux-arm-kernel
Hi!
[ Thanks a lot for upstreaming this.. ]
On Tue, Sep 11, 2018 at 02:34:57PM -0700, Jolly Shah wrote:
> From: Rajan Vaja <rajan.vaja@xilinx.com>
>
> Add ZynqMP PM driver. PM driver provides power management
> support for ZynqMP.
>
> Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
> Signed-off-by: Jolly Shah <jollys@xilinx.com>
> ---
[...]
> +static irqreturn_t zynqmp_pm_isr(int irq, void *data)
> +{
> + u32 payload[CB_PAYLOAD_SIZE];
> +
> + zynqmp_pm_get_callback_data(payload);
> +
> + /* First element is callback API ID, others are callback arguments */
> + if (payload[0] == PM_INIT_SUSPEND_CB) {
> + if (work_pending(&zynqmp_pm_init_suspend_work->callback_work))
> + goto done;
> +
> + /* Copy callback arguments into work's structure */
> + memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
> + sizeof(zynqmp_pm_init_suspend_work->args));
> +
> + queue_work(system_unbound_wq,
> + &zynqmp_pm_init_suspend_work->callback_work);
We already have devm_request_threaded_irq() which can does this
automatically for us.
Use that method to register the ISR instead, then if there's more
work to do, just do the memcpy and return IRQ_WAKE_THREAD.
> + }
> +
> +done:
> + return IRQ_HANDLED;
> +}
> +
> +/**
> + * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
> + * @work: Pointer to work_struct
> + *
> + * Bottom-half of PM callback IRQ handler.
> + */
> +static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> +{
> + struct zynqmp_pm_work_struct *pm_work =
> + container_of(work, struct zynqmp_pm_work_struct, callback_work);
> +
> + if (pm_work->args[0] == ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
we_really_seem_to_love_long_40_col_names_for_some_reason
> + orderly_poweroff(true);
> + } else if (pm_work->args[0] ==
> + ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
Ditto
[...]
> +/**
> + * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
> + * @dev: Pointer to device structure
> + *
> + * Return: 0 on success, negative error code otherwise
> + */
> +static int zynqmp_pm_sysfs_init(struct device *dev)
> +{
> + return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr);
> +}
> +
Sysfs file is created in platform driver's probe(), but is not
removed anywhere in the code.
What happens if this is built as a module? Am I missing something
obvious?
Moreover, what's the wisdom of creating a one-liner function with
a huge six-line comment that:
a) _purely_ wraps sysfs_create_file(); no extra logic
b) is called only once
c) and not passed as a function pointer anywhere
IMO Such one-liner translators obfuscate the code and review
process with no apparent gain..
> +/**
> + * zynqmp_pm_probe() - Probe existence of the PMU Firmware
> + * and initialize debugfs interface
> + *
> + * @pdev: Pointer to the platform_device structure
> + *
> + * Return: Returns 0 on success, negative error code otherwise
> + */
Again, huge 8-line comment that provide no value.
If anyone wants to know what a platform driver probe() does, he
or she better check the primary references at:
- Documentation/driver-model/platform.txt
- include/linux/platform_device.h
and not the comment above..
> +static int zynqmp_pm_probe(struct platform_device *pdev)
> +{
> + int ret, irq;
> + u32 pm_api_version;
> +
> + const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
> +
> + if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize)
> + return -ENXIO;
> +
> + eemi_ops->init_finalize();
> + eemi_ops->get_api_version(&pm_api_version);
> +
> + /* Check PM API version number */
> + if (pm_api_version < ZYNQMP_PM_VERSION)
> + return -ENODEV;
> +
> + irq = platform_get_irq(pdev, 0);
> + if (irq <= 0)
> + return -ENXIO;
> +
> + ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr, IRQF_SHARED,
> + dev_name(&pdev->dev), pdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
> + irq, ret);
> + return ret;
> + }
> +
> + zynqmp_pm_init_suspend_work =
> + devm_kzalloc(&pdev->dev, sizeof(struct zynqmp_pm_work_struct),
> + GFP_KERNEL);
> + if (!zynqmp_pm_init_suspend_work)
> + return -ENOMEM;
> +
> + INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
> + zynqmp_pm_init_suspend_work_fn);
> +
Let's use devm_request_threaded_irq(). Then we can completely
remove the work_struct, INIT_WORK(), and queuue_work() bits.
> + ret = zynqmp_pm_sysfs_init(&pdev->dev);
> + if (ret) {
> + dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
> + return ret;
> + }
> +
> + return ret;
Just return 0 please. BTW ret was declared without initialization.
> +}
> +
> +static const struct of_device_id pm_of_match[] = {
> + { .compatible = "xlnx,zynqmp-power", },
> + { /* end of table */ },
> +};
> +MODULE_DEVICE_TABLE(of, pm_of_match);
> +
> +static struct platform_driver zynqmp_pm_platform_driver = {
> + .probe = zynqmp_pm_probe,
> + .driver = {
> + .name = "zynqmp_power",
> + .of_match_table = pm_of_match,
> + },
> +};
.remove with a basic sysfs_remove_file() is needed.
Thanks,
--
Darwi
http://darwish.chasingpointers.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
2018-09-12 1:10 ` Ahmed S. Darwish
(?)
@ 2018-09-13 17:11 ` Jolly Shah
-1 siblings, 0 replies; 17+ messages in thread
From: Jolly Shah @ 2018-09-13 17:11 UTC (permalink / raw)
To: Ahmed S. Darwish
Cc: matthias.bgg, andy.gross, shawnguo, geert+renesas,
bjorn.andersson, sean.wang, m.szyprowski, Michal Simek, robh+dt,
mark.rutland, Rajan Vaja, devicetree, linux-arm-kernel,
linux-kernel, Rajan Vaja
Hi Ahmed,
Thanks for the review. I will take care of suggested changes in next version.
Thanks,
Jolly Shah
> -----Original Message-----
> From: Ahmed S. Darwish [mailto:darwish.07@gmail.com]
> Sent: Tuesday, September 11, 2018 6:10 PM
> To: Jolly Shah <JOLLYS@xilinx.com>
> Cc: matthias.bgg@gmail.com; andy.gross@linaro.org; shawnguo@kernel.org;
> geert+renesas@glider.be; bjorn.andersson@linaro.org;
> sean.wang@mediatek.com; m.szyprowski@samsung.com; Michal Simek
> <michals@xilinx.com>; robh+dt@kernel.org; mark.rutland@arm.com; Rajan
> Vaja <RAJANV@xilinx.com>; devicetree@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Rajan Vaja
> <RAJANV@xilinx.com>; Jolly Shah <JOLLYS@xilinx.com>
> Subject: Re: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
>
> Hi!
>
> [ Thanks a lot for upstreaming this.. ]
>
> On Tue, Sep 11, 2018 at 02:34:57PM -0700, Jolly Shah wrote:
> > From: Rajan Vaja <rajan.vaja@xilinx.com>
> >
> > Add ZynqMP PM driver. PM driver provides power management support for
> > ZynqMP.
> >
> > Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
> > Signed-off-by: Jolly Shah <jollys@xilinx.com>
> > ---
>
> [...]
>
> > +static irqreturn_t zynqmp_pm_isr(int irq, void *data) {
> > + u32 payload[CB_PAYLOAD_SIZE];
> > +
> > + zynqmp_pm_get_callback_data(payload);
> > +
> > + /* First element is callback API ID, others are callback arguments */
> > + if (payload[0] == PM_INIT_SUSPEND_CB) {
> > + if (work_pending(&zynqmp_pm_init_suspend_work-
> >callback_work))
> > + goto done;
> > +
> > + /* Copy callback arguments into work's structure */
> > + memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
> > + sizeof(zynqmp_pm_init_suspend_work->args));
> > +
> > + queue_work(system_unbound_wq,
> > + &zynqmp_pm_init_suspend_work->callback_work);
>
> We already have devm_request_threaded_irq() which can does this
> automatically for us.
>
> Use that method to register the ISR instead, then if there's more work to do, just
> do the memcpy and return IRQ_WAKE_THREAD.
>
> > + }
> > +
> > +done:
> > + return IRQ_HANDLED;
> > +}
> > +
> > +/**
> > + * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
> > + * @work: Pointer to work_struct
> > + *
> > + * Bottom-half of PM callback IRQ handler.
> > + */
> > +static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> > +{
> > + struct zynqmp_pm_work_struct *pm_work =
> > + container_of(work, struct zynqmp_pm_work_struct,
> callback_work);
> > +
> > + if (pm_work->args[0] ==
> ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
>
> we_really_seem_to_love_long_40_col_names_for_some_reason
>
> > + orderly_poweroff(true);
> > + } else if (pm_work->args[0] ==
> > + ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
>
> Ditto
>
> [...]
>
> > +/**
> > + * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
> > + * @dev: Pointer to device structure
> > + *
> > + * Return: 0 on success, negative error code otherwise */ static int
> > +zynqmp_pm_sysfs_init(struct device *dev) {
> > + return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr); }
> > +
>
> Sysfs file is created in platform driver's probe(), but is not removed anywhere in
> the code.
>
> What happens if this is built as a module? Am I missing something obvious?
>
> Moreover, what's the wisdom of creating a one-liner function with a huge six-
> line comment that:
>
> a) _purely_ wraps sysfs_create_file(); no extra logic
> b) is called only once
> c) and not passed as a function pointer anywhere
>
> IMO Such one-liner translators obfuscate the code and review process with no
> apparent gain..
>
> > +/**
> > + * zynqmp_pm_probe() - Probe existence of the PMU Firmware
> > + * and initialize debugfs interface
> > + *
> > + * @pdev: Pointer to the platform_device structure
> > + *
> > + * Return: Returns 0 on success, negative error code otherwise */
>
> Again, huge 8-line comment that provide no value.
>
> If anyone wants to know what a platform driver probe() does, he or she better
> check the primary references at:
>
> - Documentation/driver-model/platform.txt
> - include/linux/platform_device.h
>
> and not the comment above..
>
> > +static int zynqmp_pm_probe(struct platform_device *pdev) {
> > + int ret, irq;
> > + u32 pm_api_version;
> > +
> > + const struct zynqmp_eemi_ops *eemi_ops =
> zynqmp_pm_get_eemi_ops();
> > +
> > + if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops-
> >init_finalize)
> > + return -ENXIO;
> > +
> > + eemi_ops->init_finalize();
> > + eemi_ops->get_api_version(&pm_api_version);
> > +
> > + /* Check PM API version number */
> > + if (pm_api_version < ZYNQMP_PM_VERSION)
> > + return -ENODEV;
> > +
> > + irq = platform_get_irq(pdev, 0);
> > + if (irq <= 0)
> > + return -ENXIO;
> > +
> > + ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr,
> IRQF_SHARED,
> > + dev_name(&pdev->dev), pdev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
> > + irq, ret);
> > + return ret;
> > + }
> > +
> > + zynqmp_pm_init_suspend_work =
> > + devm_kzalloc(&pdev->dev, sizeof(struct
> zynqmp_pm_work_struct),
> > + GFP_KERNEL);
> > + if (!zynqmp_pm_init_suspend_work)
> > + return -ENOMEM;
> > +
> > + INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
> > + zynqmp_pm_init_suspend_work_fn);
> > +
>
> Let's use devm_request_threaded_irq(). Then we can completely remove the
> work_struct, INIT_WORK(), and queuue_work() bits.
>
> > + ret = zynqmp_pm_sysfs_init(&pdev->dev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
> > + return ret;
> > + }
> > +
> > + return ret;
>
> Just return 0 please. BTW ret was declared without initialization.
>
> > +}
> > +
> > +static const struct of_device_id pm_of_match[] = {
> > + { .compatible = "xlnx,zynqmp-power", },
> > + { /* end of table */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, pm_of_match);
> > +
> > +static struct platform_driver zynqmp_pm_platform_driver = {
> > + .probe = zynqmp_pm_probe,
> > + .driver = {
> > + .name = "zynqmp_power",
> > + .of_match_table = pm_of_match,
> > + },
> > +};
>
> .remove with a basic sysfs_remove_file() is needed.
>
> Thanks,
>
> --
> Darwi
> http://darwish.chasingpointers.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
@ 2018-09-13 17:11 ` Jolly Shah
0 siblings, 0 replies; 17+ messages in thread
From: Jolly Shah @ 2018-09-13 17:11 UTC (permalink / raw)
To: linux-arm-kernel
Hi Ahmed,
Thanks for the review. I will take care of suggested changes in next version.
Thanks,
Jolly Shah
> -----Original Message-----
> From: Ahmed S. Darwish [mailto:darwish.07 at gmail.com]
> Sent: Tuesday, September 11, 2018 6:10 PM
> To: Jolly Shah <JOLLYS@xilinx.com>
> Cc: matthias.bgg at gmail.com; andy.gross at linaro.org; shawnguo at kernel.org;
> geert+renesas at glider.be; bjorn.andersson at linaro.org;
> sean.wang at mediatek.com; m.szyprowski at samsung.com; Michal Simek
> <michals@xilinx.com>; robh+dt at kernel.org; mark.rutland at arm.com; Rajan
> Vaja <RAJANV@xilinx.com>; devicetree at vger.kernel.org; linux-arm-
> kernel at lists.infradead.org; linux-kernel at vger.kernel.org; Rajan Vaja
> <RAJANV@xilinx.com>; Jolly Shah <JOLLYS@xilinx.com>
> Subject: Re: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
>
> Hi!
>
> [ Thanks a lot for upstreaming this.. ]
>
> On Tue, Sep 11, 2018 at 02:34:57PM -0700, Jolly Shah wrote:
> > From: Rajan Vaja <rajan.vaja@xilinx.com>
> >
> > Add ZynqMP PM driver. PM driver provides power management support for
> > ZynqMP.
> >
> > Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
> > Signed-off-by: Jolly Shah <jollys@xilinx.com>
> > ---
>
> [...]
>
> > +static irqreturn_t zynqmp_pm_isr(int irq, void *data) {
> > + u32 payload[CB_PAYLOAD_SIZE];
> > +
> > + zynqmp_pm_get_callback_data(payload);
> > +
> > + /* First element is callback API ID, others are callback arguments */
> > + if (payload[0] == PM_INIT_SUSPEND_CB) {
> > + if (work_pending(&zynqmp_pm_init_suspend_work-
> >callback_work))
> > + goto done;
> > +
> > + /* Copy callback arguments into work's structure */
> > + memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
> > + sizeof(zynqmp_pm_init_suspend_work->args));
> > +
> > + queue_work(system_unbound_wq,
> > + &zynqmp_pm_init_suspend_work->callback_work);
>
> We already have devm_request_threaded_irq() which can does this
> automatically for us.
>
> Use that method to register the ISR instead, then if there's more work to do, just
> do the memcpy and return IRQ_WAKE_THREAD.
>
> > + }
> > +
> > +done:
> > + return IRQ_HANDLED;
> > +}
> > +
> > +/**
> > + * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
> > + * @work: Pointer to work_struct
> > + *
> > + * Bottom-half of PM callback IRQ handler.
> > + */
> > +static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> > +{
> > + struct zynqmp_pm_work_struct *pm_work =
> > + container_of(work, struct zynqmp_pm_work_struct,
> callback_work);
> > +
> > + if (pm_work->args[0] ==
> ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
>
> we_really_seem_to_love_long_40_col_names_for_some_reason
>
> > + orderly_poweroff(true);
> > + } else if (pm_work->args[0] ==
> > + ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
>
> Ditto
>
> [...]
>
> > +/**
> > + * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
> > + * @dev: Pointer to device structure
> > + *
> > + * Return: 0 on success, negative error code otherwise */ static int
> > +zynqmp_pm_sysfs_init(struct device *dev) {
> > + return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr); }
> > +
>
> Sysfs file is created in platform driver's probe(), but is not removed anywhere in
> the code.
>
> What happens if this is built as a module? Am I missing something obvious?
>
> Moreover, what's the wisdom of creating a one-liner function with a huge six-
> line comment that:
>
> a) _purely_ wraps sysfs_create_file(); no extra logic
> b) is called only once
> c) and not passed as a function pointer anywhere
>
> IMO Such one-liner translators obfuscate the code and review process with no
> apparent gain..
>
> > +/**
> > + * zynqmp_pm_probe() - Probe existence of the PMU Firmware
> > + * and initialize debugfs interface
> > + *
> > + * @pdev: Pointer to the platform_device structure
> > + *
> > + * Return: Returns 0 on success, negative error code otherwise */
>
> Again, huge 8-line comment that provide no value.
>
> If anyone wants to know what a platform driver probe() does, he or she better
> check the primary references at:
>
> - Documentation/driver-model/platform.txt
> - include/linux/platform_device.h
>
> and not the comment above..
>
> > +static int zynqmp_pm_probe(struct platform_device *pdev) {
> > + int ret, irq;
> > + u32 pm_api_version;
> > +
> > + const struct zynqmp_eemi_ops *eemi_ops =
> zynqmp_pm_get_eemi_ops();
> > +
> > + if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops-
> >init_finalize)
> > + return -ENXIO;
> > +
> > + eemi_ops->init_finalize();
> > + eemi_ops->get_api_version(&pm_api_version);
> > +
> > + /* Check PM API version number */
> > + if (pm_api_version < ZYNQMP_PM_VERSION)
> > + return -ENODEV;
> > +
> > + irq = platform_get_irq(pdev, 0);
> > + if (irq <= 0)
> > + return -ENXIO;
> > +
> > + ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr,
> IRQF_SHARED,
> > + dev_name(&pdev->dev), pdev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
> > + irq, ret);
> > + return ret;
> > + }
> > +
> > + zynqmp_pm_init_suspend_work =
> > + devm_kzalloc(&pdev->dev, sizeof(struct
> zynqmp_pm_work_struct),
> > + GFP_KERNEL);
> > + if (!zynqmp_pm_init_suspend_work)
> > + return -ENOMEM;
> > +
> > + INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
> > + zynqmp_pm_init_suspend_work_fn);
> > +
>
> Let's use devm_request_threaded_irq(). Then we can completely remove the
> work_struct, INIT_WORK(), and queuue_work() bits.
>
> > + ret = zynqmp_pm_sysfs_init(&pdev->dev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
> > + return ret;
> > + }
> > +
> > + return ret;
>
> Just return 0 please. BTW ret was declared without initialization.
>
> > +}
> > +
> > +static const struct of_device_id pm_of_match[] = {
> > + { .compatible = "xlnx,zynqmp-power", },
> > + { /* end of table */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, pm_of_match);
> > +
> > +static struct platform_driver zynqmp_pm_platform_driver = {
> > + .probe = zynqmp_pm_probe,
> > + .driver = {
> > + .name = "zynqmp_power",
> > + .of_match_table = pm_of_match,
> > + },
> > +};
>
> .remove with a basic sysfs_remove_file() is needed.
>
> Thanks,
>
> --
> Darwi
> http://darwish.chasingpointers.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
@ 2018-09-13 17:11 ` Jolly Shah
0 siblings, 0 replies; 17+ messages in thread
From: Jolly Shah @ 2018-09-13 17:11 UTC (permalink / raw)
To: Ahmed S. Darwish
Cc: matthias.bgg, andy.gross, shawnguo, geert+renesas,
bjorn.andersson, sean.wang, m.szyprowski, Michal Simek, robh+dt,
mark.rutland, Rajan Vaja, devicetree, linux-arm-kernel,
linux-kernel
Hi Ahmed,
Thanks for the review. I will take care of suggested changes in next version.
Thanks,
Jolly Shah
> -----Original Message-----
> From: Ahmed S. Darwish [mailto:darwish.07@gmail.com]
> Sent: Tuesday, September 11, 2018 6:10 PM
> To: Jolly Shah <JOLLYS@xilinx.com>
> Cc: matthias.bgg@gmail.com; andy.gross@linaro.org; shawnguo@kernel.org;
> geert+renesas@glider.be; bjorn.andersson@linaro.org;
> sean.wang@mediatek.com; m.szyprowski@samsung.com; Michal Simek
> <michals@xilinx.com>; robh+dt@kernel.org; mark.rutland@arm.com; Rajan
> Vaja <RAJANV@xilinx.com>; devicetree@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Rajan Vaja
> <RAJANV@xilinx.com>; Jolly Shah <JOLLYS@xilinx.com>
> Subject: Re: [PATCH v3 3/3] drivers: soc: xilinx: Add ZynqMP PM driver
>
> Hi!
>
> [ Thanks a lot for upstreaming this.. ]
>
> On Tue, Sep 11, 2018 at 02:34:57PM -0700, Jolly Shah wrote:
> > From: Rajan Vaja <rajan.vaja@xilinx.com>
> >
> > Add ZynqMP PM driver. PM driver provides power management support for
> > ZynqMP.
> >
> > Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
> > Signed-off-by: Jolly Shah <jollys@xilinx.com>
> > ---
>
> [...]
>
> > +static irqreturn_t zynqmp_pm_isr(int irq, void *data) {
> > + u32 payload[CB_PAYLOAD_SIZE];
> > +
> > + zynqmp_pm_get_callback_data(payload);
> > +
> > + /* First element is callback API ID, others are callback arguments */
> > + if (payload[0] == PM_INIT_SUSPEND_CB) {
> > + if (work_pending(&zynqmp_pm_init_suspend_work-
> >callback_work))
> > + goto done;
> > +
> > + /* Copy callback arguments into work's structure */
> > + memcpy(zynqmp_pm_init_suspend_work->args, &payload[1],
> > + sizeof(zynqmp_pm_init_suspend_work->args));
> > +
> > + queue_work(system_unbound_wq,
> > + &zynqmp_pm_init_suspend_work->callback_work);
>
> We already have devm_request_threaded_irq() which can does this
> automatically for us.
>
> Use that method to register the ISR instead, then if there's more work to do, just
> do the memcpy and return IRQ_WAKE_THREAD.
>
> > + }
> > +
> > +done:
> > + return IRQ_HANDLED;
> > +}
> > +
> > +/**
> > + * zynqmp_pm_init_suspend_work_fn() - Initialize suspend
> > + * @work: Pointer to work_struct
> > + *
> > + * Bottom-half of PM callback IRQ handler.
> > + */
> > +static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> > +{
> > + struct zynqmp_pm_work_struct *pm_work =
> > + container_of(work, struct zynqmp_pm_work_struct,
> callback_work);
> > +
> > + if (pm_work->args[0] ==
> ZYNQMP_PM_SUSPEND_REASON_SYSTEM_SHUTDOWN) {
>
> we_really_seem_to_love_long_40_col_names_for_some_reason
>
> > + orderly_poweroff(true);
> > + } else if (pm_work->args[0] ==
> > + ZYNQMP_PM_SUSPEND_REASON_POWER_UNIT_REQUEST) {
>
> Ditto
>
> [...]
>
> > +/**
> > + * zynqmp_pm_sysfs_init() - Initialize PM driver sysfs interface
> > + * @dev: Pointer to device structure
> > + *
> > + * Return: 0 on success, negative error code otherwise */ static int
> > +zynqmp_pm_sysfs_init(struct device *dev) {
> > + return sysfs_create_file(&dev->kobj, &dev_attr_suspend_mode.attr); }
> > +
>
> Sysfs file is created in platform driver's probe(), but is not removed anywhere in
> the code.
>
> What happens if this is built as a module? Am I missing something obvious?
>
> Moreover, what's the wisdom of creating a one-liner function with a huge six-
> line comment that:
>
> a) _purely_ wraps sysfs_create_file(); no extra logic
> b) is called only once
> c) and not passed as a function pointer anywhere
>
> IMO Such one-liner translators obfuscate the code and review process with no
> apparent gain..
>
> > +/**
> > + * zynqmp_pm_probe() - Probe existence of the PMU Firmware
> > + * and initialize debugfs interface
> > + *
> > + * @pdev: Pointer to the platform_device structure
> > + *
> > + * Return: Returns 0 on success, negative error code otherwise */
>
> Again, huge 8-line comment that provide no value.
>
> If anyone wants to know what a platform driver probe() does, he or she better
> check the primary references at:
>
> - Documentation/driver-model/platform.txt
> - include/linux/platform_device.h
>
> and not the comment above..
>
> > +static int zynqmp_pm_probe(struct platform_device *pdev) {
> > + int ret, irq;
> > + u32 pm_api_version;
> > +
> > + const struct zynqmp_eemi_ops *eemi_ops =
> zynqmp_pm_get_eemi_ops();
> > +
> > + if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops-
> >init_finalize)
> > + return -ENXIO;
> > +
> > + eemi_ops->init_finalize();
> > + eemi_ops->get_api_version(&pm_api_version);
> > +
> > + /* Check PM API version number */
> > + if (pm_api_version < ZYNQMP_PM_VERSION)
> > + return -ENODEV;
> > +
> > + irq = platform_get_irq(pdev, 0);
> > + if (irq <= 0)
> > + return -ENXIO;
> > +
> > + ret = devm_request_irq(&pdev->dev, irq, zynqmp_pm_isr,
> IRQF_SHARED,
> > + dev_name(&pdev->dev), pdev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "request_irq '%d' failed with %d\n",
> > + irq, ret);
> > + return ret;
> > + }
> > +
> > + zynqmp_pm_init_suspend_work =
> > + devm_kzalloc(&pdev->dev, sizeof(struct
> zynqmp_pm_work_struct),
> > + GFP_KERNEL);
> > + if (!zynqmp_pm_init_suspend_work)
> > + return -ENOMEM;
> > +
> > + INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
> > + zynqmp_pm_init_suspend_work_fn);
> > +
>
> Let's use devm_request_threaded_irq(). Then we can completely remove the
> work_struct, INIT_WORK(), and queuue_work() bits.
>
> > + ret = zynqmp_pm_sysfs_init(&pdev->dev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "unable to initialize sysfs interface\n");
> > + return ret;
> > + }
> > +
> > + return ret;
>
> Just return 0 please. BTW ret was declared without initialization.
>
> > +}
> > +
> > +static const struct of_device_id pm_of_match[] = {
> > + { .compatible = "xlnx,zynqmp-power", },
> > + { /* end of table */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, pm_of_match);
> > +
> > +static struct platform_driver zynqmp_pm_platform_driver = {
> > + .probe = zynqmp_pm_probe,
> > + .driver = {
> > + .name = "zynqmp_power",
> > + .of_match_table = pm_of_match,
> > + },
> > +};
>
> .remove with a basic sysfs_remove_file() is needed.
>
> Thanks,
>
> --
> Darwi
> http://darwish.chasingpointers.com
^ permalink raw reply [flat|nested] 17+ messages in thread