162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Allwinner DE2 rotation driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2020 Jernej Skrabec <jernej.skrabec@siol.net>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _SUN8I_ROTATE_H_
962306a36Sopenharmony_ci#define _SUN8I_ROTATE_H_
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <media/v4l2-ctrls.h>
1262306a36Sopenharmony_ci#include <media/v4l2-device.h>
1362306a36Sopenharmony_ci#include <media/v4l2-mem2mem.h>
1462306a36Sopenharmony_ci#include <media/videobuf2-v4l2.h>
1562306a36Sopenharmony_ci#include <media/videobuf2-dma-contig.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <linux/platform_device.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define ROTATE_NAME		"sun8i-rotate"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define ROTATE_GLB_CTL			0x00
2262306a36Sopenharmony_ci#define ROTATE_GLB_CTL_START			BIT(31)
2362306a36Sopenharmony_ci#define ROTATE_GLB_CTL_RESET			BIT(30)
2462306a36Sopenharmony_ci#define ROTATE_GLB_CTL_BURST_LEN(x)		((x) << 16)
2562306a36Sopenharmony_ci#define ROTATE_GLB_CTL_HFLIP			BIT(7)
2662306a36Sopenharmony_ci#define ROTATE_GLB_CTL_VFLIP			BIT(6)
2762306a36Sopenharmony_ci#define ROTATE_GLB_CTL_ROTATION(x)		((x) << 4)
2862306a36Sopenharmony_ci#define ROTATE_GLB_CTL_MODE(x)			((x) << 0)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#define ROTATE_INT			0x04
3162306a36Sopenharmony_ci#define ROTATE_INT_FINISH_IRQ_EN		BIT(16)
3262306a36Sopenharmony_ci#define ROTATE_INT_FINISH_IRQ			BIT(0)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define ROTATE_IN_FMT			0x20
3562306a36Sopenharmony_ci#define ROTATE_IN_FMT_FORMAT(x)			((x) << 0)
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define ROTATE_IN_SIZE			0x24
3862306a36Sopenharmony_ci#define ROTATE_IN_PITCH0		0x30
3962306a36Sopenharmony_ci#define ROTATE_IN_PITCH1		0x34
4062306a36Sopenharmony_ci#define ROTATE_IN_PITCH2		0x38
4162306a36Sopenharmony_ci#define ROTATE_IN_ADDRL0		0x40
4262306a36Sopenharmony_ci#define ROTATE_IN_ADDRH0		0x44
4362306a36Sopenharmony_ci#define ROTATE_IN_ADDRL1		0x48
4462306a36Sopenharmony_ci#define ROTATE_IN_ADDRH1		0x4c
4562306a36Sopenharmony_ci#define ROTATE_IN_ADDRL2		0x50
4662306a36Sopenharmony_ci#define ROTATE_IN_ADDRH2		0x54
4762306a36Sopenharmony_ci#define ROTATE_OUT_SIZE			0x84
4862306a36Sopenharmony_ci#define ROTATE_OUT_PITCH0		0x90
4962306a36Sopenharmony_ci#define ROTATE_OUT_PITCH1		0x94
5062306a36Sopenharmony_ci#define ROTATE_OUT_PITCH2		0x98
5162306a36Sopenharmony_ci#define ROTATE_OUT_ADDRL0		0xA0
5262306a36Sopenharmony_ci#define ROTATE_OUT_ADDRH0		0xA4
5362306a36Sopenharmony_ci#define ROTATE_OUT_ADDRL1		0xA8
5462306a36Sopenharmony_ci#define ROTATE_OUT_ADDRH1		0xAC
5562306a36Sopenharmony_ci#define ROTATE_OUT_ADDRL2		0xB0
5662306a36Sopenharmony_ci#define ROTATE_OUT_ADDRH2		0xB4
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define ROTATE_BURST_8			0x07
5962306a36Sopenharmony_ci#define ROTATE_BURST_16			0x0f
6062306a36Sopenharmony_ci#define ROTATE_BURST_32			0x1f
6162306a36Sopenharmony_ci#define ROTATE_BURST_64			0x3f
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define ROTATE_MODE_COPY_ROTATE		0x01
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define ROTATE_FORMAT_ARGB32		0x00
6662306a36Sopenharmony_ci#define ROTATE_FORMAT_ABGR32		0x01
6762306a36Sopenharmony_ci#define ROTATE_FORMAT_RGBA32		0x02
6862306a36Sopenharmony_ci#define ROTATE_FORMAT_BGRA32		0x03
6962306a36Sopenharmony_ci#define ROTATE_FORMAT_XRGB32		0x04
7062306a36Sopenharmony_ci#define ROTATE_FORMAT_XBGR32		0x05
7162306a36Sopenharmony_ci#define ROTATE_FORMAT_RGBX32		0x06
7262306a36Sopenharmony_ci#define ROTATE_FORMAT_BGRX32		0x07
7362306a36Sopenharmony_ci#define ROTATE_FORMAT_RGB24		0x08
7462306a36Sopenharmony_ci#define ROTATE_FORMAT_BGR24		0x09
7562306a36Sopenharmony_ci#define ROTATE_FORMAT_RGB565		0x0a
7662306a36Sopenharmony_ci#define ROTATE_FORMAT_BGR565		0x0b
7762306a36Sopenharmony_ci#define ROTATE_FORMAT_ARGB4444		0x0c
7862306a36Sopenharmony_ci#define ROTATE_FORMAT_ABGR4444		0x0d
7962306a36Sopenharmony_ci#define ROTATE_FORMAT_RGBA4444		0x0e
8062306a36Sopenharmony_ci#define ROTATE_FORMAT_BGRA4444		0x0f
8162306a36Sopenharmony_ci#define ROTATE_FORMAT_ARGB1555		0x10
8262306a36Sopenharmony_ci#define ROTATE_FORMAT_ABGR1555		0x11
8362306a36Sopenharmony_ci#define ROTATE_FORMAT_RGBA5551		0x12
8462306a36Sopenharmony_ci#define ROTATE_FORMAT_BGRA5551		0x13
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define ROTATE_FORMAT_YUYV		0x20
8762306a36Sopenharmony_ci#define ROTATE_FORMAT_UYVY		0x21
8862306a36Sopenharmony_ci#define ROTATE_FORMAT_YVYU		0x22
8962306a36Sopenharmony_ci#define ROTATE_FORMAT_VYUV		0x23
9062306a36Sopenharmony_ci#define ROTATE_FORMAT_NV61		0x24
9162306a36Sopenharmony_ci#define ROTATE_FORMAT_NV16		0x25
9262306a36Sopenharmony_ci#define ROTATE_FORMAT_YUV422P		0x26
9362306a36Sopenharmony_ci#define ROTATE_FORMAT_NV21		0x28
9462306a36Sopenharmony_ci#define ROTATE_FORMAT_NV12		0x29
9562306a36Sopenharmony_ci#define ROTATE_FORMAT_YUV420P		0x2A
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define ROTATE_SIZE(w, h)	(((h) - 1) << 16 | ((w) - 1))
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#define ROTATE_MIN_WIDTH	8U
10062306a36Sopenharmony_ci#define ROTATE_MIN_HEIGHT	8U
10162306a36Sopenharmony_ci#define ROTATE_MAX_WIDTH	4096U
10262306a36Sopenharmony_ci#define ROTATE_MAX_HEIGHT	4096U
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cistruct rotate_ctx {
10562306a36Sopenharmony_ci	struct v4l2_fh		fh;
10662306a36Sopenharmony_ci	struct rotate_dev	*dev;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	struct v4l2_pix_format	src_fmt;
10962306a36Sopenharmony_ci	struct v4l2_pix_format	dst_fmt;
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci	struct v4l2_ctrl_handler ctrl_handler;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	u32 hflip;
11462306a36Sopenharmony_ci	u32 vflip;
11562306a36Sopenharmony_ci	u32 rotate;
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_cistruct rotate_dev {
11962306a36Sopenharmony_ci	struct v4l2_device	v4l2_dev;
12062306a36Sopenharmony_ci	struct video_device	vfd;
12162306a36Sopenharmony_ci	struct device		*dev;
12262306a36Sopenharmony_ci	struct v4l2_m2m_dev	*m2m_dev;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	/* Device file mutex */
12562306a36Sopenharmony_ci	struct mutex		dev_mutex;
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	void __iomem		*base;
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	struct clk		*bus_clk;
13062306a36Sopenharmony_ci	struct clk		*mod_clk;
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	struct reset_control	*rstc;
13362306a36Sopenharmony_ci};
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#endif
136