linux/drivers/ptp/ptp_mock.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright 2023 NXP
 *
 * Mock-up PTP Hardware Clock driver for virtual network devices
 *
 * Create a PTP clock which offers PTP time manipulation operations
 * using a timecounter/cyclecounter on top of CLOCK_MONOTONIC_RAW.
 */

#include <linux/ptp_clock_kernel.h>
#include <linux/ptp_mock.h>
#include <linux/timecounter.h>

/* Clamp scaled_ppm between -2,097,152,000 and 2,097,152,000,
 * and thus "adj" between -68,719,476 and 68,719,476
 */
#define MOCK_PHC_MAX_ADJ_PPB
/* Timestamps from ktime_get_raw() have 1 ns resolution, so the scale factor
 * (MULT >> SHIFT) needs to be 1. Pick SHIFT as 31 bits, which translates
 * MULT(freq 0) into 0x80000000.
 */
#define MOCK_PHC_CC_SHIFT
#define MOCK_PHC_CC_MULT
#define MOCK_PHC_FADJ_SHIFT
#define MOCK_PHC_FADJ_DENOMINATOR

/* The largest cycle_delta that timecounter_read_delta() can handle without a
 * 64-bit overflow during the multiplication with cc->mult, given the max "adj"
 * we permit, is ~8.3 seconds. Make sure readouts are more frequent than that.
 */
#define MOCK_PHC_REFRESH_INTERVAL

#define info_to_phc(d)

struct mock_phc {};

static u64 mock_phc_cc_read(const struct cyclecounter *cc)
{}

static int mock_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm)
{}

static int mock_phc_adjtime(struct ptp_clock_info *info, s64 delta)
{}

static int mock_phc_settime64(struct ptp_clock_info *info,
			      const struct timespec64 *ts)
{}

static int mock_phc_gettime64(struct ptp_clock_info *info, struct timespec64 *ts)
{}

static long mock_phc_refresh(struct ptp_clock_info *info)
{}

int mock_phc_index(struct mock_phc *phc)
{}
EXPORT_SYMBOL_GPL();

struct mock_phc *mock_phc_create(struct device *dev)
{}
EXPORT_SYMBOL_GPL();

void mock_phc_destroy(struct mock_phc *phc)
{}
EXPORT_SYMBOL_GPL();

MODULE_DESCRIPTION();
MODULE_LICENSE();