diff options
Diffstat (limited to 'include/linux/phy.h')
-rw-r--r-- | include/linux/phy.h | 145 |
1 files changed, 130 insertions, 15 deletions
diff --git a/include/linux/phy.h b/include/linux/phy.h index dc82a07cb4fd..5a0c3e53e7c2 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h | |||
@@ -59,6 +59,7 @@ | |||
59 | 59 | ||
60 | #define PHY_HAS_INTERRUPT 0x00000001 | 60 | #define PHY_HAS_INTERRUPT 0x00000001 |
61 | #define PHY_IS_INTERNAL 0x00000002 | 61 | #define PHY_IS_INTERNAL 0x00000002 |
62 | #define PHY_RST_AFTER_CLK_EN 0x00000004 | ||
62 | #define MDIO_DEVICE_IS_PHY 0x80000000 | 63 | #define MDIO_DEVICE_IS_PHY 0x80000000 |
63 | 64 | ||
64 | /* Interface Mode definitions */ | 65 | /* Interface Mode definitions */ |
@@ -468,7 +469,6 @@ struct phy_device { | |||
468 | /* Interrupt and Polling infrastructure */ | 469 | /* Interrupt and Polling infrastructure */ |
469 | struct work_struct phy_queue; | 470 | struct work_struct phy_queue; |
470 | struct delayed_work state_queue; | 471 | struct delayed_work state_queue; |
471 | atomic_t irq_disable; | ||
472 | 472 | ||
473 | struct mutex lock; | 473 | struct mutex lock; |
474 | 474 | ||
@@ -497,19 +497,19 @@ struct phy_device { | |||
497 | * flags: A bitfield defining certain other features this PHY | 497 | * flags: A bitfield defining certain other features this PHY |
498 | * supports (like interrupts) | 498 | * supports (like interrupts) |
499 | * | 499 | * |
500 | * The drivers must implement config_aneg and read_status. All | 500 | * All functions are optional. If config_aneg or read_status |
501 | * other functions are optional. Note that none of these | 501 | * are not implemented, the phy core uses the genphy versions. |
502 | * functions should be called from interrupt time. The goal is | 502 | * Note that none of these functions should be called from |
503 | * for the bus read/write functions to be able to block when the | 503 | * interrupt time. The goal is for the bus read/write functions |
504 | * bus transaction is happening, and be freed up by an interrupt | 504 | * to be able to block when the bus transaction is happening, |
505 | * (The MPC85xx has this ability, though it is not currently | 505 | * and be freed up by an interrupt (The MPC85xx has this ability, |
506 | * supported in the driver). | 506 | * though it is not currently supported in the driver). |
507 | */ | 507 | */ |
508 | struct phy_driver { | 508 | struct phy_driver { |
509 | struct mdio_driver_common mdiodrv; | 509 | struct mdio_driver_common mdiodrv; |
510 | u32 phy_id; | 510 | u32 phy_id; |
511 | char *name; | 511 | char *name; |
512 | unsigned int phy_id_mask; | 512 | u32 phy_id_mask; |
513 | u32 features; | 513 | u32 features; |
514 | u32 flags; | 514 | u32 flags; |
515 | const void *driver_data; | 515 | const void *driver_data; |
@@ -634,6 +634,9 @@ struct phy_driver { | |||
634 | int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum, | 634 | int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum, |
635 | u16 val); | 635 | u16 val); |
636 | 636 | ||
637 | int (*read_page)(struct phy_device *dev); | ||
638 | int (*write_page)(struct phy_device *dev, int page); | ||
639 | |||
637 | /* Get the size and type of the eeprom contained within a plug-in | 640 | /* Get the size and type of the eeprom contained within a plug-in |
638 | * module */ | 641 | * module */ |
639 | int (*module_info)(struct phy_device *dev, | 642 | int (*module_info)(struct phy_device *dev, |
@@ -690,6 +693,8 @@ phy_lookup_setting(int speed, int duplex, const unsigned long *mask, | |||
690 | size_t phy_speeds(unsigned int *speeds, size_t size, | 693 | size_t phy_speeds(unsigned int *speeds, size_t size, |
691 | unsigned long *mask, size_t maxbit); | 694 | unsigned long *mask, size_t maxbit); |
692 | 695 | ||
696 | void phy_resolve_aneg_linkmode(struct phy_device *phydev); | ||
697 | |||
693 | /** | 698 | /** |
694 | * phy_read_mmd - Convenience function for reading a register | 699 | * phy_read_mmd - Convenience function for reading a register |
695 | * from an MMD on a given PHY. | 700 | * from an MMD on a given PHY. |
@@ -716,6 +721,18 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum) | |||
716 | } | 721 | } |
717 | 722 | ||
718 | /** | 723 | /** |
724 | * __phy_read - convenience function for reading a given PHY register | ||
725 | * @phydev: the phy_device struct | ||
726 | * @regnum: register number to read | ||
727 | * | ||
728 | * The caller must have taken the MDIO bus lock. | ||
729 | */ | ||
730 | static inline int __phy_read(struct phy_device *phydev, u32 regnum) | ||
731 | { | ||
732 | return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); | ||
733 | } | ||
734 | |||
735 | /** | ||
719 | * phy_write - Convenience function for writing a given PHY register | 736 | * phy_write - Convenience function for writing a given PHY register |
720 | * @phydev: the phy_device struct | 737 | * @phydev: the phy_device struct |
721 | * @regnum: register number to write | 738 | * @regnum: register number to write |
@@ -731,6 +748,72 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val) | |||
731 | } | 748 | } |
732 | 749 | ||
733 | /** | 750 | /** |
751 | * __phy_write - Convenience function for writing a given PHY register | ||
752 | * @phydev: the phy_device struct | ||
753 | * @regnum: register number to write | ||
754 | * @val: value to write to @regnum | ||
755 | * | ||
756 | * The caller must have taken the MDIO bus lock. | ||
757 | */ | ||
758 | static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val) | ||
759 | { | ||
760 | return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, | ||
761 | val); | ||
762 | } | ||
763 | |||
764 | int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set); | ||
765 | int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set); | ||
766 | |||
767 | /** | ||
768 | * __phy_set_bits - Convenience function for setting bits in a PHY register | ||
769 | * @phydev: the phy_device struct | ||
770 | * @regnum: register number to write | ||
771 | * @val: bits to set | ||
772 | * | ||
773 | * The caller must have taken the MDIO bus lock. | ||
774 | */ | ||
775 | static inline int __phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val) | ||
776 | { | ||
777 | return __phy_modify(phydev, regnum, 0, val); | ||
778 | } | ||
779 | |||
780 | /** | ||
781 | * __phy_clear_bits - Convenience function for clearing bits in a PHY register | ||
782 | * @phydev: the phy_device struct | ||
783 | * @regnum: register number to write | ||
784 | * @val: bits to clear | ||
785 | * | ||
786 | * The caller must have taken the MDIO bus lock. | ||
787 | */ | ||
788 | static inline int __phy_clear_bits(struct phy_device *phydev, u32 regnum, | ||
789 | u16 val) | ||
790 | { | ||
791 | return __phy_modify(phydev, regnum, val, 0); | ||
792 | } | ||
793 | |||
794 | /** | ||
795 | * phy_set_bits - Convenience function for setting bits in a PHY register | ||
796 | * @phydev: the phy_device struct | ||
797 | * @regnum: register number to write | ||
798 | * @val: bits to set | ||
799 | */ | ||
800 | static inline int phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val) | ||
801 | { | ||
802 | return phy_modify(phydev, regnum, 0, val); | ||
803 | } | ||
804 | |||
805 | /** | ||
806 | * phy_clear_bits - Convenience function for clearing bits in a PHY register | ||
807 | * @phydev: the phy_device struct | ||
808 | * @regnum: register number to write | ||
809 | * @val: bits to clear | ||
810 | */ | ||
811 | static inline int phy_clear_bits(struct phy_device *phydev, u32 regnum, u16 val) | ||
812 | { | ||
813 | return phy_modify(phydev, regnum, val, 0); | ||
814 | } | ||
815 | |||
816 | /** | ||
734 | * phy_interrupt_is_valid - Convenience function for testing a given PHY irq | 817 | * phy_interrupt_is_valid - Convenience function for testing a given PHY irq |
735 | * @phydev: the phy_device struct | 818 | * @phydev: the phy_device struct |
736 | * | 819 | * |
@@ -763,6 +846,20 @@ static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode) | |||
763 | }; | 846 | }; |
764 | 847 | ||
765 | /** | 848 | /** |
849 | * phy_interface_mode_is_8023z() - does the phy interface mode use 802.3z | ||
850 | * negotiation | ||
851 | * @mode: one of &enum phy_interface_t | ||
852 | * | ||
853 | * Returns true if the phy interface mode uses the 16-bit negotiation | ||
854 | * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding) | ||
855 | */ | ||
856 | static inline bool phy_interface_mode_is_8023z(phy_interface_t mode) | ||
857 | { | ||
858 | return mode == PHY_INTERFACE_MODE_1000BASEX || | ||
859 | mode == PHY_INTERFACE_MODE_2500BASEX; | ||
860 | } | ||
861 | |||
862 | /** | ||
766 | * phy_interface_is_rgmii - Convenience function for testing if a PHY interface | 863 | * phy_interface_is_rgmii - Convenience function for testing if a PHY interface |
767 | * is RGMII (all variants) | 864 | * is RGMII (all variants) |
768 | * @phydev: the phy_device struct | 865 | * @phydev: the phy_device struct |
@@ -794,6 +891,14 @@ static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev) | |||
794 | */ | 891 | */ |
795 | int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val); | 892 | int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val); |
796 | 893 | ||
894 | int phy_save_page(struct phy_device *phydev); | ||
895 | int phy_select_page(struct phy_device *phydev, int page); | ||
896 | int phy_restore_page(struct phy_device *phydev, int oldpage, int ret); | ||
897 | int phy_read_paged(struct phy_device *phydev, int page, u32 regnum); | ||
898 | int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val); | ||
899 | int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum, | ||
900 | u16 mask, u16 set); | ||
901 | |||
797 | struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, | 902 | struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, |
798 | bool is_c45, | 903 | bool is_c45, |
799 | struct phy_c45_device_ids *c45_ids); | 904 | struct phy_c45_device_ids *c45_ids); |
@@ -840,13 +945,11 @@ int phy_aneg_done(struct phy_device *phydev); | |||
840 | 945 | ||
841 | int phy_stop_interrupts(struct phy_device *phydev); | 946 | int phy_stop_interrupts(struct phy_device *phydev); |
842 | int phy_restart_aneg(struct phy_device *phydev); | 947 | int phy_restart_aneg(struct phy_device *phydev); |
948 | int phy_reset_after_clk_enable(struct phy_device *phydev); | ||
843 | 949 | ||
844 | static inline int phy_read_status(struct phy_device *phydev) | 950 | static inline void phy_device_reset(struct phy_device *phydev, int value) |
845 | { | 951 | { |
846 | if (!phydev->drv) | 952 | mdio_device_reset(&phydev->mdio, value); |
847 | return -EIO; | ||
848 | |||
849 | return phydev->drv->read_status(phydev); | ||
850 | } | 953 | } |
851 | 954 | ||
852 | #define phydev_err(_phydev, format, args...) \ | 955 | #define phydev_err(_phydev, format, args...) \ |
@@ -889,6 +992,18 @@ int genphy_c45_read_lpa(struct phy_device *phydev); | |||
889 | int genphy_c45_read_pma(struct phy_device *phydev); | 992 | int genphy_c45_read_pma(struct phy_device *phydev); |
890 | int genphy_c45_pma_setup_forced(struct phy_device *phydev); | 993 | int genphy_c45_pma_setup_forced(struct phy_device *phydev); |
891 | int genphy_c45_an_disable_aneg(struct phy_device *phydev); | 994 | int genphy_c45_an_disable_aneg(struct phy_device *phydev); |
995 | int genphy_c45_read_mdix(struct phy_device *phydev); | ||
996 | |||
997 | static inline int phy_read_status(struct phy_device *phydev) | ||
998 | { | ||
999 | if (!phydev->drv) | ||
1000 | return -EIO; | ||
1001 | |||
1002 | if (phydev->drv->read_status) | ||
1003 | return phydev->drv->read_status(phydev); | ||
1004 | else | ||
1005 | return genphy_read_status(phydev); | ||
1006 | } | ||
892 | 1007 | ||
893 | void phy_driver_unregister(struct phy_driver *drv); | 1008 | void phy_driver_unregister(struct phy_driver *drv); |
894 | void phy_drivers_unregister(struct phy_driver *drv, int n); | 1009 | void phy_drivers_unregister(struct phy_driver *drv, int n); |
@@ -898,7 +1013,7 @@ int phy_drivers_register(struct phy_driver *new_driver, int n, | |||
898 | void phy_state_machine(struct work_struct *work); | 1013 | void phy_state_machine(struct work_struct *work); |
899 | void phy_change(struct phy_device *phydev); | 1014 | void phy_change(struct phy_device *phydev); |
900 | void phy_change_work(struct work_struct *work); | 1015 | void phy_change_work(struct work_struct *work); |
901 | void phy_mac_interrupt(struct phy_device *phydev, int new_link); | 1016 | void phy_mac_interrupt(struct phy_device *phydev); |
902 | void phy_start_machine(struct phy_device *phydev); | 1017 | void phy_start_machine(struct phy_device *phydev); |
903 | void phy_stop_machine(struct phy_device *phydev); | 1018 | void phy_stop_machine(struct phy_device *phydev); |
904 | void phy_trigger_machine(struct phy_device *phydev, bool sync); | 1019 | void phy_trigger_machine(struct phy_device *phydev, bool sync); |