exynos_mixer.c 32 KB

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