exynos_mixer.c 33 KB

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