1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * PTP hardware clock driver for the IDT 82P33XXX family of clocks.
5 * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
10 #include <linux/ktime.h>
11 #include <linux/mfd/idt82p33_reg.h>
12 #include <linux/regmap.h>
14 #define FW_FILENAME "idt82p33xxx.bin"
15 #define MAX_PHC_PLL (2)
16 #define MAX_TRIG_CLK (3)
17 #define MAX_PER_OUT (11)
18 #define TOD_BYTE_COUNT (10)
19 #define DCO_MAX_PPB (92000)
20 #define MAX_MEASURMENT_COUNT (5)
21 #define SNAP_THRESHOLD_NS (10000)
22 #define IMMEDIATE_SNAP_THRESHOLD_NS (50000)
23 #define DDCO_THRESHOLD_NS (5)
24 #define IDT82P33_MAX_WRITE_COUNT (512)
26 #define PLLMASK_ADDR_HI 0xFF
27 #define PLLMASK_ADDR_LO 0xA5
29 #define PLL0_OUTMASK_ADDR_HI 0xFF
30 #define PLL0_OUTMASK_ADDR_LO 0xB0
32 #define PLL1_OUTMASK_ADDR_HI 0xFF
33 #define PLL1_OUTMASK_ADDR_LO 0xB2
35 #define PLL2_OUTMASK_ADDR_HI 0xFF
36 #define PLL2_OUTMASK_ADDR_LO 0xB4
38 #define PLL3_OUTMASK_ADDR_HI 0xFF
39 #define PLL3_OUTMASK_ADDR_LO 0xB6
41 #define DEFAULT_PLL_MASK (0x01)
42 #define DEFAULT_OUTPUT_MASK_PLL0 (0xc0)
43 #define DEFAULT_OUTPUT_MASK_PLL1 DEFAULT_OUTPUT_MASK_PLL0
46 * @brief Maximum absolute value for write phase offset in nanoseconds
48 #define WRITE_PHASE_OFFSET_LIMIT (20000l)
50 /** @brief Phase offset resolution
52 * DPLL phase offset = 10^15 fs / ( System Clock * 2^13)
53 * = 10^15 fs / ( 1638400000 * 2^23)
54 * = 74.5058059692382 fs
56 #define IDT_T0DPLL_PHASE_RESOL 74506
58 /* PTP Hardware Clock interface */
59 struct idt82p33_channel {
60 struct ptp_clock_info caps;
61 struct ptp_clock *ptp_clock;
62 struct idt82p33 *idt82p33;
63 enum pll_mode pll_mode;
64 /* Workaround for TOD-to-output alignment issue */
65 struct delayed_work adjtime_work;
70 /* last input trigger for extts */
72 bool discard_next_extts;
74 /* remember last tod_sts for extts */
75 u8 extts_tod_sts[TOD_BYTE_COUNT];
83 u16 dpll_input_mode_cnfg;
87 struct idt82p33_channel channel[MAX_PHC_PLL];
90 /* Polls for external time stamps */
92 bool extts_single_shot;
93 struct delayed_work extts_work;
94 /* Remember the ptp channel to report extts */
95 struct idt82p33_channel *event_channel[MAX_PHC_PLL];
96 /* Mutex to protect operations from being interrupted */
98 struct regmap *regmap;
100 /* Overhead calculation for adjtime */
102 int calculate_overhead_flag;
103 s64 tod_write_overhead_ns;
106 /* firmware interface */
107 struct idt82p33_fwrc {
114 #endif /* PTP_IDT82P33_H */