forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/gpu/drm/rockchip/rk618/rk618_hdmi.c
....@@ -21,10 +21,11 @@
2121 #endif
2222
2323 #include <drm/drm_of.h>
24
-#include <drm/drmP.h>
24
+#include <drm/drm_drv.h>
2525 #include <drm/drm_atomic_helper.h>
2626 #include <drm/drm_crtc_helper.h>
2727 #include <drm/drm_edid.h>
28
+#include <drm/drm_probe_helper.h>
2829
2930 #include <sound/hdmi-codec.h>
3031
....@@ -439,9 +440,6 @@
439440 struct switch_dev switchdev;
440441 #endif
441442 struct rockchip_drm_sub_dev sub_dev;
442
- hdmi_codec_plugged_cb plugged_cb;
443
- struct device *codec_dev;
444
- enum drm_connector_status last_connector_result;
445443 };
446444
447445 enum {
....@@ -545,26 +543,6 @@
545543 static inline void hdmi_writeb(struct rk618_hdmi *hdmi, u16 offset, u32 val)
546544 {
547545 regmap_write(hdmi->regmap, (RK618_HDMI_BASE + ((offset) << 2)), val);
548
-}
549
-
550
-static void handle_plugged_change(struct rk618_hdmi *hdmi, bool plugged)
551
-{
552
- if (hdmi->plugged_cb && hdmi->codec_dev)
553
- hdmi->plugged_cb(hdmi->codec_dev, plugged);
554
-}
555
-
556
-static int rk618_hdmi_set_plugged_cb(struct rk618_hdmi *hdmi,
557
- hdmi_codec_plugged_cb fn,
558
- struct device *codec_dev)
559
-{
560
- bool plugged;
561
-
562
- hdmi->plugged_cb = fn;
563
- hdmi->codec_dev = codec_dev;
564
- plugged = hdmi->last_connector_result == connector_status_connected;
565
- handle_plugged_change(hdmi, plugged);
566
-
567
- return 0;
568546 }
569547
570548 static void rk618_hdmi_set_polarity(struct rk618_hdmi *hdmi, int vic)
....@@ -745,7 +723,7 @@
745723 union hdmi_infoframe frame;
746724 int rc;
747725
748
- rc = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi, mode, false);
726
+ rc = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi, &hdmi->connector, mode);
749727
750728 if (hdmi->hdmi_data.enc_out_format == HDMI_COLORSPACE_YUV444)
751729 frame.avi.colorspace = HDMI_COLORSPACE_YUV444;
....@@ -968,23 +946,14 @@
968946 {
969947 struct rk618_hdmi *hdmi = connector_to_hdmi(connector);
970948 bool status;
971
- enum drm_connector_status result;
972949
973950 status = rk618_hdmi_hpd_detect(hdmi);
974951 #ifdef CONFIG_SWITCH
975952 switch_set_state(&hdmi->switchdev, status);
976953 #endif
977954
978
- result = status ? connector_status_connected :
955
+ return status ? connector_status_connected :
979956 connector_status_disconnected;
980
- if (result != hdmi->last_connector_result) {
981
- dev_dbg(hdmi->dev, "rk618_hdmi read_hpd result: %d", result);
982
- handle_plugged_change(hdmi,
983
- result == connector_status_connected);
984
- hdmi->last_connector_result = result;
985
- }
986
-
987
- return result;
988957 }
989958
990959 static int rk618_hdmi_connector_get_modes(struct drm_connector *connector)
....@@ -1063,8 +1032,8 @@
10631032 };
10641033
10651034 static void rk618_hdmi_bridge_mode_set(struct drm_bridge *bridge,
1066
- struct drm_display_mode *mode,
1067
- struct drm_display_mode *adj_mode)
1035
+ const struct drm_display_mode *mode,
1036
+ const struct drm_display_mode *adj_mode)
10681037 {
10691038 struct rk618_hdmi *hdmi = bridge_to_hdmi(bridge);
10701039
....@@ -1097,7 +1066,8 @@
10971066 clk_disable_unprepare(hdmi->clock);
10981067 }
10991068
1100
-static int rk618_hdmi_bridge_attach(struct drm_bridge *bridge)
1069
+static int rk618_hdmi_bridge_attach(struct drm_bridge *bridge,
1070
+ enum drm_bridge_attach_flags flags)
11011071 {
11021072 struct rk618_hdmi *hdmi = bridge_to_hdmi(bridge);
11031073 struct device *dev = hdmi->dev;
....@@ -1137,7 +1107,7 @@
11371107 if (!hdmi->bridge)
11381108 return -EPROBE_DEFER;
11391109
1140
- ret = drm_bridge_attach(bridge->encoder, hdmi->bridge, bridge);
1110
+ ret = drm_bridge_attach(bridge->encoder, hdmi->bridge, bridge, 0);
11411111 if (ret) {
11421112 dev_err(dev, "failed to attach bridge\n");
11431113 return ret;
....@@ -1162,9 +1132,8 @@
11621132 .disable = rk618_hdmi_bridge_disable,
11631133 };
11641134
1165
-static int rk618_hdmi_audio_config_set(struct rk618_hdmi *hdmi,
1166
- struct hdmi_codec_daifmt *daifmt,
1167
- struct audio_info *audio)
1135
+static int
1136
+rk618_hdmi_audio_config_set(struct rk618_hdmi *hdmi, struct audio_info *audio)
11681137 {
11691138 int rate, N, channel;
11701139
....@@ -1212,19 +1181,14 @@
12121181 return -ENOENT;
12131182 }
12141183
1215
- if (daifmt->fmt == HDMI_SPDIF) {
1216
- /* set_audio source SPDIF */
1217
- hdmi_writeb(hdmi, HDMI_AUDIO_CTRL1, 0x09);
1218
- } else {
1219
- /* set_audio source I2S */
1220
- hdmi_writeb(hdmi, HDMI_AUDIO_CTRL1, 0x01);
1221
- }
1184
+ /* set_audio source I2S */
1185
+ hdmi_writeb(hdmi, HDMI_AUDIO_CTRL1, 0x01);
12221186 hdmi_writeb(hdmi, AUDIO_SAMPLE_RATE, rate);
12231187 hdmi_writeb(hdmi, AUDIO_I2S_MODE, v_I2S_MODE(I2S_STANDARD) |
12241188 v_I2S_CHANNEL(channel));
12251189
12261190 hdmi_writeb(hdmi, AUDIO_I2S_MAP, 0x00);
1227
- hdmi_writeb(hdmi, AUDIO_I2S_SWAPS_SPDIF, rate);
1191
+ hdmi_writeb(hdmi, AUDIO_I2S_SWAPS_SPDIF, 0);
12281192
12291193 /* Set N value */
12301194 hdmi_writeb(hdmi, AUDIO_N_H, (N >> 16) & 0x0F);
....@@ -1259,14 +1223,12 @@
12591223 switch (daifmt->fmt) {
12601224 case HDMI_I2S:
12611225 break;
1262
- case HDMI_SPDIF:
1263
- break;
12641226 default:
12651227 dev_err(dev, "%s: Invalid format %d\n", __func__, daifmt->fmt);
12661228 return -EINVAL;
12671229 }
12681230
1269
- return rk618_hdmi_audio_config_set(hdmi, daifmt, &audio);
1231
+ return rk618_hdmi_audio_config_set(hdmi, &audio);
12701232 }
12711233
12721234 static void rk618_hdmi_audio_shutdown(struct device *dev, void *d)
....@@ -1274,7 +1236,7 @@
12741236 /* do nothing */
12751237 }
12761238
1277
-static int rk618_hdmi_audio_digital_mute(struct device *dev, void *d, bool mute)
1239
+static int rk618_hdmi_audio_mute_stream(struct device *dev, void *d, bool mute, int direction)
12781240 {
12791241 struct rk618_hdmi *hdmi = dev_get_drvdata(dev);
12801242
....@@ -1316,42 +1278,21 @@
13161278 return ret;
13171279 }
13181280
1319
-static int rk618_hdmi_hook_plugged_cb(struct device *dev, void *data,
1320
- hdmi_codec_plugged_cb fn,
1321
- struct device *codec_dev)
1322
-{
1323
- struct rk618_hdmi *hdmi = dev_get_drvdata(dev);
1324
-
1325
- return rk618_hdmi_set_plugged_cb(hdmi, fn, codec_dev);
1326
-}
1327
-
13281281 static const struct hdmi_codec_ops audio_codec_ops = {
13291282 .hw_params = rk618_hdmi_audio_hw_params,
13301283 .audio_shutdown = rk618_hdmi_audio_shutdown,
1331
- .digital_mute = rk618_hdmi_audio_digital_mute,
1284
+ .mute_stream = rk618_hdmi_audio_mute_stream,
13321285 .get_eld = rk618_hdmi_audio_get_eld,
1333
- .hook_plugged_cb = rk618_hdmi_hook_plugged_cb,
13341286 };
13351287
13361288 static int rk618_hdmi_audio_codec_init(struct rk618_hdmi *hdmi,
13371289 struct device *dev)
13381290 {
1339
- const char *str = "i2s";
1340
- struct device_node *np = dev->of_node;
13411291 struct hdmi_codec_pdata codec_data = {
13421292 .i2s = 1,
1343
- .spdif = 0,
13441293 .ops = &audio_codec_ops,
13451294 .max_i2s_channels = 8,
13461295 };
1347
-
1348
- if (of_property_read_string(np, "rockchip,format", &str))
1349
- dev_warn(dev, "can not get rockchip,format\n");
1350
-
1351
- if (strstr(str, "spdif")) {
1352
- codec_data.i2s = 0;
1353
- codec_data.spdif = 1;
1354
- }
13551296
13561297 hdmi->audio_enable = false;
13571298 hdmi->audio_pdev = platform_device_register_data(dev,
....@@ -1581,9 +1522,6 @@
15811522 dev_err(dev, "Unable to get HDMI clock\n");
15821523 return PTR_ERR(hdmi->clock);
15831524 }
1584
-
1585
- /* hpd io pull down */
1586
- regmap_write(rk618->regmap, RK618_IO_CON0, HDMI_IO_PULL_UP_DISABLE);
15871525
15881526 rk618_hdmi_pol_init(hdmi, 0);
15891527 rk618_hdmi_reset(hdmi);