1*46fb9995SMauro Carvalho Chehab /* SPDX-License-Identifier: GPL-2.0 */ 2*46fb9995SMauro Carvalho Chehab /* 3*46fb9995SMauro Carvalho Chehab * i.MX8QXP/i.MX8QM JPEG encoder/decoder v4l2 driver 4*46fb9995SMauro Carvalho Chehab * 5*46fb9995SMauro Carvalho Chehab * Copyright 2018-2019 NXP 6*46fb9995SMauro Carvalho Chehab */ 7*46fb9995SMauro Carvalho Chehab 8*46fb9995SMauro Carvalho Chehab #ifndef _MXC_JPEG_HW_H 9*46fb9995SMauro Carvalho Chehab #define _MXC_JPEG_HW_H 10*46fb9995SMauro Carvalho Chehab 11*46fb9995SMauro Carvalho Chehab /* JPEG Decoder/Encoder Wrapper Register Map */ 12*46fb9995SMauro Carvalho Chehab #define GLB_CTRL 0x0 13*46fb9995SMauro Carvalho Chehab #define COM_STATUS 0x4 14*46fb9995SMauro Carvalho Chehab #define BUF_BASE0 0x14 15*46fb9995SMauro Carvalho Chehab #define BUF_BASE1 0x18 16*46fb9995SMauro Carvalho Chehab #define LINE_PITCH 0x1C 17*46fb9995SMauro Carvalho Chehab #define STM_BUFBASE 0x20 18*46fb9995SMauro Carvalho Chehab #define STM_BUFSIZE 0x24 19*46fb9995SMauro Carvalho Chehab #define IMGSIZE 0x28 20*46fb9995SMauro Carvalho Chehab #define STM_CTRL 0x2C 21*46fb9995SMauro Carvalho Chehab 22*46fb9995SMauro Carvalho Chehab /* CAST JPEG-Decoder/Encoder Status Register Map (read-only)*/ 23*46fb9995SMauro Carvalho Chehab #define CAST_STATUS0 0x100 24*46fb9995SMauro Carvalho Chehab #define CAST_STATUS1 0x104 25*46fb9995SMauro Carvalho Chehab #define CAST_STATUS2 0x108 26*46fb9995SMauro Carvalho Chehab #define CAST_STATUS3 0x10c 27*46fb9995SMauro Carvalho Chehab #define CAST_STATUS4 0x110 28*46fb9995SMauro Carvalho Chehab #define CAST_STATUS5 0x114 29*46fb9995SMauro Carvalho Chehab #define CAST_STATUS6 0x118 30*46fb9995SMauro Carvalho Chehab #define CAST_STATUS7 0x11c 31*46fb9995SMauro Carvalho Chehab #define CAST_STATUS8 0x120 32*46fb9995SMauro Carvalho Chehab #define CAST_STATUS9 0x124 33*46fb9995SMauro Carvalho Chehab #define CAST_STATUS10 0x128 34*46fb9995SMauro Carvalho Chehab #define CAST_STATUS11 0x12c 35*46fb9995SMauro Carvalho Chehab #define CAST_STATUS12 0x130 36*46fb9995SMauro Carvalho Chehab #define CAST_STATUS13 0x134 37*46fb9995SMauro Carvalho Chehab /* the following are for encoder only */ 38*46fb9995SMauro Carvalho Chehab #define CAST_STATUS14 0x138 39*46fb9995SMauro Carvalho Chehab #define CAST_STATUS15 0x13c 40*46fb9995SMauro Carvalho Chehab #define CAST_STATUS16 0x140 41*46fb9995SMauro Carvalho Chehab #define CAST_STATUS17 0x144 42*46fb9995SMauro Carvalho Chehab #define CAST_STATUS18 0x148 43*46fb9995SMauro Carvalho Chehab #define CAST_STATUS19 0x14c 44*46fb9995SMauro Carvalho Chehab 45*46fb9995SMauro Carvalho Chehab /* CAST JPEG-Decoder Control Register Map (write-only) */ 46*46fb9995SMauro Carvalho Chehab #define CAST_CTRL CAST_STATUS13 47*46fb9995SMauro Carvalho Chehab 48*46fb9995SMauro Carvalho Chehab /* CAST JPEG-Encoder Control Register Map (write-only) */ 49*46fb9995SMauro Carvalho Chehab #define CAST_MODE CAST_STATUS0 50*46fb9995SMauro Carvalho Chehab #define CAST_CFG_MODE CAST_STATUS1 51*46fb9995SMauro Carvalho Chehab #define CAST_QUALITY CAST_STATUS2 52*46fb9995SMauro Carvalho Chehab #define CAST_RSVD CAST_STATUS3 53*46fb9995SMauro Carvalho Chehab #define CAST_REC_REGS_SEL CAST_STATUS4 54*46fb9995SMauro Carvalho Chehab #define CAST_LUMTH CAST_STATUS5 55*46fb9995SMauro Carvalho Chehab #define CAST_CHRTH CAST_STATUS6 56*46fb9995SMauro Carvalho Chehab #define CAST_NOMFRSIZE_LO CAST_STATUS7 57*46fb9995SMauro Carvalho Chehab #define CAST_NOMFRSIZE_HI CAST_STATUS8 58*46fb9995SMauro Carvalho Chehab #define CAST_OFBSIZE_LO CAST_STATUS9 59*46fb9995SMauro Carvalho Chehab #define CAST_OFBSIZE_HI CAST_STATUS10 60*46fb9995SMauro Carvalho Chehab 61*46fb9995SMauro Carvalho Chehab #define MXC_MAX_SLOTS 1 /* TODO use all 4 slots*/ 62*46fb9995SMauro Carvalho Chehab /* JPEG-Decoder Wrapper Slot Registers 0..3 */ 63*46fb9995SMauro Carvalho Chehab #define SLOT_BASE 0x10000 64*46fb9995SMauro Carvalho Chehab #define SLOT_STATUS 0x0 65*46fb9995SMauro Carvalho Chehab #define SLOT_IRQ_EN 0x4 66*46fb9995SMauro Carvalho Chehab #define SLOT_BUF_PTR 0x8 67*46fb9995SMauro Carvalho Chehab #define SLOT_CUR_DESCPT_PTR 0xC 68*46fb9995SMauro Carvalho Chehab #define SLOT_NXT_DESCPT_PTR 0x10 69*46fb9995SMauro Carvalho Chehab #define MXC_SLOT_OFFSET(slot, offset) ((SLOT_BASE * ((slot) + 1)) + (offset)) 70*46fb9995SMauro Carvalho Chehab 71*46fb9995SMauro Carvalho Chehab /* GLB_CTRL fields */ 72*46fb9995SMauro Carvalho Chehab #define GLB_CTRL_JPG_EN 0x1 73*46fb9995SMauro Carvalho Chehab #define GLB_CTRL_SFT_RST (0x1 << 1) 74*46fb9995SMauro Carvalho Chehab #define GLB_CTRL_DEC_GO (0x1 << 2) 75*46fb9995SMauro Carvalho Chehab #define GLB_CTRL_L_ENDIAN(le) ((le) << 3) 76*46fb9995SMauro Carvalho Chehab #define GLB_CTRL_SLOT_EN(slot) (0x1 << ((slot) + 4)) 77*46fb9995SMauro Carvalho Chehab 78*46fb9995SMauro Carvalho Chehab /* COM_STAUS fields */ 79*46fb9995SMauro Carvalho Chehab #define COM_STATUS_DEC_ONGOING(r) (((r) & (1 << 31)) >> 31) 80*46fb9995SMauro Carvalho Chehab #define COM_STATUS_CUR_SLOT(r) (((r) & (0x3 << 29)) >> 29) 81*46fb9995SMauro Carvalho Chehab 82*46fb9995SMauro Carvalho Chehab /* STM_CTRL fields */ 83*46fb9995SMauro Carvalho Chehab #define STM_CTRL_PIXEL_PRECISION (0x1 << 2) 84*46fb9995SMauro Carvalho Chehab #define STM_CTRL_IMAGE_FORMAT(img_fmt) ((img_fmt) << 3) 85*46fb9995SMauro Carvalho Chehab #define STM_CTRL_IMAGE_FORMAT_MASK (0xF << 3) 86*46fb9995SMauro Carvalho Chehab #define STM_CTRL_BITBUF_PTR_CLR(clr) ((clr) << 7) 87*46fb9995SMauro Carvalho Chehab #define STM_CTRL_AUTO_START(go) ((go) << 8) 88*46fb9995SMauro Carvalho Chehab #define STM_CTRL_CONFIG_MOD(mod) ((mod) << 9) 89*46fb9995SMauro Carvalho Chehab 90*46fb9995SMauro Carvalho Chehab /* SLOT_STATUS fields for slots 0..3 */ 91*46fb9995SMauro Carvalho Chehab #define SLOT_STATUS_FRMDONE (0x1 << 3) 92*46fb9995SMauro Carvalho Chehab #define SLOT_STATUS_ENC_CONFIG_ERR (0x1 << 8) 93*46fb9995SMauro Carvalho Chehab 94*46fb9995SMauro Carvalho Chehab /* SLOT_IRQ_EN fields TBD */ 95*46fb9995SMauro Carvalho Chehab 96*46fb9995SMauro Carvalho Chehab #define MXC_NXT_DESCPT_EN 0x1 97*46fb9995SMauro Carvalho Chehab #define MXC_DEC_EXIT_IDLE_MODE 0x4 98*46fb9995SMauro Carvalho Chehab 99*46fb9995SMauro Carvalho Chehab /* JPEG-Decoder Wrapper - STM_CTRL Register Fields */ 100*46fb9995SMauro Carvalho Chehab #define MXC_PIXEL_PRECISION(precision) ((precision) / 8 << 2) 101*46fb9995SMauro Carvalho Chehab enum mxc_jpeg_image_format { 102*46fb9995SMauro Carvalho Chehab MXC_JPEG_INVALID = -1, 103*46fb9995SMauro Carvalho Chehab MXC_JPEG_YUV420 = 0x0, /* 2 Plannar, Y=1st plane UV=2nd plane */ 104*46fb9995SMauro Carvalho Chehab MXC_JPEG_YUV422 = 0x1, /* 1 Plannar, YUYV sequence */ 105*46fb9995SMauro Carvalho Chehab MXC_JPEG_RGB = 0x2, /* RGBRGB packed format */ 106*46fb9995SMauro Carvalho Chehab MXC_JPEG_YUV444 = 0x3, /* 1 Plannar, YUVYUV sequence */ 107*46fb9995SMauro Carvalho Chehab MXC_JPEG_GRAY = 0x4, /* Y8 or Y12 or Single Component */ 108*46fb9995SMauro Carvalho Chehab MXC_JPEG_RESERVED = 0x5, 109*46fb9995SMauro Carvalho Chehab MXC_JPEG_ARGB = 0x6, 110*46fb9995SMauro Carvalho Chehab }; 111*46fb9995SMauro Carvalho Chehab 112*46fb9995SMauro Carvalho Chehab #include "mxc-jpeg.h" 113*46fb9995SMauro Carvalho Chehab void print_descriptor_info(struct device *dev, struct mxc_jpeg_desc *desc); 114*46fb9995SMauro Carvalho Chehab void print_cast_status(struct device *dev, void __iomem *reg, 115*46fb9995SMauro Carvalho Chehab unsigned int mode); 116*46fb9995SMauro Carvalho Chehab void print_wrapper_info(struct device *dev, void __iomem *reg); 117*46fb9995SMauro Carvalho Chehab void mxc_jpeg_sw_reset(void __iomem *reg); 118*46fb9995SMauro Carvalho Chehab int mxc_jpeg_enable(void __iomem *reg); 119*46fb9995SMauro Carvalho Chehab void wait_frmdone(struct device *dev, void __iomem *reg); 120*46fb9995SMauro Carvalho Chehab void mxc_jpeg_enc_mode_conf(struct device *dev, void __iomem *reg); 121*46fb9995SMauro Carvalho Chehab void mxc_jpeg_enc_mode_go(struct device *dev, void __iomem *reg); 122*46fb9995SMauro Carvalho Chehab void mxc_jpeg_dec_mode_go(struct device *dev, void __iomem *reg); 123*46fb9995SMauro Carvalho Chehab int mxc_jpeg_get_slot(void __iomem *reg); 124*46fb9995SMauro Carvalho Chehab u32 mxc_jpeg_get_offset(void __iomem *reg, int slot); 125*46fb9995SMauro Carvalho Chehab void mxc_jpeg_enable_slot(void __iomem *reg, int slot); 126*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_l_endian(void __iomem *reg, int le); 127*46fb9995SMauro Carvalho Chehab void mxc_jpeg_enable_irq(void __iomem *reg, int slot); 128*46fb9995SMauro Carvalho Chehab int mxc_jpeg_set_input(void __iomem *reg, u32 in_buf, u32 bufsize); 129*46fb9995SMauro Carvalho Chehab int mxc_jpeg_set_output(void __iomem *reg, u16 out_pitch, u32 out_buf, 130*46fb9995SMauro Carvalho Chehab u16 w, u16 h); 131*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_config_mode(void __iomem *reg, int config_mode); 132*46fb9995SMauro Carvalho Chehab int mxc_jpeg_set_params(struct mxc_jpeg_desc *desc, u32 bufsize, u16 133*46fb9995SMauro Carvalho Chehab out_pitch, u32 format); 134*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_bufsize(struct mxc_jpeg_desc *desc, u32 bufsize); 135*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_res(struct mxc_jpeg_desc *desc, u16 w, u16 h); 136*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_line_pitch(struct mxc_jpeg_desc *desc, u32 line_pitch); 137*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_desc(u32 desc, void __iomem *reg, int slot); 138*46fb9995SMauro Carvalho Chehab void mxc_jpeg_set_regs_from_desc(struct mxc_jpeg_desc *desc, 139*46fb9995SMauro Carvalho Chehab void __iomem *reg); 140*46fb9995SMauro Carvalho Chehab #endif 141