exynos_mixer.c 32 KB

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