diff mbox series

[v11,1/4] drm/msm/dp: do not initialize phy until plugin interrupt received

Message ID 1641926606-1012-2-git-send-email-quic_khsieh@quicinc.com (mailing list archive)
State Superseded
Headers show
Series group dp driver related patches into one series | expand

Commit Message

Kuogee Hsieh Jan. 11, 2022, 6:43 p.m. UTC
Current DP drivers have regulators, clocks, irq and phy are grouped
together within a function and executed not in a symmetric manner.
This increase difficulty of code maintenance and limited code scalability.
This patch divides the driver life cycle of operation into four states,
resume (including booting up), dongle plugin, dongle unplugged and suspend.
Regulators, core clocks and irq are grouped together and enabled at resume
(or booting up) so that the DP controller is armed and ready to receive HPD
plugin interrupts. HPD plugin interrupt is generated when a dongle plugs
into DUT (device under test). Once HPD plugin interrupt is received, DP
controller will initialize phy so that dpcd read/write will function and
following link training can be proceeded successfully. DP phy will be
disabled after main link is teared down at end of unplugged HPD interrupt
handle triggered by dongle unplugged out of DUT. Finally regulators, code
clocks and irq are disabled at corresponding suspension.

Changes in V2:
-- removed unnecessary dp_ctrl NULL check
-- removed unnecessary phy init_count and power_count DRM_DEBUG_DP logs
-- remove flip parameter out of dp_ctrl_irq_enable()
-- add fixes tag

Changes in V3:
-- call dp_display_host_phy_init() instead of dp_ctrl_phy_init() at
        dp_display_host_init() for eDP

Changes in V4:
-- rewording commit text to match this commit changes

Changes in V5:
-- rebase on top of msm-next branch

Changes in V6:
-- delete flip variable

Changes in V7:
-- dp_ctrl_irq_enable/disabe() merged into dp_ctrl_reset_irq_ctrl()

Changes in V8:
-- add more detail comment regrading dp phy at dp_display_host_init()

Changes in V9:
-- remove set phy_initialized to false when -ECONNRESET detected

Changes in v10:
--  group into one series

Changes in v11:
-- drop drm/msm/dp: dp_link_parse_sink_count() return immediately if aux read

Fixes: 8ede2ecc3e5e ("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets")
Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    | 80 +++++++++++++--------------------
 drivers/gpu/drm/msm/dp/dp_ctrl.h    |  8 ++--
 drivers/gpu/drm/msm/dp/dp_display.c | 89 ++++++++++++++++++++++++-------------
 3 files changed, 94 insertions(+), 83 deletions(-)

Comments

Stephen Boyd Jan. 12, 2022, 8 p.m. UTC | #1
Quoting Kuogee Hsieh (2022-01-11 10:43:23)
> Current DP drivers have regulators, clocks, irq and phy are grouped
> together within a function and executed not in a symmetric manner.
> This increase difficulty of code maintenance and limited code scalability.
> This patch divides the driver life cycle of operation into four states,
> resume (including booting up), dongle plugin, dongle unplugged and suspend.
> Regulators, core clocks and irq are grouped together and enabled at resume
> (or booting up) so that the DP controller is armed and ready to receive HPD
> plugin interrupts. HPD plugin interrupt is generated when a dongle plugs
> into DUT (device under test). Once HPD plugin interrupt is received, DP
> controller will initialize phy so that dpcd read/write will function and
> following link training can be proceeded successfully. DP phy will be
> disabled after main link is teared down at end of unplugged HPD interrupt
> handle triggered by dongle unplugged out of DUT. Finally regulators, code
> clocks and irq are disabled at corresponding suspension.

I'll write out the various scenarios

#1
	dongle plugged in with HDMI cable attached
	driver probe

#2
	dongle unplugged
	driver probe

#3
	dongle plugged in without HDMI cable attached
	driver probe

#4
	driver probe
	dongle plugged in without HDMI cable attached


#5
	driver probe
	dongle plugged in with HDMI cable attached

#6
	driver probe
	dongle plugged in
	suspend
	resume

#7
	driver probe
	dongle plugged in
	suspend
	dongle unplugged
	resume

#8
	driver probe
	dongle plugged in without HDMI cable attached
	suspend
	resume

#9
	driver probe
	dongle plugged in without HDMI cable attached
	suspend
	HDMI cable attached during suspend
	resume

What's the state of the phy and core initialized variable at the end of
each of these scenarios? Please fill out the truth table.

		  +-----------------+------------------------
                  |    false        |       true            |
		  +-----------------+------------------------
 phy_initialized  |                 |                       |
		  +-----------------+------------------------
 core_initialized |                 | #1,                   |
		  +-----------------+------------------------

I guess we also need eDP scenarios, but that's probably simpler

#10
	eDP panel connected
	driver probe

#11
	eDP panel disconnected
	driver probe

#12
	eDP panel disconnected
	driver probe
	suspend
	resume

> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
> index 7cc4d21..f6bb4bc 100644
> --- a/drivers/gpu/drm/msm/dp/dp_display.c
> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
> @@ -83,6 +83,7 @@ struct dp_display_private {
>
>         /* state variables */
>         bool core_initialized;
> +       bool phy_initialized;
>         bool hpd_irq_on;
>         bool audio_supported;
>
> @@ -372,21 +373,46 @@ static int dp_display_process_hpd_high(struct dp_display_private *dp)
>         return rc;
>  }
>
> -static void dp_display_host_init(struct dp_display_private *dp, int reset)
> +static void dp_display_host_phy_init(struct dp_display_private *dp)
>  {
> -       bool flip = false;
> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
> +                       dp->core_initialized, dp->phy_initialized);
>
> +       if (!dp->phy_initialized) {
> +               dp_ctrl_phy_init(dp->ctrl);
> +               dp->phy_initialized = true;
> +       }
> +}
> +
> +static void dp_display_host_phy_exit(struct dp_display_private *dp)
> +{
> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
> +                       dp->core_initialized, dp->phy_initialized);
> +
> +       if (dp->phy_initialized) {
> +               dp_ctrl_phy_exit(dp->ctrl);
> +               dp->phy_initialized = false;
> +       }
> +}
> +
> +static void dp_display_host_init(struct dp_display_private *dp)
> +{
>         DRM_DEBUG_DP("core_initialized=%d\n", dp->core_initialized);
>         if (dp->core_initialized) {
>                 DRM_DEBUG_DP("DP core already initialized\n");
>                 return;
>         }
>
> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
> -               flip = true;
> +       dp_power_init(dp->power, false);
> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
> +
> +       /*
> +        * eDP is the embedded primary display and has its own phy
> +        * initialize phy immediately

Question still stands why we can't wait for hpd high from the eDP panel.
Also, I think "has its own phy" means that it's not part of a combo
USB+DP phy? Can you please clarify?

> +        */
> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
> +               dp_display_host_phy_init(dp);
>
> -       dp_power_init(dp->power, flip);
> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
>         dp_aux_init(dp->aux);
>         dp->core_initialized = true;
>  }
> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
>         dp->hpd_state = ST_DISCONNECTED;
>
>         /* turn on dp ctrl/phy */
> -       dp_display_host_init(dp, true);
> +       dp_display_host_init(dp);
>
>         dp_catalog_ctrl_hpd_config(dp->catalog);
>
> -       /*
> -        * set sink to normal operation mode -- D0
> -        * before dpcd read
> -        */
> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>
>         if (dp_catalog_link_is_connected(dp->catalog)) {
> +               /*
> +                * set sink to normal operation mode -- D0
> +                * before dpcd read
> +                */
> +               dp_display_host_phy_init(dp);
> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>                 sink_count = drm_dp_read_sink_count(dp->aux);
>                 if (sink_count < 0)
>                         sink_count = 0;
> +
> +               dp_display_host_phy_exit(dp);

Why is the phy exited on resume when the link is still connected? Is
this supposed to be done only when the sink_count is 0? And how does
this interact with eDP where the phy is initialized by the call to
dp_display_host_init() earlier in this function.

>         }
>
>         dp->link->sink_count = sink_count;
> @@ -1366,6 +1393,8 @@ static int dp_pm_suspend(struct device *dev)
>                 dp_display_host_deinit(dp);
>         }
>
> +       dp_display_host_phy_exit(dp);
> +
>         dp->hpd_state = ST_SUSPENDED;
>
>         /* host_init will be called at pm_resume */
Kuogee Hsieh Jan. 12, 2022, 10:17 p.m. UTC | #2
On 1/12/2022 12:00 PM, Stephen Boyd wrote:
> Quoting Kuogee Hsieh (2022-01-11 10:43:23)
>> Current DP drivers have regulators, clocks, irq and phy are grouped
>> together within a function and executed not in a symmetric manner.
>> This increase difficulty of code maintenance and limited code scalability.
>> This patch divides the driver life cycle of operation into four states,
>> resume (including booting up), dongle plugin, dongle unplugged and suspend.
>> Regulators, core clocks and irq are grouped together and enabled at resume
>> (or booting up) so that the DP controller is armed and ready to receive HPD
>> plugin interrupts. HPD plugin interrupt is generated when a dongle plugs
>> into DUT (device under test). Once HPD plugin interrupt is received, DP
>> controller will initialize phy so that dpcd read/write will function and
>> following link training can be proceeded successfully. DP phy will be
>> disabled after main link is teared down at end of unplugged HPD interrupt
>> handle triggered by dongle unplugged out of DUT. Finally regulators, code
>> clocks and irq are disabled at corresponding suspension.

