hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/phy/st/phy-miphy28lp.c
....@@ -9,6 +9,7 @@
99
1010 #include <linux/platform_device.h>
1111 #include <linux/io.h>
12
+#include <linux/iopoll.h>
1213 #include <linux/kernel.h>
1314 #include <linux/module.h>
1415 #include <linux/of.h>
....@@ -484,19 +485,11 @@
484485
485486 static inline int miphy28lp_wait_compensation(struct miphy28lp_phy *miphy_phy)
486487 {
487
- unsigned long finish = jiffies + 5 * HZ;
488488 u8 val;
489489
490490 /* Waiting for Compensation to complete */
491
- do {
492
- val = readb_relaxed(miphy_phy->base + MIPHY_COMP_FSM_6);
493
-
494
- if (time_after_eq(jiffies, finish))
495
- return -EBUSY;
496
- cpu_relax();
497
- } while (!(val & COMP_DONE));
498
-
499
- return 0;
491
+ return readb_relaxed_poll_timeout(miphy_phy->base + MIPHY_COMP_FSM_6,
492
+ val, val & COMP_DONE, 1, 5 * USEC_PER_SEC);
500493 }
501494
502495
....@@ -805,7 +798,6 @@
805798
806799 static inline int miphy_is_ready(struct miphy28lp_phy *miphy_phy)
807800 {
808
- unsigned long finish = jiffies + 5 * HZ;
809801 u8 mask = HFC_PLL | HFC_RDY;
810802 u8 val;
811803
....@@ -816,21 +808,14 @@
816808 if (miphy_phy->type == PHY_TYPE_SATA)
817809 mask |= PHY_RDY;
818810
819
- do {
820
- val = readb_relaxed(miphy_phy->base + MIPHY_STATUS_1);
821
- if ((val & mask) != mask)
822
- cpu_relax();
823
- else
824
- return 0;
825
- } while (!time_after_eq(jiffies, finish));
826
-
827
- return -EBUSY;
811
+ return readb_relaxed_poll_timeout(miphy_phy->base + MIPHY_STATUS_1,
812
+ val, (val & mask) == mask, 1,
813
+ 5 * USEC_PER_SEC);
828814 }
829815
830816 static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
831817 {
832818 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
833
- unsigned long finish = jiffies + 5 * HZ;
834819 u32 val;
835820
836821 if (!miphy_phy->osc_rdy)
....@@ -839,17 +824,10 @@
839824 if (!miphy_phy->syscfg_reg[SYSCFG_STATUS])
840825 return -EINVAL;
841826
842
- do {
843
- regmap_read(miphy_dev->regmap,
844
- miphy_phy->syscfg_reg[SYSCFG_STATUS], &val);
845
-
846
- if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY)
847
- cpu_relax();
848
- else
849
- return 0;
850
- } while (!time_after_eq(jiffies, finish));
851
-
852
- return -EBUSY;
827
+ return regmap_read_poll_timeout(miphy_dev->regmap,
828
+ miphy_phy->syscfg_reg[SYSCFG_STATUS],
829
+ val, val & MIPHY_OSC_RDY, 1,
830
+ 5 * USEC_PER_SEC);
853831 }
854832
855833 static int miphy28lp_get_resource_byname(struct device_node *child,