@@ -153,7 +153,7 @@ struct mtk_hdmi_conf {
153153struct mtk_hdmi {
154154 struct drm_bridge bridge ;
155155 struct drm_bridge * next_bridge ;
156- struct drm_connector conn ;
156+ struct drm_connector * curr_conn ; /* current connector (only valid when 'enabled') */
157157 struct device * dev ;
158158 const struct mtk_hdmi_conf * conf ;
159159 struct phy * phy ;
@@ -186,11 +186,6 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
186186 return container_of (b , struct mtk_hdmi , bridge );
187187}
188188
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-
194189static u32 mtk_hdmi_read (struct mtk_hdmi * hdmi , u32 offset )
195190{
196191 return readl (hdmi -> regs + offset );
@@ -974,7 +969,7 @@ static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi,
974969 ssize_t err ;
975970
976971 err = drm_hdmi_avi_infoframe_from_display_mode (& frame ,
977- & hdmi -> conn , mode );
972+ hdmi -> curr_conn , mode );
978973 if (err < 0 ) {
979974 dev_err (hdmi -> dev ,
980975 "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,
10541049 ssize_t err ;
10551050
10561051 err = drm_hdmi_vendor_infoframe_from_display_mode (& frame ,
1057- & hdmi -> conn , mode );
1052+ hdmi -> curr_conn , mode );
10581053 if (err ) {
10591054 dev_err (hdmi -> dev ,
10601055 "Failed to get vendor infoframe from mode: %zd\n" , err );
@@ -1201,48 +1196,16 @@ mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
12011196 connector_status_connected : connector_status_disconnected ;
12021197}
12031198
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 )
12061200{
1207- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn (conn );
12081201 return mtk_hdmi_update_plugged_status (hdmi );
12091202}
12101203
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 )
12441207{
1245- struct mtk_hdmi * hdmi = hdmi_ctx_from_conn ( conn );
1208+ struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge ( bridge );
12461209 struct drm_bridge * next_bridge ;
12471210
12481211 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,
12671230 return drm_mode_validate_size (mode , 0x1fff , 0x1fff );
12681231}
12691232
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-
12931233static void mtk_hdmi_hpd_event (bool hpd , struct device * dev )
12941234{
12951235 struct mtk_hdmi * hdmi = dev_get_drvdata (dev );
12961236
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 );
12981241 drm_helper_hpd_irq_event (hdmi -> bridge .encoder -> dev );
1242+ drm_bridge_hpd_notify (& hdmi -> bridge , status );
1243+ }
12991244}
13001245
13011246/*
13021247 * Bridge callbacks
13031248 */
13041249
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+
13051272static int mtk_hdmi_bridge_attach (struct drm_bridge * bridge ,
13061273 enum drm_bridge_attach_flags flags )
13071274{
13081275 struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
13091276 int ret ;
13101277
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__ );
13131281 return - EINVAL ;
13141282 }
13151283
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-
13381284 if (hdmi -> next_bridge ) {
13391285 ret = drm_bridge_attach (bridge -> encoder , hdmi -> next_bridge ,
13401286 bridge , flags );
@@ -1369,6 +1315,8 @@ static void mtk_hdmi_bridge_atomic_disable(struct drm_bridge *bridge,
13691315 clk_disable_unprepare (hdmi -> clk [MTK_HDMI_CLK_HDMI_PIXEL ]);
13701316 clk_disable_unprepare (hdmi -> clk [MTK_HDMI_CLK_HDMI_PLL ]);
13711317
1318+ hdmi -> curr_conn = NULL ;
1319+
13721320 hdmi -> enabled = false;
13731321}
13741322
@@ -1432,8 +1380,13 @@ static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi,
14321380static void mtk_hdmi_bridge_atomic_enable (struct drm_bridge * bridge ,
14331381 struct drm_bridge_state * old_state )
14341382{
1383+ struct drm_atomic_state * state = old_state -> base .state ;
14351384 struct mtk_hdmi * hdmi = hdmi_ctx_from_bridge (bridge );
14361385
1386+ /* Retrieve the connector through the atomic state. */
1387+ hdmi -> curr_conn = drm_atomic_get_new_connector_for_encoder (state ,
1388+ bridge -> encoder );
1389+
14371390 mtk_hdmi_output_set_display_mode (hdmi , & hdmi -> mode );
14381391 clk_prepare_enable (hdmi -> clk [MTK_HDMI_CLK_HDMI_PLL ]);
14391392 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,
14441397}
14451398
14461399static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = {
1400+ .mode_valid = mtk_hdmi_bridge_mode_valid ,
14471401 .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state ,
14481402 .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state ,
14491403 .atomic_reset = drm_atomic_helper_bridge_reset ,
@@ -1454,6 +1408,8 @@ static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = {
14541408 .mode_set = mtk_hdmi_bridge_mode_set ,
14551409 .atomic_pre_enable = mtk_hdmi_bridge_atomic_pre_enable ,
14561410 .atomic_enable = mtk_hdmi_bridge_atomic_enable ,
1411+ .detect = mtk_hdmi_bridge_detect ,
1412+ .get_edid = mtk_hdmi_bridge_get_edid ,
14571413};
14581414
14591415static 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,
16691625{
16701626 struct mtk_hdmi * hdmi = dev_get_drvdata (dev );
16711627
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 );
16741632 return 0 ;
16751633}
16761634
@@ -1762,6 +1720,9 @@ static int mtk_drm_hdmi_probe(struct platform_device *pdev)
17621720
17631721 hdmi -> bridge .funcs = & mtk_hdmi_bridge_funcs ;
17641722 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 ;
17651726 drm_bridge_add (& hdmi -> bridge );
17661727
17671728 ret = mtk_hdmi_clk_enable_audio (hdmi );
0 commit comments