0) Please note that  dongles are behavior differently.

1) Apple dongle will generate plug-in interrupt only if no hdmi monitor 
atatched to dongle. it will generate irq-hpd interrupt once hdmi monitor 
connect to dongle later.

2) Apple dongle will generate plugged-in interrupt followed by irq-hpd 
interrupt if dongle has hdmi monitor attached when connects to DUT.

3) other dongle will not generate plug-in interrupt unless dongle has 
hdmi monitor attached when connects to DUT. It only generate plug-in 
interrupt only and no irq-hpd interrupt  generated on this case.

4) Note: phy_initialized only associated with plugged-in interrupt

5) irq-hpd interrupt must happen after plugged-in interrupt and before 
unplugged interrupt

I will fill up below question with Apple dongle case with the order of 
event happen timing.

> I'll write out the various scenarios
>
> #1
> 	dongle plugged in with HDMI cable attached
> 	driver probe

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) generate plugged-in interrupt triggers handler
4) dp_display_phy_init() ==> phy_initialized = true;

> 	
>
> #2
> 	dongle unplugged
> 	driver probe

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;


>
> #3
> 	dongle plugged in without HDMI cable attached
> 	driver probe

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) generate plug-in interrupt triggers handler
4) dp_display_phy_init() ==> phy_initialized = true;

Note: same as case #1
> #4
> 	driver probe
> 	dongle plugged in without HDMI cable attached

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plugged in
4) generate plug-in interrupt triggers handler
5) dp_display_phy_init() ==> phy_initialized = true;

>
>
> #5
> 	driver probe
> 	dongle plugged in with HDMI cable attached

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plugged in
4) generate plug-in interrupt trigger handler
5) dp_display_phy_init() ==> phy_initialized = true;

Note: same as case #4

>
> #6
> 	driver probe
> 	dongle plugged in
> 	suspend
> 	resume

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plug in
4) generate plug-in interrupt triggers handler
5) dp_display_phy_init() ==> phy_initialized = true;
6) suspend
7) dp_display_host_deinit() ==> core_initialized = false;
8) dp_display_host_phy_exit() ==> phy_initialize = false;
9) resume
10) dp_display_host_init() ==> core_initialized = true;
11) generate plug-in interrupt
12) dp_display_phy_init() ==> phy_initialize = true;

>
> #7
> 	driver probe
> 	dongle plugged in
> 	suspend
> 	dongle unplugged
> 	resume

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plugged in
4) generate plug-in interrupt triggers handler
5) dp_display_phy_init() ==> phy_initialized = true;
6) suspend
7) dp_display_host_deinit() ==> core_initialized = false;
8) dp_display_host_phy_exit() ==> phy_initialize = false;
9) dongle unplugged
10) resume
11) dp_display_host_init() ==> core_initialized = true;

#8
	driver probe
	dongle plugged in without HDMI cable attached
	suspend
	resume

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plug in
4) generate plug-in interrupt triggers handler
5) dp_display_phy_init() ==> phy_initialized = true;
6) suspend
7) dp_display_host_deinit() ==> core_initialized = false;
8) dp_display_host_phy_exit() ==> phy_initialize = false;
9) resume
10) dp_display_host_init() ==> core_initialized = true;
11) generate plug-in interrupt
12) dp_display_phy_init() ==> phy_initialize = true;


NOTE: same case #6

#9
	driver probe
	dongle plugged in without HDMI cable attached
	suspend
	HDMI cable attached during suspend
	resume

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) dongle plugged in
4) generate plug-in interrupt triggers handler
5) dp_display_phy_init() ==> phy_initialized = true;
6) suspend
7) dp_display_host_deinit() ==> core_initialized = false;
8) dp_display_host_phy_exit() ==> phy_initialize = false;
9) HDMI cable attached
10) resume
11) dp_display_host_init() ==> core_initialized = true;
12) generate plug-in interrupt
13) dp_display_phy_init() ==> phy_initialize = true;


What's the state of the phy and core initialized variable at the end of
each of these scenarios? Please fill out the truth table.

		  +-----------------+------------------------
                   |    false        |       true            |
		  +-----------------+------------------------
  phy_initialized  |                 |                       |
		  +-----------------+------------------------
  core_initialized |                 | #1,                   |
		  +-----------------+------------------------

I guess we also need eDP scenarios, but that's probably simpler

#10
	eDP panel connected
	driver probe

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) generate plug-in interrupt triggers handler
4) dp_display_phy_init() ==> phy_initialized = true;



#11
	eDP panel disconnected
	driver probe

NOTE: eDP panel can not be disconnected

#12
	eDP panel disconnected
	driver probe
	suspend
	resume

NOTE: assume edp panel connected
1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_host_init() ==> core_initialized = true;
3) generate plug-in interrupt triggers handler
4) dp_display_phy_init() ==> phy_initialized = true;
5) suspend
6) dp_display_host_deinit() ==> core_initialized = false;
7) dp_display_host_phy_exit() ==> phy_initialize = false;
8) resume
9) dp_display_host_init() ==> core_initialized = true;
10) generate plug-in interrupt
11) dp_display_phy_init() ==> phy_initialize = true;

>> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
>> index 7cc4d21..f6bb4bc 100644
>> --- a/drivers/gpu/drm/msm/dp/dp_display.c
>> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
>> @@ -83,6 +83,7 @@ struct dp_display_private {
>>
>>          /* state variables */
>>          bool core_initialized;
>> +       bool phy_initialized;
>>          bool hpd_irq_on;
>>          bool audio_supported;
>>
>> @@ -372,21 +373,46 @@ static int dp_display_process_hpd_high(struct dp_display_private *dp)
>>          return rc;
>>   }
>>
>> -static void dp_display_host_init(struct dp_display_private *dp, int reset)
>> +static void dp_display_host_phy_init(struct dp_display_private *dp)
>>   {
>> -       bool flip = false;
>> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
>> +                       dp->core_initialized, dp->phy_initialized);
>>
>> +       if (!dp->phy_initialized) {
>> +               dp_ctrl_phy_init(dp->ctrl);
>> +               dp->phy_initialized = true;
>> +       }
>> +}
>> +
>> +static void dp_display_host_phy_exit(struct dp_display_private *dp)
>> +{
>> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
>> +                       dp->core_initialized, dp->phy_initialized);
>> +
>> +       if (dp->phy_initialized) {
>> +               dp_ctrl_phy_exit(dp->ctrl);
>> +               dp->phy_initialized = false;
>> +       }
>> +}
>> +
>> +static void dp_display_host_init(struct dp_display_private *dp)
>> +{
>>          DRM_DEBUG_DP("core_initialized=%d\n", dp->core_initialized);
>>          if (dp->core_initialized) {
>>                  DRM_DEBUG_DP("DP core already initialized\n");
>>                  return;
>>          }
>>
>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
>> -               flip = true;
>> +       dp_power_init(dp->power, false);
>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
>> +
>> +       /*
>> +        * eDP is the embedded primary display and has its own phy
>> +        * initialize phy immediately
> Question still stands why we can't wait for hpd high from the eDP panel.
> Also, I think "has its own phy" means that it's not part of a combo
> USB+DP phy? Can you please clarify?
>
>> +        */
>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
>> +               dp_display_host_phy_init(dp);
>>
>> -       dp_power_init(dp->power, flip);
>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
>>          dp_aux_init(dp->aux);
>>          dp->core_initialized = true;
>>   }
>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
>>          dp->hpd_state = ST_DISCONNECTED;
>>
>>          /* turn on dp ctrl/phy */
>> -       dp_display_host_init(dp, true);
>> +       dp_display_host_init(dp);
>>
>>          dp_catalog_ctrl_hpd_config(dp->catalog);
>>
>> -       /*
>> -        * set sink to normal operation mode -- D0
>> -        * before dpcd read
>> -        */
>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>
>>          if (dp_catalog_link_is_connected(dp->catalog)) {
>> +               /*
>> +                * set sink to normal operation mode -- D0
>> +                * before dpcd read
>> +                */
>> +               dp_display_host_phy_init(dp);
>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>                  sink_count = drm_dp_read_sink_count(dp->aux);
>>                  if (sink_count < 0)
>>                          sink_count = 0;
>> +
>> +               dp_display_host_phy_exit(dp);
> Why is the phy exited on resume when the link is still connected? Is
> this supposed to be done only when the sink_count is 0? And how does
> this interact with eDP where the phy is initialized by the call to
> dp_display_host_init() earlier in this function.
>
>>          }
>>
>>          dp->link->sink_count = sink_count;
>> @@ -1366,6 +1393,8 @@ static int dp_pm_suspend(struct device *dev)
>>                  dp_display_host_deinit(dp);
>>          }
>>
>> +       dp_display_host_phy_exit(dp);
>> +
>>          dp->hpd_state = ST_SUSPENDED;
>>
>>          /* host_init will be called at pm_resume */
Stephen Boyd Jan. 13, 2022, 4:13 a.m. UTC | #3
Quoting Kuogee Hsieh (2022-01-12 14:17:54)
>
> On 1/12/2022 12:00 PM, Stephen Boyd wrote:
> > Quoting Kuogee Hsieh (2022-01-11 10:43:23)
> >> Current DP drivers have regulators, clocks, irq and phy are grouped
> >> together within a function and executed not in a symmetric manner.
> >> This increase difficulty of code maintenance and limited code scalability.
> >> This patch divides the driver life cycle of operation into four states,
> >> resume (including booting up), dongle plugin, dongle unplugged and suspend.
> >> Regulators, core clocks and irq are grouped together and enabled at resume
> >> (or booting up) so that the DP controller is armed and ready to receive HPD
> >> plugin interrupts. HPD plugin interrupt is generated when a dongle plugs
> >> into DUT (device under test). Once HPD plugin interrupt is received, DP
> >> controller will initialize phy so that dpcd read/write will function and
> >> following link training can be proceeded successfully. DP phy will be
> >> disabled after main link is teared down at end of unplugged HPD interrupt
> >> handle triggered by dongle unplugged out of DUT. Finally regulators, code
> >> clocks and irq are disabled at corresponding suspension.
>
> 0) Please note that  dongles are behavior differently.
>
> 1) Apple dongle will generate plug-in interrupt only if no hdmi monitor
> atatched to dongle. it will generate irq-hpd interrupt once hdmi monitor
> connect to dongle later.
>
> 2) Apple dongle will generate plugged-in interrupt followed by irq-hpd
> interrupt if dongle has hdmi monitor attached when connects to DUT.
>
> 3) other dongle will not generate plug-in interrupt unless dongle has
> hdmi monitor attached when connects to DUT. It only generate plug-in
> interrupt only and no irq-hpd interrupt  generated on this case.

