forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/gpu/drm/rockchip/cdn-dp-core.c
....@@ -1,35 +1,25 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
34 * Author: Chris Zhong <zyw@rock-chips.com>
4
- *
5
- * This software is licensed under the terms of the GNU General Public
6
- * License version 2, as published by the Free Software Foundation, and
7
- * may be copied, distributed, and modified under those terms.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
14
-
15
-#include <drm/drmP.h>
16
-#include <drm/drm_atomic_helper.h>
17
-#include <drm/drm_crtc_helper.h>
18
-#include <drm/drm_dp_helper.h>
19
-#include <drm/drm_edid.h>
20
-#include <drm/drm_of.h>
216
227 #include <linux/clk.h>
238 #include <linux/component.h>
24
-#include <linux/extcon.h>
259 #include <linux/firmware.h>
26
-#include <linux/regmap.h>
27
-#include <linux/reset.h>
2810 #include <linux/mfd/syscon.h>
2911 #include <linux/phy/phy.h>
30
-#include <uapi/linux/videodev2.h>
12
+#include <linux/regmap.h>
13
+#include <linux/reset.h>
3114
3215 #include <sound/hdmi-codec.h>
16
+
17
+#include <drm/drm_atomic_helper.h>
18
+#include <drm/drm_dp_helper.h>
19
+#include <drm/drm_edid.h>
20
+#include <drm/drm_of.h>
21
+#include <drm/drm_probe_helper.h>
22
+#include <drm/drm_simple_kms_helper.h>
3323
3424 #include "cdn-dp-core.h"
3525 #include "cdn-dp-reg.h"
....@@ -152,24 +142,7 @@
152142
153143 static int cdn_dp_get_port_lanes(struct cdn_dp_port *port)
154144 {
155
- struct extcon_dev *edev = port->extcon;
156
- union extcon_property_value property;
157
- int dptx;
158
- u8 lanes;
159
-
160
- dptx = extcon_get_state(edev, EXTCON_DISP_DP);
161
- if (dptx > 0) {
162
- extcon_get_property(edev, EXTCON_DISP_DP,
163
- EXTCON_PROP_USB_SS, &property);
164
- if (property.intval)
165
- lanes = 2;
166
- else
167
- lanes = 4;
168
- } else {
169
- lanes = 0;
170
- }
171
-
172
- return lanes;
145
+ return phy_get_bus_width(port->phy);
173146 }
174147
175148 static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count)
....@@ -178,8 +151,8 @@
178151 u8 value;
179152
180153 *sink_count = 0;
181
- ret = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, &value, 1);
182
- if (ret < 0)
154
+ ret = cdn_dp_dpcd_read(dp, DP_SINK_COUNT, &value, 1);
155
+ if (ret)
183156 return ret;
184157
185158 *sink_count = DP_GET_SINK_COUNT(value);
....@@ -203,15 +176,12 @@
203176 static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)
204177 {
205178 unsigned long timeout = jiffies + msecs_to_jiffies(CDN_DPCD_TIMEOUT_MS);
206
- struct cdn_dp_port *port;
207179 u8 sink_count = 0;
208180
209181 if (dp->active_port < 0 || dp->active_port >= dp->ports) {
210182 DRM_DEV_ERROR(dp->dev, "active_port is wrong!\n");
211183 return false;
212184 }
213
-
214
- port = dp->port[dp->active_port];
215185
216186 /*
217187 * Attempt to read sink count, retry in case the sink may not be ready.
....@@ -220,9 +190,6 @@
220190 * some docks need more time to power up.
221191 */
222192 while (time_before(jiffies, timeout)) {
223
- if (!extcon_get_state(port->extcon, EXTCON_DISP_DP))
224
- return false;
225
-
226193 if (!cdn_dp_get_sink_count(dp, &sink_count))
227194 return sink_count ? true : false;
228195
....@@ -253,22 +220,11 @@
253220 drm_connector_cleanup(connector);
254221 }
255222
256
-static int
257
-cdn_dp_atomic_connector_get_property(struct drm_connector *connector,
258
- const struct drm_connector_state *state,
259
- struct drm_property *property,
260
- uint64_t *val)
223
+static void cdn_dp_oob_hotplug_event(struct drm_connector *connector)
261224 {
262225 struct cdn_dp_device *dp = connector_to_dp(connector);
263
- struct rockchip_drm_private *private = connector->dev->dev_private;
264226
265
- if (property == private->connector_id_prop) {
266
- *val = dp->id;
267
- return 0;
268
- }
269
-
270
- DRM_ERROR("failed to get rockchip CDN DP property\n");
271
- return -EINVAL;
227
+ schedule_delayed_work(&dp->event_work, msecs_to_jiffies(100));
272228 }
273229
274230 static const struct drm_connector_funcs cdn_dp_atomic_connector_funcs = {
....@@ -278,7 +234,6 @@
278234 .reset = drm_atomic_helper_connector_reset,
279235 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
280236 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
281
- .atomic_get_property = cdn_dp_atomic_connector_get_property,
282237 };
283238
284239 static int cdn_dp_connector_get_modes(struct drm_connector *connector)
....@@ -298,27 +253,19 @@
298253 if (ret)
299254 drm_connector_update_edid_property(connector,
300255 edid);
301
- } else {
302
- ret = rockchip_drm_add_modes_noedid(connector);
303
-
304
- dev_info(dp->dev, "failed to get edid\n");
305256 }
306257 mutex_unlock(&dp->lock);
307258
308259 return ret;
309260 }
310261
311
-static int cdn_dp_connector_mode_valid(struct drm_connector *connector,
312
- struct drm_display_mode *mode)
262
+static enum drm_mode_status
263
+cdn_dp_connector_mode_valid(struct drm_connector *connector,
264
+ struct drm_display_mode *mode)
313265 {
314266 struct cdn_dp_device *dp = connector_to_dp(connector);
315267 struct drm_display_info *display_info = &dp->connector.display_info;
316268 u32 requested, actual, rate, sink_max, source_max = 0;
317
- struct drm_encoder *encoder = connector->encoder;
318
- enum drm_mode_status status = MODE_OK;
319
- struct drm_device *dev = connector->dev;
320
- struct rockchip_drm_private *priv = dev->dev_private;
321
- struct drm_crtc *crtc;
322269 u8 lanes, bpc;
323270
324271 /* If DP is disconnected, every mode is invalid */
....@@ -336,9 +283,6 @@
336283 bpc = 8;
337284 break;
338285 }
339
-
340
- if (!IS_ALIGNED(mode->hdisplay * bpc, 8))
341
- return MODE_H_ILLEGAL;
342286
343287 requested = mode->clock * bpc * 3 / 1000;
344288
....@@ -360,42 +304,6 @@
360304 "requested=%d, actual=%d, clock=%d\n",
361305 requested, actual, mode->clock);
362306 return MODE_CLOCK_HIGH;
363
- }
364
-
365
- if (!encoder) {
366
- const struct drm_connector_helper_funcs *funcs;
367
-
368
- funcs = connector->helper_private;
369
- if (funcs->atomic_best_encoder)
370
- encoder = funcs->atomic_best_encoder(connector,
371
- connector->state);
372
- else if (funcs->best_encoder)
373
- encoder = funcs->best_encoder(connector);
374
- else
375
- encoder = drm_atomic_helper_best_encoder(connector);
376
- }
377
-
378
- if (!encoder || !encoder->possible_crtcs)
379
- return MODE_BAD;
380
- /*
381
- * ensure all drm display mode can work, if someone want support more
382
- * resolutions, please limit the possible_crtc, only connect to
383
- * needed crtc.
384
- */
385
- drm_for_each_crtc(crtc, connector->dev) {
386
- int pipe = drm_crtc_index(crtc);
387
- const struct rockchip_crtc_funcs *funcs =
388
- priv->crtc_funcs[pipe];
389
-
390
- if (!(encoder->possible_crtcs & drm_crtc_mask(crtc)))
391
- continue;
392
- if (!funcs || !funcs->mode_valid)
393
- continue;
394
-
395
- status = funcs->mode_valid(crtc, mode,
396
- DRM_MODE_CONNECTOR_HDMIA);
397
- if (status != MODE_OK)
398
- return status;
399307 }
400308
401309 return MODE_OK;
....@@ -443,9 +351,9 @@
443351 if (!cdn_dp_check_sink_connection(dp))
444352 return -ENODEV;
445353
446
- ret = drm_dp_dpcd_read(&dp->aux, DP_DPCD_REV, dp->dpcd,
447
- sizeof(dp->dpcd));
448
- if (ret < 0) {
354
+ ret = cdn_dp_dpcd_read(dp, DP_DPCD_REV, dp->dpcd,
355
+ DP_RECEIVER_CAP_SIZE);
356
+ if (ret) {
449357 DRM_DEV_ERROR(dp->dev, "Failed to get caps %d\n", ret);
450358 return ret;
451359 }
....@@ -458,7 +366,6 @@
458366
459367 static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
460368 {
461
- union extcon_property_value property;
462369 int ret;
463370
464371 if (!port->phy_enabled) {
....@@ -485,15 +392,8 @@
485392 goto err_power_on;
486393 }
487394
488
- ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
489
- EXTCON_PROP_USB_TYPEC_POLARITY, &property);
490
- if (ret) {
491
- DRM_DEV_ERROR(dp->dev, "get property failed\n");
492
- goto err_power_on;
493
- }
494
-
495395 port->lanes = cdn_dp_get_port_lanes(port);
496
- ret = cdn_dp_set_host_cap(dp, port->lanes, property.intval);
396
+ ret = cdn_dp_set_host_cap(dp, port->lanes, 0);
497397 if (ret) {
498398 DRM_DEV_ERROR(dp->dev, "set host capabilities failed: %d\n",
499399 ret);
....@@ -555,8 +455,8 @@
555455 cdn_dp_set_firmware_active(dp, false);
556456 cdn_dp_clk_disable(dp);
557457 dp->active = false;
558
- dp->link.rate = 0;
559
- dp->link.num_lanes = 0;
458
+ dp->max_lanes = 0;
459
+ dp->max_rate = 0;
560460 if (!dp->connected) {
561461 kfree(dp->edid);
562462 dp->edid = NULL;
....@@ -648,11 +548,11 @@
648548 struct cdn_dp_port *port = cdn_dp_connected_port(dp);
649549 u8 sink_lanes = drm_dp_max_lane_count(dp->dpcd);
650550
651
- if (!port || !dp->link.rate || !dp->link.num_lanes)
551
+ if (!port || !dp->max_rate || !dp->max_lanes)
652552 return false;
653553
654
- if (drm_dp_dpcd_read_link_status(&dp->aux, link_status) !=
655
- DP_LINK_STATUS_SIZE) {
554
+ if (cdn_dp_dpcd_read(dp, DP_LANE0_1_STATUS, link_status,
555
+ DP_LINK_STATUS_SIZE)) {
656556 DRM_ERROR("Failed to get link status\n");
657557 return false;
658558 }
....@@ -698,13 +598,11 @@
698598 goto out;
699599 }
700600 }
701
- if (dp->use_fw_training) {
702
- ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_IDLE);
703
- if (ret) {
704
- DRM_DEV_ERROR(dp->dev,
705
- "Failed to idle video %d\n", ret);
706
- goto out;
707
- }
601
+
602
+ ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_IDLE);
603
+ if (ret) {
604
+ DRM_DEV_ERROR(dp->dev, "Failed to idle video %d\n", ret);
605
+ goto out;
708606 }
709607
710608 ret = cdn_dp_config_video(dp);
....@@ -713,15 +611,11 @@
713611 goto out;
714612 }
715613
716
- if (dp->use_fw_training) {
717
- ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_VALID);
718
- if (ret) {
719
- DRM_DEV_ERROR(dp->dev,
720
- "Failed to valid video %d\n", ret);
721
- goto out;
722
- }
614
+ ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_VALID);
615
+ if (ret) {
616
+ DRM_DEV_ERROR(dp->dev, "Failed to valid video %d\n", ret);
617
+ goto out;
723618 }
724
-
725619 out:
726620 mutex_unlock(&dp->lock);
727621 }
....@@ -729,8 +623,6 @@
729623 static void cdn_dp_encoder_disable(struct drm_encoder *encoder)
730624 {
731625 struct cdn_dp_device *dp = encoder_to_dp(encoder);
732
- struct drm_crtc *crtc = encoder->crtc;
733
- struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc->state);
734626 int ret;
735627
736628 mutex_lock(&dp->lock);
....@@ -753,35 +645,18 @@
753645 * run the event_work to re-connect it.
754646 */
755647 if (!dp->connected && cdn_dp_connected_port(dp))
756
- schedule_work(&dp->event_work);
757
-
758
- s->output_if &= ~VOP_OUTPUT_IF_DP0;
648
+ schedule_delayed_work(&dp->event_work, 0);
759649 }
760650
761651 static int cdn_dp_encoder_atomic_check(struct drm_encoder *encoder,
762652 struct drm_crtc_state *crtc_state,
763653 struct drm_connector_state *conn_state)
764654 {
765
- struct cdn_dp_device *dp = encoder_to_dp(encoder);
766
- struct drm_display_info *di = &dp->connector.display_info;
767655 struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
768656
769
- switch (di->bpc) {
770
- case 6:
771
- s->bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
772
- break;
773
- case 8:
774
- default:
775
- s->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
776
- break;
777
- }
778
-
779657 s->output_mode = ROCKCHIP_OUT_MODE_AAAA;
780
- s->output_if |= VOP_OUTPUT_IF_DP0;
781658 s->output_type = DRM_MODE_CONNECTOR_DisplayPort;
782659 s->tv_state = &conn_state->tv;
783
- s->eotf = TRADITIONAL_GAMMA_SDR;
784
- s->color_space = V4L2_COLORSPACE_DEFAULT;
785660
786661 return 0;
787662 }
....@@ -791,10 +666,6 @@
791666 .enable = cdn_dp_encoder_enable,
792667 .disable = cdn_dp_encoder_disable,
793668 .atomic_check = cdn_dp_encoder_atomic_check,
794
-};
795
-
796
-static const struct drm_encoder_funcs cdn_dp_encoder_funcs = {
797
- .destroy = drm_encoder_cleanup,
798669 };
799670
800671 static int cdn_dp_parse_dt(struct cdn_dp_device *dp)
....@@ -868,53 +739,6 @@
868739 return 0;
869740 }
870741
871
-struct dp_sdp {
872
- struct dp_sdp_header sdp_header;
873
- u8 db[28];
874
-} __packed;
875
-
876
-static int cdn_dp_setup_audio_infoframe(struct cdn_dp_device *dp)
877
-{
878
- struct dp_sdp infoframe_sdp;
879
- struct hdmi_audio_infoframe frame;
880
- u8 buffer[14];
881
- ssize_t err;
882
-
883
- /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
884
- memset(&infoframe_sdp, 0, sizeof(infoframe_sdp));
885
- infoframe_sdp.sdp_header.HB0 = 0;
886
- infoframe_sdp.sdp_header.HB1 = HDMI_INFOFRAME_TYPE_AUDIO;
887
- infoframe_sdp.sdp_header.HB2 = 0x1b;
888
- infoframe_sdp.sdp_header.HB3 = 0x48;
889
-
890
- err = hdmi_audio_infoframe_init(&frame);
891
- if (err < 0) {
892
- DRM_DEV_ERROR(dp->dev, "Failed to setup audio infoframe: %zd\n",
893
- err);
894
- return err;
895
- }
896
-
897
- frame.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM;
898
- frame.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM;
899
- frame.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM;
900
- frame.channels = 0;
901
-
902
- err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
903
- if (err < 0) {
904
- DRM_DEV_ERROR(dp->dev, "Failed to pack audio infoframe: %zd\n",
905
- err);
906
- return err;
907
- }
908
-
909
- memcpy(&infoframe_sdp.db[0], &buffer[HDMI_INFOFRAME_HEADER_SIZE],
910
- sizeof(buffer) - HDMI_INFOFRAME_HEADER_SIZE);
911
-
912
- cdn_dp_infoframe_set(dp, 0, (u8 *)&infoframe_sdp,
913
- sizeof(infoframe_sdp), 0x84);
914
-
915
- return 0;
916
-}
917
-
918742 static int cdn_dp_audio_hw_params(struct device *dev, void *data,
919743 struct hdmi_codec_daifmt *daifmt,
920744 struct hdmi_codec_params *params)
....@@ -929,7 +753,7 @@
929753
930754 mutex_lock(&dp->lock);
931755 if (!dp->active) {
932
- ret = 0;
756
+ ret = -ENODEV;
933757 goto out;
934758 }
935759
....@@ -945,10 +769,6 @@
945769 ret = -EINVAL;
946770 goto out;
947771 }
948
-
949
- ret = cdn_dp_setup_audio_infoframe(dp);
950
- if (ret)
951
- goto out;
952772
953773 ret = cdn_dp_audio_config(dp, &audio);
954774 if (!ret)
....@@ -975,15 +795,15 @@
975795 mutex_unlock(&dp->lock);
976796 }
977797
978
-static int cdn_dp_audio_digital_mute(struct device *dev, void *data,
979
- bool enable)
798
+static int cdn_dp_audio_mute_stream(struct device *dev, void *data,
799
+ bool enable, int direction)
980800 {
981801 struct cdn_dp_device *dp = dev_get_drvdata(dev);
982802 int ret;
983803
984804 mutex_lock(&dp->lock);
985805 if (!dp->active) {
986
- ret = 0;
806
+ ret = -ENODEV;
987807 goto out;
988808 }
989809
....@@ -1007,8 +827,9 @@
1007827 static const struct hdmi_codec_ops audio_codec_ops = {
1008828 .hw_params = cdn_dp_audio_hw_params,
1009829 .audio_shutdown = cdn_dp_audio_shutdown,
1010
- .digital_mute = cdn_dp_audio_digital_mute,
830
+ .mute_stream = cdn_dp_audio_mute_stream,
1011831 .get_eld = cdn_dp_audio_get_eld,
832
+ .no_capture_mute = 1,
1012833 };
1013834
1014835 static int cdn_dp_audio_codec_init(struct cdn_dp_device *dp,
....@@ -1043,8 +864,7 @@
1043864 mutex_unlock(&dp->lock);
1044865
1045866 while (time_before(jiffies, timeout)) {
1046
- ret = request_firmware_direct(&dp->fw, CDN_DP_FIRMWARE,
1047
- dp->dev);
867
+ ret = request_firmware(&dp->fw, CDN_DP_FIRMWARE, dp->dev);
1048868 if (ret == -ENOENT) {
1049869 msleep(sleep);
1050870 sleep *= 2;
....@@ -1067,27 +887,9 @@
1067887 return ret;
1068888 }
1069889
1070
-static bool cdn_dp_needs_link_retrain(struct cdn_dp_device *dp)
1071
-{
1072
- u8 link_status[DP_LINK_STATUS_SIZE];
1073
-
1074
- /*
1075
- * Validate the cached values of link parameters before attempting to
1076
- * retrain.
1077
- */
1078
- if (!dp->link.rate || !dp->link.num_lanes)
1079
- return false;
1080
-
1081
- if (drm_dp_dpcd_read_link_status(&dp->aux, link_status) < 0)
1082
- return false;
1083
-
1084
- /* Retrain if Channel EQ or CR not ok */
1085
- return !drm_dp_channel_eq_ok(link_status, dp->link.num_lanes);
1086
-}
1087
-
1088890 static void cdn_dp_pd_event_work(struct work_struct *work)
1089891 {
1090
- struct cdn_dp_device *dp = container_of(work, struct cdn_dp_device,
892
+ struct cdn_dp_device *dp = container_of(to_delayed_work(work), struct cdn_dp_device,
1091893 event_work);
1092894 struct drm_connector *connector = &dp->connector;
1093895 enum drm_connector_status old_status;
....@@ -1125,9 +927,9 @@
1125927 dp->connected = false;
1126928
1127929 /* Enabled and connected with a sink, re-train if requested */
1128
- } else if (cdn_dp_needs_link_retrain(dp)) {
1129
- unsigned int rate = dp->link.rate;
1130
- unsigned int lanes = dp->link.num_lanes;
930
+ } else if (!cdn_dp_check_link_status(dp)) {
931
+ unsigned int rate = dp->max_rate;
932
+ unsigned int lanes = dp->max_lanes;
1131933 struct drm_display_mode *mode = &dp->mode;
1132934
1133935 DRM_DEV_INFO(dp->dev, "Connected with sink. Re-train link\n");
....@@ -1140,7 +942,7 @@
1140942
1141943 /* If training result is changed, update the video config */
1142944 if (mode->clock &&
1143
- (rate != dp->link.rate || lanes != dp->link.num_lanes)) {
945
+ (rate != dp->max_rate || lanes != dp->max_lanes)) {
1144946 ret = cdn_dp_config_video(dp);
1145947 if (ret) {
1146948 dp->connected = false;
....@@ -1160,66 +962,13 @@
1160962 drm_kms_helper_hotplug_event(dp->drm_dev);
1161963 }
1162964
1163
-static int cdn_dp_pd_event(struct notifier_block *nb,
1164
- unsigned long event, void *priv)
1165
-{
1166
- struct cdn_dp_port *port = container_of(nb, struct cdn_dp_port,
1167
- event_nb);
1168
- struct cdn_dp_device *dp = port->dp;
1169
-
1170
- /*
1171
- * It would be nice to be able to just do the work inline right here.
1172
- * However, we need to make a bunch of calls that might sleep in order
1173
- * to turn on the block/phy, so use a worker instead.
1174
- */
1175
- schedule_work(&dp->event_work);
1176
-
1177
- return NOTIFY_DONE;
1178
-}
1179
-
1180
-static ssize_t cdn_dp_aux_transfer(struct drm_dp_aux *aux,
1181
- struct drm_dp_aux_msg *msg)
1182
-{
1183
- struct cdn_dp_device *dp = container_of(aux, struct cdn_dp_device, aux);
1184
- int ret;
1185
- u8 status;
1186
-
1187
- switch (msg->request & ~DP_AUX_I2C_MOT) {
1188
- case DP_AUX_NATIVE_WRITE:
1189
- case DP_AUX_I2C_WRITE:
1190
- case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1191
- ret = cdn_dp_dpcd_write(dp, msg->address, msg->buffer,
1192
- msg->size);
1193
- break;
1194
- case DP_AUX_NATIVE_READ:
1195
- case DP_AUX_I2C_READ:
1196
- ret = cdn_dp_dpcd_read(dp, msg->address, msg->buffer,
1197
- msg->size);
1198
- break;
1199
- default:
1200
- return -EINVAL;
1201
- }
1202
-
1203
- status = cdn_dp_get_aux_status(dp);
1204
- if (status == AUX_STATUS_ACK)
1205
- msg->reply = DP_AUX_NATIVE_REPLY_ACK;
1206
- else if (status == AUX_STATUS_NACK)
1207
- msg->reply = DP_AUX_NATIVE_REPLY_NACK;
1208
- else if (status == AUX_STATUS_DEFER)
1209
- msg->reply = DP_AUX_NATIVE_REPLY_DEFER;
1210
-
1211
- return ret;
1212
-}
1213
-
1214965 static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
1215966 {
1216967 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1217968 struct drm_encoder *encoder;
1218969 struct drm_connector *connector;
1219
- struct cdn_dp_port *port;
1220970 struct drm_device *drm_dev = data;
1221
- struct rockchip_drm_private *private = drm_dev->dev_private;
1222
- int ret, i;
971
+ int ret;
1223972
1224973 ret = cdn_dp_parse_dt(dp);
1225974 if (ret < 0)
....@@ -1230,24 +979,17 @@
1230979 dp->active = false;
1231980 dp->active_port = -1;
1232981 dp->fw_loaded = false;
1233
- dp->aux.name = "DP-AUX";
1234
- dp->aux.transfer = cdn_dp_aux_transfer;
1235
- dp->aux.dev = dev;
1236982
1237
- ret = drm_dp_aux_register(&dp->aux);
1238
- if (ret)
1239
- return ret;
1240
-
1241
- INIT_WORK(&dp->event_work, cdn_dp_pd_event_work);
983
+ INIT_DELAYED_WORK(&dp->event_work, cdn_dp_pd_event_work);
1242984
1243985 encoder = &dp->encoder;
1244986
1245
- encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev,
1246
- dev->of_node);
987
+ encoder->possible_crtcs = rockchip_drm_of_find_possible_crtcs(drm_dev,
988
+ dev->of_node);
1247989 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
1248990
1249
- ret = drm_encoder_init(drm_dev, encoder, &cdn_dp_encoder_funcs,
1250
- DRM_MODE_ENCODER_TMDS, NULL);
991
+ ret = drm_simple_encoder_init(drm_dev, encoder,
992
+ DRM_MODE_ENCODER_TMDS);
1251993 if (ret) {
1252994 DRM_ERROR("failed to initialize encoder with drm\n");
1253995 return ret;
....@@ -1274,25 +1016,15 @@
12741016 DRM_ERROR("failed to attach connector and encoder\n");
12751017 goto err_free_connector;
12761018 }
1277
- drm_object_attach_property(&connector->base, private->connector_id_prop, 0);
12781019
1279
- for (i = 0; i < dp->ports; i++) {
1280
- port = dp->port[i];
1281
-
1282
- port->event_nb.notifier_call = cdn_dp_pd_event;
1283
- ret = devm_extcon_register_notifier(dp->dev, port->extcon,
1284
- EXTCON_DISP_DP,
1285
- &port->event_nb);
1286
- if (ret) {
1287
- DRM_DEV_ERROR(dev,
1288
- "register EXTCON_DISP_DP notifier err\n");
1289
- goto err_free_connector;
1290
- }
1291
- }
1020
+ dp->sub_dev.connector = &dp->connector;
1021
+ dp->sub_dev.of_node = dev->of_node;
1022
+ dp->sub_dev.oob_hotplug_event = cdn_dp_oob_hotplug_event;
1023
+ rockchip_drm_register_sub_dev(&dp->sub_dev);
12921024
12931025 pm_runtime_enable(dev);
12941026
1295
- schedule_work(&dp->event_work);
1027
+ schedule_delayed_work(&dp->event_work, 0);
12961028
12971029 return 0;
12981030
....@@ -1309,7 +1041,7 @@
13091041 struct drm_encoder *encoder = &dp->encoder;
13101042 struct drm_connector *connector = &dp->connector;
13111043
1312
- cancel_work_sync(&dp->event_work);
1044
+ cancel_delayed_work_sync(&dp->event_work);
13131045 cdn_dp_encoder_disable(encoder);
13141046 encoder->funcs->destroy(encoder);
13151047 connector->funcs->destroy(connector);
....@@ -1340,14 +1072,14 @@
13401072 return ret;
13411073 }
13421074
1343
-static int cdn_dp_resume(struct device *dev)
1075
+static __maybe_unused int cdn_dp_resume(struct device *dev)
13441076 {
13451077 struct cdn_dp_device *dp = dev_get_drvdata(dev);
13461078
13471079 mutex_lock(&dp->lock);
13481080 dp->suspended = false;
13491081 if (dp->fw_loaded)
1350
- schedule_work(&dp->event_work);
1082
+ schedule_delayed_work(&dp->event_work, 0);
13511083 mutex_unlock(&dp->lock);
13521084
13531085 return 0;
....@@ -1360,39 +1092,30 @@
13601092 struct cdn_dp_data *dp_data;
13611093 struct cdn_dp_port *port;
13621094 struct cdn_dp_device *dp;
1363
- struct extcon_dev *extcon;
13641095 struct phy *phy;
1365
- int i, id;
1096
+ int i;
13661097
13671098 dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL);
13681099 if (!dp)
13691100 return -ENOMEM;
1370
- id = of_alias_get_id(dev->of_node, "dp");
1371
- if (id < 0)
1372
- id = 0;
1373
-
1374
- dp->id = id;
13751101 dp->dev = dev;
13761102
13771103 match = of_match_node(cdn_dp_dt_ids, pdev->dev.of_node);
13781104 dp_data = (struct cdn_dp_data *)match->data;
13791105
13801106 for (i = 0; i < dp_data->max_phy; i++) {
1381
- extcon = extcon_get_edev_by_phandle(dev, i);
13821107 phy = devm_of_phy_get_by_index(dev, dev->of_node, i);
13831108
1384
- if (PTR_ERR(extcon) == -EPROBE_DEFER ||
1385
- PTR_ERR(phy) == -EPROBE_DEFER)
1109
+ if (PTR_ERR(phy) == -EPROBE_DEFER)
13861110 return -EPROBE_DEFER;
13871111
1388
- if (IS_ERR(extcon) || IS_ERR(phy))
1112
+ if (IS_ERR(phy))
13891113 continue;
13901114
13911115 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
13921116 if (!port)
13931117 return -ENOMEM;
13941118
1395
- port->extcon = extcon;
13961119 port->phy = phy;
13971120 port->dp = dp;
13981121 port->id = i;
....@@ -1400,7 +1123,7 @@
14001123 }
14011124
14021125 if (!dp->ports) {
1403
- DRM_DEV_ERROR(dev, "missing extcon or phy\n");
1126
+ DRM_DEV_ERROR(dev, "missing phy\n");
14041127 return -EINVAL;
14051128 }
14061129