1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Allwinner DE2 rotation driver 4 * 5 * Copyright (C) 2020 Jernej Skrabec <jernej.skrabec@siol.net> 6 */ 7 8 #ifndef _SUN8I_ROTATE_H_ 9 #define _SUN8I_ROTATE_H_ 10 11 #include <media/v4l2-ctrls.h> 12 #include <media/v4l2-device.h> 13 #include <media/v4l2-mem2mem.h> 14 #include <media/videobuf2-v4l2.h> 15 #include <media/videobuf2-dma-contig.h> 16 17 #include <linux/platform_device.h> 18 19 #define ROTATE_NAME "sun8i-rotate" 20 21 #define ROTATE_GLB_CTL 0x00 22 #define ROTATE_GLB_CTL_START BIT(31) 23 #define ROTATE_GLB_CTL_RESET BIT(30) 24 #define ROTATE_GLB_CTL_BURST_LEN(x) ((x) << 16) 25 #define ROTATE_GLB_CTL_HFLIP BIT(7) 26 #define ROTATE_GLB_CTL_VFLIP BIT(6) 27 #define ROTATE_GLB_CTL_ROTATION(x) ((x) << 4) 28 #define ROTATE_GLB_CTL_MODE(x) ((x) << 0) 29 30 #define ROTATE_INT 0x04 31 #define ROTATE_INT_FINISH_IRQ_EN BIT(16) 32 #define ROTATE_INT_FINISH_IRQ BIT(0) 33 34 #define ROTATE_IN_FMT 0x20 35 #define ROTATE_IN_FMT_FORMAT(x) ((x) << 0) 36 37 #define ROTATE_IN_SIZE 0x24 38 #define ROTATE_IN_PITCH0 0x30 39 #define ROTATE_IN_PITCH1 0x34 40 #define ROTATE_IN_PITCH2 0x38 41 #define ROTATE_IN_ADDRL0 0x40 42 #define ROTATE_IN_ADDRH0 0x44 43 #define ROTATE_IN_ADDRL1 0x48 44 #define ROTATE_IN_ADDRH1 0x4c 45 #define ROTATE_IN_ADDRL2 0x50 46 #define ROTATE_IN_ADDRH2 0x54 47 #define ROTATE_OUT_SIZE 0x84 48 #define ROTATE_OUT_PITCH0 0x90 49 #define ROTATE_OUT_PITCH1 0x94 50 #define ROTATE_OUT_PITCH2 0x98 51 #define ROTATE_OUT_ADDRL0 0xA0 52 #define ROTATE_OUT_ADDRH0 0xA4 53 #define ROTATE_OUT_ADDRL1 0xA8 54 #define ROTATE_OUT_ADDRH1 0xAC 55 #define ROTATE_OUT_ADDRL2 0xB0 56 #define ROTATE_OUT_ADDRH2 0xB4 57 58 #define ROTATE_BURST_8 0x07 59 #define ROTATE_BURST_16 0x0f 60 #define ROTATE_BURST_32 0x1f 61 #define ROTATE_BURST_64 0x3f 62 63 #define ROTATE_MODE_COPY_ROTATE 0x01 64 65 #define ROTATE_FORMAT_ARGB32 0x00 66 #define ROTATE_FORMAT_ABGR32 0x01 67 #define ROTATE_FORMAT_RGBA32 0x02 68 #define ROTATE_FORMAT_BGRA32 0x03 69 #define ROTATE_FORMAT_XRGB32 0x04 70 #define ROTATE_FORMAT_XBGR32 0x05 71 #define ROTATE_FORMAT_RGBX32 0x06 72 #define ROTATE_FORMAT_BGRX32 0x07 73 #define ROTATE_FORMAT_RGB24 0x08 74 #define ROTATE_FORMAT_BGR24 0x09 75 #define ROTATE_FORMAT_RGB565 0x0a 76 #define ROTATE_FORMAT_BGR565 0x0b 77 #define ROTATE_FORMAT_ARGB4444 0x0c 78 #define ROTATE_FORMAT_ABGR4444 0x0d 79 #define ROTATE_FORMAT_RGBA4444 0x0e 80 #define ROTATE_FORMAT_BGRA4444 0x0f 81 #define ROTATE_FORMAT_ARGB1555 0x10 82 #define ROTATE_FORMAT_ABGR1555 0x11 83 #define ROTATE_FORMAT_RGBA5551 0x12 84 #define ROTATE_FORMAT_BGRA5551 0x13 85 86 #define ROTATE_FORMAT_YUYV 0x20 87 #define ROTATE_FORMAT_UYVY 0x21 88 #define ROTATE_FORMAT_YVYU 0x22 89 #define ROTATE_FORMAT_VYUV 0x23 90 #define ROTATE_FORMAT_NV61 0x24 91 #define ROTATE_FORMAT_NV16 0x25 92 #define ROTATE_FORMAT_YUV422P 0x26 93 #define ROTATE_FORMAT_NV21 0x28 94 #define ROTATE_FORMAT_NV12 0x29 95 #define ROTATE_FORMAT_YUV420P 0x2A 96 97 #define ROTATE_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1)) 98 99 #define ROTATE_MIN_WIDTH 8U 100 #define ROTATE_MIN_HEIGHT 8U 101 #define ROTATE_MAX_WIDTH 4096U 102 #define ROTATE_MAX_HEIGHT 4096U 103 104 struct rotate_ctx { 105 struct v4l2_fh fh; 106 struct rotate_dev *dev; 107 108 struct v4l2_pix_format src_fmt; 109 struct v4l2_pix_format dst_fmt; 110 111 struct v4l2_ctrl_handler ctrl_handler; 112 113 u32 hflip; 114 u32 vflip; 115 u32 rotate; 116 }; 117 118 struct rotate_dev { 119 struct v4l2_device v4l2_dev; 120 struct video_device vfd; 121 struct device *dev; 122 struct v4l2_m2m_dev *m2m_dev; 123 124 /* Device file mutex */ 125 struct mutex dev_mutex; 126 127 void __iomem *base; 128 129 struct clk *bus_clk; 130 struct clk *mod_clk; 131 132 struct reset_control *rstc; 133 }; 134 135 #endif 136