aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/phy.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/phy.h')
-rw-r--r--include/linux/phy.h145
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 */
508struct phy_driver { 508struct 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,
690size_t phy_speeds(unsigned int *speeds, size_t size, 693size_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
696void 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 */
730static 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 */
758static 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
764int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
765int 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 */
775static 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 */
788static 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 */
800static 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 */
811static 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 */
856static 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 */
795int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val); 892int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
796 893
894int phy_save_page(struct phy_device *phydev);
895int phy_select_page(struct phy_device *phydev, int page);
896int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
897int phy_read_paged(struct phy_device *phydev, int page, u32 regnum);
898int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val);
899int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
900 u16 mask, u16 set);
901
797struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, 902struct 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
841int phy_stop_interrupts(struct phy_device *phydev); 946int phy_stop_interrupts(struct phy_device *phydev);
842int phy_restart_aneg(struct phy_device *phydev); 947int phy_restart_aneg(struct phy_device *phydev);
948int phy_reset_after_clk_enable(struct phy_device *phydev);
843 949
844static inline int phy_read_status(struct phy_device *phydev) 950static 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);
889int genphy_c45_read_pma(struct phy_device *phydev); 992int genphy_c45_read_pma(struct phy_device *phydev);
890int genphy_c45_pma_setup_forced(struct phy_device *phydev); 993int genphy_c45_pma_setup_forced(struct phy_device *phydev);
891int genphy_c45_an_disable_aneg(struct phy_device *phydev); 994int genphy_c45_an_disable_aneg(struct phy_device *phydev);
995int genphy_c45_read_mdix(struct phy_device *phydev);
996
997static 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
893void phy_driver_unregister(struct phy_driver *drv); 1008void phy_driver_unregister(struct phy_driver *drv);
894void phy_drivers_unregister(struct phy_driver *drv, int n); 1009void phy_drivers_unregister(struct phy_driver *drv, int n);
@@ -898,7 +1013,7 @@ int phy_drivers_register(struct phy_driver *new_driver, int n,
898void phy_state_machine(struct work_struct *work); 1013void phy_state_machine(struct work_struct *work);
899void phy_change(struct phy_device *phydev); 1014void phy_change(struct phy_device *phydev);
900void phy_change_work(struct work_struct *work); 1015void phy_change_work(struct work_struct *work);
901void phy_mac_interrupt(struct phy_device *phydev, int new_link); 1016void phy_mac_interrupt(struct phy_device *phydev);
902void phy_start_machine(struct phy_device *phydev); 1017void phy_start_machine(struct phy_device *phydev);
903void phy_stop_machine(struct phy_device *phydev); 1018void phy_stop_machine(struct phy_device *phydev);
904void phy_trigger_machine(struct phy_device *phydev, bool sync); 1019void phy_trigger_machine(struct phy_device *phydev, bool sync);