drivers/net/phy/nxp-cbtx.c

Source file repositories/reference/linux-study-clean/drivers/net/phy/nxp-cbtx.c

File Facts

System
Linux kernel
Corpus path
drivers/net/phy/nxp-cbtx.c
Extension
.c
Size
4911 bytes
Lines
228
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source 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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Driver for 100BASE-TX PHY embedded into NXP SJA1110 switch
 *
 * Copyright 2022-2023 NXP
 */

#include <linux/kernel.h>
#include <linux/mii.h>
#include <linux/module.h>
#include <linux/phy.h>

#define PHY_ID_CBTX_SJA1110			0x001bb020

/* Registers */
#define  CBTX_MODE_CTRL_STAT			0x11
#define  CBTX_PDOWN_CTRL			0x18
#define  CBTX_RX_ERR_COUNTER			0x1a
#define  CBTX_IRQ_STAT				0x1d
#define  CBTX_IRQ_ENABLE			0x1e

/* Fields */
#define CBTX_MODE_CTRL_STAT_AUTO_MDIX_EN	BIT(7)
#define CBTX_MODE_CTRL_STAT_MDIX_MODE		BIT(6)

#define CBTX_PDOWN_CTL_TRUE_PDOWN		BIT(0)

#define CBTX_IRQ_ENERGYON			BIT(7)
#define CBTX_IRQ_AN_COMPLETE			BIT(6)
#define CBTX_IRQ_REM_FAULT			BIT(5)
#define CBTX_IRQ_LINK_DOWN			BIT(4)
#define CBTX_IRQ_AN_LP_ACK			BIT(3)
#define CBTX_IRQ_PARALLEL_DETECT_FAULT		BIT(2)
#define CBTX_IRQ_AN_PAGE_RECV			BIT(1)

static int cbtx_soft_reset(struct phy_device *phydev)
{
	int ret;

	/* Can't soft reset unless we remove PHY from true power down mode */
	ret = phy_clear_bits(phydev, CBTX_PDOWN_CTRL,
			     CBTX_PDOWN_CTL_TRUE_PDOWN);
	if (ret)
		return ret;

	return genphy_soft_reset(phydev);
}

static int cbtx_config_init(struct phy_device *phydev)
{
	/* Wait for cbtx_config_aneg() to kick in and apply this */
	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;

	return 0;
}

static int cbtx_mdix_status(struct phy_device *phydev)
{
	int ret;

	ret = phy_read(phydev, CBTX_MODE_CTRL_STAT);
	if (ret < 0)
		return ret;

	if (ret & CBTX_MODE_CTRL_STAT_MDIX_MODE)
		phydev->mdix = ETH_TP_MDI_X;
	else
		phydev->mdix = ETH_TP_MDI;

	return 0;
}

static int cbtx_read_status(struct phy_device *phydev)
{
	int ret;

	ret = cbtx_mdix_status(phydev);
	if (ret)
		return ret;

	return genphy_read_status(phydev);
}

static int cbtx_mdix_config(struct phy_device *phydev)
{
	int ret;

	switch (phydev->mdix_ctrl) {
	case ETH_TP_MDI_AUTO:
		return phy_set_bits(phydev, CBTX_MODE_CTRL_STAT,
				    CBTX_MODE_CTRL_STAT_AUTO_MDIX_EN);

Annotation

Implementation Notes