diff mbox series

[v4,08/12] phy: rockchip: samsung-hdptx: Provide config params validation support

Message ID 20250304-phy-sam-hdptx-bpc-v4-8-8657847c13f7@collabora.com (mailing list archive)
State New
Headers show
Series phy: rockchip: samsung-hdptx: Support high color depth management | expand

Commit Message

Cristian Ciocaltea March 4, 2025, 1:44 a.m. UTC
Implement the phy_ops.validate() callback to allow checking the PHY
configuration parameters without actually applying them.

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
 drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Maxime Ripard March 4, 2025, 8:18 a.m. UTC | #1
On Tue, Mar 04, 2025 at 03:44:07AM +0200, Cristian Ciocaltea wrote:
> Implement the phy_ops.validate() callback to allow checking the PHY
> configuration parameters without actually applying them.
> 
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> ---
>  drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
> index 7e1d1c10758249aa5bbddbdaae0108bba04f30df..47db1395051f5d900197871694bab90ca4d6e38e 100644
> --- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
> +++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
> @@ -1482,6 +1482,17 @@ static int rk_hdptx_phy_verify_hdmi_config(struct rk_hdptx_phy *hdptx,
>  	if (!hdmi->tmds_char_rate || hdmi->tmds_char_rate > HDMI20_MAX_RATE)
>  		return -EINVAL;
>  
> +	u32 bit_rate = hdmi->tmds_char_rate / 100;
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++)
> +		if (bit_rate == ropll_tmds_cfg[i].bit_rate)
> +			break;
> +
> +	if (i == ARRAY_SIZE(ropll_tmds_cfg) &&
> +	    !rk_hdptx_phy_clk_pll_calc(bit_rate, NULL))
> +		return -EINVAL;

What are you calling bit_rate here? If anything, I'd expect the bit_rate
to be a multiple of the char rate, not a divisor.

Maxime
Cristian Ciocaltea March 4, 2025, 12:20 p.m. UTC | #2
On 3/4/25 10:18 AM, Maxime Ripard wrote:
> On Tue, Mar 04, 2025 at 03:44:07AM +0200, Cristian Ciocaltea wrote:
>> Implement the phy_ops.validate() callback to allow checking the PHY
>> configuration parameters without actually applying them.
>>
>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
>> ---
>>  drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c | 23 +++++++++++++++++++++++
>>  1 file changed, 23 insertions(+)
>>
>> diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
>> index 7e1d1c10758249aa5bbddbdaae0108bba04f30df..47db1395051f5d900197871694bab90ca4d6e38e 100644
>> --- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
>> +++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
>> @@ -1482,6 +1482,17 @@ static int rk_hdptx_phy_verify_hdmi_config(struct rk_hdptx_phy *hdptx,
>>  	if (!hdmi->tmds_char_rate || hdmi->tmds_char_rate > HDMI20_MAX_RATE)
>>  		return -EINVAL;
>>  
>> +	u32 bit_rate = hdmi->tmds_char_rate / 100;
>> +	int i;
>> +
>> +	for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++)
>> +		if (bit_rate == ropll_tmds_cfg[i].bit_rate)
>> +			break;
>> +
>> +	if (i == ARRAY_SIZE(ropll_tmds_cfg) &&
>> +	    !rk_hdptx_phy_clk_pll_calc(bit_rate, NULL))
>> +		return -EINVAL;
> 
> What are you calling bit_rate here? If anything, I'd expect the bit_rate
> to be a multiple of the char rate, not a divisor.

This is just an unfortunate naming of the search key in struct
ropll_config, inherited from downstream, given in hHz rather than Hz.
I've already renamed it in the last patch, while getting rid of those
annoying unit conversions.
diff mbox series

Patch

diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
index 7e1d1c10758249aa5bbddbdaae0108bba04f30df..47db1395051f5d900197871694bab90ca4d6e38e 100644
--- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
+++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
@@ -1482,6 +1482,17 @@  static int rk_hdptx_phy_verify_hdmi_config(struct rk_hdptx_phy *hdptx,
 	if (!hdmi->tmds_char_rate || hdmi->tmds_char_rate > HDMI20_MAX_RATE)
 		return -EINVAL;
 
+	u32 bit_rate = hdmi->tmds_char_rate / 100;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++)
+		if (bit_rate == ropll_tmds_cfg[i].bit_rate)
+			break;
+
+	if (i == ARRAY_SIZE(ropll_tmds_cfg) &&
+	    !rk_hdptx_phy_clk_pll_calc(bit_rate, NULL))
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -1789,10 +1800,22 @@  static int rk_hdptx_phy_configure(struct phy *phy, union phy_configure_opts *opt
 	return 0;
 }
 
+static int rk_hdptx_phy_validate(struct phy *phy, enum phy_mode mode,
+				 int submode, union phy_configure_opts *opts)
+{
+	struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy);
+
+	if (mode != PHY_MODE_DP)
+		return rk_hdptx_phy_verify_hdmi_config(hdptx, &opts->hdmi);
+
+	return rk_hdptx_phy_verify_dp_config(hdptx, &opts->dp);
+}
+
 static const struct phy_ops rk_hdptx_phy_ops = {
 	.power_on  = rk_hdptx_phy_power_on,
 	.power_off = rk_hdptx_phy_power_off,
 	.configure = rk_hdptx_phy_configure,
+	.validate  = rk_hdptx_phy_validate,
 	.owner	   = THIS_MODULE,
 };