exynos_drm_scaler.c 19 KB

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