Commit 89a0f667 authored by Luca Ceresoli's avatar Luca Ceresoli Committed by Hans Verkuil
Browse files

staging: media: tegra-video: move syncpt init/free to a per-soc op



tegra_channel_host1x_syncpt_init() gets the host1x syncpts needed for the
Tegra210 implementation, and tegra_channel_host1x_syncpts_free() puts
them.

Tegra20 needs to get and put a different syncpt. In preparation for adding
Tegra20 support, move these functions to new ops in the soc-specific
`struct tegra_vi_ops` .

No functional changes.

Signed-off-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: default avatarDmitry Osipenko <digetx@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent ef9435a5
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -179,6 +179,56 @@ static u32 vi_csi_read(struct tegra_vi_channel *chan, u8 portno,
/*
 * Tegra210 VI channel capture operations
 */

static int tegra210_channel_host1x_syncpt_init(struct tegra_vi_channel *chan)
{
	struct tegra_vi *vi = chan->vi;
	unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED;
	struct host1x_syncpt *fs_sp;
	struct host1x_syncpt *mw_sp;
	int ret, i;

	for (i = 0; i < chan->numgangports; i++) {
		fs_sp = host1x_syncpt_request(&vi->client, flags);
		if (!fs_sp) {
			dev_err(vi->dev, "failed to request frame start syncpoint\n");
			ret = -ENOMEM;
			goto free_syncpts;
		}

		mw_sp = host1x_syncpt_request(&vi->client, flags);
		if (!mw_sp) {
			dev_err(vi->dev, "failed to request memory ack syncpoint\n");
			host1x_syncpt_put(fs_sp);
			ret = -ENOMEM;
			goto free_syncpts;
		}

		chan->frame_start_sp[i] = fs_sp;
		chan->mw_ack_sp[i] = mw_sp;
		spin_lock_init(&chan->sp_incr_lock[i]);
	}

	return 0;

free_syncpts:
	for (i = 0; i < chan->numgangports; i++) {
		host1x_syncpt_put(chan->mw_ack_sp[i]);
		host1x_syncpt_put(chan->frame_start_sp[i]);
	}
	return ret;
}

static void tegra210_channel_host1x_syncpt_free(struct tegra_vi_channel *chan)
{
	int i;

	for (i = 0; i < chan->numgangports; i++) {
		host1x_syncpt_put(chan->mw_ack_sp[i]);
		host1x_syncpt_put(chan->frame_start_sp[i]);
	}
}

static void tegra210_fmt_align(struct v4l2_pix_format *pix, unsigned int bpp)
{
	unsigned int min_bpl;
@@ -753,6 +803,8 @@ static const struct tegra_video_format tegra210_video_formats[] = {

/* Tegra210 VI operations */
static const struct tegra_vi_ops tegra210_vi_ops = {
	.channel_host1x_syncpt_init = tegra210_channel_host1x_syncpt_init,
	.channel_host1x_syncpt_free = tegra210_channel_host1x_syncpt_free,
	.vi_fmt_align = tegra210_fmt_align,
	.vi_start_streaming = tegra210_vi_start_streaming,
	.vi_stop_streaming = tegra210_vi_stop_streaming,
+3 −49
Original line number Diff line number Diff line
@@ -1064,21 +1064,11 @@ static int vi_fmts_bitmap_init(struct tegra_vi_channel *chan)
	return 0;
}

static void tegra_channel_host1x_syncpts_free(struct tegra_vi_channel *chan)
{
	int i;

	for (i = 0; i < chan->numgangports; i++) {
		host1x_syncpt_put(chan->mw_ack_sp[i]);
		host1x_syncpt_put(chan->frame_start_sp[i]);
	}
}

static void tegra_channel_cleanup(struct tegra_vi_channel *chan)
{
	v4l2_ctrl_handler_free(&chan->ctrl_handler);
	media_entity_cleanup(&chan->video.entity);
	tegra_channel_host1x_syncpts_free(chan);
	chan->vi->ops->channel_host1x_syncpt_free(chan);
	mutex_destroy(&chan->video_lock);
}

@@ -1096,42 +1086,6 @@ void tegra_channels_cleanup(struct tegra_vi *vi)
	}
}

static int tegra_channel_host1x_syncpt_init(struct tegra_vi_channel *chan)
{
	struct tegra_vi *vi = chan->vi;
	unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED;
	struct host1x_syncpt *fs_sp;
	struct host1x_syncpt *mw_sp;
	int ret, i;

	for (i = 0; i < chan->numgangports; i++) {
		fs_sp = host1x_syncpt_request(&vi->client, flags);
		if (!fs_sp) {
			dev_err(vi->dev, "failed to request frame start syncpoint\n");
			ret = -ENOMEM;
			goto free_syncpts;
		}

		mw_sp = host1x_syncpt_request(&vi->client, flags);
		if (!mw_sp) {
			dev_err(vi->dev, "failed to request memory ack syncpoint\n");
			host1x_syncpt_put(fs_sp);
			ret = -ENOMEM;
			goto free_syncpts;
		}

		chan->frame_start_sp[i] = fs_sp;
		chan->mw_ack_sp[i] = mw_sp;
		spin_lock_init(&chan->sp_incr_lock[i]);
	}

	return 0;

free_syncpts:
	tegra_channel_host1x_syncpts_free(chan);
	return ret;
}

static int tegra_channel_init(struct tegra_vi_channel *chan)
{
	struct tegra_vi *vi = chan->vi;
@@ -1157,7 +1111,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
	chan->format.sizeimage = chan->format.bytesperline * TEGRA_DEF_HEIGHT;
	vi->ops->vi_fmt_align(&chan->format, chan->fmtinfo->bpp);

	ret = tegra_channel_host1x_syncpt_init(chan);
	ret = vi->ops->channel_host1x_syncpt_init(chan);
	if (ret)
		return ret;

@@ -1220,7 +1174,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
cleanup_media:
	media_entity_cleanup(&chan->video.entity);
free_syncpts:
	tegra_channel_host1x_syncpts_free(chan);
	vi->ops->channel_host1x_syncpt_free(chan);
	return ret;
}

+5 −0
Original line number Diff line number Diff line
@@ -38,10 +38,13 @@ enum tegra_vi_pg_mode {
};

struct tegra_vi;
struct tegra_vi_channel;

/**
 * struct tegra_vi_ops - Tegra VI operations
 * @vi_enable: soc-specific operations needed to enable/disable the VI peripheral
 * @channel_host1x_syncpt_init: initialize synchronization points
 * @channel_host1x_syncpt_free: free all synchronization points
 * @vi_fmt_align: modify `pix` to fit the hardware alignment
 *		requirements and fill image geometry
 * @vi_start_streaming: starts media pipeline, subdevice streaming, sets up
@@ -52,6 +55,8 @@ struct tegra_vi;
 */
struct tegra_vi_ops {
	int (*vi_enable)(struct tegra_vi *vi, bool on);
	int (*channel_host1x_syncpt_init)(struct tegra_vi_channel *chan);
	void (*channel_host1x_syncpt_free)(struct tegra_vi_channel *chan);
	void (*vi_fmt_align)(struct v4l2_pix_format *pix, unsigned int bpp);
	int (*vi_start_streaming)(struct vb2_queue *vq, u32 count);
	void (*vi_stop_streaming)(struct vb2_queue *vq);