Commit b541d4c9 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

media: atomisp: sh_css_mipi: cleanup the code



With the ISP2401 firmware we're using, the code differences
are not that much from ISP2400. Cleanup the code in order
to make it closer to Intel Aero driver.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent ef3f3627
Loading
Loading
Loading
Loading
+38 −121
Original line number Diff line number Diff line
@@ -33,47 +33,6 @@
static u32
ref_count_mipi_allocation[N_CSI_PORTS]; /* Initialized in mipi_init */

/*
 * Check if a source port or TPG/PRBS ID is valid
 */
static bool ia_css_mipi_is_source_port_valid(struct ia_css_pipe *pipe,
	unsigned int *pport)
{
	bool ret = true;
	unsigned int port = 0;
	unsigned int max_ports = 0;

	switch (pipe->stream->config.mode) {
	case IA_CSS_INPUT_MODE_BUFFERED_SENSOR:
		port = (unsigned int)pipe->stream->config.source.port.port;
		max_ports = N_CSI_PORTS;
		break;
	case IA_CSS_INPUT_MODE_TPG:
		port = (unsigned int)pipe->stream->config.source.tpg.id;
		max_ports = N_CSS_TPG_IDS;
		break;
	case IA_CSS_INPUT_MODE_PRBS:
		port = (unsigned int)pipe->stream->config.source.prbs.id;
		max_ports = N_CSS_PRBS_IDS;
		break;
	default:
		assert(false);
		ret = false;
		break;
	}

	if (ret) {
		assert(port < max_ports);

		if (port >= max_ports)
			ret = false;
	}

	*pport = port;

	return ret;
}

/* Assumptions:
 *	- A line is multiple of 4 bytes = 1 word.
 *	- Each frame has SOF and EOF (each 1 word).
@@ -227,6 +186,10 @@ ia_css_mipi_frame_calculate_size(const unsigned int width,
	return err;
}

/*
 * Check if a source port or TPG/PRBS ID is valid
 */

#if !defined(ISP2401)
int
ia_css_mipi_frame_enable_check_on_size(const enum mipi_port_id port,
@@ -272,16 +235,20 @@ bool mipi_is_free(void)
	return true;
}

