exynos_mixer.c 30 KB

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