exynos_drm_scaler.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * Copyright (C) 2017 Samsung Electronics Co.Ltd
  3. * Author:
  4. * Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundationr
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/component.h>
  12. #include <linux/err.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <linux/of_device.h>
  18. #include <linux/pm_runtime.h>
  19. #include <drm/drmP.h>
  20. #include <drm/exynos_drm.h>
  21. #include "regs-scaler.h"
  22. #include "exynos_drm_fb.h"
  23. #include "exynos_drm_drv.h"
  24. #include "exynos_drm_iommu.h"
  25. #include "exynos_drm_ipp.h"
  26. #define scaler_read(offset) readl(scaler->regs + (offset))
  27. #define scaler_write(cfg, offset) writel(cfg, scaler->regs + (offset))
  28. #define SCALER_MAX_CLK 4
  29. #define SCALER_AUTOSUSPEND_DELAY 2000
  30. #define SCALER_RESET_WAIT_RETRIES 100
  31. struct scaler_data {
  32. const char *clk_name[SCALER_MAX_CLK];
  33. unsigned int num_clk;
  34. const struct exynos_drm_ipp_formats *formats;
  35. unsigned int num_formats;
  36. };
  37. struct scaler_context {
  38. struct exynos_drm_ipp ipp;
  39. struct drm_device *drm_dev;
  40. struct device *dev;
  41. void __iomem *regs;
  42. struct clk *clock[SCALER_MAX_CLK];
  43. struct exynos_drm_ipp_task *task;
  44. const struct scaler_data *scaler_data;
  45. };
  46. static u32 scaler_get_format(u32 drm_fmt)
  47. {
  48. switch (drm_fmt) {
  49. case DRM_FORMAT_NV12:
  50. return SCALER_YUV420_2P_UV;
  51. case DRM_FORMAT_NV21:
  52. return SCALER_YUV420_2P_VU;
  53. case DRM_FORMAT_YUV420:
  54. return SCALER_YUV420_3P;
  55. case DRM_FORMAT_YUYV:
  56. return SCALER_YUV422_1P_YUYV;
  57. case DRM_FORMAT_UYVY:
  58. return SCALER_YUV422_1P_UYVY;
  59. case DRM_FORMAT_YVYU:
  60. return SCALER_YUV422_1P_YVYU;
  61. case DRM_FORMAT_NV16:
  62. return SCALER_YUV422_2P_UV;
  63. case DRM_FORMAT_NV61:
  64. return SCALER_YUV422_2P_VU;
  65. case DRM_FORMAT_YUV422:
  66. return SCALER_YUV422_3P;
  67. case DRM_FORMAT_NV24:
  68. return SCALER_YUV444_2P_UV;
  69. case DRM_FORMAT_NV42:
  70. return SCALER_YUV444_2P_VU;
  71. case DRM_FORMAT_YUV444:
  72. return SCALER_YUV444_3P;
  73. case DRM_FORMAT_RGB565:
  74. return SCALER_RGB_565;
  75. case DRM_FORMAT_XRGB1555:
  76. return SCALER_ARGB1555;
  77. case DRM_FORMAT_ARGB1555:
  78. return SCALER_ARGB1555;
  79. case DRM_FORMAT_XRGB4444:
  80. return SCALER_ARGB4444;
  81. case DRM_FORMAT_ARGB4444:
  82. return SCALER_ARGB4444;
  83. case DRM_FORMAT_XRGB8888:
  84. return SCALER_ARGB8888;
  85. case DRM_FORMAT_ARGB8888:
  86. return SCALER_ARGB8888;
  87. case DRM_FORMAT_RGBX8888:
  88. return SCALER_RGBA8888;
  89. case DRM_FORMAT_RGBA8888:
  90. return SCALER_RGBA8888;
  91. default:
  92. break;
  93. }
  94. return 0;
  95. }
  96. static inline int scaler_reset(struct scaler_context *scaler)
  97. {
  98. int retry = SCALER_RESET_WAIT_RETRIES;
  99. scaler_write(SCALER_CFG_SOFT_RESET, SCALER_CFG);
  100. do {
  101. cpu_relax();
  102. } while (--retry > 1 &&
  103. scaler_read(SCALER_CFG) & SCALER_CFG_SOFT_RESET);
  104. do {
  105. cpu_relax();
  106. scaler_write(1, SCALER_INT_EN);
  107. } while (--retry > 0 && scaler_read(SCALER_INT_EN) != 1);
  108. return retry ? 0 : -EIO;
  109. }
  110. static inline void scaler_enable_int(struct scaler_context *scaler)
  111. {
  112. u32 val;
  113. val = SCALER_INT_EN_TIMEOUT |
  114. SCALER_INT_EN_ILLEGAL_BLEND |
  115. SCALER_INT_EN_ILLEGAL_RATIO |
  116. SCALER_INT_EN_ILLEGAL_DST_HEIGHT |
  117. SCALER_INT_EN_ILLEGAL_DST_WIDTH |
  118. SCALER_INT_EN_ILLEGAL_DST_V_POS |
  119. SCALER_INT_EN_ILLEGAL_DST_H_POS |
  120. SCALER_INT_EN_ILLEGAL_DST_C_SPAN |
  121. SCALER_INT_EN_ILLEGAL_DST_Y_SPAN |
  122. SCALER_INT_EN_ILLEGAL_DST_CR_BASE |
  123. SCALER_INT_EN_ILLEGAL_DST_CB_BASE |
  124. SCALER_INT_EN_ILLEGAL_DST_Y_BASE |
  125. SCALER_INT_EN_ILLEGAL_DST_COLOR |
  126. SCALER_INT_EN_ILLEGAL_SRC_HEIGHT |
  127. SCALER_INT_EN_ILLEGAL_SRC_WIDTH |
  128. SCALER_INT_EN_ILLEGAL_SRC_CV_POS |
  129. SCALER_INT_EN_ILLEGAL_SRC_CH_POS |
  130. SCALER_INT_EN_ILLEGAL_SRC_YV_POS |
  131. SCALER_INT_EN_ILLEGAL_SRC_YH_POS |
  132. SCALER_INT_EN_ILLEGAL_DST_SPAN |
  133. SCALER_INT_EN_ILLEGAL_SRC_Y_SPAN |
  134. SCALER_INT_EN_ILLEGAL_SRC_CR_BASE |
  135. SCALER_INT_EN_ILLEGAL_SRC_CB_BASE |
  136. SCALER_INT_EN_ILLEGAL_SRC_Y_BASE |
  137. SCALER_INT_EN_ILLEGAL_SRC_COLOR |
  138. SCALER_INT_EN_FRAME_END;
  139. scaler_write(val, SCALER_INT_EN);
  140. }
  141. static inline void scaler_set_src_fmt(struct scaler_context *scaler,
  142. u32 src_fmt)
  143. {
  144. u32 val;
  145. val = SCALER_SRC_CFG_SET_COLOR_FORMAT(src_fmt);
  146. scaler_write(val, SCALER_SRC_CFG);
  147. }
  148. static inline void scaler_set_src_base(struct scaler_context *scaler,
  149. struct exynos_drm_ipp_buffer *src_buf)
  150. {
  151. static unsigned int bases[] = {
  152. SCALER_SRC_Y_BASE,
  153. SCALER_SRC_CB_BASE,
  154. SCALER_SRC_CR_BASE,
  155. };
  156. int i;
  157. for (i = 0; i < src_buf->format->num_planes; ++i)
  158. scaler_write(src_buf->dma_addr[i], bases[i]);
  159. }
  160. static inline void scaler_set_src_span(struct scaler_context *scaler,
  161. struct exynos_drm_ipp_buffer *src_buf)
  162. {
  163. u32 val;
  164. val = SCALER_SRC_SPAN_SET_Y_SPAN(src_buf->buf.pitch[0] /
  165. src_buf->format->cpp[0]);
  166. if (src_buf->format->num_planes > 1)
  167. val |= SCALER_SRC_SPAN_SET_C_SPAN(src_buf->buf.pitch[1]);
  168. scaler_write(val, SCALER_SRC_SPAN);
  169. }
  170. static inline void scaler_set_src_luma_pos(struct scaler_context *scaler,
  171. struct drm_exynos_ipp_task_rect *src_pos)
  172. {
  173. u32 val;
  174. val = SCALER_SRC_Y_POS_SET_YH_POS(src_pos->x << 2);
  175. val |= SCALER_SRC_Y_POS_SET_YV_POS(src_pos->y << 2);
  176. scaler_write(val, SCALER_SRC_Y_POS);
  177. scaler_write(val, SCALER_SRC_C_POS); /* ATTENTION! */
  178. }
  179. static inline void scaler_set_src_wh(struct scaler_context *scaler,
  180. struct drm_exynos_ipp_task_rect *src_pos)
  181. {
  182. u32 val;
  183. val = SCALER_SRC_WH_SET_WIDTH(src_pos->w);
  184. val |= SCALER_SRC_WH_SET_HEIGHT(src_pos->h);
  185. scaler_write(val, SCALER_SRC_WH);
  186. }
  187. static inline void scaler_set_dst_fmt(struct scaler_context *scaler,
  188. u32 dst_fmt)
  189. {
  190. u32 val;
  191. val = SCALER_DST_CFG_SET_COLOR_FORMAT(dst_fmt);
  192. scaler_write(val, SCALER_DST_CFG);
  193. }
  194. static inline void scaler_set_dst_base(struct scaler_context *scaler,
  195. struct exynos_drm_ipp_buffer *dst_buf)
  196. {
  197. static unsigned int bases[] = {
  198. SCALER_DST_Y_BASE,
  199. SCALER_DST_CB_BASE,
  200. SCALER_DST_CR_BASE,
  201. };
  202. int i;
  203. for (i = 0; i < dst_buf->format->num_planes; ++i)
  204. scaler_write(dst_buf->dma_addr[i], bases[i]);
  205. }
  206. static inline void scaler_set_dst_span(struct scaler_context *scaler,
  207. struct exynos_drm_ipp_buffer *dst_buf)
  208. {
  209. u32 val;
  210. val = SCALER_DST_SPAN_SET_Y_SPAN(dst_buf->buf.pitch[0] /
  211. dst_buf->format->cpp[0]);
  212. if (dst_buf->format->num_planes > 1)
  213. val |= SCALER_DST_SPAN_SET_C_SPAN(dst_buf->buf.pitch[1]);
  214. scaler_write(val, SCALER_DST_SPAN);
  215. }
  216. static inline void scaler_set_dst_luma_pos(struct scaler_context *scaler,
  217. struct drm_exynos_ipp_task_rect *dst_pos)
  218. {
  219. u32 val;
  220. val = SCALER_DST_WH_SET_WIDTH(dst_pos->w);
  221. val |= SCALER_DST_WH_SET_HEIGHT(dst_pos->h);
  222. scaler_write(val, SCALER_DST_WH);
  223. }
  224. static inline void scaler_set_dst_wh(struct scaler_context *scaler,
  225. struct drm_exynos_ipp_task_rect *dst_pos)
  226. {
  227. u32 val;
  228. val = SCALER_DST_POS_SET_H_POS(dst_pos->x);
  229. val |= SCALER_DST_POS_SET_V_POS(dst_pos->y);
  230. scaler_write(val, SCALER_DST_POS);
  231. }
  232. static inline void scaler_set_hv_ratio(struct scaler_context *scaler,
  233. unsigned int rotation,
  234. struct drm_exynos_ipp_task_rect *src_pos,
  235. struct drm_exynos_ipp_task_rect *dst_pos)
  236. {
  237. u32 val, h_ratio, v_ratio;
  238. if (drm_rotation_90_or_270(rotation)) {
  239. h_ratio = (src_pos->h << 16) / dst_pos->w;
  240. v_ratio = (src_pos->w << 16) / dst_pos->h;
  241. } else {
  242. h_ratio = (src_pos->w << 16) / dst_pos->w;
  243. v_ratio = (src_pos->h << 16) / dst_pos->h;
  244. }
  245. val = SCALER_H_RATIO_SET(h_ratio);
  246. scaler_write(val, SCALER_H_RATIO);
  247. val = SCALER_V_RATIO_SET(v_ratio);
  248. scaler_write(val, SCALER_V_RATIO);
  249. }
  250. static inline void scaler_set_rotation(struct scaler_context *scaler,
  251. unsigned int rotation)
  252. {
  253. u32 val = 0;
  254. if (rotation & DRM_MODE_ROTATE_90)
  255. val |= SCALER_ROT_CFG_SET_ROTMODE(SCALER_ROT_MODE_90);
  256. else if (rotation & DRM_MODE_ROTATE_180)
  257. val |= SCALER_ROT_CFG_SET_ROTMODE(SCALER_ROT_MODE_180);
  258. else if (rotation & DRM_MODE_ROTATE_270)
  259. val |= SCALER_ROT_CFG_SET_ROTMODE(SCALER_ROT_MODE_270);
  260. if (rotation & DRM_MODE_REFLECT_X)
  261. val |= SCALER_ROT_CFG_FLIP_X_EN;
  262. if (rotation & DRM_MODE_REFLECT_Y)
  263. val |= SCALER_ROT_CFG_FLIP_Y_EN;
  264. scaler_write(val, SCALER_ROT_CFG);
  265. }
  266. static inline void scaler_set_csc(struct scaler_context *scaler,
  267. const struct drm_format_info *fmt)
  268. {
  269. static const u32 csc_mtx[2][3][3] = {
  270. { /* YCbCr to RGB */
  271. {0x254, 0x000, 0x331},
  272. {0x254, 0xf38, 0xe60},
  273. {0x254, 0x409, 0x000},
  274. },
  275. { /* RGB to YCbCr */
  276. {0x084, 0x102, 0x032},
  277. {0xfb4, 0xf6b, 0x0e1},
  278. {0x0e1, 0xf44, 0xfdc},
  279. },
  280. };
  281. int i, j, dir;
  282. switch (fmt->format) {
  283. case DRM_FORMAT_RGB565:
  284. case DRM_FORMAT_XRGB1555:
  285. case DRM_FORMAT_ARGB1555:
  286. case DRM_FORMAT_XRGB4444:
  287. case DRM_FORMAT_ARGB4444:
  288. case DRM_FORMAT_XRGB8888:
  289. case DRM_FORMAT_ARGB8888:
  290. case DRM_FORMAT_RGBX8888:
  291. case DRM_FORMAT_RGBA8888:
  292. dir = 1;
  293. break;
  294. default:
  295. dir = 0;
  296. }
  297. for (i = 0; i < 3; i++)
  298. for (j = 0; j < 3; j++)
  299. scaler_write(csc_mtx[dir][i][j], SCALER_CSC_COEF(j, i));
  300. }
  301. static inline void scaler_set_timer(struct scaler_context *scaler,
  302. unsigned int timer, unsigned int divider)
  303. {
  304. u32 val;
  305. val = SCALER_TIMEOUT_CTRL_TIMER_ENABLE;
  306. val |= SCALER_TIMEOUT_CTRL_SET_TIMER_VALUE(timer);
  307. val |= SCALER_TIMEOUT_CTRL_SET_TIMER_DIV(divider);
  308. scaler_write(val, SCALER_TIMEOUT_CTRL);
  309. }
  310. static inline void scaler_start_hw(struct scaler_context *scaler)
  311. {
  312. scaler_write(SCALER_CFG_START_CMD, SCALER_CFG);
  313. }
  314. static int scaler_commit(struct exynos_drm_ipp *ipp,
  315. struct exynos_drm_ipp_task *task)
  316. {
  317. struct scaler_context *scaler =
  318. container_of(ipp, struct scaler_context, ipp);
  319. u32 src_fmt = scaler_get_format(task->src.buf.fourcc);
  320. struct drm_exynos_ipp_task_rect *src_pos = &task->src.rect;
  321. u32 dst_fmt = scaler_get_format(task->dst.buf.fourcc);
  322. struct drm_exynos_ipp_task_rect *dst_pos = &task->dst.rect;
  323. pm_runtime_get_sync(scaler->dev);
  324. if (scaler_reset(scaler)) {
  325. pm_runtime_put(scaler->dev);
  326. return -EIO;
  327. }
  328. scaler->task = task;
  329. scaler_set_src_fmt(scaler, src_fmt);
  330. scaler_set_src_base(scaler, &task->src);
  331. scaler_set_src_span(scaler, &task->src);
  332. scaler_set_src_luma_pos(scaler, src_pos);
  333. scaler_set_src_wh(scaler, src_pos);
  334. scaler_set_dst_fmt(scaler, dst_fmt);
  335. scaler_set_dst_base(scaler, &task->dst);
  336. scaler_set_dst_span(scaler, &task->dst);
  337. scaler_set_dst_luma_pos(scaler, dst_pos);
  338. scaler_set_dst_wh(scaler, dst_pos);
  339. scaler_set_hv_ratio(scaler, task->transform.rotation, src_pos, dst_pos);
  340. scaler_set_rotation(scaler, task->transform.rotation);
  341. scaler_set_csc(scaler, task->src.format);
  342. scaler_set_timer(scaler, 0xffff, 0xf);
  343. scaler_enable_int(scaler);
  344. scaler_start_hw(scaler);
  345. return 0;
  346. }
  347. static struct exynos_drm_ipp_funcs ipp_funcs = {
  348. .commit = scaler_commit,
  349. };
  350. static inline void scaler_disable_int(struct scaler_context *scaler)
  351. {
  352. scaler_write(0, SCALER_INT_EN);
  353. }
  354. static inline u32 scaler_get_int_status(struct scaler_context *scaler)
  355. {
  356. u32 val = scaler_read(SCALER_INT_STATUS);
  357. scaler_write(val, SCALER_INT_STATUS);
  358. return val;
  359. }
  360. static inline int scaler_task_done(u32 val)
  361. {
  362. return val & SCALER_INT_STATUS_FRAME_END ? 0 : -EINVAL;
  363. }
  364. static irqreturn_t scaler_irq_handler(int irq, void *arg)
  365. {
  366. struct scaler_context *scaler = arg;
  367. u32 val = scaler_get_int_status(scaler);
  368. scaler_disable_int(scaler);
  369. if (scaler->task) {
  370. struct exynos_drm_ipp_task *task = scaler->task;
  371. scaler->task = NULL;
  372. pm_runtime_mark_last_busy(scaler->dev);
  373. pm_runtime_put_autosuspend(scaler->dev);
  374. exynos_drm_ipp_task_done(task, scaler_task_done(val));
  375. }
  376. return IRQ_HANDLED;
  377. }
  378. static int scaler_bind(struct device *dev, struct device *master, void *data)
  379. {
  380. struct scaler_context *scaler = dev_get_drvdata(dev);
  381. struct drm_device *drm_dev = data;
  382. struct exynos_drm_ipp *ipp = &scaler->ipp;
  383. scaler->drm_dev = drm_dev;
  384. drm_iommu_attach_device(drm_dev, dev);
  385. exynos_drm_ipp_register(drm_dev, ipp, &ipp_funcs,
  386. DRM_EXYNOS_IPP_CAP_CROP | DRM_EXYNOS_IPP_CAP_ROTATE |
  387. DRM_EXYNOS_IPP_CAP_SCALE | DRM_EXYNOS_IPP_CAP_CONVERT,
  388. scaler->scaler_data->formats,
  389. scaler->scaler_data->num_formats, "scaler");
  390. dev_info(dev, "The exynos scaler has been probed successfully\n");
  391. return 0;
  392. }
  393. static void scaler_unbind(struct device *dev, struct device *master,
  394. void *data)
  395. {
  396. struct scaler_context *scaler = dev_get_drvdata(dev);
  397. struct drm_device *drm_dev = data;
  398. struct exynos_drm_ipp *ipp = &scaler->ipp;
  399. exynos_drm_ipp_unregister(drm_dev, ipp);
  400. drm_iommu_detach_device(scaler->drm_dev, scaler->dev);
  401. }
  402. static const struct component_ops scaler_component_ops = {
  403. .bind = scaler_bind,
  404. .unbind = scaler_unbind,
  405. };
  406. static int scaler_probe(struct platform_device *pdev)
  407. {
  408. struct device *dev = &pdev->dev;
  409. struct resource *regs_res;
  410. struct scaler_context *scaler;
  411. int irq;
  412. int ret, i;
  413. scaler = devm_kzalloc(dev, sizeof(*scaler), GFP_KERNEL);
  414. if (!scaler)
  415. return -ENOMEM;
  416. scaler->scaler_data =
  417. (struct scaler_data *)of_device_get_match_data(dev);
  418. scaler->dev = dev;
  419. regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  420. scaler->regs = devm_ioremap_resource(dev, regs_res);
  421. if (IS_ERR(scaler->regs))
  422. return PTR_ERR(scaler->regs);
  423. irq = platform_get_irq(pdev, 0);
  424. if (irq < 0) {
  425. dev_err(dev, "failed to get irq\n");
  426. return irq;
  427. }
  428. ret = devm_request_threaded_irq(dev, irq, NULL, scaler_irq_handler,
  429. IRQF_ONESHOT, "drm_scaler", scaler);
  430. if (ret < 0) {
  431. dev_err(dev, "failed to request irq\n");
  432. return ret;
  433. }
  434. for (i = 0; i < scaler->scaler_data->num_clk; ++i) {
  435. scaler->clock[i] = devm_clk_get(dev,
  436. scaler->scaler_data->clk_name[i]);
  437. if (IS_ERR(scaler->clock[i])) {
  438. dev_err(dev, "failed to get clock\n");
  439. return PTR_ERR(scaler->clock[i]);
  440. }
  441. }
  442. pm_runtime_use_autosuspend(dev);
  443. pm_runtime_set_autosuspend_delay(dev, SCALER_AUTOSUSPEND_DELAY);
  444. pm_runtime_enable(dev);
  445. platform_set_drvdata(pdev, scaler);
  446. ret = component_add(dev, &scaler_component_ops);
  447. if (ret)
  448. goto err_ippdrv_register;
  449. return 0;
  450. err_ippdrv_register:
  451. pm_runtime_dont_use_autosuspend(dev);
  452. pm_runtime_disable(dev);
  453. return ret;
  454. }
  455. static int scaler_remove(struct platform_device *pdev)
  456. {
  457. struct device *dev = &pdev->dev;
  458. component_del(dev, &scaler_component_ops);
  459. pm_runtime_dont_use_autosuspend(dev);
  460. pm_runtime_disable(dev);
  461. return 0;
  462. }
  463. #ifdef CONFIG_PM
  464. static int clk_disable_unprepare_wrapper(struct clk *clk)
  465. {
  466. clk_disable_unprepare(clk);
  467. return 0;
  468. }
  469. static int scaler_clk_ctrl(struct scaler_context *scaler, bool enable)
  470. {
  471. int (*clk_fun)(struct clk *clk), i;
  472. clk_fun = enable ? clk_prepare_enable : clk_disable_unprepare_wrapper;
  473. for (i = 0; i < scaler->scaler_data->num_clk; ++i)
  474. clk_fun(scaler->clock[i]);
  475. return 0;
  476. }
  477. static int scaler_runtime_suspend(struct device *dev)
  478. {
  479. struct scaler_context *scaler = dev_get_drvdata(dev);
  480. return scaler_clk_ctrl(scaler, false);
  481. }
  482. static int scaler_runtime_resume(struct device *dev)
  483. {
  484. struct scaler_context *scaler = dev_get_drvdata(dev);
  485. return scaler_clk_ctrl(scaler, true);
  486. }
  487. #endif
  488. static const struct dev_pm_ops scaler_pm_ops = {
  489. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  490. pm_runtime_force_resume)
  491. SET_RUNTIME_PM_OPS(scaler_runtime_suspend, scaler_runtime_resume, NULL)
  492. };
  493. static const struct drm_exynos_ipp_limit scaler_5420_two_pixel_hv_limits[] = {
  494. { IPP_SIZE_LIMIT(BUFFER, .h = { 16, SZ_8K }, .v = { 16, SZ_8K }) },
  495. { IPP_SIZE_LIMIT(AREA, .h.align = 2, .v.align = 2) },
  496. { IPP_SCALE_LIMIT(.h = { 65536 * 1 / 4, 65536 * 16 },
  497. .v = { 65536 * 1 / 4, 65536 * 16 }) },
  498. };
  499. static const struct drm_exynos_ipp_limit scaler_5420_two_pixel_h_limits[] = {
  500. { IPP_SIZE_LIMIT(BUFFER, .h = { 16, SZ_8K }, .v = { 16, SZ_8K }) },
  501. { IPP_SIZE_LIMIT(AREA, .h.align = 2, .v.align = 1) },
  502. { IPP_SCALE_LIMIT(.h = { 65536 * 1 / 4, 65536 * 16 },
  503. .v = { 65536 * 1 / 4, 65536 * 16 }) },
  504. };
  505. static const struct drm_exynos_ipp_limit scaler_5420_one_pixel_limits[] = {
  506. { IPP_SIZE_LIMIT(BUFFER, .h = { 16, SZ_8K }, .v = { 16, SZ_8K }) },
  507. { IPP_SCALE_LIMIT(.h = { 65536 * 1 / 4, 65536 * 16 },
  508. .v = { 65536 * 1 / 4, 65536 * 16 }) },
  509. };
  510. static const struct exynos_drm_ipp_formats exynos5420_formats[] = {
  511. /* SCALER_YUV420_2P_UV */
  512. { IPP_SRCDST_FORMAT(NV21, scaler_5420_two_pixel_hv_limits) },
  513. /* SCALER_YUV420_2P_VU */
  514. { IPP_SRCDST_FORMAT(NV12, scaler_5420_two_pixel_hv_limits) },
  515. /* SCALER_YUV420_3P */
  516. { IPP_SRCDST_FORMAT(YUV420, scaler_5420_two_pixel_hv_limits) },
  517. /* SCALER_YUV422_1P_YUYV */
  518. { IPP_SRCDST_FORMAT(YUYV, scaler_5420_two_pixel_h_limits) },
  519. /* SCALER_YUV422_1P_UYVY */
  520. { IPP_SRCDST_FORMAT(UYVY, scaler_5420_two_pixel_h_limits) },
  521. /* SCALER_YUV422_1P_YVYU */
  522. { IPP_SRCDST_FORMAT(YVYU, scaler_5420_two_pixel_h_limits) },
  523. /* SCALER_YUV422_2P_UV */
  524. { IPP_SRCDST_FORMAT(NV61, scaler_5420_two_pixel_h_limits) },
  525. /* SCALER_YUV422_2P_VU */
  526. { IPP_SRCDST_FORMAT(NV16, scaler_5420_two_pixel_h_limits) },
  527. /* SCALER_YUV422_3P */
  528. { IPP_SRCDST_FORMAT(YUV422, scaler_5420_two_pixel_h_limits) },
  529. /* SCALER_YUV444_2P_UV */
  530. { IPP_SRCDST_FORMAT(NV42, scaler_5420_one_pixel_limits) },
  531. /* SCALER_YUV444_2P_VU */
  532. { IPP_SRCDST_FORMAT(NV24, scaler_5420_one_pixel_limits) },
  533. /* SCALER_YUV444_3P */
  534. { IPP_SRCDST_FORMAT(YUV444, scaler_5420_one_pixel_limits) },
  535. /* SCALER_RGB_565 */
  536. { IPP_SRCDST_FORMAT(RGB565, scaler_5420_one_pixel_limits) },
  537. /* SCALER_ARGB1555 */
  538. { IPP_SRCDST_FORMAT(XRGB1555, scaler_5420_one_pixel_limits) },
  539. /* SCALER_ARGB1555 */
  540. { IPP_SRCDST_FORMAT(ARGB1555, scaler_5420_one_pixel_limits) },
  541. /* SCALER_ARGB4444 */
  542. { IPP_SRCDST_FORMAT(XRGB4444, scaler_5420_one_pixel_limits) },
  543. /* SCALER_ARGB4444 */
  544. { IPP_SRCDST_FORMAT(ARGB4444, scaler_5420_one_pixel_limits) },
  545. /* SCALER_ARGB8888 */
  546. { IPP_SRCDST_FORMAT(XRGB8888, scaler_5420_one_pixel_limits) },
  547. /* SCALER_ARGB8888 */
  548. { IPP_SRCDST_FORMAT(ARGB8888, scaler_5420_one_pixel_limits) },
  549. /* SCALER_RGBA8888 */
  550. { IPP_SRCDST_FORMAT(RGBX8888, scaler_5420_one_pixel_limits) },
  551. /* SCALER_RGBA8888 */
  552. { IPP_SRCDST_FORMAT(RGBA8888, scaler_5420_one_pixel_limits) },
  553. };
  554. static const struct scaler_data exynos5420_data = {
  555. .clk_name = {"mscl"},
  556. .num_clk = 1,
  557. .formats = exynos5420_formats,
  558. .num_formats = ARRAY_SIZE(exynos5420_formats),
  559. };
  560. static const struct scaler_data exynos5433_data = {
  561. .clk_name = {"pclk", "aclk", "aclk_xiu"},
  562. .num_clk = 3,
  563. .formats = exynos5420_formats, /* intentional */
  564. .num_formats = ARRAY_SIZE(exynos5420_formats),
  565. };
  566. static const struct of_device_id exynos_scaler_match[] = {
  567. {
  568. .compatible = "samsung,exynos5420-scaler",
  569. .data = &exynos5420_data,
  570. }, {
  571. .compatible = "samsung,exynos5433-scaler",
  572. .data = &exynos5433_data,
  573. }, {
  574. },
  575. };
  576. MODULE_DEVICE_TABLE(of, exynos_scaler_match);
  577. struct platform_driver scaler_driver = {
  578. .probe = scaler_probe,
  579. .remove = scaler_remove,
  580. .driver = {
  581. .name = "exynos-scaler",
  582. .owner = THIS_MODULE,
  583. .pm = &scaler_pm_ops,
  584. .of_match_table = exynos_scaler_match,
  585. },
  586. };