[PATCH v2 3/5] drm/rockchip: cdn-dp: Support handle lane info and HPD without extcon

air windows kernel at airkyi.com
Sun Jul 20 03:06:48 PDT 2025


在 2025/7/19 18:53, Dmitry Baryshkov 写道:

> On Fri, Jul 18, 2025 at 02:26:17PM +0800, Chaoyi Chen wrote:
>> From: Chaoyi Chen <chaoyi.chen at rock-chips.com>
>>
>> This patch add support for get PHY lane info and handle HPD state
>> without help of extcon.
>>
>> There is no extcon needed if the Type-C controller is present. In this
>> case, cdn_dp_hpd_notify() will handle HPD event from USB/DP combo PHY,
>> and the lane info can be get from PHY instead of extcon.
> The DP AltMode driver will send drm_connector_oob_hotplug_event() to the
> DRM connector associated with the USB-C connector fwnode. However your
> DP connector will have fwnode set to the DP controller, if I'm not
> mistaken. So I doubt that HPD events are going to be delivered
> correctly.

Yes, that's exactly the case for the DP Altmode driver! I've thought of a few approaches, but none of them are elegant. Now it relying on the PHY driver to call the drm_connector_oob_hotplug_event(). You'll find the relevant code in the PHY driver.


>
>> The extcon device should still be supported if Type-C controller is
>> not present.
>>
>> Signed-off-by: Chaoyi Chen <chaoyi.chen at rock-chips.com>
>> ---
>>
>> Changes in v2:
>> - Ignore duplicate HPD events.
>>
>>   drivers/gpu/drm/rockchip/cdn-dp-core.c | 37 ++++++++++++++++++++------
>>   1 file changed, 29 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c
>> index 24f6b3879f4b..b574b059b58d 100644
>> --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c
>> +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c
>> @@ -156,6 +156,9 @@ static int cdn_dp_get_port_lanes(struct cdn_dp_port *port)
>>   	int dptx;
>>   	u8 lanes;
>>   
>> +	if (!edev)
>> +		return phy_get_bus_width(port->phy);
>> +
>>   	dptx = extcon_get_state(edev, EXTCON_DISP_DP);
>>   	if (dptx > 0) {
>>   		extcon_get_property(edev, EXTCON_DISP_DP,
>> @@ -219,7 +222,7 @@ static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)
>>   	 * some docks need more time to power up.
>>   	 */
>>   	while (time_before(jiffies, timeout)) {
>> -		if (!extcon_get_state(port->extcon, EXTCON_DISP_DP))
>> +		if (port->extcon && !extcon_get_state(port->extcon, EXTCON_DISP_DP))
>>   			return false;
>>   
>>   		if (!cdn_dp_get_sink_count(dp, &sink_count))
>> @@ -385,11 +388,14 @@ static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
>>   		goto err_power_on;
>>   	}
>>   
>> -	ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
>> -				  EXTCON_PROP_USB_TYPEC_POLARITY, &property);
>> -	if (ret) {
>> -		DRM_DEV_ERROR(dp->dev, "get property failed\n");
>> -		goto err_power_on;
>> +	property.intval = 0;
>> +	if (port->extcon) {
>> +		ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
>> +					  EXTCON_PROP_USB_TYPEC_POLARITY, &property);
>> +		if (ret) {
>> +			DRM_DEV_ERROR(dp->dev, "get property failed\n");
>> +			goto err_power_on;
>> +		}
>>   	}
>>   
>>   	port->lanes = cdn_dp_get_port_lanes(port);
>> @@ -821,6 +827,17 @@ static int cdn_dp_audio_mute_stream(struct drm_connector *connector,
>>   	return ret;
>>   }
>>   
>> +static void cdn_dp_hpd_notify(struct drm_bridge *bridge,
>> +			      enum drm_connector_status status)
>> +{
>> +	struct cdn_dp_device *dp = bridge_to_dp(bridge);
>> +	enum drm_connector_status last_status =
>> +		dp->connected ? connector_status_connected : connector_status_disconnected;
>> +
>> +	if (last_status != status)
>> +		schedule_work(&dp->event_work);
>> +}
>> +
>>   static const struct drm_bridge_funcs cdn_dp_bridge_funcs = {
>>   	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
>>   	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
>> @@ -831,6 +848,7 @@ static const struct drm_bridge_funcs cdn_dp_bridge_funcs = {
>>   	.atomic_disable = cdn_dp_bridge_atomic_disable,
>>   	.mode_valid = cdn_dp_bridge_mode_valid,
>>   	.mode_set = cdn_dp_bridge_mode_set,
>> +	.hpd_notify = cdn_dp_hpd_notify,
>>   
>>   	.dp_audio_prepare = cdn_dp_audio_prepare,
>>   	.dp_audio_mute_stream = cdn_dp_audio_mute_stream,
>> @@ -1028,6 +1046,9 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
>>   	for (i = 0; i < dp->ports; i++) {
>>   		port = dp->port[i];
>>   
>> +		if (!port->extcon)
>> +			continue;
>> +
>>   		port->event_nb.notifier_call = cdn_dp_pd_event;
>>   		ret = devm_extcon_register_notifier(dp->dev, port->extcon,
>>   						    EXTCON_DISP_DP,
>> @@ -1120,14 +1141,14 @@ static int cdn_dp_probe(struct platform_device *pdev)
>>   		    PTR_ERR(phy) == -EPROBE_DEFER)
>>   			return -EPROBE_DEFER;
>>   
>> -		if (IS_ERR(extcon) || IS_ERR(phy))
>> +		if (IS_ERR(phy) || PTR_ERR(extcon) != -ENODEV)
>>   			continue;
>>   
>>   		port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
>>   		if (!port)
>>   			return -ENOMEM;
>>   
>> -		port->extcon = extcon;
>> +		port->extcon = IS_ERR(extcon) ? NULL : extcon;
>>   		port->phy = phy;
>>   		port->dp = dp;
>>   		port->id = i;
>> -- 
>> 2.49.0
>>



More information about the Linux-rockchip mailing list