forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/tilcdc/tilcdc_external.c
....@@ -1,16 +1,16 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2015 Texas Instruments
34 * Author: Jyri Sarha <jsarha@ti.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License version 2 as published by
7
- * the Free Software Foundation.
8
- *
95 */
106
117 #include <linux/component.h>
128 #include <linux/of_graph.h>
9
+
10
+#include <drm/drm_atomic_helper.h>
11
+#include <drm/drm_bridge.h>
1312 #include <drm/drm_of.h>
13
+#include <drm/drm_simple_kms_helper.h>
1414
1515 #include "tilcdc_drv.h"
1616 #include "tilcdc_external.h"
....@@ -40,64 +40,6 @@
4040 .raster_order = 0,
4141 };
4242
43
-static int tilcdc_external_mode_valid(struct drm_connector *connector,
44
- struct drm_display_mode *mode)
45
-{
46
- struct tilcdc_drm_private *priv = connector->dev->dev_private;
47
- int ret;
48
-
49
- ret = tilcdc_crtc_mode_valid(priv->crtc, mode);
50
- if (ret != MODE_OK)
51
- return ret;
52
-
53
- BUG_ON(priv->external_connector != connector);
54
- BUG_ON(!priv->connector_funcs);
55
-
56
- /* If the connector has its own mode_valid call it. */
57
- if (!IS_ERR(priv->connector_funcs) &&
58
- priv->connector_funcs->mode_valid)
59
- return priv->connector_funcs->mode_valid(connector, mode);
60
-
61
- return MODE_OK;
62
-}
63
-
64
-static int tilcdc_add_external_connector(struct drm_device *dev,
65
- struct drm_connector *connector)
66
-{
67
- struct tilcdc_drm_private *priv = dev->dev_private;
68
- struct drm_connector_helper_funcs *connector_funcs;
69
-
70
- /* There should never be more than one connector */
71
- if (WARN_ON(priv->external_connector))
72
- return -EINVAL;
73
-
74
- priv->external_connector = connector;
75
- connector_funcs = devm_kzalloc(dev->dev, sizeof(*connector_funcs),
76
- GFP_KERNEL);
77
- if (!connector_funcs)
78
- return -ENOMEM;
79
-
80
- /* connector->helper_private contains always struct
81
- * connector_helper_funcs pointer. For tilcdc crtc to have a
82
- * say if a specific mode is Ok, we need to install our own
83
- * helper functions. In our helper functions we copy
84
- * everything else but use our own mode_valid() (above).
85
- */
86
- if (connector->helper_private) {
87
- priv->connector_funcs = connector->helper_private;
88
- *connector_funcs = *priv->connector_funcs;
89
- } else {
90
- priv->connector_funcs = ERR_PTR(-ENOENT);
91
- }
92
- connector_funcs->mode_valid = tilcdc_external_mode_valid;
93
- drm_connector_helper_add(connector, connector_funcs);
94
-
95
- dev_dbg(dev->dev, "External connector '%s' connected\n",
96
- connector->name);
97
-
98
- return 0;
99
-}
100
-
10143 static
10244 struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev,
10345 struct drm_encoder *encoder)
....@@ -118,56 +60,41 @@
11860 int tilcdc_add_component_encoder(struct drm_device *ddev)
11961 {
12062 struct tilcdc_drm_private *priv = ddev->dev_private;
121
- struct drm_connector *connector;
122
- struct drm_encoder *encoder;
63
+ struct drm_encoder *encoder = NULL, *iter;
12364
124
- list_for_each_entry(encoder, &ddev->mode_config.encoder_list, head)
125
- if (encoder->possible_crtcs & (1 << priv->crtc->index))
65
+ list_for_each_entry(iter, &ddev->mode_config.encoder_list, head)
66
+ if (iter->possible_crtcs & (1 << priv->crtc->index)) {
67
+ encoder = iter;
12668 break;
69
+ }
12770
12871 if (!encoder) {
12972 dev_err(ddev->dev, "%s: No suitable encoder found\n", __func__);
13073 return -ENODEV;
13174 }
13275
133
- connector = tilcdc_encoder_find_connector(ddev, encoder);
76
+ priv->external_connector =
77
+ tilcdc_encoder_find_connector(ddev, encoder);
13478
135
- if (!connector)
79
+ if (!priv->external_connector)
13680 return -ENODEV;
13781
13882 /* Only tda998x is supported at the moment. */
13983 tilcdc_crtc_set_simulate_vesa_sync(priv->crtc, true);
14084 tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x);
14185
142
- return tilcdc_add_external_connector(ddev, connector);
86
+ return 0;
14387 }
144
-
145
-void tilcdc_remove_external_device(struct drm_device *dev)
146
-{
147
- struct tilcdc_drm_private *priv = dev->dev_private;
148
-
149
- /* Restore the original helper functions, if any. */
150
- if (IS_ERR(priv->connector_funcs))
151
- drm_connector_helper_add(priv->external_connector, NULL);
152
- else if (priv->connector_funcs)
153
- drm_connector_helper_add(priv->external_connector,
154
- priv->connector_funcs);
155
-}
156
-
157
-static const struct drm_encoder_funcs tilcdc_external_encoder_funcs = {
158
- .destroy = drm_encoder_cleanup,
159
-};
16088
16189 static
16290 int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge)
16391 {
16492 struct tilcdc_drm_private *priv = ddev->dev_private;
165
- struct drm_connector *connector;
16693 int ret;
16794
16895 priv->external_encoder->possible_crtcs = BIT(0);
16996
170
- ret = drm_bridge_attach(priv->external_encoder, bridge, NULL);
97
+ ret = drm_bridge_attach(priv->external_encoder, bridge, NULL, 0);
17198 if (ret) {
17299 dev_err(ddev->dev, "drm_bridge_attach() failed %d\n", ret);
173100 return ret;
....@@ -175,13 +102,12 @@
175102
176103 tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_default);
177104
178
- connector = tilcdc_encoder_find_connector(ddev, priv->external_encoder);
179
- if (!connector)
105
+ priv->external_connector =
106
+ tilcdc_encoder_find_connector(ddev, priv->external_encoder);
107
+ if (!priv->external_connector)
180108 return -ENODEV;
181109
182
- ret = tilcdc_add_external_connector(ddev, connector);
183
-
184
- return ret;
110
+ return 0;
185111 }
186112
187113 int tilcdc_attach_external_device(struct drm_device *ddev)
....@@ -204,17 +130,16 @@
204130 if (!priv->external_encoder)
205131 return -ENOMEM;
206132
207
- ret = drm_encoder_init(ddev, priv->external_encoder,
208
- &tilcdc_external_encoder_funcs,
209
- DRM_MODE_ENCODER_NONE, NULL);
133
+ ret = drm_simple_encoder_init(ddev, priv->external_encoder,
134
+ DRM_MODE_ENCODER_NONE);
210135 if (ret) {
211136 dev_err(ddev->dev, "drm_encoder_init() failed %d\n", ret);
212137 return ret;
213138 }
214139
215140 if (panel) {
216
- bridge = devm_drm_panel_bridge_add(ddev->dev, panel,
217
- DRM_MODE_CONNECTOR_DPI);
141
+ bridge = devm_drm_panel_bridge_add_typed(ddev->dev, panel,
142
+ DRM_MODE_CONNECTOR_DPI);
218143 if (IS_ERR(bridge)) {
219144 ret = PTR_ERR(bridge);
220145 goto err_encoder_cleanup;