Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: st: miphy28lp: use _poll_timeout functions for waits

This commit introduces _poll_timeout functions usage instead of
wait loops waiting for a status bit.

Signed-off-by: Alain Volmat <avolmat@me.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Link: https://lore.kernel.org/r/20230210224309.98452-1-avolmat@me.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Alain Volmat and committed by
Vinod Koul
e3be4dd2 8b798761

+10 -32
+10 -32
drivers/phy/st/phy-miphy28lp.c
··· 9 9 10 10 #include <linux/platform_device.h> 11 11 #include <linux/io.h> 12 + #include <linux/iopoll.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/module.h> 14 15 #include <linux/of.h> ··· 485 484 486 485 static inline int miphy28lp_wait_compensation(struct miphy28lp_phy *miphy_phy) 487 486 { 488 - unsigned long finish = jiffies + 5 * HZ; 489 487 u8 val; 490 488 491 489 /* Waiting for Compensation to complete */ 492 - do { 493 - val = readb_relaxed(miphy_phy->base + MIPHY_COMP_FSM_6); 494 - 495 - if (time_after_eq(jiffies, finish)) 496 - return -EBUSY; 497 - cpu_relax(); 498 - } while (!(val & COMP_DONE)); 499 - 500 - return 0; 490 + return readb_relaxed_poll_timeout(miphy_phy->base + MIPHY_COMP_FSM_6, 491 + val, val & COMP_DONE, 1, 5 * USEC_PER_SEC); 501 492 } 502 493 503 494 ··· 798 805 799 806 static inline int miphy_is_ready(struct miphy28lp_phy *miphy_phy) 800 807 { 801 - unsigned long finish = jiffies + 5 * HZ; 802 808 u8 mask = HFC_PLL | HFC_RDY; 803 809 u8 val; 804 810 ··· 808 816 if (miphy_phy->type == PHY_TYPE_SATA) 809 817 mask |= PHY_RDY; 810 818 811 - do { 812 - val = readb_relaxed(miphy_phy->base + MIPHY_STATUS_1); 813 - if ((val & mask) != mask) 814 - cpu_relax(); 815 - else 816 - return 0; 817 - } while (!time_after_eq(jiffies, finish)); 818 - 819 - return -EBUSY; 819 + return readb_relaxed_poll_timeout(miphy_phy->base + MIPHY_STATUS_1, 820 + val, (val & mask) == mask, 1, 821 + 5 * USEC_PER_SEC); 820 822 } 821 823 822 824 static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy) 823 825 { 824 826 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev; 825 - unsigned long finish = jiffies + 5 * HZ; 826 827 u32 val; 827 828 828 829 if (!miphy_phy->osc_rdy) ··· 824 839 if (!miphy_phy->syscfg_reg[SYSCFG_STATUS]) 825 840 return -EINVAL; 826 841 827 - do { 828 - regmap_read(miphy_dev->regmap, 829 - miphy_phy->syscfg_reg[SYSCFG_STATUS], &val); 830 - 831 - if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY) 832 - cpu_relax(); 833 - else 834 - return 0; 835 - } while (!time_after_eq(jiffies, finish)); 836 - 837 - return -EBUSY; 842 + return regmap_read_poll_timeout(miphy_dev->regmap, 843 + miphy_phy->syscfg_reg[SYSCFG_STATUS], 844 + val, val & MIPHY_OSC_RDY, 1, 845 + 5 * USEC_PER_SEC); 838 846 } 839 847 840 848 static int miphy28lp_get_resource_byname(struct device_node *child,