Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
0002 /*
0003  * DSA driver for:
0004  * Hirschmann Hellcreek TSN switch.
0005  *
0006  * Copyright (C) 2019,2020 Hochschule Offenburg
0007  * Copyright (C) 2019,2020 Linutronix GmbH
0008  * Authors: Kurt Kanzenbach <kurt@linutronix.de>
0009  *      Kamil Alkhouri <kamil.alkhouri@hs-offenburg.de>
0010  */
0011 
0012 #ifndef _HELLCREEK_PTP_H_
0013 #define _HELLCREEK_PTP_H_
0014 
0015 #include <linux/bitops.h>
0016 #include <linux/ptp_clock_kernel.h>
0017 
0018 #include "hellcreek.h"
0019 
0020 /* Every jump in time is 7 ns */
0021 #define MAX_NS_PER_STEP         7L
0022 
0023 /* Correct offset at every clock cycle */
0024 #define MIN_CLK_CYCLES_BETWEEN_STEPS    0
0025 
0026 /* Maximum available slow offset resources */
0027 #define MAX_SLOW_OFFSET_ADJ                 \
0028     ((unsigned long long)((1 << 30) - 1) * MAX_NS_PER_STEP)
0029 
0030 /* four times a second overflow check */
0031 #define HELLCREEK_OVERFLOW_PERIOD   (HZ / 4)
0032 
0033 /* PTP Register */
0034 #define PR_SETTINGS_C           (0x09 * 2)
0035 #define PR_SETTINGS_C_RES3TS        BIT(4)
0036 #define PR_SETTINGS_C_TS_SRC_TK_SHIFT   8
0037 #define PR_SETTINGS_C_TS_SRC_TK_MASK    GENMASK(9, 8)
0038 #define PR_COMMAND_C            (0x0a * 2)
0039 #define PR_COMMAND_C_SS         BIT(0)
0040 
0041 #define PR_CLOCK_STATUS_C       (0x0c * 2)
0042 #define PR_CLOCK_STATUS_C_ENA_DRIFT BIT(12)
0043 #define PR_CLOCK_STATUS_C_OFS_ACT   BIT(13)
0044 #define PR_CLOCK_STATUS_C_ENA_OFS   BIT(14)
0045 
0046 #define PR_CLOCK_READ_C         (0x0d * 2)
0047 #define PR_CLOCK_WRITE_C        (0x0e * 2)
0048 #define PR_CLOCK_OFFSET_C       (0x0f * 2)
0049 #define PR_CLOCK_DRIFT_C        (0x10 * 2)
0050 
0051 #define PR_SS_FREE_DATA_C       (0x12 * 2)
0052 #define PR_SS_SYNT_DATA_C       (0x14 * 2)
0053 #define PR_SS_SYNC_DATA_C       (0x16 * 2)
0054 #define PR_SS_DRAC_DATA_C       (0x18 * 2)
0055 
0056 #define STATUS_OUT          (0x60 * 2)
0057 #define STATUS_OUT_SYNC_GOOD        BIT(0)
0058 #define STATUS_OUT_IS_GM        BIT(1)
0059 
0060 int hellcreek_ptp_setup(struct hellcreek *hellcreek);
0061 void hellcreek_ptp_free(struct hellcreek *hellcreek);
0062 u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset);
0063 void hellcreek_ptp_write(struct hellcreek *hellcreek, u16 data,
0064              unsigned int offset);
0065 u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns);
0066 
0067 #define ptp_to_hellcreek(ptp)                   \
0068     container_of(ptp, struct hellcreek, ptp_clock_info)
0069 
0070 #define dw_overflow_to_hellcreek(dw)                \
0071     container_of(dw, struct hellcreek, overflow_work)
0072 
0073 #define led_to_hellcreek(ldev, led)             \
0074     container_of(ldev, struct hellcreek, led)
0075 
0076 #endif /* _HELLCREEK_PTP_H_ */