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

Commit 2b36de55 authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Use worker thread to update thermal state



Thermal framework will update thermal state in its interrupt
thread, so the update in npu driver needs to be moved to worker
thread.

Change-Id: Ib06eb336f0caee21374c6c3b33976163dcc3d045
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 547f42d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -319,6 +319,7 @@ irqreturn_t npu_wdg_intr_hdlr(int irq, void *ptr);


int npu_set_uc_power_level(struct npu_device *npu_dev,
int npu_set_uc_power_level(struct npu_device *npu_dev,
	uint32_t pwr_level);
	uint32_t pwr_level);
int npu_set_power_level(struct npu_device *npu_dev, bool notify_cxlimit);


int enable_fw(struct npu_device *npu_dev);
int enable_fw(struct npu_device *npu_dev);
void disable_fw(struct npu_device *npu_dev);
void disable_fw(struct npu_device *npu_dev);
+2 −10
Original line number Original line Diff line number Diff line
@@ -101,7 +101,6 @@ static int npu_suspend(struct platform_device *dev, pm_message_t state);
static int npu_resume(struct platform_device *dev);
static int npu_resume(struct platform_device *dev);
static int __init npu_init(void);
static int __init npu_init(void);
static void __exit npu_exit(void);
static void __exit npu_exit(void);
static int npu_set_power_level(struct npu_device *npu_dev, bool notify_cxlimit);


