forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/rcar-du/rcar_du_encoder.c
....@@ -1,56 +1,56 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * rcar_du_encoder.c -- R-Car Display Unit Encoder
34 *
45 * Copyright (C) 2013-2014 Renesas Electronics Corporation
56 *
67 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
128 */
139
1410 #include <linux/export.h>
1511
16
-#include <drm/drmP.h>
12
+#include <drm/drm_bridge.h>
1713 #include <drm/drm_crtc.h>
18
-#include <drm/drm_crtc_helper.h>
14
+#include <drm/drm_modeset_helper_vtables.h>
1915 #include <drm/drm_panel.h>
16
+#include <drm/drm_simple_kms_helper.h>
2017
2118 #include "rcar_du_drv.h"
2219 #include "rcar_du_encoder.h"
2320 #include "rcar_du_kms.h"
21
+#include "rcar_lvds.h"
2422
2523 /* -----------------------------------------------------------------------------
2624 * Encoder
2725 */
2826
29
-static void rcar_du_encoder_mode_set(struct drm_encoder *encoder,
30
- struct drm_crtc_state *crtc_state,
31
- struct drm_connector_state *conn_state)
27
+static unsigned int rcar_du_encoder_count_ports(struct device_node *node)
3228 {
33
- struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
29
+ struct device_node *ports;
30
+ struct device_node *port;
31
+ unsigned int num_ports = 0;
3432
35
- rcar_du_crtc_route_output(crtc_state->crtc, renc->output);
33
+ ports = of_get_child_by_name(node, "ports");
34
+ if (!ports)
35
+ ports = of_node_get(node);
36
+
37
+ for_each_child_of_node(ports, port) {
38
+ if (of_node_name_eq(port, "port"))
39
+ num_ports++;
40
+ }
41
+
42
+ of_node_put(ports);
43
+
44
+ return num_ports;
3645 }
37
-
38
-static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
39
- .atomic_mode_set = rcar_du_encoder_mode_set,
40
-};
41
-
42
-static const struct drm_encoder_funcs encoder_funcs = {
43
- .destroy = drm_encoder_cleanup,
44
-};
4546
4647 int rcar_du_encoder_init(struct rcar_du_device *rcdu,
4748 enum rcar_du_output output,
48
- struct device_node *enc_node,
49
- struct device_node *con_node)
49
+ struct device_node *enc_node)
5050 {
5151 struct rcar_du_encoder *renc;
5252 struct drm_encoder *encoder;
53
- struct drm_bridge *bridge = NULL;
53
+ struct drm_bridge *bridge;
5454 int ret;
5555
5656 renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
....@@ -63,25 +63,60 @@
6363 dev_dbg(rcdu->dev, "initializing encoder %pOF for output %u\n",
6464 enc_node, output);
6565
66
- /* Locate the DRM bridge from the encoder DT node. */
67
- bridge = of_drm_find_bridge(enc_node);
68
- if (!bridge) {
69
- ret = -EPROBE_DEFER;
70
- goto done;
66
+ /*
67
+ * Locate the DRM bridge from the DT node. For the DPAD outputs, if the
68
+ * DT node has a single port, assume that it describes a panel and
69
+ * create a panel bridge.
70
+ */
71
+ if ((output == RCAR_DU_OUTPUT_DPAD0 ||
72
+ output == RCAR_DU_OUTPUT_DPAD1) &&
73
+ rcar_du_encoder_count_ports(enc_node) == 1) {
74
+ struct drm_panel *panel = of_drm_find_panel(enc_node);
75
+
76
+ if (IS_ERR(panel)) {
77
+ ret = PTR_ERR(panel);
78
+ goto done;
79
+ }
80
+
81
+ bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel,
82
+ DRM_MODE_CONNECTOR_DPI);
83
+ if (IS_ERR(bridge)) {
84
+ ret = PTR_ERR(bridge);
85
+ goto done;
86
+ }
87
+ } else {
88
+ bridge = of_drm_find_bridge(enc_node);
89
+ if (!bridge) {
90
+ ret = -EPROBE_DEFER;
91
+ goto done;
92
+ }
93
+
94
+ if (output == RCAR_DU_OUTPUT_LVDS0 ||
95
+ output == RCAR_DU_OUTPUT_LVDS1)
96
+ rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] = bridge;
7197 }
7298
73
- ret = drm_encoder_init(rcdu->ddev, encoder, &encoder_funcs,
74
- DRM_MODE_ENCODER_NONE, NULL);
99
+ /*
100
+ * On Gen3 skip the LVDS1 output if the LVDS1 encoder is used as a
101
+ * companion for LVDS0 in dual-link mode.
102
+ */
103
+ if (rcdu->info->gen >= 3 && output == RCAR_DU_OUTPUT_LVDS1) {
104
+ if (rcar_lvds_dual_link(bridge)) {
105
+ ret = -ENOLINK;
106
+ goto done;
107
+ }
108
+ }
109
+
110
+ ret = drm_simple_encoder_init(rcdu->ddev, encoder,
111
+ DRM_MODE_ENCODER_NONE);
75112 if (ret < 0)
76113 goto done;
77
-
78
- drm_encoder_helper_add(encoder, &encoder_helper_funcs);
79114
80115 /*
81116 * Attach the bridge to the encoder. The bridge will create the
82117 * connector.
83118 */
84
- ret = drm_bridge_attach(encoder, bridge, NULL);
119
+ ret = drm_bridge_attach(encoder, bridge, NULL, 0);
85120 if (ret) {
86121 drm_encoder_cleanup(encoder);
87122 return ret;