162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2012 Mentor Graphics Inc.
462306a36Sopenharmony_ci * Copyright 2005-2012 Freescale Semiconductor, Inc. All Rights Reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci#include <linux/bitrev.h>
862306a36Sopenharmony_ci#include <linux/io.h>
962306a36Sopenharmony_ci#include <linux/sizes.h>
1062306a36Sopenharmony_ci#include <drm/drm_fourcc.h>
1162306a36Sopenharmony_ci#include "ipu-prv.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct ipu_cpmem_word {
1462306a36Sopenharmony_ci	u32 data[5];
1562306a36Sopenharmony_ci	u32 res[3];
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct ipu_ch_param {
1962306a36Sopenharmony_ci	struct ipu_cpmem_word word[2];
2062306a36Sopenharmony_ci};
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct ipu_cpmem {
2362306a36Sopenharmony_ci	struct ipu_ch_param __iomem *base;
2462306a36Sopenharmony_ci	u32 module;
2562306a36Sopenharmony_ci	spinlock_t lock;
2662306a36Sopenharmony_ci	int use_count;
2762306a36Sopenharmony_ci	struct ipu_soc *ipu;
2862306a36Sopenharmony_ci};
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#define IPU_CPMEM_WORD(word, ofs, size) ((((word) * 160 + (ofs)) << 8) | (size))
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define IPU_FIELD_UBO		IPU_CPMEM_WORD(0, 46, 22)
3362306a36Sopenharmony_ci#define IPU_FIELD_VBO		IPU_CPMEM_WORD(0, 68, 22)
3462306a36Sopenharmony_ci#define IPU_FIELD_IOX		IPU_CPMEM_WORD(0, 90, 4)
3562306a36Sopenharmony_ci#define IPU_FIELD_RDRW		IPU_CPMEM_WORD(0, 94, 1)
3662306a36Sopenharmony_ci#define IPU_FIELD_SO		IPU_CPMEM_WORD(0, 113, 1)
3762306a36Sopenharmony_ci#define IPU_FIELD_SLY		IPU_CPMEM_WORD(1, 102, 14)
3862306a36Sopenharmony_ci#define IPU_FIELD_SLUV		IPU_CPMEM_WORD(1, 128, 14)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define IPU_FIELD_XV		IPU_CPMEM_WORD(0, 0, 10)
4162306a36Sopenharmony_ci#define IPU_FIELD_YV		IPU_CPMEM_WORD(0, 10, 9)
4262306a36Sopenharmony_ci#define IPU_FIELD_XB		IPU_CPMEM_WORD(0, 19, 13)
4362306a36Sopenharmony_ci#define IPU_FIELD_YB		IPU_CPMEM_WORD(0, 32, 12)
4462306a36Sopenharmony_ci#define IPU_FIELD_NSB_B		IPU_CPMEM_WORD(0, 44, 1)
4562306a36Sopenharmony_ci#define IPU_FIELD_CF		IPU_CPMEM_WORD(0, 45, 1)
4662306a36Sopenharmony_ci#define IPU_FIELD_SX		IPU_CPMEM_WORD(0, 46, 12)
4762306a36Sopenharmony_ci#define IPU_FIELD_SY		IPU_CPMEM_WORD(0, 58, 11)
4862306a36Sopenharmony_ci#define IPU_FIELD_NS		IPU_CPMEM_WORD(0, 69, 10)
4962306a36Sopenharmony_ci#define IPU_FIELD_SDX		IPU_CPMEM_WORD(0, 79, 7)
5062306a36Sopenharmony_ci#define IPU_FIELD_SM		IPU_CPMEM_WORD(0, 86, 10)
5162306a36Sopenharmony_ci#define IPU_FIELD_SCC		IPU_CPMEM_WORD(0, 96, 1)
5262306a36Sopenharmony_ci#define IPU_FIELD_SCE		IPU_CPMEM_WORD(0, 97, 1)
5362306a36Sopenharmony_ci#define IPU_FIELD_SDY		IPU_CPMEM_WORD(0, 98, 7)
5462306a36Sopenharmony_ci#define IPU_FIELD_SDRX		IPU_CPMEM_WORD(0, 105, 1)
5562306a36Sopenharmony_ci#define IPU_FIELD_SDRY		IPU_CPMEM_WORD(0, 106, 1)
5662306a36Sopenharmony_ci#define IPU_FIELD_BPP		IPU_CPMEM_WORD(0, 107, 3)
5762306a36Sopenharmony_ci#define IPU_FIELD_DEC_SEL	IPU_CPMEM_WORD(0, 110, 2)
5862306a36Sopenharmony_ci#define IPU_FIELD_DIM		IPU_CPMEM_WORD(0, 112, 1)
5962306a36Sopenharmony_ci#define IPU_FIELD_BNDM		IPU_CPMEM_WORD(0, 114, 3)
6062306a36Sopenharmony_ci#define IPU_FIELD_BM		IPU_CPMEM_WORD(0, 117, 2)
6162306a36Sopenharmony_ci#define IPU_FIELD_ROT		IPU_CPMEM_WORD(0, 119, 1)
6262306a36Sopenharmony_ci#define IPU_FIELD_ROT_HF_VF	IPU_CPMEM_WORD(0, 119, 3)
6362306a36Sopenharmony_ci#define IPU_FIELD_HF		IPU_CPMEM_WORD(0, 120, 1)
6462306a36Sopenharmony_ci#define IPU_FIELD_VF		IPU_CPMEM_WORD(0, 121, 1)
6562306a36Sopenharmony_ci#define IPU_FIELD_THE		IPU_CPMEM_WORD(0, 122, 1)
6662306a36Sopenharmony_ci#define IPU_FIELD_CAP		IPU_CPMEM_WORD(0, 123, 1)
6762306a36Sopenharmony_ci#define IPU_FIELD_CAE		IPU_CPMEM_WORD(0, 124, 1)
6862306a36Sopenharmony_ci#define IPU_FIELD_FW		IPU_CPMEM_WORD(0, 125, 13)
6962306a36Sopenharmony_ci#define IPU_FIELD_FH		IPU_CPMEM_WORD(0, 138, 12)
7062306a36Sopenharmony_ci#define IPU_FIELD_EBA0		IPU_CPMEM_WORD(1, 0, 29)
7162306a36Sopenharmony_ci#define IPU_FIELD_EBA1		IPU_CPMEM_WORD(1, 29, 29)
7262306a36Sopenharmony_ci#define IPU_FIELD_ILO		IPU_CPMEM_WORD(1, 58, 20)
7362306a36Sopenharmony_ci#define IPU_FIELD_NPB		IPU_CPMEM_WORD(1, 78, 7)
7462306a36Sopenharmony_ci#define IPU_FIELD_PFS		IPU_CPMEM_WORD(1, 85, 4)
7562306a36Sopenharmony_ci#define IPU_FIELD_ALU		IPU_CPMEM_WORD(1, 89, 1)
7662306a36Sopenharmony_ci#define IPU_FIELD_ALBM		IPU_CPMEM_WORD(1, 90, 3)
7762306a36Sopenharmony_ci#define IPU_FIELD_ID		IPU_CPMEM_WORD(1, 93, 2)
7862306a36Sopenharmony_ci#define IPU_FIELD_TH		IPU_CPMEM_WORD(1, 95, 7)
7962306a36Sopenharmony_ci#define IPU_FIELD_SL		IPU_CPMEM_WORD(1, 102, 14)
8062306a36Sopenharmony_ci#define IPU_FIELD_WID0		IPU_CPMEM_WORD(1, 116, 3)
8162306a36Sopenharmony_ci#define IPU_FIELD_WID1		IPU_CPMEM_WORD(1, 119, 3)
8262306a36Sopenharmony_ci#define IPU_FIELD_WID2		IPU_CPMEM_WORD(1, 122, 3)
8362306a36Sopenharmony_ci#define IPU_FIELD_WID3		IPU_CPMEM_WORD(1, 125, 3)
8462306a36Sopenharmony_ci#define IPU_FIELD_OFS0		IPU_CPMEM_WORD(1, 128, 5)
8562306a36Sopenharmony_ci#define IPU_FIELD_OFS1		IPU_CPMEM_WORD(1, 133, 5)
8662306a36Sopenharmony_ci#define IPU_FIELD_OFS2		IPU_CPMEM_WORD(1, 138, 5)
8762306a36Sopenharmony_ci#define IPU_FIELD_OFS3		IPU_CPMEM_WORD(1, 143, 5)
8862306a36Sopenharmony_ci#define IPU_FIELD_SXYS		IPU_CPMEM_WORD(1, 148, 1)
8962306a36Sopenharmony_ci#define IPU_FIELD_CRE		IPU_CPMEM_WORD(1, 149, 1)
9062306a36Sopenharmony_ci#define IPU_FIELD_DEC_SEL2	IPU_CPMEM_WORD(1, 150, 1)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_cistatic inline struct ipu_ch_param __iomem *
9362306a36Sopenharmony_ciipu_get_cpmem(struct ipuv3_channel *ch)
9462306a36Sopenharmony_ci{
9562306a36Sopenharmony_ci	struct ipu_cpmem *cpmem = ch->ipu->cpmem_priv;
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	return cpmem->base + ch->num;
9862306a36Sopenharmony_ci}
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cistatic void ipu_ch_param_write_field(struct ipuv3_channel *ch, u32 wbs, u32 v)
10162306a36Sopenharmony_ci{
10262306a36Sopenharmony_ci	struct ipu_ch_param __iomem *base = ipu_get_cpmem(ch);
10362306a36Sopenharmony_ci	u32 bit = (wbs >> 8) % 160;
10462306a36Sopenharmony_ci	u32 size = wbs & 0xff;
10562306a36Sopenharmony_ci	u32 word = (wbs >> 8) / 160;
10662306a36Sopenharmony_ci	u32 i = bit / 32;
10762306a36Sopenharmony_ci	u32 ofs = bit % 32;
10862306a36Sopenharmony_ci	u32 mask = (1 << size) - 1;
10962306a36Sopenharmony_ci	u32 val;
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci	pr_debug("%s %d %d %d\n", __func__, word, bit , size);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	val = readl(&base->word[word].data[i]);
11462306a36Sopenharmony_ci	val &= ~(mask << ofs);
11562306a36Sopenharmony_ci	val |= v << ofs;
11662306a36Sopenharmony_ci	writel(val, &base->word[word].data[i]);
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	if ((bit + size - 1) / 32 > i) {
11962306a36Sopenharmony_ci		val = readl(&base->word[word].data[i + 1]);
12062306a36Sopenharmony_ci		val &= ~(mask >> (ofs ? (32 - ofs) : 0));
12162306a36Sopenharmony_ci		val |= v >> (ofs ? (32 - ofs) : 0);
12262306a36Sopenharmony_ci		writel(val, &base->word[word].data[i + 1]);
12362306a36Sopenharmony_ci	}
12462306a36Sopenharmony_ci}
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_cistatic u32 ipu_ch_param_read_field(struct ipuv3_channel *ch, u32 wbs)
12762306a36Sopenharmony_ci{
12862306a36Sopenharmony_ci	struct ipu_ch_param __iomem *base = ipu_get_cpmem(ch);
12962306a36Sopenharmony_ci	u32 bit = (wbs >> 8) % 160;
13062306a36Sopenharmony_ci	u32 size = wbs & 0xff;
13162306a36Sopenharmony_ci	u32 word = (wbs >> 8) / 160;
13262306a36Sopenharmony_ci	u32 i = bit / 32;
13362306a36Sopenharmony_ci	u32 ofs = bit % 32;
13462306a36Sopenharmony_ci	u32 mask = (1 << size) - 1;
13562306a36Sopenharmony_ci	u32 val = 0;
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	pr_debug("%s %d %d %d\n", __func__, word, bit , size);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	val = (readl(&base->word[word].data[i]) >> ofs) & mask;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	if ((bit + size - 1) / 32 > i) {
14262306a36Sopenharmony_ci		u32 tmp;
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci		tmp = readl(&base->word[word].data[i + 1]);
14562306a36Sopenharmony_ci		tmp &= mask >> (ofs ? (32 - ofs) : 0);
14662306a36Sopenharmony_ci		val |= tmp << (ofs ? (32 - ofs) : 0);
14762306a36Sopenharmony_ci	}
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci	return val;
15062306a36Sopenharmony_ci}
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/*
15362306a36Sopenharmony_ci * The V4L2 spec defines packed RGB formats in memory byte order, which from
15462306a36Sopenharmony_ci * point of view of the IPU corresponds to little-endian words with the first
15562306a36Sopenharmony_ci * component in the least significant bits.
15662306a36Sopenharmony_ci * The DRM pixel formats and IPU internal representation are ordered the other
15762306a36Sopenharmony_ci * way around, with the first named component ordered at the most significant
15862306a36Sopenharmony_ci * bits. Further, V4L2 formats are not well defined:
15962306a36Sopenharmony_ci *     https://linuxtv.org/downloads/v4l-dvb-apis/packed-rgb.html
16062306a36Sopenharmony_ci * We choose the interpretation which matches GStreamer behavior.
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_cistatic int v4l2_pix_fmt_to_drm_fourcc(u32 pixelformat)
16362306a36Sopenharmony_ci{
16462306a36Sopenharmony_ci	switch (pixelformat) {
16562306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB565:
16662306a36Sopenharmony_ci		/*
16762306a36Sopenharmony_ci		 * Here we choose the 'corrected' interpretation of RGBP, a
16862306a36Sopenharmony_ci		 * little-endian 16-bit word with the red component at the most
16962306a36Sopenharmony_ci		 * significant bits:
17062306a36Sopenharmony_ci		 * g[2:0]b[4:0] r[4:0]g[5:3] <=> [16:0] R:G:B
17162306a36Sopenharmony_ci		 */
17262306a36Sopenharmony_ci		return DRM_FORMAT_RGB565;
17362306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGR24:
17462306a36Sopenharmony_ci		/* B G R <=> [24:0] R:G:B */
17562306a36Sopenharmony_ci		return DRM_FORMAT_RGB888;
17662306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB24:
17762306a36Sopenharmony_ci		/* R G B <=> [24:0] B:G:R */
17862306a36Sopenharmony_ci		return DRM_FORMAT_BGR888;
17962306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGR32:
18062306a36Sopenharmony_ci		/* B G R A <=> [32:0] A:B:G:R */
18162306a36Sopenharmony_ci		return DRM_FORMAT_XRGB8888;
18262306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB32:
18362306a36Sopenharmony_ci		/* R G B A <=> [32:0] A:B:G:R */
18462306a36Sopenharmony_ci		return DRM_FORMAT_XBGR8888;
18562306a36Sopenharmony_ci	case V4L2_PIX_FMT_ABGR32:
18662306a36Sopenharmony_ci		/* B G R A <=> [32:0] A:R:G:B */
18762306a36Sopenharmony_ci		return DRM_FORMAT_ARGB8888;
18862306a36Sopenharmony_ci	case V4L2_PIX_FMT_XBGR32:
18962306a36Sopenharmony_ci		/* B G R X <=> [32:0] X:R:G:B */
19062306a36Sopenharmony_ci		return DRM_FORMAT_XRGB8888;
19162306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGRA32:
19262306a36Sopenharmony_ci		/* A B G R <=> [32:0] R:G:B:A */
19362306a36Sopenharmony_ci		return DRM_FORMAT_RGBA8888;
19462306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGRX32:
19562306a36Sopenharmony_ci		/* X B G R <=> [32:0] R:G:B:X */
19662306a36Sopenharmony_ci		return DRM_FORMAT_RGBX8888;
19762306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGBA32:
19862306a36Sopenharmony_ci		/* R G B A <=> [32:0] A:B:G:R */
19962306a36Sopenharmony_ci		return DRM_FORMAT_ABGR8888;
20062306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGBX32:
20162306a36Sopenharmony_ci		/* R G B X <=> [32:0] X:B:G:R */
20262306a36Sopenharmony_ci		return DRM_FORMAT_XBGR8888;
20362306a36Sopenharmony_ci	case V4L2_PIX_FMT_ARGB32:
20462306a36Sopenharmony_ci		/* A R G B <=> [32:0] B:G:R:A */
20562306a36Sopenharmony_ci		return DRM_FORMAT_BGRA8888;
20662306a36Sopenharmony_ci	case V4L2_PIX_FMT_XRGB32:
20762306a36Sopenharmony_ci		/* X R G B <=> [32:0] B:G:R:X */
20862306a36Sopenharmony_ci		return DRM_FORMAT_BGRX8888;
20962306a36Sopenharmony_ci	case V4L2_PIX_FMT_UYVY:
21062306a36Sopenharmony_ci		return DRM_FORMAT_UYVY;
21162306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUYV:
21262306a36Sopenharmony_ci		return DRM_FORMAT_YUYV;
21362306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV420:
21462306a36Sopenharmony_ci		return DRM_FORMAT_YUV420;
21562306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV422P:
21662306a36Sopenharmony_ci		return DRM_FORMAT_YUV422;
21762306a36Sopenharmony_ci	case V4L2_PIX_FMT_YVU420:
21862306a36Sopenharmony_ci		return DRM_FORMAT_YVU420;
21962306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV12:
22062306a36Sopenharmony_ci		return DRM_FORMAT_NV12;
22162306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV16:
22262306a36Sopenharmony_ci		return DRM_FORMAT_NV16;
22362306a36Sopenharmony_ci	}
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci	return -EINVAL;
22662306a36Sopenharmony_ci}
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_civoid ipu_cpmem_zero(struct ipuv3_channel *ch)
22962306a36Sopenharmony_ci{
23062306a36Sopenharmony_ci	struct ipu_ch_param __iomem *p = ipu_get_cpmem(ch);
23162306a36Sopenharmony_ci	void __iomem *base = p;
23262306a36Sopenharmony_ci	int i;
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci	for (i = 0; i < sizeof(*p) / sizeof(u32); i++)
23562306a36Sopenharmony_ci		writel(0, base + i * sizeof(u32));
23662306a36Sopenharmony_ci}
23762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_zero);
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_civoid ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int xres, int yres)
24062306a36Sopenharmony_ci{
24162306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_FW, xres - 1);
24262306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_FH, yres - 1);
24362306a36Sopenharmony_ci}
24462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_resolution);
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_civoid ipu_cpmem_skip_odd_chroma_rows(struct ipuv3_channel *ch)
24762306a36Sopenharmony_ci{
24862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_RDRW, 1);
24962306a36Sopenharmony_ci}
25062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_skip_odd_chroma_rows);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_civoid ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride)
25362306a36Sopenharmony_ci{
25462306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_SLY, stride - 1);
25562306a36Sopenharmony_ci}
25662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_stride);
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_civoid ipu_cpmem_set_high_priority(struct ipuv3_channel *ch)
25962306a36Sopenharmony_ci{
26062306a36Sopenharmony_ci	struct ipu_soc *ipu = ch->ipu;
26162306a36Sopenharmony_ci	u32 val;
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci	if (ipu->ipu_type == IPUV3EX)
26462306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_ID, 1);
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci	val = ipu_idmac_read(ipu, IDMAC_CHA_PRI(ch->num));
26762306a36Sopenharmony_ci	val |= 1 << (ch->num % 32);
26862306a36Sopenharmony_ci	ipu_idmac_write(ipu, val, IDMAC_CHA_PRI(ch->num));
26962306a36Sopenharmony_ci};
27062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_high_priority);
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_civoid ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t buf)
27362306a36Sopenharmony_ci{
27462306a36Sopenharmony_ci	WARN_ON_ONCE(buf & 0x7);
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci	if (bufnum)
27762306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_EBA1, buf >> 3);
27862306a36Sopenharmony_ci	else
27962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_EBA0, buf >> 3);
28062306a36Sopenharmony_ci}
28162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_buffer);
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_civoid ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off)
28462306a36Sopenharmony_ci{
28562306a36Sopenharmony_ci	WARN_ON_ONCE((u_off & 0x7) || (v_off & 0x7));
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_UBO, u_off / 8);
28862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_VBO, v_off / 8);
28962306a36Sopenharmony_ci}
29062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_uv_offset);
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_civoid ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride,
29362306a36Sopenharmony_ci			       u32 pixelformat)
29462306a36Sopenharmony_ci{
29562306a36Sopenharmony_ci	u32 ilo, sly, sluv;
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_ci	if (stride < 0) {
29862306a36Sopenharmony_ci		stride = -stride;
29962306a36Sopenharmony_ci		ilo = 0x100000 - (stride / 8);
30062306a36Sopenharmony_ci	} else {
30162306a36Sopenharmony_ci		ilo = stride / 8;
30262306a36Sopenharmony_ci	}
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci	sly = (stride * 2) - 1;
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci	switch (pixelformat) {
30762306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV420:
30862306a36Sopenharmony_ci	case V4L2_PIX_FMT_YVU420:
30962306a36Sopenharmony_ci		sluv = stride / 2 - 1;
31062306a36Sopenharmony_ci		break;
31162306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV12:
31262306a36Sopenharmony_ci		sluv = stride - 1;
31362306a36Sopenharmony_ci		break;
31462306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV422P:
31562306a36Sopenharmony_ci		sluv = stride - 1;
31662306a36Sopenharmony_ci		break;
31762306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV16:
31862306a36Sopenharmony_ci		sluv = stride * 2 - 1;
31962306a36Sopenharmony_ci		break;
32062306a36Sopenharmony_ci	default:
32162306a36Sopenharmony_ci		sluv = 0;
32262306a36Sopenharmony_ci		break;
32362306a36Sopenharmony_ci	}
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_SO, 1);
32662306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_ILO, ilo);
32762306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_SLY, sly);
32862306a36Sopenharmony_ci	if (sluv)
32962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_SLUV, sluv);
33062306a36Sopenharmony_ci};
33162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_interlaced_scan);
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_civoid ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id)
33462306a36Sopenharmony_ci{
33562306a36Sopenharmony_ci	id &= 0x3;
33662306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_ID, id);
33762306a36Sopenharmony_ci}
33862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_axi_id);
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ciint ipu_cpmem_get_burstsize(struct ipuv3_channel *ch)
34162306a36Sopenharmony_ci{
34262306a36Sopenharmony_ci	return ipu_ch_param_read_field(ch, IPU_FIELD_NPB) + 1;
34362306a36Sopenharmony_ci}
34462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_get_burstsize);
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_civoid ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize)
34762306a36Sopenharmony_ci{
34862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_NPB, burstsize - 1);
34962306a36Sopenharmony_ci};
35062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_burstsize);
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_civoid ipu_cpmem_set_block_mode(struct ipuv3_channel *ch)
35362306a36Sopenharmony_ci{
35462306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_BM, 1);
35562306a36Sopenharmony_ci}
35662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_block_mode);
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_civoid ipu_cpmem_set_rotation(struct ipuv3_channel *ch,
35962306a36Sopenharmony_ci			    enum ipu_rotate_mode rot)
36062306a36Sopenharmony_ci{
36162306a36Sopenharmony_ci	u32 temp_rot = bitrev8(rot) >> 5;
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_ROT_HF_VF, temp_rot);
36462306a36Sopenharmony_ci}
36562306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_rotation);
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ciint ipu_cpmem_set_format_rgb(struct ipuv3_channel *ch,
36862306a36Sopenharmony_ci			     const struct ipu_rgb *rgb)
36962306a36Sopenharmony_ci{
37062306a36Sopenharmony_ci	int bpp = 0, npb = 0, ro, go, bo, to;
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci	ro = rgb->bits_per_pixel - rgb->red.length - rgb->red.offset;
37362306a36Sopenharmony_ci	go = rgb->bits_per_pixel - rgb->green.length - rgb->green.offset;
37462306a36Sopenharmony_ci	bo = rgb->bits_per_pixel - rgb->blue.length - rgb->blue.offset;
37562306a36Sopenharmony_ci	to = rgb->bits_per_pixel - rgb->transp.length - rgb->transp.offset;
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_WID0, rgb->red.length - 1);
37862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_OFS0, ro);
37962306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_WID1, rgb->green.length - 1);
38062306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_OFS1, go);
38162306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_WID2, rgb->blue.length - 1);
38262306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_OFS2, bo);
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci	if (rgb->transp.length) {
38562306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_WID3,
38662306a36Sopenharmony_ci				rgb->transp.length - 1);
38762306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_OFS3, to);
38862306a36Sopenharmony_ci	} else {
38962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_WID3, 7);
39062306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_OFS3,
39162306a36Sopenharmony_ci				rgb->bits_per_pixel);
39262306a36Sopenharmony_ci	}
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci	switch (rgb->bits_per_pixel) {
39562306a36Sopenharmony_ci	case 32:
39662306a36Sopenharmony_ci		bpp = 0;
39762306a36Sopenharmony_ci		npb = 15;
39862306a36Sopenharmony_ci		break;
39962306a36Sopenharmony_ci	case 24:
40062306a36Sopenharmony_ci		bpp = 1;
40162306a36Sopenharmony_ci		npb = 19;
40262306a36Sopenharmony_ci		break;
40362306a36Sopenharmony_ci	case 16:
40462306a36Sopenharmony_ci		bpp = 3;
40562306a36Sopenharmony_ci		npb = 31;
40662306a36Sopenharmony_ci		break;
40762306a36Sopenharmony_ci	case 8:
40862306a36Sopenharmony_ci		bpp = 5;
40962306a36Sopenharmony_ci		npb = 63;
41062306a36Sopenharmony_ci		break;
41162306a36Sopenharmony_ci	default:
41262306a36Sopenharmony_ci		return -EINVAL;
41362306a36Sopenharmony_ci	}
41462306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_BPP, bpp);
41562306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_NPB, npb);
41662306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 7); /* rgb mode */
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_ci	return 0;
41962306a36Sopenharmony_ci}
42062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_format_rgb);
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ciint ipu_cpmem_set_format_passthrough(struct ipuv3_channel *ch, int width)
42362306a36Sopenharmony_ci{
42462306a36Sopenharmony_ci	int bpp = 0, npb = 0;
42562306a36Sopenharmony_ci
42662306a36Sopenharmony_ci	switch (width) {
42762306a36Sopenharmony_ci	case 32:
42862306a36Sopenharmony_ci		bpp = 0;
42962306a36Sopenharmony_ci		npb = 15;
43062306a36Sopenharmony_ci		break;
43162306a36Sopenharmony_ci	case 24:
43262306a36Sopenharmony_ci		bpp = 1;
43362306a36Sopenharmony_ci		npb = 19;
43462306a36Sopenharmony_ci		break;
43562306a36Sopenharmony_ci	case 16:
43662306a36Sopenharmony_ci		bpp = 3;
43762306a36Sopenharmony_ci		npb = 31;
43862306a36Sopenharmony_ci		break;
43962306a36Sopenharmony_ci	case 8:
44062306a36Sopenharmony_ci		bpp = 5;
44162306a36Sopenharmony_ci		npb = 63;
44262306a36Sopenharmony_ci		break;
44362306a36Sopenharmony_ci	default:
44462306a36Sopenharmony_ci		return -EINVAL;
44562306a36Sopenharmony_ci	}
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_BPP, bpp);
44862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_NPB, npb);
44962306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 6); /* raw mode */
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	return 0;
45262306a36Sopenharmony_ci}
45362306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_format_passthrough);
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_civoid ipu_cpmem_set_yuv_interleaved(struct ipuv3_channel *ch, u32 pixel_format)
45662306a36Sopenharmony_ci{
45762306a36Sopenharmony_ci	switch (pixel_format) {
45862306a36Sopenharmony_ci	case V4L2_PIX_FMT_UYVY:
45962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_BPP, 3); /* bits/pixel */
46062306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 0xA);/* pix fmt */
46162306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);/* burst size */
46262306a36Sopenharmony_ci		break;
46362306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUYV:
46462306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_BPP, 3); /* bits/pixel */
46562306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 0x8);/* pix fmt */
46662306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);/* burst size */
46762306a36Sopenharmony_ci		break;
46862306a36Sopenharmony_ci	}
46962306a36Sopenharmony_ci}
47062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_yuv_interleaved);
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_civoid ipu_cpmem_set_yuv_planar_full(struct ipuv3_channel *ch,
47362306a36Sopenharmony_ci				   unsigned int uv_stride,
47462306a36Sopenharmony_ci				   unsigned int u_offset, unsigned int v_offset)
47562306a36Sopenharmony_ci{
47662306a36Sopenharmony_ci	WARN_ON_ONCE((u_offset & 0x7) || (v_offset & 0x7));
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_SLUV, uv_stride - 1);
47962306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_UBO, u_offset / 8);
48062306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_VBO, v_offset / 8);
48162306a36Sopenharmony_ci}
48262306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_yuv_planar_full);
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_cistatic const struct ipu_rgb def_xrgb_32 = {
48562306a36Sopenharmony_ci	.red	= { .offset = 16, .length = 8, },
48662306a36Sopenharmony_ci	.green	= { .offset =  8, .length = 8, },
48762306a36Sopenharmony_ci	.blue	= { .offset =  0, .length = 8, },
48862306a36Sopenharmony_ci	.transp = { .offset = 24, .length = 8, },
48962306a36Sopenharmony_ci	.bits_per_pixel = 32,
49062306a36Sopenharmony_ci};
49162306a36Sopenharmony_ci
49262306a36Sopenharmony_cistatic const struct ipu_rgb def_xbgr_32 = {
49362306a36Sopenharmony_ci	.red	= { .offset =  0, .length = 8, },
49462306a36Sopenharmony_ci	.green	= { .offset =  8, .length = 8, },
49562306a36Sopenharmony_ci	.blue	= { .offset = 16, .length = 8, },
49662306a36Sopenharmony_ci	.transp = { .offset = 24, .length = 8, },
49762306a36Sopenharmony_ci	.bits_per_pixel = 32,
49862306a36Sopenharmony_ci};
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_cistatic const struct ipu_rgb def_rgbx_32 = {
50162306a36Sopenharmony_ci	.red	= { .offset = 24, .length = 8, },
50262306a36Sopenharmony_ci	.green	= { .offset = 16, .length = 8, },
50362306a36Sopenharmony_ci	.blue	= { .offset =  8, .length = 8, },
50462306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 8, },
50562306a36Sopenharmony_ci	.bits_per_pixel = 32,
50662306a36Sopenharmony_ci};
50762306a36Sopenharmony_ci
50862306a36Sopenharmony_cistatic const struct ipu_rgb def_bgrx_32 = {
50962306a36Sopenharmony_ci	.red	= { .offset =  8, .length = 8, },
51062306a36Sopenharmony_ci	.green	= { .offset = 16, .length = 8, },
51162306a36Sopenharmony_ci	.blue	= { .offset = 24, .length = 8, },
51262306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 8, },
51362306a36Sopenharmony_ci	.bits_per_pixel = 32,
51462306a36Sopenharmony_ci};
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_cistatic const struct ipu_rgb def_rgb_24 = {
51762306a36Sopenharmony_ci	.red	= { .offset = 16, .length = 8, },
51862306a36Sopenharmony_ci	.green	= { .offset =  8, .length = 8, },
51962306a36Sopenharmony_ci	.blue	= { .offset =  0, .length = 8, },
52062306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 0, },
52162306a36Sopenharmony_ci	.bits_per_pixel = 24,
52262306a36Sopenharmony_ci};
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_cistatic const struct ipu_rgb def_bgr_24 = {
52562306a36Sopenharmony_ci	.red	= { .offset =  0, .length = 8, },
52662306a36Sopenharmony_ci	.green	= { .offset =  8, .length = 8, },
52762306a36Sopenharmony_ci	.blue	= { .offset = 16, .length = 8, },
52862306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 0, },
52962306a36Sopenharmony_ci	.bits_per_pixel = 24,
53062306a36Sopenharmony_ci};
53162306a36Sopenharmony_ci
53262306a36Sopenharmony_cistatic const struct ipu_rgb def_rgb_16 = {
53362306a36Sopenharmony_ci	.red	= { .offset = 11, .length = 5, },
53462306a36Sopenharmony_ci	.green	= { .offset =  5, .length = 6, },
53562306a36Sopenharmony_ci	.blue	= { .offset =  0, .length = 5, },
53662306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 0, },
53762306a36Sopenharmony_ci	.bits_per_pixel = 16,
53862306a36Sopenharmony_ci};
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_cistatic const struct ipu_rgb def_bgr_16 = {
54162306a36Sopenharmony_ci	.red	= { .offset =  0, .length = 5, },
54262306a36Sopenharmony_ci	.green	= { .offset =  5, .length = 6, },
54362306a36Sopenharmony_ci	.blue	= { .offset = 11, .length = 5, },
54462306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 0, },
54562306a36Sopenharmony_ci	.bits_per_pixel = 16,
54662306a36Sopenharmony_ci};
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_cistatic const struct ipu_rgb def_argb_16 = {
54962306a36Sopenharmony_ci	.red	= { .offset = 10, .length = 5, },
55062306a36Sopenharmony_ci	.green	= { .offset =  5, .length = 5, },
55162306a36Sopenharmony_ci	.blue	= { .offset =  0, .length = 5, },
55262306a36Sopenharmony_ci	.transp = { .offset = 15, .length = 1, },
55362306a36Sopenharmony_ci	.bits_per_pixel = 16,
55462306a36Sopenharmony_ci};
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_cistatic const struct ipu_rgb def_argb_16_4444 = {
55762306a36Sopenharmony_ci	.red	= { .offset =  8, .length = 4, },
55862306a36Sopenharmony_ci	.green	= { .offset =  4, .length = 4, },
55962306a36Sopenharmony_ci	.blue	= { .offset =  0, .length = 4, },
56062306a36Sopenharmony_ci	.transp = { .offset = 12, .length = 4, },
56162306a36Sopenharmony_ci	.bits_per_pixel = 16,
56262306a36Sopenharmony_ci};
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_cistatic const struct ipu_rgb def_abgr_16 = {
56562306a36Sopenharmony_ci	.red	= { .offset =  0, .length = 5, },
56662306a36Sopenharmony_ci	.green	= { .offset =  5, .length = 5, },
56762306a36Sopenharmony_ci	.blue	= { .offset = 10, .length = 5, },
56862306a36Sopenharmony_ci	.transp = { .offset = 15, .length = 1, },
56962306a36Sopenharmony_ci	.bits_per_pixel = 16,
57062306a36Sopenharmony_ci};
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_cistatic const struct ipu_rgb def_rgba_16 = {
57362306a36Sopenharmony_ci	.red	= { .offset = 11, .length = 5, },
57462306a36Sopenharmony_ci	.green	= { .offset =  6, .length = 5, },
57562306a36Sopenharmony_ci	.blue	= { .offset =  1, .length = 5, },
57662306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 1, },
57762306a36Sopenharmony_ci	.bits_per_pixel = 16,
57862306a36Sopenharmony_ci};
57962306a36Sopenharmony_ci
58062306a36Sopenharmony_cistatic const struct ipu_rgb def_bgra_16 = {
58162306a36Sopenharmony_ci	.red	= { .offset =  1, .length = 5, },
58262306a36Sopenharmony_ci	.green	= { .offset =  6, .length = 5, },
58362306a36Sopenharmony_ci	.blue	= { .offset = 11, .length = 5, },
58462306a36Sopenharmony_ci	.transp = { .offset =  0, .length = 1, },
58562306a36Sopenharmony_ci	.bits_per_pixel = 16,
58662306a36Sopenharmony_ci};
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci#define Y_OFFSET(pix, x, y)	((x) + pix->bytesperline * (y))
58962306a36Sopenharmony_ci#define U_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
59062306a36Sopenharmony_ci				 (pix->bytesperline * ((y) / 2) / 2) + (x) / 2)
59162306a36Sopenharmony_ci#define V_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
59262306a36Sopenharmony_ci				 (pix->bytesperline * pix->height / 4) + \
59362306a36Sopenharmony_ci				 (pix->bytesperline * ((y) / 2) / 2) + (x) / 2)
59462306a36Sopenharmony_ci#define U2_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
59562306a36Sopenharmony_ci				 (pix->bytesperline * (y) / 2) + (x) / 2)
59662306a36Sopenharmony_ci#define V2_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
59762306a36Sopenharmony_ci				 (pix->bytesperline * pix->height / 2) + \
59862306a36Sopenharmony_ci				 (pix->bytesperline * (y) / 2) + (x) / 2)
59962306a36Sopenharmony_ci#define UV_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
60062306a36Sopenharmony_ci				 (pix->bytesperline * ((y) / 2)) + (x))
60162306a36Sopenharmony_ci#define UV2_OFFSET(pix, x, y)	((pix->bytesperline * pix->height) +	 \
60262306a36Sopenharmony_ci				 (pix->bytesperline * y) + (x))
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_ci#define NUM_ALPHA_CHANNELS	7
60562306a36Sopenharmony_ci
60662306a36Sopenharmony_ci/* See Table 37-12. Alpha channels mapping. */
60762306a36Sopenharmony_cistatic int ipu_channel_albm(int ch_num)
60862306a36Sopenharmony_ci{
60962306a36Sopenharmony_ci	switch (ch_num) {
61062306a36Sopenharmony_ci	case IPUV3_CHANNEL_G_MEM_IC_PRP_VF:	return 0;
61162306a36Sopenharmony_ci	case IPUV3_CHANNEL_G_MEM_IC_PP:		return 1;
61262306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_FG_SYNC:		return 2;
61362306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_FG_ASYNC:	return 3;
61462306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_BG_SYNC:		return 4;
61562306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_BG_ASYNC:	return 5;
61662306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB: return 6;
61762306a36Sopenharmony_ci	default:
61862306a36Sopenharmony_ci		return -EINVAL;
61962306a36Sopenharmony_ci	}
62062306a36Sopenharmony_ci}
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_cistatic void ipu_cpmem_set_separate_alpha(struct ipuv3_channel *ch)
62362306a36Sopenharmony_ci{
62462306a36Sopenharmony_ci	struct ipu_soc *ipu = ch->ipu;
62562306a36Sopenharmony_ci	int albm;
62662306a36Sopenharmony_ci	u32 val;
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ci	albm = ipu_channel_albm(ch->num);
62962306a36Sopenharmony_ci	if (albm < 0)
63062306a36Sopenharmony_ci		return;
63162306a36Sopenharmony_ci
63262306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_ALU, 1);
63362306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_ALBM, albm);
63462306a36Sopenharmony_ci	ipu_ch_param_write_field(ch, IPU_FIELD_CRE, 1);
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_ci	val = ipu_idmac_read(ipu, IDMAC_SEP_ALPHA);
63762306a36Sopenharmony_ci	val |= BIT(ch->num);
63862306a36Sopenharmony_ci	ipu_idmac_write(ipu, val, IDMAC_SEP_ALPHA);
63962306a36Sopenharmony_ci}
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_ciint ipu_cpmem_set_fmt(struct ipuv3_channel *ch, u32 drm_fourcc)
64262306a36Sopenharmony_ci{
64362306a36Sopenharmony_ci	switch (drm_fourcc) {
64462306a36Sopenharmony_ci	case DRM_FORMAT_YUV420:
64562306a36Sopenharmony_ci	case DRM_FORMAT_YVU420:
64662306a36Sopenharmony_ci		/* pix format */
64762306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 2);
64862306a36Sopenharmony_ci		/* burst size */
64962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
65062306a36Sopenharmony_ci		break;
65162306a36Sopenharmony_ci	case DRM_FORMAT_YUV422:
65262306a36Sopenharmony_ci	case DRM_FORMAT_YVU422:
65362306a36Sopenharmony_ci		/* pix format */
65462306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 1);
65562306a36Sopenharmony_ci		/* burst size */
65662306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
65762306a36Sopenharmony_ci		break;
65862306a36Sopenharmony_ci	case DRM_FORMAT_YUV444:
65962306a36Sopenharmony_ci	case DRM_FORMAT_YVU444:
66062306a36Sopenharmony_ci		/* pix format */
66162306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 0);
66262306a36Sopenharmony_ci		/* burst size */
66362306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
66462306a36Sopenharmony_ci		break;
66562306a36Sopenharmony_ci	case DRM_FORMAT_NV12:
66662306a36Sopenharmony_ci		/* pix format */
66762306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 4);
66862306a36Sopenharmony_ci		/* burst size */
66962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
67062306a36Sopenharmony_ci		break;
67162306a36Sopenharmony_ci	case DRM_FORMAT_NV16:
67262306a36Sopenharmony_ci		/* pix format */
67362306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 3);
67462306a36Sopenharmony_ci		/* burst size */
67562306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
67662306a36Sopenharmony_ci		break;
67762306a36Sopenharmony_ci	case DRM_FORMAT_UYVY:
67862306a36Sopenharmony_ci		/* bits/pixel */
67962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_BPP, 3);
68062306a36Sopenharmony_ci		/* pix format */
68162306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 0xA);
68262306a36Sopenharmony_ci		/* burst size */
68362306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
68462306a36Sopenharmony_ci		break;
68562306a36Sopenharmony_ci	case DRM_FORMAT_YUYV:
68662306a36Sopenharmony_ci		/* bits/pixel */
68762306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_BPP, 3);
68862306a36Sopenharmony_ci		/* pix format */
68962306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_PFS, 0x8);
69062306a36Sopenharmony_ci		/* burst size */
69162306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_NPB, 31);
69262306a36Sopenharmony_ci		break;
69362306a36Sopenharmony_ci	case DRM_FORMAT_ABGR8888:
69462306a36Sopenharmony_ci	case DRM_FORMAT_XBGR8888:
69562306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_xbgr_32);
69662306a36Sopenharmony_ci		break;
69762306a36Sopenharmony_ci	case DRM_FORMAT_ARGB8888:
69862306a36Sopenharmony_ci	case DRM_FORMAT_XRGB8888:
69962306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_xrgb_32);
70062306a36Sopenharmony_ci		break;
70162306a36Sopenharmony_ci	case DRM_FORMAT_RGBA8888:
70262306a36Sopenharmony_ci	case DRM_FORMAT_RGBX8888:
70362306a36Sopenharmony_ci	case DRM_FORMAT_RGBX8888_A8:
70462306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_rgbx_32);
70562306a36Sopenharmony_ci		break;
70662306a36Sopenharmony_ci	case DRM_FORMAT_BGRA8888:
70762306a36Sopenharmony_ci	case DRM_FORMAT_BGRX8888:
70862306a36Sopenharmony_ci	case DRM_FORMAT_BGRX8888_A8:
70962306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_bgrx_32);
71062306a36Sopenharmony_ci		break;
71162306a36Sopenharmony_ci	case DRM_FORMAT_BGR888:
71262306a36Sopenharmony_ci	case DRM_FORMAT_BGR888_A8:
71362306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_bgr_24);
71462306a36Sopenharmony_ci		break;
71562306a36Sopenharmony_ci	case DRM_FORMAT_RGB888:
71662306a36Sopenharmony_ci	case DRM_FORMAT_RGB888_A8:
71762306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_rgb_24);
71862306a36Sopenharmony_ci		break;
71962306a36Sopenharmony_ci	case DRM_FORMAT_RGB565:
72062306a36Sopenharmony_ci	case DRM_FORMAT_RGB565_A8:
72162306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_rgb_16);
72262306a36Sopenharmony_ci		break;
72362306a36Sopenharmony_ci	case DRM_FORMAT_BGR565:
72462306a36Sopenharmony_ci	case DRM_FORMAT_BGR565_A8:
72562306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_bgr_16);
72662306a36Sopenharmony_ci		break;
72762306a36Sopenharmony_ci	case DRM_FORMAT_ARGB1555:
72862306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_argb_16);
72962306a36Sopenharmony_ci		break;
73062306a36Sopenharmony_ci	case DRM_FORMAT_ABGR1555:
73162306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_abgr_16);
73262306a36Sopenharmony_ci		break;
73362306a36Sopenharmony_ci	case DRM_FORMAT_RGBA5551:
73462306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_rgba_16);
73562306a36Sopenharmony_ci		break;
73662306a36Sopenharmony_ci	case DRM_FORMAT_BGRA5551:
73762306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_bgra_16);
73862306a36Sopenharmony_ci		break;
73962306a36Sopenharmony_ci	case DRM_FORMAT_ARGB4444:
74062306a36Sopenharmony_ci		ipu_cpmem_set_format_rgb(ch, &def_argb_16_4444);
74162306a36Sopenharmony_ci		break;
74262306a36Sopenharmony_ci	default:
74362306a36Sopenharmony_ci		return -EINVAL;
74462306a36Sopenharmony_ci	}
74562306a36Sopenharmony_ci
74662306a36Sopenharmony_ci	switch (drm_fourcc) {
74762306a36Sopenharmony_ci	case DRM_FORMAT_RGB565_A8:
74862306a36Sopenharmony_ci	case DRM_FORMAT_BGR565_A8:
74962306a36Sopenharmony_ci	case DRM_FORMAT_RGB888_A8:
75062306a36Sopenharmony_ci	case DRM_FORMAT_BGR888_A8:
75162306a36Sopenharmony_ci	case DRM_FORMAT_RGBX8888_A8:
75262306a36Sopenharmony_ci	case DRM_FORMAT_BGRX8888_A8:
75362306a36Sopenharmony_ci		ipu_ch_param_write_field(ch, IPU_FIELD_WID3, 7);
75462306a36Sopenharmony_ci		ipu_cpmem_set_separate_alpha(ch);
75562306a36Sopenharmony_ci		break;
75662306a36Sopenharmony_ci	default:
75762306a36Sopenharmony_ci		break;
75862306a36Sopenharmony_ci	}
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_ci	return 0;
76162306a36Sopenharmony_ci}
76262306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_fmt);
76362306a36Sopenharmony_ci
76462306a36Sopenharmony_ciint ipu_cpmem_set_image(struct ipuv3_channel *ch, struct ipu_image *image)
76562306a36Sopenharmony_ci{
76662306a36Sopenharmony_ci	struct v4l2_pix_format *pix = &image->pix;
76762306a36Sopenharmony_ci	int offset, u_offset, v_offset;
76862306a36Sopenharmony_ci	int ret = 0;
76962306a36Sopenharmony_ci
77062306a36Sopenharmony_ci	pr_debug("%s: resolution: %dx%d stride: %d\n",
77162306a36Sopenharmony_ci		 __func__, pix->width, pix->height,
77262306a36Sopenharmony_ci		 pix->bytesperline);
77362306a36Sopenharmony_ci
77462306a36Sopenharmony_ci	ipu_cpmem_set_resolution(ch, image->rect.width, image->rect.height);
77562306a36Sopenharmony_ci	ipu_cpmem_set_stride(ch, pix->bytesperline);
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_ci	ipu_cpmem_set_fmt(ch, v4l2_pix_fmt_to_drm_fourcc(pix->pixelformat));
77862306a36Sopenharmony_ci
77962306a36Sopenharmony_ci	switch (pix->pixelformat) {
78062306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV420:
78162306a36Sopenharmony_ci		offset = Y_OFFSET(pix, image->rect.left, image->rect.top);
78262306a36Sopenharmony_ci		u_offset = image->u_offset ?
78362306a36Sopenharmony_ci			image->u_offset : U_OFFSET(pix, image->rect.left,
78462306a36Sopenharmony_ci						   image->rect.top) - offset;
78562306a36Sopenharmony_ci		v_offset = image->v_offset ?
78662306a36Sopenharmony_ci			image->v_offset : V_OFFSET(pix, image->rect.left,
78762306a36Sopenharmony_ci						   image->rect.top) - offset;
78862306a36Sopenharmony_ci
78962306a36Sopenharmony_ci		ipu_cpmem_set_yuv_planar_full(ch, pix->bytesperline / 2,
79062306a36Sopenharmony_ci					      u_offset, v_offset);
79162306a36Sopenharmony_ci		break;
79262306a36Sopenharmony_ci	case V4L2_PIX_FMT_YVU420:
79362306a36Sopenharmony_ci		offset = Y_OFFSET(pix, image->rect.left, image->rect.top);
79462306a36Sopenharmony_ci		u_offset = image->u_offset ?
79562306a36Sopenharmony_ci			image->u_offset : V_OFFSET(pix, image->rect.left,
79662306a36Sopenharmony_ci						   image->rect.top) - offset;
79762306a36Sopenharmony_ci		v_offset = image->v_offset ?
79862306a36Sopenharmony_ci			image->v_offset : U_OFFSET(pix, image->rect.left,
79962306a36Sopenharmony_ci						   image->rect.top) - offset;
80062306a36Sopenharmony_ci
80162306a36Sopenharmony_ci		ipu_cpmem_set_yuv_planar_full(ch, pix->bytesperline / 2,
80262306a36Sopenharmony_ci					      u_offset, v_offset);
80362306a36Sopenharmony_ci		break;
80462306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUV422P:
80562306a36Sopenharmony_ci		offset = Y_OFFSET(pix, image->rect.left, image->rect.top);
80662306a36Sopenharmony_ci		u_offset = image->u_offset ?
80762306a36Sopenharmony_ci			image->u_offset : U2_OFFSET(pix, image->rect.left,
80862306a36Sopenharmony_ci						    image->rect.top) - offset;
80962306a36Sopenharmony_ci		v_offset = image->v_offset ?
81062306a36Sopenharmony_ci			image->v_offset : V2_OFFSET(pix, image->rect.left,
81162306a36Sopenharmony_ci						    image->rect.top) - offset;
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci		ipu_cpmem_set_yuv_planar_full(ch, pix->bytesperline / 2,
81462306a36Sopenharmony_ci					      u_offset, v_offset);
81562306a36Sopenharmony_ci		break;
81662306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV12:
81762306a36Sopenharmony_ci		offset = Y_OFFSET(pix, image->rect.left, image->rect.top);
81862306a36Sopenharmony_ci		u_offset = image->u_offset ?
81962306a36Sopenharmony_ci			image->u_offset : UV_OFFSET(pix, image->rect.left,
82062306a36Sopenharmony_ci						    image->rect.top) - offset;
82162306a36Sopenharmony_ci		v_offset = image->v_offset ? image->v_offset : 0;
82262306a36Sopenharmony_ci
82362306a36Sopenharmony_ci		ipu_cpmem_set_yuv_planar_full(ch, pix->bytesperline,
82462306a36Sopenharmony_ci					      u_offset, v_offset);
82562306a36Sopenharmony_ci		break;
82662306a36Sopenharmony_ci	case V4L2_PIX_FMT_NV16:
82762306a36Sopenharmony_ci		offset = Y_OFFSET(pix, image->rect.left, image->rect.top);
82862306a36Sopenharmony_ci		u_offset = image->u_offset ?
82962306a36Sopenharmony_ci			image->u_offset : UV2_OFFSET(pix, image->rect.left,
83062306a36Sopenharmony_ci						     image->rect.top) - offset;
83162306a36Sopenharmony_ci		v_offset = image->v_offset ? image->v_offset : 0;
83262306a36Sopenharmony_ci
83362306a36Sopenharmony_ci		ipu_cpmem_set_yuv_planar_full(ch, pix->bytesperline,
83462306a36Sopenharmony_ci					      u_offset, v_offset);
83562306a36Sopenharmony_ci		break;
83662306a36Sopenharmony_ci	case V4L2_PIX_FMT_UYVY:
83762306a36Sopenharmony_ci	case V4L2_PIX_FMT_YUYV:
83862306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB565:
83962306a36Sopenharmony_ci		offset = image->rect.left * 2 +
84062306a36Sopenharmony_ci			image->rect.top * pix->bytesperline;
84162306a36Sopenharmony_ci		break;
84262306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB32:
84362306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGR32:
84462306a36Sopenharmony_ci	case V4L2_PIX_FMT_ABGR32:
84562306a36Sopenharmony_ci	case V4L2_PIX_FMT_XBGR32:
84662306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGRA32:
84762306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGRX32:
84862306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGBA32:
84962306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGBX32:
85062306a36Sopenharmony_ci	case V4L2_PIX_FMT_ARGB32:
85162306a36Sopenharmony_ci	case V4L2_PIX_FMT_XRGB32:
85262306a36Sopenharmony_ci		offset = image->rect.left * 4 +
85362306a36Sopenharmony_ci			image->rect.top * pix->bytesperline;
85462306a36Sopenharmony_ci		break;
85562306a36Sopenharmony_ci	case V4L2_PIX_FMT_RGB24:
85662306a36Sopenharmony_ci	case V4L2_PIX_FMT_BGR24:
85762306a36Sopenharmony_ci		offset = image->rect.left * 3 +
85862306a36Sopenharmony_ci			image->rect.top * pix->bytesperline;
85962306a36Sopenharmony_ci		break;
86062306a36Sopenharmony_ci	case V4L2_PIX_FMT_SBGGR8:
86162306a36Sopenharmony_ci	case V4L2_PIX_FMT_SGBRG8:
86262306a36Sopenharmony_ci	case V4L2_PIX_FMT_SGRBG8:
86362306a36Sopenharmony_ci	case V4L2_PIX_FMT_SRGGB8:
86462306a36Sopenharmony_ci	case V4L2_PIX_FMT_GREY:
86562306a36Sopenharmony_ci		offset = image->rect.left + image->rect.top * pix->bytesperline;
86662306a36Sopenharmony_ci		break;
86762306a36Sopenharmony_ci	case V4L2_PIX_FMT_SBGGR16:
86862306a36Sopenharmony_ci	case V4L2_PIX_FMT_SGBRG16:
86962306a36Sopenharmony_ci	case V4L2_PIX_FMT_SGRBG16:
87062306a36Sopenharmony_ci	case V4L2_PIX_FMT_SRGGB16:
87162306a36Sopenharmony_ci	case V4L2_PIX_FMT_Y16:
87262306a36Sopenharmony_ci		offset = image->rect.left * 2 +
87362306a36Sopenharmony_ci			 image->rect.top * pix->bytesperline;
87462306a36Sopenharmony_ci		break;
87562306a36Sopenharmony_ci	default:
87662306a36Sopenharmony_ci		/* This should not happen */
87762306a36Sopenharmony_ci		WARN_ON(1);
87862306a36Sopenharmony_ci		offset = 0;
87962306a36Sopenharmony_ci		ret = -EINVAL;
88062306a36Sopenharmony_ci	}
88162306a36Sopenharmony_ci
88262306a36Sopenharmony_ci	ipu_cpmem_set_buffer(ch, 0, image->phys0 + offset);
88362306a36Sopenharmony_ci	ipu_cpmem_set_buffer(ch, 1, image->phys1 + offset);
88462306a36Sopenharmony_ci
88562306a36Sopenharmony_ci	return ret;
88662306a36Sopenharmony_ci}
88762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_set_image);
88862306a36Sopenharmony_ci
88962306a36Sopenharmony_civoid ipu_cpmem_dump(struct ipuv3_channel *ch)
89062306a36Sopenharmony_ci{
89162306a36Sopenharmony_ci	struct ipu_ch_param __iomem *p = ipu_get_cpmem(ch);
89262306a36Sopenharmony_ci	struct ipu_soc *ipu = ch->ipu;
89362306a36Sopenharmony_ci	int chno = ch->num;
89462306a36Sopenharmony_ci
89562306a36Sopenharmony_ci	dev_dbg(ipu->dev, "ch %d word 0 - %08X %08X %08X %08X %08X\n", chno,
89662306a36Sopenharmony_ci		readl(&p->word[0].data[0]),
89762306a36Sopenharmony_ci		readl(&p->word[0].data[1]),
89862306a36Sopenharmony_ci		readl(&p->word[0].data[2]),
89962306a36Sopenharmony_ci		readl(&p->word[0].data[3]),
90062306a36Sopenharmony_ci		readl(&p->word[0].data[4]));
90162306a36Sopenharmony_ci	dev_dbg(ipu->dev, "ch %d word 1 - %08X %08X %08X %08X %08X\n", chno,
90262306a36Sopenharmony_ci		readl(&p->word[1].data[0]),
90362306a36Sopenharmony_ci		readl(&p->word[1].data[1]),
90462306a36Sopenharmony_ci		readl(&p->word[1].data[2]),
90562306a36Sopenharmony_ci		readl(&p->word[1].data[3]),
90662306a36Sopenharmony_ci		readl(&p->word[1].data[4]));
90762306a36Sopenharmony_ci	dev_dbg(ipu->dev, "PFS 0x%x, ",
90862306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_PFS));
90962306a36Sopenharmony_ci	dev_dbg(ipu->dev, "BPP 0x%x, ",
91062306a36Sopenharmony_ci		ipu_ch_param_read_field(ch, IPU_FIELD_BPP));
91162306a36Sopenharmony_ci	dev_dbg(ipu->dev, "NPB 0x%x\n",
91262306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_NPB));
91362306a36Sopenharmony_ci
91462306a36Sopenharmony_ci	dev_dbg(ipu->dev, "FW %d, ",
91562306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_FW));
91662306a36Sopenharmony_ci	dev_dbg(ipu->dev, "FH %d, ",
91762306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_FH));
91862306a36Sopenharmony_ci	dev_dbg(ipu->dev, "EBA0 0x%x\n",
91962306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_EBA0) << 3);
92062306a36Sopenharmony_ci	dev_dbg(ipu->dev, "EBA1 0x%x\n",
92162306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_EBA1) << 3);
92262306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Stride %d\n",
92362306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_SL));
92462306a36Sopenharmony_ci	dev_dbg(ipu->dev, "scan_order %d\n",
92562306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_SO));
92662306a36Sopenharmony_ci	dev_dbg(ipu->dev, "uv_stride %d\n",
92762306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_SLUV));
92862306a36Sopenharmony_ci	dev_dbg(ipu->dev, "u_offset 0x%x\n",
92962306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_UBO) << 3);
93062306a36Sopenharmony_ci	dev_dbg(ipu->dev, "v_offset 0x%x\n",
93162306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_VBO) << 3);
93262306a36Sopenharmony_ci
93362306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Width0 %d+1, ",
93462306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_WID0));
93562306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Width1 %d+1, ",
93662306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_WID1));
93762306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Width2 %d+1, ",
93862306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_WID2));
93962306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Width3 %d+1, ",
94062306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_WID3));
94162306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Offset0 %d, ",
94262306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_OFS0));
94362306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Offset1 %d, ",
94462306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_OFS1));
94562306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Offset2 %d, ",
94662306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_OFS2));
94762306a36Sopenharmony_ci	dev_dbg(ipu->dev, "Offset3 %d\n",
94862306a36Sopenharmony_ci		 ipu_ch_param_read_field(ch, IPU_FIELD_OFS3));
94962306a36Sopenharmony_ci}
95062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(ipu_cpmem_dump);
95162306a36Sopenharmony_ci
95262306a36Sopenharmony_ciint ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base)
95362306a36Sopenharmony_ci{
95462306a36Sopenharmony_ci	struct ipu_cpmem *cpmem;
95562306a36Sopenharmony_ci
95662306a36Sopenharmony_ci	cpmem = devm_kzalloc(dev, sizeof(*cpmem), GFP_KERNEL);
95762306a36Sopenharmony_ci	if (!cpmem)
95862306a36Sopenharmony_ci		return -ENOMEM;
95962306a36Sopenharmony_ci
96062306a36Sopenharmony_ci	ipu->cpmem_priv = cpmem;
96162306a36Sopenharmony_ci
96262306a36Sopenharmony_ci	spin_lock_init(&cpmem->lock);
96362306a36Sopenharmony_ci	cpmem->base = devm_ioremap(dev, base, SZ_128K);
96462306a36Sopenharmony_ci	if (!cpmem->base)
96562306a36Sopenharmony_ci		return -ENOMEM;
96662306a36Sopenharmony_ci
96762306a36Sopenharmony_ci	dev_dbg(dev, "CPMEM base: 0x%08lx remapped to %p\n",
96862306a36Sopenharmony_ci		base, cpmem->base);
96962306a36Sopenharmony_ci	cpmem->ipu = ipu;
97062306a36Sopenharmony_ci
97162306a36Sopenharmony_ci	return 0;
97262306a36Sopenharmony_ci}
97362306a36Sopenharmony_ci
97462306a36Sopenharmony_civoid ipu_cpmem_exit(struct ipu_soc *ipu)
97562306a36Sopenharmony_ci{
97662306a36Sopenharmony_ci}
977