Ok. The test scenarios can be reworded in terms of plugin irq and
irq-hpd if that makes it easier.

>
> 4) Note: phy_initialized only associated with plugged-in interrupt
>
> 5) irq-hpd interrupt must happen after plugged-in interrupt and before
> unplugged interrupt

More precisely it's that plugged-in interrupt must be handled before
irq-hpd but plugged-in and irq-hpd can both be pending at the device
concurrently unless they're masked and unmasked in some particular
order. I thought the driver ensures that only irq-hpd is unmasked once
the plugged in irq is handled. Can you confirm? Similarly, unplugged irq
is unmasked after plugged in irq is handled, but irq-hpd and unplugged
can both be pending if the irq handler is delayed?

>
> I will fill up below question with Apple dongle case with the order of
> event happen timing.
>
> > I'll write out the various scenarios
> >
> > #1
> >       dongle plugged in with HDMI cable attached
> >       driver probe
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) generate plugged-in interrupt triggers handler
> 4) dp_display_phy_init() ==> phy_initialized = true;
>
> >
> >
> > #2
> >       dongle unplugged
> >       driver probe
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
>
>
> >
> > #3
> >       dongle plugged in without HDMI cable attached
> >       driver probe
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) generate plug-in interrupt triggers handler
> 4) dp_display_phy_init() ==> phy_initialized = true;
>
> Note: same as case #1
> > #4
> >       driver probe
> >       dongle plugged in without HDMI cable attached
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plugged in
> 4) generate plug-in interrupt triggers handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
>
> >
> >
> > #5
> >       driver probe
> >       dongle plugged in with HDMI cable attached
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plugged in
> 4) generate plug-in interrupt trigger handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
>
> Note: same as case #4
>
> >
> > #6
> >       driver probe
> >       dongle plugged in
> >       suspend
> >       resume
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plug in
> 4) generate plug-in interrupt triggers handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
> 6) suspend
> 7) dp_display_host_deinit() ==> core_initialized = false;
> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
> 9) resume
> 10) dp_display_host_init() ==> core_initialized = true;
> 11) generate plug-in interrupt
> 12) dp_display_phy_init() ==> phy_initialize = true;
>
> >
> > #7
> >       driver probe
> >       dongle plugged in
> >       suspend
> >       dongle unplugged
> >       resume
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plugged in
> 4) generate plug-in interrupt triggers handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
> 6) suspend
> 7) dp_display_host_deinit() ==> core_initialized = false;
> 8) dp_display_host_phy_exit() ==> phy_initialize = false;

Why is the order of operations swapped? During probe core_initialized
is done first and then phy_initialized but then on suspend
core_initialized is done first again before phy_initialized. That's
asymmetric.

> 9) dongle unplugged
> 10) resume
> 11) dp_display_host_init() ==> core_initialized = true;
>
> #8
>         driver probe
>         dongle plugged in without HDMI cable attached
>         suspend
>         resume
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plug in
> 4) generate plug-in interrupt triggers handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
> 6) suspend
> 7) dp_display_host_deinit() ==> core_initialized = false;
> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
> 9) resume
> 10) dp_display_host_init() ==> core_initialized = true;
> 11) generate plug-in interrupt
> 12) dp_display_phy_init() ==> phy_initialize = true;
>
>
> NOTE: same case #6
>
> #9
>         driver probe
>         dongle plugged in without HDMI cable attached
>         suspend
>         HDMI cable attached during suspend
>         resume
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) dongle plugged in
> 4) generate plug-in interrupt triggers handler
> 5) dp_display_phy_init() ==> phy_initialized = true;
> 6) suspend
> 7) dp_display_host_deinit() ==> core_initialized = false;
> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
> 9) HDMI cable attached
> 10) resume
> 11) dp_display_host_init() ==> core_initialized = true;
> 12) generate plug-in interrupt
> 13) dp_display_phy_init() ==> phy_initialize = true;
>
>
> What's the state of the phy and core initialized variable at the end of
> each of these scenarios? Please fill out the truth table.
>
>                   +-----------------+------------------------
>                    |    false        |       true            |
>                   +-----------------+------------------------
>   phy_initialized  |                 |                       |
>                   +-----------------+------------------------
>   core_initialized |                 | #1,                   |
>                   +-----------------+------------------------
>
> I guess we also need eDP scenarios, but that's probably simpler
>
> #10
>         eDP panel connected
>         driver probe
>
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) generate plug-in interrupt triggers handler

I think this is more like "dp_display_config_hpd() is called by hpd
kthread"?

> 4) dp_display_phy_init() ==> phy_initialized = true;
>
>
>
> #11
>         eDP panel disconnected
>         driver probe
>
> NOTE: eDP panel can not be disconnected

The panel can certainly be disconnected in the sense that the ribbon
cable to the panel is busted or not working properly. That's what this
scenario is for.

>
> #12
>         eDP panel disconnected
>         driver probe
>         suspend
>         resume
>
> NOTE: assume edp panel connected
> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
> 2) dp_display_host_init() ==> core_initialized = true;
> 3) generate plug-in interrupt triggers handler
> 4) dp_display_phy_init() ==> phy_initialized = true;
> 5) suspend
> 6) dp_display_host_deinit() ==> core_initialized = false;
> 7) dp_display_host_phy_exit() ==> phy_initialize = false;
> 8) resume
> 9) dp_display_host_init() ==> core_initialized = true;
> 10) generate plug-in interrupt
> 11) dp_display_phy_init() ==> phy_initialize = true;

Thanks. It really helps to see the various scenarios.

