Skip to contentSkip to conversation

phy: mediatek: Avoid floating point constants

PATCH In review Thierry Reding 5 participants 5 messages Apr 19, 2023 – May 17, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: mediatek: Avoid floating point constants

From: Thierry Reding <[email protected]>

When building with old versions of GCC (6.3 in this case), the compiler stumbles over the floating point constants in this driver:

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c: In function ‘mtk_hdmi_pll_prepare’:
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:331:23: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
^~~~~~~~~~~~~~~~~~~~
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code

Fix this by switching to the KILO macro instead and multiplying the constants by 1000 to get rid of the floating point.

Fixes 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195")
---
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +4 -4
index abfc077fb0a8..b10af26cad2f 100644
@@ -239,9 +239,9 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw,
 		txposdiv = 8;
 	else if (tmds_clk >= 54 * MEGA && tmds_clk < 148.35 * MEGA)
 		txposdiv = 4;
-	else if (tmds_clk >= 148.35 * MEGA && tmds_clk < 296.7 * MEGA)
+	else if (tmds_clk >= 148350 * KILO && tmds_clk < 296700 * KILO)
 		txposdiv = 2;
-	else if (tmds_clk >= 296.7 * MEGA && tmds_clk <= 594 * MEGA)
+	else if (tmds_clk >= 296700 * KILO && tmds_clk <= 594 * MEGA)
 		txposdiv = 1;
 	else
 		return -EINVAL;
