forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
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 }
....@@ -751,32 +645,18 @@
751645 * run the event_work to re-connect it.
752646 */
753647 if (!dp->connected && cdn_dp_connected_port(dp))
754
- schedule_work(&dp->event_work);
648
+ schedule_delayed_work(&dp->event_work, 0);
755649 }
756650
757651 static int cdn_dp_encoder_atomic_check(struct drm_encoder *encoder,
758652 struct drm_crtc_state *crtc_state,
759653 struct drm_connector_state *conn_state)
760654 {
761
- struct cdn_dp_device *dp = encoder_to_dp(encoder);
762
- struct drm_display_info *di = &dp->connector.display_info;
763655 struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
764
-
765
- switch (di->bpc) {
766
- case 6:
767
- s->bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
768
- break;
769
- case 8:
770
- default:
771
- s->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
772
- break;
773
- }
774656
775657 s->output_mode = ROCKCHIP_OUT_MODE_AAAA;
776658 s->output_type = DRM_MODE_CONNECTOR_DisplayPort;
777659 s->tv_state = &conn_state->tv;
778
- s->eotf = TRADITIONAL_GAMMA_SDR;
779
- s->color_space = V4L2_COLORSPACE_DEFAULT;
780660
781661 return 0;
782662 }
....@@ -786,10 +666,6 @@
786666 .enable = cdn_dp_encoder_enable,
787667 .disable = cdn_dp_encoder_disable,
788668 .atomic_check = cdn_dp_encoder_atomic_check,
789
-};
790
-
791
-static const struct drm_encoder_funcs cdn_dp_encoder_funcs = {
792
- .destroy = drm_encoder_cleanup,
793669 };
794670
795671 static int cdn_dp_parse_dt(struct cdn_dp_device *dp)
....@@ -863,53 +739,6 @@
863739 return 0;
864740 }
865741
866
-struct dp_sdp {
867
- struct dp_sdp_header sdp_header;
868
- u8 db[28];
869
-} __packed;
870
-
871
-static int cdn_dp_setup_audio_infoframe(struct cdn_dp_device *dp)
872
-{
873
- struct dp_sdp infoframe_sdp;
874
- struct hdmi_audio_infoframe frame;
875
- u8 buffer[14];
876
- ssize_t err;
877
-
878
- /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
879
- memset(&infoframe_sdp, 0, sizeof(infoframe_sdp));
880
- infoframe_sdp.sdp_header.HB0 = 0;
881
- infoframe_sdp.sdp_header.HB1 = HDMI_INFOFRAME_TYPE_AUDIO;
882
- infoframe_sdp.sdp_header.HB2 = 0x1b;
883
- infoframe_sdp.sdp_header.HB3 = 0x48;
884
-
885
- err = hdmi_audio_infoframe_init(&frame);
886
- if (err < 0) {
887
- DRM_DEV_ERROR(dp->dev, "Failed to setup audio infoframe: %zd\n",
888
- err);
889
- return err;
890
- }
891
-
892
- frame.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM;
893
- frame.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM;
894
- frame.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM;
895
- frame.channels = 0;
896
-
897
- err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
898
- if (err < 0) {
899
- DRM_DEV_ERROR(dp->dev, "Failed to pack audio infoframe: %zd\n",
900
- err);
901
- return err;
902
- }
903
-
904
- memcpy(&infoframe_sdp.db[0], &buffer[HDMI_INFOFRAME_HEADER_SIZE],
905
- sizeof(buffer) - HDMI_INFOFRAME_HEADER_SIZE);
906
-
907
- cdn_dp_infoframe_set(dp, 0, (u8 *)&infoframe_sdp,
908
- sizeof(infoframe_sdp), 0x84);
909
-
910
- return 0;
911
-}
912
-
913742 static int cdn_dp_audio_hw_params(struct device *dev, void *data,
914743 struct hdmi_codec_daifmt *daifmt,
915744 struct hdmi_codec_params *params)
....@@ -924,7 +753,7 @@
924753
925754 mutex_lock(&dp->lock);
926755 if (!dp->active) {
927
- ret = 0;
756
+ ret = -ENODEV;
928757 goto out;
929758 }
930759
....@@ -940,10 +769,6 @@
940769 ret = -EINVAL;
941770 goto out;
942771 }
943
-
944
- ret = cdn_dp_setup_audio_infoframe(dp);
945
- if (ret)
946
- goto out;
947772
948773 ret = cdn_dp_audio_config(dp, &audio);
949774 if (!ret)
....@@ -970,15 +795,15 @@
970795 mutex_unlock(&dp->lock);
971796 }
972797
973
-static int cdn_dp_audio_digital_mute(struct device *dev, void *data,
974
- bool enable)
798
+static int cdn_dp_audio_mute_stream(struct device *dev, void *data,
799
+ bool enable, int direction)
975800 {
976801 struct cdn_dp_device *dp = dev_get_drvdata(dev);
977802 int ret;
978803
979804 mutex_lock(&dp->lock);
980805 if (!dp->active) {
981
- ret = 0;
806
+ ret = -ENODEV;
982807 goto out;
983808 }
984809
....@@ -1002,8 +827,9 @@
1002827 static const struct hdmi_codec_ops audio_codec_ops = {
1003828 .hw_params = cdn_dp_audio_hw_params,
1004829 .audio_shutdown = cdn_dp_audio_shutdown,
1005
- .digital_mute = cdn_dp_audio_digital_mute,
830
+ .mute_stream = cdn_dp_audio_mute_stream,
1006831 .get_eld = cdn_dp_audio_get_eld,
832
+ .no_capture_mute = 1,
1007833 };
1008834
1009835 static int cdn_dp_audio_codec_init(struct cdn_dp_device *dp,
....@@ -1038,8 +864,7 @@
1038864 mutex_unlock(&dp->lock);
1039865
1040866 while (time_before(jiffies, timeout)) {
1041
- ret = request_firmware_direct(&dp->fw, CDN_DP_FIRMWARE,
1042
- dp->dev);
867
+ ret = request_firmware(&dp->fw, CDN_DP_FIRMWARE, dp->dev);
1043868 if (ret == -ENOENT) {
1044869 msleep(sleep);
1045870 sleep *= 2;
....@@ -1062,27 +887,9 @@
1062887 return ret;
1063888 }
1064889
1065
-static bool cdn_dp_needs_link_retrain(struct cdn_dp_device *dp)
1066
-{
1067
- u8 link_status[DP_LINK_STATUS_SIZE];
1068
-
1069
- /*
1070
- * Validate the cached values of link parameters before attempting to
1071
- * retrain.
1072
- */
1073
- if (!dp->link.rate || !dp->link.num_lanes)
1074
- return false;
1075
-
1076
- if (drm_dp_dpcd_read_link_status(&dp->aux, link_status) < 0)
1077
- return false;
1078
-
1079
- /* Retrain if Channel EQ or CR not ok */
1080
- return !drm_dp_channel_eq_ok(link_status, dp->link.num_lanes);
1081
-}
1082
-
1083890 static void cdn_dp_pd_event_work(struct work_struct *work)
1084891 {
1085
- 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,
1086893 event_work);
1087894 struct drm_connector *connector = &dp->connector;
1088895 enum drm_connector_status old_status;
....@@ -1120,9 +927,9 @@
1120927 dp->connected = false;
1121928
1122929 /* Enabled and connected with a sink, re-train if requested */
1123
- } else if (cdn_dp_needs_link_retrain(dp)) {
1124
- unsigned int rate = dp->link.rate;
1125
- 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;
1126933 struct drm_display_mode *mode = &dp->mode;
1127934
1128935 DRM_DEV_INFO(dp->dev, "Connected with sink. Re-train link\n");
....@@ -1135,7 +942,7 @@
1135942
1136943 /* If training result is changed, update the video config */
1137944 if (mode->clock &&
1138
- (rate != dp->link.rate || lanes != dp->link.num_lanes)) {
945
+ (rate != dp->max_rate || lanes != dp->max_lanes)) {
1139946 ret = cdn_dp_config_video(dp);
1140947 if (ret) {
1141948 dp->connected = false;
....@@ -1155,66 +962,13 @@
1155962 drm_kms_helper_hotplug_event(dp->drm_dev);
1156963 }
1157964
1158
-static int cdn_dp_pd_event(struct notifier_block *nb,
1159
- unsigned long event, void *priv)
1160
-{
1161
- struct cdn_dp_port *port = container_of(nb, struct cdn_dp_port,
1162
- event_nb);
1163
- struct cdn_dp_device *dp = port->dp;
1164
-
1165
- /*
1166
- * It would be nice to be able to just do the work inline right here.
1167
- * However, we need to make a bunch of calls that might sleep in order
1168
- * to turn on the block/phy, so use a worker instead.
1169
- */
1170
- schedule_work(&dp->event_work);
1171
-
1172
- return NOTIFY_DONE;
1173
-}
1174
-
1175
-static ssize_t cdn_dp_aux_transfer(struct drm_dp_aux *aux,
1176
- struct drm_dp_aux_msg *msg)
1177
-{
1178
- struct cdn_dp_device *dp = container_of(aux, struct cdn_dp_device, aux);
1179
- int ret;
1180
- u8 status;
1181
-
1182
- switch (msg->request & ~DP_AUX_I2C_MOT) {
1183
- case DP_AUX_NATIVE_WRITE:
1184
- case DP_AUX_I2C_WRITE:
1185
- case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1186
- ret = cdn_dp_dpcd_write(dp, msg->address, msg->buffer,
1187
- msg->size);
1188
- break;
1189
- case DP_AUX_NATIVE_READ:
1190
- case DP_AUX_I2C_READ:
1191
- ret = cdn_dp_dpcd_read(dp, msg->address, msg->buffer,
1192
- msg->size);
1193
- break;
1194
- default:
1195
- return -EINVAL;
1196
- }
1197
-
1198
- status = cdn_dp_get_aux_status(dp);
1199
- if (status == AUX_STATUS_ACK)
1200
- msg->reply = DP_AUX_NATIVE_REPLY_ACK;
1201
- else if (status == AUX_STATUS_NACK)
1202
- msg->reply = DP_AUX_NATIVE_REPLY_NACK;
1203
- else if (status == AUX_STATUS_DEFER)
1204
- msg->reply = DP_AUX_NATIVE_REPLY_DEFER;
1205
-
1206
- return ret;
1207
-}
1208
-
1209965 static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
1210966 {
1211967 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1212968 struct drm_encoder *encoder;
1213969 struct drm_connector *connector;
1214
- struct cdn_dp_port *port;
1215970 struct drm_device *drm_dev = data;
1216
- struct rockchip_drm_private *private = drm_dev->dev_private;
1217
- int ret, i;
971
+ int ret;
1218972
1219973 ret = cdn_dp_parse_dt(dp);
1220974 if (ret < 0)
....@@ -1225,24 +979,17 @@
1225979 dp->active = false;
1226980 dp->active_port = -1;
1227981 dp->fw_loaded = false;
1228
- dp->aux.name = "DP-AUX";
1229
- dp->aux.transfer = cdn_dp_aux_transfer;
1230
- dp->aux.dev = dev;
1231982
1232
- ret = drm_dp_aux_register(&dp->aux);
1233
- if (ret)
1234
- return ret;
1235
-
1236
- INIT_WORK(&dp->event_work, cdn_dp_pd_event_work);
983
+ INIT_DELAYED_WORK(&dp->event_work, cdn_dp_pd_event_work);
1237984
1238985 encoder = &dp->encoder;
1239986
1240
- encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev,
1241
- dev->of_node);
987
+ encoder->possible_crtcs = rockchip_drm_of_find_possible_crtcs(drm_dev,
988
+ dev->of_node);
1242989 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
1243990
1244
- ret = drm_encoder_init(drm_dev, encoder, &cdn_dp_encoder_funcs,
1245
- DRM_MODE_ENCODER_TMDS, NULL);
991
+ ret = drm_simple_encoder_init(drm_dev, encoder,
992
+ DRM_MODE_ENCODER_TMDS);
1246993 if (ret) {
1247994 DRM_ERROR("failed to initialize encoder with drm\n");
1248995 return ret;
....@@ -1269,25 +1016,15 @@
12691016 DRM_ERROR("failed to attach connector and encoder\n");
12701017 goto err_free_connector;
12711018 }
1272
- drm_object_attach_property(&connector->base, private->connector_id_prop, 0);
12731019
1274
- for (i = 0; i < dp->ports; i++) {
1275
- port = dp->port[i];
1276
-
1277
- port->event_nb.notifier_call = cdn_dp_pd_event;
1278
- ret = devm_extcon_register_notifier(dp->dev, port->extcon,
1279
- EXTCON_DISP_DP,
1280
- &port->event_nb);
1281
- if (ret) {
1282
- DRM_DEV_ERROR(dev,
1283
- "register EXTCON_DISP_DP notifier err\n");
1284
- goto err_free_connector;
1285
- }
1286
- }
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);
12871024
12881025 pm_runtime_enable(dev);
12891026
1290
- schedule_work(&dp->event_work);
1027
+ schedule_delayed_work(&dp->event_work, 0);
12911028
12921029 return 0;
12931030
....@@ -1304,7 +1041,7 @@
13041041 struct drm_encoder *encoder = &dp->encoder;
13051042 struct drm_connector *connector = &dp->connector;
13061043
1307
- cancel_work_sync(&dp->event_work);
1044
+ cancel_delayed_work_sync(&dp->event_work);
13081045 cdn_dp_encoder_disable(encoder);
13091046 encoder->funcs->destroy(encoder);
13101047 connector->funcs->destroy(connector);
....@@ -1335,14 +1072,14 @@
13351072 return ret;
13361073 }
13371074
1338
-static int cdn_dp_resume(struct device *dev)
1075
+static __maybe_unused int cdn_dp_resume(struct device *dev)
13391076 {
13401077 struct cdn_dp_device *dp = dev_get_drvdata(dev);
13411078
13421079 mutex_lock(&dp->lock);
13431080 dp->suspended = false;
13441081 if (dp->fw_loaded)
1345
- schedule_work(&dp->event_work);
1082
+ schedule_delayed_work(&dp->event_work, 0);
13461083 mutex_unlock(&dp->lock);
13471084
13481085 return 0;
....@@ -1355,39 +1092,30 @@
13551092 struct cdn_dp_data *dp_data;
13561093 struct cdn_dp_port *port;
13571094 struct cdn_dp_device *dp;
1358
- struct extcon_dev *extcon;
13591095 struct phy *phy;
1360
- int i, id;
1096
+ int i;
13611097
13621098 dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL);
13631099 if (!dp)
13641100 return -ENOMEM;
1365
- id = of_alias_get_id(dev->of_node, "dp");
1366
- if (id < 0)
1367
- id = 0;
1368
-
1369
- dp->id = id;
13701101 dp->dev = dev;
13711102
13721103 match = of_match_node(cdn_dp_dt_ids, pdev->dev.of_node);
13731104 dp_data = (struct cdn_dp_data *)match->data;
13741105
13751106 for (i = 0; i < dp_data->max_phy; i++) {
1376
- extcon = extcon_get_edev_by_phandle(dev, i);
13771107 phy = devm_of_phy_get_by_index(dev, dev->of_node, i);
13781108
1379
- if (PTR_ERR(extcon) == -EPROBE_DEFER ||
1380
- PTR_ERR(phy) == -EPROBE_DEFER)
1109
+ if (PTR_ERR(phy) == -EPROBE_DEFER)
13811110 return -EPROBE_DEFER;
13821111
1383
- if (IS_ERR(extcon) || IS_ERR(phy))
1112
+ if (IS_ERR(phy))
13841113 continue;
13851114
13861115 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
13871116 if (!port)
13881117 return -ENOMEM;
13891118
1390
- port->extcon = extcon;
13911119 port->phy = phy;
13921120 port->dp = dp;
13931121 port->id = i;
....@@ -1395,7 +1123,7 @@
13951123 }
13961124
13971125 if (!dp->ports) {
1398
- DRM_DEV_ERROR(dev, "missing extcon or phy\n");
1126
+ DRM_DEV_ERROR(dev, "missing phy\n");
13991127 return -EINVAL;
14001128 }
14011129