>
> >> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
> >> index 7cc4d21..f6bb4bc 100644
> >> --- a/drivers/gpu/drm/msm/dp/dp_display.c
> >> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
> >> @@ -83,6 +83,7 @@ struct dp_display_private {
> >>
> >>          /* state variables */
> >>          bool core_initialized;
> >> +       bool phy_initialized;
> >>          bool hpd_irq_on;
> >>          bool audio_supported;
> >>
> >> @@ -372,21 +373,46 @@ static int dp_display_process_hpd_high(struct dp_display_private *dp)
> >>          return rc;
> >>   }
> >>
> >> -static void dp_display_host_init(struct dp_display_private *dp, int reset)
> >> +static void dp_display_host_phy_init(struct dp_display_private *dp)
> >>   {
> >> -       bool flip = false;
> >> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
> >> +                       dp->core_initialized, dp->phy_initialized);
> >>
> >> +       if (!dp->phy_initialized) {
> >> +               dp_ctrl_phy_init(dp->ctrl);
> >> +               dp->phy_initialized = true;
> >> +       }
> >> +}
> >> +
> >> +static void dp_display_host_phy_exit(struct dp_display_private *dp)
> >> +{
> >> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
> >> +                       dp->core_initialized, dp->phy_initialized);
> >> +
> >> +       if (dp->phy_initialized) {
> >> +               dp_ctrl_phy_exit(dp->ctrl);
> >> +               dp->phy_initialized = false;
> >> +       }
> >> +}
> >> +
> >> +static void dp_display_host_init(struct dp_display_private *dp)
> >> +{
> >>          DRM_DEBUG_DP("core_initialized=%d\n", dp->core_initialized);
> >>          if (dp->core_initialized) {
> >>                  DRM_DEBUG_DP("DP core already initialized\n");
> >>                  return;
> >>          }
> >>
> >> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
> >> -               flip = true;
> >> +       dp_power_init(dp->power, false);
> >> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
> >> +
> >> +       /*
> >> +        * eDP is the embedded primary display and has its own phy
> >> +        * initialize phy immediately
> > Question still stands why we can't wait for hpd high from the eDP panel.
> > Also, I think "has its own phy" means that it's not part of a combo
> > USB+DP phy? Can you please clarify?
> >
> >> +        */
> >> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
> >> +               dp_display_host_phy_init(dp);
> >>
> >> -       dp_power_init(dp->power, flip);
> >> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
> >>          dp_aux_init(dp->aux);
> >>          dp->core_initialized = true;
> >>   }
> >> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
> >>          dp->hpd_state = ST_DISCONNECTED;
> >>
> >>          /* turn on dp ctrl/phy */
> >> -       dp_display_host_init(dp, true);
> >> +       dp_display_host_init(dp);
> >>
> >>          dp_catalog_ctrl_hpd_config(dp->catalog);
> >>
> >> -       /*
> >> -        * set sink to normal operation mode -- D0
> >> -        * before dpcd read
> >> -        */
> >> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>
> >>          if (dp_catalog_link_is_connected(dp->catalog)) {
> >> +               /*
> >> +                * set sink to normal operation mode -- D0
> >> +                * before dpcd read
> >> +                */
> >> +               dp_display_host_phy_init(dp);
> >> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>                  sink_count = drm_dp_read_sink_count(dp->aux);
> >>                  if (sink_count < 0)
> >>                          sink_count = 0;
> >> +
> >> +               dp_display_host_phy_exit(dp);
> > Why is the phy exited on resume when the link is still connected? Is
> > this supposed to be done only when the sink_count is 0? And how does
> > this interact with eDP where the phy is initialized by the call to
> > dp_display_host_init() earlier in this function.
> >
> >>          }
> >>
> >>          dp->link->sink_count = sink_count;

Any response to the above two comments?
Kuogee Hsieh Jan. 13, 2022, 5:51 p.m. UTC | #4
On 1/12/2022 8:13 PM, Stephen Boyd wrote:
> Quoting Kuogee Hsieh (2022-01-12 14:17:54)
>> On 1/12/2022 12:00 PM, Stephen Boyd wrote:
>>> Quoting Kuogee Hsieh (2022-01-11 10:43:23)
>>>> Current DP drivers have regulators, clocks, irq and phy are grouped
>>>> together within a function and executed not in a symmetric manner.
>>>> This increase difficulty of code maintenance and limited code scalability.
>>>> This patch divides the driver life cycle of operation into four states,
>>>> resume (including booting up), dongle plugin, dongle unplugged and suspend.
>>>> Regulators, core clocks and irq are grouped together and enabled at resume
>>>> (or booting up) so that the DP controller is armed and ready to receive HPD
>>>> plugin interrupts. HPD plugin interrupt is generated when a dongle plugs
>>>> into DUT (device under test). Once HPD plugin interrupt is received, DP
>>>> controller will initialize phy so that dpcd read/write will function and
>>>> following link training can be proceeded successfully. DP phy will be
>>>> disabled after main link is teared down at end of unplugged HPD interrupt
>>>> handle triggered by dongle unplugged out of DUT. Finally regulators, code
>>>> clocks and irq are disabled at corresponding suspension.
>> 0) Please note that  dongles are behavior differently.
>>
>> 1) Apple dongle will generate plug-in interrupt only if no hdmi monitor
>> atatched to dongle. it will generate irq-hpd interrupt once hdmi monitor
>> connect to dongle later.
>>
>> 2) Apple dongle will generate plugged-in interrupt followed by irq-hpd
>> interrupt if dongle has hdmi monitor attached when connects to DUT.
>>
>> 3) other dongle will not generate plug-in interrupt unless dongle has
>> hdmi monitor attached when connects to DUT. It only generate plug-in
>> interrupt only and no irq-hpd interrupt  generated on this case.
> Ok. The test scenarios can be reworded in terms of plugin irq and
> irq-hpd if that makes it easier.
>
>> 4) Note: phy_initialized only associated with plugged-in interrupt
>>
>> 5) irq-hpd interrupt must happen after plugged-in interrupt and before
>> unplugged interrupt
> More precisely it's that plugged-in interrupt must be handled before
> irq-hpd but plugged-in and irq-hpd can both be pending at the device
> concurrently unless they're masked and unmasked in some particular
> order. I thought the driver ensures that only irq-hpd is unmasked once
> the plugged in irq is handled. Can you confirm? Similarly, unplugged irq
> is unmasked after plugged in irq is handled, but irq-hpd and unplugged
> can both be pending if the irq handler is delayed?

we went through this before,

1) plugin_handler ==> do plug staffs + unmask irq_hpd at end of handler

2) unplug_handler ==> mask both plugin and irq_hpd  + do unplug staffs + 
unmask plugin irq at end of handler

3) priority order of handling irq when multiple irqs pending ==> plugin 
-> irq_hpd -> unplug

>
>> I will fill up below question with Apple dongle case with the order of
>> event happen timing.
>>
>>> I'll write out the various scenarios
>>>
>>> #1
>>>        dongle plugged in with HDMI cable attached
>>>        driver probe
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) generate plugged-in interrupt triggers handler
>> 4) dp_display_phy_init() ==> phy_initialized = true;
>>
>>>
>>> #2
>>>        dongle unplugged
>>>        driver probe
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>>
>>
>>> #3
>>>        dongle plugged in without HDMI cable attached
>>>        driver probe
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) generate plug-in interrupt triggers handler
>> 4) dp_display_phy_init() ==> phy_initialized = true;
>>
>> Note: same as case #1
>>> #4
>>>        driver probe
>>>        dongle plugged in without HDMI cable attached
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plugged in
>> 4) generate plug-in interrupt triggers handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>>
>>>
>>> #5
>>>        driver probe
>>>        dongle plugged in with HDMI cable attached
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plugged in
>> 4) generate plug-in interrupt trigger handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>>
>> Note: same as case #4
>>
>>> #6
>>>        driver probe
>>>        dongle plugged in
>>>        suspend
>>>        resume
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plug in
>> 4) generate plug-in interrupt triggers handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>> 6) suspend
>> 7) dp_display_host_deinit() ==> core_initialized = false;
>> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
>> 9) resume
>> 10) dp_display_host_init() ==> core_initialized = true;
>> 11) generate plug-in interrupt
>> 12) dp_display_phy_init() ==> phy_initialize = true;
>>
>>> #7
>>>        driver probe
>>>        dongle plugged in
>>>        suspend
>>>        dongle unplugged
>>>        resume
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plugged in
>> 4) generate plug-in interrupt triggers handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>> 6) suspend
>> 7) dp_display_host_deinit() ==> core_initialized = false;
>> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
> Why is the order of operations swapped? During probe core_initialized
> is done first and then phy_initialized but then on suspend
> core_initialized is done first again before phy_initialized. That's
> asymmetric.
ok, will fix this
>
>> 9) dongle unplugged
>> 10) resume
>> 11) dp_display_host_init() ==> core_initialized = true;
>>
>> #8
>>          driver probe
>>          dongle plugged in without HDMI cable attached
>>          suspend
>>          resume
>>
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plug in
>> 4) generate plug-in interrupt triggers handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>> 6) suspend
>> 7) dp_display_host_deinit() ==> core_initialized = false;
>> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
>> 9) resume
>> 10) dp_display_host_init() ==> core_initialized = true;
>> 11) generate plug-in interrupt
>> 12) dp_display_phy_init() ==> phy_initialize = true;
>>
>>
>> NOTE: same case #6
>>
>> #9
>>          driver probe
>>          dongle plugged in without HDMI cable attached
>>          suspend
>>          HDMI cable attached during suspend
>>          resume
>>
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) dongle plugged in
>> 4) generate plug-in interrupt triggers handler
>> 5) dp_display_phy_init() ==> phy_initialized = true;
>> 6) suspend
>> 7) dp_display_host_deinit() ==> core_initialized = false;
>> 8) dp_display_host_phy_exit() ==> phy_initialize = false;
>> 9) HDMI cable attached
>> 10) resume
>> 11) dp_display_host_init() ==> core_initialized = true;
>> 12) generate plug-in interrupt
>> 13) dp_display_phy_init() ==> phy_initialize = true;
>>
>>
>> What's the state of the phy and core initialized variable at the end of
>> each of these scenarios? Please fill out the truth table.
>>
>>                    +-----------------+------------------------
>>                     |    false        |       true            |
>>                    +-----------------+------------------------
>>    phy_initialized  |                 |                       |
>>                    +-----------------+------------------------
>>    core_initialized |                 | #1,                   |
>>                    +-----------------+------------------------
>>
>> I guess we also need eDP scenarios, but that's probably simpler
>>
>> #10
>>          eDP panel connected
>>          driver probe
>>
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) generate plug-in interrupt triggers handler
> I think this is more like "dp_display_config_hpd() is called by hpd
> kthread"?

