19aab906aSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */ 2a1cba561SArun Parameswaran /* 3a1cba561SArun Parameswaran * Copyright (C) 2015 Broadcom Corporation 4a1cba561SArun Parameswaran */ 5a1cba561SArun Parameswaran 6a1cba561SArun Parameswaran #ifndef _LINUX_BCM_PHY_LIB_H 7a1cba561SArun Parameswaran #define _LINUX_BCM_PHY_LIB_H 8a1cba561SArun Parameswaran 979fb218dSFlorian Fainelli #include <linux/brcmphy.h> 10a1cba561SArun Parameswaran #include <linux/phy.h> 11*4781e965SFlorian Fainelli #include <linux/interrupt.h> 12a1cba561SArun Parameswaran 138baddaa9SFlorian Fainelli struct ethtool_wolinfo; 148baddaa9SFlorian Fainelli 15f878fe56SFlorian Fainelli /* 28nm only register definitions */ 16f878fe56SFlorian Fainelli #define MISC_ADDR(base, channel) base, channel 17f878fe56SFlorian Fainelli 18f878fe56SFlorian Fainelli #define DSP_TAP10 MISC_ADDR(0x0a, 0) 19f878fe56SFlorian Fainelli #define PLL_PLLCTRL_1 MISC_ADDR(0x32, 1) 20f878fe56SFlorian Fainelli #define PLL_PLLCTRL_2 MISC_ADDR(0x32, 2) 21f878fe56SFlorian Fainelli #define PLL_PLLCTRL_4 MISC_ADDR(0x33, 0) 22f878fe56SFlorian Fainelli 23f878fe56SFlorian Fainelli #define AFE_RXCONFIG_0 MISC_ADDR(0x38, 0) 24f878fe56SFlorian Fainelli #define AFE_RXCONFIG_1 MISC_ADDR(0x38, 1) 25f878fe56SFlorian Fainelli #define AFE_RXCONFIG_2 MISC_ADDR(0x38, 2) 26f878fe56SFlorian Fainelli #define AFE_RX_LP_COUNTER MISC_ADDR(0x38, 3) 27f878fe56SFlorian Fainelli #define AFE_TX_CONFIG MISC_ADDR(0x39, 0) 28f878fe56SFlorian Fainelli #define AFE_VDCA_ICTRL_0 MISC_ADDR(0x39, 1) 29f878fe56SFlorian Fainelli #define AFE_VDAC_OTHERS_0 MISC_ADDR(0x39, 3) 30f878fe56SFlorian Fainelli #define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0) 31f878fe56SFlorian Fainelli 32f878fe56SFlorian Fainelli 337d7e7bceSMichael Walle int __bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val); 347d7e7bceSMichael Walle int __bcm_phy_read_exp(struct phy_device *phydev, u16 reg); 35e184a907SMichael Walle int __bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set); 36a1cba561SArun Parameswaran int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val); 37a1cba561SArun Parameswaran int bcm_phy_read_exp(struct phy_device *phydev, u16 reg); 38e184a907SMichael Walle int bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set); 39a1cba561SArun Parameswaran 4079fb218dSFlorian Fainelli static inline int bcm_phy_write_exp_sel(struct phy_device *phydev, 4179fb218dSFlorian Fainelli u16 reg, u16 val) 4279fb218dSFlorian Fainelli { 4379fb218dSFlorian Fainelli return bcm_phy_write_exp(phydev, reg | MII_BCM54XX_EXP_SEL_ER, val); 4479fb218dSFlorian Fainelli } 4579fb218dSFlorian Fainelli 46582dbb2cSFlorian Fainelli static inline int bcm_phy_read_exp_sel(struct phy_device *phydev, u16 reg) 47582dbb2cSFlorian Fainelli { 48582dbb2cSFlorian Fainelli return bcm_phy_read_exp(phydev, reg | MII_BCM54XX_EXP_SEL_ER); 49582dbb2cSFlorian Fainelli } 50582dbb2cSFlorian Fainelli 515519da87SFlorian Fainelli int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val); 525519da87SFlorian Fainelli int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum); 535519da87SFlorian Fainelli 54a1cba561SArun Parameswaran int bcm_phy_write_misc(struct phy_device *phydev, 55a1cba561SArun Parameswaran u16 reg, u16 chl, u16 value); 56a1cba561SArun Parameswaran int bcm_phy_read_misc(struct phy_device *phydev, 57a1cba561SArun Parameswaran u16 reg, u16 chl); 58a1cba561SArun Parameswaran 59a1cba561SArun Parameswaran int bcm_phy_write_shadow(struct phy_device *phydev, u16 shadow, 60a1cba561SArun Parameswaran u16 val); 61a1cba561SArun Parameswaran int bcm_phy_read_shadow(struct phy_device *phydev, u16 shadow); 62a1cba561SArun Parameswaran 630a32f1ffSMichael Walle int __bcm_phy_write_rdb(struct phy_device *phydev, u16 rdb, u16 val); 640a32f1ffSMichael Walle int bcm_phy_write_rdb(struct phy_device *phydev, u16 rdb, u16 val); 650a32f1ffSMichael Walle int __bcm_phy_read_rdb(struct phy_device *phydev, u16 rdb); 660a32f1ffSMichael Walle int bcm_phy_read_rdb(struct phy_device *phydev, u16 rdb); 670a32f1ffSMichael Walle int __bcm_phy_modify_rdb(struct phy_device *phydev, u16 rdb, u16 mask, 680a32f1ffSMichael Walle u16 set); 690a32f1ffSMichael Walle int bcm_phy_modify_rdb(struct phy_device *phydev, u16 rdb, u16 mask, 700a32f1ffSMichael Walle u16 set); 710a32f1ffSMichael Walle 72a1cba561SArun Parameswaran int bcm_phy_ack_intr(struct phy_device *phydev); 73a1cba561SArun Parameswaran int bcm_phy_config_intr(struct phy_device *phydev); 744567d5c3SIoana Ciornei irqreturn_t bcm_phy_handle_interrupt(struct phy_device *phydev); 75a1cba561SArun Parameswaran 76a1cba561SArun Parameswaran int bcm_phy_enable_apd(struct phy_device *phydev, bool dll_pwr_down); 77a1cba561SArun Parameswaran 7899cec8a4SFlorian Fainelli int bcm_phy_set_eee(struct phy_device *phydev, bool enable); 79d06f78c4SFlorian Fainelli 80d06f78c4SFlorian Fainelli int bcm_phy_downshift_get(struct phy_device *phydev, u8 *count); 81d06f78c4SFlorian Fainelli 82d06f78c4SFlorian Fainelli int bcm_phy_downshift_set(struct phy_device *phydev, u8 count); 83d06f78c4SFlorian Fainelli 84820ee17bSFlorian Fainelli int bcm_phy_get_sset_count(struct phy_device *phydev); 85820ee17bSFlorian Fainelli void bcm_phy_get_strings(struct phy_device *phydev, u8 *data); 86820ee17bSFlorian Fainelli void bcm_phy_get_stats(struct phy_device *phydev, u64 *shadow, 87820ee17bSFlorian Fainelli struct ethtool_stats *stats, u64 *data); 88f878fe56SFlorian Fainelli void bcm_phy_r_rc_cal_reset(struct phy_device *phydev); 89f878fe56SFlorian Fainelli int bcm_phy_28nm_a0b0_afe_config_init(struct phy_device *phydev); 90ab41ca34SMurali Krishna Policharla int bcm_phy_enable_jumbo(struct phy_device *phydev); 91820ee17bSFlorian Fainelli 9211ecf8c5SMichael Walle int bcm_phy_cable_test_get_status_rdb(struct phy_device *phydev, 9311ecf8c5SMichael Walle bool *finished); 9411ecf8c5SMichael Walle int bcm_phy_cable_test_start_rdb(struct phy_device *phydev); 9511ecf8c5SMichael Walle int bcm_phy_cable_test_start(struct phy_device *phydev); 9611ecf8c5SMichael Walle int bcm_phy_cable_test_get_status(struct phy_device *phydev, bool *finished); 9711ecf8c5SMichael Walle 9815acf89eSJonathan Lemon #if IS_ENABLED(CONFIG_BCM_NET_PHYPTP) 9915acf89eSJonathan Lemon struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev); 10015acf89eSJonathan Lemon void bcm_ptp_config_init(struct phy_device *phydev); 10115acf89eSJonathan Lemon void bcm_ptp_stop(struct bcm_ptp_private *priv); 10215acf89eSJonathan Lemon #else 10315acf89eSJonathan Lemon static inline struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev) 10415acf89eSJonathan Lemon { 10515acf89eSJonathan Lemon return NULL; 10615acf89eSJonathan Lemon } 10715acf89eSJonathan Lemon 10815acf89eSJonathan Lemon static inline void bcm_ptp_config_init(struct phy_device *phydev) 10915acf89eSJonathan Lemon { 11015acf89eSJonathan Lemon } 11115acf89eSJonathan Lemon 11215acf89eSJonathan Lemon static inline void bcm_ptp_stop(struct bcm_ptp_private *priv) 11315acf89eSJonathan Lemon { 11415acf89eSJonathan Lemon } 11515acf89eSJonathan Lemon #endif 11615acf89eSJonathan Lemon 1178baddaa9SFlorian Fainelli int bcm_phy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol); 1188baddaa9SFlorian Fainelli void bcm_phy_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol); 119*4781e965SFlorian Fainelli irqreturn_t bcm_phy_wol_isr(int irq, void *dev_id); 1208baddaa9SFlorian Fainelli 121a1cba561SArun Parameswaran #endif /* _LINUX_BCM_PHY_LIB_H */ 122