exynos_mixer.c 32 KB

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