yes, correct as below (eDP will call phy_init immediately

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_config_hpd()
3) dp_display_host_init() ==> core_initialized = true;
4) dp_display_host_phy_init() ==> phy_initialize = true
5) generate plug-in interrupt triggers handler

>
>> 4) dp_display_phy_init() ==> phy_initialized = true;
>>
>>
>>
>> #11
>>          eDP panel disconnected
>>          driver probe
>>
>> NOTE: eDP panel can not be disconnected
> The panel can certainly be disconnected in the sense that the ribbon
> cable to the panel is busted or not working properly. That's what this
> scenario is for.

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_config_hpd()
3) dp_display_host_init() ==> core_initialized = true;
4) dp_display_host_phy_init() ==> phy_initialize = true

1) driver probe ==> core_initialized = false; phy_initialized = false;
>> #12
>>          eDP panel disconnected
>>          driver probe
>>          suspend
>>          resume
>>
>> NOTE: assume edp panel connected
>> 1) driver probe ==> core_initialized = false;    phy_initialized = false;
>> 2) dp_display_host_init() ==> core_initialized = true;
>> 3) generate plug-in interrupt triggers handler
>> 4) dp_display_phy_init() ==> phy_initialized = true;
>> 5) suspend
>> 6) dp_display_host_deinit() ==> core_initialized = false;
>> 7) dp_display_host_phy_exit() ==> phy_initialize = false;
>> 8) resume
>> 9) dp_display_host_init() ==> core_initialized = true;
>> 10) generate plug-in interrupt
>> 11) dp_display_phy_init() ==> phy_initialize = true;

1) driver probe ==> core_initialized = false;    phy_initialized = false;
2) dp_display_config_hpd()
3) dp_display_host_init() ==> core_initialized = true;
4) dp_display_host_phy_init() ==> phy_initialize = true
5) generate plug-in interrupt triggers handler
6) dp_display_phy_init() ==> phy_initialized = true;
7) suspend
8) dp_display_host_deinit() ==> core_initialized = false;
9) dp_display_host_phy_exit() ==> phy_initialize = false;
10) resume
11) dp_display_host_init() ==> core_initialized = true;
11) dp_display_phy_init() ==> phy_initialize = true;
12) generate plug-in interrupt triggers handler

> Thanks. It really helps to see the various scenarios.
>
>>>> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
>>>> index 7cc4d21..f6bb4bc 100644
>>>> --- a/drivers/gpu/drm/msm/dp/dp_display.c
>>>> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
>>>> @@ -83,6 +83,7 @@ struct dp_display_private {
>>>>
>>>>           /* state variables */
>>>>           bool core_initialized;
>>>> +       bool phy_initialized;
>>>>           bool hpd_irq_on;
>>>>           bool audio_supported;
>>>>
>>>> @@ -372,21 +373,46 @@ static int dp_display_process_hpd_high(struct dp_display_private *dp)
>>>>           return rc;
>>>>    }
>>>>
>>>> -static void dp_display_host_init(struct dp_display_private *dp, int reset)
>>>> +static void dp_display_host_phy_init(struct dp_display_private *dp)
>>>>    {
>>>> -       bool flip = false;
>>>> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
>>>> +                       dp->core_initialized, dp->phy_initialized);
>>>>
>>>> +       if (!dp->phy_initialized) {
>>>> +               dp_ctrl_phy_init(dp->ctrl);
>>>> +               dp->phy_initialized = true;
>>>> +       }
>>>> +}
>>>> +
>>>> +static void dp_display_host_phy_exit(struct dp_display_private *dp)
>>>> +{
>>>> +       DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
>>>> +                       dp->core_initialized, dp->phy_initialized);
>>>> +
>>>> +       if (dp->phy_initialized) {
>>>> +               dp_ctrl_phy_exit(dp->ctrl);
>>>> +               dp->phy_initialized = false;
>>>> +       }
>>>> +}
>>>> +
>>>> +static void dp_display_host_init(struct dp_display_private *dp)
>>>> +{
>>>>           DRM_DEBUG_DP("core_initialized=%d\n", dp->core_initialized);
>>>>           if (dp->core_initialized) {
>>>>                   DRM_DEBUG_DP("DP core already initialized\n");
>>>>                   return;
>>>>           }
>>>>
>>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
>>>> -               flip = true;
>>>> +       dp_power_init(dp->power, false);
>>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
>>>> +
>>>> +       /*
>>>> +        * eDP is the embedded primary display and has its own phy
>>>> +        * initialize phy immediately
>>> Question still stands why we can't wait for hpd high from the eDP panel.
>>> Also, I think "has its own phy" means that it's not part of a combo
>>> USB+DP phy? Can you please clarify?
>>>
>>>> +        */
>>>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
>>>> +               dp_display_host_phy_init(dp);
>>>>
>>>> -       dp_power_init(dp->power, flip);
>>>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
>>>>           dp_aux_init(dp->aux);
>>>>           dp->core_initialized = true;
>>>>    }
>>>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
>>>>           dp->hpd_state = ST_DISCONNECTED;
>>>>
>>>>           /* turn on dp ctrl/phy */
>>>> -       dp_display_host_init(dp, true);
>>>> +       dp_display_host_init(dp);
>>>>
>>>>           dp_catalog_ctrl_hpd_config(dp->catalog);
>>>>
>>>> -       /*
>>>> -        * set sink to normal operation mode -- D0
>>>> -        * before dpcd read
>>>> -        */
>>>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>
>>>>           if (dp_catalog_link_is_connected(dp->catalog)) {
>>>> +               /*
>>>> +                * set sink to normal operation mode -- D0
>>>> +                * before dpcd read
>>>> +                */
>>>> +               dp_display_host_phy_init(dp);
>>>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>                   sink_count = drm_dp_read_sink_count(dp->aux);
>>>>                   if (sink_count < 0)
>>>>                           sink_count = 0;
>>>> +
>>>> +               dp_display_host_phy_exit(dp);
>>> Why is the phy exited on resume when the link is still connected? Is
>>> this supposed to be done only when the sink_count is 0? And how does
>>> this interact with eDP where the phy is initialized by the call to
>>> dp_display_host_init() earlier in this function.
>>>
>>>>           }
>>>>
>>>>           dp->link->sink_count = sink_count;
> Any response to the above two comments?
Stephen Boyd Jan. 13, 2022, 7:47 p.m. UTC | #5
Quoting Kuogee Hsieh (2022-01-13 09:51:42)
>
> On 1/12/2022 8:13 PM, Stephen Boyd wrote:
> >>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
> >>>> -               flip = true;
> >>>> +       dp_power_init(dp->power, false);
> >>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
> >>>> +
> >>>> +       /*
> >>>> +        * eDP is the embedded primary display and has its own phy
> >>>> +        * initialize phy immediately
> >>> Question still stands why we can't wait for hpd high from the eDP panel.
> >>> Also, I think "has its own phy" means that it's not part of a combo
> >>> USB+DP phy? Can you please clarify?
> >>>
> >>>> +        */
> >>>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
> >>>> +               dp_display_host_phy_init(dp);
> >>>>
> >>>> -       dp_power_init(dp->power, flip);
> >>>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
> >>>>           dp_aux_init(dp->aux);
> >>>>           dp->core_initialized = true;
> >>>>    }
> >>>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
> >>>>           dp->hpd_state = ST_DISCONNECTED;
> >>>>
> >>>>           /* turn on dp ctrl/phy */
> >>>> -       dp_display_host_init(dp, true);
> >>>> +       dp_display_host_init(dp);
> >>>>
> >>>>           dp_catalog_ctrl_hpd_config(dp->catalog);
> >>>>
> >>>> -       /*
> >>>> -        * set sink to normal operation mode -- D0
> >>>> -        * before dpcd read
> >>>> -        */
> >>>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>>>
> >>>>           if (dp_catalog_link_is_connected(dp->catalog)) {
> >>>> +               /*
> >>>> +                * set sink to normal operation mode -- D0
> >>>> +                * before dpcd read
> >>>> +                */
> >>>> +               dp_display_host_phy_init(dp);
> >>>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>>>                   sink_count = drm_dp_read_sink_count(dp->aux);
> >>>>                   if (sink_count < 0)
> >>>>                           sink_count = 0;
> >>>> +
> >>>> +               dp_display_host_phy_exit(dp);
> >>> Why is the phy exited on resume when the link is still connected? Is
> >>> this supposed to be done only when the sink_count is 0? And how does
> >>> this interact with eDP where the phy is initialized by the call to
> >>> dp_display_host_init() earlier in this function.
> >>>
> >>>>           }
> >>>>
> >>>>           dp->link->sink_count = sink_count;
> > Any response to the above two comments?

