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