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

Commit 0ee7f85d authored by Jigarkumar Zala's avatar Jigarkumar Zala
Browse files

msm: camera: cdm: Use common logging macros for CDM driver



Start using common logging macros for CDM module driver for
debug/info/warn/error logs.

Change-Id: I777526e8103ef1b54935c2645df5046ebc8bcadc
Signed-off-by: default avatarJigarkumar Zala <jzala@codeaurora.org>
parent b2252423
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -27,18 +27,7 @@
#include "cam_cpas_api.h"
#include "cam_hw_intf.h"
#include "cam_hw.h"

#ifdef CONFIG_CAM_CDM_DBG
#define CDM_CDBG(fmt, args...) pr_err(fmt, ##args)
#else
#define CDM_CDBG(fmt, args...) pr_debug(fmt, ##args)
#endif

#ifdef CONFIG_CAM_CDM_DUMP_DBG
#define CDM_DUMP_CDBG(fmt, args...) pr_err(fmt, ##args)
#else
#define CDM_DUMP_CDBG(fmt, args...) pr_debug(fmt, ##args)
#endif
#include "cam_debug_util.h"

#define CAM_MAX_SW_CDM_VERSION_SUPPORTED  1
#define CAM_SW_CDM_INDEX                  0
+71 −55
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@
 * GNU General Public License for more details.
 */

#define pr_fmt(fmt) "CAM-CDM-CORE %s:%d " fmt, __func__, __LINE__

