exynos_mixer.c 33 KB

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