1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 2 /* 3 * RP1 PiSP common definitions. 4 * 5 * Copyright (C) 2021 - Raspberry Pi Ltd. 6 * 7 */ 8 #ifndef _UAPI_PISP_COMMON_H_ 9 #define _UAPI_PISP_COMMON_H_ 10 11 #include <linux/types.h> 12 13 struct pisp_image_format_config { 14 /* size in pixels */ 15 __u16 width; 16 __u16 height; 17 /* must match struct pisp_image_format below */ 18 __u32 format; 19 __s32 stride; 20 /* some planar image formats will need a second stride */ 21 __s32 stride2; 22 } __attribute__((packed)); 23 24 enum pisp_bayer_order { 25 /* 26 * Note how bayer_order&1 tells you if G is on the even pixels of the 27 * checkerboard or not, and bayer_order&2 tells you if R is on the even 28 * rows or is swapped with B. Note that if the top (of the 8) bits is 29 * set, this denotes a monochrome or greyscale image, and the lower bits 30 * should all be ignored. 31 */ 32 PISP_BAYER_ORDER_RGGB = 0, 33 PISP_BAYER_ORDER_GBRG = 1, 34 PISP_BAYER_ORDER_BGGR = 2, 35 PISP_BAYER_ORDER_GRBG = 3, 36 PISP_BAYER_ORDER_GREYSCALE = 128 37 }; 38 39 enum pisp_image_format { 40 /* 41 * Precise values are mostly tbd. Generally these will be portmanteau 42 * values comprising bit fields and flags. This format must be shared 43 * throughout the PiSP. 44 */ 45 PISP_IMAGE_FORMAT_BPS_8 = 0x00000000, 46 PISP_IMAGE_FORMAT_BPS_10 = 0x00000001, 47 PISP_IMAGE_FORMAT_BPS_12 = 0x00000002, 48 PISP_IMAGE_FORMAT_BPS_16 = 0x00000003, 49 PISP_IMAGE_FORMAT_BPS_MASK = 0x00000003, 50 51 PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED = 0x00000000, 52 PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR = 0x00000010, 53 PISP_IMAGE_FORMAT_PLANARITY_PLANAR = 0x00000020, 54 PISP_IMAGE_FORMAT_PLANARITY_MASK = 0x00000030, 55 56 PISP_IMAGE_FORMAT_SAMPLING_444 = 0x00000000, 57 PISP_IMAGE_FORMAT_SAMPLING_422 = 0x00000100, 58 PISP_IMAGE_FORMAT_SAMPLING_420 = 0x00000200, 59 PISP_IMAGE_FORMAT_SAMPLING_MASK = 0x00000300, 60 61 PISP_IMAGE_FORMAT_ORDER_NORMAL = 0x00000000, 62 PISP_IMAGE_FORMAT_ORDER_SWAPPED = 0x00001000, 63 64 PISP_IMAGE_FORMAT_SHIFT_0 = 0x00000000, 65 PISP_IMAGE_FORMAT_SHIFT_1 = 0x00010000, 66 PISP_IMAGE_FORMAT_SHIFT_2 = 0x00020000, 67 PISP_IMAGE_FORMAT_SHIFT_3 = 0x00030000, 68 PISP_IMAGE_FORMAT_SHIFT_4 = 0x00040000, 69 PISP_IMAGE_FORMAT_SHIFT_5 = 0x00050000, 70 PISP_IMAGE_FORMAT_SHIFT_6 = 0x00060000, 71 PISP_IMAGE_FORMAT_SHIFT_7 = 0x00070000, 72 PISP_IMAGE_FORMAT_SHIFT_8 = 0x00080000, 73 PISP_IMAGE_FORMAT_SHIFT_MASK = 0x000f0000, 74 75 PISP_IMAGE_FORMAT_BPP_32 = 0x00100000, 76 77 PISP_IMAGE_FORMAT_UNCOMPRESSED = 0x00000000, 78 PISP_IMAGE_FORMAT_COMPRESSION_MODE_1 = 0x01000000, 79 PISP_IMAGE_FORMAT_COMPRESSION_MODE_2 = 0x02000000, 80 PISP_IMAGE_FORMAT_COMPRESSION_MODE_3 = 0x03000000, 81 PISP_IMAGE_FORMAT_COMPRESSION_MASK = 0x03000000, 82 83 PISP_IMAGE_FORMAT_HOG_SIGNED = 0x04000000, 84 PISP_IMAGE_FORMAT_HOG_UNSIGNED = 0x08000000, 85 PISP_IMAGE_FORMAT_INTEGRAL_IMAGE = 0x10000000, 86 PISP_IMAGE_FORMAT_WALLPAPER_ROLL = 0x20000000, 87 PISP_IMAGE_FORMAT_THREE_CHANNEL = 0x40000000, 88 89 /* Lastly a few specific instantiations of the above. */ 90 PISP_IMAGE_FORMAT_SINGLE_16 = PISP_IMAGE_FORMAT_BPS_16, 91 PISP_IMAGE_FORMAT_THREE_16 = PISP_IMAGE_FORMAT_BPS_16 | 92 PISP_IMAGE_FORMAT_THREE_CHANNEL 93 }; 94 95 #define PISP_IMAGE_FORMAT_BPS_8(fmt) \ 96 (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_8) 97 #define PISP_IMAGE_FORMAT_BPS_10(fmt) \ 98 (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_10) 99 #define PISP_IMAGE_FORMAT_BPS_12(fmt) \ 100 (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_12) 101 #define PISP_IMAGE_FORMAT_BPS_16(fmt) \ 102 (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_16) 103 #define PISP_IMAGE_FORMAT_BPS(fmt) \ 104 (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) ? \ 105 8 + (2 << (((fmt) & PISP_IMAGE_FORMAT_BPS_MASK) - 1)) : 8) 106 #define PISP_IMAGE_FORMAT_SHIFT(fmt) \ 107 (((fmt) & PISP_IMAGE_FORMAT_SHIFT_MASK) / PISP_IMAGE_FORMAT_SHIFT_1) 108 #define PISP_IMAGE_FORMAT_THREE_CHANNEL(fmt) \ 109 ((fmt) & PISP_IMAGE_FORMAT_THREE_CHANNEL) 110 #define PISP_IMAGE_FORMAT_SINGLE_CHANNEL(fmt) \ 111 (!((fmt) & PISP_IMAGE_FORMAT_THREE_CHANNEL)) 112 #define PISP_IMAGE_FORMAT_COMPRESSED(fmt) \ 113 (((fmt) & PISP_IMAGE_FORMAT_COMPRESSION_MASK) != \ 114 PISP_IMAGE_FORMAT_UNCOMPRESSED) 115 #define PISP_IMAGE_FORMAT_SAMPLING_444(fmt) \ 116 (((fmt) & PISP_IMAGE_FORMAT_SAMPLING_MASK) == \ 117 PISP_IMAGE_FORMAT_SAMPLING_444) 118 #define PISP_IMAGE_FORMAT_SAMPLING_422(fmt) \ 119 (((fmt) & PISP_IMAGE_FORMAT_SAMPLING_MASK) == \ 120 PISP_IMAGE_FORMAT_SAMPLING_422) 121 #define PISP_IMAGE_FORMAT_SAMPLING_420(fmt) \ 122 (((fmt) & PISP_IMAGE_FORMAT_SAMPLING_MASK) == \ 123 PISP_IMAGE_FORMAT_SAMPLING_420) 124 #define PISP_IMAGE_FORMAT_ORDER_NORMAL(fmt) \ 125 (!((fmt) & PISP_IMAGE_FORMAT_ORDER_SWAPPED)) 126 #define PISP_IMAGE_FORMAT_ORDER_SWAPPED(fmt) \ 127 ((fmt) & PISP_IMAGE_FORMAT_ORDER_SWAPPED) 128 #define PISP_IMAGE_FORMAT_INTERLEAVED(fmt) \ 129 (((fmt) & PISP_IMAGE_FORMAT_PLANARITY_MASK) == \ 130 PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED) 131 #define PISP_IMAGE_FORMAT_SEMIPLANAR(fmt) \ 132 (((fmt) & PISP_IMAGE_FORMAT_PLANARITY_MASK) == \ 133 PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR) 134 #define PISP_IMAGE_FORMAT_PLANAR(fmt) \ 135 (((fmt) & PISP_IMAGE_FORMAT_PLANARITY_MASK) == \ 136 PISP_IMAGE_FORMAT_PLANARITY_PLANAR) 137 #define PISP_IMAGE_FORMAT_WALLPAPER(fmt) \ 138 ((fmt) & PISP_IMAGE_FORMAT_WALLPAPER_ROLL) 139 #define PISP_IMAGE_FORMAT_BPP_32(fmt) ((fmt) & PISP_IMAGE_FORMAT_BPP_32) 140 #define PISP_IMAGE_FORMAT_HOG(fmt) \ 141 ((fmt) & \ 142 (PISP_IMAGE_FORMAT_HOG_SIGNED | PISP_IMAGE_FORMAT_HOG_UNSIGNED)) 143 144 #define PISP_WALLPAPER_WIDTH 128 /* in bytes */ 145 146 struct pisp_bla_config { 147 __u16 black_level_r; 148 __u16 black_level_gr; 149 __u16 black_level_gb; 150 __u16 black_level_b; 151 __u16 output_black_level; 152 __u8 pad[2]; 153 } __attribute__((packed)); 154 155 struct pisp_wbg_config { 156 __u16 gain_r; 157 __u16 gain_g; 158 __u16 gain_b; 159 __u8 pad[2]; 160 } __attribute__((packed)); 161 162 struct pisp_compress_config { 163 /* value subtracted from incoming data */ 164 __u16 offset; 165 __u8 pad; 166 /* 1 => Companding; 2 => Delta (recommended); 3 => Combined (for HDR) */ 167 __u8 mode; 168 } __attribute__((packed)); 169 170 struct pisp_decompress_config { 171 /* value added to reconstructed data */ 172 __u16 offset; 173 __u8 pad; 174 /* 1 => Companding; 2 => Delta (recommended); 3 => Combined (for HDR) */ 175 __u8 mode; 176 } __attribute__((packed)); 177 178 enum pisp_axi_flags { 179 /* 180 * round down bursts to end at a 32-byte boundary, to align following 181 * bursts 182 */ 183 PISP_AXI_FLAG_ALIGN = 128, 184 /* for FE writer: force WSTRB high, to pad output to 16-byte boundary */ 185 PISP_AXI_FLAG_PAD = 64, 186 /* for FE writer: Use Output FIFO level to trigger "panic" */ 187 PISP_AXI_FLAG_PANIC = 32, 188 }; 189 190 struct pisp_axi_config { 191 /* 192 * burst length minus one, which must be in the range 0:15; OR'd with 193 * flags 194 */ 195 __u8 maxlen_flags; 196 /* { prot[2:0], cache[3:0] } fields, echoed on AXI bus */ 197 __u8 cache_prot; 198 /* QoS field(s) (4x4 bits for FE writer; 4 bits for other masters) */ 199 __u16 qos; 200 } __attribute__((packed)); 201 202 #endif /* _UAPI_PISP_COMMON_H_ */ 203