exynos_mixer.c 33 KB

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