@@ -222,6 +222,9 @@ int ethosu_buffer_create(struct ethosu_device *edev,
struct ethosu_buffer *buf;
int ret = -ENOMEM;
+ if (!capacity)
+ return -EINVAL;
+
buf = devm_kzalloc(edev->dev, sizeof(*buf), GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -60,6 +60,8 @@ enum ethosu_core_msg_type {
ETHOSU_CORE_MSG_VERSION_RSP,
ETHOSU_CORE_MSG_CAPABILITIES_REQ,
ETHOSU_CORE_MSG_CAPABILITIES_RSP,
+ ETHOSU_CORE_MSG_POWER_REQ,
+ ETHOSU_CORE_MSG_POWER_RSP,
ETHOSU_CORE_MSG_MAX
};
@@ -161,6 +163,18 @@ struct ethosu_core_msg_capabilities_rsp {
uint32_t custom_dma;
};
+enum ethosu_core_power_req_type {
+ ETHOSU_CORE_POWER_REQ_SUSPEND = 0,
+ ETHOSU_CORE_POWER_REQ_RESUME
+};
+
+/**
+ * struct ethosu_core_power_req - Message power request
+ */
+struct ethosu_core_power_req {
+ enum ethosu_core_power_req_type type;
+};
+
/**
* enum ethosu_core_msg_err_type - Error types
*/
@@ -38,6 +38,7 @@
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/of_reserved_mem.h>
+#include <linux/remoteproc.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
@@ -49,6 +50,8 @@
#define CAPABILITIES_RESP_TIMEOUT_MS 2000
+#define ETHOSU_FIRMWARE_NAME "ethosu_firmware"
+
/****************************************************************************
* Types
****************************************************************************/
@@ -161,6 +164,9 @@ static int ethosu_handle_msg(struct ethosu_device *edev, void *data)
case ETHOSU_CORE_MSG_PONG:
dev_info(edev->dev, "Msg: Pong\n");
break;
+ case ETHOSU_CORE_MSG_POWER_RSP:
+ dev_info(edev->dev, "Msg: Power response\n");
+ break;
case ETHOSU_CORE_MSG_INFERENCE_RSP:
if (header->length != sizeof(struct ethosu_core_inference_rsp)) {
dev_warn(edev->dev,
@@ -243,11 +249,41 @@ static int ethosu_open(struct inode *inode,
{
struct ethosu_device *edev =
container_of(inode->i_cdev, struct ethosu_device, cdev);
+ phandle rproc_phandle;
+ struct rproc *rproc;
+ int ret = 0;
file->private_data = edev;
dev_info(edev->dev, "Opening device node.\n");
+ if (of_property_read_u32(edev->dev->of_node, "fsl,cm33-proc",
+ &rproc_phandle)) {
+ dev_err(edev->dev, "could not get rproc phandle\n");
+ return -ENODEV;
+ }
+
+ rproc = rproc_get_by_phandle(rproc_phandle);
+ if (!rproc) {
+ dev_err(edev->dev, "could not get rproc handle\n");
+ return -EINVAL;
+ }
+
+ ret = rproc_set_firmware(rproc, ETHOSU_FIRMWARE_NAME);
+
+ if (!ret && atomic_read(&rproc->power) == 0) {
+ init_completion(&edev->erp.rpmsg_ready);
+ ret = rproc_boot(rproc);
+ if (ret)
+ dev_err(edev->dev, "could not boot a remote processor\n");
+ else
+ wait_for_completion_interruptible(&edev->erp.rpmsg_ready);
+ } else {
+ dev_err(edev->dev, "can't change firmware or remote processor is running\n");
+ }
+
+ edev->open = true;
+
return nonseekable_open(inode, file);
}
@@ -51,6 +51,7 @@ struct ethosu_device {
struct ethosu_rpmsg erp;
struct list_head capabilities_list;
struct list_head inference_list;
+ bool open;
};
/**
@@ -83,4 +84,13 @@ int ethosu_dev_init(struct ethosu_device *edev,
*/
void ethosu_dev_deinit(struct ethosu_device *edev);
+/**
+ * ethosu_suspend() - Suspend the device
+ */
+int ethosu_suspend(struct device *dev);
+/**
+ * ethosu_resume() - Resume the device
+ */
+int ethosu_resume(struct device *dev);
+
#endif /* ETHOSU_DEVICE_H */
@@ -27,6 +27,7 @@
#include <linux/of_address.h>
#include <linux/platform_device.h>
+#include "ethosu_core_interface.h"
#include "ethosu_device.h"
/****************************************************************************
@@ -101,6 +102,33 @@ static int ethosu_pdev_remove(struct platform_device *pdev)
return 0;
}
+int ethosu_suspend(struct device *dev)
+{
+ struct ethosu_device *edev = dev->driver_data;
+ int ret = 0;
+
+ if (edev->open)
+ ret = ethosu_rpmsg_power_request(&edev->erp, ETHOSU_CORE_POWER_REQ_SUSPEND);
+
+ return ret;
+}
+
+int ethosu_resume(struct device *dev)
+{
+ struct ethosu_device *edev = dev->driver_data;
+ int ret = 0;
+
+ if (edev->open)
+ ret = ethosu_rpmsg_power_request(&edev->erp, ETHOSU_CORE_POWER_REQ_RESUME);
+
+ return ret;
+}
+
+struct dev_pm_ops ethosu_pm_ops = {
+ .suspend = ethosu_suspend,
+ .resume = ethosu_resume,
+};
+
static const struct of_device_id ethosu_pdev_match[] = {
{ .compatible = "arm,ethosu" },
{ /* Sentinel */ },
@@ -115,6 +143,7 @@ static struct platform_driver ethosu_pdev_driver = {
.name = ETHOSU_DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(ethosu_pdev_match),
+ .pm = ðosu_pm_ops,
},
};
@@ -98,6 +98,35 @@ int ethosu_rpmsg_capabilities_request(struct ethosu_rpmsg *erp, void *user_arg)
return 0;
}
+int ethosu_rpmsg_power_request(struct ethosu_rpmsg *erp,
+ enum ethosu_core_power_req_type power_type)
+{
+ struct ethosu_core_msg msg = {
+ .magic = ETHOSU_CORE_MSG_MAGIC,
+ .type = ETHOSU_CORE_MSG_POWER_REQ,
+ .length = sizeof(struct ethosu_core_power_req)
+ };
+ struct ethosu_core_power_req req;
+ struct rpmsg_device *rpdev = erp->rpdev;
+ uint8_t data[sizeof(struct ethosu_core_msg) +
+ sizeof(struct ethosu_core_power_req)];
+ int ret;
+
+ req.type = power_type;
+ memcpy(data, &msg, sizeof(struct ethosu_core_msg));
+ memcpy(data + sizeof(struct ethosu_core_msg), &req,
+ sizeof(struct ethosu_core_power_req));
+
+ ret = rpmsg_send(rpdev->ept, (void *)&data,
+ sizeof(struct ethosu_core_msg) +
+ sizeof(struct ethosu_core_power_req));
+ if (ret) {
+ dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
+ return ret;
+ }
+ return 0;
+}
+
int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
void *user_arg,
uint32_t ifm_count,
@@ -193,6 +222,7 @@ static int ethosu_rpmsg_probe(struct rpmsg_device *rpdev)
if (ret) {
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
}
+ complete(&grp->rpmsg_ready);
return 0;
}
@@ -7,6 +7,8 @@
#define ETHOSU_RPMSG_H
#include <linux/types.h>
+#include <linux/completion.h>
+#include "ethosu_core_interface.h"
struct device;
struct ethosu_buffer;
@@ -19,6 +21,7 @@ struct ethosu_rpmsg {
struct rpmsg_device *rpdev;
ethosu_rpmsg_cb callback;
void *user_arg;
+ struct completion rpmsg_ready;
};
/**
* ethosu_rpmsg_ping() - Send ping message
@@ -49,6 +52,14 @@ int ethosu_rpmsg_version_request(struct ethosu_rpmsg *erp);
int ethosu_rpmsg_capabilities_request(struct ethosu_rpmsg *erp,
void *user_arg);
+/**
+ * ethosu_rpmsg_power_request - Send power request
+ *
+ * Return: 0 on success, else error code
+ */
+int ethosu_rpmsg_power_request(struct ethosu_rpmsg *erp,
+ enum ethosu_core_power_req_type power_type);
+
/**
* ethosu_rpmsg_inference() - Send inference
*