exynos_mixer.c 30 KB

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