forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/pl111/pl111_display.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved.
34 *
....@@ -6,24 +7,19 @@
67 * Copyright (c) 2006-2008 Intel Corporation
78 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
89 * Copyright (C) 2011 Texas Instruments
9
- *
10
- * This program is free software and is provided to you under the terms of the
11
- * GNU General Public License version 2 as published by the Free Software
12
- * Foundation, and any use by you of this program is subject to the terms of
13
- * such GNU licence.
14
- *
1510 */
1611
17
-#include <linux/amba/clcd-regs.h>
1812 #include <linux/clk.h>
13
+#include <linux/delay.h>
1914 #include <linux/version.h>
2015 #include <linux/dma-buf.h>
2116 #include <linux/of_graph.h>
2217
23
-#include <drm/drmP.h>
18
+#include <drm/drm_fb_cma_helper.h>
19
+#include <drm/drm_fourcc.h>
2420 #include <drm/drm_gem_cma_helper.h>
2521 #include <drm/drm_gem_framebuffer_helper.h>
26
-#include <drm/drm_fb_cma_helper.h>
22
+#include <drm/drm_vblank.h>
2723
2824 #include "pl111_drm.h"
2925
....@@ -51,10 +47,10 @@
5147 }
5248
5349 static enum drm_mode_status
54
-pl111_mode_valid(struct drm_crtc *crtc,
50
+pl111_mode_valid(struct drm_simple_display_pipe *pipe,
5551 const struct drm_display_mode *mode)
5652 {
57
- struct drm_device *drm = crtc->dev;
53
+ struct drm_device *drm = pipe->crtc.dev;
5854 struct pl111_drm_dev_private *priv = drm->dev_private;
5955 u32 cpp = priv->variant->fb_bpp / 8;
6056 u64 bw;
....@@ -131,6 +127,7 @@
131127 struct drm_framebuffer *fb = plane->state->fb;
132128 struct drm_connector *connector = priv->connector;
133129 struct drm_bridge *bridge = priv->bridge;
130
+ bool grayscale = false;
134131 u32 cntl;
135132 u32 ppl, hsw, hfp, hbp;
136133 u32 lpp, vsw, vfp, vbp;
....@@ -188,8 +185,22 @@
188185 tim2 |= TIM2_IOE;
189186
190187 if (connector->display_info.bus_flags &
191
- DRM_BUS_FLAG_PIXDATA_NEGEDGE)
188
+ DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE)
192189 tim2 |= TIM2_IPC;
190
+
191
+ if (connector->display_info.num_bus_formats == 1 &&
192
+ connector->display_info.bus_formats[0] ==
193
+ MEDIA_BUS_FMT_Y8_1X8)
194
+ grayscale = true;
195
+
196
+ /*
197
+ * The AC pin bias frequency is set to max count when using
198
+ * grayscale so at least once in a while we will reverse
199
+ * polarity and get rid of any DC built up that could
200
+ * damage the display.
201
+ */
202
+ if (grayscale)
203
+ tim2 |= TIM2_ACB_MASK;
193204 }
194205
195206 if (bridge) {
....@@ -221,8 +232,18 @@
221232
222233 writel(0, priv->regs + CLCD_TIM3);
223234
224
- /* Hard-code TFT panel */
225
- cntl = CNTL_LCDEN | CNTL_LCDTFT | CNTL_LCDVCOMP(1);
235
+ /*
236
+ * Detect grayscale bus format. We do not support a grayscale mode
237
+ * toward userspace, instead we expose an RGB24 buffer and then the
238
+ * hardware will activate its grayscaler to convert to the grayscale
239
+ * format.
240
+ */
241
+ if (grayscale)
242
+ cntl = CNTL_LCDEN | CNTL_LCDMONO8;
243
+ else
244
+ /* Else we assume TFT display */
245
+ cntl = CNTL_LCDEN | CNTL_LCDTFT | CNTL_LCDVCOMP(1);
246
+
226247 /* On the ST Micro variant, assume all 24 bits are connected */
227248 if (priv->variant->st_bitmux_control)
228249 cntl |= CNTL_ST_CDWID_24;
....@@ -551,24 +572,7 @@
551572 int pl111_display_init(struct drm_device *drm)
552573 {
553574 struct pl111_drm_dev_private *priv = drm->dev_private;
554
- struct device *dev = drm->dev;
555
- struct device_node *endpoint;
556
- u32 tft_r0b0g0[3];
557575 int ret;
558
-
559
- endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
560
- if (!endpoint)
561
- return -ENODEV;
562
-
563
- if (of_property_read_u32_array(endpoint,
564
- "arm,pl11x,tft-r0g0b0-pads",
565
- tft_r0b0g0,
566
- ARRAY_SIZE(tft_r0b0g0)) != 0) {
567
- dev_err(dev, "arm,pl11x,tft-r0g0b0-pads should be 3 ints\n");
568
- of_node_put(endpoint);
569
- return -ENOENT;
570
- }
571
- of_node_put(endpoint);
572576
573577 ret = pl111_init_clock_divider(drm);
574578 if (ret)