162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) Jernej Skrabec <jernej.skrabec@siol.net>
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _SUN8I_VI_LAYER_H_
762306a36Sopenharmony_ci#define _SUN8I_VI_LAYER_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <drm/drm_plane.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_ATTR(base, layer) \
1262306a36Sopenharmony_ci		((base) + 0x30 * (layer) + 0x0)
1362306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_SIZE(base, layer) \
1462306a36Sopenharmony_ci		((base) + 0x30 * (layer) + 0x4)
1562306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_COORD(base, layer) \
1662306a36Sopenharmony_ci		((base) + 0x30 * (layer) + 0x8)
1762306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_PITCH(base, layer, plane) \
1862306a36Sopenharmony_ci		((base) + 0x30 * (layer) + 0xc + 4 * (plane))
1962306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_TOP_LADDR(base, layer, plane) \
2062306a36Sopenharmony_ci		((base) + 0x30 * (layer) + 0x18 + 4 * (plane))
2162306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_OVL_SIZE(base) \
2262306a36Sopenharmony_ci		((base) + 0xe8)
2362306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_HDS_Y(base) \
2462306a36Sopenharmony_ci		((base) + 0xf0)
2562306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_HDS_UV(base) \
2662306a36Sopenharmony_ci		((base) + 0xf4)
2762306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_VDS_Y(base) \
2862306a36Sopenharmony_ci		((base) + 0xf8)
2962306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_VDS_UV(base) \
3062306a36Sopenharmony_ci		((base) + 0xfc)
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define SUN8I_MIXER_FCC_GLOBAL_ALPHA_REG \
3362306a36Sopenharmony_ci		(0xAA000 + 0x90)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define SUN8I_MIXER_FCC_GLOBAL_ALPHA(x)			((x) << 24)
3662306a36Sopenharmony_ci#define SUN8I_MIXER_FCC_GLOBAL_ALPHA_MASK		GENMASK(31, 24)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_EN		BIT(0)
3962306a36Sopenharmony_ci/* RGB mode should be set for RGB formats and cleared for YCbCr */
4062306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE		BIT(15)
4162306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_OFFSET	8
4262306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_MASK	GENMASK(12, 8)
4362306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_MASK	GENMASK(2, 1)
4462306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MASK	GENMASK(31, 24)
4562306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA(x)	((x) << 24)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_PIXEL	((0) << 1)
4862306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_LAYER	((1) << 1)
4962306a36Sopenharmony_ci#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_COMBINED	((2) << 1)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_DS_N(x)			((x) << 16)
5262306a36Sopenharmony_ci#define SUN8I_MIXER_CHAN_VI_DS_M(x)			((x) << 0)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct sun8i_mixer;
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistruct sun8i_vi_layer {
5762306a36Sopenharmony_ci	struct drm_plane	plane;
5862306a36Sopenharmony_ci	struct sun8i_mixer	*mixer;
5962306a36Sopenharmony_ci	int			channel;
6062306a36Sopenharmony_ci	int			overlay;
6162306a36Sopenharmony_ci};
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistatic inline struct sun8i_vi_layer *
6462306a36Sopenharmony_ciplane_to_sun8i_vi_layer(struct drm_plane *plane)
6562306a36Sopenharmony_ci{
6662306a36Sopenharmony_ci	return container_of(plane, struct sun8i_vi_layer, plane);
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistruct sun8i_vi_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
7062306a36Sopenharmony_ci					       struct sun8i_mixer *mixer,
7162306a36Sopenharmony_ci					       int index);
7262306a36Sopenharmony_ci#endif /* _SUN8I_VI_LAYER_H_ */
73