Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fbfa686 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: npu: Notify AOP when NPU powers up and down"

parents 9a14e377 4ed311b8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -67,8 +67,8 @@
		vdd_cx-supply = <&VDD_CX_LEVEL>;
		qcom,proxy-reg-names ="vdd", "vdd_cx";
		qcom,vdd_cx-uV-uA = <RPMH_REGULATOR_LEVEL_TURBO 100000>;
		mboxes = <&qmp_npu0 0>, <&qmp_npu1 0>;
		mbox-names = "npu_low", "npu_high";
		mboxes = <&qmp_aop 0>;
		mbox-names = "aop";
		#cooling-cells = <2>;
		qcom,npubw-dev = <&npu_npu_ddr_bw>;
		qcom,npu-pwrlevels {
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/uaccess.h>
#include <linux/mailbox/qmp.h>

#include "npu_mgr.h"

@@ -198,7 +199,7 @@ struct npu_device {
	struct npu_smmu_ctx smmu_ctx;
	struct npu_debugfs_ctx debugfs_ctx;

	struct npu_mbox mbox[NPU_MAX_MBOX_NUM];
	struct npu_mbox mbox_aop;

	struct thermal_cooling_device *tcdev;
	struct npu_pwrctrl pwrctrl;
+33 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#define DDR_MAPPED_SIZE         0x60000000

#define PERF_MODE_DEFAULT 0
#define MBOX_OP_TIMEOUTMS 1000

/* -------------------------------------------------------------------------
 * File Scope Prototypes
@@ -1524,6 +1525,29 @@ static int npu_irq_init(struct npu_device *npu_dev)
	return ret;
}

static int npu_mbox_init(struct npu_device *npu_dev)
{
	struct platform_device *pdev = npu_dev->pdev;
	struct npu_mbox *mbox_aop = &npu_dev->mbox_aop;
	int ret = 0;

	if (of_find_property(pdev->dev.of_node, "mboxes", NULL)) {
		mbox_aop->client.dev = &pdev->dev;
		mbox_aop->client.tx_block = true;
		mbox_aop->client.tx_tout = MBOX_OP_TIMEOUTMS;
		mbox_aop->client.knows_txdone = false;

		mbox_aop->chan = mbox_request_channel(&mbox_aop->client, 0);
		if (IS_ERR(mbox_aop->chan)) {
			ret = PTR_ERR(mbox_aop->chan);
			pr_err("mailbox channel request failed, ret=%d\n", ret);
			mbox_aop->chan = NULL;
		}
	}

	return ret;
}

/* -------------------------------------------------------------------------
 * Probe/Remove
 * -------------------------------------------------------------------------
@@ -1572,6 +1596,10 @@ static int npu_probe(struct platform_device *pdev)
	if (rc)
		goto error_get_dev_num;

	rc = npu_mbox_init(npu_dev);
	if (rc)
		goto error_get_dev_num;

	npu_dev->npu_base = devm_ioremap(&pdev->dev, res->start,
					npu_dev->reg_size);
	if (unlikely(!npu_dev->npu_base)) {
@@ -1680,6 +1708,8 @@ static int npu_probe(struct platform_device *pdev)
	class_destroy(npu_dev->class);
error_class_create:
	unregister_chrdev_region(npu_dev->dev_num, 1);
	if (npu_dev->mbox_aop.chan)
		mbox_free_channel(npu_dev->mbox_aop.chan);
error_get_dev_num:
	return rc;
}
@@ -1700,6 +1730,9 @@ static int npu_remove(struct platform_device *pdev)
	class_destroy(npu_dev->class);
	unregister_chrdev_region(npu_dev->dev_num, 1);
	platform_set_drvdata(pdev, NULL);
	if (npu_dev->mbox_aop.chan)
		mbox_free_channel(npu_dev->mbox_aop.chan);

	return 0;
}

+37 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ static int npu_send_misc_cmd(struct npu_device *npu_dev, uint32_t q_idx,
	void *cmd_ptr);
static int npu_queue_event(struct npu_client *client, struct npu_kevent *evt);
static int npu_notify_dsp(struct npu_device *npu_dev, bool pwr_up);
static int npu_notify_aop(struct npu_device *npu_dev, bool on);

/* -------------------------------------------------------------------------
 * Function Definitions - Init / Deinit
@@ -78,6 +79,8 @@ int fw_init(struct npu_device *npu_dev)
		return 0;
	}

	npu_notify_aop(npu_dev, true);

	if (npu_enable_core_power(npu_dev)) {
		ret = -EPERM;
		goto enable_pw_fail;
@@ -263,6 +266,8 @@ void fw_deinit(struct npu_device *npu_dev, bool ssr)
	complete(&host_ctx->fw_deinit_done);
	mutex_unlock(&host_ctx->lock);
	pr_debug("firmware deinit complete\n");
	npu_notify_aop(npu_dev, false);

	return;
}

@@ -447,6 +452,38 @@ static int npu_notify_dsp(struct npu_device *npu_dev, bool pwr_up)
	return ret;
}

#define MAX_LEN 128

static int npu_notify_aop(struct npu_device *npu_dev, bool on)
{
	char buf[MAX_LEN];
	struct qmp_pkt pkt;
	int buf_size, rc = 0;

	if (!npu_dev->mbox_aop.chan) {
		pr_warn("aop mailbox channel is not available\n");
		return 0;
	}

	buf_size = snprintf(buf, MAX_LEN, "{class: bcm, res: npu_on, val: %d}",
		on ? 1 : 0);
	if (buf_size < 0) {
		pr_err("prepare qmp notify buf failed\n");
		return -EINVAL;
	}

	pr_debug("send msg %s to aop\n", buf);
	memset(&pkt, 0, sizeof(pkt));
	pkt.size = (buf_size + 3) & ~0x3;
	pkt.data = buf;

	rc = mbox_send_message(npu_dev->mbox_aop.chan, &pkt);
	if (rc < 0)
		pr_err("qmp message send failed, ret=%d\n", rc);

	return rc;
}

/* -------------------------------------------------------------------------
 * Function Definitions - Network Management
 * -------------------------------------------------------------------------