Skip to content

Commit 0edf9d2

Browse files
cristiccvinodkoul
authored andcommitted
phy: rockchip: samsung-hdptx: Avoid Hz<->hHz unit conversion overhead
The ropll_tmds_cfg table used to identify the configuration params for the supported rates expects the search key, i.e. bit_rate member of struct ropll_config, to be provided in hHz rather than Hz (1 hHz = 100 Hz). This requires multiple conversions between these units being performed at runtime. Improve implementation clarity and efficiency by consistently using the Hz unit throughout driver's internal data structures and functions. Also rename the rather misleading struct member. Signed-off-by: Cristian Ciocaltea <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent bacf2fe commit 0edf9d2

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ enum dp_link_rate {
330330
};
331331

332332
struct ropll_config {
333-
u32 bit_rate;
333+
unsigned long long rate;
334334
u8 pms_mdiv;
335335
u8 pms_mdiv_afc;
336336
u8 pms_pdiv;
@@ -410,45 +410,45 @@ struct rk_hdptx_phy {
410410
};
411411

412412
static const struct ropll_config ropll_tmds_cfg[] = {
413-
{ 5940000, 124, 124, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
413+
{ 594000000ULL, 124, 124, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
414414
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
415-
{ 3712500, 155, 155, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
415+
{ 371250000ULL, 155, 155, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
416416
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
417-
{ 2970000, 124, 124, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
417+
{ 297000000ULL, 124, 124, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
418418
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
419-
{ 1620000, 135, 135, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 4, 0, 3, 5, 5, 0x10,
419+
{ 162000000ULL, 135, 135, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 4, 0, 3, 5, 5, 0x10,
420420
1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
421-
{ 1856250, 155, 155, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
421+
{ 185625000ULL, 155, 155, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
422422
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
423-
{ 1540000, 193, 193, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 193, 1, 32, 2, 1,
423+
{ 154000000ULL, 193, 193, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 193, 1, 32, 2, 1,
424424
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
425-
{ 1485000, 0x7b, 0x7b, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 0, 3, 5, 5,
425+
{ 148500000ULL, 0x7b, 0x7b, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 0, 3, 5, 5,
426426
0x10, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
427-
{ 1462500, 122, 122, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 244, 1, 16, 2, 1, 1,
427+
{ 146250000ULL, 122, 122, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 244, 1, 16, 2, 1, 1,
428428
1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
429-
{ 1190000, 149, 149, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 149, 1, 16, 2, 1, 1,
429+
{ 119000000ULL, 149, 149, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 149, 1, 16, 2, 1, 1,
430430
1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
431-
{ 1065000, 89, 89, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 89, 1, 16, 1, 0, 1,
431+
{ 106500000ULL, 89, 89, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 89, 1, 16, 1, 0, 1,
432432
1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
433-
{ 1080000, 135, 135, 1, 1, 5, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
433+
{ 108000000ULL, 135, 135, 1, 1, 5, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
434434
0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
435-
{ 855000, 214, 214, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 214, 1, 16, 2, 1,
435+
{ 85500000ULL, 214, 214, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 214, 1, 16, 2, 1,
436436
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
437-
{ 835000, 105, 105, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 42, 1, 16, 1, 0,
437+
{ 83500000ULL, 105, 105, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 42, 1, 16, 1, 0,
438438
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
439-
{ 928125, 155, 155, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
439+
{ 92812500ULL, 155, 155, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
440440
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
441-
{ 742500, 124, 124, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
441+
{ 74250000ULL, 124, 124, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
442442
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
443-
{ 650000, 162, 162, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 54, 0, 16, 4, 1,
443+
{ 65000000ULL, 162, 162, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 54, 0, 16, 4, 1,
444444
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
445-
{ 337500, 0x70, 0x70, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 0x2, 0, 0x01, 5,
445+
{ 33750000ULL, 0x70, 0x70, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 0x2, 0, 0x01, 5,
446446
1, 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
447-
{ 400000, 100, 100, 1, 1, 11, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
447+
{ 40000000ULL, 100, 100, 1, 1, 11, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
448448
0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
449-
{ 270000, 0x5a, 0x5a, 1, 1, 0xf, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
449+
{ 27000000ULL, 0x5a, 0x5a, 1, 1, 0xf, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,
450450
0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
451-
{ 251750, 84, 84, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 168, 1, 16, 4, 1, 1,
451+
{ 25175000ULL, 84, 84, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 168, 1, 16, 4, 1, 1,
452452
1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
453453
};
454454

@@ -894,10 +894,10 @@ static void rk_hdptx_phy_disable(struct rk_hdptx_phy *hdptx)
894894
regmap_write(hdptx->grf, GRF_HDPTX_CON0, val);
895895
}
896896

897-
static bool rk_hdptx_phy_clk_pll_calc(unsigned int data_rate,
897+
static bool rk_hdptx_phy_clk_pll_calc(unsigned long long rate,
898898
struct ropll_config *cfg)
899899
{
900-
const unsigned int fout = data_rate / 2, fref = 24000;
900+
const unsigned int fout = div_u64(rate, 200), fref = 24000;
901901
unsigned long k = 0, lc, k_sub, lc_sub;
902902
unsigned int fvco, sdc;
903903
u32 mdiv, sdiv, n = 8;
@@ -967,14 +967,14 @@ static bool rk_hdptx_phy_clk_pll_calc(unsigned int data_rate,
967967
}
968968

969969
static int rk_hdptx_ropll_tmds_cmn_config(struct rk_hdptx_phy *hdptx,
970-
unsigned int rate)
970+
unsigned long long rate)
971971
{
972972
const struct ropll_config *cfg = NULL;
973973
struct ropll_config rc = {0};
974974
int ret, i;
975975

976976
for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++)
977-
if (rate == ropll_tmds_cfg[i].bit_rate) {
977+
if (rate == ropll_tmds_cfg[i].rate) {
978978
cfg = &ropll_tmds_cfg[i];
979979
break;
980980
}
@@ -988,8 +988,8 @@ static int rk_hdptx_ropll_tmds_cmn_config(struct rk_hdptx_phy *hdptx,
988988
}
989989
}
990990

991-
dev_dbg(hdptx->dev, "mdiv=%u, sdiv=%u, sdm_en=%u, k_sign=%u, k=%u, lc=%u\n",
992-
cfg->pms_mdiv, cfg->pms_sdiv + 1, cfg->sdm_en,
991+
dev_dbg(hdptx->dev, "%s rate=%llu mdiv=%u sdiv=%u sdm_en=%u k_sign=%u k=%u lc=%u\n",
992+
__func__, rate, cfg->pms_mdiv, cfg->pms_sdiv + 1, cfg->sdm_en,
993993
cfg->sdm_num_sign, cfg->sdm_num, cfg->sdm_deno);
994994

995995
rk_hdptx_pre_power_up(hdptx);
@@ -1028,19 +1028,19 @@ static int rk_hdptx_ropll_tmds_cmn_config(struct rk_hdptx_phy *hdptx,
10281028

10291029
ret = rk_hdptx_post_enable_pll(hdptx);
10301030
if (!ret)
1031-
hdptx->rate = rate * 100;
1031+
hdptx->rate = rate;
10321032

10331033
return ret;
10341034
}
10351035

10361036
static int rk_hdptx_ropll_tmds_mode_config(struct rk_hdptx_phy *hdptx,
1037-
unsigned int rate)
1037+
unsigned long long rate)
10381038
{
10391039
rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_common_sb_init_seq);
10401040

10411041
regmap_write(hdptx->regmap, LNTOP_REG(0200), 0x06);
10421042

1043-
if (rate > HDMI14_MAX_RATE / 100) {
1043+
if (rate > HDMI14_MAX_RATE) {
10441044
/* For 1/40 bitrate clk */
10451045
rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_tmds_lntop_highbr_seq);
10461046
} else {
@@ -1093,7 +1093,7 @@ static void rk_hdptx_dp_reset(struct rk_hdptx_phy *hdptx)
10931093
}
10941094

10951095
static int rk_hdptx_phy_consumer_get(struct rk_hdptx_phy *hdptx,
1096-
unsigned int rate)
1096+
unsigned long long rate)
10971097
{
10981098
enum phy_mode mode = phy_get_mode(hdptx->phy);
10991099
u32 status;
@@ -1411,19 +1411,19 @@ static int rk_hdptx_dp_aux_init(struct rk_hdptx_phy *hdptx)
14111411
static int rk_hdptx_phy_power_on(struct phy *phy)
14121412
{
14131413
struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy);
1414-
int bus_width = phy_get_bus_width(hdptx->phy);
14151414
enum phy_mode mode = phy_get_mode(phy);
1415+
unsigned long long rate;
14161416
int ret, lane;
14171417

14181418
/*
14191419
* FIXME: Temporary workaround to pass pixel_clk_rate
14201420
* from the HDMI bridge driver until phy_configure_opts_hdmi
14211421
* becomes available in the PHY API.
14221422
*/
1423-
unsigned int rate = bus_width & 0xfffffff;
1423+
rate = phy_get_bus_width(hdptx->phy) & 0xfffffff;
1424+
rate *= 100;
14241425

1425-
dev_dbg(hdptx->dev, "%s bus_width=%x rate=%u\n",
1426-
__func__, bus_width, rate);
1426+
dev_dbg(hdptx->dev, "%s rate=%llu\n", __func__, rate);
14271427

14281428
ret = rk_hdptx_phy_consumer_get(hdptx, rate);
14291429
if (ret)
@@ -1785,7 +1785,7 @@ static int rk_hdptx_phy_clk_prepare(struct clk_hw *hw)
17851785
{
17861786
struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw);
17871787

1788-
return rk_hdptx_phy_consumer_get(hdptx, hdptx->rate / 100);
1788+
return rk_hdptx_phy_consumer_get(hdptx, hdptx->rate);
17891789
}
17901790

17911791
static void rk_hdptx_phy_clk_unprepare(struct clk_hw *hw)
@@ -1806,18 +1806,17 @@ static unsigned long rk_hdptx_phy_clk_recalc_rate(struct clk_hw *hw,
18061806
static long rk_hdptx_phy_clk_round_rate(struct clk_hw *hw, unsigned long rate,
18071807
unsigned long *parent_rate)
18081808
{
1809-
u32 bit_rate = rate / 100;
18101809
int i;
18111810

18121811
if (rate > HDMI20_MAX_RATE)
18131812
return rate;
18141813

18151814
for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++)
1816-
if (bit_rate == ropll_tmds_cfg[i].bit_rate)
1815+
if (rate == ropll_tmds_cfg[i].rate)
18171816
break;
18181817

18191818
if (i == ARRAY_SIZE(ropll_tmds_cfg) &&
1820-
!rk_hdptx_phy_clk_pll_calc(bit_rate, NULL))
1819+
!rk_hdptx_phy_clk_pll_calc(rate, NULL))
18211820
return -EINVAL;
18221821

18231822
return rate;
@@ -1828,7 +1827,7 @@ static int rk_hdptx_phy_clk_set_rate(struct clk_hw *hw, unsigned long rate,
18281827
{
18291828
struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw);
18301829

1831-
return rk_hdptx_ropll_tmds_cmn_config(hdptx, rate / 100);
1830+
return rk_hdptx_ropll_tmds_cmn_config(hdptx, rate);
18321831
}
18331832

18341833
static const struct clk_ops hdptx_phy_clk_ops = {

0 commit comments

Comments
 (0)