atmel_hlcdc_dc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * Copyright (C) 2014 Traphandler
  3. * Copyright (C) 2014 Free Electrons
  4. * Copyright (C) 2014 Atmel
  5. *
  6. * Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
  7. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef DRM_ATMEL_HLCDC_H
  22. #define DRM_ATMEL_HLCDC_H
  23. #include <linux/clk.h>
  24. #include <linux/dmapool.h>
  25. #include <linux/irqdomain.h>
  26. #include <linux/mfd/atmel-hlcdc.h>
  27. #include <linux/pwm.h>
  28. #include <drm/drm_atomic.h>
  29. #include <drm/drm_atomic_helper.h>
  30. #include <drm/drm_crtc.h>
  31. #include <drm/drm_crtc_helper.h>
  32. #include <drm/drm_fb_cma_helper.h>
  33. #include <drm/drm_gem_cma_helper.h>
  34. #include <drm/drm_panel.h>
  35. #include <drm/drm_plane_helper.h>
  36. #include <drm/drmP.h>
  37. #define ATMEL_HLCDC_LAYER_CHER 0x0
  38. #define ATMEL_HLCDC_LAYER_CHDR 0x4
  39. #define ATMEL_HLCDC_LAYER_CHSR 0x8
  40. #define ATMEL_HLCDC_LAYER_EN BIT(0)
  41. #define ATMEL_HLCDC_LAYER_UPDATE BIT(1)
  42. #define ATMEL_HLCDC_LAYER_A2Q BIT(2)
  43. #define ATMEL_HLCDC_LAYER_RST BIT(8)
  44. #define ATMEL_HLCDC_LAYER_IER 0xc
  45. #define ATMEL_HLCDC_LAYER_IDR 0x10
  46. #define ATMEL_HLCDC_LAYER_IMR 0x14
  47. #define ATMEL_HLCDC_LAYER_ISR 0x18
  48. #define ATMEL_HLCDC_LAYER_DFETCH BIT(0)
  49. #define ATMEL_HLCDC_LAYER_LFETCH BIT(1)
  50. #define ATMEL_HLCDC_LAYER_DMA_IRQ(p) BIT(2 + (8 * (p)))
  51. #define ATMEL_HLCDC_LAYER_DSCR_IRQ(p) BIT(3 + (8 * (p)))
  52. #define ATMEL_HLCDC_LAYER_ADD_IRQ(p) BIT(4 + (8 * (p)))
  53. #define ATMEL_HLCDC_LAYER_DONE_IRQ(p) BIT(5 + (8 * (p)))
  54. #define ATMEL_HLCDC_LAYER_OVR_IRQ(p) BIT(6 + (8 * (p)))
  55. #define ATMEL_HLCDC_LAYER_PLANE_HEAD(p) (((p) * 0x10) + 0x1c)
  56. #define ATMEL_HLCDC_LAYER_PLANE_ADDR(p) (((p) * 0x10) + 0x20)
  57. #define ATMEL_HLCDC_LAYER_PLANE_CTRL(p) (((p) * 0x10) + 0x24)
  58. #define ATMEL_HLCDC_LAYER_PLANE_NEXT(p) (((p) * 0x10) + 0x28)
  59. #define ATMEL_HLCDC_LAYER_DMA_CFG 0
  60. #define ATMEL_HLCDC_LAYER_DMA_SIF BIT(0)
  61. #define ATMEL_HLCDC_LAYER_DMA_BLEN_MASK GENMASK(5, 4)
  62. #define ATMEL_HLCDC_LAYER_DMA_BLEN_SINGLE (0 << 4)
  63. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR4 (1 << 4)
  64. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR8 (2 << 4)
  65. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 (3 << 4)
  66. #define ATMEL_HLCDC_LAYER_DMA_DLBO BIT(8)
  67. #define ATMEL_HLCDC_LAYER_DMA_ROTDIS BIT(12)
  68. #define ATMEL_HLCDC_LAYER_DMA_LOCKDIS BIT(13)
  69. #define ATMEL_HLCDC_LAYER_FORMAT_CFG 1
  70. #define ATMEL_HLCDC_LAYER_RGB (0 << 0)
  71. #define ATMEL_HLCDC_LAYER_CLUT (1 << 0)
  72. #define ATMEL_HLCDC_LAYER_YUV (2 << 0)
  73. #define ATMEL_HLCDC_RGB_MODE(m) \
  74. (ATMEL_HLCDC_LAYER_RGB | (((m) & 0xf) << 4))
  75. #define ATMEL_HLCDC_CLUT_MODE(m) \
  76. (ATMEL_HLCDC_LAYER_CLUT | (((m) & 0x3) << 8))
  77. #define ATMEL_HLCDC_YUV_MODE(m) \
  78. (ATMEL_HLCDC_LAYER_YUV | (((m) & 0xf) << 12))
  79. #define ATMEL_HLCDC_YUV422ROT BIT(16)
  80. #define ATMEL_HLCDC_YUV422SWP BIT(17)
  81. #define ATMEL_HLCDC_DSCALEOPT BIT(20)
  82. #define ATMEL_HLCDC_XRGB4444_MODE ATMEL_HLCDC_RGB_MODE(0)
  83. #define ATMEL_HLCDC_ARGB4444_MODE ATMEL_HLCDC_RGB_MODE(1)
  84. #define ATMEL_HLCDC_RGBA4444_MODE ATMEL_HLCDC_RGB_MODE(2)
  85. #define ATMEL_HLCDC_RGB565_MODE ATMEL_HLCDC_RGB_MODE(3)
  86. #define ATMEL_HLCDC_ARGB1555_MODE ATMEL_HLCDC_RGB_MODE(4)
  87. #define ATMEL_HLCDC_XRGB8888_MODE ATMEL_HLCDC_RGB_MODE(9)
  88. #define ATMEL_HLCDC_RGB888_MODE ATMEL_HLCDC_RGB_MODE(10)
  89. #define ATMEL_HLCDC_ARGB8888_MODE ATMEL_HLCDC_RGB_MODE(12)
  90. #define ATMEL_HLCDC_RGBA8888_MODE ATMEL_HLCDC_RGB_MODE(13)
  91. #define ATMEL_HLCDC_AYUV_MODE ATMEL_HLCDC_YUV_MODE(0)
  92. #define ATMEL_HLCDC_YUYV_MODE ATMEL_HLCDC_YUV_MODE(1)
  93. #define ATMEL_HLCDC_UYVY_MODE ATMEL_HLCDC_YUV_MODE(2)
  94. #define ATMEL_HLCDC_YVYU_MODE ATMEL_HLCDC_YUV_MODE(3)
  95. #define ATMEL_HLCDC_VYUY_MODE ATMEL_HLCDC_YUV_MODE(4)
  96. #define ATMEL_HLCDC_NV61_MODE ATMEL_HLCDC_YUV_MODE(5)
  97. #define ATMEL_HLCDC_YUV422_MODE ATMEL_HLCDC_YUV_MODE(6)
  98. #define ATMEL_HLCDC_NV21_MODE ATMEL_HLCDC_YUV_MODE(7)
  99. #define ATMEL_HLCDC_YUV420_MODE ATMEL_HLCDC_YUV_MODE(8)
  100. #define ATMEL_HLCDC_LAYER_POS(x, y) ((x) | ((y) << 16))
  101. #define ATMEL_HLCDC_LAYER_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))
  102. #define ATMEL_HLCDC_LAYER_CRKEY BIT(0)
  103. #define ATMEL_HLCDC_LAYER_INV BIT(1)
  104. #define ATMEL_HLCDC_LAYER_ITER2BL BIT(2)
  105. #define ATMEL_HLCDC_LAYER_ITER BIT(3)
  106. #define ATMEL_HLCDC_LAYER_REVALPHA BIT(4)
  107. #define ATMEL_HLCDC_LAYER_GAEN BIT(5)
  108. #define ATMEL_HLCDC_LAYER_LAEN BIT(6)
  109. #define ATMEL_HLCDC_LAYER_OVR BIT(7)
  110. #define ATMEL_HLCDC_LAYER_DMA BIT(8)
  111. #define ATMEL_HLCDC_LAYER_REP BIT(9)
  112. #define ATMEL_HLCDC_LAYER_DSTKEY BIT(10)
  113. #define ATMEL_HLCDC_LAYER_DISCEN BIT(11)
  114. #define ATMEL_HLCDC_LAYER_GA_SHIFT 16
  115. #define ATMEL_HLCDC_LAYER_GA_MASK \
  116. GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)
  117. #define ATMEL_HLCDC_LAYER_GA(x) \
  118. ((x) << ATMEL_HLCDC_LAYER_GA_SHIFT)
  119. #define ATMEL_HLCDC_LAYER_DISC_POS(x, y) ((x) | ((y) << 16))
  120. #define ATMEL_HLCDC_LAYER_DISC_SIZE(w, h) (((w) - 1) | (((h) - 1) << 16))
  121. #define ATMEL_HLCDC_LAYER_SCALER_FACTORS(x, y) ((x) | ((y) << 16))
  122. #define ATMEL_HLCDC_LAYER_SCALER_ENABLE BIT(31)
  123. #define ATMEL_HLCDC_LAYER_MAX_PLANES 3
  124. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)
  125. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)
  126. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)
  127. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)
  128. #define ATMEL_HLCDC_MAX_LAYERS 6
  129. /**
  130. * Atmel HLCDC Layer registers layout structure
  131. *
  132. * Each HLCDC layer has its own register organization and a given register
  133. * can be placed differently on 2 different layers depending on its
  134. * capabilities.
  135. * This structure stores common registers layout for a given layer and is
  136. * used by HLCDC layer code to choose the appropriate register to write to
  137. * or to read from.
  138. *
  139. * For all fields, a value of zero means "unsupported".
  140. *
  141. * See Atmel's datasheet for a detailled description of these registers.
  142. *
  143. * @xstride: xstride registers
  144. * @pstride: pstride registers
  145. * @pos: position register
  146. * @size: displayed size register
  147. * @memsize: memory size register
  148. * @default_color: default color register
  149. * @chroma_key: chroma key register
  150. * @chroma_key_mask: chroma key mask register
  151. * @general_config: general layer config register
  152. * @sacler_config: scaler factors register
  153. * @phicoeffs: X/Y PHI coefficient registers
  154. * @disc_pos: discard area position register
  155. * @disc_size: discard area size register
  156. * @csc: color space conversion register
  157. */
  158. struct atmel_hlcdc_layer_cfg_layout {
  159. int xstride[ATMEL_HLCDC_LAYER_MAX_PLANES];
  160. int pstride[ATMEL_HLCDC_LAYER_MAX_PLANES];
  161. int pos;
  162. int size;
  163. int memsize;
  164. int default_color;
  165. int chroma_key;
  166. int chroma_key_mask;
  167. int general_config;
  168. int scaler_config;
  169. struct {
  170. int x;
  171. int y;
  172. } phicoeffs;
  173. int disc_pos;
  174. int disc_size;
  175. int csc;
  176. };
  177. /**
  178. * Atmel HLCDC DMA descriptor structure
  179. *
  180. * This structure is used by the HLCDC DMA engine to schedule a DMA transfer.
  181. *
  182. * The structure fields must remain in this specific order, because they're
  183. * used by the HLCDC DMA engine, which expect them in this order.
  184. * HLCDC DMA descriptors must be aligned on 64 bits.
  185. *
  186. * @addr: buffer DMA address
  187. * @ctrl: DMA transfer options
  188. * @next: next DMA descriptor to fetch
  189. * @self: descriptor DMA address
  190. */
  191. struct atmel_hlcdc_dma_channel_dscr {
  192. dma_addr_t addr;
  193. u32 ctrl;
  194. dma_addr_t next;
  195. dma_addr_t self;
  196. } __aligned(sizeof(u64));
  197. /**
  198. * Atmel HLCDC layer types
  199. */
  200. enum atmel_hlcdc_layer_type {
  201. ATMEL_HLCDC_NO_LAYER,
  202. ATMEL_HLCDC_BASE_LAYER,
  203. ATMEL_HLCDC_OVERLAY_LAYER,
  204. ATMEL_HLCDC_CURSOR_LAYER,
  205. ATMEL_HLCDC_PP_LAYER,
  206. };
  207. /**
  208. * Atmel HLCDC Supported formats structure
  209. *
  210. * This structure list all the formats supported by a given layer.
  211. *
  212. * @nformats: number of supported formats
  213. * @formats: supported formats
  214. */
  215. struct atmel_hlcdc_formats {
  216. int nformats;
  217. u32 *formats;
  218. };
  219. /**
  220. * Atmel HLCDC Layer description structure
  221. *
  222. * This structure describes the capabilities provided by a given layer.
  223. *
  224. * @name: layer name
  225. * @type: layer type
  226. * @id: layer id
  227. * @regs_offset: offset of the layer registers from the HLCDC registers base
  228. * @cfgs_offset: CFGX registers offset from the layer registers base
  229. * @formats: supported formats
  230. * @layout: config registers layout
  231. * @max_width: maximum width supported by this layer (0 means unlimited)
  232. * @max_height: maximum height supported by this layer (0 means unlimited)
  233. */
  234. struct atmel_hlcdc_layer_desc {
  235. const char *name;
  236. enum atmel_hlcdc_layer_type type;
  237. int id;
  238. int regs_offset;
  239. int cfgs_offset;
  240. struct atmel_hlcdc_formats *formats;
  241. struct atmel_hlcdc_layer_cfg_layout layout;
  242. int max_width;
  243. int max_height;
  244. };
  245. /**
  246. * Atmel HLCDC Layer.
  247. *
  248. * A layer can be a DRM plane of a post processing layer used to render
  249. * HLCDC composition into memory.
  250. *
  251. * @desc: layer description
  252. * @regmap: pointer to the HLCDC regmap
  253. */
  254. struct atmel_hlcdc_layer {
  255. const struct atmel_hlcdc_layer_desc *desc;
  256. struct regmap *regmap;
  257. };
  258. /**
  259. * Atmel HLCDC Plane.
  260. *
  261. * @base: base DRM plane structure
  262. * @layer: HLCDC layer structure
  263. * @properties: pointer to the property definitions structure
  264. */
  265. struct atmel_hlcdc_plane {
  266. struct drm_plane base;
  267. struct atmel_hlcdc_layer layer;
  268. struct atmel_hlcdc_plane_properties *properties;
  269. };
  270. static inline struct atmel_hlcdc_plane *
  271. drm_plane_to_atmel_hlcdc_plane(struct drm_plane *p)
  272. {
  273. return container_of(p, struct atmel_hlcdc_plane, base);
  274. }
  275. static inline struct atmel_hlcdc_plane *
  276. atmel_hlcdc_layer_to_plane(struct atmel_hlcdc_layer *layer)
  277. {
  278. return container_of(layer, struct atmel_hlcdc_plane, layer);
  279. }
  280. /**
  281. * Atmel HLCDC Display Controller description structure.
  282. *
  283. * This structure describes the HLCDC IP capabilities and depends on the
  284. * HLCDC IP version (or Atmel SoC family).
  285. *
  286. * @min_width: minimum width supported by the Display Controller
  287. * @min_height: minimum height supported by the Display Controller
  288. * @max_width: maximum width supported by the Display Controller
  289. * @max_height: maximum height supported by the Display Controller
  290. * @max_spw: maximum vertical/horizontal pulse width
  291. * @max_vpw: maximum vertical back/front porch width
  292. * @max_hpw: maximum horizontal back/front porch width
  293. * @conflicting_output_formats: true if RGBXXX output formats conflict with
  294. * each other.
  295. * @layers: a layer description table describing available layers
  296. * @nlayers: layer description table size
  297. */
  298. struct atmel_hlcdc_dc_desc {
  299. int min_width;
  300. int min_height;
  301. int max_width;
  302. int max_height;
  303. int max_spw;
  304. int max_vpw;
  305. int max_hpw;
  306. bool conflicting_output_formats;
  307. const struct atmel_hlcdc_layer_desc *layers;
  308. int nlayers;
  309. };
  310. /**
  311. * Atmel HLCDC Plane properties.
  312. *
  313. * This structure stores plane property definitions.
  314. *
  315. * @alpha: alpha blending (or transparency) property
  316. * @rotation: rotation property
  317. */
  318. struct atmel_hlcdc_plane_properties {
  319. struct drm_property *alpha;
  320. };
  321. /**
  322. * Atmel HLCDC Display Controller.
  323. *
  324. * @desc: HLCDC Display Controller description
  325. * @dscrpool: DMA coherent pool used to allocate DMA descriptors
  326. * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
  327. * @fbdev: framebuffer device attached to the Display Controller
  328. * @crtc: CRTC provided by the display controller
  329. * @planes: instantiated planes
  330. * @layers: active HLCDC layers
  331. * @wq: display controller workqueue
  332. * @suspend: used to store the HLCDC state when entering suspend
  333. * @commit: used for async commit handling
  334. */
  335. struct atmel_hlcdc_dc {
  336. const struct atmel_hlcdc_dc_desc *desc;
  337. struct dma_pool *dscrpool;
  338. struct atmel_hlcdc *hlcdc;
  339. struct drm_fbdev_cma *fbdev;
  340. struct drm_crtc *crtc;
  341. struct atmel_hlcdc_layer *layers[ATMEL_HLCDC_MAX_LAYERS];
  342. struct workqueue_struct *wq;
  343. struct {
  344. u32 imr;
  345. struct drm_atomic_state *state;
  346. } suspend;
  347. struct {
  348. wait_queue_head_t wait;
  349. bool pending;
  350. } commit;
  351. };
  352. extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_formats;
  353. extern struct atmel_hlcdc_formats atmel_hlcdc_plane_rgb_and_yuv_formats;
  354. static inline void atmel_hlcdc_layer_write_reg(struct atmel_hlcdc_layer *layer,
  355. unsigned int reg, u32 val)
  356. {
  357. regmap_write(layer->regmap, layer->desc->regs_offset + reg, val);
  358. }
  359. static inline u32 atmel_hlcdc_layer_read_reg(struct atmel_hlcdc_layer *layer,
  360. unsigned int reg)
  361. {
  362. u32 val;
  363. regmap_read(layer->regmap, layer->desc->regs_offset + reg, &val);
  364. return val;
  365. }
  366. static inline void atmel_hlcdc_layer_write_cfg(struct atmel_hlcdc_layer *layer,
  367. unsigned int cfgid, u32 val)
  368. {
  369. atmel_hlcdc_layer_write_reg(layer,
  370. layer->desc->cfgs_offset +
  371. (cfgid * sizeof(u32)), val);
  372. }
  373. static inline u32 atmel_hlcdc_layer_read_cfg(struct atmel_hlcdc_layer *layer,
  374. unsigned int cfgid)
  375. {
  376. return atmel_hlcdc_layer_read_reg(layer,
  377. layer->desc->cfgs_offset +
  378. (cfgid * sizeof(u32)));
  379. }
  380. static inline void atmel_hlcdc_layer_init(struct atmel_hlcdc_layer *layer,
  381. const struct atmel_hlcdc_layer_desc *desc,
  382. struct regmap *regmap)
  383. {
  384. layer->desc = desc;
  385. layer->regmap = regmap;
  386. }
  387. int atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc,
  388. struct drm_display_mode *mode);
  389. int atmel_hlcdc_create_planes(struct drm_device *dev);
  390. void atmel_hlcdc_plane_irq(struct atmel_hlcdc_plane *plane);
  391. int atmel_hlcdc_plane_prepare_disc_area(struct drm_crtc_state *c_state);
  392. int atmel_hlcdc_plane_prepare_ahb_routing(struct drm_crtc_state *c_state);
  393. void atmel_hlcdc_crtc_irq(struct drm_crtc *c);
  394. int atmel_hlcdc_crtc_create(struct drm_device *dev);
  395. int atmel_hlcdc_create_outputs(struct drm_device *dev);
  396. #endif /* DRM_ATMEL_HLCDC_H */