??
Kuogee Hsieh Jan. 13, 2022, 8:44 p.m. UTC | #6
On 1/13/2022 11:47 AM, Stephen Boyd wrote:
> Quoting Kuogee Hsieh (2022-01-13 09:51:42)
>> On 1/12/2022 8:13 PM, Stephen Boyd wrote:
>>>>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
>>>>>> -               flip = true;
>>>>>> +       dp_power_init(dp->power, false);
>>>>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
>>>>>> +
>>>>>> +       /*
>>>>>> +        * eDP is the embedded primary display and has its own phy
>>>>>> +        * initialize phy immediately
>>>>> Question still stands why we can't wait for hpd high from the eDP panel.
>>>>> Also, I think "has its own phy" means that it's not part of a combo
>>>>> USB+DP phy? Can you please clarify?
Correct, eDP has its dedicated phy which is not part of combo phy.
>>>>>> +        */
>>>>>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
>>>>>> +               dp_display_host_phy_init(dp);
>>>>>>
>>>>>> -       dp_power_init(dp->power, flip);
>>>>>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
>>>>>>            dp_aux_init(dp->aux);
>>>>>>            dp->core_initialized = true;
>>>>>>     }
>>>>>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
>>>>>>            dp->hpd_state = ST_DISCONNECTED;
>>>>>>
>>>>>>            /* turn on dp ctrl/phy */
>>>>>> -       dp_display_host_init(dp, true);
>>>>>> +       dp_display_host_init(dp);
>>>>>>
>>>>>>            dp_catalog_ctrl_hpd_config(dp->catalog);
>>>>>>
>>>>>> -       /*
>>>>>> -        * set sink to normal operation mode -- D0
>>>>>> -        * before dpcd read
>>>>>> -        */
>>>>>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>>>
>>>>>>            if (dp_catalog_link_is_connected(dp->catalog)) {
>>>>>> +               /*
>>>>>> +                * set sink to normal operation mode -- D0
>>>>>> +                * before dpcd read
>>>>>> +                */
>>>>>> +               dp_display_host_phy_init(dp);
>>>>>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>>>                    sink_count = drm_dp_read_sink_count(dp->aux);
>>>>>>                    if (sink_count < 0)
>>>>>>                            sink_count = 0;
>>>>>> +
>>>>>> +               dp_display_host_phy_exit(dp);
>>>>> Why is the phy exited on resume when the link is still connected? Is
>>>>> this supposed to be done only when the sink_count is 0? And how does
>>>>> this interact with eDP where the phy is initialized by the call to
>>>>> dp_display_host_init() earlier in this function.

At beginning of dp_pm_resume bot core_initialized and phy_initialized 
should be off.

However at the case of dongle still connected to DUT, we have to read 
dongle dpcd to decided any hdmi connect to dongle (sink_count != 0). in 
this case, we have to turn on phy to perform dpcd read and  turn off phy 
after read so the following plugged-in interrupt can be handled correctly.

>>>>>>            }
>>>>>>
>>>>>>            dp->link->sink_count = sink_count;
>>> Any response to the above two comments?
> ??
Stephen Boyd Jan. 13, 2022, 9:52 p.m. UTC | #7
Quoting Kuogee Hsieh (2022-01-13 12:44:16)
>
> On 1/13/2022 11:47 AM, Stephen Boyd wrote:
> > Quoting Kuogee Hsieh (2022-01-13 09:51:42)
> >> On 1/12/2022 8:13 PM, Stephen Boyd wrote:
> >>>>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
> >>>>>> -               flip = true;
> >>>>>> +       dp_power_init(dp->power, false);
> >>>>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
> >>>>>> +
> >>>>>> +       /*
> >>>>>> +        * eDP is the embedded primary display and has its own phy
> >>>>>> +        * initialize phy immediately
> >>>>> Question still stands why we can't wait for hpd high from the eDP panel.
> >>>>> Also, I think "has its own phy" means that it's not part of a combo
> >>>>> USB+DP phy? Can you please clarify?
> Correct, eDP has its dedicated phy which is not part of combo phy.

Why does that mean we can't wait for hpd high from the eDP panel?

> >>>>>> +        */
> >>>>>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
> >>>>>> +               dp_display_host_phy_init(dp);
> >>>>>>
> >>>>>> -       dp_power_init(dp->power, flip);
> >>>>>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
> >>>>>>            dp_aux_init(dp->aux);
> >>>>>>            dp->core_initialized = true;
> >>>>>>     }
> >>>>>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
> >>>>>>            dp->hpd_state = ST_DISCONNECTED;
> >>>>>>
> >>>>>>            /* turn on dp ctrl/phy */
> >>>>>> -       dp_display_host_init(dp, true);
> >>>>>> +       dp_display_host_init(dp);
> >>>>>>
> >>>>>>            dp_catalog_ctrl_hpd_config(dp->catalog);
> >>>>>>
> >>>>>> -       /*
> >>>>>> -        * set sink to normal operation mode -- D0
> >>>>>> -        * before dpcd read
> >>>>>> -        */
> >>>>>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>>>>>
> >>>>>>            if (dp_catalog_link_is_connected(dp->catalog)) {
> >>>>>> +               /*
> >>>>>> +                * set sink to normal operation mode -- D0
> >>>>>> +                * before dpcd read
> >>>>>> +                */
> >>>>>> +               dp_display_host_phy_init(dp);
> >>>>>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
> >>>>>>                    sink_count = drm_dp_read_sink_count(dp->aux);
> >>>>>>                    if (sink_count < 0)
> >>>>>>                            sink_count = 0;
> >>>>>> +
> >>>>>> +               dp_display_host_phy_exit(dp);
> >>>>> Why is the phy exited on resume when the link is still connected? Is
> >>>>> this supposed to be done only when the sink_count is 0? And how does
> >>>>> this interact with eDP where the phy is initialized by the call to
> >>>>> dp_display_host_init() earlier in this function.
>
> At beginning of dp_pm_resume bot core_initialized and phy_initialized
> should be off.
>
> However at the case of dongle still connected to DUT, we have to read
> dongle dpcd to decided any hdmi connect to dongle (sink_count != 0). in
> this case, we have to turn on phy to perform dpcd read and  turn off phy
> after read so the following plugged-in interrupt can be handled correctly.
>

That looks like a lot of wasted work. Why can't we turn on the core,
turn on the phy, check if it's connected, and then turn off the phy if
it isn't? At the least, please put a comment above this phy_exit() call
indicating that we'll turn the phy back on while processing a plugged in
interrupt.
Kuogee Hsieh Jan. 13, 2022, 10:14 p.m. UTC | #8
On 1/13/2022 1:52 PM, Stephen Boyd wrote:
> Quoting Kuogee Hsieh (2022-01-13 12:44:16)
>> On 1/13/2022 11:47 AM, Stephen Boyd wrote:
>>> Quoting Kuogee Hsieh (2022-01-13 09:51:42)
>>>> On 1/12/2022 8:13 PM, Stephen Boyd wrote:
>>>>>>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
>>>>>>>> -               flip = true;
>>>>>>>> +       dp_power_init(dp->power, false);
>>>>>>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
>>>>>>>> +
>>>>>>>> +       /*
>>>>>>>> +        * eDP is the embedded primary display and has its own phy
>>>>>>>> +        * initialize phy immediately
>>>>>>> Question still stands why we can't wait for hpd high from the eDP panel.
>>>>>>> Also, I think "has its own phy" means that it's not part of a combo
>>>>>>> USB+DP phy? Can you please clarify?
>> Correct, eDP has its dedicated phy which is not part of combo phy.
> Why does that mean we can't wait for hpd high from the eDP panel?

Sorry, missed this one.

Yes, it can wait for hpd high.

Since it always presented, I just think it is better to show display 
sooner not later until hdp high.

you like it to wait until hpd high?

>>>>>>>> +        */
>>>>>>>> +       if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
>>>>>>>> +               dp_display_host_phy_init(dp);
>>>>>>>>
>>>>>>>> -       dp_power_init(dp->power, flip);
>>>>>>>> -       dp_ctrl_host_init(dp->ctrl, flip, reset);
>>>>>>>>             dp_aux_init(dp->aux);
>>>>>>>>             dp->core_initialized = true;
>>>>>>>>      }
>>>>>>>> @@ -1306,20 +1330,23 @@ static int dp_pm_resume(struct device *dev)
>>>>>>>>             dp->hpd_state = ST_DISCONNECTED;
>>>>>>>>
>>>>>>>>             /* turn on dp ctrl/phy */
>>>>>>>> -       dp_display_host_init(dp, true);
>>>>>>>> +       dp_display_host_init(dp);
>>>>>>>>
>>>>>>>>             dp_catalog_ctrl_hpd_config(dp->catalog);
>>>>>>>>
>>>>>>>> -       /*
>>>>>>>> -        * set sink to normal operation mode -- D0
>>>>>>>> -        * before dpcd read
>>>>>>>> -        */
>>>>>>>> -       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>>>>>
>>>>>>>>             if (dp_catalog_link_is_connected(dp->catalog)) {
>>>>>>>> +               /*
>>>>>>>> +                * set sink to normal operation mode -- D0
>>>>>>>> +                * before dpcd read
>>>>>>>> +                */
>>>>>>>> +               dp_display_host_phy_init(dp);
>>>>>>>> +               dp_link_psm_config(dp->link, &dp->panel->link_info, false);
>>>>>>>>                     sink_count = drm_dp_read_sink_count(dp->aux);
>>>>>>>>                     if (sink_count < 0)
>>>>>>>>                             sink_count = 0;
>>>>>>>> +
>>>>>>>> +               dp_display_host_phy_exit(dp);
>>>>>>> Why is the phy exited on resume when the link is still connected? Is
>>>>>>> this supposed to be done only when the sink_count is 0? And how does
>>>>>>> this interact with eDP where the phy is initialized by the call to
>>>>>>> dp_display_host_init() earlier in this function.
>> At beginning of dp_pm_resume bot core_initialized and phy_initialized
>> should be off.
>>
>> However at the case of dongle still connected to DUT, we have to read
>> dongle dpcd to decided any hdmi connect to dongle (sink_count != 0). in
>> this case, we have to turn on phy to perform dpcd read and  turn off phy
>> after read so the following plugged-in interrupt can be handled correctly.
>>
> That looks like a lot of wasted work. Why can't we turn on the core,
> turn on the phy, check if it's connected, and then turn off the phy if
> it isn't? At the least, please put a comment above this phy_exit() call
> indicating that we'll turn the phy back on while processing a plugged in
> interrupt.
Stephen Boyd Jan. 13, 2022, 11:13 p.m. UTC | #9
Quoting Kuogee Hsieh (2022-01-13 14:14:27)
>
> On 1/13/2022 1:52 PM, Stephen Boyd wrote:
> > Quoting Kuogee Hsieh (2022-01-13 12:44:16)
> >> On 1/13/2022 11:47 AM, Stephen Boyd wrote:
> >>> Quoting Kuogee Hsieh (2022-01-13 09:51:42)
> >>>> On 1/12/2022 8:13 PM, Stephen Boyd wrote:
> >>>>>>>> -       if (dp->usbpd->orientation == ORIENTATION_CC2)
> >>>>>>>> -               flip = true;
> >>>>>>>> +       dp_power_init(dp->power, false);
> >>>>>>>> +       dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
> >>>>>>>> +
> >>>>>>>> +       /*
> >>>>>>>> +        * eDP is the embedded primary display and has its own phy
> >>>>>>>> +        * initialize phy immediately
> >>>>>>> Question still stands why we can't wait for hpd high from the eDP panel.
> >>>>>>> Also, I think "has its own phy" means that it's not part of a combo
> >>>>>>> USB+DP phy? Can you please clarify?
> >> Correct, eDP has its dedicated phy which is not part of combo phy.
> > Why does that mean we can't wait for hpd high from the eDP panel?
>
> Sorry, missed this one.
>
> Yes, it can wait for hpd high.
>
> Since it always presented, I just think it is better to show display
> sooner not later until hdp high.
>
> you like it to wait until hpd high?

Yes. The less special cases the easier it is to read and modify later. I
also worry that someone will decide to connect a DP connector to the eDP
pins and then not always drive HPD high. In that case this code would
need to change so it seems better to follow one flow instead of two.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index c724cb0..9c80b49 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -1365,60 +1365,44 @@  static int dp_ctrl_enable_stream_clocks(struct dp_ctrl_private *ctrl)
 	return ret;
 }
 
-int dp_ctrl_host_init(struct dp_ctrl *dp_ctrl, bool flip, bool reset)
+void dp_ctrl_reset_irq_ctrl(struct dp_ctrl *dp_ctrl, bool enable)
+{
+	struct dp_ctrl_private *ctrl;
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+
+	dp_catalog_ctrl_reset(ctrl->catalog);
+
+	if (enable)
+		dp_catalog_ctrl_enable_irq(ctrl->catalog, enable);
+}
+
+void dp_ctrl_phy_init(struct dp_ctrl *dp_ctrl)
 {
 	struct dp_ctrl_private *ctrl;
 	struct dp_io *dp_io;
 	struct phy *phy;
 
-	if (!dp_ctrl) {
-		DRM_ERROR("Invalid input data\n");
-		return -EINVAL;
-	}
-
 	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
 	dp_io = &ctrl->parser->io;
 	phy = dp_io->phy;
 
-	ctrl->dp_ctrl.orientation = flip;
-
-	if (reset)
-		dp_catalog_ctrl_reset(ctrl->catalog);
-
-	DRM_DEBUG_DP("flip=%d\n", flip);
 	dp_catalog_ctrl_phy_reset(ctrl->catalog);
 	phy_init(phy);
-	dp_catalog_ctrl_enable_irq(ctrl->catalog, true);
-
-	return 0;
 }
 
-/**
- * dp_ctrl_host_deinit() - Uninitialize DP controller
- * @dp_ctrl: Display Port Driver data
- *
- * Perform required steps to uninitialize DP controller
- * and its resources.
- */
-void dp_ctrl_host_deinit(struct dp_ctrl *dp_ctrl)
+void dp_ctrl_phy_exit(struct dp_ctrl *dp_ctrl)
 {
 	struct dp_ctrl_private *ctrl;
 	struct dp_io *dp_io;
 	struct phy *phy;
 
-	if (!dp_ctrl) {
-		DRM_ERROR("Invalid input data\n");
-		return;
-	}
-
 	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
 	dp_io = &ctrl->parser->io;
 	phy = dp_io->phy;
 
-	dp_catalog_ctrl_enable_irq(ctrl->catalog, false);
+	dp_catalog_ctrl_phy_reset(ctrl->catalog);
 	phy_exit(phy);
-
-	DRM_DEBUG_DP("Host deinitialized successfully\n");
 }
 
 static bool dp_ctrl_use_fixed_nvid(struct dp_ctrl_private *ctrl)
@@ -1488,7 +1472,10 @@  static int dp_ctrl_deinitialize_mainlink(struct dp_ctrl_private *ctrl)
 	}
 
 	phy_power_off(phy);
