drivers/ptp/ptp_idt82p33.c

Source file repositories/reference/linux-study-clean/drivers/ptp/ptp_idt82p33.c

File Facts

System
Linux kernel
Corpus path
drivers/ptp/ptp_idt82p33.c
Extension
.c
Size
32986 bytes
Lines
1459
Domain
Driver Families
Bucket
drivers/ptp
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

if (ref < 0) {
			dev_err(idt82p33->dev, "%s: No valid pin found for Pll%d!\n",
				__func__, channel->plln);
			return -EBUSY;
		}

		err = map_ref_to_tod_trig_sel(ref, &trigger);

		if (err) {
			dev_err(idt82p33->dev,
				"%s: Unsupported ref %d!\n", __func__, ref);
			return err;
		}

		err = arm_tod_read_with_trigger(&idt82p33->channel[index], trigger);

		if (err == 0) {
			idt82p33->extts_mask |= mask;
			idt82p33->channel[index].tod_trigger = trigger;
			idt82p33->event_channel[index] = channel;
			idt82p33->extts_single_shot = is_one_shot(idt82p33->extts_mask);

			if (old_mask)
				return 0;

			schedule_delayed_work(&idt82p33->extts_work,
					      msecs_to_jiffies(EXTTS_PERIOD_MS));
		}
	} else {
		idt82p33->extts_mask &= ~mask;
		idt82p33->extts_single_shot = is_one_shot(idt82p33->extts_mask);

		if (idt82p33->extts_mask == 0)
			cancel_delayed_work(&idt82p33->extts_work);
	}

	return err;
}

static int idt82p33_extts_check_channel(struct idt82p33 *idt82p33, u8 todn)
{
	struct idt82p33_channel *event_channel;
	struct ptp_clock_event event;
	struct timespec64 ts;
	int err;

	err = idt82p33_get_extts(&idt82p33->channel[todn], &ts);
	if (err == 0) {
		event_channel = idt82p33->event_channel[todn];
		event.type = PTP_CLOCK_EXTTS;
		event.index = todn;
		event.timestamp = timespec64_to_ns(&ts);
		ptp_clock_event(event_channel->ptp_clock,
				&event);
	}
	return err;
}

static u8 idt82p33_extts_enable_mask(struct idt82p33_channel *channel,
				     u8 extts_mask, bool enable)
{
	struct idt82p33 *idt82p33 = channel->idt82p33;
	u8 trigger = channel->tod_trigger;
	u8 mask;
	int err;
	int i;

	if (extts_mask == 0)
		return 0;

	if (enable == false)
		cancel_delayed_work_sync(&idt82p33->extts_work);

	for (i = 0; i < MAX_PHC_PLL; i++) {
		mask = 1 << i;

		if ((extts_mask & mask) == 0)
			continue;

		if (enable) {
			err = arm_tod_read_with_trigger(&idt82p33->channel[i], trigger);
			if (err)
				dev_err(idt82p33->dev,
					"%s: Arm ToD read trigger failed, err = %d",
					__func__, err);
		} else {
			err = idt82p33_extts_check_channel(idt82p33, i);
			if (err == 0 && idt82p33->extts_single_shot)
				/* trigger happened so we won't re-enable it */
				extts_mask &= ~mask;

Annotation

Implementation Notes