forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/imx/ipuv3-crtc.c
....@@ -1,32 +1,28 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * i.MX IPUv3 Graphics driver
34 *
45 * Copyright (C) 2011 Sascha Hauer, Pengutronix
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version 2
9
- * of the License, or (at your option) any later version.
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
15
-#include <linux/component.h>
16
-#include <linux/module.h>
17
-#include <linux/export.h>
18
-#include <linux/device.h>
19
-#include <linux/platform_device.h>
20
-#include <drm/drmP.h>
21
-#include <drm/drm_atomic.h>
22
-#include <drm/drm_atomic_helper.h>
23
-#include <drm/drm_crtc_helper.h>
7
+
248 #include <linux/clk.h>
9
+#include <linux/component.h>
10
+#include <linux/device.h>
11
+#include <linux/dma-mapping.h>
2512 #include <linux/errno.h>
26
-#include <drm/drm_gem_cma_helper.h>
27
-#include <drm/drm_fb_cma_helper.h>
13
+#include <linux/export.h>
14
+#include <linux/module.h>
15
+#include <linux/platform_device.h>
2816
2917 #include <video/imx-ipu-v3.h>
18
+
19
+#include <drm/drm_atomic.h>
20
+#include <drm/drm_atomic_helper.h>
21
+#include <drm/drm_fb_cma_helper.h>
22
+#include <drm/drm_gem_cma_helper.h>
23
+#include <drm/drm_probe_helper.h>
24
+#include <drm/drm_vblank.h>
25
+
3026 #include "imx-drm.h"
3127 #include "ipuv3-plane.h"
3228
....@@ -42,6 +38,7 @@
4238 struct ipu_dc *dc;
4339 struct ipu_di *di;
4440 int irq;
41
+ struct drm_pending_vblank_event *event;
4542 };
4643
4744 static inline struct ipu_crtc *to_ipu_crtc(struct drm_crtc *crtc)
....@@ -71,7 +68,7 @@
7168 drm_atomic_crtc_state_for_each_plane(plane, old_crtc_state) {
7269 if (plane == &ipu_crtc->plane[0]->base)
7370 disable_full = true;
74
- if (&ipu_crtc->plane[1] && plane == &ipu_crtc->plane[1]->base)
71
+ if (ipu_crtc->plane[1] && plane == &ipu_crtc->plane[1]->base)
7572 disable_partial = true;
7673 }
7774
....@@ -112,20 +109,15 @@
112109 {
113110 struct imx_crtc_state *state;
114111
115
- if (crtc->state) {
116
- if (crtc->state->mode_blob)
117
- drm_property_blob_put(crtc->state->mode_blob);
112
+ if (crtc->state)
113
+ __drm_atomic_helper_crtc_destroy_state(crtc->state);
118114
119
- state = to_imx_crtc_state(crtc->state);
120
- memset(state, 0, sizeof(*state));
121
- } else {
122
- state = kzalloc(sizeof(*state), GFP_KERNEL);
123
- if (!state)
124
- return;
125
- crtc->state = &state->base;
126
- }
115
+ kfree(to_imx_crtc_state(crtc->state));
116
+ crtc->state = NULL;
127117
128
- state->base.crtc = crtc;
118
+ state = kzalloc(sizeof(*state), GFP_KERNEL);
119
+ if (state)
120
+ __drm_atomic_helper_crtc_reset(crtc, &state->base);
129121 }
130122
131123 static struct drm_crtc_state *imx_drm_crtc_duplicate_state(struct drm_crtc *crtc)
....@@ -181,8 +173,31 @@
181173 static irqreturn_t ipu_irq_handler(int irq, void *dev_id)
182174 {
183175 struct ipu_crtc *ipu_crtc = dev_id;
176
+ struct drm_crtc *crtc = &ipu_crtc->base;
177
+ unsigned long flags;
178
+ int i;
184179
185
- drm_crtc_handle_vblank(&ipu_crtc->base);
180
+ drm_crtc_handle_vblank(crtc);
181
+
182
+ if (ipu_crtc->event) {
183
+ for (i = 0; i < ARRAY_SIZE(ipu_crtc->plane); i++) {
184
+ struct ipu_plane *plane = ipu_crtc->plane[i];
185
+
186
+ if (!plane)
187
+ continue;
188
+
189
+ if (ipu_plane_atomic_update_pending(&plane->base))
190
+ break;
191
+ }
192
+
193
+ if (i == ARRAY_SIZE(ipu_crtc->plane)) {
194
+ spin_lock_irqsave(&crtc->dev->event_lock, flags);
195
+ drm_crtc_send_vblank_event(crtc, ipu_crtc->event);
196
+ ipu_crtc->event = NULL;
197
+ drm_crtc_vblank_put(crtc);
198
+ spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
199
+ }
200
+ }
186201
187202 return IRQ_HANDLED;
188203 }
....@@ -231,8 +246,10 @@
231246 {
232247 spin_lock_irq(&crtc->dev->event_lock);
233248 if (crtc->state->event) {
249
+ struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
250
+
234251 WARN_ON(drm_crtc_vblank_get(crtc));
235
- drm_crtc_arm_vblank_event(crtc, crtc->state->event);
252
+ ipu_crtc->event = crtc->state->event;
236253 crtc->state->event = NULL;
237254 }
238255 spin_unlock_irq(&crtc->dev->event_lock);
....@@ -277,7 +294,7 @@
277294 sig_cfg.enable_pol = !(imx_crtc_state->bus_flags & DRM_BUS_FLAG_DE_LOW);
278295 /* Default to driving pixel data on negative clock edges */
279296 sig_cfg.clk_pol = !!(imx_crtc_state->bus_flags &
280
- DRM_BUS_FLAG_PIXDATA_POSEDGE);
297
+ DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE);
281298 sig_cfg.bus_format = imx_crtc_state->bus_format;
282299 sig_cfg.v_to_h_sync = 0;
283300 sig_cfg.hsync_pin = imx_crtc_state->di_hsync_pin;
....@@ -416,21 +433,13 @@
416433 struct ipu_client_platformdata *pdata = dev->platform_data;
417434 struct drm_device *drm = data;
418435 struct ipu_crtc *ipu_crtc;
419
- int ret;
420436
421
- ipu_crtc = devm_kzalloc(dev, sizeof(*ipu_crtc), GFP_KERNEL);
422
- if (!ipu_crtc)
423
- return -ENOMEM;
437
+ ipu_crtc = dev_get_drvdata(dev);
438
+ memset(ipu_crtc, 0, sizeof(*ipu_crtc));
424439
425440 ipu_crtc->dev = dev;
426441
427
- ret = ipu_crtc_init(ipu_crtc, pdata, drm);
428
- if (ret)
429
- return ret;
430
-
431
- dev_set_drvdata(dev, ipu_crtc);
432
-
433
- return 0;
442
+ return ipu_crtc_init(ipu_crtc, pdata, drm);
434443 }
435444
436445 static void ipu_drm_unbind(struct device *dev, struct device *master,
....@@ -452,6 +461,7 @@
452461 static int ipu_drm_probe(struct platform_device *pdev)
453462 {
454463 struct device *dev = &pdev->dev;
464
+ struct ipu_crtc *ipu_crtc;
455465 int ret;
456466
457467 if (!dev->platform_data)
....@@ -461,6 +471,12 @@
461471 if (ret)
462472 return ret;
463473
474
+ ipu_crtc = devm_kzalloc(dev, sizeof(*ipu_crtc), GFP_KERNEL);
475
+ if (!ipu_crtc)
476
+ return -ENOMEM;
477
+
478
+ dev_set_drvdata(dev, ipu_crtc);
479
+
464480 return component_add(dev, &ipu_crtc_ops);
465481 }
466482