@@ -36,7 +36,10 @@ struct adv7511 {
3636 bool edid_read ;
3737
3838 wait_queue_head_t wq ;
39+ struct work_struct hpd_work ;
40+
3941 struct drm_encoder * encoder ;
42+ struct drm_connector connector ;
4043
4144 bool embedded_sync ;
4245 enum adv7511_sync_polarity vsync_polarity ;
@@ -48,6 +51,10 @@ struct adv7511 {
4851 struct gpio_desc * gpio_pd ;
4952};
5053
54+ static const int edid_i2c_addr = 0x7e ;
55+ static const int packet_i2c_addr = 0x70 ;
56+ static const int cec_i2c_addr = 0x78 ;
57+
5158static struct adv7511 * encoder_to_adv7511 (struct drm_encoder * encoder )
5259{
5360 return to_encoder_slave (encoder )-> slave_priv ;
@@ -362,12 +369,19 @@ static void adv7511_power_on(struct adv7511 *adv7511)
362369{
363370 adv7511 -> current_edid_segment = -1 ;
364371
365- regmap_write (adv7511 -> regmap , ADV7511_REG_INT (0 ),
366- ADV7511_INT0_EDID_READY );
367- regmap_write (adv7511 -> regmap , ADV7511_REG_INT (1 ),
368- ADV7511_INT1_DDC_ERROR );
369372 regmap_update_bits (adv7511 -> regmap , ADV7511_REG_POWER ,
370373 ADV7511_POWER_POWER_DOWN , 0 );
374+ if (adv7511 -> i2c_main -> irq ) {
375+ /*
376+ * Documentation says the INT_ENABLE registers are reset in
377+ * POWER_DOWN mode. My 7511w preserved the bits, however.
378+ * Still, let's be safe and stick to the documentation.
379+ */
380+ regmap_write (adv7511 -> regmap , ADV7511_REG_INT_ENABLE (0 ),
381+ ADV7511_INT0_EDID_READY );
382+ regmap_write (adv7511 -> regmap , ADV7511_REG_INT_ENABLE (1 ),
383+ ADV7511_INT1_DDC_ERROR );
384+ }
371385
372386 /*
373387 * Per spec it is allowed to pulse the HDP signal to indicate that the
@@ -422,7 +436,27 @@ static bool adv7511_hpd(struct adv7511 *adv7511)
422436 return false;
423437}
424438
425- static int adv7511_irq_process (struct adv7511 * adv7511 )
439+ static void adv7511_hpd_work (struct work_struct * work )
440+ {
441+ struct adv7511 * adv7511 = container_of (work , struct adv7511 , hpd_work );
442+ enum drm_connector_status status ;
443+ unsigned int val ;
444+ int ret ;
445+ ret = regmap_read (adv7511 -> regmap , ADV7511_REG_STATUS , & val );
446+ if (ret < 0 )
447+ status = connector_status_disconnected ;
448+ else if (val & ADV7511_STATUS_HPD )
449+ status = connector_status_connected ;
450+ else
451+ status = connector_status_disconnected ;
452+
453+ if (adv7511 -> connector .status != status ) {
454+ adv7511 -> connector .status = status ;
455+ drm_kms_helper_hotplug_event (adv7511 -> connector .dev );
456+ }
457+ }
458+
459+ static int adv7511_irq_process (struct adv7511 * adv7511 , bool process_hpd )
426460{
427461 unsigned int irq0 , irq1 ;
428462 int ret ;
@@ -438,8 +472,8 @@ static int adv7511_irq_process(struct adv7511 *adv7511)
438472 regmap_write (adv7511 -> regmap , ADV7511_REG_INT (0 ), irq0 );
439473 regmap_write (adv7511 -> regmap , ADV7511_REG_INT (1 ), irq1 );
440474
441- if (irq0 & ADV7511_INT0_HDP && adv7511 -> encoder )
442- drm_helper_hpd_irq_event ( adv7511 -> encoder -> dev );
475+ if (process_hpd && irq0 & ADV7511_INT0_HDP && adv7511 -> encoder )
476+ schedule_work ( & adv7511 -> hpd_work );
443477
444478 if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR ) {
445479 adv7511 -> edid_read = true;
@@ -456,7 +490,7 @@ static irqreturn_t adv7511_irq_handler(int irq, void *devid)
456490 struct adv7511 * adv7511 = devid ;
457491 int ret ;
458492
459- ret = adv7511_irq_process (adv7511 );
493+ ret = adv7511_irq_process (adv7511 , true );
460494 return ret < 0 ? IRQ_NONE : IRQ_HANDLED ;
461495}
462496
@@ -473,7 +507,7 @@ static int adv7511_wait_for_edid(struct adv7511 *adv7511, int timeout)
473507 adv7511 -> edid_read , msecs_to_jiffies (timeout ));
474508 } else {
475509 for (; timeout > 0 ; timeout -= 25 ) {
476- ret = adv7511_irq_process (adv7511 );
510+ ret = adv7511_irq_process (adv7511 , false );
477511 if (ret < 0 )
478512 break ;
479513
@@ -567,13 +601,18 @@ static int adv7511_get_modes(struct drm_encoder *encoder,
567601
568602 /* Reading the EDID only works if the device is powered */
569603 if (!adv7511 -> powered ) {
570- regmap_write (adv7511 -> regmap , ADV7511_REG_INT (0 ),
571- ADV7511_INT0_EDID_READY );
572- regmap_write (adv7511 -> regmap , ADV7511_REG_INT (1 ),
573- ADV7511_INT1_DDC_ERROR );
574604 regmap_update_bits (adv7511 -> regmap , ADV7511_REG_POWER ,
575605 ADV7511_POWER_POWER_DOWN , 0 );
606+ if (adv7511 -> i2c_main -> irq ) {
607+ regmap_write (adv7511 -> regmap , ADV7511_REG_INT_ENABLE (0 ),
608+ ADV7511_INT0_EDID_READY );
609+ regmap_write (adv7511 -> regmap , ADV7511_REG_INT_ENABLE (1 ),
610+ ADV7511_INT1_DDC_ERROR );
611+ }
576612 adv7511 -> current_edid_segment = -1 ;
613+ /* Reset the EDID_I2C_ADDR register as it might be cleared */
614+ regmap_write (adv7511 -> regmap , ADV7511_REG_EDID_I2C_ADDR ,
615+ edid_i2c_addr );
577616 }
578617
579618 edid = drm_do_get_edid (connector , adv7511_get_edid_block , adv7511 );
@@ -849,10 +888,6 @@ static int adv7511_parse_dt(struct device_node *np,
849888 return 0 ;
850889}
851890
852- static const int edid_i2c_addr = 0x7e ;
853- static const int packet_i2c_addr = 0x70 ;
854- static const int cec_i2c_addr = 0x78 ;
855-
856891static int adv7511_probe (struct i2c_client * i2c , const struct i2c_device_id * id )
857892{
858893 struct adv7511_link_config link_config ;
@@ -913,6 +948,8 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
913948 if (!adv7511 -> i2c_edid )
914949 return - ENOMEM ;
915950
951+ INIT_WORK (& adv7511 -> hpd_work , adv7511_hpd_work );
952+
916953 if (i2c -> irq ) {
917954 init_waitqueue_head (& adv7511 -> wq );
918955
0 commit comments