Path: blob/master/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h
26494 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2014 Traphandler3* Copyright (C) 2014 Free Electrons4* Copyright (C) 2014 Atmel5*6* Author: Jean-Jacques Hiblot <[email protected]>7* Author: Boris BREZILLON <[email protected]>8*/910#ifndef DRM_ATMEL_HLCDC_H11#define DRM_ATMEL_HLCDC_H1213#include <linux/regmap.h>1415#include <drm/drm_plane.h>1617/* LCD controller common registers */18#define ATMEL_HLCDC_LAYER_CHER 0x019#define ATMEL_HLCDC_LAYER_CHDR 0x420#define ATMEL_HLCDC_LAYER_CHSR 0x821#define ATMEL_HLCDC_LAYER_EN BIT(0)22#define ATMEL_HLCDC_LAYER_UPDATE BIT(1)23#define ATMEL_HLCDC_LAYER_A2Q BIT(2)24#define ATMEL_HLCDC_LAYER_RST BIT(8)2526#define ATMEL_HLCDC_LAYER_IER 0xc27#define ATMEL_HLCDC_LAYER_IDR 0x1028#define ATMEL_HLCDC_LAYER_IMR 0x1429#define ATMEL_HLCDC_LAYER_ISR 0x1830#define ATMEL_HLCDC_LAYER_DFETCH BIT(0)31#define ATMEL_HLCDC_LAYER_LFETCH BIT(1)32#define ATMEL_HLCDC_LAYER_DMA_IRQ(p) BIT(2 + (8 * (p)))33#define ATMEL_HLCDC_LAYER_DSCR_IRQ(p) BIT(3 + (8 * (p)))34#define ATMEL_HLCDC_LAYER_ADD_IRQ(p) BIT(4 + (8 * (p)))35#define ATMEL_HLCDC_LAYER_DONE_IRQ(p) BIT(5 + (8 * (p)))36#define ATMEL_HLCDC_LAYER_OVR_IRQ(p) BIT(6 + (8 * (p)))3738#define ATMEL_HLCDC_LAYER_PLANE_HEAD(p) (((p) * 0x10) + 0x1c)39#define ATMEL_HLCDC_LAYER_PLANE_ADDR(p) (((p) * 0x10) + 0x20)40#define ATMEL_HLCDC_LAYER_PLANE_CTRL(p) (((p) * 0x10) + 0x24)41#define ATMEL_HLCDC_LAYER_PLANE_NEXT(p) (((p) * 0x10) + 0x28)4243#define ATMEL_HLCDC_LAYER_DMA_CFG 044#define ATMEL_HLCDC_LAYER_DMA_SIF BIT(0)45#define ATMEL_HLCDC_LAYER_DMA_BLEN_MASK GENMASK(5, 4)46#define ATMEL_HLCDC_LAYER_DMA_BLEN_SINGLE (0 << 4)47#define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR4 (1 << 4)48#define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR8 (2 << 4)49#define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 (3 << 4)50#define ATMEL_HLCDC_LAYER_DMA_DLBO BIT(8)51#define ATMEL_HLCDC_LAYER_DMA_ROTDIS BIT(12)52#define ATMEL_HLCDC_LAYER_DMA_LOCKDIS BIT(13)5354#define ATMEL_HLCDC_LAYER_FORMAT_CFG 155#define ATMEL_HLCDC_LAYER_RGB (0 << 0)56#define ATMEL_HLCDC_LAYER_CLUT (1 << 0)57#define ATMEL_HLCDC_LAYER_YUV (2 << 0)58#define ATMEL_HLCDC_RGB_MODE(m) \59(ATMEL_HLCDC_LAYER_RGB | (((m) & 0xf) << 4))60#define ATMEL_HLCDC_CLUT_MODE(m) \61(ATMEL_HLCDC_LAYER_CLUT | (((m) & 0x3) << 8))62#define ATMEL_HLCDC_YUV_MODE(m) \63(ATMEL_HLCDC_LAYER_YUV | (((m) & 0xf) << 12))64#define ATMEL_HLCDC_YUV422ROT BIT(16)65#define ATMEL_HLCDC_YUV422SWP BIT(17)66#define ATMEL_HLCDC_DSCALEOPT BIT(20)6768#define ATMEL_HLCDC_C1_MODE ATMEL_HLCDC_CLUT_MODE(0)69#define ATMEL_HLCDC_C2_MODE ATMEL_HLCDC_CLUT_MODE(1)70#define ATMEL_HLCDC_C4_MODE ATMEL_HLCDC_CLUT_MODE(2)71#define ATMEL_HLCDC_C8_MODE ATMEL_HLCDC_CLUT_MODE(3)7273#define ATMEL_HLCDC_XRGB4444_MODE ATMEL_HLCDC_RGB_MODE(0)74#define ATMEL_HLCDC_ARGB4444_MODE ATMEL_HLCDC_RGB_MODE(1)75#define ATMEL_HLCDC_RGBA4444_MODE ATMEL_HLCDC_RGB_MODE(2)76#define ATMEL_HLCDC_RGB565_MODE ATMEL_HLCDC_RGB_MODE(3)77#define ATMEL_HLCDC_ARGB1555_MODE ATMEL_HLCDC_RGB_MODE(4)78#define ATMEL_HLCDC_XRGB8888_MODE ATMEL_HLCDC_RGB_MODE(9)79#define ATMEL_HLCDC_RGB888_MODE ATMEL_HLCDC_RGB_MODE(10)80#define ATMEL_HLCDC_ARGB8888_MODE ATMEL_HLCDC_RGB_MODE(12)81#define ATMEL_HLCDC_RGBA8888_MODE ATMEL_HLCDC_RGB_MODE(13)8283#define ATMEL_HLCDC_AYUV_MODE ATMEL_HLCDC_YUV_MODE(0)84#define ATMEL_HLCDC_YUYV_MODE ATMEL_HLCDC_YUV_MODE(1)85#define ATMEL_HLCDC_UYVY_MODE ATMEL_HLCDC_YUV_MODE(2)86#define ATMEL_HLCDC_YVYU_MODE ATMEL_HLCDC_YUV_MODE(3)87#define ATMEL_HLCDC_VYUY_MODE ATMEL_HLCDC_YUV_MODE(4)88#define ATMEL_HLCDC_NV61_MODE ATMEL_HLCDC_YUV_MODE(5)89#define ATMEL_HLCDC_YUV422_MODE ATMEL_HLCDC_YUV_MODE(6)90#define ATMEL_HLCDC_NV21_MODE ATMEL_HLCDC_YUV_MODE(7)91#define ATMEL_HLCDC_YUV420_MODE ATMEL_HLCDC_YUV_MODE(8)9293#define ATMEL_HLCDC_LAYER_POS(x, y) ((x) | ((y) << 16))94#define ATMEL_HLCDC_LAYER_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))9596#define ATMEL_HLCDC_LAYER_CRKEY BIT(0)97#define ATMEL_HLCDC_LAYER_INV BIT(1)98#define ATMEL_HLCDC_LAYER_ITER2BL BIT(2)99#define ATMEL_HLCDC_LAYER_ITER BIT(3)100#define ATMEL_HLCDC_LAYER_REVALPHA BIT(4)101#define ATMEL_HLCDC_LAYER_GAEN BIT(5)102#define ATMEL_HLCDC_LAYER_LAEN BIT(6)103#define ATMEL_HLCDC_LAYER_OVR BIT(7)104#define ATMEL_HLCDC_LAYER_DMA BIT(8)105#define ATMEL_HLCDC_LAYER_REP BIT(9)106#define ATMEL_HLCDC_LAYER_DSTKEY BIT(10)107#define ATMEL_HLCDC_LAYER_DISCEN BIT(11)108#define ATMEL_HLCDC_LAYER_GA_SHIFT 16109#define ATMEL_HLCDC_LAYER_GA_MASK \110GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)111#define ATMEL_HLCDC_LAYER_GA(x) \112((x) << ATMEL_HLCDC_LAYER_GA_SHIFT)113114#define ATMEL_HLCDC_LAYER_DISC_POS(x, y) ((x) | ((y) << 16))115#define ATMEL_HLCDC_LAYER_DISC_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))116117#define ATMEL_HLCDC_LAYER_SCALER_FACTORS(x, y) ((x) | ((y) << 16))118#define ATMEL_HLCDC_LAYER_SCALER_ENABLE BIT(31)119120#define ATMEL_HLCDC_LAYER_MAX_PLANES 3121122#define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)123#define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)124#define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)125#define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)126127#define ATMEL_HLCDC_CLUT_SIZE 256128129#define ATMEL_HLCDC_MAX_LAYERS 6130131/* XLCDC controller specific registers */132#define ATMEL_XLCDC_LAYER_ENR 0x10133#define ATMEL_XLCDC_LAYER_EN BIT(0)134135#define ATMEL_XLCDC_LAYER_IER 0x0136#define ATMEL_XLCDC_LAYER_IDR 0x4137#define ATMEL_XLCDC_LAYER_ISR 0xc138#define ATMEL_XLCDC_LAYER_OVR_IRQ(p) BIT(2 + (8 * (p)))139140#define ATMEL_XLCDC_LAYER_PLANE_ADDR(p) (((p) * 0x4) + 0x18)141142#define ATMEL_XLCDC_LAYER_DMA_CFG 0143144#define ATMEL_XLCDC_LAYER_DMA BIT(0)145#define ATMEL_XLCDC_LAYER_REP BIT(1)146#define ATMEL_XLCDC_LAYER_DISCEN BIT(4)147148#define ATMEL_XLCDC_LAYER_SFACTC_A0_MULT_AS (4 << 6)149#define ATMEL_XLCDC_LAYER_SFACTA_ONE BIT(9)150#define ATMEL_XLCDC_LAYER_DFACTC_M_A0_MULT_AS (6 << 11)151#define ATMEL_XLCDC_LAYER_DFACTA_ONE BIT(14)152153#define ATMEL_XLCDC_LAYER_A0_SHIFT 16154#define ATMEL_XLCDC_LAYER_A0(x) \155((x) << ATMEL_XLCDC_LAYER_A0_SHIFT)156157#define ATMEL_XLCDC_LAYER_VSCALER_LUMA_ENABLE BIT(0)158#define ATMEL_XLCDC_LAYER_VSCALER_CHROMA_ENABLE BIT(1)159#define ATMEL_XLCDC_LAYER_HSCALER_LUMA_ENABLE BIT(4)160#define ATMEL_XLCDC_LAYER_HSCALER_CHROMA_ENABLE BIT(5)161162#define ATMEL_XLCDC_LAYER_VXSYCFG_ONE BIT(0)163#define ATMEL_XLCDC_LAYER_VXSYTAP2_ENABLE BIT(4)164#define ATMEL_XLCDC_LAYER_VXSCCFG_ONE BIT(16)165#define ATMEL_XLCDC_LAYER_VXSCTAP2_ENABLE BIT(20)166167#define ATMEL_XLCDC_LAYER_HXSYCFG_ONE BIT(0)168#define ATMEL_XLCDC_LAYER_HXSYTAP2_ENABLE BIT(4)169#define ATMEL_XLCDC_LAYER_HXSCCFG_ONE BIT(16)170#define ATMEL_XLCDC_LAYER_HXSCTAP2_ENABLE BIT(20)171172/**173* Atmel HLCDC Layer registers layout structure174*175* Each HLCDC layer has its own register organization and a given register176* can be placed differently on 2 different layers depending on its177* capabilities.178* This structure stores common registers layout for a given layer and is179* used by HLCDC layer code to choose the appropriate register to write to180* or to read from.181*182* For all fields, a value of zero means "unsupported".183*184* See Atmel's datasheet for a detailled description of these registers.185*186* @xstride: xstride registers187* @pstride: pstride registers188* @pos: position register189* @size: displayed size register190* @memsize: memory size register191* @default_color: default color register192* @chroma_key: chroma key register193* @chroma_key_mask: chroma key mask register194* @general_config: general layer config register195* @sacler_config: scaler factors register196* @phicoeffs: X/Y PHI coefficient registers197* @disc_pos: discard area position register198* @disc_size: discard area size register199* @csc: color space conversion register200* @vxs_config: vertical scalar filter taps control register201* @hxs_config: horizontal scalar filter taps control register202*/203struct atmel_hlcdc_layer_cfg_layout {204int xstride[ATMEL_HLCDC_LAYER_MAX_PLANES];205int pstride[ATMEL_HLCDC_LAYER_MAX_PLANES];206int pos;207int size;208int memsize;209int default_color;210int chroma_key;211int chroma_key_mask;212int general_config;213int scaler_config;214struct {215int x;216int y;217} phicoeffs;218int disc_pos;219int disc_size;220int csc;221int vxs_config;222int hxs_config;223};224225/**226* Atmel HLCDC DMA descriptor structure227*228* This structure is used by the HLCDC DMA engine to schedule a DMA transfer.229*230* The structure fields must remain in this specific order, because they're231* used by the HLCDC DMA engine, which expect them in this order.232* HLCDC DMA descriptors must be aligned on 64 bits.233*234* @addr: buffer DMA address235* @ctrl: DMA transfer options236* @next: next DMA descriptor to fetch237* @self: descriptor DMA address238*/239struct atmel_hlcdc_dma_channel_dscr {240dma_addr_t addr;241u32 ctrl;242dma_addr_t next;243dma_addr_t self;244} __aligned(sizeof(u64));245246/**247* Atmel HLCDC layer types248*/249enum atmel_hlcdc_layer_type {250ATMEL_HLCDC_NO_LAYER,251ATMEL_HLCDC_BASE_LAYER,252ATMEL_HLCDC_OVERLAY_LAYER,253ATMEL_HLCDC_CURSOR_LAYER,254ATMEL_HLCDC_PP_LAYER,255};256257/**258* Atmel HLCDC Supported formats structure259*260* This structure list all the formats supported by a given layer.261*262* @nformats: number of supported formats263* @formats: supported formats264*/265struct atmel_hlcdc_formats {266int nformats;267u32 *formats;268};269270/**271* Atmel HLCDC Layer description structure272*273* This structure describes the capabilities provided by a given layer.274*275* @name: layer name276* @type: layer type277* @id: layer id278* @regs_offset: offset of the layer registers from the HLCDC registers base279* @cfgs_offset: CFGX registers offset from the layer registers base280* @formats: supported formats281* @layout: config registers layout282* @max_width: maximum width supported by this layer (0 means unlimited)283* @max_height: maximum height supported by this layer (0 means unlimited)284*/285struct atmel_hlcdc_layer_desc {286const char *name;287enum atmel_hlcdc_layer_type type;288int id;289int regs_offset;290int cfgs_offset;291int clut_offset;292struct atmel_hlcdc_formats *formats;293struct atmel_hlcdc_layer_cfg_layout layout;294int max_width;295int max_height;296};297298/**299* Atmel HLCDC Layer.300*301* A layer can be a DRM plane of a post processing layer used to render302* HLCDC composition into memory.303*304* @desc: layer description305* @regmap: pointer to the HLCDC regmap306*/307struct atmel_hlcdc_layer {308const struct atmel_hlcdc_layer_desc *desc;309struct regmap *regmap;310};311312/**313* Atmel HLCDC Plane.314*315* @base: base DRM plane structure316* @layer: HLCDC layer structure317* @properties: pointer to the property definitions structure318*/319struct atmel_hlcdc_plane {320struct drm_plane base;321struct atmel_hlcdc_layer layer;322};323324static inline struct atmel_hlcdc_plane *325drm_plane_to_atmel_hlcdc_plane(struct drm_plane *p)326{327return container_of(p, struct atmel_hlcdc_plane, base);328}329330static inline struct atmel_hlcdc_plane *331atmel_hlcdc_layer_to_plane(struct atmel_hlcdc_layer *layer)332{333return container_of(layer, struct atmel_hlcdc_plane, layer);334}335336/**337* struct atmel_hlcdc_dc - Atmel HLCDC Display Controller.338* @desc: HLCDC Display Controller description339* @dscrpool: DMA coherent pool used to allocate DMA descriptors340* @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device341* @crtc: CRTC provided by the display controller342* @layers: active HLCDC layers343* @suspend: used to store the HLCDC state when entering suspend344* @suspend.imr: used to read/write LCDC Interrupt Mask Register345* @suspend.state: Atomic commit structure346*/347struct atmel_hlcdc_dc {348const struct atmel_hlcdc_dc_desc *desc;349struct dma_pool *dscrpool;350struct atmel_hlcdc *hlcdc;351struct drm_crtc *crtc;352struct atmel_hlcdc_layer *layers[ATMEL_HLCDC_MAX_LAYERS];353struct {354u32 imr;355struct drm_atomic_state *state;356} suspend;357};358359struct atmel_hlcdc_plane_state;360361/**362* struct atmel_lcdc_dc_ops - describes atmel_lcdc ops group363* to differentiate HLCDC and XLCDC IP code support364* @plane_setup_scaler: update the vertical and horizontal scaling factors365* @update_lcdc_buffers: update the each LCDC layers DMA registers366* @lcdc_atomic_disable: disable LCDC interrupts and layers367* @lcdc_update_general_settings: update each LCDC layers general368* configuration register369* @lcdc_atomic_update: enable the LCDC layers and interrupts370* @lcdc_csc_init: update the color space conversion co-efficient of371* High-end overlay register372* @lcdc_irq_dbg: to raise alert incase of interrupt overrun in any LCDC layer373*/374struct atmel_lcdc_dc_ops {375void (*plane_setup_scaler)(struct atmel_hlcdc_plane *plane,376struct atmel_hlcdc_plane_state *state);377void (*lcdc_update_buffers)(struct atmel_hlcdc_plane *plane,378struct atmel_hlcdc_plane_state *state,379u32 sr, int i);380void (*lcdc_atomic_disable)(struct atmel_hlcdc_plane *plane);381void (*lcdc_update_general_settings)(struct atmel_hlcdc_plane *plane,382struct atmel_hlcdc_plane_state *state);383void (*lcdc_atomic_update)(struct atmel_hlcdc_plane *plane,384struct atmel_hlcdc_dc *dc);385void (*lcdc_csc_init)(struct atmel_hlcdc_plane *plane,386const struct atmel_hlcdc_layer_desc *desc);387void (*lcdc_irq_dbg)(struct atmel_hlcdc_plane *plane,388const struct atmel_hlcdc_layer_desc *desc);389};390391extern const struct atmel_lcdc_dc_ops atmel_hlcdc_ops;392extern const struct atmel_lcdc_dc_ops atmel_xlcdc_ops;393394/**395* Atmel HLCDC Display Controller description structure.396*397* This structure describes the HLCDC IP capabilities and depends on the398* HLCDC IP version (or Atmel SoC family).399*400* @min_width: minimum width supported by the Display Controller401* @min_height: minimum height supported by the Display Controller402* @max_width: maximum width supported by the Display Controller403* @max_height: maximum height supported by the Display Controller404* @max_spw: maximum vertical/horizontal pulse width405* @max_vpw: maximum vertical back/front porch width406* @max_hpw: maximum horizontal back/front porch width407* @conflicting_output_formats: true if RGBXXX output formats conflict with408* each other.409* @fixed_clksrc: true if clock source is fixed410* @is_xlcdc: true if XLCDC IP is supported411* @layers: a layer description table describing available layers412* @nlayers: layer description table size413* @ops: atmel lcdc dc ops414*/415struct atmel_hlcdc_dc_desc {416int min_width;417int min_height;418int max_width;419int max_height;420int max_spw;421int max_vpw;422int max_hpw;423bool conflicting_output_formats;424bool fixed_clksrc;425bool is_xlcdc;426const struct atmel_hlcdc_layer_desc *layers;427int nlayers;428const struct atmel_lcdc_dc_ops *ops;429};430431extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_formats;432extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_and_yuv_formats;433434static inline void atmel_hlcdc_layer_write_reg(struct atmel_hlcdc_layer *layer,435unsigned int reg, u32 val)436{437regmap_write(layer->regmap, layer->desc->regs_offset + reg, val);438}439440static inline u32 atmel_hlcdc_layer_read_reg(struct atmel_hlcdc_layer *layer,441unsigned int reg)442{443u32 val;444445regmap_read(layer->regmap, layer->desc->regs_offset + reg, &val);446447return val;448}449450static inline void atmel_hlcdc_layer_write_cfg(struct atmel_hlcdc_layer *layer,451unsigned int cfgid, u32 val)452{453atmel_hlcdc_layer_write_reg(layer,454layer->desc->cfgs_offset +455(cfgid * sizeof(u32)), val);456}457458static inline u32 atmel_hlcdc_layer_read_cfg(struct atmel_hlcdc_layer *layer,459unsigned int cfgid)460{461return atmel_hlcdc_layer_read_reg(layer,462layer->desc->cfgs_offset +463(cfgid * sizeof(u32)));464}465466static inline void atmel_hlcdc_layer_write_clut(struct atmel_hlcdc_layer *layer,467unsigned int c, u32 val)468{469regmap_write(layer->regmap,470layer->desc->clut_offset + c * sizeof(u32),471val);472}473474static inline void atmel_hlcdc_layer_init(struct atmel_hlcdc_layer *layer,475const struct atmel_hlcdc_layer_desc *desc,476struct regmap *regmap)477{478layer->desc = desc;479layer->regmap = regmap;480}481482enum drm_mode_status483atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc,484const struct drm_display_mode *mode);485486int atmel_hlcdc_create_planes(struct drm_device *dev);487void atmel_hlcdc_plane_irq(struct atmel_hlcdc_plane *plane);488489int atmel_hlcdc_plane_prepare_disc_area(struct drm_crtc_state *c_state);490int atmel_hlcdc_plane_prepare_ahb_routing(struct drm_crtc_state *c_state);491492void atmel_hlcdc_crtc_irq(struct drm_crtc *c);493494int atmel_hlcdc_crtc_create(struct drm_device *dev);495496int atmel_hlcdc_create_outputs(struct drm_device *dev);497int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder);498499#endif /* DRM_ATMEL_HLCDC_H */500501502