forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/drm/exynos/exynos_drm_fimc.c
....@@ -1,32 +1,29 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2012 Samsung Electronics Co.Ltd
34 * Authors:
45 * Eunchul Kim <chulspro.kim@samsung.com>
56 * Jinyoung Jeon <jy0.jeon@samsung.com>
67 * Sangmin Lee <lsmin.lee@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License as published by the
10
- * Free Software Foundation; either version 2 of the License, or (at your
11
- * option) any later version.
12
- *
138 */
14
-#include <linux/kernel.h>
15
-#include <linux/component.h>
16
-#include <linux/platform_device.h>
17
-#include <linux/mfd/syscon.h>
18
-#include <linux/regmap.h>
9
+
1910 #include <linux/clk.h>
20
-#include <linux/pm_runtime.h>
11
+#include <linux/component.h>
12
+#include <linux/kernel.h>
13
+#include <linux/mfd/syscon.h>
2114 #include <linux/of.h>
15
+#include <linux/platform_device.h>
16
+#include <linux/pm_runtime.h>
17
+#include <linux/regmap.h>
2218 #include <linux/spinlock.h>
2319
24
-#include <drm/drmP.h>
20
+#include <drm/drm_fourcc.h>
21
+#include <drm/drm_print.h>
2522 #include <drm/exynos_drm.h>
26
-#include "regs-fimc.h"
23
+
2724 #include "exynos_drm_drv.h"
28
-#include "exynos_drm_iommu.h"
2925 #include "exynos_drm_ipp.h"
26
+#include "regs-fimc.h"
3027
3128 /*
3229 * FIMC stands for Fully Interactive Mobile Camera and
....@@ -49,7 +46,7 @@
4946 module_param_named(fimc_devs, fimc_mask, uint, 0644);
5047 MODULE_PARM_DESC(fimc_devs, "Alias mask for assigning FIMC devices to Exynos DRM");
5148
52
-#define get_fimc_context(dev) platform_get_drvdata(to_platform_device(dev))
49
+#define get_fimc_context(dev) dev_get_drvdata(dev)
5350
5451 enum {
5552 FIMC_CLK_LCLK,
....@@ -100,6 +97,7 @@
10097 struct fimc_context {
10198 struct exynos_drm_ipp ipp;
10299 struct drm_device *drm_dev;
100
+ void *dma_priv;
103101 struct device *dev;
104102 struct exynos_drm_ipp_task *task;
105103 struct exynos_drm_ipp_formats *formats;
....@@ -187,7 +185,7 @@
187185 {
188186 u32 cfg;
189187
190
- DRM_DEBUG_KMS("enable[%d]\n", enable);
188
+ DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
191189
192190 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
193191 if (enable)
....@@ -202,7 +200,7 @@
202200 {
203201 u32 cfg;
204202
205
- DRM_DEBUG_KMS("enable[%d]\n", enable);
203
+ DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
206204
207205 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
208206 if (enable) {
....@@ -226,15 +224,16 @@
226224 flag = EXYNOS_CISTATUS_OVFIY | EXYNOS_CISTATUS_OVFICB |
227225 EXYNOS_CISTATUS_OVFICR;
228226
229
- DRM_DEBUG_KMS("flag[0x%x]\n", flag);
227
+ DRM_DEV_DEBUG_KMS(ctx->dev, "flag[0x%x]\n", flag);
230228
231229 if (status & flag) {
232230 fimc_set_bits(ctx, EXYNOS_CIWDOFST,
233231 EXYNOS_CIWDOFST_CLROVFIY | EXYNOS_CIWDOFST_CLROVFICB |
234232 EXYNOS_CIWDOFST_CLROVFICR);
235233
236
- dev_err(ctx->dev, "occurred overflow at %d, status 0x%x.\n",
237
- ctx->id, status);
234
+ DRM_DEV_ERROR(ctx->dev,
235
+ "occurred overflow at %d, status 0x%x.\n",
236
+ ctx->id, status);
238237 return true;
239238 }
240239
....@@ -247,7 +246,7 @@
247246
248247 cfg = fimc_read(ctx, EXYNOS_CISTATUS);
249248
250
- DRM_DEBUG_KMS("cfg[0x%x]\n", cfg);
249
+ DRM_DEV_DEBUG_KMS(ctx->dev, "cfg[0x%x]\n", cfg);
251250
252251 if (!(cfg & EXYNOS_CISTATUS_FRAMEEND))
253252 return false;
....@@ -269,17 +268,17 @@
269268 if (frame_cnt == 0)
270269 frame_cnt = EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg);
271270
272
- DRM_DEBUG_KMS("present[%d]before[%d]\n",
273
- EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg),
274
- EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg));
271
+ DRM_DEV_DEBUG_KMS(ctx->dev, "present[%d]before[%d]\n",
272
+ EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg),
273
+ EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg));
275274
276275 if (frame_cnt == 0) {
277
- DRM_ERROR("failed to get frame count.\n");
276
+ DRM_DEV_ERROR(ctx->dev, "failed to get frame count.\n");
278277 return -EIO;
279278 }
280279
281280 buf_id = frame_cnt - 1;
282
- DRM_DEBUG_KMS("buf_id[%d]\n", buf_id);
281
+ DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id);
283282
284283 return buf_id;
285284 }
....@@ -288,7 +287,7 @@
288287 {
289288 u32 cfg;
290289
291
- DRM_DEBUG_KMS("enable[%d]\n", enable);
290
+ DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
292291
293292 cfg = fimc_read(ctx, EXYNOS_CIOCTRL);
294293 if (enable)
....@@ -303,7 +302,7 @@
303302 {
304303 u32 cfg;
305304
306
- DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
305
+ DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
307306
308307 /* RGB */
309308 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
....@@ -368,7 +367,7 @@
368367 {
369368 u32 cfg;
370369
371
- DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
370
+ DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
372371
373372 cfg = fimc_read(ctx, EXYNOS_MSCTRL);
374373 cfg &= ~EXYNOS_MSCTRL_INFORMAT_RGB;
....@@ -421,7 +420,7 @@
421420 unsigned int degree = rotation & DRM_MODE_ROTATE_MASK;
422421 u32 cfg1, cfg2;
423422
424
- DRM_DEBUG_KMS("rotation[%x]\n", rotation);
423
+ DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[%x]\n", rotation);
425424
426425 cfg1 = fimc_read(ctx, EXYNOS_MSCTRL);
427426 cfg1 &= ~(EXYNOS_MSCTRL_FLIP_X_MIRROR |
....@@ -479,10 +478,11 @@
479478 v1 = buf->rect.y;
480479 v2 = buf->buf.height - buf->rect.h - buf->rect.y;
481480
482
- DRM_DEBUG_KMS("x[%d]y[%d]w[%d]h[%d]hsize[%d]vsize[%d]\n",
483
- buf->rect.x, buf->rect.y, buf->rect.w, buf->rect.h,
484
- real_width, buf->buf.height);
485
- DRM_DEBUG_KMS("h1[%d]h2[%d]v1[%d]v2[%d]\n", h1, h2, v1, v2);
481
+ DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]hsize[%d]vsize[%d]\n",
482
+ buf->rect.x, buf->rect.y, buf->rect.w, buf->rect.h,
483
+ real_width, buf->buf.height);
484
+ DRM_DEV_DEBUG_KMS(ctx->dev, "h1[%d]h2[%d]v1[%d]v2[%d]\n", h1, h2, v1,
485
+ v2);
486486
487487 /*
488488 * set window offset 1, 2 size
....@@ -507,7 +507,8 @@
507507 unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
508508 u32 cfg;
509509
510
- DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", real_width, buf->buf.height);
510
+ DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width,
511
+ buf->buf.height);
511512
512513 /* original size */
513514 cfg = (EXYNOS_ORGISIZE_HORIZONTAL(real_width) |
....@@ -515,8 +516,8 @@
515516
516517 fimc_write(ctx, cfg, EXYNOS_ORGISIZE);
517518
518
- DRM_DEBUG_KMS("x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x, buf->rect.y,
519
- buf->rect.w, buf->rect.h);
519
+ DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x,
520
+ buf->rect.y, buf->rect.w, buf->rect.h);
520521
521522 /* set input DMA image size */
522523 cfg = fimc_read(ctx, EXYNOS_CIREAL_ISIZE);
....@@ -561,7 +562,7 @@
561562 {
562563 u32 cfg;
563564
564
- DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
565
+ DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
565566
566567 /* RGB */
567568 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
....@@ -632,7 +633,7 @@
632633 {
633634 u32 cfg;
634635
635
- DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
636
+ DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
636637
637638 cfg = fimc_read(ctx, EXYNOS_CIEXTEN);
638639
....@@ -692,7 +693,7 @@
692693 unsigned int degree = rotation & DRM_MODE_ROTATE_MASK;
693694 u32 cfg;
694695
695
- DRM_DEBUG_KMS("rotation[0x%x]\n", rotation);
696
+ DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[0x%x]\n", rotation);
696697
697698 cfg = fimc_read(ctx, EXYNOS_CITRGFMT);
698699 cfg &= ~EXYNOS_CITRGFMT_FLIP_MASK;
....@@ -776,19 +777,20 @@
776777
777778 pre_dst_width = src_w >> hfactor;
778779 pre_dst_height = src_h >> vfactor;
779
- DRM_DEBUG_KMS("pre_dst_width[%d]pre_dst_height[%d]\n",
780
- pre_dst_width, pre_dst_height);
781
- DRM_DEBUG_KMS("hfactor[%d]vfactor[%d]\n", hfactor, vfactor);
780
+ DRM_DEV_DEBUG_KMS(ctx->dev, "pre_dst_width[%d]pre_dst_height[%d]\n",
781
+ pre_dst_width, pre_dst_height);
782
+ DRM_DEV_DEBUG_KMS(ctx->dev, "hfactor[%d]vfactor[%d]\n", hfactor,
783
+ vfactor);
782784
783785 sc->hratio = (src_w << 14) / (dst_w << hfactor);
784786 sc->vratio = (src_h << 14) / (dst_h << vfactor);
785787 sc->up_h = (dst_w >= src_w) ? true : false;
786788 sc->up_v = (dst_h >= src_h) ? true : false;
787
- DRM_DEBUG_KMS("hratio[%d]vratio[%d]up_h[%d]up_v[%d]\n",
788
- sc->hratio, sc->vratio, sc->up_h, sc->up_v);
789
+ DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]up_h[%d]up_v[%d]\n",
790
+ sc->hratio, sc->vratio, sc->up_h, sc->up_v);
789791
790792 shfactor = FIMC_SHFACTOR - (hfactor + vfactor);
791
- DRM_DEBUG_KMS("shfactor[%d]\n", shfactor);
793
+ DRM_DEV_DEBUG_KMS(ctx->dev, "shfactor[%d]\n", shfactor);
792794
793795 cfg = (EXYNOS_CISCPRERATIO_SHFACTOR(shfactor) |
794796 EXYNOS_CISCPRERATIO_PREHORRATIO(1 << hfactor) |
....@@ -806,10 +808,10 @@
806808 {
807809 u32 cfg, cfg_ext;
808810
809
- DRM_DEBUG_KMS("range[%d]bypass[%d]up_h[%d]up_v[%d]\n",
810
- sc->range, sc->bypass, sc->up_h, sc->up_v);
811
- DRM_DEBUG_KMS("hratio[%d]vratio[%d]\n",
812
- sc->hratio, sc->vratio);
811
+ DRM_DEV_DEBUG_KMS(ctx->dev, "range[%d]bypass[%d]up_h[%d]up_v[%d]\n",
812
+ sc->range, sc->bypass, sc->up_h, sc->up_v);
813
+ DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]\n",
814
+ sc->hratio, sc->vratio);
813815
814816 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
815817 cfg &= ~(EXYNOS_CISCCTRL_SCALERBYPASS |
....@@ -847,7 +849,8 @@
847849 unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
848850 u32 cfg, cfg_ext;
849851
850
- DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", real_width, buf->buf.height);
852
+ DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width,
853
+ buf->buf.height);
851854
852855 /* original size */
853856 cfg = (EXYNOS_ORGOSIZE_HORIZONTAL(real_width) |
....@@ -855,8 +858,9 @@
855858
856859 fimc_write(ctx, cfg, EXYNOS_ORGOSIZE);
857860
858
- DRM_DEBUG_KMS("x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x, buf->rect.y,
859
- buf->rect.w, buf->rect.h);
861
+ DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x,
862
+ buf->rect.y,
863
+ buf->rect.w, buf->rect.h);
860864
861865 /* CSC ITU */
862866 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
....@@ -906,7 +910,7 @@
906910 u32 buf_num;
907911 u32 cfg;
908912
909
- DRM_DEBUG_KMS("buf_id[%d]enqueu[%d]\n", buf_id, enqueue);
913
+ DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]enqueu[%d]\n", buf_id, enqueue);
910914
911915 spin_lock_irqsave(&ctx->lock, flags);
912916
....@@ -946,7 +950,7 @@
946950 struct fimc_context *ctx = dev_id;
947951 int buf_id;
948952
949
- DRM_DEBUG_KMS("fimc id[%d]\n", ctx->id);
953
+ DRM_DEV_DEBUG_KMS(ctx->dev, "fimc id[%d]\n", ctx->id);
950954
951955 fimc_clear_irq(ctx);
952956 if (fimc_check_ovf(ctx))
....@@ -959,7 +963,7 @@
959963 if (buf_id < 0)
960964 return IRQ_HANDLED;
961965
962
- DRM_DEBUG_KMS("buf_id[%d]\n", buf_id);
966
+ DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id);
963967
964968 if (ctx->task) {
965969 struct exynos_drm_ipp_task *task = ctx->task;
....@@ -1129,9 +1133,10 @@
11291133 struct exynos_drm_ipp *ipp = &ctx->ipp;
11301134
11311135 ctx->drm_dev = drm_dev;
1132
- drm_iommu_attach_device(drm_dev, dev);
1136
+ ipp->drm_dev = drm_dev;
1137
+ exynos_drm_register_dma(drm_dev, dev, &ctx->dma_priv);
11331138
1134
- exynos_drm_ipp_register(drm_dev, ipp, &ipp_funcs,
1139
+ exynos_drm_ipp_register(dev, ipp, &ipp_funcs,
11351140 DRM_EXYNOS_IPP_CAP_CROP | DRM_EXYNOS_IPP_CAP_ROTATE |
11361141 DRM_EXYNOS_IPP_CAP_SCALE | DRM_EXYNOS_IPP_CAP_CONVERT,
11371142 ctx->formats, ctx->num_formats, "fimc");
....@@ -1148,8 +1153,8 @@
11481153 struct drm_device *drm_dev = data;
11491154 struct exynos_drm_ipp *ipp = &ctx->ipp;
11501155
1151
- exynos_drm_ipp_unregister(drm_dev, ipp);
1152
- drm_iommu_detach_device(drm_dev, dev);
1156
+ exynos_drm_ipp_unregister(dev, ipp);
1157
+ exynos_drm_unregister_dma(drm_dev, dev, &ctx->dma_priv);
11531158 }
11541159
11551160 static const struct component_ops fimc_component_ops = {
....@@ -1381,7 +1386,7 @@
13811386 {
13821387 struct fimc_context *ctx = get_fimc_context(dev);
13831388
1384
- DRM_DEBUG_KMS("id[%d]\n", ctx->id);
1389
+ DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id);
13851390 clk_disable_unprepare(ctx->clocks[FIMC_CLK_GATE]);
13861391 return 0;
13871392 }
....@@ -1390,7 +1395,7 @@
13901395 {
13911396 struct fimc_context *ctx = get_fimc_context(dev);
13921397
1393
- DRM_DEBUG_KMS("id[%d]\n", ctx->id);
1398
+ DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id);
13941399 return clk_prepare_enable(ctx->clocks[FIMC_CLK_GATE]);
13951400 }
13961401 #endif