drivers/net/dsa/mv88e6xxx/ptp.c

Source file repositories/reference/linux-study-clean/drivers/net/dsa/mv88e6xxx/ptp.c

File Facts

System
Linux kernel
Corpus path
drivers/net/dsa/mv88e6xxx/ptp.c
Extension
.c
Size
15523 bytes
Lines
566
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

struct mv88e6xxx_cc_coeffs {
	u32 cc_shift;
	u32 cc_mult;
	u32 cc_mult_num;
	u32 cc_mult_dem;
};

/* Family MV88E6250:
 * Raw timestamps are in units of 10-ns clock periods.
 *
 * clkadj = scaled_ppm * 10*2^28 / (10^6 * 2^16)
 * simplifies to
 * clkadj = scaled_ppm * 2^7 / 5^5
 */
#define MV88E6XXX_CC_10NS_SHIFT 28
static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_10ns_coeffs = {
	.cc_shift = MV88E6XXX_CC_10NS_SHIFT,
	.cc_mult = 10 << MV88E6XXX_CC_10NS_SHIFT,
	.cc_mult_num = 1 << 7,
	.cc_mult_dem = 3125ULL,
};

/* Other families except MV88E6393X in internal clock mode:
 * Raw timestamps are in units of 8-ns clock periods.
 *
 * clkadj = scaled_ppm * 8*2^28 / (10^6 * 2^16)
 * simplifies to
 * clkadj = scaled_ppm * 2^9 / 5^6
 */
#define MV88E6XXX_CC_8NS_SHIFT 28
static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_8ns_coeffs = {
	.cc_shift = MV88E6XXX_CC_8NS_SHIFT,
	.cc_mult = 8 << MV88E6XXX_CC_8NS_SHIFT,
	.cc_mult_num = 1 << 9,
	.cc_mult_dem = 15625ULL
};

/* Family MV88E6393X using internal clock:
 * Raw timestamps are in units of 4-ns clock periods.
 *
 * clkadj = scaled_ppm * 4*2^28 / (10^6 * 2^16)
 * simplifies to
 * clkadj = scaled_ppm * 2^8 / 5^6
 */
#define MV88E6XXX_CC_4NS_SHIFT 28
static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_4ns_coeffs = {
	.cc_shift = MV88E6XXX_CC_4NS_SHIFT,
	.cc_mult = 4 << MV88E6XXX_CC_4NS_SHIFT,
	.cc_mult_num = 1 << 8,
	.cc_mult_dem = 15625ULL
};

#define TAI_EVENT_WORK_INTERVAL msecs_to_jiffies(100)

#define cc_to_chip(cc) container_of(cc, struct mv88e6xxx_chip, tstamp_cc)
#define dw_overflow_to_chip(dw) container_of(dw, struct mv88e6xxx_chip, \
					     overflow_work)
#define dw_tai_event_to_chip(dw) container_of(dw, struct mv88e6xxx_chip, \
					      tai_event_work)

static int mv88e6xxx_tai_read(struct mv88e6xxx_chip *chip, int addr,
			      u16 *data, int len)
{
	if (!chip->info->ops->avb_ops->tai_read)
		return -EOPNOTSUPP;

	return chip->info->ops->avb_ops->tai_read(chip, addr, data, len);
}

static int mv88e6xxx_tai_write(struct mv88e6xxx_chip *chip, int addr, u16 data)
{
	if (!chip->info->ops->avb_ops->tai_write)
		return -EOPNOTSUPP;

	return chip->info->ops->avb_ops->tai_write(chip, addr, data);
}

/* TODO: places where this are called should be using pinctrl */
static int mv88e6352_set_gpio_func(struct mv88e6xxx_chip *chip, int pin,
				   int func, int input)
{
	int err;

	if (!chip->info->ops->gpio_ops)
		return -EOPNOTSUPP;

	err = chip->info->ops->gpio_ops->set_dir(chip, pin, input);
	if (err)
		return err;

Annotation

Implementation Notes