18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Allwinner DE2 rotation driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2020 Jernej Skrabec <jernej.skrabec@siol.net>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _SUN8I_ROTATE_H_
98c2ecf20Sopenharmony_ci#define _SUN8I_ROTATE_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h>
128c2ecf20Sopenharmony_ci#include <media/v4l2-device.h>
138c2ecf20Sopenharmony_ci#include <media/v4l2-mem2mem.h>
148c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h>
158c2ecf20Sopenharmony_ci#include <media/videobuf2-dma-contig.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define ROTATE_NAME		"sun8i-rotate"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL			0x00
228c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_START			BIT(31)
238c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_RESET			BIT(30)
248c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_BURST_LEN(x)		((x) << 16)
258c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_HFLIP			BIT(7)
268c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_VFLIP			BIT(6)
278c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_ROTATION(x)		((x) << 4)
288c2ecf20Sopenharmony_ci#define ROTATE_GLB_CTL_MODE(x)			((x) << 0)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define ROTATE_INT			0x04
318c2ecf20Sopenharmony_ci#define ROTATE_INT_FINISH_IRQ_EN		BIT(16)
328c2ecf20Sopenharmony_ci#define ROTATE_INT_FINISH_IRQ			BIT(0)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define ROTATE_IN_FMT			0x20
358c2ecf20Sopenharmony_ci#define ROTATE_IN_FMT_FORMAT(x)			((x) << 0)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define ROTATE_IN_SIZE			0x24
388c2ecf20Sopenharmony_ci#define ROTATE_IN_PITCH0		0x30
398c2ecf20Sopenharmony_ci#define ROTATE_IN_PITCH1		0x34
408c2ecf20Sopenharmony_ci#define ROTATE_IN_PITCH2		0x38
418c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRL0		0x40
428c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRH0		0x44
438c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRL1		0x48
448c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRH1		0x4c
458c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRL2		0x50
468c2ecf20Sopenharmony_ci#define ROTATE_IN_ADDRH2		0x54
478c2ecf20Sopenharmony_ci#define ROTATE_OUT_SIZE			0x84
488c2ecf20Sopenharmony_ci#define ROTATE_OUT_PITCH0		0x90
498c2ecf20Sopenharmony_ci#define ROTATE_OUT_PITCH1		0x94
508c2ecf20Sopenharmony_ci#define ROTATE_OUT_PITCH2		0x98
518c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRL0		0xA0
528c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRH0		0xA4
538c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRL1		0xA8
548c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRH1		0xAC
558c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRL2		0xB0
568c2ecf20Sopenharmony_ci#define ROTATE_OUT_ADDRH2		0xB4
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define ROTATE_BURST_8			0x07
598c2ecf20Sopenharmony_ci#define ROTATE_BURST_16			0x0f
608c2ecf20Sopenharmony_ci#define ROTATE_BURST_32			0x1f
618c2ecf20Sopenharmony_ci#define ROTATE_BURST_64			0x3f
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define ROTATE_MODE_COPY_ROTATE		0x01
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ARGB32		0x00
668c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ABGR32		0x01
678c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGBA32		0x02
688c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGRA32		0x03
698c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_XRGB32		0x04
708c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_XBGR32		0x05
718c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGBX32		0x06
728c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGRX32		0x07
738c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGB24		0x08
748c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGR24		0x09
758c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGB565		0x0a
768c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGR565		0x0b
778c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ARGB4444		0x0c
788c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ABGR4444		0x0d
798c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGBA4444		0x0e
808c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGRA4444		0x0f
818c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ARGB1555		0x10
828c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_ABGR1555		0x11
838c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_RGBA5551		0x12
848c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_BGRA5551		0x13
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_YUYV		0x20
878c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_UYVY		0x21
888c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_YVYU		0x22
898c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_VYUV		0x23
908c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_NV61		0x24
918c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_NV16		0x25
928c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_YUV422P		0x26
938c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_NV21		0x28
948c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_NV12		0x29
958c2ecf20Sopenharmony_ci#define ROTATE_FORMAT_YUV420P		0x2A
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define ROTATE_SIZE(w, h)	(((h) - 1) << 16 | ((w) - 1))
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define ROTATE_MIN_WIDTH	8U
1008c2ecf20Sopenharmony_ci#define ROTATE_MIN_HEIGHT	8U
1018c2ecf20Sopenharmony_ci#define ROTATE_MAX_WIDTH	4096U
1028c2ecf20Sopenharmony_ci#define ROTATE_MAX_HEIGHT	4096U
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct rotate_ctx {
1058c2ecf20Sopenharmony_ci	struct v4l2_fh		fh;
1068c2ecf20Sopenharmony_ci	struct rotate_dev	*dev;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	struct v4l2_pix_format	src_fmt;
1098c2ecf20Sopenharmony_ci	struct v4l2_pix_format	dst_fmt;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler ctrl_handler;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	u32 hflip;
1148c2ecf20Sopenharmony_ci	u32 vflip;
1158c2ecf20Sopenharmony_ci	u32 rotate;
1168c2ecf20Sopenharmony_ci};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistruct rotate_dev {
1198c2ecf20Sopenharmony_ci	struct v4l2_device	v4l2_dev;
1208c2ecf20Sopenharmony_ci	struct video_device	vfd;
1218c2ecf20Sopenharmony_ci	struct device		*dev;
1228c2ecf20Sopenharmony_ci	struct v4l2_m2m_dev	*m2m_dev;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	/* Device file mutex */
1258c2ecf20Sopenharmony_ci	struct mutex		dev_mutex;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	void __iomem		*base;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	struct clk		*bus_clk;
1308c2ecf20Sopenharmony_ci	struct clk		*mod_clk;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	struct reset_control	*rstc;
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#endif
136