0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef DRM_ATMEL_HLCDC_H
0012 #define DRM_ATMEL_HLCDC_H
0013
0014 #include <linux/regmap.h>
0015
0016 #include <drm/drm_plane.h>
0017
0018 #define ATMEL_HLCDC_LAYER_CHER 0x0
0019 #define ATMEL_HLCDC_LAYER_CHDR 0x4
0020 #define ATMEL_HLCDC_LAYER_CHSR 0x8
0021 #define ATMEL_HLCDC_LAYER_EN BIT(0)
0022 #define ATMEL_HLCDC_LAYER_UPDATE BIT(1)
0023 #define ATMEL_HLCDC_LAYER_A2Q BIT(2)
0024 #define ATMEL_HLCDC_LAYER_RST BIT(8)
0025
0026 #define ATMEL_HLCDC_LAYER_IER 0xc
0027 #define ATMEL_HLCDC_LAYER_IDR 0x10
0028 #define ATMEL_HLCDC_LAYER_IMR 0x14
0029 #define ATMEL_HLCDC_LAYER_ISR 0x18
0030 #define ATMEL_HLCDC_LAYER_DFETCH BIT(0)
0031 #define ATMEL_HLCDC_LAYER_LFETCH BIT(1)
0032 #define ATMEL_HLCDC_LAYER_DMA_IRQ(p) BIT(2 + (8 * (p)))
0033 #define ATMEL_HLCDC_LAYER_DSCR_IRQ(p) BIT(3 + (8 * (p)))
0034 #define ATMEL_HLCDC_LAYER_ADD_IRQ(p) BIT(4 + (8 * (p)))
0035 #define ATMEL_HLCDC_LAYER_DONE_IRQ(p) BIT(5 + (8 * (p)))
0036 #define ATMEL_HLCDC_LAYER_OVR_IRQ(p) BIT(6 + (8 * (p)))
0037
0038 #define ATMEL_HLCDC_LAYER_PLANE_HEAD(p) (((p) * 0x10) + 0x1c)
0039 #define ATMEL_HLCDC_LAYER_PLANE_ADDR(p) (((p) * 0x10) + 0x20)
0040 #define ATMEL_HLCDC_LAYER_PLANE_CTRL(p) (((p) * 0x10) + 0x24)
0041 #define ATMEL_HLCDC_LAYER_PLANE_NEXT(p) (((p) * 0x10) + 0x28)
0042
0043 #define ATMEL_HLCDC_LAYER_DMA_CFG 0
0044 #define ATMEL_HLCDC_LAYER_DMA_SIF BIT(0)
0045 #define ATMEL_HLCDC_LAYER_DMA_BLEN_MASK GENMASK(5, 4)
0046 #define ATMEL_HLCDC_LAYER_DMA_BLEN_SINGLE (0 << 4)
0047 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR4 (1 << 4)
0048 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR8 (2 << 4)
0049 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 (3 << 4)
0050 #define ATMEL_HLCDC_LAYER_DMA_DLBO BIT(8)
0051 #define ATMEL_HLCDC_LAYER_DMA_ROTDIS BIT(12)
0052 #define ATMEL_HLCDC_LAYER_DMA_LOCKDIS BIT(13)
0053
0054 #define ATMEL_HLCDC_LAYER_FORMAT_CFG 1
0055 #define ATMEL_HLCDC_LAYER_RGB (0 << 0)
0056 #define ATMEL_HLCDC_LAYER_CLUT (1 << 0)
0057 #define ATMEL_HLCDC_LAYER_YUV (2 << 0)
0058 #define ATMEL_HLCDC_RGB_MODE(m) \
0059 (ATMEL_HLCDC_LAYER_RGB | (((m) & 0xf) << 4))
0060 #define ATMEL_HLCDC_CLUT_MODE(m) \
0061 (ATMEL_HLCDC_LAYER_CLUT | (((m) & 0x3) << 8))
0062 #define ATMEL_HLCDC_YUV_MODE(m) \
0063 (ATMEL_HLCDC_LAYER_YUV | (((m) & 0xf) << 12))
0064 #define ATMEL_HLCDC_YUV422ROT BIT(16)
0065 #define ATMEL_HLCDC_YUV422SWP BIT(17)
0066 #define ATMEL_HLCDC_DSCALEOPT BIT(20)
0067
0068 #define ATMEL_HLCDC_C1_MODE ATMEL_HLCDC_CLUT_MODE(0)
0069 #define ATMEL_HLCDC_C2_MODE ATMEL_HLCDC_CLUT_MODE(1)
0070 #define ATMEL_HLCDC_C4_MODE ATMEL_HLCDC_CLUT_MODE(2)
0071 #define ATMEL_HLCDC_C8_MODE ATMEL_HLCDC_CLUT_MODE(3)
0072
0073 #define ATMEL_HLCDC_XRGB4444_MODE ATMEL_HLCDC_RGB_MODE(0)
0074 #define ATMEL_HLCDC_ARGB4444_MODE ATMEL_HLCDC_RGB_MODE(1)
0075 #define ATMEL_HLCDC_RGBA4444_MODE ATMEL_HLCDC_RGB_MODE(2)
0076 #define ATMEL_HLCDC_RGB565_MODE ATMEL_HLCDC_RGB_MODE(3)
0077 #define ATMEL_HLCDC_ARGB1555_MODE ATMEL_HLCDC_RGB_MODE(4)
0078 #define ATMEL_HLCDC_XRGB8888_MODE ATMEL_HLCDC_RGB_MODE(9)
0079 #define ATMEL_HLCDC_RGB888_MODE ATMEL_HLCDC_RGB_MODE(10)
0080 #define ATMEL_HLCDC_ARGB8888_MODE ATMEL_HLCDC_RGB_MODE(12)
0081 #define ATMEL_HLCDC_RGBA8888_MODE ATMEL_HLCDC_RGB_MODE(13)
0082
0083 #define ATMEL_HLCDC_AYUV_MODE ATMEL_HLCDC_YUV_MODE(0)
0084 #define ATMEL_HLCDC_YUYV_MODE ATMEL_HLCDC_YUV_MODE(1)
0085 #define ATMEL_HLCDC_UYVY_MODE ATMEL_HLCDC_YUV_MODE(2)
0086 #define ATMEL_HLCDC_YVYU_MODE ATMEL_HLCDC_YUV_MODE(3)
0087 #define ATMEL_HLCDC_VYUY_MODE ATMEL_HLCDC_YUV_MODE(4)
0088 #define ATMEL_HLCDC_NV61_MODE ATMEL_HLCDC_YUV_MODE(5)
0089 #define ATMEL_HLCDC_YUV422_MODE ATMEL_HLCDC_YUV_MODE(6)
0090 #define ATMEL_HLCDC_NV21_MODE ATMEL_HLCDC_YUV_MODE(7)
0091 #define ATMEL_HLCDC_YUV420_MODE ATMEL_HLCDC_YUV_MODE(8)
0092
0093 #define ATMEL_HLCDC_LAYER_POS(x, y) ((x) | ((y) << 16))
0094 #define ATMEL_HLCDC_LAYER_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))
0095
0096 #define ATMEL_HLCDC_LAYER_CRKEY BIT(0)
0097 #define ATMEL_HLCDC_LAYER_INV BIT(1)
0098 #define ATMEL_HLCDC_LAYER_ITER2BL BIT(2)
0099 #define ATMEL_HLCDC_LAYER_ITER BIT(3)
0100 #define ATMEL_HLCDC_LAYER_REVALPHA BIT(4)
0101 #define ATMEL_HLCDC_LAYER_GAEN BIT(5)
0102 #define ATMEL_HLCDC_LAYER_LAEN BIT(6)
0103 #define ATMEL_HLCDC_LAYER_OVR BIT(7)
0104 #define ATMEL_HLCDC_LAYER_DMA BIT(8)
0105 #define ATMEL_HLCDC_LAYER_REP BIT(9)
0106 #define ATMEL_HLCDC_LAYER_DSTKEY BIT(10)
0107 #define ATMEL_HLCDC_LAYER_DISCEN BIT(11)
0108 #define ATMEL_HLCDC_LAYER_GA_SHIFT 16
0109 #define ATMEL_HLCDC_LAYER_GA_MASK \
0110 GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)
0111 #define ATMEL_HLCDC_LAYER_GA(x) \
0112 ((x) << ATMEL_HLCDC_LAYER_GA_SHIFT)
0113
0114 #define ATMEL_HLCDC_LAYER_DISC_POS(x, y) ((x) | ((y) << 16))
0115 #define ATMEL_HLCDC_LAYER_DISC_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))
0116
0117 #define ATMEL_HLCDC_LAYER_SCALER_FACTORS(x, y) ((x) | ((y) << 16))
0118 #define ATMEL_HLCDC_LAYER_SCALER_ENABLE BIT(31)
0119
0120 #define ATMEL_HLCDC_LAYER_MAX_PLANES 3
0121
0122 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)
0123 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)
0124 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)
0125 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)
0126
0127 #define ATMEL_HLCDC_CLUT_SIZE 256
0128
0129 #define ATMEL_HLCDC_MAX_LAYERS 6
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 struct atmel_hlcdc_layer_cfg_layout {
0161 int xstride[ATMEL_HLCDC_LAYER_MAX_PLANES];
0162 int pstride[ATMEL_HLCDC_LAYER_MAX_PLANES];
0163 int pos;
0164 int size;
0165 int memsize;
0166 int default_color;
0167 int chroma_key;
0168 int chroma_key_mask;
0169 int general_config;
0170 int scaler_config;
0171 struct {
0172 int x;
0173 int y;
0174 } phicoeffs;
0175 int disc_pos;
0176 int disc_size;
0177 int csc;
0178 };
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 struct atmel_hlcdc_dma_channel_dscr {
0195 dma_addr_t addr;
0196 u32 ctrl;
0197 dma_addr_t next;
0198 dma_addr_t self;
0199 } __aligned(sizeof(u64));
0200
0201
0202
0203
0204 enum atmel_hlcdc_layer_type {
0205 ATMEL_HLCDC_NO_LAYER,
0206 ATMEL_HLCDC_BASE_LAYER,
0207 ATMEL_HLCDC_OVERLAY_LAYER,
0208 ATMEL_HLCDC_CURSOR_LAYER,
0209 ATMEL_HLCDC_PP_LAYER,
0210 };
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 struct atmel_hlcdc_formats {
0221 int nformats;
0222 u32 *formats;
0223 };
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 struct atmel_hlcdc_layer_desc {
0241 const char *name;
0242 enum atmel_hlcdc_layer_type type;
0243 int id;
0244 int regs_offset;
0245 int cfgs_offset;
0246 int clut_offset;
0247 struct atmel_hlcdc_formats *formats;
0248 struct atmel_hlcdc_layer_cfg_layout layout;
0249 int max_width;
0250 int max_height;
0251 };
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262 struct atmel_hlcdc_layer {
0263 const struct atmel_hlcdc_layer_desc *desc;
0264 struct regmap *regmap;
0265 };
0266
0267
0268
0269
0270
0271
0272
0273
0274 struct atmel_hlcdc_plane {
0275 struct drm_plane base;
0276 struct atmel_hlcdc_layer layer;
0277 };
0278
0279 static inline struct atmel_hlcdc_plane *
0280 drm_plane_to_atmel_hlcdc_plane(struct drm_plane *p)
0281 {
0282 return container_of(p, struct atmel_hlcdc_plane, base);
0283 }
0284
0285 static inline struct atmel_hlcdc_plane *
0286 atmel_hlcdc_layer_to_plane(struct atmel_hlcdc_layer *layer)
0287 {
0288 return container_of(layer, struct atmel_hlcdc_plane, layer);
0289 }
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310 struct atmel_hlcdc_dc_desc {
0311 int min_width;
0312 int min_height;
0313 int max_width;
0314 int max_height;
0315 int max_spw;
0316 int max_vpw;
0317 int max_hpw;
0318 bool conflicting_output_formats;
0319 bool fixed_clksrc;
0320 const struct atmel_hlcdc_layer_desc *layers;
0321 int nlayers;
0322 };
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 struct atmel_hlcdc_dc {
0337 const struct atmel_hlcdc_dc_desc *desc;
0338 struct dma_pool *dscrpool;
0339 struct atmel_hlcdc *hlcdc;
0340 struct drm_crtc *crtc;
0341 struct atmel_hlcdc_layer *layers[ATMEL_HLCDC_MAX_LAYERS];
0342 struct {
0343 u32 imr;
0344 struct drm_atomic_state *state;
0345 } suspend;
0346 };
0347
0348 extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_formats;
0349 extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_and_yuv_formats;
0350
0351 static inline void atmel_hlcdc_layer_write_reg(struct atmel_hlcdc_layer *layer,
0352 unsigned int reg, u32 val)
0353 {
0354 regmap_write(layer->regmap, layer->desc->regs_offset + reg, val);
0355 }
0356
0357 static inline u32 atmel_hlcdc_layer_read_reg(struct atmel_hlcdc_layer *layer,
0358 unsigned int reg)
0359 {
0360 u32 val;
0361
0362 regmap_read(layer->regmap, layer->desc->regs_offset + reg, &val);
0363
0364 return val;
0365 }
0366
0367 static inline void atmel_hlcdc_layer_write_cfg(struct atmel_hlcdc_layer *layer,
0368 unsigned int cfgid, u32 val)
0369 {
0370 atmel_hlcdc_layer_write_reg(layer,
0371 layer->desc->cfgs_offset +
0372 (cfgid * sizeof(u32)), val);
0373 }
0374
0375 static inline u32 atmel_hlcdc_layer_read_cfg(struct atmel_hlcdc_layer *layer,
0376 unsigned int cfgid)
0377 {
0378 return atmel_hlcdc_layer_read_reg(layer,
0379 layer->desc->cfgs_offset +
0380 (cfgid * sizeof(u32)));
0381 }
0382
0383 static inline void atmel_hlcdc_layer_write_clut(struct atmel_hlcdc_layer *layer,
0384 unsigned int c, u32 val)
0385 {
0386 regmap_write(layer->regmap,
0387 layer->desc->clut_offset + c * sizeof(u32),
0388 val);
0389 }
0390
0391 static inline void atmel_hlcdc_layer_init(struct atmel_hlcdc_layer *layer,
0392 const struct atmel_hlcdc_layer_desc *desc,
0393 struct regmap *regmap)
0394 {
0395 layer->desc = desc;
0396 layer->regmap = regmap;
0397 }
0398
0399 enum drm_mode_status
0400 atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc,
0401 const struct drm_display_mode *mode);
0402
0403 int atmel_hlcdc_create_planes(struct drm_device *dev);
0404 void atmel_hlcdc_plane_irq(struct atmel_hlcdc_plane *plane);
0405
0406 int atmel_hlcdc_plane_prepare_disc_area(struct drm_crtc_state *c_state);
0407 int atmel_hlcdc_plane_prepare_ahb_routing(struct drm_crtc_state *c_state);
0408
0409 void atmel_hlcdc_crtc_irq(struct drm_crtc *c);
0410
0411 int atmel_hlcdc_crtc_create(struct drm_device *dev);
0412
0413 int atmel_hlcdc_create_outputs(struct drm_device *dev);
0414 int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder);
0415
0416 #endif