.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * i.MX IPUv3 Graphics driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
14 | 6 | */ |
---|
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 | + |
---|
24 | 8 | #include <linux/clk.h> |
---|
| 9 | +#include <linux/component.h> |
---|
| 10 | +#include <linux/device.h> |
---|
| 11 | +#include <linux/dma-mapping.h> |
---|
25 | 12 | #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> |
---|
28 | 16 | |
---|
29 | 17 | #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 | + |
---|
30 | 26 | #include "imx-drm.h" |
---|
31 | 27 | #include "ipuv3-plane.h" |
---|
32 | 28 | |
---|
.. | .. |
---|
42 | 38 | struct ipu_dc *dc; |
---|
43 | 39 | struct ipu_di *di; |
---|
44 | 40 | int irq; |
---|
| 41 | + struct drm_pending_vblank_event *event; |
---|
45 | 42 | }; |
---|
46 | 43 | |
---|
47 | 44 | static inline struct ipu_crtc *to_ipu_crtc(struct drm_crtc *crtc) |
---|
.. | .. |
---|
71 | 68 | drm_atomic_crtc_state_for_each_plane(plane, old_crtc_state) { |
---|
72 | 69 | if (plane == &ipu_crtc->plane[0]->base) |
---|
73 | 70 | 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) |
---|
75 | 72 | disable_partial = true; |
---|
76 | 73 | } |
---|
77 | 74 | |
---|
.. | .. |
---|
112 | 109 | { |
---|
113 | 110 | struct imx_crtc_state *state; |
---|
114 | 111 | |
---|
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); |
---|
118 | 114 | |
---|
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; |
---|
127 | 117 | |
---|
128 | | - state->base.crtc = crtc; |
---|
| 118 | + state = kzalloc(sizeof(*state), GFP_KERNEL); |
---|
| 119 | + if (state) |
---|
| 120 | + __drm_atomic_helper_crtc_reset(crtc, &state->base); |
---|
129 | 121 | } |
---|
130 | 122 | |
---|
131 | 123 | static struct drm_crtc_state *imx_drm_crtc_duplicate_state(struct drm_crtc *crtc) |
---|
.. | .. |
---|
181 | 173 | static irqreturn_t ipu_irq_handler(int irq, void *dev_id) |
---|
182 | 174 | { |
---|
183 | 175 | struct ipu_crtc *ipu_crtc = dev_id; |
---|
| 176 | + struct drm_crtc *crtc = &ipu_crtc->base; |
---|
| 177 | + unsigned long flags; |
---|
| 178 | + int i; |
---|
184 | 179 | |
---|
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 | + } |
---|
186 | 201 | |
---|
187 | 202 | return IRQ_HANDLED; |
---|
188 | 203 | } |
---|
.. | .. |
---|
231 | 246 | { |
---|
232 | 247 | spin_lock_irq(&crtc->dev->event_lock); |
---|
233 | 248 | if (crtc->state->event) { |
---|
| 249 | + struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); |
---|
| 250 | + |
---|
234 | 251 | WARN_ON(drm_crtc_vblank_get(crtc)); |
---|
235 | | - drm_crtc_arm_vblank_event(crtc, crtc->state->event); |
---|
| 252 | + ipu_crtc->event = crtc->state->event; |
---|
236 | 253 | crtc->state->event = NULL; |
---|
237 | 254 | } |
---|
238 | 255 | spin_unlock_irq(&crtc->dev->event_lock); |
---|
.. | .. |
---|
277 | 294 | sig_cfg.enable_pol = !(imx_crtc_state->bus_flags & DRM_BUS_FLAG_DE_LOW); |
---|
278 | 295 | /* Default to driving pixel data on negative clock edges */ |
---|
279 | 296 | sig_cfg.clk_pol = !!(imx_crtc_state->bus_flags & |
---|
280 | | - DRM_BUS_FLAG_PIXDATA_POSEDGE); |
---|
| 297 | + DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE); |
---|
281 | 298 | sig_cfg.bus_format = imx_crtc_state->bus_format; |
---|
282 | 299 | sig_cfg.v_to_h_sync = 0; |
---|
283 | 300 | sig_cfg.hsync_pin = imx_crtc_state->di_hsync_pin; |
---|
.. | .. |
---|
416 | 433 | struct ipu_client_platformdata *pdata = dev->platform_data; |
---|
417 | 434 | struct drm_device *drm = data; |
---|
418 | 435 | struct ipu_crtc *ipu_crtc; |
---|
419 | | - int ret; |
---|
420 | 436 | |
---|
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)); |
---|
424 | 439 | |
---|
425 | 440 | ipu_crtc->dev = dev; |
---|
426 | 441 | |
---|
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); |
---|
434 | 443 | } |
---|
435 | 444 | |
---|
436 | 445 | static void ipu_drm_unbind(struct device *dev, struct device *master, |
---|
.. | .. |
---|
452 | 461 | static int ipu_drm_probe(struct platform_device *pdev) |
---|
453 | 462 | { |
---|
454 | 463 | struct device *dev = &pdev->dev; |
---|
| 464 | + struct ipu_crtc *ipu_crtc; |
---|
455 | 465 | int ret; |
---|
456 | 466 | |
---|
457 | 467 | if (!dev->platform_data) |
---|
.. | .. |
---|
461 | 471 | if (ret) |
---|
462 | 472 | return ret; |
---|
463 | 473 | |
---|
| 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 | + |
---|
464 | 480 | return component_add(dev, &ipu_crtc_ops); |
---|
465 | 481 | } |
---|
466 | 482 | |
---|