// SPDX-License-Identifier: GPL-2.0 /* Driver for the Texas Instruments DP83TD510 PHY * Copyright (c) 2022 Pengutronix, Oleksij Rempel <[email protected]> */ #include <linux/bitfield.h> #include <linux/ethtool_netlink.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/phy.h> #define DP83TD510E_PHY_ID … /* MDIO_MMD_VEND2 registers */ #define DP83TD510E_PHY_STS … /* Bit 7 - mii_interrupt, active high. Clears on read. * Note: Clearing does not necessarily deactivate IRQ pin if interrupts pending. * This differs from the DP83TD510E datasheet (2020) which states this bit * clears on write 0. */ #define DP83TD510E_STS_MII_INT … #define DP83TD510E_LINK_STATUS … #define DP83TD510E_GEN_CFG … #define DP83TD510E_GENCFG_INT_POLARITY … #define DP83TD510E_GENCFG_INT_EN … #define DP83TD510E_GENCFG_INT_OE … #define DP83TD510E_INTERRUPT_REG_1 … #define DP83TD510E_INT1_LINK … #define DP83TD510E_INT1_LINK_EN … #define DP83TD510E_CTRL … #define DP83TD510E_CTRL_HW_RESET … #define DP83TD510E_CTRL_SW_RESET … #define DP83TD510E_AN_STAT_1 … #define DP83TD510E_MASTER_SLAVE_RESOL_FAIL … #define DP83TD510E_MSE_DETECT … #define DP83TD510_SQI_MAX … /* Register values are converted to SNR(dB) as suggested by * "Application Report - DP83TD510E Cable Diagnostics Toolkit": * SNR(dB) = -10 * log10 (VAL/2^17) - 1.76 dB. * SQI ranges are implemented according to "OPEN ALLIANCE - Advanced diagnostic * features for 100BASE-T1 automotive Ethernet PHYs" */ static const u16 dp83td510_mse_sqi_map[] = …; /* Time Domain Reflectometry (TDR) Functionality of DP83TD510 PHY * * I assume that this PHY is using a variation of Spread Spectrum Time Domain * Reflectometry (SSTDR) rather than the commonly used TDR found in many PHYs. * Here are the following observations which likely confirm this: * - The DP83TD510 PHY transmits a modulated signal of configurable length * (default 16000 µs) instead of a single pulse pattern, which is typical * for traditional TDR. * - The pulse observed on the wire, triggered by the HW RESET register, is not * part of the cable testing process. * * I assume that SSTDR seems to be a logical choice for the 10BaseT1L * environment due to improved noise resistance, making it suitable for * environments with significant electrical noise, such as long 10BaseT1L cable * runs. * * Configuration Variables: * The SSTDR variation used in this PHY involves more configuration variables * that can dramatically affect the functionality and precision of cable * testing. Since most of these configuration options are either not well * documented or documented with minimal details, the following sections * describe my understanding and observations of these variables and their * impact on TDR functionality. * * Timeline: * ,<--cfg_pre_silence_time * | ,<-SSTDR Modulated Transmission * | | ,<--cfg_post_silence_time * | | | ,<--Force Link Mode * |<--'-->|<-------'------->|<--'-->|<--------'------->| * * - cfg_pre_silence_time: Optional silence time before TDR transmission starts. * - SSTDR Modulated Transmission: Transmission duration configured by * cfg_tdr_tx_duration and amplitude configured by cfg_tdr_tx_type. * - cfg_post_silence_time: Silence time after TDR transmission. * - Force Link Mode: If nothing is configured after cfg_post_silence_time, * the PHY continues in force link mode without autonegotiation. */ #define DP83TD510E_TDR_CFG … #define DP83TD510E_TDR_START … #define DP83TD510E_TDR_DONE … #define DP83TD510E_TDR_FAIL … #define DP83TD510E_TDR_CFG1 … /* cfg_tdr_tx_type: Transmit voltage level for TDR. * 0 = 1V, 1 = 2.4V * Note: Using different voltage levels may not work * in all configuration variations. For example, setting * 2.4V may give different cable length measurements. * Other settings may be needed to make it work properly. */ #define DP83TD510E_TDR_TX_TYPE … #define DP83TD510E_TDR_TX_TYPE_1V … #define DP83TD510E_TDR_TX_TYPE_2_4V … /* cfg_post_silence_time: Time after the TDR sequence. Since we force master mode * for the TDR will proceed with forced link state after this time. For Linux * it is better to set max value to avoid false link state detection. */ #define DP83TD510E_TDR_CFG1_POST_SILENCE_TIME … #define DP83TD510E_TDR_CFG1_POST_SILENCE_TIME_0MS … #define DP83TD510E_TDR_CFG1_POST_SILENCE_TIME_10MS … #define DP83TD510E_TDR_CFG1_POST_SILENCE_TIME_100MS … #define DP83TD510E_TDR_CFG1_POST_SILENCE_TIME_1000MS … /* cfg_pre_silence_time: Time before the TDR sequence. It should be enough to * settle down all pulses and reflections. Since for 10BASE-T1L we have * maximum 2000m cable length, we can set it to 1ms. */ #define DP83TD510E_TDR_CFG1_PRE_SILENCE_TIME … #define DP83TD510E_TDR_CFG1_PRE_SILENCE_TIME_0MS … #define DP83TD510E_TDR_CFG1_PRE_SILENCE_TIME_10MS … #define DP83TD510E_TDR_CFG1_PRE_SILENCE_TIME_100MS … #define DP83TD510E_TDR_CFG1_PRE_SILENCE_TIME_1000MS … #define DP83TD510E_TDR_CFG2 … #define DP83TD510E_TDR_END_TAP_INDEX_1 … #define DP83TD510E_TDR_END_TAP_INDEX_1_DEF … #define DP83TD510E_TDR_START_TAP_INDEX_1 … #define DP83TD510E_TDR_START_TAP_INDEX_1_DEF … #define DP83TD510E_TDR_CFG3 … /* cfg_tdr_tx_duration: Duration of the TDR transmission in microseconds. * This value sets the duration of the modulated signal used for TDR * measurements. * - Default: 16000 µs * - Observation: A minimum duration of 6000 µs is recommended to ensure * accurate detection of cable faults. Durations shorter than 6000 µs may * result in incomplete data, especially for shorter cables (e.g., 20 meters), * leading to false "OK" results. Longer durations (e.g., 6000 µs or more) * provide better accuracy, particularly for detecting open circuits. */ #define DP83TD510E_TDR_TX_DURATION_US … #define DP83TD510E_TDR_TX_DURATION_US_DEF … #define DP83TD510E_TDR_FAULT_CFG1 … #define DP83TD510E_TDR_FLT_LOC_OFFSET_1 … #define DP83TD510E_TDR_FLT_LOC_OFFSET_1_DEF … #define DP83TD510E_TDR_FLT_INIT_1 … #define DP83TD510E_TDR_FLT_INIT_1_DEF … #define DP83TD510E_TDR_FAULT_STAT … #define DP83TD510E_TDR_PEAK_DETECT … #define DP83TD510E_TDR_PEAK_SIGN … #define DP83TD510E_TDR_PEAK_LOCATION … /* Not documented registers and values but recommended according to * "DP83TD510E Cable Diagnostics Toolkit revC" */ #define DP83TD510E_UNKN_030E … #define DP83TD510E_030E_VAL … static int dp83td510_config_intr(struct phy_device *phydev) { … } static irqreturn_t dp83td510_handle_interrupt(struct phy_device *phydev) { … } static int dp83td510_read_status(struct phy_device *phydev) { … } static int dp83td510_config_aneg(struct phy_device *phydev) { … } static int dp83td510_get_sqi(struct phy_device *phydev) { … } static int dp83td510_get_sqi_max(struct phy_device *phydev) { … } /** * dp83td510_cable_test_start - Start the cable test for the DP83TD510 PHY. * @phydev: Pointer to the phy_device structure. * * This sequence is implemented according to the "Application Note DP83TD510E * Cable Diagnostics Toolkit revC". * * Returns: 0 on success, a negative error code on failure. */ static int dp83td510_cable_test_start(struct phy_device *phydev) { … } /** * dp83td510_cable_test_get_status - Get the status of the cable test for the * DP83TD510 PHY. * @phydev: Pointer to the phy_device structure. * @finished: Pointer to a boolean that indicates whether the test is finished. * * The function sets the @finished flag to true if the test is complete. * * Returns: 0 on success or a negative error code on failure. */ static int dp83td510_cable_test_get_status(struct phy_device *phydev, bool *finished) { … } static int dp83td510_get_features(struct phy_device *phydev) { … } static struct phy_driver dp83td510_driver[] = …; module_phy_driver(dp83td510_driver); static struct mdio_device_id __maybe_unused dp83td510_tbl[] = …; MODULE_DEVICE_TABLE(mdio, dp83td510_tbl); MODULE_DESCRIPTION(…) …; MODULE_AUTHOR(…) …; MODULE_LICENSE(…) …;