exynos_mixer.c 34 KB

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