int
calculate_mipi_buff_size(
    struct ia_css_stream_config *stream_cfg,
#if defined(ISP2401)
/*
 * @brief Calculate the required MIPI buffer sizes.
 * Based on the stream configuration, calculate the
 * required MIPI buffer sizes (in DDR words).
 *
 * @param[in]   stream_cfg              Point to the target stream configuration
 * @param[out]  size_mem_words  MIPI buffer size in DDR words.
 *
 * @return
 */
static int calculate_mipi_buff_size(struct ia_css_stream_config *stream_cfg,
				    unsigned int *size_mem_words)
{
#if !defined(ISP2401)
	int err = -EINVAL;
	(void)stream_cfg;
	(void)size_mem_words;
#else
	unsigned int width;
	unsigned int height;
	enum atomisp_input_format format;
@@ -373,26 +340,9 @@ calculate_mipi_buff_size(
	*size_mem_words = mem_words_per_buff;

	IA_CSS_LEAVE_ERR(err);
#endif
	return err;
}

static bool buffers_needed(struct ia_css_pipe *pipe)
{
	if (!IS_ISP2401) {
		if (pipe->stream->config.mode == IA_CSS_INPUT_MODE_BUFFERED_SENSOR)
			return true;
		else
			return false;
	}

	if (pipe->stream->config.mode == IA_CSS_INPUT_MODE_BUFFERED_SENSOR ||
	    pipe->stream->config.mode == IA_CSS_INPUT_MODE_TPG ||
	    pipe->stream->config.mode == IA_CSS_INPUT_MODE_PRBS)
		return true;

	return false;
}
#endif

int
allocate_mipi_frames(struct ia_css_pipe *pipe,
@@ -422,45 +372,25 @@ allocate_mipi_frames(struct ia_css_pipe *pipe,
	}

#endif

	if (!buffers_needed(pipe)) {
	if (pipe->stream->config.mode != IA_CSS_INPUT_MODE_BUFFERED_SENSOR) {
		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
				    "allocate_mipi_frames(%p) exit: no buffers needed for pipe mode.\n",
				    pipe);
		return 0; /* AM TODO: Check  */
	}

	if (!IS_ISP2401) {
	port = (unsigned int)pipe->stream->config.source.port.port;
	} else {
		/* Returns true if port is valid. So, invert it */
		err = !ia_css_mipi_is_source_port_valid(pipe, &port);
	}

	assert(port < N_CSI_PORTS);

	if ((!IS_ISP2401 && port >= N_CSI_PORTS) ||
	    (IS_ISP2401 && err)) {
	if (port >= N_CSI_PORTS) {
		IA_CSS_ERROR("allocate_mipi_frames(%p) exit: port is not correct (port=%d).",
			     pipe, port);
		return -EINVAL;
	}

#ifdef ISP2401
	err = calculate_mipi_buff_size(
	    &pipe->stream->config,
	err = calculate_mipi_buff_size(&pipe->stream->config,
				       &my_css.mipi_frame_size[port]);
#endif

#if !defined(ISP2401)
	if (ref_count_mipi_allocation[port] != 0) {
		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
				    "allocate_mipi_frames(%p) exit: already allocated for this port (port=%d).\n",
				    pipe, port);
		return 0;
	}
#else
	/* 2401 system allows multiple streams to use same physical port. This is not
	/*
	 * 2401 system allows multiple streams to use same physical port. This is not
	 * true for 2400 system. Currently 2401 uses MIPI buffers as a temporary solution.
	 * TODO AM: Once that is changed (removed) this code should be removed as well.
	 * In that case only 2400 related code should remain.
@@ -472,6 +402,13 @@ allocate_mipi_frames(struct ia_css_pipe *pipe,
				    pipe, port);
		return 0;
	}
#else
	if (ref_count_mipi_allocation[port] != 0) {
		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
				    "allocate_mipi_frames(%p) exit: already allocated for this port (port=%d).\n",
				    pipe, port);
		return 0;
	}
#endif

	ref_count_mipi_allocation[port]++;
@@ -552,23 +489,15 @@ free_mipi_frames(struct ia_css_pipe *pipe)
			return -EINVAL;
		}

		if (!buffers_needed(pipe)) {
		if (pipe->stream->config.mode != IA_CSS_INPUT_MODE_BUFFERED_SENSOR) {
			IA_CSS_ERROR("free_mipi_frames(%p) exit: wrong mode.",
				     pipe);
			return err;
		}

		if (!IS_ISP2401) {
		port = (unsigned int)pipe->stream->config.source.port.port;
		} else {
			/* Returns true if port is valid. So, invert it */
			err = !ia_css_mipi_is_source_port_valid(pipe, &port);
		}

		assert(port < N_CSI_PORTS);

		if ((!IS_ISP2401 && port >= N_CSI_PORTS) ||
		    (IS_ISP2401 && err)) {
		if (port >= N_CSI_PORTS) {
			IA_CSS_ERROR("free_mipi_frames(%p, %d) exit: pipe port is not correct.",
				     pipe, port);
			return err;
@@ -647,11 +576,7 @@ send_mipi_frames(struct ia_css_pipe *pipe)
{
	int err = -EINVAL;
	unsigned int i;
#ifndef ISP2401
	unsigned int port;
#else
	unsigned int port = 0;
#endif

	IA_CSS_ENTER_PRIVATE("pipe=%p", pipe);

@@ -664,23 +589,15 @@ send_mipi_frames(struct ia_css_pipe *pipe)

	/* multi stream video needs mipi buffers */
	/* nothing to be done in other cases. */
	if (!buffers_needed(pipe)) {
	if (pipe->stream->config.mode != IA_CSS_INPUT_MODE_BUFFERED_SENSOR) {
		IA_CSS_LOG("nothing to be done for this mode");
		return 0;
		/* TODO: AM: maybe this should be returning an error. */
	}

	if (!IS_ISP2401) {
	port = (unsigned int)pipe->stream->config.source.port.port;
	} else {
		/* Returns true if port is valid. So, invert it */
		err = !ia_css_mipi_is_source_port_valid(pipe, &port);
	}

	assert(port < N_CSI_PORTS);

	if ((!IS_ISP2401 && port >= N_CSI_PORTS) ||
	    (IS_ISP2401 && err)) {
	if (port >= N_CSI_PORTS) {
		IA_CSS_ERROR("send_mipi_frames(%p) exit: invalid port specified (port=%d).",
			     pipe, port);
		return err;
+0 −15
Original line number Diff line number Diff line
@@ -34,19 +34,4 @@ free_mipi_frames(struct ia_css_pipe *pipe);
int
send_mipi_frames(struct ia_css_pipe *pipe);

/**
 * @brief Calculate the required MIPI buffer sizes.
 * Based on the stream configuration, calculate the
 * required MIPI buffer sizes (in DDR words).
 *
 * @param[in]	stream_cfg		Point to the target stream configuration
 * @param[out]	size_mem_words	MIPI buffer size in DDR words.
 *
 * @return
 */
int
calculate_mipi_buff_size(
    struct ia_css_stream_config *stream_cfg,
    unsigned int *size_mem_words);

#endif /* __SH_CSS_MIPI_H */