exynos_mixer.c 33 KB

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