exynos_mixer.c 33 KB

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