exynos_mixer.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Seung-Woo Kim <sw0312.kim@samsung.com>
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * Based on drivers/media/video/s5p-tv/mixer_reg.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <drm/drmP.h>
  17. #include "regs-mixer.h"
  18. #include "regs-vp.h"
  19. #include <linux/kernel.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/wait.h>
  22. #include <linux/i2c.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/delay.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/clk.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/of.h>
  31. #include <linux/of_device.h>
  32. #include <linux/component.h>
  33. #include <drm/exynos_drm.h>
  34. #include "exynos_drm_drv.h"
  35. #include "exynos_drm_crtc.h"
  36. #include "exynos_drm_fb.h"
  37. #include "exynos_drm_plane.h"
  38. #include "exynos_drm_iommu.h"
  39. #define MIXER_WIN_NR 3
  40. #define VP_DEFAULT_WIN 2
  41. /* The pixelformats that are natively supported by the mixer. */
  42. #define MXR_FORMAT_RGB565 4
  43. #define MXR_FORMAT_ARGB1555 5
  44. #define MXR_FORMAT_ARGB4444 6
  45. #define MXR_FORMAT_ARGB8888 7
  46. struct mixer_resources {
  47. int irq;
  48. void __iomem *mixer_regs;
  49. void __iomem *vp_regs;
  50. spinlock_t reg_slock;
  51. struct clk *mixer;
  52. struct clk *vp;
  53. struct clk *hdmi;
  54. struct clk *sclk_mixer;
  55. struct clk *sclk_hdmi;
  56. struct clk *mout_mixer;
  57. };
  58. enum mixer_version_id {
  59. MXR_VER_0_0_0_16,
  60. MXR_VER_16_0_33_0,
  61. MXR_VER_128_0_0_184,
  62. };
  63. enum mixer_flag_bits {
  64. MXR_BIT_POWERED,
  65. MXR_BIT_VSYNC,
  66. MXR_BIT_INTERLACE,
  67. MXR_BIT_VP_ENABLED,
  68. MXR_BIT_HAS_SCLK,
  69. };
  70. static const uint32_t mixer_formats[] = {
  71. DRM_FORMAT_XRGB4444,
  72. DRM_FORMAT_ARGB4444,
  73. DRM_FORMAT_XRGB1555,
  74. DRM_FORMAT_ARGB1555,
  75. DRM_FORMAT_RGB565,
  76. DRM_FORMAT_XRGB8888,
  77. DRM_FORMAT_ARGB8888,
  78. };
  79. static const uint32_t vp_formats[] = {
  80. DRM_FORMAT_NV12,
  81. DRM_FORMAT_NV21,
  82. };
  83. struct mixer_context {
  84. struct platform_device *pdev;
  85. struct device *dev;
  86. struct drm_device *drm_dev;
  87. struct exynos_drm_crtc *crtc;
  88. struct exynos_drm_plane planes[MIXER_WIN_NR];
  89. int pipe;
  90. unsigned long flags;
  91. struct mixer_resources mixer_res;
  92. enum mixer_version_id mxr_ver;
  93. };
  94. struct mixer_drv_data {
  95. enum mixer_version_id version;
  96. bool is_vp_enabled;
  97. bool has_sclk;
  98. };
  99. static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
  100. {
  101. .zpos = 0,
  102. .type = DRM_PLANE_TYPE_PRIMARY,
  103. .pixel_formats = mixer_formats,
  104. .num_pixel_formats = ARRAY_SIZE(mixer_formats),
  105. .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
  106. EXYNOS_DRM_PLANE_CAP_ZPOS,
  107. }, {
  108. .zpos = 1,
  109. .type = DRM_PLANE_TYPE_CURSOR,
  110. .pixel_formats = mixer_formats,
  111. .num_pixel_formats = ARRAY_SIZE(mixer_formats),
  112. .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
  113. EXYNOS_DRM_PLANE_CAP_ZPOS,
  114. }, {
  115. .zpos = 2,
  116. .type = DRM_PLANE_TYPE_OVERLAY,
  117. .pixel_formats = vp_formats,
  118. .num_pixel_formats = ARRAY_SIZE(vp_formats),
  119. .capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
  120. EXYNOS_DRM_PLANE_CAP_ZPOS,
  121. },
  122. };
  123. static const u8 filter_y_horiz_tap8[] = {
  124. 0, -1, -1, -1, -1, -1, -1, -1,
  125. -1, -1, -1, -1, -1, 0, 0, 0,
  126. 0, 2, 4, 5, 6, 6, 6, 6,
  127. 6, 5, 5, 4, 3, 2, 1, 1,
  128. 0, -6, -12, -16, -18, -20, -21, -20,
  129. -20, -18, -16, -13, -10, -8, -5, -2,
  130. 127, 126, 125, 121, 114, 107, 99, 89,
  131. 79, 68, 57, 46, 35, 25, 16, 8,
  132. };
  133. static const u8 filter_y_vert_tap4[] = {
  134. 0, -3, -6, -8, -8, -8, -8, -7,
  135. -6, -5, -4, -3, -2, -1, -1, 0,
  136. 127, 126, 124, 118, 111, 102, 92, 81,
  137. 70, 59, 48, 37, 27, 19, 11, 5,
  138. 0, 5, 11, 19, 27, 37, 48, 59,
  139. 70, 81, 92, 102, 111, 118, 124, 126,
  140. 0, 0, -1, -1, -2, -3, -4, -5,
  141. -6, -7, -8, -8, -8, -8, -6, -3,
  142. };
  143. static const u8 filter_cr_horiz_tap4[] = {
  144. 0, -3, -6, -8, -8, -8, -8, -7,
  145. -6, -5, -4, -3, -2, -1, -1, 0,
  146. 127, 126, 124, 118, 111, 102, 92, 81,
  147. 70, 59, 48, 37, 27, 19, 11, 5,
  148. };
  149. static inline bool is_alpha_format(unsigned int pixel_format)
  150. {
  151. switch (pixel_format) {
  152. case DRM_FORMAT_ARGB8888:
  153. case DRM_FORMAT_ARGB1555:
  154. case DRM_FORMAT_ARGB4444:
  155. return true;
  156. default:
  157. return false;
  158. }
  159. }
  160. static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
  161. {
  162. return readl(res->vp_regs + reg_id);
  163. }
  164. static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
  165. u32 val)
  166. {
  167. writel(val, res->vp_regs + reg_id);
  168. }
  169. static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
  170. u32 val, u32 mask)
  171. {
  172. u32 old = vp_reg_read(res, reg_id);
  173. val = (val & mask) | (old & ~mask);
  174. writel(val, res->vp_regs + reg_id);
  175. }
  176. static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
  177. {
  178. return readl(res->mixer_regs + reg_id);
  179. }
  180. static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
  181. u32 val)
  182. {
  183. writel(val, res->mixer_regs + reg_id);
  184. }
  185. static inline void mixer_reg_writemask(struct mixer_resources *res,
  186. u32 reg_id, u32 val, u32 mask)
  187. {
  188. u32 old = mixer_reg_read(res, reg_id);
  189. val = (val & mask) | (old & ~mask);
  190. writel(val, res->mixer_regs + reg_id);
  191. }
  192. static void mixer_regs_dump(struct mixer_context *ctx)
  193. {
  194. #define DUMPREG(reg_id) \
  195. do { \
  196. DRM_DEBUG_KMS(#reg_id " = %08x\n", \
  197. (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
  198. } while (0)
  199. DUMPREG(MXR_STATUS);
  200. DUMPREG(MXR_CFG);
  201. DUMPREG(MXR_INT_EN);
  202. DUMPREG(MXR_INT_STATUS);
  203. DUMPREG(MXR_LAYER_CFG);
  204. DUMPREG(MXR_VIDEO_CFG);
  205. DUMPREG(MXR_GRAPHIC0_CFG);
  206. DUMPREG(MXR_GRAPHIC0_BASE);
  207. DUMPREG(MXR_GRAPHIC0_SPAN);
  208. DUMPREG(MXR_GRAPHIC0_WH);
  209. DUMPREG(MXR_GRAPHIC0_SXY);
  210. DUMPREG(MXR_GRAPHIC0_DXY);
  211. DUMPREG(MXR_GRAPHIC1_CFG);
  212. DUMPREG(MXR_GRAPHIC1_BASE);
  213. DUMPREG(MXR_GRAPHIC1_SPAN);
  214. DUMPREG(MXR_GRAPHIC1_WH);
  215. DUMPREG(MXR_GRAPHIC1_SXY);
  216. DUMPREG(MXR_GRAPHIC1_DXY);
  217. #undef DUMPREG
  218. }
  219. static void vp_regs_dump(struct mixer_context *ctx)
  220. {
  221. #define DUMPREG(reg_id) \
  222. do { \
  223. DRM_DEBUG_KMS(#reg_id " = %08x\n", \
  224. (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
  225. } while (0)
  226. DUMPREG(VP_ENABLE);
  227. DUMPREG(VP_SRESET);
  228. DUMPREG(VP_SHADOW_UPDATE);
  229. DUMPREG(VP_FIELD_ID);
  230. DUMPREG(VP_MODE);
  231. DUMPREG(VP_IMG_SIZE_Y);
  232. DUMPREG(VP_IMG_SIZE_C);
  233. DUMPREG(VP_PER_RATE_CTRL);
  234. DUMPREG(VP_TOP_Y_PTR);
  235. DUMPREG(VP_BOT_Y_PTR);
  236. DUMPREG(VP_TOP_C_PTR);
  237. DUMPREG(VP_BOT_C_PTR);
  238. DUMPREG(VP_ENDIAN_MODE);
  239. DUMPREG(VP_SRC_H_POSITION);
  240. DUMPREG(VP_SRC_V_POSITION);
  241. DUMPREG(VP_SRC_WIDTH);
  242. DUMPREG(VP_SRC_HEIGHT);
  243. DUMPREG(VP_DST_H_POSITION);
  244. DUMPREG(VP_DST_V_POSITION);
  245. DUMPREG(VP_DST_WIDTH);
  246. DUMPREG(VP_DST_HEIGHT);
  247. DUMPREG(VP_H_RATIO);
  248. DUMPREG(VP_V_RATIO);
  249. #undef DUMPREG
  250. }
  251. static inline void vp_filter_set(struct mixer_resources *res,
  252. int reg_id, const u8 *data, unsigned int size)
  253. {
  254. /* assure 4-byte align */
  255. BUG_ON(size & 3);
  256. for (; size; size -= 4, reg_id += 4, data += 4) {
  257. u32 val = (data[0] << 24) | (data[1] << 16) |
  258. (data[2] << 8) | data[3];
  259. vp_reg_write(res, reg_id, val);
  260. }
  261. }
  262. static void vp_default_filter(struct mixer_resources *res)
  263. {
  264. vp_filter_set(res, VP_POLY8_Y0_LL,
  265. filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
  266. vp_filter_set(res, VP_POLY4_Y0_LL,
  267. filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
  268. vp_filter_set(res, VP_POLY4_C0_LL,
  269. filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
  270. }
  271. static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win,
  272. bool alpha)
  273. {
  274. struct mixer_resources *res = &ctx->mixer_res;
  275. u32 val;
  276. val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
  277. if (alpha) {
  278. /* blending based on pixel alpha */
  279. val |= MXR_GRP_CFG_BLEND_PRE_MUL;
  280. val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
  281. }
  282. mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
  283. val, MXR_GRP_CFG_MISC_MASK);
  284. }
  285. static void mixer_cfg_vp_blend(struct mixer_context *ctx)
  286. {
  287. struct mixer_resources *res = &ctx->mixer_res;
  288. u32 val;
  289. /*
  290. * No blending at the moment since the NV12/NV21 pixelformats don't
  291. * have an alpha channel. However the mixer supports a global alpha
  292. * value for a layer. Once this functionality is exposed, we can
  293. * support blending of the video layer through this.
  294. */
  295. val = 0;
  296. mixer_reg_write(res, MXR_VIDEO_CFG, val);
  297. }
  298. static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
  299. {
  300. struct mixer_resources *res = &ctx->mixer_res;
  301. /* block update on vsync */
  302. mixer_reg_writemask(res, MXR_STATUS, enable ?
  303. MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
  304. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
  305. vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
  306. VP_SHADOW_UPDATE_ENABLE : 0);
  307. }
  308. static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
  309. {
  310. struct mixer_resources *res = &ctx->mixer_res;
  311. u32 val;
  312. /* choosing between interlace and progressive mode */
  313. val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
  314. MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
  315. if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
  316. /* choosing between proper HD and SD mode */
  317. if (height <= 480)
  318. val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
  319. else if (height <= 576)
  320. val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
  321. else if (height <= 720)
  322. val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
  323. else if (height <= 1080)
  324. val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
  325. else
  326. val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
  327. }
  328. mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
  329. }
  330. static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
  331. {
  332. struct mixer_resources *res = &ctx->mixer_res;
  333. u32 val;
  334. if (height == 480) {
  335. val = MXR_CFG_RGB601_0_255;
  336. } else if (height == 576) {
  337. val = MXR_CFG_RGB601_0_255;
  338. } else if (height == 720) {
  339. val = MXR_CFG_RGB709_16_235;
  340. mixer_reg_write(res, MXR_CM_COEFF_Y,
  341. (1 << 30) | (94 << 20) | (314 << 10) |
  342. (32 << 0));
  343. mixer_reg_write(res, MXR_CM_COEFF_CB,
  344. (972 << 20) | (851 << 10) | (225 << 0));
  345. mixer_reg_write(res, MXR_CM_COEFF_CR,
  346. (225 << 20) | (820 << 10) | (1004 << 0));
  347. } else if (height == 1080) {
  348. val = MXR_CFG_RGB709_16_235;
  349. mixer_reg_write(res, MXR_CM_COEFF_Y,
  350. (1 << 30) | (94 << 20) | (314 << 10) |
  351. (32 << 0));
  352. mixer_reg_write(res, MXR_CM_COEFF_CB,
  353. (972 << 20) | (851 << 10) | (225 << 0));
  354. mixer_reg_write(res, MXR_CM_COEFF_CR,
  355. (225 << 20) | (820 << 10) | (1004 << 0));
  356. } else {
  357. val = MXR_CFG_RGB709_16_235;
  358. mixer_reg_write(res, MXR_CM_COEFF_Y,
  359. (1 << 30) | (94 << 20) | (314 << 10) |
  360. (32 << 0));
  361. mixer_reg_write(res, MXR_CM_COEFF_CB,
  362. (972 << 20) | (851 << 10) | (225 << 0));
  363. mixer_reg_write(res, MXR_CM_COEFF_CR,
  364. (225 << 20) | (820 << 10) | (1004 << 0));
  365. }
  366. mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
  367. }
  368. static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
  369. unsigned int priority, bool enable)
  370. {
  371. struct mixer_resources *res = &ctx->mixer_res;
  372. u32 val = enable ? ~0 : 0;
  373. switch (win) {
  374. case 0:
  375. mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
  376. mixer_reg_writemask(res, MXR_LAYER_CFG,
  377. MXR_LAYER_CFG_GRP0_VAL(priority),
  378. MXR_LAYER_CFG_GRP0_MASK);
  379. break;
  380. case 1:
  381. mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
  382. mixer_reg_writemask(res, MXR_LAYER_CFG,
  383. MXR_LAYER_CFG_GRP1_VAL(priority),
  384. MXR_LAYER_CFG_GRP1_MASK);
  385. break;
  386. case VP_DEFAULT_WIN:
  387. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
  388. vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
  389. mixer_reg_writemask(res, MXR_CFG, val,
  390. MXR_CFG_VP_ENABLE);
  391. mixer_reg_writemask(res, MXR_LAYER_CFG,
  392. MXR_LAYER_CFG_VP_VAL(priority),
  393. MXR_LAYER_CFG_VP_MASK);
  394. }
  395. break;
  396. }
  397. }
  398. static void mixer_run(struct mixer_context *ctx)
  399. {
  400. struct mixer_resources *res = &ctx->mixer_res;
  401. mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
  402. }
  403. static void mixer_stop(struct mixer_context *ctx)
  404. {
  405. struct mixer_resources *res = &ctx->mixer_res;
  406. int timeout = 20;
  407. mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
  408. while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
  409. --timeout)
  410. usleep_range(10000, 12000);
  411. }
  412. static void vp_video_buffer(struct mixer_context *ctx,
  413. struct exynos_drm_plane *plane)
  414. {
  415. struct exynos_drm_plane_state *state =
  416. to_exynos_plane_state(plane->base.state);
  417. struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
  418. struct mixer_resources *res = &ctx->mixer_res;
  419. struct drm_framebuffer *fb = state->base.fb;
  420. unsigned int priority = state->base.normalized_zpos + 1;
  421. unsigned long flags;
  422. dma_addr_t luma_addr[2], chroma_addr[2];
  423. bool tiled_mode = false;
  424. bool crcb_mode = false;
  425. u32 val;
  426. switch (fb->format->format) {
  427. case DRM_FORMAT_NV12:
  428. crcb_mode = false;
  429. break;
  430. case DRM_FORMAT_NV21:
  431. crcb_mode = true;
  432. break;
  433. default:
  434. DRM_ERROR("pixel format for vp is wrong [%d].\n",
  435. fb->format->format);
  436. return;
  437. }
  438. luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
  439. chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
  440. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  441. __set_bit(MXR_BIT_INTERLACE, &ctx->flags);
  442. if (tiled_mode) {
  443. luma_addr[1] = luma_addr[0] + 0x40;
  444. chroma_addr[1] = chroma_addr[0] + 0x40;
  445. } else {
  446. luma_addr[1] = luma_addr[0] + fb->pitches[0];
  447. chroma_addr[1] = chroma_addr[0] + fb->pitches[0];
  448. }
  449. } else {
  450. __clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
  451. luma_addr[1] = 0;
  452. chroma_addr[1] = 0;
  453. }
  454. spin_lock_irqsave(&res->reg_slock, flags);
  455. /* interlace or progressive scan mode */
  456. val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
  457. vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
  458. /* setup format */
  459. val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
  460. val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
  461. vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
  462. /* setting size of input image */
  463. vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
  464. VP_IMG_VSIZE(fb->height));
  465. /* chroma height has to reduced by 2 to avoid chroma distorions */
  466. vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) |
  467. VP_IMG_VSIZE(fb->height / 2));
  468. vp_reg_write(res, VP_SRC_WIDTH, state->src.w);
  469. vp_reg_write(res, VP_SRC_HEIGHT, state->src.h);
  470. vp_reg_write(res, VP_SRC_H_POSITION,
  471. VP_SRC_H_POSITION_VAL(state->src.x));
  472. vp_reg_write(res, VP_SRC_V_POSITION, state->src.y);
  473. vp_reg_write(res, VP_DST_WIDTH, state->crtc.w);
  474. vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x);
  475. if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
  476. vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2);
  477. vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2);
  478. } else {
  479. vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h);
  480. vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y);
  481. }
  482. vp_reg_write(res, VP_H_RATIO, state->h_ratio);
  483. vp_reg_write(res, VP_V_RATIO, state->v_ratio);
  484. vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
  485. /* set buffer address to vp */
  486. vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
  487. vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
  488. vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
  489. vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
  490. mixer_cfg_scan(ctx, mode->vdisplay);
  491. mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
  492. mixer_cfg_layer(ctx, plane->index, priority, true);
  493. mixer_cfg_vp_blend(ctx);
  494. mixer_run(ctx);
  495. spin_unlock_irqrestore(&res->reg_slock, flags);
  496. mixer_regs_dump(ctx);
  497. vp_regs_dump(ctx);
  498. }
  499. static void mixer_layer_update(struct mixer_context *ctx)
  500. {
  501. struct mixer_resources *res = &ctx->mixer_res;
  502. mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
  503. }
  504. static void mixer_graph_buffer(struct mixer_context *ctx,
  505. struct exynos_drm_plane *plane)
  506. {
  507. struct exynos_drm_plane_state *state =
  508. to_exynos_plane_state(plane->base.state);
  509. struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
  510. struct mixer_resources *res = &ctx->mixer_res;
  511. struct drm_framebuffer *fb = state->base.fb;
  512. unsigned int priority = state->base.normalized_zpos + 1;
  513. unsigned long flags;
  514. unsigned int win = plane->index;
  515. unsigned int x_ratio = 0, y_ratio = 0;
  516. unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
  517. dma_addr_t dma_addr;
  518. unsigned int fmt;
  519. u32 val;
  520. switch (fb->format->format) {
  521. case DRM_FORMAT_XRGB4444:
  522. case DRM_FORMAT_ARGB4444:
  523. fmt = MXR_FORMAT_ARGB4444;
  524. break;
  525. case DRM_FORMAT_XRGB1555:
  526. case DRM_FORMAT_ARGB1555:
  527. fmt = MXR_FORMAT_ARGB1555;
  528. break;
  529. case DRM_FORMAT_RGB565:
  530. fmt = MXR_FORMAT_RGB565;
  531. break;
  532. case DRM_FORMAT_XRGB8888:
  533. case DRM_FORMAT_ARGB8888:
  534. fmt = MXR_FORMAT_ARGB8888;
  535. break;
  536. default:
  537. DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
  538. return;
  539. }
  540. /* ratio is already checked by common plane code */
  541. x_ratio = state->h_ratio == (1 << 15);
  542. y_ratio = state->v_ratio == (1 << 15);
  543. dst_x_offset = state->crtc.x;
  544. dst_y_offset = state->crtc.y;
  545. /* converting dma address base and source offset */
  546. dma_addr = exynos_drm_fb_dma_addr(fb, 0)
  547. + (state->src.x * fb->format->cpp[0])
  548. + (state->src.y * fb->pitches[0]);
  549. src_x_offset = 0;
  550. src_y_offset = 0;
  551. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  552. __set_bit(MXR_BIT_INTERLACE, &ctx->flags);
  553. else
  554. __clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
  555. spin_lock_irqsave(&res->reg_slock, flags);
  556. /* setup format */
  557. mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
  558. MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
  559. /* setup geometry */
  560. mixer_reg_write(res, MXR_GRAPHIC_SPAN(win),
  561. fb->pitches[0] / fb->format->cpp[0]);
  562. /* setup display size */
  563. if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
  564. win == DEFAULT_WIN) {
  565. val = MXR_MXR_RES_HEIGHT(mode->vdisplay);
  566. val |= MXR_MXR_RES_WIDTH(mode->hdisplay);
  567. mixer_reg_write(res, MXR_RESOLUTION, val);
  568. }
  569. val = MXR_GRP_WH_WIDTH(state->src.w);
  570. val |= MXR_GRP_WH_HEIGHT(state->src.h);
  571. val |= MXR_GRP_WH_H_SCALE(x_ratio);
  572. val |= MXR_GRP_WH_V_SCALE(y_ratio);
  573. mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
  574. /* setup offsets in source image */
  575. val = MXR_GRP_SXY_SX(src_x_offset);
  576. val |= MXR_GRP_SXY_SY(src_y_offset);
  577. mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
  578. /* setup offsets in display image */
  579. val = MXR_GRP_DXY_DX(dst_x_offset);
  580. val |= MXR_GRP_DXY_DY(dst_y_offset);
  581. mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
  582. /* set buffer address to mixer */
  583. mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
  584. mixer_cfg_scan(ctx, mode->vdisplay);
  585. mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
  586. mixer_cfg_layer(ctx, win, priority, true);
  587. mixer_cfg_gfx_blend(ctx, win, is_alpha_format(fb->format->format));
  588. /* layer update mandatory for mixer 16.0.33.0 */
  589. if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
  590. ctx->mxr_ver == MXR_VER_128_0_0_184)
  591. mixer_layer_update(ctx);
  592. mixer_run(ctx);
  593. spin_unlock_irqrestore(&res->reg_slock, flags);
  594. mixer_regs_dump(ctx);
  595. }
  596. static void vp_win_reset(struct mixer_context *ctx)
  597. {
  598. struct mixer_resources *res = &ctx->mixer_res;
  599. unsigned int tries = 100;
  600. vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
  601. while (tries--) {
  602. /* waiting until VP_SRESET_PROCESSING is 0 */
  603. if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
  604. break;
  605. mdelay(10);
  606. }
  607. WARN(tries == 0, "failed to reset Video Processor\n");
  608. }
  609. static void mixer_win_reset(struct mixer_context *ctx)
  610. {
  611. struct mixer_resources *res = &ctx->mixer_res;
  612. unsigned long flags;
  613. spin_lock_irqsave(&res->reg_slock, flags);
  614. mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
  615. /* set output in RGB888 mode */
  616. mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
  617. /* 16 beat burst in DMA */
  618. mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
  619. MXR_STATUS_BURST_MASK);
  620. /* reset default layer priority */
  621. mixer_reg_write(res, MXR_LAYER_CFG, 0);
  622. /* setting background color */
  623. mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
  624. mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
  625. mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
  626. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
  627. /* configuration of Video Processor Registers */
  628. vp_win_reset(ctx);
  629. vp_default_filter(res);
  630. }
  631. /* disable all layers */
  632. mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
  633. mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
  634. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
  635. mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
  636. spin_unlock_irqrestore(&res->reg_slock, flags);
  637. }
  638. static irqreturn_t mixer_irq_handler(int irq, void *arg)
  639. {
  640. struct mixer_context *ctx = arg;
  641. struct mixer_resources *res = &ctx->mixer_res;
  642. u32 val, base, shadow;
  643. spin_lock(&res->reg_slock);
  644. /* read interrupt status for handling and clearing flags for VSYNC */
  645. val = mixer_reg_read(res, MXR_INT_STATUS);
  646. /* handling VSYNC */
  647. if (val & MXR_INT_STATUS_VSYNC) {
  648. /* vsync interrupt use different bit for read and clear */
  649. val |= MXR_INT_CLEAR_VSYNC;
  650. val &= ~MXR_INT_STATUS_VSYNC;
  651. /* interlace scan need to check shadow register */
  652. if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
  653. base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
  654. shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
  655. if (base != shadow)
  656. goto out;
  657. base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
  658. shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
  659. if (base != shadow)
  660. goto out;
  661. }
  662. drm_crtc_handle_vblank(&ctx->crtc->base);
  663. }
  664. out:
  665. /* clear interrupts */
  666. mixer_reg_write(res, MXR_INT_STATUS, val);
  667. spin_unlock(&res->reg_slock);
  668. return IRQ_HANDLED;
  669. }
  670. static int mixer_resources_init(struct mixer_context *mixer_ctx)
  671. {
  672. struct device *dev = &mixer_ctx->pdev->dev;
  673. struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
  674. struct resource *res;
  675. int ret;
  676. spin_lock_init(&mixer_res->reg_slock);
  677. mixer_res->mixer = devm_clk_get(dev, "mixer");
  678. if (IS_ERR(mixer_res->mixer)) {
  679. dev_err(dev, "failed to get clock 'mixer'\n");
  680. return -ENODEV;
  681. }
  682. mixer_res->hdmi = devm_clk_get(dev, "hdmi");
  683. if (IS_ERR(mixer_res->hdmi)) {
  684. dev_err(dev, "failed to get clock 'hdmi'\n");
  685. return PTR_ERR(mixer_res->hdmi);
  686. }
  687. mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  688. if (IS_ERR(mixer_res->sclk_hdmi)) {
  689. dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
  690. return -ENODEV;
  691. }
  692. res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
  693. if (res == NULL) {
  694. dev_err(dev, "get memory resource failed.\n");
  695. return -ENXIO;
  696. }
  697. mixer_res->mixer_regs = devm_ioremap(dev, res->start,
  698. resource_size(res));
  699. if (mixer_res->mixer_regs == NULL) {
  700. dev_err(dev, "register mapping failed.\n");
  701. return -ENXIO;
  702. }
  703. res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
  704. if (res == NULL) {
  705. dev_err(dev, "get interrupt resource failed.\n");
  706. return -ENXIO;
  707. }
  708. ret = devm_request_irq(dev, res->start, mixer_irq_handler,
  709. 0, "drm_mixer", mixer_ctx);
  710. if (ret) {
  711. dev_err(dev, "request interrupt failed.\n");
  712. return ret;
  713. }
  714. mixer_res->irq = res->start;
  715. return 0;
  716. }
  717. static int vp_resources_init(struct mixer_context *mixer_ctx)
  718. {
  719. struct device *dev = &mixer_ctx->pdev->dev;
  720. struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
  721. struct resource *res;
  722. mixer_res->vp = devm_clk_get(dev, "vp");
  723. if (IS_ERR(mixer_res->vp)) {
  724. dev_err(dev, "failed to get clock 'vp'\n");
  725. return -ENODEV;
  726. }
  727. if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
  728. mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
  729. if (IS_ERR(mixer_res->sclk_mixer)) {
  730. dev_err(dev, "failed to get clock 'sclk_mixer'\n");
  731. return -ENODEV;
  732. }
  733. mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
  734. if (IS_ERR(mixer_res->mout_mixer)) {
  735. dev_err(dev, "failed to get clock 'mout_mixer'\n");
  736. return -ENODEV;
  737. }
  738. if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
  739. clk_set_parent(mixer_res->mout_mixer,
  740. mixer_res->sclk_hdmi);
  741. }
  742. res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
  743. if (res == NULL) {
  744. dev_err(dev, "get memory resource failed.\n");
  745. return -ENXIO;
  746. }
  747. mixer_res->vp_regs = devm_ioremap(dev, res->start,
  748. resource_size(res));
  749. if (mixer_res->vp_regs == NULL) {
  750. dev_err(dev, "register mapping failed.\n");
  751. return -ENXIO;
  752. }
  753. return 0;
  754. }
  755. static int mixer_initialize(struct mixer_context *mixer_ctx,
  756. struct drm_device *drm_dev)
  757. {
  758. int ret;
  759. struct exynos_drm_private *priv;
  760. priv = drm_dev->dev_private;
  761. mixer_ctx->drm_dev = drm_dev;
  762. mixer_ctx->pipe = priv->pipe++;
  763. /* acquire resources: regs, irqs, clocks */
  764. ret = mixer_resources_init(mixer_ctx);
  765. if (ret) {
  766. DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
  767. return ret;
  768. }
  769. if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
  770. /* acquire vp resources: regs, irqs, clocks */
  771. ret = vp_resources_init(mixer_ctx);
  772. if (ret) {
  773. DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
  774. return ret;
  775. }
  776. }
  777. ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
  778. if (ret)
  779. priv->pipe--;
  780. return ret;
  781. }
  782. static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
  783. {
  784. drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
  785. }
  786. static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
  787. {
  788. struct mixer_context *mixer_ctx = crtc->ctx;
  789. struct mixer_resources *res = &mixer_ctx->mixer_res;
  790. __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
  791. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  792. return 0;
  793. /* enable vsync interrupt */
  794. mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
  795. mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
  796. return 0;
  797. }
  798. static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
  799. {
  800. struct mixer_context *mixer_ctx = crtc->ctx;
  801. struct mixer_resources *res = &mixer_ctx->mixer_res;
  802. __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
  803. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  804. return;
  805. /* disable vsync interrupt */
  806. mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
  807. mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
  808. }
  809. static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
  810. {
  811. struct mixer_context *mixer_ctx = crtc->ctx;
  812. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  813. return;
  814. mixer_vsync_set_update(mixer_ctx, false);
  815. }
  816. static void mixer_update_plane(struct exynos_drm_crtc *crtc,
  817. struct exynos_drm_plane *plane)
  818. {
  819. struct mixer_context *mixer_ctx = crtc->ctx;
  820. DRM_DEBUG_KMS("win: %d\n", plane->index);
  821. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  822. return;
  823. if (plane->index == VP_DEFAULT_WIN)
  824. vp_video_buffer(mixer_ctx, plane);
  825. else
  826. mixer_graph_buffer(mixer_ctx, plane);
  827. }
  828. static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
  829. struct exynos_drm_plane *plane)
  830. {
  831. struct mixer_context *mixer_ctx = crtc->ctx;
  832. struct mixer_resources *res = &mixer_ctx->mixer_res;
  833. unsigned long flags;
  834. DRM_DEBUG_KMS("win: %d\n", plane->index);
  835. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  836. return;
  837. spin_lock_irqsave(&res->reg_slock, flags);
  838. mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
  839. spin_unlock_irqrestore(&res->reg_slock, flags);
  840. }
  841. static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
  842. {
  843. struct mixer_context *mixer_ctx = crtc->ctx;
  844. if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
  845. return;
  846. mixer_vsync_set_update(mixer_ctx, true);
  847. }
  848. static void mixer_enable(struct exynos_drm_crtc *crtc)
  849. {
  850. struct mixer_context *ctx = crtc->ctx;
  851. struct mixer_resources *res = &ctx->mixer_res;
  852. if (test_bit(MXR_BIT_POWERED, &ctx->flags))
  853. return;
  854. pm_runtime_get_sync(ctx->dev);
  855. exynos_drm_pipe_clk_enable(crtc, true);
  856. mixer_vsync_set_update(ctx, false);
  857. mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
  858. if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
  859. mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
  860. mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
  861. }
  862. mixer_win_reset(ctx);
  863. mixer_vsync_set_update(ctx, true);
  864. set_bit(MXR_BIT_POWERED, &ctx->flags);
  865. }
  866. static void mixer_disable(struct exynos_drm_crtc *crtc)
  867. {
  868. struct mixer_context *ctx = crtc->ctx;
  869. int i;
  870. if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
  871. return;
  872. mixer_stop(ctx);
  873. mixer_regs_dump(ctx);
  874. for (i = 0; i < MIXER_WIN_NR; i++)
  875. mixer_disable_plane(crtc, &ctx->planes[i]);
  876. exynos_drm_pipe_clk_enable(crtc, false);
  877. pm_runtime_put(ctx->dev);
  878. clear_bit(MXR_BIT_POWERED, &ctx->flags);
  879. }
  880. /* Only valid for Mixer version 16.0.33.0 */
  881. static int mixer_atomic_check(struct exynos_drm_crtc *crtc,
  882. struct drm_crtc_state *state)
  883. {
  884. struct drm_display_mode *mode = &state->adjusted_mode;
  885. u32 w, h;
  886. w = mode->hdisplay;
  887. h = mode->vdisplay;
  888. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
  889. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  890. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  891. if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
  892. (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
  893. (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
  894. return 0;
  895. return -EINVAL;
  896. }
  897. static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
  898. .enable = mixer_enable,
  899. .disable = mixer_disable,
  900. .enable_vblank = mixer_enable_vblank,
  901. .disable_vblank = mixer_disable_vblank,
  902. .atomic_begin = mixer_atomic_begin,
  903. .update_plane = mixer_update_plane,
  904. .disable_plane = mixer_disable_plane,
  905. .atomic_flush = mixer_atomic_flush,
  906. .atomic_check = mixer_atomic_check,
  907. };
  908. static struct mixer_drv_data exynos5420_mxr_drv_data = {
  909. .version = MXR_VER_128_0_0_184,
  910. .is_vp_enabled = 0,
  911. };
  912. static struct mixer_drv_data exynos5250_mxr_drv_data = {
  913. .version = MXR_VER_16_0_33_0,
  914. .is_vp_enabled = 0,
  915. };
  916. static struct mixer_drv_data exynos4212_mxr_drv_data = {
  917. .version = MXR_VER_0_0_0_16,
  918. .is_vp_enabled = 1,
  919. };
  920. static struct mixer_drv_data exynos4210_mxr_drv_data = {
  921. .version = MXR_VER_0_0_0_16,
  922. .is_vp_enabled = 1,
  923. .has_sclk = 1,
  924. };
  925. static struct of_device_id mixer_match_types[] = {
  926. {
  927. .compatible = "samsung,exynos4210-mixer",
  928. .data = &exynos4210_mxr_drv_data,
  929. }, {
  930. .compatible = "samsung,exynos4212-mixer",
  931. .data = &exynos4212_mxr_drv_data,
  932. }, {
  933. .compatible = "samsung,exynos5-mixer",
  934. .data = &exynos5250_mxr_drv_data,
  935. }, {
  936. .compatible = "samsung,exynos5250-mixer",
  937. .data = &exynos5250_mxr_drv_data,
  938. }, {
  939. .compatible = "samsung,exynos5420-mixer",
  940. .data = &exynos5420_mxr_drv_data,
  941. }, {
  942. /* end node */
  943. }
  944. };
  945. MODULE_DEVICE_TABLE(of, mixer_match_types);
  946. static int mixer_bind(struct device *dev, struct device *manager, void *data)
  947. {
  948. struct mixer_context *ctx = dev_get_drvdata(dev);
  949. struct drm_device *drm_dev = data;
  950. struct exynos_drm_plane *exynos_plane;
  951. unsigned int i;
  952. int ret;
  953. ret = mixer_initialize(ctx, drm_dev);
  954. if (ret)
  955. return ret;
  956. for (i = 0; i < MIXER_WIN_NR; i++) {
  957. if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
  958. &ctx->flags))
  959. continue;
  960. ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
  961. 1 << ctx->pipe, &plane_configs[i]);
  962. if (ret)
  963. return ret;
  964. }
  965. exynos_plane = &ctx->planes[DEFAULT_WIN];
  966. ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
  967. ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI,
  968. &mixer_crtc_ops, ctx);
  969. if (IS_ERR(ctx->crtc)) {
  970. mixer_ctx_remove(ctx);
  971. ret = PTR_ERR(ctx->crtc);
  972. goto free_ctx;
  973. }
  974. return 0;
  975. free_ctx:
  976. devm_kfree(dev, ctx);
  977. return ret;
  978. }
  979. static void mixer_unbind(struct device *dev, struct device *master, void *data)
  980. {
  981. struct mixer_context *ctx = dev_get_drvdata(dev);
  982. mixer_ctx_remove(ctx);
  983. }
  984. static const struct component_ops mixer_component_ops = {
  985. .bind = mixer_bind,
  986. .unbind = mixer_unbind,
  987. };
  988. static int mixer_probe(struct platform_device *pdev)
  989. {
  990. struct device *dev = &pdev->dev;
  991. const struct mixer_drv_data *drv;
  992. struct mixer_context *ctx;
  993. int ret;
  994. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  995. if (!ctx) {
  996. DRM_ERROR("failed to alloc mixer context.\n");
  997. return -ENOMEM;
  998. }
  999. drv = of_device_get_match_data(dev);
  1000. ctx->pdev = pdev;
  1001. ctx->dev = dev;
  1002. ctx->mxr_ver = drv->version;
  1003. if (drv->is_vp_enabled)
  1004. __set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
  1005. if (drv->has_sclk)
  1006. __set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
  1007. platform_set_drvdata(pdev, ctx);
  1008. ret = component_add(&pdev->dev, &mixer_component_ops);
  1009. if (!ret)
  1010. pm_runtime_enable(dev);
  1011. return ret;
  1012. }
  1013. static int mixer_remove(struct platform_device *pdev)
  1014. {
  1015. pm_runtime_disable(&pdev->dev);
  1016. component_del(&pdev->dev, &mixer_component_ops);
  1017. return 0;
  1018. }
  1019. static int __maybe_unused exynos_mixer_suspend(struct device *dev)
  1020. {
  1021. struct mixer_context *ctx = dev_get_drvdata(dev);
  1022. struct mixer_resources *res = &ctx->mixer_res;
  1023. clk_disable_unprepare(res->hdmi);
  1024. clk_disable_unprepare(res->mixer);
  1025. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
  1026. clk_disable_unprepare(res->vp);
  1027. if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
  1028. clk_disable_unprepare(res->sclk_mixer);
  1029. }
  1030. return 0;
  1031. }
  1032. static int __maybe_unused exynos_mixer_resume(struct device *dev)
  1033. {
  1034. struct mixer_context *ctx = dev_get_drvdata(dev);
  1035. struct mixer_resources *res = &ctx->mixer_res;
  1036. int ret;
  1037. ret = clk_prepare_enable(res->mixer);
  1038. if (ret < 0) {
  1039. DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
  1040. return ret;
  1041. }
  1042. ret = clk_prepare_enable(res->hdmi);
  1043. if (ret < 0) {
  1044. DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
  1045. return ret;
  1046. }
  1047. if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
  1048. ret = clk_prepare_enable(res->vp);
  1049. if (ret < 0) {
  1050. DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
  1051. ret);
  1052. return ret;
  1053. }
  1054. if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
  1055. ret = clk_prepare_enable(res->sclk_mixer);
  1056. if (ret < 0) {
  1057. DRM_ERROR("Failed to prepare_enable the " \
  1058. "sclk_mixer clk [%d]\n",
  1059. ret);
  1060. return ret;
  1061. }
  1062. }
  1063. }
  1064. return 0;
  1065. }
  1066. static const struct dev_pm_ops exynos_mixer_pm_ops = {
  1067. SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
  1068. };
  1069. struct platform_driver mixer_driver = {
  1070. .driver = {
  1071. .name = "exynos-mixer",
  1072. .owner = THIS_MODULE,
  1073. .pm = &exynos_mixer_pm_ops,
  1074. .of_match_table = mixer_match_types,
  1075. },
  1076. .probe = mixer_probe,
  1077. .remove = mixer_remove,
  1078. };