xref: /linux/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
146fb9995SMauro Carvalho Chehab /* SPDX-License-Identifier: GPL-2.0 */
246fb9995SMauro Carvalho Chehab /*
346fb9995SMauro Carvalho Chehab  * i.MX8QXP/i.MX8QM JPEG encoder/decoder v4l2 driver
446fb9995SMauro Carvalho Chehab  *
546fb9995SMauro Carvalho Chehab  * Copyright 2018-2019 NXP
646fb9995SMauro Carvalho Chehab  */
746fb9995SMauro Carvalho Chehab 
846fb9995SMauro Carvalho Chehab #ifndef _MXC_JPEG_HW_H
946fb9995SMauro Carvalho Chehab #define _MXC_JPEG_HW_H
1046fb9995SMauro Carvalho Chehab 
1146fb9995SMauro Carvalho Chehab /* JPEG Decoder/Encoder Wrapper Register Map */
1246fb9995SMauro Carvalho Chehab #define GLB_CTRL			0x0
1346fb9995SMauro Carvalho Chehab #define COM_STATUS			0x4
1446fb9995SMauro Carvalho Chehab #define BUF_BASE0			0x14
1546fb9995SMauro Carvalho Chehab #define BUF_BASE1			0x18
1646fb9995SMauro Carvalho Chehab #define LINE_PITCH			0x1C
1746fb9995SMauro Carvalho Chehab #define STM_BUFBASE			0x20
1846fb9995SMauro Carvalho Chehab #define STM_BUFSIZE			0x24
1946fb9995SMauro Carvalho Chehab #define IMGSIZE				0x28
2046fb9995SMauro Carvalho Chehab #define STM_CTRL			0x2C
2146fb9995SMauro Carvalho Chehab 
2246fb9995SMauro Carvalho Chehab /* CAST JPEG-Decoder/Encoder Status Register Map (read-only)*/
2346fb9995SMauro Carvalho Chehab #define CAST_STATUS0			0x100
2446fb9995SMauro Carvalho Chehab #define CAST_STATUS1			0x104
2546fb9995SMauro Carvalho Chehab #define CAST_STATUS2			0x108
2646fb9995SMauro Carvalho Chehab #define CAST_STATUS3			0x10c
2746fb9995SMauro Carvalho Chehab #define CAST_STATUS4			0x110
2846fb9995SMauro Carvalho Chehab #define CAST_STATUS5			0x114
2946fb9995SMauro Carvalho Chehab #define CAST_STATUS6			0x118
3046fb9995SMauro Carvalho Chehab #define CAST_STATUS7			0x11c
3146fb9995SMauro Carvalho Chehab #define CAST_STATUS8			0x120
3246fb9995SMauro Carvalho Chehab #define CAST_STATUS9			0x124
3346fb9995SMauro Carvalho Chehab #define CAST_STATUS10			0x128
3446fb9995SMauro Carvalho Chehab #define CAST_STATUS11			0x12c
3546fb9995SMauro Carvalho Chehab #define CAST_STATUS12			0x130
3646fb9995SMauro Carvalho Chehab #define CAST_STATUS13			0x134
3746fb9995SMauro Carvalho Chehab /* the following are for encoder only */
3846fb9995SMauro Carvalho Chehab #define CAST_STATUS14		0x138
3946fb9995SMauro Carvalho Chehab #define CAST_STATUS15		0x13c
4046fb9995SMauro Carvalho Chehab #define CAST_STATUS16		0x140
4146fb9995SMauro Carvalho Chehab #define CAST_STATUS17		0x144
4246fb9995SMauro Carvalho Chehab #define CAST_STATUS18		0x148
4346fb9995SMauro Carvalho Chehab #define CAST_STATUS19		0x14c
4446fb9995SMauro Carvalho Chehab 
4546fb9995SMauro Carvalho Chehab /* CAST JPEG-Decoder Control Register Map (write-only) */
4646fb9995SMauro Carvalho Chehab #define CAST_CTRL			CAST_STATUS13
4746fb9995SMauro Carvalho Chehab 
4846fb9995SMauro Carvalho Chehab /* CAST JPEG-Encoder Control Register Map (write-only) */
4946fb9995SMauro Carvalho Chehab #define CAST_MODE			CAST_STATUS0
5046fb9995SMauro Carvalho Chehab #define CAST_CFG_MODE			CAST_STATUS1
5146fb9995SMauro Carvalho Chehab #define CAST_QUALITY			CAST_STATUS2
5246fb9995SMauro Carvalho Chehab #define CAST_RSVD			CAST_STATUS3
5346fb9995SMauro Carvalho Chehab #define CAST_REC_REGS_SEL		CAST_STATUS4
5446fb9995SMauro Carvalho Chehab #define CAST_LUMTH			CAST_STATUS5
5546fb9995SMauro Carvalho Chehab #define CAST_CHRTH			CAST_STATUS6
565a601f89SMing Qian #define CAST_NOMFRSIZE_LO		CAST_STATUS16
575a601f89SMing Qian #define CAST_NOMFRSIZE_HI		CAST_STATUS17
585a601f89SMing Qian #define CAST_OFBSIZE_LO			CAST_STATUS18
595a601f89SMing Qian #define CAST_OFBSIZE_HI			CAST_STATUS19
6046fb9995SMauro Carvalho Chehab 
6146fb9995SMauro Carvalho Chehab /* JPEG-Decoder Wrapper Slot Registers 0..3 */
6246fb9995SMauro Carvalho Chehab #define SLOT_BASE			0x10000
6346fb9995SMauro Carvalho Chehab #define SLOT_STATUS			0x0
6446fb9995SMauro Carvalho Chehab #define SLOT_IRQ_EN			0x4
6546fb9995SMauro Carvalho Chehab #define SLOT_BUF_PTR			0x8
6646fb9995SMauro Carvalho Chehab #define SLOT_CUR_DESCPT_PTR		0xC
6746fb9995SMauro Carvalho Chehab #define SLOT_NXT_DESCPT_PTR		0x10
6846fb9995SMauro Carvalho Chehab #define MXC_SLOT_OFFSET(slot, offset)	((SLOT_BASE * ((slot) + 1)) + (offset))
6946fb9995SMauro Carvalho Chehab 
7046fb9995SMauro Carvalho Chehab /* GLB_CTRL fields */
7146fb9995SMauro Carvalho Chehab #define GLB_CTRL_JPG_EN					0x1
7246fb9995SMauro Carvalho Chehab #define GLB_CTRL_SFT_RST				(0x1 << 1)
7346fb9995SMauro Carvalho Chehab #define GLB_CTRL_DEC_GO					(0x1 << 2)
7446fb9995SMauro Carvalho Chehab #define GLB_CTRL_L_ENDIAN(le)				((le) << 3)
7546fb9995SMauro Carvalho Chehab #define GLB_CTRL_SLOT_EN(slot)				(0x1 << ((slot) + 4))
7646fb9995SMauro Carvalho Chehab 
7746fb9995SMauro Carvalho Chehab /* COM_STAUS fields */
7846fb9995SMauro Carvalho Chehab #define COM_STATUS_DEC_ONGOING(r)		(((r) & (1 << 31)) >> 31)
7946fb9995SMauro Carvalho Chehab #define COM_STATUS_CUR_SLOT(r)			(((r) & (0x3 << 29)) >> 29)
8046fb9995SMauro Carvalho Chehab 
8146fb9995SMauro Carvalho Chehab /* STM_CTRL fields */
8246fb9995SMauro Carvalho Chehab #define STM_CTRL_PIXEL_PRECISION		(0x1 << 2)
8346fb9995SMauro Carvalho Chehab #define STM_CTRL_IMAGE_FORMAT(img_fmt)		((img_fmt) << 3)
8446fb9995SMauro Carvalho Chehab #define STM_CTRL_IMAGE_FORMAT_MASK		(0xF << 3)
8546fb9995SMauro Carvalho Chehab #define STM_CTRL_BITBUF_PTR_CLR(clr)		((clr) << 7)
8646fb9995SMauro Carvalho Chehab #define STM_CTRL_AUTO_START(go)			((go) << 8)
8746fb9995SMauro Carvalho Chehab #define STM_CTRL_CONFIG_MOD(mod)		((mod) << 9)
8846fb9995SMauro Carvalho Chehab 
8946fb9995SMauro Carvalho Chehab /* SLOT_STATUS fields for slots 0..3 */
9046fb9995SMauro Carvalho Chehab #define SLOT_STATUS_FRMDONE			(0x1 << 3)
9146fb9995SMauro Carvalho Chehab #define SLOT_STATUS_ENC_CONFIG_ERR		(0x1 << 8)
9246fb9995SMauro Carvalho Chehab 
9346fb9995SMauro Carvalho Chehab /* SLOT_IRQ_EN fields TBD */
9446fb9995SMauro Carvalho Chehab 
9546fb9995SMauro Carvalho Chehab #define MXC_NXT_DESCPT_EN			0x1
9646fb9995SMauro Carvalho Chehab #define MXC_DEC_EXIT_IDLE_MODE			0x4
9746fb9995SMauro Carvalho Chehab 
9846fb9995SMauro Carvalho Chehab /* JPEG-Decoder Wrapper - STM_CTRL Register Fields */
9946fb9995SMauro Carvalho Chehab #define MXC_PIXEL_PRECISION(precision) ((precision) / 8 << 2)
10046fb9995SMauro Carvalho Chehab enum mxc_jpeg_image_format {
10146fb9995SMauro Carvalho Chehab 	MXC_JPEG_INVALID = -1,
10246fb9995SMauro Carvalho Chehab 	MXC_JPEG_YUV420 = 0x0, /* 2 Plannar, Y=1st plane UV=2nd plane */
10346fb9995SMauro Carvalho Chehab 	MXC_JPEG_YUV422 = 0x1, /* 1 Plannar, YUYV sequence */
104d387c6f6SMing Qian 	MXC_JPEG_BGR	= 0x2, /* BGR packed format */
10546fb9995SMauro Carvalho Chehab 	MXC_JPEG_YUV444	= 0x3, /* 1 Plannar, YUVYUV sequence */
10646fb9995SMauro Carvalho Chehab 	MXC_JPEG_GRAY = 0x4, /* Y8 or Y12 or Single Component */
10746fb9995SMauro Carvalho Chehab 	MXC_JPEG_RESERVED = 0x5,
108d387c6f6SMing Qian 	MXC_JPEG_ABGR	= 0x6,
10946fb9995SMauro Carvalho Chehab };
11046fb9995SMauro Carvalho Chehab 
11146fb9995SMauro Carvalho Chehab #include "mxc-jpeg.h"
11246fb9995SMauro Carvalho Chehab void print_descriptor_info(struct device *dev, struct mxc_jpeg_desc *desc);
11346fb9995SMauro Carvalho Chehab void print_cast_status(struct device *dev, void __iomem *reg,
11446fb9995SMauro Carvalho Chehab 		       unsigned int mode);
11546fb9995SMauro Carvalho Chehab void print_wrapper_info(struct device *dev, void __iomem *reg);
11646fb9995SMauro Carvalho Chehab void mxc_jpeg_sw_reset(void __iomem *reg);
11746fb9995SMauro Carvalho Chehab int mxc_jpeg_enable(void __iomem *reg);
118*3b764ff0SMing Qian void mxc_jpeg_enc_mode_conf(struct device *dev, void __iomem *reg, u8 extseq);
119*3b764ff0SMing Qian void mxc_jpeg_enc_mode_go(struct device *dev, void __iomem *reg, u8 extseq);
120a23196c7SMing Qian void mxc_jpeg_enc_set_quality(struct device *dev, void __iomem *reg, u8 quality);
12146fb9995SMauro Carvalho Chehab void mxc_jpeg_dec_mode_go(struct device *dev, void __iomem *reg);
12246fb9995SMauro Carvalho Chehab void mxc_jpeg_enable_slot(void __iomem *reg, int slot);
12346fb9995SMauro Carvalho Chehab void mxc_jpeg_set_l_endian(void __iomem *reg, int le);
12446fb9995SMauro Carvalho Chehab void mxc_jpeg_enable_irq(void __iomem *reg, int slot);
12522a2bc88SMing Qian void mxc_jpeg_disable_irq(void __iomem *reg, int slot);
12646fb9995SMauro Carvalho Chehab void mxc_jpeg_set_bufsize(struct mxc_jpeg_desc *desc,  u32 bufsize);
12746fb9995SMauro Carvalho Chehab void mxc_jpeg_set_res(struct mxc_jpeg_desc *desc, u16 w, u16 h);
12846fb9995SMauro Carvalho Chehab void mxc_jpeg_set_line_pitch(struct mxc_jpeg_desc *desc, u32 line_pitch);
12946fb9995SMauro Carvalho Chehab void mxc_jpeg_set_desc(u32 desc, void __iomem *reg, int slot);
130a14e14baSMing Qian void mxc_jpeg_clr_desc(void __iomem *reg, int slot);
13146fb9995SMauro Carvalho Chehab #endif
132