@@ -153,7 +153,7 @@ struct mtk_hdmi_conf {
153
153
struct mtk_hdmi {
154
154
struct drm_bridge bridge ;
155
155
struct drm_bridge * next_bridge ;
156
- struct drm_connector conn ;
156
+ struct drm_connector * curr_conn ; /* current connector (only valid when 'enabled') */
157
157
struct device * dev ;
158
158
const struct mtk_hdmi_conf * conf ;
159
159
struct phy * phy ;
@@ -186,11 +186,6 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
186
186
return container_of (b , struct mtk_hdmi , bridge );
187
187
}
188
188
189
- static inline struct mtk_hdmi * hdmi_ctx_from_conn (struct drm_connector * c )
190
- {
191
- return container_of (c , struct mtk_hdmi , conn );
192
- }
193
-
194
189
static u32 mtk_hdmi_read (struct mtk_hdmi * hdmi , u32 offset )
195
190
{
196
191
return readl (hdmi -> regs + offset );
@@ -974,7 +969,7 @@ static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi,
974
969
ssize_t err ;
975
970
976
971
err = drm_hdmi_avi_infoframe_from_display_mode (& frame ,
977
- & hdmi -> conn , mode );
972
+ hdmi -> curr_conn , mode );
978
973
if (err < 0 ) {
979
974
dev_err (hdmi -> dev ,
980
975
"Failed to get AVI infoframe from mode: %zd\n" , err );
@@ -1054,7 +1049,7 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
1054
1049
ssize_t err ;
1055
1050
1056
1051
err = drm_hdmi_vendor_infoframe_from_display_mode (& frame ,
1057
- & hdmi -> conn , mode );
1052
+ hdmi -> curr_conn , mode );
1058
1053
if (err ) {
1059
1054
dev_err (hdmi -> dev ,
1060
1055
"Failed to get vendor infoframe from mode: %zd\n" , err );
@@ -1201,48 +1196,16 @@ mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
1201
1196
connector_status_connected : connector_status_disconnected ;
1202
1197
}
1203
1198
1204
- static enum drm_connector_status hdmi_conn_detect (struct drm_connector * conn ,
1205
- bool force )
1199
+ static enum drm_connector_status mtk_hdmi_detect (struct mtk_hdmi * hdmi )
1206
1200
{
1207
- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn (conn );
1208
1201
return mtk_hdmi_update_plugged_status (hdmi );
1209
1202
}
1210
1203
1211
- static void hdmi_conn_destroy (struct drm_connector * conn )
1212
- {
1213
- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn (conn );
1214
-
1215
- mtk_cec_set_hpd_event (hdmi -> cec_dev , NULL , NULL );
1216
-
1217
- drm_connector_cleanup (conn );
1218
- }
1219
-
1220
- static int mtk_hdmi_conn_get_modes (struct drm_connector * conn )
1221
- {
1222
- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn (conn );
1223
- struct edid * edid ;
1224
- int ret ;
1225
-
1226
- if (!hdmi -> ddc_adpt )
1227
- return - ENODEV ;
1228
-
1229
- edid = drm_get_edid (conn , hdmi -> ddc_adpt );
1230
- if (!edid )
1231
- return - ENODEV ;
1232
-
1233
- hdmi -> dvi_mode = !drm_detect_monitor_audio (edid );
1234
-
1235
- drm_connector_update_edid_property (conn , edid );
1236
-
1237
- ret = drm_add_edid_modes (conn , edid );
1238
- kfree (edid );
1239
- return ret ;
1240
- }
1241
-
1242
- static int mtk_hdmi_conn_mode_valid (struct drm_connector * conn ,
1243
- struct drm_display_mode * mode )
1204
+ static int mtk_hdmi_bridge_mode_valid (struct drm_bridge * bridge ,
1205
+ const struct drm_display_info * info ,
1206
+ const struct drm_display_mode * mode )
1244
1207
{
1245
- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn ( conn );
1208
+ struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge ( bridge );
1246
1209
struct drm_bridge * next_bridge ;
1247
1210
1248
1211
dev_dbg (hdmi -> dev , "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n" ,
@@ -1267,74 +1230,57 @@ static int mtk_hdmi_conn_mode_valid(struct drm_connector *conn,
1267
1230
return drm_mode_validate_size (mode , 0x1fff , 0x1fff );
1268
1231
}
1269
1232
1270
- static struct drm_encoder * mtk_hdmi_conn_best_enc (struct drm_connector * conn )
1271
- {
1272
- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn (conn );
1273
-
1274
- return hdmi -> bridge .encoder ;
1275
- }
1276
-
1277
- static const struct drm_connector_funcs mtk_hdmi_connector_funcs = {
1278
- .detect = hdmi_conn_detect ,
1279
- .fill_modes = drm_helper_probe_single_connector_modes ,
1280
- .destroy = hdmi_conn_destroy ,
1281
- .reset = drm_atomic_helper_connector_reset ,
1282
- .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state ,
1283
- .atomic_destroy_state = drm_atomic_helper_connector_destroy_state ,
1284
- };
1285
-
1286
- static const struct drm_connector_helper_funcs
1287
- mtk_hdmi_connector_helper_funcs = {
1288
- .get_modes = mtk_hdmi_conn_get_modes ,
1289
- .mode_valid = mtk_hdmi_conn_mode_valid ,
1290
- .best_encoder = mtk_hdmi_conn_best_enc ,
1291
- };
1292
-
1293
1233
static void mtk_hdmi_hpd_event (bool hpd , struct device * dev )
1294
1234
{
1295
1235
struct mtk_hdmi * hdmi = dev_get_drvdata (dev );
1296
1236
1297
- if (hdmi && hdmi -> bridge .encoder && hdmi -> bridge .encoder -> dev )
1237
+ if (hdmi && hdmi -> bridge .encoder && hdmi -> bridge .encoder -> dev ) {
1238
+ static enum drm_connector_status status ;
1239
+
1240
+ status = mtk_hdmi_detect (hdmi );
1298
1241
drm_helper_hpd_irq_event (hdmi -> bridge .encoder -> dev );
1242
+ drm_bridge_hpd_notify (& hdmi -> bridge , status );
1243
+ }
1299
1244
}
1300
1245
1301
1246
/*
1302
1247
* Bridge callbacks
1303
1248
*/
1304
1249
1250
+ static enum drm_connector_status mtk_hdmi_bridge_detect (struct drm_bridge * bridge )
1251
+ {
1252
+ struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
1253
+
1254
+ return mtk_hdmi_detect (hdmi );
1255
+ }
1256
+
1257
+ static struct edid * mtk_hdmi_bridge_get_edid (struct drm_bridge * bridge ,
1258
+ struct drm_connector * connector )
1259
+ {
1260
+ struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
1261
+ struct edid * edid ;
1262
+
1263
+ if (!hdmi -> ddc_adpt )
1264
+ return NULL ;
1265
+ edid = drm_get_edid (connector , hdmi -> ddc_adpt );
1266
+ if (!edid )
1267
+ return NULL ;
1268
+ hdmi -> dvi_mode = !drm_detect_monitor_audio (edid );
1269
+ return edid ;
1270
+ }
1271
+
1305
1272
static int mtk_hdmi_bridge_attach (struct drm_bridge * bridge ,
1306
1273
enum drm_bridge_attach_flags flags )
1307
1274
{
1308
1275
struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
1309
1276
int ret ;
1310
1277
1311
- if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ) {
1312
- DRM_ERROR ("Fix bridge driver to make connector optional!" );
1278
+ if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR )) {
1279
+ DRM_ERROR ("%s: The flag DRM_BRIDGE_ATTACH_NO_CONNECTOR must be supplied\n" ,
1280
+ __func__ );
1313
1281
return - EINVAL ;
1314
1282
}
1315
1283
1316
- ret = drm_connector_init_with_ddc (bridge -> encoder -> dev , & hdmi -> conn ,
1317
- & mtk_hdmi_connector_funcs ,
1318
- DRM_MODE_CONNECTOR_HDMIA ,
1319
- hdmi -> ddc_adpt );
1320
- if (ret ) {
1321
- dev_err (hdmi -> dev , "Failed to initialize connector: %d\n" , ret );
1322
- return ret ;
1323
- }
1324
- drm_connector_helper_add (& hdmi -> conn , & mtk_hdmi_connector_helper_funcs );
1325
-
1326
- hdmi -> conn .polled = DRM_CONNECTOR_POLL_HPD ;
1327
- hdmi -> conn .interlace_allowed = true;
1328
- hdmi -> conn .doublescan_allowed = false;
1329
-
1330
- ret = drm_connector_attach_encoder (& hdmi -> conn ,
1331
- bridge -> encoder );
1332
- if (ret ) {
1333
- dev_err (hdmi -> dev ,
1334
- "Failed to attach connector to encoder: %d\n" , ret );
1335
- return ret ;
1336
- }
1337
-
1338
1284
if (hdmi -> next_bridge ) {
1339
1285
ret = drm_bridge_attach (bridge -> encoder , hdmi -> next_bridge ,
1340
1286
bridge , flags );
@@ -1369,6 +1315,8 @@ static void mtk_hdmi_bridge_atomic_disable(struct drm_bridge *bridge,
1369
1315
clk_disable_unprepare (hdmi -> clk [MTK_HDMI_CLK_HDMI_PIXEL ]);
1370
1316
clk_disable_unprepare (hdmi -> clk [MTK_HDMI_CLK_HDMI_PLL ]);
1371
1317
1318
+ hdmi -> curr_conn = NULL ;
1319
+
1372
1320
hdmi -> enabled = false;
1373
1321
}
1374
1322
@@ -1432,8 +1380,13 @@ static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi,
1432
1380
static void mtk_hdmi_bridge_atomic_enable (struct drm_bridge * bridge ,
1433
1381
struct drm_bridge_state * old_state )
1434
1382
{
1383
+ struct drm_atomic_state * state = old_state -> base .state ;
1435
1384
struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
1436
1385
1386
+ /* Retrieve the connector through the atomic state. */
1387
+ hdmi -> curr_conn = drm_atomic_get_new_connector_for_encoder (state ,
1388
+ bridge -> encoder );
1389
+
1437
1390
mtk_hdmi_output_set_display_mode (hdmi , & hdmi -> mode );
1438
1391
clk_prepare_enable (hdmi -> clk [MTK_HDMI_CLK_HDMI_PLL ]);
1439
1392
clk_prepare_enable (hdmi -> clk [MTK_HDMI_CLK_HDMI_PIXEL ]);
@@ -1444,6 +1397,7 @@ static void mtk_hdmi_bridge_atomic_enable(struct drm_bridge *bridge,
1444
1397
}
1445
1398
1446
1399
static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = {
1400
+ .mode_valid = mtk_hdmi_bridge_mode_valid ,
1447
1401
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state ,
1448
1402
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state ,
1449
1403
.atomic_reset = drm_atomic_helper_bridge_reset ,
@@ -1454,6 +1408,8 @@ static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = {
1454
1408
.mode_set = mtk_hdmi_bridge_mode_set ,
1455
1409
.atomic_pre_enable = mtk_hdmi_bridge_atomic_pre_enable ,
1456
1410
.atomic_enable = mtk_hdmi_bridge_atomic_enable ,
1411
+ .detect = mtk_hdmi_bridge_detect ,
1412
+ .get_edid = mtk_hdmi_bridge_get_edid ,
1457
1413
};
1458
1414
1459
1415
static int mtk_hdmi_dt_parse_pdata (struct mtk_hdmi * hdmi ,
@@ -1669,8 +1625,10 @@ static int mtk_hdmi_audio_get_eld(struct device *dev, void *data, uint8_t *buf,
1669
1625
{
1670
1626
struct mtk_hdmi * hdmi = dev_get_drvdata (dev );
1671
1627
1672
- memcpy (buf , hdmi -> conn .eld , min (sizeof (hdmi -> conn .eld ), len ));
1673
-
1628
+ if (hdmi -> enabled )
1629
+ memcpy (buf , hdmi -> curr_conn -> eld , min (sizeof (hdmi -> curr_conn -> eld ), len ));
1630
+ else
1631
+ memset (buf , 0 , len );
1674
1632
return 0 ;
1675
1633
}
1676
1634
@@ -1762,6 +1720,9 @@ static int mtk_drm_hdmi_probe(struct platform_device *pdev)
1762
1720
1763
1721
hdmi -> bridge .funcs = & mtk_hdmi_bridge_funcs ;
1764
1722
hdmi -> bridge .of_node = pdev -> dev .of_node ;
1723
+ hdmi -> bridge .ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID
1724
+ | DRM_BRIDGE_OP_HPD ;
1725
+ hdmi -> bridge .type = DRM_MODE_CONNECTOR_HDMIA ;
1765
1726
drm_bridge_add (& hdmi -> bridge );
1766
1727
1767
1728
ret = mtk_hdmi_clk_enable_audio (hdmi );
0 commit comments