.. | .. |
---|
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> |
---|
.. | .. |
---|
484 | 485 | |
---|
485 | 486 | static inline int miphy28lp_wait_compensation(struct miphy28lp_phy *miphy_phy) |
---|
486 | 487 | { |
---|
487 | | - unsigned long finish = jiffies + 5 * HZ; |
---|
488 | 488 | u8 val; |
---|
489 | 489 | |
---|
490 | 490 | /* 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); |
---|
500 | 493 | } |
---|
501 | 494 | |
---|
502 | 495 | |
---|
.. | .. |
---|
805 | 798 | |
---|
806 | 799 | static inline int miphy_is_ready(struct miphy28lp_phy *miphy_phy) |
---|
807 | 800 | { |
---|
808 | | - unsigned long finish = jiffies + 5 * HZ; |
---|
809 | 801 | u8 mask = HFC_PLL | HFC_RDY; |
---|
810 | 802 | u8 val; |
---|
811 | 803 | |
---|
.. | .. |
---|
816 | 808 | if (miphy_phy->type == PHY_TYPE_SATA) |
---|
817 | 809 | mask |= PHY_RDY; |
---|
818 | 810 | |
---|
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); |
---|
828 | 814 | } |
---|
829 | 815 | |
---|
830 | 816 | static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy) |
---|
831 | 817 | { |
---|
832 | 818 | struct miphy28lp_dev *miphy_dev = miphy_phy->phydev; |
---|
833 | | - unsigned long finish = jiffies + 5 * HZ; |
---|
834 | 819 | u32 val; |
---|
835 | 820 | |
---|
836 | 821 | if (!miphy_phy->osc_rdy) |
---|
.. | .. |
---|
839 | 824 | if (!miphy_phy->syscfg_reg[SYSCFG_STATUS]) |
---|
840 | 825 | return -EINVAL; |
---|
841 | 826 | |
---|
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); |
---|
853 | 831 | } |
---|
854 | 832 | |
---|
855 | 833 | static int miphy28lp_get_resource_byname(struct device_node *child, |
---|