malidp_hw.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
  3. * Author: Liviu Dudau <Liviu.Dudau@arm.com>
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * ARM Mali DP500/DP550/DP650 hardware manipulation routines. This is where
  11. * the difference between various versions of the hardware is being dealt with
  12. * in an attempt to provide to the rest of the driver code a unified view
  13. */
  14. #include <linux/types.h>
  15. #include <linux/io.h>
  16. #include <drm/drmP.h>
  17. #include <video/videomode.h>
  18. #include <video/display_timing.h>
  19. #include "malidp_drv.h"
  20. #include "malidp_hw.h"
  21. static const struct malidp_input_format malidp500_de_formats[] = {
  22. /* fourcc, layers supporting the format, internal id */
  23. { DRM_FORMAT_ARGB2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 0 },
  24. { DRM_FORMAT_ABGR2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 1 },
  25. { DRM_FORMAT_ARGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 2 },
  26. { DRM_FORMAT_ABGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 3 },
  27. { DRM_FORMAT_XRGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 4 },
  28. { DRM_FORMAT_XBGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 5 },
  29. { DRM_FORMAT_RGB888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 6 },
  30. { DRM_FORMAT_BGR888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 7 },
  31. { DRM_FORMAT_RGBA5551, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 8 },
  32. { DRM_FORMAT_ABGR1555, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 9 },
  33. { DRM_FORMAT_RGB565, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 10 },
  34. { DRM_FORMAT_BGR565, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 11 },
  35. { DRM_FORMAT_UYVY, DE_VIDEO1, 12 },
  36. { DRM_FORMAT_YUYV, DE_VIDEO1, 13 },
  37. { DRM_FORMAT_NV12, DE_VIDEO1, 14 },
  38. { DRM_FORMAT_YUV420, DE_VIDEO1, 15 },
  39. };
  40. #define MALIDP_ID(__group, __format) \
  41. ((((__group) & 0x7) << 3) | ((__format) & 0x7))
  42. #define MALIDP_COMMON_FORMATS \
  43. /* fourcc, layers supporting the format, internal id */ \
  44. { DRM_FORMAT_ARGB2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 0) }, \
  45. { DRM_FORMAT_ABGR2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 1) }, \
  46. { DRM_FORMAT_RGBA1010102, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 2) }, \
  47. { DRM_FORMAT_BGRA1010102, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 3) }, \
  48. { DRM_FORMAT_ARGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 0) }, \
  49. { DRM_FORMAT_ABGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 1) }, \
  50. { DRM_FORMAT_RGBA8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 2) }, \
  51. { DRM_FORMAT_BGRA8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 3) }, \
  52. { DRM_FORMAT_XRGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 0) }, \
  53. { DRM_FORMAT_XBGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 1) }, \
  54. { DRM_FORMAT_RGBX8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 2) }, \
  55. { DRM_FORMAT_BGRX8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 3) }, \
  56. { DRM_FORMAT_RGB888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(3, 0) }, \
  57. { DRM_FORMAT_BGR888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(3, 1) }, \
  58. { DRM_FORMAT_RGBA5551, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 0) }, \
  59. { DRM_FORMAT_ABGR1555, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 1) }, \
  60. { DRM_FORMAT_RGB565, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 2) }, \
  61. { DRM_FORMAT_BGR565, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 3) }, \
  62. { DRM_FORMAT_YUYV, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 2) }, \
  63. { DRM_FORMAT_UYVY, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 3) }, \
  64. { DRM_FORMAT_NV12, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 6) }, \
  65. { DRM_FORMAT_YUV420, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 7) }
  66. static const struct malidp_input_format malidp550_de_formats[] = {
  67. MALIDP_COMMON_FORMATS,
  68. };
  69. static const struct malidp_layer malidp500_layers[] = {
  70. { DE_VIDEO1, MALIDP500_DE_LV_BASE, MALIDP500_DE_LV_PTR_BASE },
  71. { DE_GRAPHICS1, MALIDP500_DE_LG1_BASE, MALIDP500_DE_LG1_PTR_BASE },
  72. { DE_GRAPHICS2, MALIDP500_DE_LG2_BASE, MALIDP500_DE_LG2_PTR_BASE },
  73. };
  74. static const struct malidp_layer malidp550_layers[] = {
  75. { DE_VIDEO1, MALIDP550_DE_LV1_BASE, MALIDP550_DE_LV1_PTR_BASE },
  76. { DE_GRAPHICS1, MALIDP550_DE_LG_BASE, MALIDP550_DE_LG_PTR_BASE },
  77. { DE_VIDEO2, MALIDP550_DE_LV2_BASE, MALIDP550_DE_LV2_PTR_BASE },
  78. { DE_SMART, MALIDP550_DE_LS_BASE, MALIDP550_DE_LS_PTR_BASE },
  79. };
  80. #define MALIDP_DE_DEFAULT_PREFETCH_START 5
  81. static int malidp500_query_hw(struct malidp_hw_device *hwdev)
  82. {
  83. u32 conf = malidp_hw_read(hwdev, MALIDP500_CONFIG_ID);
  84. /* bit 4 of the CONFIG_ID register holds the line size multiplier */
  85. u8 ln_size_mult = conf & 0x10 ? 2 : 1;
  86. hwdev->min_line_size = 2;
  87. hwdev->max_line_size = SZ_2K * ln_size_mult;
  88. hwdev->rotation_memory[0] = SZ_1K * 64 * ln_size_mult;
  89. hwdev->rotation_memory[1] = 0; /* no second rotation memory bank */
  90. return 0;
  91. }
  92. static void malidp500_enter_config_mode(struct malidp_hw_device *hwdev)
  93. {
  94. u32 status, count = 100;
  95. malidp_hw_setbits(hwdev, MALIDP500_DC_CONFIG_REQ, MALIDP500_DC_CONTROL);
  96. while (count) {
  97. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  98. if ((status & MALIDP500_DC_CONFIG_REQ) == MALIDP500_DC_CONFIG_REQ)
  99. break;
  100. /*
  101. * entering config mode can take as long as the rendering
  102. * of a full frame, hence the long sleep here
  103. */
  104. usleep_range(1000, 10000);
  105. count--;
  106. }
  107. WARN(count == 0, "timeout while entering config mode");
  108. }
  109. static void malidp500_leave_config_mode(struct malidp_hw_device *hwdev)
  110. {
  111. u32 status, count = 100;
  112. malidp_hw_clearbits(hwdev, MALIDP500_DC_CONFIG_REQ, MALIDP500_DC_CONTROL);
  113. while (count) {
  114. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  115. if ((status & MALIDP500_DC_CONFIG_REQ) == 0)
  116. break;
  117. usleep_range(100, 1000);
  118. count--;
  119. }
  120. WARN(count == 0, "timeout while leaving config mode");
  121. }
  122. static bool malidp500_in_config_mode(struct malidp_hw_device *hwdev)
  123. {
  124. u32 status;
  125. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  126. if ((status & MALIDP500_DC_CONFIG_REQ) == MALIDP500_DC_CONFIG_REQ)
  127. return true;
  128. return false;
  129. }
  130. static void malidp500_set_config_valid(struct malidp_hw_device *hwdev)
  131. {
  132. malidp_hw_setbits(hwdev, MALIDP_CFG_VALID, MALIDP500_CONFIG_VALID);
  133. }
  134. static void malidp500_modeset(struct malidp_hw_device *hwdev, struct videomode *mode)
  135. {
  136. u32 val = 0;
  137. malidp_hw_clearbits(hwdev, MALIDP500_DC_CLEAR_MASK, MALIDP500_DC_CONTROL);
  138. if (mode->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  139. val |= MALIDP500_HSYNCPOL;
  140. if (mode->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  141. val |= MALIDP500_VSYNCPOL;
  142. val |= MALIDP_DE_DEFAULT_PREFETCH_START;
  143. malidp_hw_setbits(hwdev, val, MALIDP500_DC_CONTROL);
  144. /*
  145. * Mali-DP500 encodes the background color like this:
  146. * - red @ MALIDP500_BGND_COLOR[12:0]
  147. * - green @ MALIDP500_BGND_COLOR[27:16]
  148. * - blue @ (MALIDP500_BGND_COLOR + 4)[12:0]
  149. */
  150. val = ((MALIDP_BGND_COLOR_G & 0xfff) << 16) |
  151. (MALIDP_BGND_COLOR_R & 0xfff);
  152. malidp_hw_write(hwdev, val, MALIDP500_BGND_COLOR);
  153. malidp_hw_write(hwdev, MALIDP_BGND_COLOR_B, MALIDP500_BGND_COLOR + 4);
  154. val = MALIDP_DE_H_FRONTPORCH(mode->hfront_porch) |
  155. MALIDP_DE_H_BACKPORCH(mode->hback_porch);
  156. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_H_TIMINGS);
  157. val = MALIDP500_DE_V_FRONTPORCH(mode->vfront_porch) |
  158. MALIDP_DE_V_BACKPORCH(mode->vback_porch);
  159. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_V_TIMINGS);
  160. val = MALIDP_DE_H_SYNCWIDTH(mode->hsync_len) |
  161. MALIDP_DE_V_SYNCWIDTH(mode->vsync_len);
  162. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_SYNC_WIDTH);
  163. val = MALIDP_DE_H_ACTIVE(mode->hactive) | MALIDP_DE_V_ACTIVE(mode->vactive);
  164. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_HV_ACTIVE);
  165. if (mode->flags & DISPLAY_FLAGS_INTERLACED)
  166. malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  167. else
  168. malidp_hw_clearbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  169. }
  170. static int malidp500_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt)
  171. {
  172. unsigned int depth;
  173. int bpp;
  174. /* RGB888 or BGR888 can't be rotated */
  175. if ((fmt == DRM_FORMAT_RGB888) || (fmt == DRM_FORMAT_BGR888))
  176. return -EINVAL;
  177. /*
  178. * Each layer needs enough rotation memory to fit 8 lines
  179. * worth of pixel data. Required size is then:
  180. * size = rotated_width * (bpp / 8) * 8;
  181. */
  182. drm_fb_get_bpp_depth(fmt, &depth, &bpp);
  183. return w * bpp;
  184. }
  185. static int malidp550_query_hw(struct malidp_hw_device *hwdev)
  186. {
  187. u32 conf = malidp_hw_read(hwdev, MALIDP550_CONFIG_ID);
  188. u8 ln_size = (conf >> 4) & 0x3, rsize;
  189. hwdev->min_line_size = 2;
  190. switch (ln_size) {
  191. case 0:
  192. hwdev->max_line_size = SZ_2K;
  193. /* two banks of 64KB for rotation memory */
  194. rsize = 64;
  195. break;
  196. case 1:
  197. hwdev->max_line_size = SZ_4K;
  198. /* two banks of 128KB for rotation memory */
  199. rsize = 128;
  200. break;
  201. case 2:
  202. hwdev->max_line_size = 1280;
  203. /* two banks of 40KB for rotation memory */
  204. rsize = 40;
  205. break;
  206. case 3:
  207. /* reserved value */
  208. hwdev->max_line_size = 0;
  209. return -EINVAL;
  210. }
  211. hwdev->rotation_memory[0] = hwdev->rotation_memory[1] = rsize * SZ_1K;
  212. return 0;
  213. }
  214. static void malidp550_enter_config_mode(struct malidp_hw_device *hwdev)
  215. {
  216. u32 status, count = 100;
  217. malidp_hw_setbits(hwdev, MALIDP550_DC_CONFIG_REQ, MALIDP550_DC_CONTROL);
  218. while (count) {
  219. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  220. if ((status & MALIDP550_DC_CONFIG_REQ) == MALIDP550_DC_CONFIG_REQ)
  221. break;
  222. /*
  223. * entering config mode can take as long as the rendering
  224. * of a full frame, hence the long sleep here
  225. */
  226. usleep_range(1000, 10000);
  227. count--;
  228. }
  229. WARN(count == 0, "timeout while entering config mode");
  230. }
  231. static void malidp550_leave_config_mode(struct malidp_hw_device *hwdev)
  232. {
  233. u32 status, count = 100;
  234. malidp_hw_clearbits(hwdev, MALIDP550_DC_CONFIG_REQ, MALIDP550_DC_CONTROL);
  235. while (count) {
  236. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  237. if ((status & MALIDP550_DC_CONFIG_REQ) == 0)
  238. break;
  239. usleep_range(100, 1000);
  240. count--;
  241. }
  242. WARN(count == 0, "timeout while leaving config mode");
  243. }
  244. static bool malidp550_in_config_mode(struct malidp_hw_device *hwdev)
  245. {
  246. u32 status;
  247. status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  248. if ((status & MALIDP550_DC_CONFIG_REQ) == MALIDP550_DC_CONFIG_REQ)
  249. return true;
  250. return false;
  251. }
  252. static void malidp550_set_config_valid(struct malidp_hw_device *hwdev)
  253. {
  254. malidp_hw_setbits(hwdev, MALIDP_CFG_VALID, MALIDP550_CONFIG_VALID);
  255. }
  256. static void malidp550_modeset(struct malidp_hw_device *hwdev, struct videomode *mode)
  257. {
  258. u32 val = MALIDP_DE_DEFAULT_PREFETCH_START;
  259. malidp_hw_write(hwdev, val, MALIDP550_DE_CONTROL);
  260. /*
  261. * Mali-DP550 and Mali-DP650 encode the background color like this:
  262. * - red @ MALIDP550_DE_BGND_COLOR[23:16]
  263. * - green @ MALIDP550_DE_BGND_COLOR[15:8]
  264. * - blue @ MALIDP550_DE_BGND_COLOR[7:0]
  265. *
  266. * We need to truncate the least significant 4 bits from the default
  267. * MALIDP_BGND_COLOR_x values
  268. */
  269. val = (((MALIDP_BGND_COLOR_R >> 4) & 0xff) << 16) |
  270. (((MALIDP_BGND_COLOR_G >> 4) & 0xff) << 8) |
  271. ((MALIDP_BGND_COLOR_B >> 4) & 0xff);
  272. malidp_hw_write(hwdev, val, MALIDP550_DE_BGND_COLOR);
  273. val = MALIDP_DE_H_FRONTPORCH(mode->hfront_porch) |
  274. MALIDP_DE_H_BACKPORCH(mode->hback_porch);
  275. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_H_TIMINGS);
  276. val = MALIDP550_DE_V_FRONTPORCH(mode->vfront_porch) |
  277. MALIDP_DE_V_BACKPORCH(mode->vback_porch);
  278. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_V_TIMINGS);
  279. val = MALIDP_DE_H_SYNCWIDTH(mode->hsync_len) |
  280. MALIDP_DE_V_SYNCWIDTH(mode->vsync_len);
  281. if (mode->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  282. val |= MALIDP550_HSYNCPOL;
  283. if (mode->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  284. val |= MALIDP550_VSYNCPOL;
  285. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_SYNC_WIDTH);
  286. val = MALIDP_DE_H_ACTIVE(mode->hactive) | MALIDP_DE_V_ACTIVE(mode->vactive);
  287. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_HV_ACTIVE);
  288. if (mode->flags & DISPLAY_FLAGS_INTERLACED)
  289. malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  290. else
  291. malidp_hw_clearbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  292. }
  293. static int malidp550_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt)
  294. {
  295. u32 bytes_per_col;
  296. /* raw RGB888 or BGR888 can't be rotated */
  297. if ((fmt == DRM_FORMAT_RGB888) || (fmt == DRM_FORMAT_BGR888))
  298. return -EINVAL;
  299. switch (fmt) {
  300. /* 8 lines at 4 bytes per pixel */
  301. case DRM_FORMAT_ARGB2101010:
  302. case DRM_FORMAT_ABGR2101010:
  303. case DRM_FORMAT_RGBA1010102:
  304. case DRM_FORMAT_BGRA1010102:
  305. case DRM_FORMAT_ARGB8888:
  306. case DRM_FORMAT_ABGR8888:
  307. case DRM_FORMAT_RGBA8888:
  308. case DRM_FORMAT_BGRA8888:
  309. case DRM_FORMAT_XRGB8888:
  310. case DRM_FORMAT_XBGR8888:
  311. case DRM_FORMAT_RGBX8888:
  312. case DRM_FORMAT_BGRX8888:
  313. case DRM_FORMAT_RGB888:
  314. case DRM_FORMAT_BGR888:
  315. /* 16 lines at 2 bytes per pixel */
  316. case DRM_FORMAT_RGBA5551:
  317. case DRM_FORMAT_ABGR1555:
  318. case DRM_FORMAT_RGB565:
  319. case DRM_FORMAT_BGR565:
  320. case DRM_FORMAT_UYVY:
  321. case DRM_FORMAT_YUYV:
  322. bytes_per_col = 32;
  323. break;
  324. /* 16 lines at 1.5 bytes per pixel */
  325. case DRM_FORMAT_NV12:
  326. case DRM_FORMAT_YUV420:
  327. bytes_per_col = 24;
  328. break;
  329. default:
  330. return -EINVAL;
  331. }
  332. return w * bytes_per_col;
  333. }
  334. static int malidp650_query_hw(struct malidp_hw_device *hwdev)
  335. {
  336. u32 conf = malidp_hw_read(hwdev, MALIDP550_CONFIG_ID);
  337. u8 ln_size = (conf >> 4) & 0x3, rsize;
  338. hwdev->min_line_size = 4;
  339. switch (ln_size) {
  340. case 0:
  341. case 2:
  342. /* reserved values */
  343. hwdev->max_line_size = 0;
  344. return -EINVAL;
  345. case 1:
  346. hwdev->max_line_size = SZ_4K;
  347. /* two banks of 128KB for rotation memory */
  348. rsize = 128;
  349. break;
  350. case 3:
  351. hwdev->max_line_size = 2560;
  352. /* two banks of 80KB for rotation memory */
  353. rsize = 80;
  354. }
  355. hwdev->rotation_memory[0] = hwdev->rotation_memory[1] = rsize * SZ_1K;
  356. return 0;
  357. }
  358. const struct malidp_hw_device malidp_device[MALIDP_MAX_DEVICES] = {
  359. [MALIDP_500] = {
  360. .map = {
  361. .se_base = MALIDP500_SE_BASE,
  362. .dc_base = MALIDP500_DC_BASE,
  363. .out_depth_base = MALIDP500_OUTPUT_DEPTH,
  364. .features = 0, /* no CLEARIRQ register */
  365. .n_layers = ARRAY_SIZE(malidp500_layers),
  366. .layers = malidp500_layers,
  367. .de_irq_map = {
  368. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  369. MALIDP500_DE_IRQ_AXI_ERR |
  370. MALIDP500_DE_IRQ_VSYNC |
  371. MALIDP500_DE_IRQ_GLOBAL,
  372. .vsync_irq = MALIDP500_DE_IRQ_VSYNC,
  373. },
  374. .se_irq_map = {
  375. .irq_mask = MALIDP500_SE_IRQ_CONF_MODE,
  376. .vsync_irq = 0,
  377. },
  378. .dc_irq_map = {
  379. .irq_mask = MALIDP500_DE_IRQ_CONF_VALID,
  380. .vsync_irq = MALIDP500_DE_IRQ_CONF_VALID,
  381. },
  382. .input_formats = malidp500_de_formats,
  383. .n_input_formats = ARRAY_SIZE(malidp500_de_formats),
  384. },
  385. .query_hw = malidp500_query_hw,
  386. .enter_config_mode = malidp500_enter_config_mode,
  387. .leave_config_mode = malidp500_leave_config_mode,
  388. .in_config_mode = malidp500_in_config_mode,
  389. .set_config_valid = malidp500_set_config_valid,
  390. .modeset = malidp500_modeset,
  391. .rotmem_required = malidp500_rotmem_required,
  392. },
  393. [MALIDP_550] = {
  394. .map = {
  395. .se_base = MALIDP550_SE_BASE,
  396. .dc_base = MALIDP550_DC_BASE,
  397. .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH,
  398. .features = MALIDP_REGMAP_HAS_CLEARIRQ,
  399. .n_layers = ARRAY_SIZE(malidp550_layers),
  400. .layers = malidp550_layers,
  401. .de_irq_map = {
  402. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  403. MALIDP550_DE_IRQ_VSYNC,
  404. .vsync_irq = MALIDP550_DE_IRQ_VSYNC,
  405. },
  406. .se_irq_map = {
  407. .irq_mask = MALIDP550_SE_IRQ_EOW |
  408. MALIDP550_SE_IRQ_AXI_ERR,
  409. },
  410. .dc_irq_map = {
  411. .irq_mask = MALIDP550_DC_IRQ_CONF_VALID,
  412. .vsync_irq = MALIDP550_DC_IRQ_CONF_VALID,
  413. },
  414. .input_formats = malidp550_de_formats,
  415. .n_input_formats = ARRAY_SIZE(malidp550_de_formats),
  416. },
  417. .query_hw = malidp550_query_hw,
  418. .enter_config_mode = malidp550_enter_config_mode,
  419. .leave_config_mode = malidp550_leave_config_mode,
  420. .in_config_mode = malidp550_in_config_mode,
  421. .set_config_valid = malidp550_set_config_valid,
  422. .modeset = malidp550_modeset,
  423. .rotmem_required = malidp550_rotmem_required,
  424. },
  425. [MALIDP_650] = {
  426. .map = {
  427. .se_base = MALIDP550_SE_BASE,
  428. .dc_base = MALIDP550_DC_BASE,
  429. .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH,
  430. .features = MALIDP_REGMAP_HAS_CLEARIRQ,
  431. .n_layers = ARRAY_SIZE(malidp550_layers),
  432. .layers = malidp550_layers,
  433. .de_irq_map = {
  434. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  435. MALIDP650_DE_IRQ_DRIFT |
  436. MALIDP550_DE_IRQ_VSYNC,
  437. .vsync_irq = MALIDP550_DE_IRQ_VSYNC,
  438. },
  439. .se_irq_map = {
  440. .irq_mask = MALIDP550_SE_IRQ_EOW |
  441. MALIDP550_SE_IRQ_AXI_ERR,
  442. },
  443. .dc_irq_map = {
  444. .irq_mask = MALIDP550_DC_IRQ_CONF_VALID,
  445. .vsync_irq = MALIDP550_DC_IRQ_CONF_VALID,
  446. },
  447. .input_formats = malidp550_de_formats,
  448. .n_input_formats = ARRAY_SIZE(malidp550_de_formats),
  449. },
  450. .query_hw = malidp650_query_hw,
  451. .enter_config_mode = malidp550_enter_config_mode,
  452. .leave_config_mode = malidp550_leave_config_mode,
  453. .in_config_mode = malidp550_in_config_mode,
  454. .set_config_valid = malidp550_set_config_valid,
  455. .modeset = malidp550_modeset,
  456. .rotmem_required = malidp550_rotmem_required,
  457. },
  458. };
  459. u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
  460. u8 layer_id, u32 format)
  461. {
  462. unsigned int i;
  463. for (i = 0; i < map->n_input_formats; i++) {
  464. if (((map->input_formats[i].layer & layer_id) == layer_id) &&
  465. (map->input_formats[i].format == format))
  466. return map->input_formats[i].id;
  467. }
  468. return MALIDP_INVALID_FORMAT_ID;
  469. }
  470. static void malidp_hw_clear_irq(struct malidp_hw_device *hwdev, u8 block, u32 irq)
  471. {
  472. u32 base = malidp_get_block_base(hwdev, block);
  473. if (hwdev->map.features & MALIDP_REGMAP_HAS_CLEARIRQ)
  474. malidp_hw_write(hwdev, irq, base + MALIDP_REG_CLEARIRQ);
  475. else
  476. malidp_hw_write(hwdev, irq, base + MALIDP_REG_STATUS);
  477. }
  478. static irqreturn_t malidp_de_irq(int irq, void *arg)
  479. {
  480. struct drm_device *drm = arg;
  481. struct malidp_drm *malidp = drm->dev_private;
  482. struct malidp_hw_device *hwdev;
  483. const struct malidp_irq_map *de;
  484. u32 status, mask, dc_status;
  485. irqreturn_t ret = IRQ_NONE;
  486. if (!drm->dev_private)
  487. return IRQ_HANDLED;
  488. hwdev = malidp->dev;
  489. de = &hwdev->map.de_irq_map;
  490. /* first handle the config valid IRQ */
  491. dc_status = malidp_hw_read(hwdev, hwdev->map.dc_base + MALIDP_REG_STATUS);
  492. if (dc_status & hwdev->map.dc_irq_map.vsync_irq) {
  493. /* we have a page flip event */
  494. atomic_set(&malidp->config_valid, 1);
  495. malidp_hw_clear_irq(hwdev, MALIDP_DC_BLOCK, dc_status);
  496. ret = IRQ_WAKE_THREAD;
  497. }
  498. status = malidp_hw_read(hwdev, MALIDP_REG_STATUS);
  499. if (!(status & de->irq_mask))
  500. return ret;
  501. mask = malidp_hw_read(hwdev, MALIDP_REG_MASKIRQ);
  502. status &= mask;
  503. if (status & de->vsync_irq)
  504. drm_crtc_handle_vblank(&malidp->crtc);
  505. malidp_hw_clear_irq(hwdev, MALIDP_DE_BLOCK, status);
  506. return (ret == IRQ_NONE) ? IRQ_HANDLED : ret;
  507. }
  508. static irqreturn_t malidp_de_irq_thread_handler(int irq, void *arg)
  509. {
  510. struct drm_device *drm = arg;
  511. struct malidp_drm *malidp = drm->dev_private;
  512. wake_up(&malidp->wq);
  513. return IRQ_HANDLED;
  514. }
  515. int malidp_de_irq_init(struct drm_device *drm, int irq)
  516. {
  517. struct malidp_drm *malidp = drm->dev_private;
  518. struct malidp_hw_device *hwdev = malidp->dev;
  519. int ret;
  520. /* ensure interrupts are disabled */
  521. malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK, 0xffffffff);
  522. malidp_hw_clear_irq(hwdev, MALIDP_DE_BLOCK, 0xffffffff);
  523. malidp_hw_disable_irq(hwdev, MALIDP_DC_BLOCK, 0xffffffff);
  524. malidp_hw_clear_irq(hwdev, MALIDP_DC_BLOCK, 0xffffffff);
  525. ret = devm_request_threaded_irq(drm->dev, irq, malidp_de_irq,
  526. malidp_de_irq_thread_handler,
  527. IRQF_SHARED, "malidp-de", drm);
  528. if (ret < 0) {
  529. DRM_ERROR("failed to install DE IRQ handler\n");
  530. return ret;
  531. }
  532. /* first enable the DC block IRQs */
  533. malidp_hw_enable_irq(hwdev, MALIDP_DC_BLOCK,
  534. hwdev->map.dc_irq_map.irq_mask);
  535. /* now enable the DE block IRQs */
  536. malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK,
  537. hwdev->map.de_irq_map.irq_mask);
  538. return 0;
  539. }
  540. void malidp_de_irq_fini(struct drm_device *drm)
  541. {
  542. struct malidp_drm *malidp = drm->dev_private;
  543. struct malidp_hw_device *hwdev = malidp->dev;
  544. malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK,
  545. hwdev->map.de_irq_map.irq_mask);
  546. malidp_hw_disable_irq(hwdev, MALIDP_DC_BLOCK,
  547. hwdev->map.dc_irq_map.irq_mask);
  548. }
  549. static irqreturn_t malidp_se_irq(int irq, void *arg)
  550. {
  551. struct drm_device *drm = arg;
  552. struct malidp_drm *malidp = drm->dev_private;
  553. struct malidp_hw_device *hwdev = malidp->dev;
  554. u32 status, mask;
  555. status = malidp_hw_read(hwdev, hwdev->map.se_base + MALIDP_REG_STATUS);
  556. if (!(status & hwdev->map.se_irq_map.irq_mask))
  557. return IRQ_NONE;
  558. mask = malidp_hw_read(hwdev, hwdev->map.se_base + MALIDP_REG_MASKIRQ);
  559. status = malidp_hw_read(hwdev, hwdev->map.se_base + MALIDP_REG_STATUS);
  560. status &= mask;
  561. /* ToDo: status decoding and firing up of VSYNC and page flip events */
  562. malidp_hw_clear_irq(hwdev, MALIDP_SE_BLOCK, status);
  563. return IRQ_HANDLED;
  564. }
  565. static irqreturn_t malidp_se_irq_thread_handler(int irq, void *arg)
  566. {
  567. return IRQ_HANDLED;
  568. }
  569. int malidp_se_irq_init(struct drm_device *drm, int irq)
  570. {
  571. struct malidp_drm *malidp = drm->dev_private;
  572. struct malidp_hw_device *hwdev = malidp->dev;
  573. int ret;
  574. /* ensure interrupts are disabled */
  575. malidp_hw_disable_irq(hwdev, MALIDP_SE_BLOCK, 0xffffffff);
  576. malidp_hw_clear_irq(hwdev, MALIDP_SE_BLOCK, 0xffffffff);
  577. ret = devm_request_threaded_irq(drm->dev, irq, malidp_se_irq,
  578. malidp_se_irq_thread_handler,
  579. IRQF_SHARED, "malidp-se", drm);
  580. if (ret < 0) {
  581. DRM_ERROR("failed to install SE IRQ handler\n");
  582. return ret;
  583. }
  584. malidp_hw_enable_irq(hwdev, MALIDP_SE_BLOCK,
  585. hwdev->map.se_irq_map.irq_mask);
  586. return 0;
  587. }
  588. void malidp_se_irq_fini(struct drm_device *drm)
  589. {
  590. struct malidp_drm *malidp = drm->dev_private;
  591. struct malidp_hw_device *hwdev = malidp->dev;
  592. malidp_hw_disable_irq(hwdev, MALIDP_SE_BLOCK,
  593. hwdev->map.se_irq_map.irq_mask);
  594. }