+
+	/* aux channel down, reinit phy */
 	phy_exit(phy);
+	phy_init(phy);
 
 	return 0;
 }
@@ -1893,8 +1880,14 @@  int dp_ctrl_off_link_stream(struct dp_ctrl *dp_ctrl)
 		return ret;
 	}
 
+	DRM_DEBUG_DP("Before, phy=%x init_count=%d power_on=%d\n",
+		(u32)(uintptr_t)phy, phy->init_count, phy->power_count);
+
 	phy_power_off(phy);
 
+	DRM_DEBUG_DP("After, phy=%x init_count=%d power_on=%d\n",
+		(u32)(uintptr_t)phy, phy->init_count, phy->power_count);
+
 	/* aux channel down, reinit phy */
 	phy_exit(phy);
 	phy_init(phy);
@@ -1903,23 +1896,6 @@  int dp_ctrl_off_link_stream(struct dp_ctrl *dp_ctrl)
 	return ret;
 }
 
-void dp_ctrl_off_phy(struct dp_ctrl *dp_ctrl)
-{
-	struct dp_ctrl_private *ctrl;
-	struct dp_io *dp_io;
-	struct phy *phy;
-
-	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
-	dp_io = &ctrl->parser->io;
-	phy = dp_io->phy;
-
-	dp_catalog_ctrl_reset(ctrl->catalog);
-
-	phy_exit(phy);
-
-	DRM_DEBUG_DP("DP off phy done\n");
-}
-
 int dp_ctrl_off(struct dp_ctrl *dp_ctrl)
 {
 	struct dp_ctrl_private *ctrl;
@@ -1947,10 +1923,14 @@  int dp_ctrl_off(struct dp_ctrl *dp_ctrl)
 		DRM_ERROR("Failed to disable link clocks. ret=%d\n", ret);
 	}
 
+	DRM_DEBUG_DP("Before, phy=%x init_count=%d power_on=%d\n",
+		(u32)(uintptr_t)phy, phy->init_count, phy->power_count);
+
 	phy_power_off(phy);
-	phy_exit(phy);
 
