exynos_mixer.c 33 KB

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