malidp_hw.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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/clk.h>
  15. #include <linux/types.h>
  16. #include <linux/io.h>
  17. #include <drm/drmP.h>
  18. #include <video/videomode.h>
  19. #include <video/display_timing.h>
  20. #include "malidp_drv.h"
  21. #include "malidp_hw.h"
  22. static const struct malidp_format_id malidp500_de_formats[] = {
  23. /* fourcc, layers supporting the format, internal id */
  24. { DRM_FORMAT_ARGB2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 0 },
  25. { DRM_FORMAT_ABGR2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 1 },
  26. { DRM_FORMAT_ARGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 2 },
  27. { DRM_FORMAT_ABGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 3 },
  28. { DRM_FORMAT_XRGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 4 },
  29. { DRM_FORMAT_XBGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 5 },
  30. { DRM_FORMAT_RGB888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 6 },
  31. { DRM_FORMAT_BGR888, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 7 },
  32. { DRM_FORMAT_RGBA5551, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 8 },
  33. { DRM_FORMAT_ABGR1555, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 9 },
  34. { DRM_FORMAT_RGB565, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 10 },
  35. { DRM_FORMAT_BGR565, DE_VIDEO1 | DE_GRAPHICS1 | DE_GRAPHICS2, 11 },
  36. { DRM_FORMAT_UYVY, DE_VIDEO1, 12 },
  37. { DRM_FORMAT_YUYV, DE_VIDEO1, 13 },
  38. { DRM_FORMAT_NV12, DE_VIDEO1, 14 },
  39. { DRM_FORMAT_YUV420, DE_VIDEO1, 15 },
  40. };
  41. #define MALIDP_ID(__group, __format) \
  42. ((((__group) & 0x7) << 3) | ((__format) & 0x7))
  43. #define MALIDP_COMMON_FORMATS \
  44. /* fourcc, layers supporting the format, internal id */ \
  45. { DRM_FORMAT_ARGB2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 0) }, \
  46. { DRM_FORMAT_ABGR2101010, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 1) }, \
  47. { DRM_FORMAT_RGBA1010102, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 2) }, \
  48. { DRM_FORMAT_BGRA1010102, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(0, 3) }, \
  49. { DRM_FORMAT_ARGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 0) }, \
  50. { DRM_FORMAT_ABGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 1) }, \
  51. { DRM_FORMAT_RGBA8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 2) }, \
  52. { DRM_FORMAT_BGRA8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(1, 3) }, \
  53. { DRM_FORMAT_XRGB8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 0) }, \
  54. { DRM_FORMAT_XBGR8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 1) }, \
  55. { DRM_FORMAT_RGBX8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 2) }, \
  56. { DRM_FORMAT_BGRX8888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2 | DE_SMART, MALIDP_ID(2, 3) }, \
  57. { DRM_FORMAT_RGB888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(3, 0) }, \
  58. { DRM_FORMAT_BGR888, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(3, 1) }, \
  59. { DRM_FORMAT_RGBA5551, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 0) }, \
  60. { DRM_FORMAT_ABGR1555, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 1) }, \
  61. { DRM_FORMAT_RGB565, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 2) }, \
  62. { DRM_FORMAT_BGR565, DE_VIDEO1 | DE_GRAPHICS1 | DE_VIDEO2, MALIDP_ID(4, 3) }, \
  63. { DRM_FORMAT_YUYV, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 2) }, \
  64. { DRM_FORMAT_UYVY, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 3) }, \
  65. { DRM_FORMAT_NV12, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 6) }, \
  66. { DRM_FORMAT_YUV420, DE_VIDEO1 | DE_VIDEO2, MALIDP_ID(5, 7) }
  67. static const struct malidp_format_id malidp550_de_formats[] = {
  68. MALIDP_COMMON_FORMATS,
  69. };
  70. static const struct malidp_layer malidp500_layers[] = {
  71. { DE_VIDEO1, MALIDP500_DE_LV_BASE, MALIDP500_DE_LV_PTR_BASE, MALIDP_DE_LV_STRIDE0 },
  72. { DE_GRAPHICS1, MALIDP500_DE_LG1_BASE, MALIDP500_DE_LG1_PTR_BASE, MALIDP_DE_LG_STRIDE },
  73. { DE_GRAPHICS2, MALIDP500_DE_LG2_BASE, MALIDP500_DE_LG2_PTR_BASE, MALIDP_DE_LG_STRIDE },
  74. };
  75. static const struct malidp_layer malidp550_layers[] = {
  76. { DE_VIDEO1, MALIDP550_DE_LV1_BASE, MALIDP550_DE_LV1_PTR_BASE, MALIDP_DE_LV_STRIDE0 },
  77. { DE_GRAPHICS1, MALIDP550_DE_LG_BASE, MALIDP550_DE_LG_PTR_BASE, MALIDP_DE_LG_STRIDE },
  78. { DE_VIDEO2, MALIDP550_DE_LV2_BASE, MALIDP550_DE_LV2_PTR_BASE, MALIDP_DE_LV_STRIDE0 },
  79. { DE_SMART, MALIDP550_DE_LS_BASE, MALIDP550_DE_LS_PTR_BASE, MALIDP550_DE_LS_R1_STRIDE },
  80. };
  81. #define SE_N_SCALING_COEFFS 96
  82. static const u16 dp500_se_scaling_coeffs[][SE_N_SCALING_COEFFS] = {
  83. [MALIDP_UPSCALING_COEFFS - 1] = {
  84. 0x0000, 0x0001, 0x0007, 0x0011, 0x001e, 0x002e, 0x003f, 0x0052,
  85. 0x0064, 0x0073, 0x007d, 0x0080, 0x007a, 0x006c, 0x0053, 0x002f,
  86. 0x0000, 0x3fc6, 0x3f83, 0x3f39, 0x3eea, 0x3e9b, 0x3e4f, 0x3e0a,
  87. 0x3dd4, 0x3db0, 0x3da2, 0x3db1, 0x3dde, 0x3e2f, 0x3ea5, 0x3f40,
  88. 0x0000, 0x00e5, 0x01ee, 0x0315, 0x0456, 0x05aa, 0x0709, 0x086c,
  89. 0x09c9, 0x0b15, 0x0c4a, 0x0d5d, 0x0e4a, 0x0f06, 0x0f91, 0x0fe5,
  90. 0x1000, 0x0fe5, 0x0f91, 0x0f06, 0x0e4a, 0x0d5d, 0x0c4a, 0x0b15,
  91. 0x09c9, 0x086c, 0x0709, 0x05aa, 0x0456, 0x0315, 0x01ee, 0x00e5,
  92. 0x0000, 0x3f40, 0x3ea5, 0x3e2f, 0x3dde, 0x3db1, 0x3da2, 0x3db0,
  93. 0x3dd4, 0x3e0a, 0x3e4f, 0x3e9b, 0x3eea, 0x3f39, 0x3f83, 0x3fc6,
  94. 0x0000, 0x002f, 0x0053, 0x006c, 0x007a, 0x0080, 0x007d, 0x0073,
  95. 0x0064, 0x0052, 0x003f, 0x002e, 0x001e, 0x0011, 0x0007, 0x0001
  96. },
  97. [MALIDP_DOWNSCALING_1_5_COEFFS - 1] = {
  98. 0x0059, 0x004f, 0x0041, 0x002e, 0x0016, 0x3ffb, 0x3fd9, 0x3fb4,
  99. 0x3f8c, 0x3f62, 0x3f36, 0x3f09, 0x3edd, 0x3eb3, 0x3e8d, 0x3e6c,
  100. 0x3e52, 0x3e3f, 0x3e35, 0x3e37, 0x3e46, 0x3e61, 0x3e8c, 0x3ec5,
  101. 0x3f0f, 0x3f68, 0x3fd1, 0x004a, 0x00d3, 0x0169, 0x020b, 0x02b8,
  102. 0x036e, 0x042d, 0x04f2, 0x05b9, 0x0681, 0x0745, 0x0803, 0x08ba,
  103. 0x0965, 0x0a03, 0x0a91, 0x0b0d, 0x0b75, 0x0bc6, 0x0c00, 0x0c20,
  104. 0x0c28, 0x0c20, 0x0c00, 0x0bc6, 0x0b75, 0x0b0d, 0x0a91, 0x0a03,
  105. 0x0965, 0x08ba, 0x0803, 0x0745, 0x0681, 0x05b9, 0x04f2, 0x042d,
  106. 0x036e, 0x02b8, 0x020b, 0x0169, 0x00d3, 0x004a, 0x3fd1, 0x3f68,
  107. 0x3f0f, 0x3ec5, 0x3e8c, 0x3e61, 0x3e46, 0x3e37, 0x3e35, 0x3e3f,
  108. 0x3e52, 0x3e6c, 0x3e8d, 0x3eb3, 0x3edd, 0x3f09, 0x3f36, 0x3f62,
  109. 0x3f8c, 0x3fb4, 0x3fd9, 0x3ffb, 0x0016, 0x002e, 0x0041, 0x004f
  110. },
  111. [MALIDP_DOWNSCALING_2_COEFFS - 1] = {
  112. 0x3f19, 0x3f03, 0x3ef0, 0x3edf, 0x3ed0, 0x3ec5, 0x3ebd, 0x3eb9,
  113. 0x3eb9, 0x3ebf, 0x3eca, 0x3ed9, 0x3eef, 0x3f0a, 0x3f2c, 0x3f52,
  114. 0x3f7f, 0x3fb0, 0x3fe8, 0x0026, 0x006a, 0x00b4, 0x0103, 0x0158,
  115. 0x01b1, 0x020d, 0x026c, 0x02cd, 0x032f, 0x0392, 0x03f4, 0x0455,
  116. 0x04b4, 0x051e, 0x0585, 0x05eb, 0x064c, 0x06a8, 0x06fe, 0x074e,
  117. 0x0796, 0x07d5, 0x080c, 0x0839, 0x085c, 0x0875, 0x0882, 0x0887,
  118. 0x0881, 0x0887, 0x0882, 0x0875, 0x085c, 0x0839, 0x080c, 0x07d5,
  119. 0x0796, 0x074e, 0x06fe, 0x06a8, 0x064c, 0x05eb, 0x0585, 0x051e,
  120. 0x04b4, 0x0455, 0x03f4, 0x0392, 0x032f, 0x02cd, 0x026c, 0x020d,
  121. 0x01b1, 0x0158, 0x0103, 0x00b4, 0x006a, 0x0026, 0x3fe8, 0x3fb0,
  122. 0x3f7f, 0x3f52, 0x3f2c, 0x3f0a, 0x3eef, 0x3ed9, 0x3eca, 0x3ebf,
  123. 0x3eb9, 0x3eb9, 0x3ebd, 0x3ec5, 0x3ed0, 0x3edf, 0x3ef0, 0x3f03
  124. },
  125. [MALIDP_DOWNSCALING_2_75_COEFFS - 1] = {
  126. 0x3f51, 0x3f60, 0x3f71, 0x3f84, 0x3f98, 0x3faf, 0x3fc8, 0x3fe3,
  127. 0x0000, 0x001f, 0x0040, 0x0064, 0x008a, 0x00b1, 0x00da, 0x0106,
  128. 0x0133, 0x0160, 0x018e, 0x01bd, 0x01ec, 0x021d, 0x024e, 0x0280,
  129. 0x02b2, 0x02e4, 0x0317, 0x0349, 0x037c, 0x03ad, 0x03df, 0x0410,
  130. 0x0440, 0x0468, 0x048f, 0x04b3, 0x04d6, 0x04f8, 0x0516, 0x0533,
  131. 0x054e, 0x0566, 0x057c, 0x0590, 0x05a0, 0x05ae, 0x05ba, 0x05c3,
  132. 0x05c9, 0x05c3, 0x05ba, 0x05ae, 0x05a0, 0x0590, 0x057c, 0x0566,
  133. 0x054e, 0x0533, 0x0516, 0x04f8, 0x04d6, 0x04b3, 0x048f, 0x0468,
  134. 0x0440, 0x0410, 0x03df, 0x03ad, 0x037c, 0x0349, 0x0317, 0x02e4,
  135. 0x02b2, 0x0280, 0x024e, 0x021d, 0x01ec, 0x01bd, 0x018e, 0x0160,
  136. 0x0133, 0x0106, 0x00da, 0x00b1, 0x008a, 0x0064, 0x0040, 0x001f,
  137. 0x0000, 0x3fe3, 0x3fc8, 0x3faf, 0x3f98, 0x3f84, 0x3f71, 0x3f60
  138. },
  139. [MALIDP_DOWNSCALING_4_COEFFS - 1] = {
  140. 0x0094, 0x00a9, 0x00be, 0x00d4, 0x00ea, 0x0101, 0x0118, 0x012f,
  141. 0x0148, 0x0160, 0x017a, 0x0193, 0x01ae, 0x01c8, 0x01e4, 0x01ff,
  142. 0x021c, 0x0233, 0x024a, 0x0261, 0x0278, 0x028f, 0x02a6, 0x02bd,
  143. 0x02d4, 0x02eb, 0x0302, 0x0319, 0x032f, 0x0346, 0x035d, 0x0374,
  144. 0x038a, 0x0397, 0x03a3, 0x03af, 0x03bb, 0x03c6, 0x03d1, 0x03db,
  145. 0x03e4, 0x03ed, 0x03f6, 0x03fe, 0x0406, 0x040d, 0x0414, 0x041a,
  146. 0x0420, 0x041a, 0x0414, 0x040d, 0x0406, 0x03fe, 0x03f6, 0x03ed,
  147. 0x03e4, 0x03db, 0x03d1, 0x03c6, 0x03bb, 0x03af, 0x03a3, 0x0397,
  148. 0x038a, 0x0374, 0x035d, 0x0346, 0x032f, 0x0319, 0x0302, 0x02eb,
  149. 0x02d4, 0x02bd, 0x02a6, 0x028f, 0x0278, 0x0261, 0x024a, 0x0233,
  150. 0x021c, 0x01ff, 0x01e4, 0x01c8, 0x01ae, 0x0193, 0x017a, 0x0160,
  151. 0x0148, 0x012f, 0x0118, 0x0101, 0x00ea, 0x00d4, 0x00be, 0x00a9
  152. },
  153. };
  154. #define MALIDP_DE_DEFAULT_PREFETCH_START 5
  155. static int malidp500_query_hw(struct malidp_hw_device *hwdev)
  156. {
  157. u32 conf = malidp_hw_read(hwdev, MALIDP500_CONFIG_ID);
  158. /* bit 4 of the CONFIG_ID register holds the line size multiplier */
  159. u8 ln_size_mult = conf & 0x10 ? 2 : 1;
  160. hwdev->min_line_size = 2;
  161. hwdev->max_line_size = SZ_2K * ln_size_mult;
  162. hwdev->rotation_memory[0] = SZ_1K * 64 * ln_size_mult;
  163. hwdev->rotation_memory[1] = 0; /* no second rotation memory bank */
  164. return 0;
  165. }
  166. static void malidp500_enter_config_mode(struct malidp_hw_device *hwdev)
  167. {
  168. u32 status, count = 100;
  169. malidp_hw_setbits(hwdev, MALIDP500_DC_CONFIG_REQ, MALIDP500_DC_CONTROL);
  170. while (count) {
  171. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  172. if ((status & MALIDP500_DC_CONFIG_REQ) == MALIDP500_DC_CONFIG_REQ)
  173. break;
  174. /*
  175. * entering config mode can take as long as the rendering
  176. * of a full frame, hence the long sleep here
  177. */
  178. usleep_range(1000, 10000);
  179. count--;
  180. }
  181. WARN(count == 0, "timeout while entering config mode");
  182. }
  183. static void malidp500_leave_config_mode(struct malidp_hw_device *hwdev)
  184. {
  185. u32 status, count = 100;
  186. malidp_hw_clearbits(hwdev, MALIDP_CFG_VALID, MALIDP500_CONFIG_VALID);
  187. malidp_hw_clearbits(hwdev, MALIDP500_DC_CONFIG_REQ, MALIDP500_DC_CONTROL);
  188. while (count) {
  189. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  190. if ((status & MALIDP500_DC_CONFIG_REQ) == 0)
  191. break;
  192. usleep_range(100, 1000);
  193. count--;
  194. }
  195. WARN(count == 0, "timeout while leaving config mode");
  196. }
  197. static bool malidp500_in_config_mode(struct malidp_hw_device *hwdev)
  198. {
  199. u32 status;
  200. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  201. if ((status & MALIDP500_DC_CONFIG_REQ) == MALIDP500_DC_CONFIG_REQ)
  202. return true;
  203. return false;
  204. }
  205. static void malidp500_set_config_valid(struct malidp_hw_device *hwdev)
  206. {
  207. malidp_hw_setbits(hwdev, MALIDP_CFG_VALID, MALIDP500_CONFIG_VALID);
  208. }
  209. static void malidp500_modeset(struct malidp_hw_device *hwdev, struct videomode *mode)
  210. {
  211. u32 val = 0;
  212. malidp_hw_clearbits(hwdev, MALIDP500_DC_CLEAR_MASK, MALIDP500_DC_CONTROL);
  213. if (mode->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  214. val |= MALIDP500_HSYNCPOL;
  215. if (mode->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  216. val |= MALIDP500_VSYNCPOL;
  217. val |= MALIDP_DE_DEFAULT_PREFETCH_START;
  218. malidp_hw_setbits(hwdev, val, MALIDP500_DC_CONTROL);
  219. /*
  220. * Mali-DP500 encodes the background color like this:
  221. * - red @ MALIDP500_BGND_COLOR[12:0]
  222. * - green @ MALIDP500_BGND_COLOR[27:16]
  223. * - blue @ (MALIDP500_BGND_COLOR + 4)[12:0]
  224. */
  225. val = ((MALIDP_BGND_COLOR_G & 0xfff) << 16) |
  226. (MALIDP_BGND_COLOR_R & 0xfff);
  227. malidp_hw_write(hwdev, val, MALIDP500_BGND_COLOR);
  228. malidp_hw_write(hwdev, MALIDP_BGND_COLOR_B, MALIDP500_BGND_COLOR + 4);
  229. val = MALIDP_DE_H_FRONTPORCH(mode->hfront_porch) |
  230. MALIDP_DE_H_BACKPORCH(mode->hback_porch);
  231. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_H_TIMINGS);
  232. val = MALIDP500_DE_V_FRONTPORCH(mode->vfront_porch) |
  233. MALIDP_DE_V_BACKPORCH(mode->vback_porch);
  234. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_V_TIMINGS);
  235. val = MALIDP_DE_H_SYNCWIDTH(mode->hsync_len) |
  236. MALIDP_DE_V_SYNCWIDTH(mode->vsync_len);
  237. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_SYNC_WIDTH);
  238. val = MALIDP_DE_H_ACTIVE(mode->hactive) | MALIDP_DE_V_ACTIVE(mode->vactive);
  239. malidp_hw_write(hwdev, val, MALIDP500_TIMINGS_BASE + MALIDP_DE_HV_ACTIVE);
  240. if (mode->flags & DISPLAY_FLAGS_INTERLACED)
  241. malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  242. else
  243. malidp_hw_clearbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  244. }
  245. static int malidp500_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt)
  246. {
  247. /* RGB888 or BGR888 can't be rotated */
  248. if ((fmt == DRM_FORMAT_RGB888) || (fmt == DRM_FORMAT_BGR888))
  249. return -EINVAL;
  250. /*
  251. * Each layer needs enough rotation memory to fit 8 lines
  252. * worth of pixel data. Required size is then:
  253. * size = rotated_width * (bpp / 8) * 8;
  254. */
  255. return w * drm_format_plane_cpp(fmt, 0) * 8;
  256. }
  257. static void malidp500_se_write_pp_coefftab(struct malidp_hw_device *hwdev,
  258. u32 direction,
  259. u16 addr,
  260. u8 coeffs_id)
  261. {
  262. int i;
  263. u16 scaling_control = MALIDP500_SE_CONTROL + MALIDP_SE_SCALING_CONTROL;
  264. malidp_hw_write(hwdev,
  265. direction | (addr & MALIDP_SE_COEFFTAB_ADDR_MASK),
  266. scaling_control + MALIDP_SE_COEFFTAB_ADDR);
  267. for (i = 0; i < ARRAY_SIZE(dp500_se_scaling_coeffs); ++i)
  268. malidp_hw_write(hwdev, MALIDP_SE_SET_COEFFTAB_DATA(
  269. dp500_se_scaling_coeffs[coeffs_id][i]),
  270. scaling_control + MALIDP_SE_COEFFTAB_DATA);
  271. }
  272. static int malidp500_se_set_scaling_coeffs(struct malidp_hw_device *hwdev,
  273. struct malidp_se_config *se_config,
  274. struct malidp_se_config *old_config)
  275. {
  276. /* Get array indices into dp500_se_scaling_coeffs. */
  277. u8 h = (u8)se_config->hcoeff - 1;
  278. u8 v = (u8)se_config->vcoeff - 1;
  279. if (WARN_ON(h >= ARRAY_SIZE(dp500_se_scaling_coeffs) ||
  280. v >= ARRAY_SIZE(dp500_se_scaling_coeffs)))
  281. return -EINVAL;
  282. if ((h == v) && (se_config->hcoeff != old_config->hcoeff ||
  283. se_config->vcoeff != old_config->vcoeff)) {
  284. malidp500_se_write_pp_coefftab(hwdev,
  285. (MALIDP_SE_V_COEFFTAB |
  286. MALIDP_SE_H_COEFFTAB),
  287. 0, v);
  288. } else {
  289. if (se_config->vcoeff != old_config->vcoeff)
  290. malidp500_se_write_pp_coefftab(hwdev,
  291. MALIDP_SE_V_COEFFTAB,
  292. 0, v);
  293. if (se_config->hcoeff != old_config->hcoeff)
  294. malidp500_se_write_pp_coefftab(hwdev,
  295. MALIDP_SE_H_COEFFTAB,
  296. 0, h);
  297. }
  298. return 0;
  299. }
  300. static long malidp500_se_calc_mclk(struct malidp_hw_device *hwdev,
  301. struct malidp_se_config *se_config,
  302. struct videomode *vm)
  303. {
  304. unsigned long mclk;
  305. unsigned long pxlclk = vm->pixelclock; /* Hz */
  306. unsigned long htotal = vm->hactive + vm->hfront_porch +
  307. vm->hback_porch + vm->hsync_len;
  308. unsigned long input_size = se_config->input_w * se_config->input_h;
  309. unsigned long a = 10;
  310. long ret;
  311. /*
  312. * mclk = max(a, 1.5) * pxlclk
  313. *
  314. * To avoid float calculaiton, using 15 instead of 1.5 and div by
  315. * 10 to get mclk.
  316. */
  317. if (se_config->scale_enable) {
  318. a = 15 * input_size / (htotal * se_config->output_h);
  319. if (a < 15)
  320. a = 15;
  321. }
  322. mclk = a * pxlclk / 10;
  323. ret = clk_get_rate(hwdev->mclk);
  324. if (ret < mclk) {
  325. DRM_DEBUG_DRIVER("mclk requirement of %lu kHz can't be met.\n",
  326. mclk / 1000);
  327. return -EINVAL;
  328. }
  329. return ret;
  330. }
  331. static int malidp550_query_hw(struct malidp_hw_device *hwdev)
  332. {
  333. u32 conf = malidp_hw_read(hwdev, MALIDP550_CONFIG_ID);
  334. u8 ln_size = (conf >> 4) & 0x3, rsize;
  335. hwdev->min_line_size = 2;
  336. switch (ln_size) {
  337. case 0:
  338. hwdev->max_line_size = SZ_2K;
  339. /* two banks of 64KB for rotation memory */
  340. rsize = 64;
  341. break;
  342. case 1:
  343. hwdev->max_line_size = SZ_4K;
  344. /* two banks of 128KB for rotation memory */
  345. rsize = 128;
  346. break;
  347. case 2:
  348. hwdev->max_line_size = 1280;
  349. /* two banks of 40KB for rotation memory */
  350. rsize = 40;
  351. break;
  352. case 3:
  353. /* reserved value */
  354. hwdev->max_line_size = 0;
  355. return -EINVAL;
  356. }
  357. hwdev->rotation_memory[0] = hwdev->rotation_memory[1] = rsize * SZ_1K;
  358. return 0;
  359. }
  360. static void malidp550_enter_config_mode(struct malidp_hw_device *hwdev)
  361. {
  362. u32 status, count = 100;
  363. malidp_hw_setbits(hwdev, MALIDP550_DC_CONFIG_REQ, MALIDP550_DC_CONTROL);
  364. while (count) {
  365. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  366. if ((status & MALIDP550_DC_CONFIG_REQ) == MALIDP550_DC_CONFIG_REQ)
  367. break;
  368. /*
  369. * entering config mode can take as long as the rendering
  370. * of a full frame, hence the long sleep here
  371. */
  372. usleep_range(1000, 10000);
  373. count--;
  374. }
  375. WARN(count == 0, "timeout while entering config mode");
  376. }
  377. static void malidp550_leave_config_mode(struct malidp_hw_device *hwdev)
  378. {
  379. u32 status, count = 100;
  380. malidp_hw_clearbits(hwdev, MALIDP_CFG_VALID, MALIDP550_CONFIG_VALID);
  381. malidp_hw_clearbits(hwdev, MALIDP550_DC_CONFIG_REQ, MALIDP550_DC_CONTROL);
  382. while (count) {
  383. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  384. if ((status & MALIDP550_DC_CONFIG_REQ) == 0)
  385. break;
  386. usleep_range(100, 1000);
  387. count--;
  388. }
  389. WARN(count == 0, "timeout while leaving config mode");
  390. }
  391. static bool malidp550_in_config_mode(struct malidp_hw_device *hwdev)
  392. {
  393. u32 status;
  394. status = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_REG_STATUS);
  395. if ((status & MALIDP550_DC_CONFIG_REQ) == MALIDP550_DC_CONFIG_REQ)
  396. return true;
  397. return false;
  398. }
  399. static void malidp550_set_config_valid(struct malidp_hw_device *hwdev)
  400. {
  401. malidp_hw_setbits(hwdev, MALIDP_CFG_VALID, MALIDP550_CONFIG_VALID);
  402. }
  403. static void malidp550_modeset(struct malidp_hw_device *hwdev, struct videomode *mode)
  404. {
  405. u32 val = MALIDP_DE_DEFAULT_PREFETCH_START;
  406. malidp_hw_write(hwdev, val, MALIDP550_DE_CONTROL);
  407. /*
  408. * Mali-DP550 and Mali-DP650 encode the background color like this:
  409. * - red @ MALIDP550_DE_BGND_COLOR[23:16]
  410. * - green @ MALIDP550_DE_BGND_COLOR[15:8]
  411. * - blue @ MALIDP550_DE_BGND_COLOR[7:0]
  412. *
  413. * We need to truncate the least significant 4 bits from the default
  414. * MALIDP_BGND_COLOR_x values
  415. */
  416. val = (((MALIDP_BGND_COLOR_R >> 4) & 0xff) << 16) |
  417. (((MALIDP_BGND_COLOR_G >> 4) & 0xff) << 8) |
  418. ((MALIDP_BGND_COLOR_B >> 4) & 0xff);
  419. malidp_hw_write(hwdev, val, MALIDP550_DE_BGND_COLOR);
  420. val = MALIDP_DE_H_FRONTPORCH(mode->hfront_porch) |
  421. MALIDP_DE_H_BACKPORCH(mode->hback_porch);
  422. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_H_TIMINGS);
  423. val = MALIDP550_DE_V_FRONTPORCH(mode->vfront_porch) |
  424. MALIDP_DE_V_BACKPORCH(mode->vback_porch);
  425. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_V_TIMINGS);
  426. val = MALIDP_DE_H_SYNCWIDTH(mode->hsync_len) |
  427. MALIDP_DE_V_SYNCWIDTH(mode->vsync_len);
  428. if (mode->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  429. val |= MALIDP550_HSYNCPOL;
  430. if (mode->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  431. val |= MALIDP550_VSYNCPOL;
  432. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_SYNC_WIDTH);
  433. val = MALIDP_DE_H_ACTIVE(mode->hactive) | MALIDP_DE_V_ACTIVE(mode->vactive);
  434. malidp_hw_write(hwdev, val, MALIDP550_TIMINGS_BASE + MALIDP_DE_HV_ACTIVE);
  435. if (mode->flags & DISPLAY_FLAGS_INTERLACED)
  436. malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  437. else
  438. malidp_hw_clearbits(hwdev, MALIDP_DISP_FUNC_ILACED, MALIDP_DE_DISPLAY_FUNC);
  439. }
  440. static int malidp550_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt)
  441. {
  442. u32 bytes_per_col;
  443. /* raw RGB888 or BGR888 can't be rotated */
  444. if ((fmt == DRM_FORMAT_RGB888) || (fmt == DRM_FORMAT_BGR888))
  445. return -EINVAL;
  446. switch (fmt) {
  447. /* 8 lines at 4 bytes per pixel */
  448. case DRM_FORMAT_ARGB2101010:
  449. case DRM_FORMAT_ABGR2101010:
  450. case DRM_FORMAT_RGBA1010102:
  451. case DRM_FORMAT_BGRA1010102:
  452. case DRM_FORMAT_ARGB8888:
  453. case DRM_FORMAT_ABGR8888:
  454. case DRM_FORMAT_RGBA8888:
  455. case DRM_FORMAT_BGRA8888:
  456. case DRM_FORMAT_XRGB8888:
  457. case DRM_FORMAT_XBGR8888:
  458. case DRM_FORMAT_RGBX8888:
  459. case DRM_FORMAT_BGRX8888:
  460. case DRM_FORMAT_RGB888:
  461. case DRM_FORMAT_BGR888:
  462. /* 16 lines at 2 bytes per pixel */
  463. case DRM_FORMAT_RGBA5551:
  464. case DRM_FORMAT_ABGR1555:
  465. case DRM_FORMAT_RGB565:
  466. case DRM_FORMAT_BGR565:
  467. case DRM_FORMAT_UYVY:
  468. case DRM_FORMAT_YUYV:
  469. bytes_per_col = 32;
  470. break;
  471. /* 16 lines at 1.5 bytes per pixel */
  472. case DRM_FORMAT_NV12:
  473. case DRM_FORMAT_YUV420:
  474. bytes_per_col = 24;
  475. break;
  476. default:
  477. return -EINVAL;
  478. }
  479. return w * bytes_per_col;
  480. }
  481. static int malidp550_se_set_scaling_coeffs(struct malidp_hw_device *hwdev,
  482. struct malidp_se_config *se_config,
  483. struct malidp_se_config *old_config)
  484. {
  485. u32 mask = MALIDP550_SE_CTL_VCSEL(MALIDP550_SE_CTL_SEL_MASK) |
  486. MALIDP550_SE_CTL_HCSEL(MALIDP550_SE_CTL_SEL_MASK);
  487. u32 new_value = MALIDP550_SE_CTL_VCSEL(se_config->vcoeff) |
  488. MALIDP550_SE_CTL_HCSEL(se_config->hcoeff);
  489. malidp_hw_clearbits(hwdev, mask, MALIDP550_SE_CONTROL);
  490. malidp_hw_setbits(hwdev, new_value, MALIDP550_SE_CONTROL);
  491. return 0;
  492. }
  493. static long malidp550_se_calc_mclk(struct malidp_hw_device *hwdev,
  494. struct malidp_se_config *se_config,
  495. struct videomode *vm)
  496. {
  497. unsigned long mclk;
  498. unsigned long pxlclk = vm->pixelclock;
  499. unsigned long htotal = vm->hactive + vm->hfront_porch +
  500. vm->hback_porch + vm->hsync_len;
  501. unsigned long numerator = 1, denominator = 1;
  502. long ret;
  503. if (se_config->scale_enable) {
  504. numerator = max(se_config->input_w, se_config->output_w) *
  505. se_config->input_h;
  506. numerator += se_config->output_w *
  507. (se_config->output_h -
  508. min(se_config->input_h, se_config->output_h));
  509. denominator = (htotal - 2) * se_config->output_h;
  510. }
  511. /* mclk can't be slower than pxlclk. */
  512. if (numerator < denominator)
  513. numerator = denominator = 1;
  514. mclk = (pxlclk * numerator) / denominator;
  515. ret = clk_get_rate(hwdev->mclk);
  516. if (ret < mclk) {
  517. DRM_DEBUG_DRIVER("mclk requirement of %lu kHz can't be met.\n",
  518. mclk / 1000);
  519. return -EINVAL;
  520. }
  521. return ret;
  522. }
  523. static int malidp650_query_hw(struct malidp_hw_device *hwdev)
  524. {
  525. u32 conf = malidp_hw_read(hwdev, MALIDP550_CONFIG_ID);
  526. u8 ln_size = (conf >> 4) & 0x3, rsize;
  527. hwdev->min_line_size = 4;
  528. switch (ln_size) {
  529. case 0:
  530. case 2:
  531. /* reserved values */
  532. hwdev->max_line_size = 0;
  533. return -EINVAL;
  534. case 1:
  535. hwdev->max_line_size = SZ_4K;
  536. /* two banks of 128KB for rotation memory */
  537. rsize = 128;
  538. break;
  539. case 3:
  540. hwdev->max_line_size = 2560;
  541. /* two banks of 80KB for rotation memory */
  542. rsize = 80;
  543. }
  544. hwdev->rotation_memory[0] = hwdev->rotation_memory[1] = rsize * SZ_1K;
  545. return 0;
  546. }
  547. const struct malidp_hw malidp_device[MALIDP_MAX_DEVICES] = {
  548. [MALIDP_500] = {
  549. .map = {
  550. .coeffs_base = MALIDP500_COEFFS_BASE,
  551. .se_base = MALIDP500_SE_BASE,
  552. .dc_base = MALIDP500_DC_BASE,
  553. .out_depth_base = MALIDP500_OUTPUT_DEPTH,
  554. .features = 0, /* no CLEARIRQ register */
  555. .n_layers = ARRAY_SIZE(malidp500_layers),
  556. .layers = malidp500_layers,
  557. .de_irq_map = {
  558. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  559. MALIDP500_DE_IRQ_AXI_ERR |
  560. MALIDP500_DE_IRQ_VSYNC |
  561. MALIDP500_DE_IRQ_GLOBAL,
  562. .vsync_irq = MALIDP500_DE_IRQ_VSYNC,
  563. },
  564. .se_irq_map = {
  565. .irq_mask = MALIDP500_SE_IRQ_CONF_MODE,
  566. .vsync_irq = 0,
  567. },
  568. .dc_irq_map = {
  569. .irq_mask = MALIDP500_DE_IRQ_CONF_VALID,
  570. .vsync_irq = MALIDP500_DE_IRQ_CONF_VALID,
  571. },
  572. .pixel_formats = malidp500_de_formats,
  573. .n_pixel_formats = ARRAY_SIZE(malidp500_de_formats),
  574. .bus_align_bytes = 8,
  575. },
  576. .query_hw = malidp500_query_hw,
  577. .enter_config_mode = malidp500_enter_config_mode,
  578. .leave_config_mode = malidp500_leave_config_mode,
  579. .in_config_mode = malidp500_in_config_mode,
  580. .set_config_valid = malidp500_set_config_valid,
  581. .modeset = malidp500_modeset,
  582. .rotmem_required = malidp500_rotmem_required,
  583. .se_set_scaling_coeffs = malidp500_se_set_scaling_coeffs,
  584. .se_calc_mclk = malidp500_se_calc_mclk,
  585. .features = MALIDP_DEVICE_LV_HAS_3_STRIDES,
  586. },
  587. [MALIDP_550] = {
  588. .map = {
  589. .coeffs_base = MALIDP550_COEFFS_BASE,
  590. .se_base = MALIDP550_SE_BASE,
  591. .dc_base = MALIDP550_DC_BASE,
  592. .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH,
  593. .features = MALIDP_REGMAP_HAS_CLEARIRQ,
  594. .n_layers = ARRAY_SIZE(malidp550_layers),
  595. .layers = malidp550_layers,
  596. .de_irq_map = {
  597. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  598. MALIDP550_DE_IRQ_VSYNC,
  599. .vsync_irq = MALIDP550_DE_IRQ_VSYNC,
  600. },
  601. .se_irq_map = {
  602. .irq_mask = MALIDP550_SE_IRQ_EOW |
  603. MALIDP550_SE_IRQ_AXI_ERR,
  604. },
  605. .dc_irq_map = {
  606. .irq_mask = MALIDP550_DC_IRQ_CONF_VALID,
  607. .vsync_irq = MALIDP550_DC_IRQ_CONF_VALID,
  608. },
  609. .pixel_formats = malidp550_de_formats,
  610. .n_pixel_formats = ARRAY_SIZE(malidp550_de_formats),
  611. .bus_align_bytes = 8,
  612. },
  613. .query_hw = malidp550_query_hw,
  614. .enter_config_mode = malidp550_enter_config_mode,
  615. .leave_config_mode = malidp550_leave_config_mode,
  616. .in_config_mode = malidp550_in_config_mode,
  617. .set_config_valid = malidp550_set_config_valid,
  618. .modeset = malidp550_modeset,
  619. .rotmem_required = malidp550_rotmem_required,
  620. .se_set_scaling_coeffs = malidp550_se_set_scaling_coeffs,
  621. .se_calc_mclk = malidp550_se_calc_mclk,
  622. .features = 0,
  623. },
  624. [MALIDP_650] = {
  625. .map = {
  626. .coeffs_base = MALIDP550_COEFFS_BASE,
  627. .se_base = MALIDP550_SE_BASE,
  628. .dc_base = MALIDP550_DC_BASE,
  629. .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH,
  630. .features = MALIDP_REGMAP_HAS_CLEARIRQ,
  631. .n_layers = ARRAY_SIZE(malidp550_layers),
  632. .layers = malidp550_layers,
  633. .de_irq_map = {
  634. .irq_mask = MALIDP_DE_IRQ_UNDERRUN |
  635. MALIDP650_DE_IRQ_DRIFT |
  636. MALIDP550_DE_IRQ_VSYNC,
  637. .vsync_irq = MALIDP550_DE_IRQ_VSYNC,
  638. },
  639. .se_irq_map = {
  640. .irq_mask = MALIDP550_SE_IRQ_EOW |
  641. MALIDP550_SE_IRQ_AXI_ERR,
  642. },
  643. .dc_irq_map = {
  644. .irq_mask = MALIDP550_DC_IRQ_CONF_VALID,
  645. .vsync_irq = MALIDP550_DC_IRQ_CONF_VALID,
  646. },
  647. .pixel_formats = malidp550_de_formats,
  648. .n_pixel_formats = ARRAY_SIZE(malidp550_de_formats),
  649. .bus_align_bytes = 16,
  650. },
  651. .query_hw = malidp650_query_hw,
  652. .enter_config_mode = malidp550_enter_config_mode,
  653. .leave_config_mode = malidp550_leave_config_mode,
  654. .in_config_mode = malidp550_in_config_mode,
  655. .set_config_valid = malidp550_set_config_valid,
  656. .modeset = malidp550_modeset,
  657. .rotmem_required = malidp550_rotmem_required,
  658. .se_set_scaling_coeffs = malidp550_se_set_scaling_coeffs,
  659. .se_calc_mclk = malidp550_se_calc_mclk,
  660. .features = 0,
  661. },
  662. };
  663. u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
  664. u8 layer_id, u32 format)
  665. {
  666. unsigned int i;
  667. for (i = 0; i < map->n_pixel_formats; i++) {
  668. if (((map->pixel_formats[i].layer & layer_id) == layer_id) &&
  669. (map->pixel_formats[i].format == format))
  670. return map->pixel_formats[i].id;
  671. }
  672. return MALIDP_INVALID_FORMAT_ID;
  673. }
  674. static void malidp_hw_clear_irq(struct malidp_hw_device *hwdev, u8 block, u32 irq)
  675. {
  676. u32 base = malidp_get_block_base(hwdev, block);
  677. if (hwdev->hw->map.features & MALIDP_REGMAP_HAS_CLEARIRQ)
  678. malidp_hw_write(hwdev, irq, base + MALIDP_REG_CLEARIRQ);
  679. else
  680. malidp_hw_write(hwdev, irq, base + MALIDP_REG_STATUS);
  681. }
  682. static irqreturn_t malidp_de_irq(int irq, void *arg)
  683. {
  684. struct drm_device *drm = arg;
  685. struct malidp_drm *malidp = drm->dev_private;
  686. struct malidp_hw_device *hwdev;
  687. struct malidp_hw *hw;
  688. const struct malidp_irq_map *de;
  689. u32 status, mask, dc_status;
  690. irqreturn_t ret = IRQ_NONE;
  691. hwdev = malidp->dev;
  692. hw = hwdev->hw;
  693. de = &hw->map.de_irq_map;
  694. /*
  695. * if we are suspended it is likely that we were invoked because
  696. * we share an interrupt line with some other driver, don't try
  697. * to read the hardware registers
  698. */
  699. if (hwdev->pm_suspended)
  700. return IRQ_NONE;
  701. /* first handle the config valid IRQ */
  702. dc_status = malidp_hw_read(hwdev, hw->map.dc_base + MALIDP_REG_STATUS);
  703. if (dc_status & hw->map.dc_irq_map.vsync_irq) {
  704. /* we have a page flip event */
  705. atomic_set(&malidp->config_valid, 1);
  706. malidp_hw_clear_irq(hwdev, MALIDP_DC_BLOCK, dc_status);
  707. ret = IRQ_WAKE_THREAD;
  708. }
  709. status = malidp_hw_read(hwdev, MALIDP_REG_STATUS);
  710. if (!(status & de->irq_mask))
  711. return ret;
  712. mask = malidp_hw_read(hwdev, MALIDP_REG_MASKIRQ);
  713. status &= mask;
  714. if (status & de->vsync_irq)
  715. drm_crtc_handle_vblank(&malidp->crtc);
  716. malidp_hw_clear_irq(hwdev, MALIDP_DE_BLOCK, status);
  717. return (ret == IRQ_NONE) ? IRQ_HANDLED : ret;
  718. }
  719. static irqreturn_t malidp_de_irq_thread_handler(int irq, void *arg)
  720. {
  721. struct drm_device *drm = arg;
  722. struct malidp_drm *malidp = drm->dev_private;
  723. wake_up(&malidp->wq);
  724. return IRQ_HANDLED;
  725. }
  726. int malidp_de_irq_init(struct drm_device *drm, int irq)
  727. {
  728. struct malidp_drm *malidp = drm->dev_private;
  729. struct malidp_hw_device *hwdev = malidp->dev;
  730. int ret;
  731. /* ensure interrupts are disabled */
  732. malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK, 0xffffffff);
  733. malidp_hw_clear_irq(hwdev, MALIDP_DE_BLOCK, 0xffffffff);
  734. malidp_hw_disable_irq(hwdev, MALIDP_DC_BLOCK, 0xffffffff);
  735. malidp_hw_clear_irq(hwdev, MALIDP_DC_BLOCK, 0xffffffff);
  736. ret = devm_request_threaded_irq(drm->dev, irq, malidp_de_irq,
  737. malidp_de_irq_thread_handler,
  738. IRQF_SHARED, "malidp-de", drm);
  739. if (ret < 0) {
  740. DRM_ERROR("failed to install DE IRQ handler\n");
  741. return ret;
  742. }
  743. /* first enable the DC block IRQs */
  744. malidp_hw_enable_irq(hwdev, MALIDP_DC_BLOCK,
  745. hwdev->hw->map.dc_irq_map.irq_mask);
  746. /* now enable the DE block IRQs */
  747. malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK,
  748. hwdev->hw->map.de_irq_map.irq_mask);
  749. return 0;
  750. }
  751. void malidp_de_irq_fini(struct drm_device *drm)
  752. {
  753. struct malidp_drm *malidp = drm->dev_private;
  754. struct malidp_hw_device *hwdev = malidp->dev;
  755. malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK,
  756. hwdev->hw->map.de_irq_map.irq_mask);
  757. malidp_hw_disable_irq(hwdev, MALIDP_DC_BLOCK,
  758. hwdev->hw->map.dc_irq_map.irq_mask);
  759. }
  760. static irqreturn_t malidp_se_irq(int irq, void *arg)
  761. {
  762. struct drm_device *drm = arg;
  763. struct malidp_drm *malidp = drm->dev_private;
  764. struct malidp_hw_device *hwdev = malidp->dev;
  765. struct malidp_hw *hw = hwdev->hw;
  766. const struct malidp_irq_map *se = &hw->map.se_irq_map;
  767. u32 status, mask;
  768. /*
  769. * if we are suspended it is likely that we were invoked because
  770. * we share an interrupt line with some other driver, don't try
  771. * to read the hardware registers
  772. */
  773. if (hwdev->pm_suspended)
  774. return IRQ_NONE;
  775. status = malidp_hw_read(hwdev, hw->map.se_base + MALIDP_REG_STATUS);
  776. if (!(status & se->irq_mask))
  777. return IRQ_NONE;
  778. mask = malidp_hw_read(hwdev, hw->map.se_base + MALIDP_REG_MASKIRQ);
  779. status = malidp_hw_read(hwdev, hw->map.se_base + MALIDP_REG_STATUS);
  780. status &= mask;
  781. /* ToDo: status decoding and firing up of VSYNC and page flip events */
  782. malidp_hw_clear_irq(hwdev, MALIDP_SE_BLOCK, status);
  783. return IRQ_HANDLED;
  784. }
  785. static irqreturn_t malidp_se_irq_thread_handler(int irq, void *arg)
  786. {
  787. return IRQ_HANDLED;
  788. }
  789. int malidp_se_irq_init(struct drm_device *drm, int irq)
  790. {
  791. struct malidp_drm *malidp = drm->dev_private;
  792. struct malidp_hw_device *hwdev = malidp->dev;
  793. int ret;
  794. /* ensure interrupts are disabled */
  795. malidp_hw_disable_irq(hwdev, MALIDP_SE_BLOCK, 0xffffffff);
  796. malidp_hw_clear_irq(hwdev, MALIDP_SE_BLOCK, 0xffffffff);
  797. ret = devm_request_threaded_irq(drm->dev, irq, malidp_se_irq,
  798. malidp_se_irq_thread_handler,
  799. IRQF_SHARED, "malidp-se", drm);
  800. if (ret < 0) {
  801. DRM_ERROR("failed to install SE IRQ handler\n");
  802. return ret;
  803. }
  804. malidp_hw_enable_irq(hwdev, MALIDP_SE_BLOCK,
  805. hwdev->hw->map.se_irq_map.irq_mask);
  806. return 0;
  807. }
  808. void malidp_se_irq_fini(struct drm_device *drm)
  809. {
  810. struct malidp_drm *malidp = drm->dev_private;
  811. struct malidp_hw_device *hwdev = malidp->dev;
  812. malidp_hw_disable_irq(hwdev, MALIDP_SE_BLOCK,
  813. hwdev->hw->map.se_irq_map.irq_mask);
  814. }