exynos_mixer.c 32 KB

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