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