@@ -328,12 +328,12 @@ static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw)
 		clk_channel_bias = 0x34; /* 20mA */
 		impedance_en = 0xf;
 		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {
+	} else if (pixel_clk >= 74175 * KILO && pixel_clk <= 300 * MEGA) {
 		data_channel_bias = 0x34; /* 20mA */
 		clk_channel_bias = 0x2c; /* 16mA */
 		impedance_en = 0xf;
 		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74.175 * MEGA) {
+	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74175 * KILO) {
 		data_channel_bias = 0x14; /* 10mA */
 		clk_channel_bias = 0x14; /* 10mA */
 		impedance_en = 0x0;
Signature · 7 lines
2.40.0


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer Reviewed-by on v1 1/1
#1 lore raw

Il 19/04/23 14:21, Thierry Reding ha scritto:

Quoted 14 lines

From: Thierry Reding <[email protected]>

When building with old versions of GCC (6.3 in this case), the compiler stumbles over the floating point constants in this driver:

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c: In function ‘mtk_hdmi_pll_prepare’:
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:331:23: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
^~~~~~~~~~~~~~~~~~~~
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code

Quoted 6 lines

Fix this by switching to the KILO macro instead and multiplying the constants by 1000 to get rid of the floating point.

Fixes 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195")
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thierry Reding
Quoted 56 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When building with old versions of GCC (6.3 in this case), the compiler stumbles over the floating point constants in this driver:

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c: In function ‘mtk_hdmi_pll_prepare’:
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:331:23: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
^~~~~~~~~~~~~~~~~~~~
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code

Fix this by switching to the KILO macro instead and multiplying the constants by 1000 to get rid of the floating point.

Fixes 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195")

---
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +4 -5
index abfc077fb0a8..b10af26cad2f 100644
@@ -239,9 +239,9 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw,
 		txposdiv = 8;
 	else if (tmds_clk >= 54 * MEGA && tmds_clk < 148.35 * MEGA)
 		txposdiv = 4;
-	else if (tmds_clk >= 148.35 * MEGA && tmds_clk < 296.7 * MEGA)
+	else if (tmds_clk >= 148350 * KILO && tmds_clk < 296700 * KILO)
 		txposdiv = 2;
-	else if (tmds_clk >= 296.7 * MEGA && tmds_clk <= 594 * MEGA)
+	else if (tmds_clk >= 296700 * KILO && tmds_clk <= 594 * MEGA)
 		txposdiv = 1;
 	else
 		return -EINVAL;
@@ -328,12 +328,12 @@ static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw)
 		clk_channel_bias = 0x34; /* 20mA */
 		impedance_en = 0xf;
 		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {
+	} else if (pixel_clk >= 74175 * KILO && pixel_clk <= 300 * MEGA) {
 		data_channel_bias = 0x34; /* 20mA */
 		clk_channel_bias = 0x2c; /* 16mA */
 		impedance_en = 0xf;
 		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74.175 * MEGA) {
+	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74175 * KILO) {
 		data_channel_bias = 0x14; /* 10mA */
 		clk_channel_bias = 0x14; /* 10mA */
 		impedance_en = 0x0;
--
Quoted 2 lines

2.40.0

Thx for the fix!

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Thierry Reding

Hi Vinod,

Quoted 45 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When building with old versions of GCC (6.3 in this case), the compiler stumbles over the floating point constants in this driver:

: In function ‘mtk_hdmi_pll_prepare’:
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:331:23: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
^~~~~~~~~~~~~~~~~~~~
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code

Fix this by switching to the KILO macro instead and multiplying the constants by 1000 to get rid of the floating point.

Fixes 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195")
---
  drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +2 -3
index abfc077fb0a8..b10af26cad2f 100644
@@ -239,9 +239,9 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw,
  		txposdiv = 8;
  	else if (tmds_clk >= 54 * MEGA && tmds_clk < 148.35 * MEGA)
  		txposdiv = 4;
-	else if (tmds_clk >= 148.35 * MEGA && tmds_clk < 296.7 * MEGA)
+	else if (tmds_clk >= 148350 * KILO && tmds_clk < 296700 * KILO)
  		txposdiv = 2;
-	else if (tmds_clk >= 296.7 * MEGA && tmds_clk <= 594 * MEGA)
+	else if (tmds_clk >= 296700 * KILO && tmds_clk <= 594 * MEGA)
  		txposdiv = 1;
  	else
  		return -EINVAL;
@@ -328,12 +328,12 @@ static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw)
  		clk_channel_bias = 0x34; /* 20mA */
  		impedance_en = 0xf;
  		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw) · line 339

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +2 -1
+	} else if (pixel_clk >= 74175 * KILO && pixel_clk <= 300 * MEGA) {
  		data_channel_bias = 0x34; /* 20mA */
  		clk_channel_bias = 0x2c; /* 16mA */
  		impedance_en = 0xf;
  		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74.175 * MEGA) {
+	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74175 * KILO) {
  		data_channel_bias = 0x14; /* 10mA */
  		clk_channel_bias = 0x14; /* 10mA */
  		impedance_en = 0x0;

This is breaking kernel compilation with older compilers such as GCC7. This is now in the mainline and older compilers cannot build the kernel with this driver enabled. The kernel docs say the min version supported is GCC 5.1 currently.

Can we get this merged as a fix for v6.4?

Thanks
Jon

Signature · 1 line
nvpublic
maintainer
#4 lore raw
Quoted 65 lines · Jon Hunter

Hi Vinod,

Quoted 45 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When building with old versions of GCC (6.3 in this case), the compiler stumbles over the floating point constants in this driver:

: In function ‘mtk_hdmi_pll_prepare’:
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:331:23: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code
static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
^~~~~~~~~~~~~~~~~~~~
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c:361:12: error: ‘-mgeneral-regs-only’ is incompatible with floating-point code

Fix this by switching to the KILO macro instead and multiplying the constants by 1000 to get rid of the floating point.

Fixes 45810d486bb4 ("phy: mediatek: add support for phy-mtk-hdmi-mt8195")
---
  drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +2 -3
index abfc077fb0a8..b10af26cad2f 100644
@@ -239,9 +239,9 @@ static int mtk_hdmi_pll_calc(struct mtk_hdmi_phy *hdmi_phy, struct clk_hw *hw,
  		txposdiv = 8;
  	else if (tmds_clk >= 54 * MEGA && tmds_clk < 148.35 * MEGA)
  		txposdiv = 4;
-	else if (tmds_clk >= 148.35 * MEGA && tmds_clk < 296.7 * MEGA)
+	else if (tmds_clk >= 148350 * KILO && tmds_clk < 296700 * KILO)
  		txposdiv = 2;
-	else if (tmds_clk >= 296.7 * MEGA && tmds_clk <= 594 * MEGA)
+	else if (tmds_clk >= 296700 * KILO && tmds_clk <= 594 * MEGA)
  		txposdiv = 1;
  	else
  		return -EINVAL;
@@ -328,12 +328,12 @@ static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw)
  		clk_channel_bias = 0x34; /* 20mA */
  		impedance_en = 0xf;
  		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 74.175 * MEGA && pixel_clk <= 300 * MEGA) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw) · line 339

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c +2 -1
+	} else if (pixel_clk >= 74175 * KILO && pixel_clk <= 300 * MEGA) {
  		data_channel_bias = 0x34; /* 20mA */
  		clk_channel_bias = 0x2c; /* 16mA */
  		impedance_en = 0xf;
  		impedance = 0x36; /* 100ohm */
-	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74.175 * MEGA) {
+	} else if (pixel_clk >= 27 * MEGA && pixel_clk < 74175 * KILO) {
  		data_channel_bias = 0x14; /* 10mA */
  		clk_channel_bias = 0x14; /* 10mA */
  		impedance_en = 0x0;

This is breaking kernel compilation with older compilers such as GCC7. This is now in the mainline and older compilers cannot build the kernel with this driver enabled. The kernel docs say the min version supported is GCC 5.1 currently.

Quoted 1 line

Can we get this merged as a fix for v6.4?

Sorry I missed this one but I have already applied 03262a3f5b5b ("phy:
mediatek: rework the floating point comparisons to fixed point") and this is in linux-next and should be hopefully in Linus's tree in next rc

Thanks

Signature · 1 line
~Vinod