atmel_hlcdc_layer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * Copyright (C) 2014 Free Electrons
  3. * Copyright (C) 2014 Atmel
  4. *
  5. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef DRM_ATMEL_HLCDC_LAYER_H
  20. #define DRM_ATMEL_HLCDC_LAYER_H
  21. #include <linux/mfd/atmel-hlcdc.h>
  22. #include <drm/drm_crtc.h>
  23. #include <drm/drm_flip_work.h>
  24. #include <drm/drmP.h>
  25. #define ATMEL_HLCDC_LAYER_CHER 0x0
  26. #define ATMEL_HLCDC_LAYER_CHDR 0x4
  27. #define ATMEL_HLCDC_LAYER_CHSR 0x8
  28. #define ATMEL_HLCDC_LAYER_DMA_CHAN BIT(0)
  29. #define ATMEL_HLCDC_LAYER_UPDATE BIT(1)
  30. #define ATMEL_HLCDC_LAYER_A2Q BIT(2)
  31. #define ATMEL_HLCDC_LAYER_RST BIT(8)
  32. #define ATMEL_HLCDC_LAYER_IER 0xc
  33. #define ATMEL_HLCDC_LAYER_IDR 0x10
  34. #define ATMEL_HLCDC_LAYER_IMR 0x14
  35. #define ATMEL_HLCDC_LAYER_ISR 0x18
  36. #define ATMEL_HLCDC_LAYER_DFETCH BIT(0)
  37. #define ATMEL_HLCDC_LAYER_LFETCH BIT(1)
  38. #define ATMEL_HLCDC_LAYER_DMA_IRQ BIT(2)
  39. #define ATMEL_HLCDC_LAYER_DSCR_IRQ BIT(3)
  40. #define ATMEL_HLCDC_LAYER_ADD_IRQ BIT(4)
  41. #define ATMEL_HLCDC_LAYER_DONE_IRQ BIT(5)
  42. #define ATMEL_HLCDC_LAYER_OVR_IRQ BIT(6)
  43. #define ATMEL_HLCDC_LAYER_PLANE_HEAD(n) (((n) * 0x10) + 0x1c)
  44. #define ATMEL_HLCDC_LAYER_PLANE_ADDR(n) (((n) * 0x10) + 0x20)
  45. #define ATMEL_HLCDC_LAYER_PLANE_CTRL(n) (((n) * 0x10) + 0x24)
  46. #define ATMEL_HLCDC_LAYER_PLANE_NEXT(n) (((n) * 0x10) + 0x28)
  47. #define ATMEL_HLCDC_LAYER_CFG(p, c) (((c) * 4) + ((p)->max_planes * 0x10) + 0x1c)
  48. #define ATMEL_HLCDC_LAYER_DMA_CFG_ID 0
  49. #define ATMEL_HLCDC_LAYER_DMA_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, ATMEL_HLCDC_LAYER_DMA_CFG_ID)
  50. #define ATMEL_HLCDC_LAYER_DMA_SIF BIT(0)
  51. #define ATMEL_HLCDC_LAYER_DMA_BLEN_MASK GENMASK(5, 4)
  52. #define ATMEL_HLCDC_LAYER_DMA_BLEN_SINGLE (0 << 4)
  53. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR4 (1 << 4)
  54. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR8 (2 << 4)
  55. #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 (3 << 4)
  56. #define ATMEL_HLCDC_LAYER_DMA_DLBO BIT(8)
  57. #define ATMEL_HLCDC_LAYER_DMA_ROTDIS BIT(12)
  58. #define ATMEL_HLCDC_LAYER_DMA_LOCKDIS BIT(13)
  59. #define ATMEL_HLCDC_LAYER_FORMAT_CFG_ID 1
  60. #define ATMEL_HLCDC_LAYER_FORMAT_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, ATMEL_HLCDC_LAYER_FORMAT_CFG_ID)
  61. #define ATMEL_HLCDC_LAYER_RGB (0 << 0)
  62. #define ATMEL_HLCDC_LAYER_CLUT (1 << 0)
  63. #define ATMEL_HLCDC_LAYER_YUV (2 << 0)
  64. #define ATMEL_HLCDC_RGB_MODE(m) (((m) & 0xf) << 4)
  65. #define ATMEL_HLCDC_CLUT_MODE(m) (((m) & 0x3) << 8)
  66. #define ATMEL_HLCDC_YUV_MODE(m) (((m) & 0xf) << 12)
  67. #define ATMEL_HLCDC_YUV422ROT BIT(16)
  68. #define ATMEL_HLCDC_YUV422SWP BIT(17)
  69. #define ATMEL_HLCDC_DSCALEOPT BIT(20)
  70. #define ATMEL_HLCDC_XRGB4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(0))
  71. #define ATMEL_HLCDC_ARGB4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(1))
  72. #define ATMEL_HLCDC_RGBA4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(2))
  73. #define ATMEL_HLCDC_RGB565_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(3))
  74. #define ATMEL_HLCDC_ARGB1555_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(4))
  75. #define ATMEL_HLCDC_XRGB8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(9))
  76. #define ATMEL_HLCDC_RGB888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(10))
  77. #define ATMEL_HLCDC_ARGB8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(12))
  78. #define ATMEL_HLCDC_RGBA8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(13))
  79. #define ATMEL_HLCDC_AYUV_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(0))
  80. #define ATMEL_HLCDC_YUYV_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(1))
  81. #define ATMEL_HLCDC_UYVY_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(2))
  82. #define ATMEL_HLCDC_YVYU_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(3))
  83. #define ATMEL_HLCDC_VYUY_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(4))
  84. #define ATMEL_HLCDC_NV61_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(5))
  85. #define ATMEL_HLCDC_YUV422_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(6))
  86. #define ATMEL_HLCDC_NV21_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(7))
  87. #define ATMEL_HLCDC_YUV420_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(8))
  88. #define ATMEL_HLCDC_LAYER_POS_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.pos)
  89. #define ATMEL_HLCDC_LAYER_SIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.size)
  90. #define ATMEL_HLCDC_LAYER_MEMSIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.memsize)
  91. #define ATMEL_HLCDC_LAYER_XSTRIDE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.xstride)
  92. #define ATMEL_HLCDC_LAYER_PSTRIDE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.pstride)
  93. #define ATMEL_HLCDC_LAYER_DFLTCOLOR_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.default_color)
  94. #define ATMEL_HLCDC_LAYER_CRKEY_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.chroma_key)
  95. #define ATMEL_HLCDC_LAYER_CRKEY_MASK_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.chroma_key_mask)
  96. #define ATMEL_HLCDC_LAYER_GENERAL_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.general_config)
  97. #define ATMEL_HLCDC_LAYER_CRKEY BIT(0)
  98. #define ATMEL_HLCDC_LAYER_INV BIT(1)
  99. #define ATMEL_HLCDC_LAYER_ITER2BL BIT(2)
  100. #define ATMEL_HLCDC_LAYER_ITER BIT(3)
  101. #define ATMEL_HLCDC_LAYER_REVALPHA BIT(4)
  102. #define ATMEL_HLCDC_LAYER_GAEN BIT(5)
  103. #define ATMEL_HLCDC_LAYER_LAEN BIT(6)
  104. #define ATMEL_HLCDC_LAYER_OVR BIT(7)
  105. #define ATMEL_HLCDC_LAYER_DMA BIT(8)
  106. #define ATMEL_HLCDC_LAYER_REP BIT(9)
  107. #define ATMEL_HLCDC_LAYER_DSTKEY BIT(10)
  108. #define ATMEL_HLCDC_LAYER_DISCEN BIT(11)
  109. #define ATMEL_HLCDC_LAYER_GA_SHIFT 16
  110. #define ATMEL_HLCDC_LAYER_GA_MASK GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)
  111. #define ATMEL_HLCDC_LAYER_CSC_CFG(p, o) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.csc + o)
  112. #define ATMEL_HLCDC_LAYER_DISC_POS_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_pos)
  113. #define ATMEL_HLCDC_LAYER_DISC_SIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_size)
  114. #define ATMEL_HLCDC_MAX_PLANES 3
  115. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)
  116. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)
  117. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)
  118. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)
  119. /**
  120. * Atmel HLCDC Layer registers layout structure
  121. *
  122. * Each HLCDC layer has its own register organization and a given register
  123. * can be placed differently on 2 different layers depending on its
  124. * capabilities.
  125. * This structure stores common registers layout for a given layer and is
  126. * used by HLCDC layer code to choose the appropriate register to write to
  127. * or to read from.
  128. *
  129. * For all fields, a value of zero means "unsupported".
  130. *
  131. * See Atmel's datasheet for a detailled description of these registers.
  132. *
  133. * @xstride: xstride registers
  134. * @pstride: pstride registers
  135. * @pos: position register
  136. * @size: displayed size register
  137. * @memsize: memory size register
  138. * @default_color: default color register
  139. * @chroma_key: chroma key register
  140. * @chroma_key_mask: chroma key mask register
  141. * @general_config: general layer config register
  142. * @disc_pos: discard area position register
  143. * @disc_size: discard area size register
  144. * @csc: color space conversion register
  145. */
  146. struct atmel_hlcdc_layer_cfg_layout {
  147. int xstride[ATMEL_HLCDC_MAX_PLANES];
  148. int pstride[ATMEL_HLCDC_MAX_PLANES];
  149. int pos;
  150. int size;
  151. int memsize;
  152. int default_color;
  153. int chroma_key;
  154. int chroma_key_mask;
  155. int general_config;
  156. int disc_pos;
  157. int disc_size;
  158. int csc;
  159. };
  160. /**
  161. * Atmel HLCDC framebuffer flip structure
  162. *
  163. * This structure is allocated when someone asked for a layer update (most
  164. * likely a DRM plane update, either primary, overlay or cursor plane) and
  165. * released when the layer do not need to reference the framebuffer object
  166. * anymore (i.e. the layer was disabled or updated).
  167. *
  168. * @dscrs: DMA descriptors
  169. * @fb: the referenced framebuffer object
  170. * @ngems: number of GEM objects referenced by the fb element
  171. * @status: fb flip operation status
  172. */
  173. struct atmel_hlcdc_layer_fb_flip {
  174. struct atmel_hlcdc_dma_channel_dscr *dscrs[ATMEL_HLCDC_MAX_PLANES];
  175. struct drm_flip_task *task;
  176. struct drm_framebuffer *fb;
  177. int ngems;
  178. u32 status;
  179. };
  180. /**
  181. * Atmel HLCDC DMA descriptor structure
  182. *
  183. * This structure is used by the HLCDC DMA engine to schedule a DMA transfer.
  184. *
  185. * The structure fields must remain in this specific order, because they're
  186. * used by the HLCDC DMA engine, which expect them in this order.
  187. * HLCDC DMA descriptors must be aligned on 64 bits.
  188. *
  189. * @addr: buffer DMA address
  190. * @ctrl: DMA transfer options
  191. * @next: next DMA descriptor to fetch
  192. * @gem_flip: the attached gem_flip operation
  193. */
  194. struct atmel_hlcdc_dma_channel_dscr {
  195. dma_addr_t addr;
  196. u32 ctrl;
  197. dma_addr_t next;
  198. u32 status;
  199. } __aligned(sizeof(u64));
  200. /**
  201. * Atmel HLCDC layer types
  202. */
  203. enum atmel_hlcdc_layer_type {
  204. ATMEL_HLCDC_BASE_LAYER,
  205. ATMEL_HLCDC_OVERLAY_LAYER,
  206. ATMEL_HLCDC_CURSOR_LAYER,
  207. ATMEL_HLCDC_PP_LAYER,
  208. };
  209. /**
  210. * Atmel HLCDC Supported formats structure
  211. *
  212. * This structure list all the formats supported by a given layer.
  213. *
  214. * @nformats: number of supported formats
  215. * @formats: supported formats
  216. */
  217. struct atmel_hlcdc_formats {
  218. int nformats;
  219. uint32_t *formats;
  220. };
  221. /**
  222. * Atmel HLCDC Layer description structure
  223. *
  224. * This structure describe the capabilities provided by a given layer.
  225. *
  226. * @name: layer name
  227. * @type: layer type
  228. * @id: layer id
  229. * @regs_offset: offset of the layer registers from the HLCDC registers base
  230. * @nconfigs: number of config registers provided by this layer
  231. * @formats: supported formats
  232. * @layout: config registers layout
  233. * @max_width: maximum width supported by this layer (0 means unlimited)
  234. * @max_height: maximum height supported by this layer (0 means unlimited)
  235. */
  236. struct atmel_hlcdc_layer_desc {
  237. const char *name;
  238. enum atmel_hlcdc_layer_type type;
  239. int id;
  240. int regs_offset;
  241. int nconfigs;
  242. struct atmel_hlcdc_formats *formats;
  243. struct atmel_hlcdc_layer_cfg_layout layout;
  244. int max_width;
  245. int max_height;
  246. };
  247. /**
  248. * Atmel HLCDC Layer Update Slot structure
  249. *
  250. * This structure stores layer update requests to be applied on next frame.
  251. * This is the base structure behind the atomic layer update infrastructure.
  252. *
  253. * Atomic layer update provides a way to update all layer's parameters
  254. * simultaneously. This is needed to avoid incompatible sequential updates
  255. * like this one:
  256. * 1) update layer format from RGB888 (1 plane/buffer) to YUV422
  257. * (2 planes/buffers)
  258. * 2) the format update is applied but the DMA channel for the second
  259. * plane/buffer is not enabled
  260. * 3) enable the DMA channel for the second plane
  261. *
  262. * @fb_flip: fb_flip object
  263. * @updated_configs: bitmask used to record modified configs
  264. * @configs: new config values
  265. */
  266. struct atmel_hlcdc_layer_update_slot {
  267. struct atmel_hlcdc_layer_fb_flip *fb_flip;
  268. unsigned long *updated_configs;
  269. u32 *configs;
  270. };
  271. /**
  272. * Atmel HLCDC Layer Update structure
  273. *
  274. * This structure provides a way to queue layer update requests.
  275. *
  276. * At a given time there is at most:
  277. * - one pending update request, which means the update request has been
  278. * committed (or validated) and is waiting for the DMA channel(s) to be
  279. * available
  280. * - one request being prepared, which means someone started a layer update
  281. * but has not committed it yet. There cannot be more than one started
  282. * request, because the update lock is taken when starting a layer update
  283. * and release when committing or rolling back the request.
  284. *
  285. * @slots: update slots. One is used for pending request and the other one
  286. * for started update request
  287. * @pending: the pending slot index or -1 if no request is pending
  288. * @next: the started update slot index or -1 no update has been started
  289. */
  290. struct atmel_hlcdc_layer_update {
  291. struct atmel_hlcdc_layer_update_slot slots[2];
  292. int pending;
  293. int next;
  294. };
  295. enum atmel_hlcdc_layer_dma_channel_status {
  296. ATMEL_HLCDC_LAYER_DISABLED,
  297. ATMEL_HLCDC_LAYER_ENABLED,
  298. ATMEL_HLCDC_LAYER_DISABLING,
  299. };
  300. /**
  301. * Atmel HLCDC Layer DMA channel structure
  302. *
  303. * This structure stores information on the DMA channel associated to a
  304. * given layer.
  305. *
  306. * @status: DMA channel status
  307. * @cur: current framebuffer
  308. * @queue: next framebuffer
  309. * @dscrs: allocated DMA descriptors
  310. */
  311. struct atmel_hlcdc_layer_dma_channel {
  312. enum atmel_hlcdc_layer_dma_channel_status status;
  313. struct atmel_hlcdc_layer_fb_flip *cur;
  314. struct atmel_hlcdc_layer_fb_flip *queue;
  315. struct atmel_hlcdc_dma_channel_dscr *dscrs;
  316. };
  317. /**
  318. * Atmel HLCDC Layer structure
  319. *
  320. * This structure stores information on the layer instance.
  321. *
  322. * @desc: layer description
  323. * @max_planes: maximum planes/buffers that can be associated with this layer.
  324. * This depends on the supported formats.
  325. * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
  326. * @dma: dma channel
  327. * @gc: fb flip garbage collector
  328. * @update: update handler
  329. * @lock: layer lock
  330. */
  331. struct atmel_hlcdc_layer {
  332. const struct atmel_hlcdc_layer_desc *desc;
  333. int max_planes;
  334. struct atmel_hlcdc *hlcdc;
  335. struct workqueue_struct *wq;
  336. struct drm_flip_work gc;
  337. struct atmel_hlcdc_layer_dma_channel dma;
  338. struct atmel_hlcdc_layer_update update;
  339. spinlock_t lock;
  340. };
  341. void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer *layer);
  342. int atmel_hlcdc_layer_init(struct drm_device *dev,
  343. struct atmel_hlcdc_layer *layer,
  344. const struct atmel_hlcdc_layer_desc *desc);
  345. void atmel_hlcdc_layer_cleanup(struct drm_device *dev,
  346. struct atmel_hlcdc_layer *layer);
  347. int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer);
  348. int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer);
  349. void atmel_hlcdc_layer_update_cfg(struct atmel_hlcdc_layer *layer, int cfg,
  350. u32 mask, u32 val);
  351. void atmel_hlcdc_layer_update_set_fb(struct atmel_hlcdc_layer *layer,
  352. struct drm_framebuffer *fb,
  353. unsigned int *offsets);
  354. void atmel_hlcdc_layer_update_set_finished(struct atmel_hlcdc_layer *layer,
  355. void (*finished)(void *data),
  356. void *finished_data);
  357. void atmel_hlcdc_layer_update_rollback(struct atmel_hlcdc_layer *layer);
  358. void atmel_hlcdc_layer_update_commit(struct atmel_hlcdc_layer *layer);
  359. #endif /* DRM_ATMEL_HLCDC_LAYER_H */