exynos_mixer.c 33 KB

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