exynos_drm_scaler.c 20 KB

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