-	DRM_DEBUG_DP("DP off done\n");
+	DRM_DEBUG_DP("After, phy=%x init_count=%d power_on=%d\n",
+		(u32)(uintptr_t)phy, phy->init_count, phy->power_count);
+
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.h b/drivers/gpu/drm/msm/dp/dp_ctrl.h
index 2363a2d..2433edb 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.h
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.h
@@ -19,12 +19,9 @@  struct dp_ctrl {
 	u32 pixel_rate;
 };
 
-int dp_ctrl_host_init(struct dp_ctrl *dp_ctrl, bool flip, bool reset);
-void dp_ctrl_host_deinit(struct dp_ctrl *dp_ctrl);
 int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl);
 int dp_ctrl_on_stream(struct dp_ctrl *dp_ctrl);
 int dp_ctrl_off_link_stream(struct dp_ctrl *dp_ctrl);
-void dp_ctrl_off_phy(struct dp_ctrl *dp_ctrl);
 int dp_ctrl_off(struct dp_ctrl *dp_ctrl);
 void dp_ctrl_push_idle(struct dp_ctrl *dp_ctrl);
 void dp_ctrl_isr(struct dp_ctrl *dp_ctrl);
@@ -34,4 +31,9 @@  struct dp_ctrl *dp_ctrl_get(struct device *dev, struct dp_link *link,
 			struct dp_power *power, struct dp_catalog *catalog,
 			struct dp_parser *parser);
 
+void dp_ctrl_reset_irq_ctrl(struct dp_ctrl *dp_ctrl, bool enable);
+void dp_ctrl_phy_init(struct dp_ctrl *dp_ctrl);
+void dp_ctrl_phy_exit(struct dp_ctrl *dp_ctrl);
+void dp_ctrl_irq_phy_exit(struct dp_ctrl *dp_ctrl);
+
 #endif /* _DP_CTRL_H_ */
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index 7cc4d21..f6bb4bc 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -83,6 +83,7 @@  struct dp_display_private {
 
 	/* state variables */
 	bool core_initialized;
+	bool phy_initialized;
 	bool hpd_irq_on;
 	bool audio_supported;
 
@@ -372,21 +373,46 @@  static int dp_display_process_hpd_high(struct dp_display_private *dp)
 	return rc;
 }
 
-static void dp_display_host_init(struct dp_display_private *dp, int reset)
+static void dp_display_host_phy_init(struct dp_display_private *dp)
 {
-	bool flip = false;
+	DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
+			dp->core_initialized, dp->phy_initialized);
 
+	if (!dp->phy_initialized) {
+		dp_ctrl_phy_init(dp->ctrl);
+		dp->phy_initialized = true;
+	}
+}
+
+static void dp_display_host_phy_exit(struct dp_display_private *dp)
+{
+	DRM_DEBUG_DP("core_init=%d phy_init=%d\n",
+			dp->core_initialized, dp->phy_initialized);
+
+	if (dp->phy_initialized) {
+		dp_ctrl_phy_exit(dp->ctrl);
+		dp->phy_initialized = false;
+	}
+}
+
+static void dp_display_host_init(struct dp_display_private *dp)
+{
 	DRM_DEBUG_DP("core_initialized=%d\n", dp->core_initialized);
 	if (dp->core_initialized) {
 		DRM_DEBUG_DP("DP core already initialized\n");
 		return;
 	}
 
-	if (dp->usbpd->orientation == ORIENTATION_CC2)
-		flip = true;
+	dp_power_init(dp->power, false);
+	dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
+
+	/*
+	 * eDP is the embedded primary display and has its own phy
+	 * initialize phy immediately
+	 */
+	if (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP)
+		dp_display_host_phy_init(dp);
 
-	dp_power_init(dp->power, flip);
-	dp_ctrl_host_init(dp->ctrl, flip, reset);
 	dp_aux_init(dp->aux);
 	dp->core_initialized = true;
 }
@@ -398,7 +424,7 @@  static void dp_display_host_deinit(struct dp_display_private *dp)
 		return;
 	}
 
-	dp_ctrl_host_deinit(dp->ctrl);
+	dp_ctrl_reset_irq_ctrl(dp->ctrl, false);
 	dp_aux_deinit(dp->aux);
 	dp_power_deinit(dp->power);
 
@@ -409,7 +435,7 @@  static int dp_display_usbpd_configure_cb(struct device *dev)
 {
 	struct dp_display_private *dp = dev_get_dp_display_private(dev);
 
-	dp_display_host_init(dp, false);
+	dp_display_host_phy_init(dp);
 
 	return dp_display_process_hpd_high(dp);
 }
@@ -530,11 +556,6 @@  static int dp_hpd_plug_handle(struct dp_display_private *dp, u32 data)
 	ret = dp_display_usbpd_configure_cb(&dp->pdev->dev);
 	if (ret) {	/* link train failed */
 		dp->hpd_state = ST_DISCONNECTED;
-
-		if (ret == -ECONNRESET) { /* cable unplugged */
-			dp->core_initialized = false;
-		}
-
 	} else {
 		/* start sentinel checking in case of missing uevent */
 		dp_add_event(dp, EV_CONNECT_PENDING_TIMEOUT, 0, tout);
@@ -604,8 +625,7 @@  static int dp_hpd_unplug_handle(struct dp_display_private *dp, u32 data)
 	if (state == ST_DISCONNECTED) {
 		/* triggered by irq_hdp with sink_count = 0 */
 		if (dp->link->sink_count == 0) {
-			dp_ctrl_off_phy(dp->ctrl);
-			dp->core_initialized = false;
+			dp_display_host_phy_exit(dp);
 		}
 		mutex_unlock(&dp->event_mutex);
 		return 0;
@@ -696,12 +716,9 @@  static int dp_irq_hpd_handle(struct dp_display_private *dp, u32 data)
 	 * dp core (ahb/aux clks) must be initialized before
 	 * irq_hpd be handled
 	 */
-	if (dp->core_initialized) {
+	if (dp->core_initialized)
 		ret = dp_display_usbpd_attention_cb(&dp->pdev->dev);
-		if (ret == -ECONNRESET) { /* cable unplugged */
-			dp->core_initialized = false;
-		}
-	}
+
 	DRM_DEBUG_DP("hpd_state=%d\n", state);
 
 	mutex_unlock(&dp->event_mutex);
@@ -892,12 +909,19 @@  static int dp_display_disable(struct dp_display_private *dp, u32 data)
 
 	dp_display->audio_enabled = false;
 
-	/* triggered by irq_hpd with sink_count = 0 */
 	if (dp->link->sink_count == 0) {
+		/*
+		 * irq_hpd with sink_count = 0
+		 * hdmi unplugged out of dongle
+		 */
 		dp_ctrl_off_link_stream(dp->ctrl);
 	} else {
+		/*
+		 * unplugged interrupt
+		 * dongle unplugged out of DUT
+		 */
 		dp_ctrl_off(dp->ctrl);
-		dp->core_initialized = false;
+		dp_display_host_phy_exit(dp);
 	}
 
 	dp_display->power_on = false;
@@ -1027,7 +1051,7 @@  void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
 static void dp_display_config_hpd(struct dp_display_private *dp)
 {
 
-	dp_display_host_init(dp, true);
+	dp_display_host_init(dp);
 	dp_catalog_ctrl_hpd_config(dp->catalog);
 
 	/* Enable interrupt first time
@@ -1306,20 +1330,23 @@  static int dp_pm_resume(struct device *dev)
 	dp->hpd_state = ST_DISCONNECTED;
 
 	/* turn on dp ctrl/phy */
-	dp_display_host_init(dp, true);
+	dp_display_host_init(dp);
 
 	dp_catalog_ctrl_hpd_config(dp->catalog);
 
-	/*
-	 * set sink to normal operation mode -- D0
-	 * before dpcd read
-	 */
-	dp_link_psm_config(dp->link, &dp->panel->link_info, false);
 
 	if (dp_catalog_link_is_connected(dp->catalog)) {
+		/*
+		 * set sink to normal operation mode -- D0
+		 * before dpcd read
+		 */
+		dp_display_host_phy_init(dp);
+		dp_link_psm_config(dp->link, &dp->panel->link_info, false);
 		sink_count = drm_dp_read_sink_count(dp->aux);
 		if (sink_count < 0)
 			sink_count = 0;
+
+		dp_display_host_phy_exit(dp);
 	}
 
 	dp->link->sink_count = sink_count;
@@ -1366,6 +1393,8 @@  static int dp_pm_suspend(struct device *dev)
 		dp_display_host_deinit(dp);
 	}
 
+	dp_display_host_phy_exit(dp);
+
 	dp->hpd_state = ST_SUSPENDED;
 
 	/* host_init will be called at pm_resume */
@@ -1535,7 +1564,7 @@  int msm_dp_display_enable(struct msm_dp *dp, struct drm_encoder *encoder)
 	state =  dp_display->hpd_state;
 
 	if (state == ST_DISPLAY_OFF)
-		dp_display_host_init(dp_display, true);
+		dp_display_host_phy_init(dp_display);
 
 	dp_display_enable(dp_display, 0);