hellcreek_ptp.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
  2. /*
  3. * DSA driver for:
  4. * Hirschmann Hellcreek TSN switch.
  5. *
  6. * Copyright (C) 2019,2020 Hochschule Offenburg
  7. * Copyright (C) 2019,2020 Linutronix GmbH
  8. * Authors: Kurt Kanzenbach <[email protected]>
  9. * Kamil Alkhouri <[email protected]>
  10. */
  11. #ifndef _HELLCREEK_PTP_H_
  12. #define _HELLCREEK_PTP_H_
  13. #include <linux/bitops.h>
  14. #include <linux/ptp_clock_kernel.h>
  15. #include "hellcreek.h"
  16. /* Every jump in time is 7 ns */
  17. #define MAX_NS_PER_STEP 7L
  18. /* Correct offset at every clock cycle */
  19. #define MIN_CLK_CYCLES_BETWEEN_STEPS 0
  20. /* Maximum available slow offset resources */
  21. #define MAX_SLOW_OFFSET_ADJ \
  22. ((unsigned long long)((1 << 30) - 1) * MAX_NS_PER_STEP)
  23. /* four times a second overflow check */
  24. #define HELLCREEK_OVERFLOW_PERIOD (HZ / 4)
  25. /* PTP Register */
  26. #define PR_SETTINGS_C (0x09 * 2)
  27. #define PR_SETTINGS_C_RES3TS BIT(4)
  28. #define PR_SETTINGS_C_TS_SRC_TK_SHIFT 8
  29. #define PR_SETTINGS_C_TS_SRC_TK_MASK GENMASK(9, 8)
  30. #define PR_COMMAND_C (0x0a * 2)
  31. #define PR_COMMAND_C_SS BIT(0)
  32. #define PR_CLOCK_STATUS_C (0x0c * 2)
  33. #define PR_CLOCK_STATUS_C_ENA_DRIFT BIT(12)
  34. #define PR_CLOCK_STATUS_C_OFS_ACT BIT(13)
  35. #define PR_CLOCK_STATUS_C_ENA_OFS BIT(14)
  36. #define PR_CLOCK_READ_C (0x0d * 2)
  37. #define PR_CLOCK_WRITE_C (0x0e * 2)
  38. #define PR_CLOCK_OFFSET_C (0x0f * 2)
  39. #define PR_CLOCK_DRIFT_C (0x10 * 2)
  40. #define PR_SS_FREE_DATA_C (0x12 * 2)
  41. #define PR_SS_SYNT_DATA_C (0x14 * 2)
  42. #define PR_SS_SYNC_DATA_C (0x16 * 2)
  43. #define PR_SS_DRAC_DATA_C (0x18 * 2)
  44. #define STATUS_OUT (0x60 * 2)
  45. #define STATUS_OUT_SYNC_GOOD BIT(0)
  46. #define STATUS_OUT_IS_GM BIT(1)
  47. int hellcreek_ptp_setup(struct hellcreek *hellcreek);
  48. void hellcreek_ptp_free(struct hellcreek *hellcreek);
  49. u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset);
  50. void hellcreek_ptp_write(struct hellcreek *hellcreek, u16 data,
  51. unsigned int offset);
  52. u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns);
  53. #define ptp_to_hellcreek(ptp) \
  54. container_of(ptp, struct hellcreek, ptp_clock_info)
  55. #define dw_overflow_to_hellcreek(dw) \
  56. container_of(dw, struct hellcreek, overflow_work)
  57. #define led_to_hellcreek(ldev, led) \
  58. container_of(ldev, struct hellcreek, led)
  59. #endif /* _HELLCREEK_PTP_H_ */