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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-phy-micrel-add-ptp-support-for-lan8842'

Horatiu Vultur says:

====================
net: phy: micrel: Add PTP support for lan8842

The PTP block in lan8842 is the same as lan8814 so reuse all these
functions. The first patch of the series just does cosmetic changes such
that lan8842 can reuse the function lan8814_ptp_probe. There should not be
any functional changes here. While the second patch adds the PTP support
to lan8842.
====================

Link: https://patch.msgid.link/20250902121832.3258544-1-horatiu.vultur@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+111 -5
+111 -5
drivers/net/phy/micrel.c
··· 362 362 /* Delay used to get the second part from the LTC */ 363 363 #define LAN8841_GET_SEC_LTC_DELAY (500 * NSEC_PER_MSEC) 364 364 365 + #define LAN8842_REV_8832 0x8832 366 + 365 367 struct kszphy_hw_stat { 366 368 const char *string; 367 369 u8 reg; ··· 459 457 460 458 struct lan8842_priv { 461 459 struct lan8842_phy_stats phy_stats; 460 + struct kszphy_ptp_priv ptp_priv; 461 + u16 rev; 462 462 }; 463 463 464 464 static const struct kszphy_type lan8814_type = { ··· 4246 4242 phydev->default_timestamp = true; 4247 4243 } 4248 4244 4249 - static int lan8814_ptp_probe_once(struct phy_device *phydev) 4245 + static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name, 4246 + int gpios) 4250 4247 { 4251 4248 struct lan8814_shared_priv *shared = phy_package_get_priv(phydev); 4252 4249 ··· 4255 4250 mutex_init(&shared->shared_lock); 4256 4251 4257 4252 shared->pin_config = devm_kmalloc_array(&phydev->mdio.dev, 4258 - LAN8814_PTP_GPIO_NUM, 4253 + gpios, 4259 4254 sizeof(*shared->pin_config), 4260 4255 GFP_KERNEL); 4261 4256 if (!shared->pin_config) 4262 4257 return -ENOMEM; 4263 4258 4264 - for (int i = 0; i < LAN8814_PTP_GPIO_NUM; i++) { 4259 + for (int i = 0; i < gpios; i++) { 4265 4260 struct ptp_pin_desc *ptp_pin = &shared->pin_config[i]; 4266 4261 4267 4262 memset(ptp_pin, 0, sizeof(*ptp_pin)); 4268 4263 snprintf(ptp_pin->name, 4269 - sizeof(ptp_pin->name), "lan8814_ptp_pin_%02d", i); 4264 + sizeof(ptp_pin->name), "%s_%02d", pin_name, i); 4270 4265 ptp_pin->index = i; 4271 4266 ptp_pin->func = PTP_PF_NONE; 4272 4267 } ··· 4276 4271 shared->ptp_clock_info.max_adj = 31249999; 4277 4272 shared->ptp_clock_info.n_alarm = 0; 4278 4273 shared->ptp_clock_info.n_ext_ts = LAN8814_PTP_EXTTS_NUM; 4279 - shared->ptp_clock_info.n_pins = LAN8814_PTP_GPIO_NUM; 4274 + shared->ptp_clock_info.n_pins = gpios; 4280 4275 shared->ptp_clock_info.pps = 0; 4281 4276 shared->ptp_clock_info.supported_extts_flags = PTP_RISING_EDGE | 4282 4277 PTP_FALLING_EDGE | ··· 4321 4316 PTP_CMD_CTL_PTP_ENABLE_); 4322 4317 4323 4318 return 0; 4319 + } 4320 + 4321 + static int lan8814_ptp_probe_once(struct phy_device *phydev) 4322 + { 4323 + return __lan8814_ptp_probe_once(phydev, "lan8814_ptp_pin", 4324 + LAN8814_PTP_GPIO_NUM); 4324 4325 } 4325 4326 4326 4327 static void lan8814_setup_led(struct phy_device *phydev, int val) ··· 5790 5779 return kszphy_resume(phydev); 5791 5780 } 5792 5781 5782 + #define LAN8842_PTP_GPIO_NUM 16 5783 + 5784 + static int lan8842_ptp_probe_once(struct phy_device *phydev) 5785 + { 5786 + return __lan8814_ptp_probe_once(phydev, "lan8842_ptp_pin", 5787 + LAN8842_PTP_GPIO_NUM); 5788 + } 5789 + 5790 + #define LAN8842_STRAP_REG 0 /* 0x0 */ 5791 + #define LAN8842_STRAP_REG_PHYADDR_MASK GENMASK(4, 0) 5792 + #define LAN8842_SKU_REG 11 /* 0x0b */ 5793 5793 #define LAN8842_SELF_TEST 14 /* 0x0e */ 5794 5794 #define LAN8842_SELF_TEST_RX_CNT_ENA BIT(8) 5795 5795 #define LAN8842_SELF_TEST_TX_CNT_ENA BIT(4) ··· 5808 5786 static int lan8842_probe(struct phy_device *phydev) 5809 5787 { 5810 5788 struct lan8842_priv *priv; 5789 + int addr; 5811 5790 int ret; 5812 5791 5813 5792 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); ··· 5832 5809 LAN8842_SELF_TEST_TX_CNT_ENA); 5833 5810 if (ret < 0) 5834 5811 return ret; 5812 + 5813 + /* Revision lan8832 doesn't have support for PTP, therefore don't add 5814 + * any PTP clocks 5815 + */ 5816 + ret = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS, 5817 + LAN8842_SKU_REG); 5818 + if (ret < 0) 5819 + return ret; 5820 + 5821 + priv->rev = ret; 5822 + if (priv->rev == LAN8842_REV_8832) 5823 + return 0; 5824 + 5825 + /* As the lan8814 and lan8842 has the same IP for the PTP block, the 5826 + * only difference is the number of the GPIOs, then make sure that the 5827 + * lan8842 initialized also the shared data pointer as this is used in 5828 + * all the PTP functions for lan8814. The lan8842 doesn't have multiple 5829 + * PHYs in the same package. 5830 + */ 5831 + addr = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS, 5832 + LAN8842_STRAP_REG); 5833 + if (addr < 0) 5834 + return addr; 5835 + addr &= LAN8842_STRAP_REG_PHYADDR_MASK; 5836 + 5837 + ret = devm_phy_package_join(&phydev->mdio.dev, phydev, addr, 5838 + sizeof(struct lan8814_shared_priv)); 5839 + if (ret) 5840 + return ret; 5841 + 5842 + if (phy_package_init_once(phydev)) { 5843 + ret = lan8842_ptp_probe_once(phydev); 5844 + if (ret) 5845 + return ret; 5846 + } 5847 + 5848 + lan8814_ptp_init(phydev); 5835 5849 5836 5850 return 0; 5837 5851 } ··· 5949 5889 enable ? LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA : 0); 5950 5890 } 5951 5891 5892 + static void lan8842_handle_ptp_interrupt(struct phy_device *phydev, u16 status) 5893 + { 5894 + struct kszphy_ptp_priv *ptp_priv; 5895 + struct lan8842_priv *priv; 5896 + 5897 + priv = phydev->priv; 5898 + ptp_priv = &priv->ptp_priv; 5899 + 5900 + if (status & PTP_TSU_INT_STS_PTP_TX_TS_EN_) 5901 + lan8814_get_tx_ts(ptp_priv); 5902 + 5903 + if (status & PTP_TSU_INT_STS_PTP_RX_TS_EN_) 5904 + lan8814_get_rx_ts(ptp_priv); 5905 + 5906 + if (status & PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_) { 5907 + lan8814_flush_fifo(phydev, true); 5908 + skb_queue_purge(&ptp_priv->tx_queue); 5909 + } 5910 + 5911 + if (status & PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_) { 5912 + lan8814_flush_fifo(phydev, false); 5913 + skb_queue_purge(&ptp_priv->rx_queue); 5914 + } 5915 + } 5916 + 5952 5917 static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev) 5953 5918 { 5919 + struct lan8842_priv *priv = phydev->priv; 5954 5920 int ret = IRQ_NONE; 5955 5921 int irq_status; 5956 5922 ··· 5991 5905 ret = IRQ_HANDLED; 5992 5906 } 5993 5907 5908 + /* Phy revision lan8832 doesn't have support for PTP therefore there is 5909 + * not need to check the PTP and GPIO interrupts 5910 + */ 5911 + if (priv->rev == LAN8842_REV_8832) 5912 + goto out; 5913 + 5914 + while (true) { 5915 + irq_status = lanphy_read_page_reg(phydev, LAN8814_PAGE_PORT_REGS, 5916 + PTP_TSU_INT_STS); 5917 + if (!irq_status) 5918 + break; 5919 + 5920 + lan8842_handle_ptp_interrupt(phydev, irq_status); 5921 + ret = IRQ_HANDLED; 5922 + } 5923 + 5924 + if (!lan8814_handle_gpio_interrupt(phydev, irq_status)) 5925 + ret = IRQ_HANDLED; 5926 + 5927 + out: 5994 5928 return ret; 5995 5929 } 5996 5930