atmel_hlcdc_layer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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_GA(x) ((x) << ATMEL_HLCDC_LAYER_GA_SHIFT)
  112. #define ATMEL_HLCDC_LAYER_CSC_CFG(p, o) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.csc + o)
  113. #define ATMEL_HLCDC_LAYER_DISC_POS_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_pos)
  114. #define ATMEL_HLCDC_LAYER_DISC_SIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_size)
  115. #define ATMEL_HLCDC_MAX_PLANES 3
  116. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)
  117. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)
  118. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)
  119. #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)
  120. /**
  121. * Atmel HLCDC Layer registers layout structure
  122. *
  123. * Each HLCDC layer has its own register organization and a given register
  124. * can be placed differently on 2 different layers depending on its
  125. * capabilities.
  126. * This structure stores common registers layout for a given layer and is
  127. * used by HLCDC layer code to choose the appropriate register to write to
  128. * or to read from.
  129. *
  130. * For all fields, a value of zero means "unsupported".
  131. *
  132. * See Atmel's datasheet for a detailled description of these registers.
  133. *
  134. * @xstride: xstride registers
  135. * @pstride: pstride registers
  136. * @pos: position register
  137. * @size: displayed size register
  138. * @memsize: memory size register
  139. * @default_color: default color register
  140. * @chroma_key: chroma key register
  141. * @chroma_key_mask: chroma key mask register
  142. * @general_config: general layer config register
  143. * @disc_pos: discard area position register
  144. * @disc_size: discard area size register
  145. * @csc: color space conversion register
  146. */
  147. struct atmel_hlcdc_layer_cfg_layout {
  148. int xstride[ATMEL_HLCDC_MAX_PLANES];
  149. int pstride[ATMEL_HLCDC_MAX_PLANES];
  150. int pos;
  151. int size;
  152. int memsize;
  153. int default_color;
  154. int chroma_key;
  155. int chroma_key_mask;
  156. int general_config;
  157. int disc_pos;
  158. int disc_size;
  159. int csc;
  160. };
  161. /**
  162. * Atmel HLCDC framebuffer flip structure
  163. *
  164. * This structure is allocated when someone asked for a layer update (most
  165. * likely a DRM plane update, either primary, overlay or cursor plane) and
  166. * released when the layer do not need to reference the framebuffer object
  167. * anymore (i.e. the layer was disabled or updated).
  168. *
  169. * @dscrs: DMA descriptors
  170. * @fb: the referenced framebuffer object
  171. * @ngems: number of GEM objects referenced by the fb element
  172. * @status: fb flip operation status
  173. */
  174. struct atmel_hlcdc_layer_fb_flip {
  175. struct atmel_hlcdc_dma_channel_dscr *dscrs[ATMEL_HLCDC_MAX_PLANES];
  176. struct drm_flip_task *task;
  177. struct drm_framebuffer *fb;
  178. int ngems;
  179. u32 status;
  180. };
  181. /**
  182. * Atmel HLCDC DMA descriptor structure
  183. *
  184. * This structure is used by the HLCDC DMA engine to schedule a DMA transfer.
  185. *
  186. * The structure fields must remain in this specific order, because they're
  187. * used by the HLCDC DMA engine, which expect them in this order.
  188. * HLCDC DMA descriptors must be aligned on 64 bits.
  189. *
  190. * @addr: buffer DMA address
  191. * @ctrl: DMA transfer options
  192. * @next: next DMA descriptor to fetch
  193. * @gem_flip: the attached gem_flip operation
  194. */
  195. struct atmel_hlcdc_dma_channel_dscr {
  196. dma_addr_t addr;
  197. u32 ctrl;
  198. dma_addr_t next;
  199. u32 status;
  200. } __aligned(sizeof(u64));
  201. /**
  202. * Atmel HLCDC layer types
  203. */
  204. enum atmel_hlcdc_layer_type {
  205. ATMEL_HLCDC_BASE_LAYER,
  206. ATMEL_HLCDC_OVERLAY_LAYER,
  207. ATMEL_HLCDC_CURSOR_LAYER,
  208. ATMEL_HLCDC_PP_LAYER,
  209. };
  210. /**
  211. * Atmel HLCDC Supported formats structure
  212. *
  213. * This structure list all the formats supported by a given layer.
  214. *
  215. * @nformats: number of supported formats
  216. * @formats: supported formats
  217. */
  218. struct atmel_hlcdc_formats {
  219. int nformats;
  220. uint32_t *formats;
  221. };
  222. /**
  223. * Atmel HLCDC Layer description structure
  224. *
  225. * This structure describe the capabilities provided by a given layer.
  226. *
  227. * @name: layer name
  228. * @type: layer type
  229. * @id: layer id
  230. * @regs_offset: offset of the layer registers from the HLCDC registers base
  231. * @nconfigs: number of config registers provided by this layer
  232. * @formats: supported formats
  233. * @layout: config registers layout
  234. * @max_width: maximum width supported by this layer (0 means unlimited)
  235. * @max_height: maximum height supported by this layer (0 means unlimited)
  236. */
  237. struct atmel_hlcdc_layer_desc {
  238. const char *name;
  239. enum atmel_hlcdc_layer_type type;
  240. int id;
  241. int regs_offset;
  242. int nconfigs;
  243. struct atmel_hlcdc_formats *formats;
  244. struct atmel_hlcdc_layer_cfg_layout layout;
  245. int max_width;
  246. int max_height;
  247. };
  248. /**
  249. * Atmel HLCDC Layer Update Slot structure
  250. *
  251. * This structure stores layer update requests to be applied on next frame.
  252. * This is the base structure behind the atomic layer update infrastructure.
  253. *
  254. * Atomic layer update provides a way to update all layer's parameters
  255. * simultaneously. This is needed to avoid incompatible sequential updates
  256. * like this one:
  257. * 1) update layer format from RGB888 (1 plane/buffer) to YUV422
  258. * (2 planes/buffers)
  259. * 2) the format update is applied but the DMA channel for the second
  260. * plane/buffer is not enabled
  261. * 3) enable the DMA channel for the second plane
  262. *
  263. * @fb_flip: fb_flip object
  264. * @updated_configs: bitmask used to record modified configs
  265. * @configs: new config values
  266. */
  267. struct atmel_hlcdc_layer_update_slot {
  268. struct atmel_hlcdc_layer_fb_flip *fb_flip;
  269. unsigned long *updated_configs;
  270. u32 *configs;
  271. };
  272. /**
  273. * Atmel HLCDC Layer Update structure
  274. *
  275. * This structure provides a way to queue layer update requests.
  276. *
  277. * At a given time there is at most:
  278. * - one pending update request, which means the update request has been
  279. * committed (or validated) and is waiting for the DMA channel(s) to be
  280. * available
  281. * - one request being prepared, which means someone started a layer update
  282. * but has not committed it yet. There cannot be more than one started
  283. * request, because the update lock is taken when starting a layer update
  284. * and release when committing or rolling back the request.
  285. *
  286. * @slots: update slots. One is used for pending request and the other one
  287. * for started update request
  288. * @pending: the pending slot index or -1 if no request is pending
  289. * @next: the started update slot index or -1 no update has been started
  290. */
  291. struct atmel_hlcdc_layer_update {
  292. struct atmel_hlcdc_layer_update_slot slots[2];
  293. int pending;
  294. int next;
  295. };
  296. enum atmel_hlcdc_layer_dma_channel_status {
  297. ATMEL_HLCDC_LAYER_DISABLED,
  298. ATMEL_HLCDC_LAYER_ENABLED,
  299. ATMEL_HLCDC_LAYER_DISABLING,
  300. };
  301. /**
  302. * Atmel HLCDC Layer DMA channel structure
  303. *
  304. * This structure stores information on the DMA channel associated to a
  305. * given layer.
  306. *
  307. * @status: DMA channel status
  308. * @cur: current framebuffer
  309. * @queue: next framebuffer
  310. * @dscrs: allocated DMA descriptors
  311. */
  312. struct atmel_hlcdc_layer_dma_channel {
  313. enum atmel_hlcdc_layer_dma_channel_status status;
  314. struct atmel_hlcdc_layer_fb_flip *cur;
  315. struct atmel_hlcdc_layer_fb_flip *queue;
  316. struct atmel_hlcdc_dma_channel_dscr *dscrs;
  317. };
  318. /**
  319. * Atmel HLCDC Layer structure
  320. *
  321. * This structure stores information on the layer instance.
  322. *
  323. * @desc: layer description
  324. * @max_planes: maximum planes/buffers that can be associated with this layer.
  325. * This depends on the supported formats.
  326. * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
  327. * @dma: dma channel
  328. * @gc: fb flip garbage collector
  329. * @update: update handler
  330. * @lock: layer lock
  331. */
  332. struct atmel_hlcdc_layer {
  333. const struct atmel_hlcdc_layer_desc *desc;
  334. int max_planes;
  335. struct atmel_hlcdc *hlcdc;
  336. struct workqueue_struct *wq;
  337. struct drm_flip_work gc;
  338. struct atmel_hlcdc_layer_dma_channel dma;
  339. struct atmel_hlcdc_layer_update update;
  340. spinlock_t lock;
  341. };
  342. void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer *layer);
  343. int atmel_hlcdc_layer_init(struct drm_device *dev,
  344. struct atmel_hlcdc_layer *layer,
  345. const struct atmel_hlcdc_layer_desc *desc);
  346. void atmel_hlcdc_layer_cleanup(struct drm_device *dev,
  347. struct atmel_hlcdc_layer *layer);
  348. void atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer);
  349. int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer);
  350. void atmel_hlcdc_layer_update_cfg(struct atmel_hlcdc_layer *layer, int cfg,
  351. u32 mask, u32 val);
  352. void atmel_hlcdc_layer_update_set_fb(struct atmel_hlcdc_layer *layer,
  353. struct drm_framebuffer *fb,
  354. unsigned int *offsets);
  355. void atmel_hlcdc_layer_update_set_finished(struct atmel_hlcdc_layer *layer,
  356. void (*finished)(void *data),
  357. void *finished_data);
  358. void atmel_hlcdc_layer_update_rollback(struct atmel_hlcdc_layer *layer);
  359. void atmel_hlcdc_layer_update_commit(struct atmel_hlcdc_layer *layer);
  360. #endif /* DRM_ATMEL_HLCDC_LAYER_H */