exynos_mixer.c 34 KB

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