ptp_idt82p33.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * PTP hardware clock driver for the IDT 82P33XXX family of clocks.
  4. *
  5. * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
  6. */
  7. #ifndef PTP_IDT82P33_H
  8. #define PTP_IDT82P33_H
  9. #include <linux/ktime.h>
  10. #include <linux/mfd/idt82p33_reg.h>
  11. #include <linux/regmap.h>
  12. #define FW_FILENAME "idt82p33xxx.bin"
  13. #define MAX_PHC_PLL (2)
  14. #define MAX_TRIG_CLK (3)
  15. #define MAX_PER_OUT (11)
  16. #define TOD_BYTE_COUNT (10)
  17. #define DCO_MAX_PPB (92000)
  18. #define MAX_MEASURMENT_COUNT (5)
  19. #define SNAP_THRESHOLD_NS (10000)
  20. #define IMMEDIATE_SNAP_THRESHOLD_NS (50000)
  21. #define DDCO_THRESHOLD_NS (5)
  22. #define IDT82P33_MAX_WRITE_COUNT (512)
  23. #define PLLMASK_ADDR_HI 0xFF
  24. #define PLLMASK_ADDR_LO 0xA5
  25. #define PLL0_OUTMASK_ADDR_HI 0xFF
  26. #define PLL0_OUTMASK_ADDR_LO 0xB0
  27. #define PLL1_OUTMASK_ADDR_HI 0xFF
  28. #define PLL1_OUTMASK_ADDR_LO 0xB2
  29. #define PLL2_OUTMASK_ADDR_HI 0xFF
  30. #define PLL2_OUTMASK_ADDR_LO 0xB4
  31. #define PLL3_OUTMASK_ADDR_HI 0xFF
  32. #define PLL3_OUTMASK_ADDR_LO 0xB6
  33. #define DEFAULT_PLL_MASK (0x01)
  34. #define DEFAULT_OUTPUT_MASK_PLL0 (0xc0)
  35. #define DEFAULT_OUTPUT_MASK_PLL1 DEFAULT_OUTPUT_MASK_PLL0
  36. /**
  37. * @brief Maximum absolute value for write phase offset in nanoseconds
  38. */
  39. #define WRITE_PHASE_OFFSET_LIMIT (20000l)
  40. /** @brief Phase offset resolution
  41. *
  42. * DPLL phase offset = 10^15 fs / ( System Clock * 2^13)
  43. * = 10^15 fs / ( 1638400000 * 2^23)
  44. * = 74.5058059692382 fs
  45. */
  46. #define IDT_T0DPLL_PHASE_RESOL 74506
  47. /* PTP Hardware Clock interface */
  48. struct idt82p33_channel {
  49. struct ptp_clock_info caps;
  50. struct ptp_clock *ptp_clock;
  51. struct idt82p33 *idt82p33;
  52. enum pll_mode pll_mode;
  53. /* Workaround for TOD-to-output alignment issue */
  54. struct delayed_work adjtime_work;
  55. s32 current_freq;
  56. /* double dco mode */
  57. bool ddco;
  58. u8 output_mask;
  59. /* last input trigger for extts */
  60. u8 tod_trigger;
  61. bool discard_next_extts;
  62. u8 plln;
  63. /* remember last tod_sts for extts */
  64. u8 extts_tod_sts[TOD_BYTE_COUNT];
  65. u16 dpll_tod_cnfg;
  66. u16 dpll_tod_trigger;
  67. u16 dpll_tod_sts;
  68. u16 dpll_mode_cnfg;
  69. u16 dpll_freq_cnfg;
  70. u16 dpll_phase_cnfg;
  71. u16 dpll_sync_cnfg;
  72. u16 dpll_input_mode_cnfg;
  73. };
  74. struct idt82p33 {
  75. struct idt82p33_channel channel[MAX_PHC_PLL];
  76. struct device *dev;
  77. u8 pll_mask;
  78. /* Polls for external time stamps */
  79. u8 extts_mask;
  80. bool extts_single_shot;
  81. struct delayed_work extts_work;
  82. /* Remember the ptp channel to report extts */
  83. struct idt82p33_channel *event_channel[MAX_PHC_PLL];
  84. /* Mutex to protect operations from being interrupted */
  85. struct mutex *lock;
  86. struct regmap *regmap;
  87. struct device *mfd;
  88. /* Overhead calculation for adjtime */
  89. ktime_t start_time;
  90. int calculate_overhead_flag;
  91. s64 tod_write_overhead_ns;
  92. };
  93. /* firmware interface */
  94. struct idt82p33_fwrc {
  95. u8 hiaddr;
  96. u8 loaddr;
  97. u8 value;
  98. u8 reserved;
  99. } __packed;
  100. #endif /* PTP_IDT82P33_H */