exynos_mixer.c 33 KB

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