1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * PTP hardware clock driver for the IDT ClockMatrix(TM) family of timing and
4 * synchronization devices.
6 * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
8 #ifndef PTP_IDTCLOCKMATRIX_H
9 #define PTP_IDTCLOCKMATRIX_H
11 #include <linux/ktime.h>
13 #include "idt8a340_reg.h"
15 #define FW_FILENAME "idtcm.bin"
18 #define MAX_ABS_WRITE_PHASE_PICOSECONDS (107374182350LL)
20 #define PLL_MASK_ADDR (0xFFA5)
21 #define DEFAULT_PLL_MASK (0x04)
23 #define SET_U16_LSB(orig, val8) (orig = (0xff00 & (orig)) | (val8))
24 #define SET_U16_MSB(orig, val8) (orig = (0x00ff & (orig)) | (val8 << 8))
26 #define OUTPUT_MASK_PLL0_ADDR (0xFFB0)
27 #define OUTPUT_MASK_PLL1_ADDR (0xFFB2)
28 #define OUTPUT_MASK_PLL2_ADDR (0xFFB4)
29 #define OUTPUT_MASK_PLL3_ADDR (0xFFB6)
31 #define DEFAULT_OUTPUT_MASK_PLL0 (0x003)
32 #define DEFAULT_OUTPUT_MASK_PLL1 (0x00c)
33 #define DEFAULT_OUTPUT_MASK_PLL2 (0x030)
34 #define DEFAULT_OUTPUT_MASK_PLL3 (0x0c0)
36 #define POST_SM_RESET_DELAY_MS (3000)
37 #define PHASE_PULL_IN_THRESHOLD_NS (150000)
38 #define TOD_WRITE_OVERHEAD_COUNT_MAX (5)
39 #define TOD_BYTE_COUNT (11)
40 #define WR_PHASE_SETUP_MS (5000)
42 /* Values of DPLL_N.DPLL_MODE.PLL_MODE */
45 PLL_MODE_NORMAL = PLL_MODE_MIN,
46 PLL_MODE_WRITE_PHASE = 1,
47 PLL_MODE_WRITE_FREQUENCY = 2,
48 PLL_MODE_GPIO_INC_DEC = 3,
49 PLL_MODE_SYNTHESIS = 4,
50 PLL_MODE_PHASE_MEASUREMENT = 5,
51 PLL_MODE_MAX = PLL_MODE_PHASE_MEASUREMENT,
54 enum hw_tod_write_trig_sel {
55 HW_TOD_WR_TRIG_SEL_MIN = 0,
56 HW_TOD_WR_TRIG_SEL_MSB = HW_TOD_WR_TRIG_SEL_MIN,
57 HW_TOD_WR_TRIG_SEL_RESERVED = 1,
58 HW_TOD_WR_TRIG_SEL_TOD_PPS = 2,
59 HW_TOD_WR_TRIG_SEL_IRIGB_PPS = 3,
60 HW_TOD_WR_TRIG_SEL_PWM_PPS = 4,
61 HW_TOD_WR_TRIG_SEL_GPIO = 5,
62 HW_TOD_WR_TRIG_SEL_FOD_SYNC = 6,
63 WR_TRIG_SEL_MAX = HW_TOD_WR_TRIG_SEL_FOD_SYNC,
68 struct idtcm_channel {
69 struct ptp_clock_info caps;
70 struct ptp_clock *ptp_clock;
76 u16 dpll_phase_pull_in;
81 enum pll_mode pll_mode;
83 int write_phase_ready;
87 struct idtcm_channel channel[MAX_PHC_PLL];
88 struct i2c_client *client;
92 /* Overhead calculation for adjtime */
93 u8 calculate_overhead_flag;
94 s64 tod_write_overhead_ns;
97 /* Protects I2C read/modify/write registers from concurrent access */
98 struct mutex reg_lock;
108 #endif /* PTP_IDTCLOCKMATRIX_H */