2019-11-01 11:20:07 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
/*
|
|
|
|
* PTP hardware clock driver for the IDT ClockMatrix(TM) family of timing and
|
|
|
|
* synchronization devices.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
|
|
|
|
*/
|
|
|
|
#ifndef PTP_IDTCLOCKMATRIX_H
|
|
|
|
#define PTP_IDTCLOCKMATRIX_H
|
|
|
|
|
|
|
|
#include <linux/ktime.h>
|
2021-09-25 03:01:32 +08:00
|
|
|
#include <linux/mfd/idt8a340_reg.h>
|
|
|
|
#include <linux/regmap.h>
|
2019-11-01 11:20:07 +08:00
|
|
|
|
|
|
|
#define FW_FILENAME "idtcm.bin"
|
2020-07-29 04:00:30 +08:00
|
|
|
#define MAX_TOD (4)
|
|
|
|
#define MAX_PLL (8)
|
2019-11-01 11:20:07 +08:00
|
|
|
|
2020-05-02 11:35:38 +08:00
|
|
|
#define MAX_ABS_WRITE_PHASE_PICOSECONDS (107374182350LL)
|
|
|
|
|
2020-07-29 04:00:30 +08:00
|
|
|
#define TOD_MASK_ADDR (0xFFA5)
|
|
|
|
#define DEFAULT_TOD_MASK (0x04)
|
2019-11-01 11:20:07 +08:00
|
|
|
|
|
|
|
#define SET_U16_LSB(orig, val8) (orig = (0xff00 & (orig)) | (val8))
|
|
|
|
#define SET_U16_MSB(orig, val8) (orig = (0x00ff & (orig)) | (val8 << 8))
|
|
|
|
|
2020-07-29 04:00:30 +08:00
|
|
|
#define TOD0_PTP_PLL_ADDR (0xFFA8)
|
|
|
|
#define TOD1_PTP_PLL_ADDR (0xFFA9)
|
|
|
|
#define TOD2_PTP_PLL_ADDR (0xFFAA)
|
|
|
|
#define TOD3_PTP_PLL_ADDR (0xFFAB)
|
|
|
|
|
|
|
|
#define TOD0_OUT_ALIGN_MASK_ADDR (0xFFB0)
|
|
|
|
#define TOD1_OUT_ALIGN_MASK_ADDR (0xFFB2)
|
|
|
|
#define TOD2_OUT_ALIGN_MASK_ADDR (0xFFB4)
|
|
|
|
#define TOD3_OUT_ALIGN_MASK_ADDR (0xFFB6)
|
2019-11-01 11:20:07 +08:00
|
|
|
|
|
|
|
#define DEFAULT_OUTPUT_MASK_PLL0 (0x003)
|
|
|
|
#define DEFAULT_OUTPUT_MASK_PLL1 (0x00c)
|
|
|
|
#define DEFAULT_OUTPUT_MASK_PLL2 (0x030)
|
|
|
|
#define DEFAULT_OUTPUT_MASK_PLL3 (0x0c0)
|
|
|
|
|
2020-07-29 04:00:30 +08:00
|
|
|
#define DEFAULT_TOD0_PTP_PLL (0)
|
|
|
|
#define DEFAULT_TOD1_PTP_PLL (1)
|
|
|
|
#define DEFAULT_TOD2_PTP_PLL (2)
|
|
|
|
#define DEFAULT_TOD3_PTP_PLL (3)
|
|
|
|
|
2020-12-08 23:41:57 +08:00
|
|
|
#define PHASE_PULL_IN_THRESHOLD_NS_DEPRECATED (150000)
|
|
|
|
#define PHASE_PULL_IN_THRESHOLD_NS (15000)
|
|
|
|
#define TOD_WRITE_OVERHEAD_COUNT_MAX (2)
|
|
|
|
#define TOD_BYTE_COUNT (11)
|
2020-07-29 04:00:30 +08:00
|
|
|
|
2021-02-17 13:42:12 +08:00
|
|
|
#define LOCK_TIMEOUT_MS (2000)
|
|
|
|
#define LOCK_POLL_INTERVAL_MS (10)
|
|
|
|
|
2020-12-08 23:41:54 +08:00
|
|
|
#define PEROUT_ENABLE_OUTPUT_MASK (0xdeadbeef)
|
2020-07-29 04:00:30 +08:00
|
|
|
|
2020-12-08 23:41:54 +08:00
|
|
|
#define IDTCM_MAX_WRITE_COUNT (512)
|
|
|
|
|
2021-09-14 04:12:34 +08:00
|
|
|
#define PHASE_PULL_IN_MAX_PPB (144000)
|
|
|
|
#define PHASE_PULL_IN_MIN_THRESHOLD_NS (2)
|
|
|
|
|
2021-09-14 04:12:33 +08:00
|
|
|
/*
|
|
|
|
* Return register address based on passed in firmware version
|
|
|
|
*/
|
|
|
|
#define IDTCM_FW_REG(FW, VER, REG) (((FW) < (VER)) ? (REG) : (REG##_##VER))
|
2021-09-25 03:01:32 +08:00
|
|
|
enum fw_version {
|
|
|
|
V_DEFAULT = 0,
|
|
|
|
V487 = 1,
|
|
|
|
V520 = 2,
|
|
|
|
};
|
2020-08-18 22:41:22 +08:00
|
|
|
|
2021-09-14 04:12:34 +08:00
|
|
|
/* PTP PLL Mode */
|
|
|
|
enum ptp_pll_mode {
|
|
|
|
PTP_PLL_MODE_MIN = 0,
|
|
|
|
PTP_PLL_MODE_WRITE_FREQUENCY = PTP_PLL_MODE_MIN,
|
|
|
|
PTP_PLL_MODE_WRITE_PHASE,
|
|
|
|
PTP_PLL_MODE_UNSUPPORTED,
|
|
|
|
PTP_PLL_MODE_MAX = PTP_PLL_MODE_UNSUPPORTED,
|
|
|
|
};
|
|
|
|
|
2019-11-01 11:20:07 +08:00
|
|
|
struct idtcm;
|
|
|
|
|
|
|
|
struct idtcm_channel {
|
|
|
|
struct ptp_clock_info caps;
|
|
|
|
struct ptp_clock *ptp_clock;
|
|
|
|
struct idtcm *idtcm;
|
|
|
|
u16 dpll_phase;
|
|
|
|
u16 dpll_freq;
|
|
|
|
u16 dpll_n;
|
|
|
|
u16 dpll_ctrl_n;
|
|
|
|
u16 dpll_phase_pull_in;
|
|
|
|
u16 tod_read_primary;
|
|
|
|
u16 tod_write;
|
|
|
|
u16 tod_n;
|
|
|
|
u16 hw_dpll_n;
|
2021-09-14 04:12:33 +08:00
|
|
|
u8 sync_src;
|
2021-09-14 04:12:34 +08:00
|
|
|
enum ptp_pll_mode mode;
|
|
|
|
int (*configure_write_frequency)(struct idtcm_channel *channel);
|
|
|
|
int (*configure_write_phase)(struct idtcm_channel *channel);
|
|
|
|
int (*do_phase_pull_in)(struct idtcm_channel *channel,
|
|
|
|
s32 offset_ns, u32 max_ffo_ppb);
|
|
|
|
s32 current_freq_scaled_ppm;
|
|
|
|
bool phase_pull_in;
|
2021-09-25 03:01:32 +08:00
|
|
|
u32 dco_delay;
|
|
|
|
/* last input trigger for extts */
|
|
|
|
u8 refn;
|
2020-07-29 04:00:30 +08:00
|
|
|
u8 pll;
|
2019-11-01 11:20:07 +08:00
|
|
|
u16 output_mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct idtcm {
|
2020-07-29 04:00:30 +08:00
|
|
|
struct idtcm_channel channel[MAX_TOD];
|
2021-09-25 03:01:32 +08:00
|
|
|
struct device *dev;
|
2020-07-29 04:00:30 +08:00
|
|
|
u8 tod_mask;
|
|
|
|
char version[16];
|
2021-09-14 04:12:33 +08:00
|
|
|
enum fw_version fw_ver;
|
2021-09-25 03:01:32 +08:00
|
|
|
/* Polls for external time stamps */
|
|
|
|
u8 extts_mask;
|
|
|
|
struct delayed_work extts_work;
|
|
|
|
/* Remember the ptp channel to report extts */
|
|
|
|
struct idtcm_channel *event_channel[MAX_TOD];
|
|
|
|
/* Mutex to protect operations from being interrupted */
|
|
|
|
struct mutex *lock;
|
|
|
|
struct device *mfd;
|
|
|
|
struct regmap *regmap;
|
2019-11-01 11:20:07 +08:00
|
|
|
/* Overhead calculation for adjtime */
|
|
|
|
u8 calculate_overhead_flag;
|
|
|
|
s64 tod_write_overhead_ns;
|
|
|
|
ktime_t start_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct idtcm_fwrc {
|
|
|
|
u8 hiaddr;
|
|
|
|
u8 loaddr;
|
|
|
|
u8 value;
|
|
|
|
u8 reserved;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#endif /* PTP_IDTCLOCKMATRIX_H */
|