#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
@@ -32,7 +30,7 @@
static void cam_cdm_get_client_refcount(struct cam_cdm_client *client)
{
	mutex_lock(&client->lock);
	CDM_CDBG("CDM client get refcount=%d\n",
	CAM_DBG(CAM_CDM, "CDM client get refcount=%d",
		client->refcount);
	client->refcount++;
	mutex_unlock(&client->lock);
@@ -41,12 +39,12 @@ static void cam_cdm_get_client_refcount(struct cam_cdm_client *client)
static void cam_cdm_put_client_refcount(struct cam_cdm_client *client)
{
	mutex_lock(&client->lock);
	CDM_CDBG("CDM client put refcount=%d\n",
	CAM_DBG(CAM_CDM, "CDM client put refcount=%d",
		client->refcount);
	if (client->refcount > 0) {
		client->refcount--;
	} else {
		pr_err("Refcount put when zero\n");
		CAM_ERR(CAM_CDM, "Refcount put when zero");
		WARN_ON(1);
	}
	mutex_unlock(&client->lock);
@@ -63,7 +61,7 @@ bool cam_cdm_set_cam_hw_version(
		cam_version->reserved = 0;
		return true;
	default:
		pr_err("CDM Version=%x not supported in util\n", ver);
		CAM_ERR(CAM_CDM, "CDM Version=%x not supported in util", ver);
	break;
	}
	return false;
@@ -72,7 +70,7 @@ bool cam_cdm_set_cam_hw_version(
void cam_cdm_cpas_cb(uint32_t client_handle, void *userdata,
	enum cam_camnoc_irq_type evt_type, uint32_t evt_data)
{
	pr_err("CPAS error callback type=%d with data=%x\n", evt_type,
	CAM_ERR(CAM_CDM, "CPAS error callback type=%d with data=%x", evt_type,
		evt_data);
}

@@ -84,13 +82,14 @@ struct cam_cdm_utils_ops *cam_cdm_get_ops(
		case CAM_CDM170_VERSION:
			return &CDM170_ops;
		default:
			pr_err("CDM Version=%x not supported in util\n", ver);
			CAM_ERR(CAM_CDM, "CDM Version=%x not supported in util",
				ver);
		}
	} else if (cam_version) {
		if ((cam_version->major == 1) && (cam_version->minor == 0) &&
			(cam_version->incr == 0))
			return &CDM170_ops;
		pr_err("cam_hw_version=%x:%x:%x not supported\n",
		CAM_ERR(CAM_CDM, "cam_hw_version=%x:%x:%x not supported",
			cam_version->major, cam_version->minor,
			cam_version->incr);
	}
@@ -107,7 +106,7 @@ struct cam_cdm_bl_cb_request_entry *cam_cdm_find_request_by_bl_tag(
		if (node->bl_tag == tag)
			return node;
	}
	pr_err("Could not find the bl request for tag=%x\n", tag);
	CAM_ERR(CAM_CDM, "Could not find the bl request for tag=%x", tag);

	return NULL;
}
@@ -135,11 +134,11 @@ int cam_cdm_find_free_client_slot(struct cam_cdm *hw)

	for (i = 0; i < CAM_PER_CDM_MAX_REGISTERED_CLIENTS; i++) {
		if (hw->clients[i] == NULL) {
			CDM_CDBG("Found client slot %d\n", i);
			CAM_DBG(CAM_CDM, "Found client slot %d", i);
			return i;
		}
	}
	pr_err("No more client slots\n");
	CAM_ERR(CAM_CDM, "No more client slots");

	return -EBUSY;
}
@@ -153,7 +152,7 @@ void cam_cdm_notify_clients(struct cam_hw_info *cdm_hw,
	struct cam_cdm_client *client = NULL;

	if (!cdm_hw) {
		pr_err("CDM Notify called with NULL hw info\n");
		CAM_ERR(CAM_CDM, "CDM Notify called with NULL hw info");
		return;
	}
	core = (struct cam_cdm *)cdm_hw->core_info;
@@ -166,20 +165,21 @@ void cam_cdm_notify_clients(struct cam_hw_info *cdm_hw,
		client_idx = CAM_CDM_GET_CLIENT_IDX(node->client_hdl);
		client = core->clients[client_idx];
		if ((!client) || (client->handle != node->client_hdl)) {
			pr_err("Invalid client %pK hdl=%x\n", client,
			CAM_ERR(CAM_CDM, "Invalid client %pK hdl=%x", client,
				node->client_hdl);
			return;
		}
		cam_cdm_get_client_refcount(client);
		if (client->data.cam_cdm_callback) {
			CDM_CDBG("Calling client=%s cb cookie=%d\n",
			CAM_DBG(CAM_CDM, "Calling client=%s cb cookie=%d",
				client->data.identifier, node->cookie);
			client->data.cam_cdm_callback(node->client_hdl,
				node->userdata, CAM_CDM_CB_STATUS_BL_SUCCESS,
				node->cookie);
			CDM_CDBG("Exit client cb cookie=%d\n", node->cookie);
			CAM_DBG(CAM_CDM, "Exit client cb cookie=%d",
				node->cookie);
		} else {
			pr_err("No cb registered for client hdl=%x\n",
			CAM_ERR(CAM_CDM, "No cb registered for client hdl=%x",
				node->client_hdl);
		}
		cam_cdm_put_client_refcount(client);
@@ -190,7 +190,7 @@ void cam_cdm_notify_clients(struct cam_hw_info *cdm_hw,
		if (core->clients[i] != NULL) {
			client = core->clients[i];
			mutex_lock(&client->lock);
			CDM_CDBG("Found client slot %d\n", i);
			CAM_DBG(CAM_CDM, "Found client slot %d", i);
			if (client->data.cam_cdm_callback) {
				if (status == CAM_CDM_CB_STATUS_PAGEFAULT) {
					unsigned long iova =
@@ -203,7 +203,8 @@ void cam_cdm_notify_clients(struct cam_hw_info *cdm_hw,
						(iova & 0xFFFFFFFF));
				}
			} else {
				pr_err("No cb registered for client hdl=%x\n",
				CAM_ERR(CAM_CDM,
					"No cb registered for client hdl=%x",
					client->handle);
			}
			mutex_unlock(&client->lock);
@@ -228,24 +229,26 @@ int cam_cdm_stream_ops_internal(void *hw_priv,
	client_idx = CAM_CDM_GET_CLIENT_IDX(*handle);
	client = core->clients[client_idx];
	if (!client) {
		pr_err("Invalid client %pK hdl=%x\n", client, *handle);
		CAM_ERR(CAM_CDM, "Invalid client %pK hdl=%x", client, *handle);
		return -EINVAL;
	}
	cam_cdm_get_client_refcount(client);
	if (*handle != client->handle) {
		pr_err("client id given handle=%x invalid\n", *handle);
		CAM_ERR(CAM_CDM, "client id given handle=%x invalid", *handle);
		cam_cdm_put_client_refcount(client);
		return -EINVAL;
	}
	if (operation == true) {
		if (true == client->stream_on) {
			pr_err("Invalid CDM client is already streamed ON\n");
			CAM_ERR(CAM_CDM,
				"Invalid CDM client is already streamed ON");
			cam_cdm_put_client_refcount(client);
			return rc;
		}
	} else {
		if (client->stream_on == false) {
			pr_err("Invalid CDM client is already streamed Off\n");
			CAM_ERR(CAM_CDM,
				"Invalid CDM client is already streamed Off");
			cam_cdm_put_client_refcount(client);
			return rc;
		}
@@ -265,26 +268,28 @@ int cam_cdm_stream_ops_internal(void *hw_priv,
			rc = cam_cpas_start(core->cpas_handle,
				&ahb_vote, &axi_vote);
			if (rc != 0) {
				pr_err("CPAS start failed\n");
				CAM_ERR(CAM_CDM, "CPAS start failed");
				goto end;
			}
			CDM_CDBG("CDM init first time\n");
			CAM_DBG(CAM_CDM, "CDM init first time");
			if (core->id == CAM_CDM_VIRTUAL) {
				CDM_CDBG("Virtual CDM HW init first time\n");
				CAM_DBG(CAM_CDM,
					"Virtual CDM HW init first time");
				rc = 0;
			} else {
				CDM_CDBG("CDM HW init first time\n");
				CAM_DBG(CAM_CDM, "CDM HW init first time");
				rc = cam_hw_cdm_init(hw_priv, NULL, 0);
				if (rc == 0) {
					rc = cam_hw_cdm_alloc_genirq_mem(
						hw_priv);
					if (rc != 0) {
						pr_err("Genirqalloc failed\n");
						CAM_ERR(CAM_CDM,
							"Genirqalloc failed");
						cam_hw_cdm_deinit(hw_priv,
							NULL, 0);
					}
				} else {
					pr_err("CDM HW init failed\n");
					CAM_ERR(CAM_CDM, "CDM HW init failed");
				}
			}
			if (rc == 0) {
@@ -292,11 +297,11 @@ int cam_cdm_stream_ops_internal(void *hw_priv,
				client->stream_on = true;
			} else {
				if (cam_cpas_stop(core->cpas_handle))
					pr_err("CPAS stop failed\n");
					CAM_ERR(CAM_CDM, "CPAS stop failed");
			}
		} else {
			cdm_hw->open_count++;
			CDM_CDBG("CDM HW already ON count=%d\n",
			CAM_DBG(CAM_CDM, "CDM HW already ON count=%d",
				cdm_hw->open_count);
			rc = 0;
			client->stream_on = true;
@@ -304,35 +309,41 @@ int cam_cdm_stream_ops_internal(void *hw_priv,
	} else {
		if (cdm_hw->open_count) {
			cdm_hw->open_count--;
			CDM_CDBG("stream OFF CDM %d\n", cdm_hw->open_count);
			CAM_DBG(CAM_CDM, "stream OFF CDM %d",
				cdm_hw->open_count);
			if (!cdm_hw->open_count) {
				CDM_CDBG("CDM Deinit now\n");
				CAM_DBG(CAM_CDM, "CDM Deinit now");
				if (core->id == CAM_CDM_VIRTUAL) {
					CDM_CDBG("Virtual CDM HW Deinit\n");
					CAM_DBG(CAM_CDM,
						"Virtual CDM HW Deinit");
					rc = 0;
				} else {
					CDM_CDBG("CDM HW Deinit now\n");
					CAM_DBG(CAM_CDM, "CDM HW Deinit now");
					rc = cam_hw_cdm_deinit(
						hw_priv, NULL, 0);
					if (cam_hw_cdm_release_genirq_mem(
						hw_priv))
						pr_err("Genirq release failed\n");
						CAM_ERR(CAM_CDM,
							"Genirq release fail");
				}
				if (rc) {
					pr_err("Deinit failed in streamoff\n");
					CAM_ERR(CAM_CDM,
						"Deinit failed in streamoff");
				} else {
					client->stream_on = false;
					rc = cam_cpas_stop(core->cpas_handle);
					if (rc)
						pr_err("CPAS stop failed\n");
						CAM_ERR(CAM_CDM,
							"CPAS stop failed");
				}
			} else {
				client->stream_on = false;
				CDM_CDBG("Client stream off success =%d\n",
				CAM_DBG(CAM_CDM,
					"Client stream off success =%d",
					cdm_hw->open_count);
			}
		} else {
			CDM_CDBG("stream OFF CDM Invalid %d\n",
			CAM_DBG(CAM_CDM, "stream OFF CDM Invalid %d",
				cdm_hw->open_count);
			rc = -ENXIO;
		}
@@ -390,33 +401,35 @@ int cam_cdm_process_cmd(void *hw_priv,
		struct cam_cdm_client *client;

		if (sizeof(struct cam_cdm_hw_intf_cmd_submit_bl) != arg_size) {
			pr_err("Invalid CDM cmd %d arg size=%x\n", cmd,
			CAM_ERR(CAM_CDM, "Invalid CDM cmd %d arg size=%x", cmd,
				arg_size);
			break;
		}
		req = (struct cam_cdm_hw_intf_cmd_submit_bl *)cmd_args;
		if ((req->data->type < 0) ||
			(req->data->type > CAM_CDM_BL_CMD_TYPE_KERNEL_IOVA)) {
			pr_err("Invalid req bl cmd addr type=%d\n",
			CAM_ERR(CAM_CDM, "Invalid req bl cmd addr type=%d",
				req->data->type);
			break;
		}
		idx = CAM_CDM_GET_CLIENT_IDX(req->handle);
		client = core->clients[idx];
		if ((!client) || (req->handle != client->handle)) {
			pr_err("Invalid client %pK hdl=%x\n", client,
			CAM_ERR(CAM_CDM, "Invalid client %pK hdl=%x", client,
				req->handle);
			break;
		}
		cam_cdm_get_client_refcount(client);
		if ((req->data->flag == true) &&
			(!client->data.cam_cdm_callback)) {
			pr_err("CDM request cb without registering cb\n");
			CAM_ERR(CAM_CDM,
				"CDM request cb without registering cb");
			cam_cdm_put_client_refcount(client);
			break;
		}
		if (client->stream_on != true) {
			pr_err("Invalid CDM needs to be streamed ON first\n");
			CAM_ERR(CAM_CDM,
				"Invalid CDM needs to be streamed ON first");
			cam_cdm_put_client_refcount(client);
			break;
		}
@@ -434,19 +447,20 @@ int cam_cdm_process_cmd(void *hw_priv,
		struct cam_cdm_client *client;

		if (sizeof(struct cam_cdm_acquire_data) != arg_size) {
			pr_err("Invalid CDM cmd %d arg size=%x\n", cmd,
			CAM_ERR(CAM_CDM, "Invalid CDM cmd %d arg size=%x", cmd,
				arg_size);
			break;
		}

		mutex_lock(&cdm_hw->hw_mutex);
		data = (struct cam_cdm_acquire_data *)cmd_args;
		CDM_CDBG("Trying to acquire client=%s in hw idx=%d\n",
		CAM_DBG(CAM_CDM, "Trying to acquire client=%s in hw idx=%d",
			data->identifier, core->index);
		idx = cam_cdm_find_free_client_slot(core);
		if ((idx < 0) || (core->clients[idx])) {
			mutex_unlock(&cdm_hw->hw_mutex);
			pr_err("Failed to client slots for client=%s in hw idx=%d\n",
			CAM_ERR(CAM_CDM,
				"Fail to client slots, client=%s in hw idx=%d",
			data->identifier, core->index);
			break;
		}
@@ -477,7 +491,7 @@ int cam_cdm_process_cmd(void *hw_priv,
				mutex_unlock(
					&cdm_hw->hw_mutex);
				rc = -EPERM;
				pr_err("Invalid ops for virtual cdm\n");
				CAM_ERR(CAM_CDM, "Invalid ops for virtual cdm");
				break;
			}
		} else {
@@ -493,7 +507,7 @@ int cam_cdm_process_cmd(void *hw_priv,
					idx);
		client->stream_on = false;
		data->handle = client->handle;
		CDM_CDBG("Acquired client=%s in hwidx=%d\n",
		CAM_DBG(CAM_CDM, "Acquired client=%s in hwidx=%d",
			data->identifier, core->index);
		mutex_unlock(&client->lock);
		rc = 0;
@@ -505,7 +519,8 @@ int cam_cdm_process_cmd(void *hw_priv,
		struct cam_cdm_client *client;

		if (sizeof(uint32_t) != arg_size) {
			pr_err("Invalid CDM cmd %d size=%x for handle=%x\n",
			CAM_ERR(CAM_CDM,
				"Invalid CDM cmd %d size=%x for handle=%x",
				cmd, arg_size, *handle);
			return -EINVAL;
		}
@@ -513,14 +528,15 @@ int cam_cdm_process_cmd(void *hw_priv,
		mutex_lock(&cdm_hw->hw_mutex);
		client = core->clients[idx];
		if ((!client) || (*handle != client->handle)) {
			pr_err("Invalid client %pK hdl=%x\n", client, *handle);
			CAM_ERR(CAM_CDM, "Invalid client %pK hdl=%x",
				client, *handle);
			mutex_unlock(&cdm_hw->hw_mutex);
			break;
		}
		cam_cdm_put_client_refcount(client);
		mutex_lock(&client->lock);
		if (client->refcount != 0) {
			pr_err("CDM Client refcount not zero %d",
			CAM_ERR(CAM_CDM, "CDM Client refcount not zero %d",
				client->refcount);
			rc = -EPERM;
			mutex_unlock(&client->lock);
@@ -536,12 +552,12 @@ int cam_cdm_process_cmd(void *hw_priv,
		break;
	}
	case CAM_CDM_HW_INTF_CMD_RESET_HW: {
		pr_err("CDM HW reset not supported for handle =%x\n",
		CAM_ERR(CAM_CDM, "CDM HW reset not supported for handle =%x",
			*((uint32_t *)cmd_args));
		break;
	}
	default:
		pr_err("CDM HW intf command not valid =%d\n", cmd);
		CAM_ERR(CAM_CDM, "CDM HW intf command not valid =%d", cmd);
		break;
	}
	return rc;
+153 −135

File changed.

Preview size limit exceeded, changes collapsed.

+51 −45
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@
 * GNU General Public License for more details.
 */

#define pr_fmt(fmt) "CAM-CDM-INTF %s:%d " fmt, __func__, __LINE__

#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
@@ -41,10 +39,10 @@ static int get_cdm_mgr_refcount(void)

	mutex_lock(&cam_cdm_mgr_lock);
	if (cdm_mgr.probe_done == false) {
		pr_err("CDM intf mgr not probed yet\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr not probed yet");
		rc = -EPERM;
	} else {
		CDM_CDBG("CDM intf mgr get refcount=%d\n",
		CAM_DBG(CAM_CDM, "CDM intf mgr get refcount=%d",
			cdm_mgr.refcount);
		cdm_mgr.refcount++;
	}
@@ -56,14 +54,14 @@ static void put_cdm_mgr_refcount(void)
{
	mutex_lock(&cam_cdm_mgr_lock);
	if (cdm_mgr.probe_done == false) {
		pr_err("CDM intf mgr not probed yet\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr not probed yet");
	} else {
		CDM_CDBG("CDM intf mgr put refcount=%d\n",
		CAM_DBG(CAM_CDM, "CDM intf mgr put refcount=%d",
			cdm_mgr.refcount);
		if (cdm_mgr.refcount > 0) {
			cdm_mgr.refcount--;
		} else {
			pr_err("Refcount put when zero\n");
			CAM_ERR(CAM_CDM, "Refcount put when zero");
			WARN_ON(1);
		}
	}
@@ -90,20 +88,20 @@ static int get_cdm_index_by_id(char *identifier,
	int rc = -EPERM, i, j;
	char client_name[128];

	CDM_CDBG("Looking for HW id of =%s and index=%d\n",
	CAM_DBG(CAM_CDM, "Looking for HW id of =%s and index=%d",
		identifier, cell_index);
	snprintf(client_name, sizeof(client_name), "%s", identifier);
	CDM_CDBG("Looking for HW id of %s count:%d\n", client_name,
	CAM_DBG(CAM_CDM, "Looking for HW id of %s count:%d", client_name,
		cdm_mgr.cdm_count);
	mutex_lock(&cam_cdm_mgr_lock);
	for (i = 0; i < cdm_mgr.cdm_count; i++) {
		mutex_lock(&cdm_mgr.nodes[i].lock);
		CDM_CDBG("dt_num_supported_clients=%d\n",
		CAM_DBG(CAM_CDM, "dt_num_supported_clients=%d",
			cdm_mgr.nodes[i].data->dt_num_supported_clients);

		for (j = 0; j <
			cdm_mgr.nodes[i].data->dt_num_supported_clients; j++) {
			CDM_CDBG("client name:%s\n",
			CAM_DBG(CAM_CDM, "client name:%s",
				cdm_mgr.nodes[i].data->dt_cdm_client_name[j]);
			if (!strcmp(
				cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
@@ -131,10 +129,10 @@ int cam_cdm_get_iommu_handle(char *identifier,
		return -EINVAL;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		return rc;
	}
	CDM_CDBG("Looking for Iommu handle of %s\n", identifier);
	CAM_DBG(CAM_CDM, "Looking for Iommu handle of %s", identifier);

	for (i = 0; i < cdm_mgr.cdm_count; i++) {
		mutex_lock(&cdm_mgr.nodes[i].lock);
@@ -173,39 +171,41 @@ int cam_cdm_acquire(struct cam_cdm_acquire_data *data)
		return -EINVAL;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		return rc;
	}

	if (data->id > CAM_CDM_HW_ANY) {
		pr_err("only CAM_CDM_VIRTUAL/CAM_CDM_HW_ANY is supported\n");
		CAM_ERR(CAM_CDM,
			"only CAM_CDM_VIRTUAL/CAM_CDM_HW_ANY is supported");
		rc = -EPERM;
		goto end;
	}
	rc = get_cdm_index_by_id(data->identifier, data->cell_index,
		&hw_index);
	if ((rc < 0) && (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM)) {
		pr_err("Failed to identify associated hw id\n");
		CAM_ERR(CAM_CDM, "Failed to identify associated hw id");
		goto end;
	} else {
		CDM_CDBG("hw_index:%d\n", hw_index);
		CAM_DBG(CAM_CDM, "hw_index:%d", hw_index);
		hw = cdm_mgr.nodes[hw_index].device;
		if (hw && hw->hw_ops.process_cmd) {
			rc = hw->hw_ops.process_cmd(hw->hw_priv,
					CAM_CDM_HW_INTF_CMD_ACQUIRE, data,
					sizeof(struct cam_cdm_acquire_data));
			if (rc < 0) {
				pr_err("CDM hw acquire failed\n");
				CAM_ERR(CAM_CDM, "CDM hw acquire failed");
				goto end;
			}
		} else {
			pr_err("idx %d doesn't have acquire ops\n", hw_index);
			CAM_ERR(CAM_CDM, "idx %d doesn't have acquire ops",
				hw_index);
			rc = -EPERM;
		}
	}
end:
	if (rc < 0) {
		pr_err("CDM acquire failed for id=%d name=%s, idx=%d\n",
		CAM_ERR(CAM_CDM, "CDM acquire failed for id=%d name=%s, idx=%d",
			data->id, data->identifier, data->cell_index);
		put_cdm_mgr_refcount();
	}
@@ -220,7 +220,7 @@ int cam_cdm_release(uint32_t handle)
	struct cam_hw_intf *hw;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		return rc;
	}

@@ -232,10 +232,11 @@ int cam_cdm_release(uint32_t handle)
					CAM_CDM_HW_INTF_CMD_RELEASE, &handle,
					sizeof(handle));
			if (rc < 0)
				pr_err("hw release failed for handle=%x\n",
				CAM_ERR(CAM_CDM,
					"hw release failed for handle=%x",
					handle);
		} else
			pr_err("hw idx %d doesn't have release ops\n",
			CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
				hw_index);
	}
	put_cdm_mgr_refcount();
@@ -257,7 +258,7 @@ int cam_cdm_submit_bls(uint32_t handle, struct cam_cdm_bl_request *data)
		return rc;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		rc = -EPERM;
		return rc;
	}
@@ -274,10 +275,11 @@ int cam_cdm_submit_bls(uint32_t handle, struct cam_cdm_bl_request *data)
				CAM_CDM_HW_INTF_CMD_SUBMIT_BL, &req,
				sizeof(struct cam_cdm_hw_intf_cmd_submit_bl));
			if (rc < 0)
				pr_err("hw submit bl failed for handle=%x\n",
				CAM_ERR(CAM_CDM,
					"hw submit bl failed for handle=%x",
					handle);
		} else {
			pr_err("hw idx %d doesn't have submit ops\n",
			CAM_ERR(CAM_CDM, "hw idx %d doesn't have submit ops",
				hw_index);
		}
	}
@@ -294,7 +296,7 @@ int cam_cdm_stream_on(uint32_t handle)
	struct cam_hw_intf *hw;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		rc = -EPERM;
		return rc;
	}
@@ -306,10 +308,12 @@ int cam_cdm_stream_on(uint32_t handle)
				rc = hw->hw_ops.start(hw->hw_priv, &handle,
						sizeof(uint32_t));
				if (rc < 0)
					pr_err("hw start failed handle=%x\n",
					CAM_ERR(CAM_CDM,
						"hw start failed handle=%x",
						handle);
			} else {
				pr_err("hw idx %d doesn't have start ops\n",
				CAM_ERR(CAM_CDM,
					"hw idx %d doesn't have start ops",
					hw_index);
			}
	}
@@ -326,7 +330,7 @@ int cam_cdm_stream_off(uint32_t handle)
	struct cam_hw_intf *hw;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		rc = -EPERM;
		return rc;
	}
@@ -338,10 +342,10 @@ int cam_cdm_stream_off(uint32_t handle)
			rc = hw->hw_ops.stop(hw->hw_priv, &handle,
					sizeof(uint32_t));
			if (rc < 0)
				pr_err("hw stop failed handle=%x\n",
				CAM_ERR(CAM_CDM, "hw stop failed handle=%x",
					handle);
		} else {
			pr_err("hw idx %d doesn't have stop ops\n",
			CAM_ERR(CAM_CDM, "hw idx %d doesn't have stop ops",
				hw_index);
		}
	}
@@ -358,7 +362,7 @@ int cam_cdm_reset_hw(uint32_t handle)
	struct cam_hw_intf *hw;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		rc = -EPERM;
		return rc;
	}
@@ -371,10 +375,11 @@ int cam_cdm_reset_hw(uint32_t handle)
					CAM_CDM_HW_INTF_CMD_RESET_HW, &handle,
					sizeof(handle));
			if (rc < 0)
				pr_err("CDM hw release failed for handle=%x\n",
				CAM_ERR(CAM_CDM,
					"CDM hw release failed for handle=%x",
					handle);
		} else {
			pr_err("hw idx %d doesn't have release ops\n",
			CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
				hw_index);
		}
	}
@@ -394,7 +399,7 @@ int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
		return rc;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		return rc;
	}

@@ -417,7 +422,7 @@ int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
		cdm_mgr.cdm_count++;
		rc = 0;
	} else {
		pr_err("CDM registration failed type=%d count=%d\n",
		CAM_ERR(CAM_CDM, "CDM registration failed type=%d count=%d",
			type, cdm_mgr.cdm_count);
	}
	mutex_unlock(&cam_cdm_mgr_lock);
@@ -436,7 +441,7 @@ int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
		return rc;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		rc = -EPERM;
		return rc;
	}
@@ -459,7 +464,7 @@ int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
		cdm_mgr.cdm_count--;
		rc = 0;
	} else {
		pr_err("CDM Deregistration failed type=%d index=%d\n",
		CAM_ERR(CAM_CDM, "CDM Deregistration failed type=%d index=%d",
			type, index);
	}
	mutex_unlock(&cam_cdm_mgr_lock);
@@ -474,7 +479,7 @@ static int cam_cdm_intf_probe(struct platform_device *pdev)

	rc = cam_cdm_intf_mgr_soc_get_dt_properties(pdev, &cdm_mgr);
	if (rc) {
		pr_err("Failed to get dt properties\n");
		CAM_ERR(CAM_CDM, "Failed to get dt properties");
		return rc;
	}
	mutex_lock(&cam_cdm_mgr_lock);
@@ -494,7 +499,8 @@ static int cam_cdm_intf_probe(struct platform_device *pdev)
		for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
			if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
				(cdm_mgr.nodes[i].refcount != 0))
				pr_err("Valid node present in index=%d\n", i);
				CAM_ERR(CAM_CDM,
					"Valid node present in index=%d", i);
			mutex_destroy(&cdm_mgr.nodes[i].lock);
			cdm_mgr.nodes[i].device = NULL;
			cdm_mgr.nodes[i].data = NULL;
@@ -511,19 +517,19 @@ static int cam_cdm_intf_remove(struct platform_device *pdev)
	int i, rc = -EBUSY;

	if (get_cdm_mgr_refcount()) {
		pr_err("CDM intf mgr get refcount failed\n");
		CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
		return rc;
	}

	if (cam_virtual_cdm_remove(pdev)) {
		pr_err("Virtual CDM remove failed\n");
		CAM_ERR(CAM_CDM, "Virtual CDM remove failed");
		goto end;
	}
	put_cdm_mgr_refcount();

	mutex_lock(&cam_cdm_mgr_lock);
	if (cdm_mgr.refcount != 0) {
		pr_err("cdm manger refcount not zero %d\n",
		CAM_ERR(CAM_CDM, "cdm manger refcount not zero %d",
			cdm_mgr.refcount);
		goto end;
	}
@@ -531,7 +537,7 @@ static int cam_cdm_intf_remove(struct platform_device *pdev)
	for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
		if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
			(cdm_mgr.nodes[i].refcount != 0)) {
			pr_err("Valid node present in index=%d\n", i);
			CAM_ERR(CAM_CDM, "Valid node present in index=%d", i);
			mutex_unlock(&cam_cdm_mgr_lock);
			goto end;
		}
+25 −22
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@
 * GNU General Public License for more details.
 */

#define pr_fmt(fmt) "CAM-CDM-SOC %s:%d " fmt, __func__, __LINE__

#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
@@ -40,27 +38,29 @@ bool cam_cdm_read_hw_reg(struct cam_hw_info *cdm_hw,
	resource_size_t mem_len =
		cdm_hw->soc_info.reg_map[CAM_HW_CDM_BASE_INDEX].size;

	CDM_CDBG("E: b=%pK blen=%d reg=%x off=%x\n", (void *)base,
	CAM_DBG(CAM_CDM, "E: b=%pK blen=%d reg=%x off=%x", (void __iomem *)base,
		(int)mem_len, reg, (CAM_CDM_OFFSET_FROM_REG(cdm->offset_tbl,
		reg)));
	CDM_CDBG("E: b=%pK reg=%x off=%x\n", (void *)base,
	CAM_DBG(CAM_CDM, "E: b=%pK reg=%x off=%x", (void __iomem *)base,
		reg, (CAM_CDM_OFFSET_FROM_REG(cdm->offset_tbl, reg)));

	if ((reg > cdm->offset_tbl->offset_max_size) ||
		(reg > cdm->offset_tbl->last_offset)) {
		pr_err_ratelimited("Invalid reg=%d\n", reg);
		CAM_ERR_RATE_LIMIT(CAM_CDM, "Invalid reg=%d\n", reg);
		goto permission_error;
	} else {
		reg_addr = (base + (CAM_CDM_OFFSET_FROM_REG(
				cdm->offset_tbl, reg)));
		if (reg_addr > (base + mem_len)) {
			pr_err_ratelimited("Invalid mapped region %d\n", reg);
			CAM_ERR_RATE_LIMIT(CAM_CDM,
				"Invalid mapped region %d", reg);
			goto permission_error;
		}
		*value = cam_io_r_mb(reg_addr);
		CDM_CDBG("X b=%pK reg=%x off=%x val=%x\n",
			(void *)base, reg, (CAM_CDM_OFFSET_FROM_REG(
				cdm->offset_tbl, reg)),	*value);
		CAM_DBG(CAM_CDM, "X b=%pK reg=%x off=%x val=%x",
			(void __iomem *)base, reg,
			(CAM_CDM_OFFSET_FROM_REG(cdm->offset_tbl, reg)),
			*value);
		return false;
	}
permission_error:
@@ -79,18 +79,20 @@ bool cam_cdm_write_hw_reg(struct cam_hw_info *cdm_hw,
	resource_size_t mem_len =
		cdm_hw->soc_info.reg_map[CAM_HW_CDM_BASE_INDEX].size;

	CDM_CDBG("E: b=%pK reg=%x off=%x val=%x\n", (void *)base,
	CAM_DBG(CAM_CDM, "E: b=%pK reg=%x off=%x val=%x", (void __iomem *)base,
		reg, (CAM_CDM_OFFSET_FROM_REG(cdm->offset_tbl, reg)), value);

	if ((reg > cdm->offset_tbl->offset_max_size) ||
		(reg > cdm->offset_tbl->last_offset)) {
		pr_err_ratelimited("CDM accessing invalid reg=%d\n", reg);
		CAM_ERR_RATE_LIMIT(CAM_CDM, "CDM accessing invalid reg=%d\n",
			reg);
		goto permission_error;
	} else {
		reg_addr = (base + CAM_CDM_OFFSET_FROM_REG(
				cdm->offset_tbl, reg));
		if (reg_addr > (base + mem_len)) {
			pr_err_ratelimited("Accessing invalid region %d:%d\n",
			CAM_ERR_RATE_LIMIT(CAM_CDM,
				"Accessing invalid region %d:%d\n",
				reg, (CAM_CDM_OFFSET_FROM_REG(
				cdm->offset_tbl, reg)));
			goto permission_error;
@@ -111,17 +113,17 @@ int cam_cdm_soc_load_dt_private(struct platform_device *pdev,
	ptr->dt_num_supported_clients = of_property_count_strings(
						pdev->dev.of_node,
						"cdm-client-names");
	CDM_CDBG("Num supported cdm_client = %d\n",
	CAM_DBG(CAM_CDM, "Num supported cdm_client = %d",
		ptr->dt_num_supported_clients);
	if (ptr->dt_num_supported_clients >
		CAM_PER_CDM_MAX_REGISTERED_CLIENTS) {
		pr_err("Invalid count of client names count=%d\n",
		CAM_ERR(CAM_CDM, "Invalid count of client names count=%d",
			ptr->dt_num_supported_clients);
		rc = -EINVAL;
		return rc;
	}
	if (ptr->dt_num_supported_clients < 0) {
		CDM_CDBG("No cdm client names found\n");
		CAM_DBG(CAM_CDM, "No cdm client names found");
		ptr->dt_num_supported_clients = 0;
		ptr->dt_cdm_shared = false;
	} else {
@@ -130,10 +132,10 @@ int cam_cdm_soc_load_dt_private(struct platform_device *pdev,
	for (i = 0; i < ptr->dt_num_supported_clients; i++) {
		rc = of_property_read_string_index(pdev->dev.of_node,
			"cdm-client-names", i, &(ptr->dt_cdm_client_name[i]));
		CDM_CDBG("cdm-client-names[%d] = %s\n",	i,
		CAM_DBG(CAM_CDM, "cdm-client-names[%d] = %s",	i,
			ptr->dt_cdm_client_name[i]);
		if (rc < 0) {
			pr_err("Reading cdm-client-names failed\n");
			CAM_ERR(CAM_CDM, "Reading cdm-client-names failed");
			break;
		}
	}
@@ -156,7 +158,7 @@ int cam_hw_cdm_soc_get_dt_properties(struct cam_hw_info *cdm_hw,

	rc = cam_soc_util_get_dt_properties(soc_ptr);
	if (rc != 0) {
		pr_err("Failed to retrieve the CDM dt properties\n");
		CAM_ERR(CAM_CDM, "Failed to retrieve the CDM dt properties");
	} else {
		soc_ptr->soc_private = kzalloc(
				sizeof(struct cam_cdm_private_dt_data),
@@ -167,15 +169,15 @@ int cam_hw_cdm_soc_get_dt_properties(struct cam_hw_info *cdm_hw,
		rc = cam_cdm_soc_load_dt_private(soc_ptr->pdev,
			soc_ptr->soc_private);
		if (rc != 0) {
			pr_err("Failed to load CDM dt private data\n");
			CAM_ERR(CAM_CDM, "Failed to load CDM dt private data");
			goto error;
		}
		id = of_match_node(table, soc_ptr->pdev->dev.of_node);
		if ((!id) || !(id->data)) {
			pr_err("Failed to retrieve the CDM id table\n");
			CAM_ERR(CAM_CDM, "Failed to retrieve the CDM id table");
			goto error;
		}
		CDM_CDBG("CDM Hw Id compatible =%s\n", id->compatible);
		CAM_DBG(CAM_CDM, "CDM Hw Id compatible =%s", id->compatible);
		((struct cam_cdm *)cdm_hw->core_info)->offset_tbl =
			(struct cam_cdm_reg_offset_table *)id->data;
		strlcpy(((struct cam_cdm *)cdm_hw->core_info)->name,
@@ -199,7 +201,8 @@ int cam_cdm_intf_mgr_soc_get_dt_properties(

	rc = of_property_read_u32(pdev->dev.of_node,
		"num-hw-cdm", &mgr->dt_supported_hw_cdm);
	CDM_CDBG("Number of HW cdm supported =%d\n", mgr->dt_supported_hw_cdm);
	CAM_DBG(CAM_CDM, "Number of HW cdm supported =%d",
		mgr->dt_supported_hw_cdm);

	return rc;
}
Loading