drivers/net/phy/mediatek/mtk-phy-lib.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/mediatek/mtk-phy-lib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/mediatek/mtk-phy-lib.c- Extension
.c- Size
- 9645 bytes
- Lines
- 348
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/phy.hlinux/module.hlinux/netdevice.hmtk.h
Detected Declarations
function __mtk_tr_accessfunction __mtk_tr_readfunction __mtk_tr_writefunction __mtk_tr_modifyfunction mtk_tr_modifyfunction __mtk_tr_set_bitsfunction __mtk_tr_clr_bitsfunction mtk_phy_read_pagefunction mtk_phy_write_pagefunction mtk_phy_led_hw_is_supportedfunction mtk_phy_led_hw_ctrl_getfunction mtk_phy_led_hw_ctrl_setfunction mtk_phy_led_num_dly_cfgfunction mtk_phy_hw_led_on_setfunction mtk_phy_hw_led_blink_setfunction mtk_phy_leds_state_initexport __mtk_tr_modifyexport mtk_tr_modifyexport __mtk_tr_set_bitsexport __mtk_tr_clr_bitsexport mtk_phy_read_pageexport mtk_phy_write_pageexport mtk_phy_led_hw_is_supportedexport mtk_phy_led_hw_ctrl_getexport mtk_phy_led_hw_ctrl_setexport mtk_phy_led_num_dly_cfgexport mtk_phy_hw_led_on_setexport mtk_phy_hw_led_blink_setexport mtk_phy_leds_state_init
Annotated Snippet
if (on & on_set) {
if (on & MTK_PHY_LED_ON_LINK10)
blink |= MTK_PHY_LED_BLINK_10RX;
if (on & MTK_PHY_LED_ON_LINK100)
blink |= MTK_PHY_LED_BLINK_100RX;
if (on & MTK_PHY_LED_ON_LINK1000)
blink |= MTK_PHY_LED_BLINK_1000RX;
if (on & MTK_PHY_LED_ON_LINK2500)
blink |= MTK_PHY_LED_BLINK_2500RX;
} else {
blink |= rx_blink_set;
}
}
if (rules & BIT(TRIGGER_NETDEV_TX)) {
if (on & on_set) {
if (on & MTK_PHY_LED_ON_LINK10)
blink |= MTK_PHY_LED_BLINK_10TX;
if (on & MTK_PHY_LED_ON_LINK100)
blink |= MTK_PHY_LED_BLINK_100TX;
if (on & MTK_PHY_LED_ON_LINK1000)
blink |= MTK_PHY_LED_BLINK_1000TX;
if (on & MTK_PHY_LED_ON_LINK2500)
blink |= MTK_PHY_LED_BLINK_2500TX;
} else {
blink |= tx_blink_set;
}
}
if (blink || on)
set_bit(bit_netdev, &priv->led_state);
else
clear_bit(bit_netdev, &priv->led_state);
ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?
MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL,
MTK_PHY_LED_ON_FDX | MTK_PHY_LED_ON_HDX | on_set,
on);
if (ret)
return ret;
return phy_write_mmd(phydev, MDIO_MMD_VEND2, index ?
MTK_PHY_LED1_BLINK_CTRL :
MTK_PHY_LED0_BLINK_CTRL, blink);
}
EXPORT_SYMBOL_GPL(mtk_phy_led_hw_ctrl_set);
int mtk_phy_led_num_dly_cfg(u8 index, unsigned long *delay_on,
unsigned long *delay_off, bool *blinking)
{
if (index > 1)
return -EINVAL;
if (delay_on && delay_off && (*delay_on > 0) && (*delay_off > 0)) {
*blinking = true;
*delay_on = 50;
*delay_off = 50;
}
return 0;
}
EXPORT_SYMBOL_GPL(mtk_phy_led_num_dly_cfg);
int mtk_phy_hw_led_on_set(struct phy_device *phydev, u8 index,
u16 led_on_mask, bool on)
{
unsigned int bit_on = MTK_PHY_LED_STATE_FORCE_ON + (index ? 16 : 0);
struct mtk_socphy_priv *priv = phydev->priv;
bool changed;
if (on)
changed = !test_and_set_bit(bit_on, &priv->led_state);
else
changed = !!test_and_clear_bit(bit_on, &priv->led_state);
changed |= !!test_and_clear_bit(MTK_PHY_LED_STATE_NETDEV +
(index ? 16 : 0), &priv->led_state);
if (changed)
return phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?
MTK_PHY_LED1_ON_CTRL :
MTK_PHY_LED0_ON_CTRL,
led_on_mask,
on ? MTK_PHY_LED_ON_FORCE_ON : 0);
else
return 0;
}
EXPORT_SYMBOL_GPL(mtk_phy_hw_led_on_set);
int mtk_phy_hw_led_blink_set(struct phy_device *phydev, u8 index, bool blinking)
Annotation
- Immediate include surface: `linux/phy.h`, `linux/module.h`, `linux/netdevice.h`, `mtk.h`.
- Detected declarations: `function __mtk_tr_access`, `function __mtk_tr_read`, `function __mtk_tr_write`, `function __mtk_tr_modify`, `function mtk_tr_modify`, `function __mtk_tr_set_bits`, `function __mtk_tr_clr_bits`, `function mtk_phy_read_page`, `function mtk_phy_write_page`, `function mtk_phy_led_hw_is_supported`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.