/* -------------------------------------------------------------------------
/* -------------------------------------------------------------------------
 * File Scope Variables
 * File Scope Variables
@@ -458,7 +457,7 @@ static uint32_t npu_calc_power_level(struct npu_device *npu_dev)
	return ret_level;
	return ret_level;
}
}


static int npu_set_power_level(struct npu_device *npu_dev, bool notify_cxlimit)
int npu_set_power_level(struct npu_device *npu_dev, bool notify_cxlimit)
{
{
	struct npu_pwrctrl *pwr = &npu_dev->pwrctrl;
	struct npu_pwrctrl *pwr = &npu_dev->pwrctrl;
	struct npu_pwrlevel *pwrlevel;
	struct npu_pwrlevel *pwrlevel;
@@ -764,23 +763,16 @@ static int
npu_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
npu_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
{
{
	struct npu_device *npu_dev = cdev->devdata;
	struct npu_device *npu_dev = cdev->devdata;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	struct npu_thermalctrl *thermal = &npu_dev->thermalctrl;
	struct npu_thermalctrl *thermal = &npu_dev->thermalctrl;
	int rc = 0;


	NPU_DBG("request state=%lu\n", state);
	NPU_DBG("request state=%lu\n", state);
	if (state > thermal->max_state)
	if (state > thermal->max_state)
		return -EINVAL;
		return -EINVAL;


	mutex_lock(&host_ctx->lock);
	thermal->current_state = state;
	thermal->current_state = state;
	thermal->pwr_level =  npu_power_level_from_index(npu_dev,
	thermal->pwr_level =  npu_power_level_from_index(npu_dev,
		thermal->max_state - state);
		thermal->max_state - state);

	return npu_host_update_power(npu_dev);
	rc = npu_set_power_level(npu_dev, true);
	mutex_unlock(&host_ctx->lock);

	return rc;
}
}


/* -------------------------------------------------------------------------
/* -------------------------------------------------------------------------
+29 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ static void npu_ipc_irq_work(struct work_struct *work);
static void npu_wdg_err_irq_work(struct work_struct *work);
static void npu_wdg_err_irq_work(struct work_struct *work);
static void npu_bridge_mbox_work(struct work_struct *work);
static void npu_bridge_mbox_work(struct work_struct *work);
static void npu_disable_fw_work(struct work_struct *work);
static void npu_disable_fw_work(struct work_struct *work);
static void npu_update_pwr_work(struct work_struct *work);
static void turn_off_fw_logging(struct npu_device *npu_dev);
static void turn_off_fw_logging(struct npu_device *npu_dev);
static int wait_for_status_ready(struct npu_device *npu_dev,
static int wait_for_status_ready(struct npu_device *npu_dev,
	uint32_t status_reg, uint32_t status_bits);
	uint32_t status_reg, uint32_t status_bits);
@@ -542,6 +543,33 @@ static int npu_notifier_cb(struct notifier_block *this, unsigned long code,
	return ret;
	return ret;
}
}


static void npu_update_pwr_work(struct work_struct *work)
{
	int ret;
	struct npu_host_ctx *host_ctx;
	struct npu_device *npu_dev;

	host_ctx = container_of(work, struct npu_host_ctx, update_pwr_work);
	npu_dev = container_of(host_ctx, struct npu_device, host_ctx);

	mutex_lock(&host_ctx->lock);
	ret = npu_set_power_level(npu_dev, true);
	mutex_unlock(&host_ctx->lock);

	if (ret)
		NPU_ERR("Update power level failed %d\n", ret);
}

int npu_host_update_power(struct npu_device *npu_dev)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;

	if (host_ctx->wq)
		queue_work(host_ctx->wq, &host_ctx->update_pwr_work);

	return 0;
}

int npu_host_init(struct npu_device *npu_dev)
int npu_host_init(struct npu_device *npu_dev)
{
{
	int sts = 0;
	int sts = 0;
@@ -575,6 +603,7 @@ int npu_host_init(struct npu_device *npu_dev)
		INIT_WORK(&host_ctx->wdg_err_irq_work, npu_wdg_err_irq_work);
		INIT_WORK(&host_ctx->wdg_err_irq_work, npu_wdg_err_irq_work);
		INIT_WORK(&host_ctx->bridge_mbox_work, npu_bridge_mbox_work);
		INIT_WORK(&host_ctx->bridge_mbox_work, npu_bridge_mbox_work);
		INIT_WORK(&host_ctx->load_fw_work, npu_load_fw_work);
		INIT_WORK(&host_ctx->load_fw_work, npu_load_fw_work);
		INIT_WORK(&host_ctx->update_pwr_work, npu_update_pwr_work);
		INIT_DELAYED_WORK(&host_ctx->disable_fw_work,
		INIT_DELAYED_WORK(&host_ctx->disable_fw_work,
			npu_disable_fw_work);
			npu_disable_fw_work);
	}
	}
+2 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ struct npu_host_ctx {
	struct work_struct wdg_err_irq_work;
	struct work_struct wdg_err_irq_work;
	struct work_struct bridge_mbox_work;
	struct work_struct bridge_mbox_work;
	struct work_struct load_fw_work;
	struct work_struct load_fw_work;
	struct work_struct update_pwr_work;
	struct delayed_work disable_fw_work;
	struct delayed_work disable_fw_work;
	struct workqueue_struct *wq;
	struct workqueue_struct *wq;
	struct completion misc_cmd_done;
	struct completion misc_cmd_done;
@@ -146,6 +147,7 @@ int32_t npu_host_loopback_test(struct npu_device *npu_dev);
void npu_host_cleanup_networks(struct npu_client *client);
void npu_host_cleanup_networks(struct npu_client *client);
int npu_host_notify_fw_pwr_state(struct npu_device *npu_dev,
int npu_host_notify_fw_pwr_state(struct npu_device *npu_dev,
	uint32_t pwr_level, bool post);
	uint32_t pwr_level, bool post);
int npu_host_update_power(struct npu_device *npu_dev);


void npu_dump_debug_info(struct npu_device *npu_dev);
void npu_dump_debug_info(struct npu_device *npu_dev);
void npu_dump_ipc_packet(struct npu_device *npu_dev, void *cmd_ptr);
void npu_dump_ipc_packet(struct npu_device *npu_dev, void *cmd_ptr);