77 lines · c
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 Offenburg7 * Copyright (C) 2019,2020 Linutronix GmbH8 * Authors: Kurt Kanzenbach <kurt@linutronix.de>9 * Kamil Alkhouri <kamil.alkhouri@hs-offenburg.de>10 */11 12#ifndef _HELLCREEK_PTP_H_13#define _HELLCREEK_PTP_H_14 15#include <linux/bitops.h>16#include <linux/ptp_clock_kernel.h>17 18#include "hellcreek.h"19 20/* Every jump in time is 7 ns */21#define MAX_NS_PER_STEP 7L22 23/* Correct offset at every clock cycle */24#define MIN_CLK_CYCLES_BETWEEN_STEPS 025 26/* Maximum available slow offset resources */27#define MAX_SLOW_OFFSET_ADJ \28 ((unsigned long long)((1 << 30) - 1) * MAX_NS_PER_STEP)29 30/* four times a second overflow check */31#define HELLCREEK_OVERFLOW_PERIOD (HZ / 4)32 33/* PTP Register */34#define PR_SETTINGS_C (0x09 * 2)35#define PR_SETTINGS_C_RES3TS BIT(4)36#define PR_SETTINGS_C_TS_SRC_TK_SHIFT 837#define PR_SETTINGS_C_TS_SRC_TK_MASK GENMASK(9, 8)38#define PR_COMMAND_C (0x0a * 2)39#define PR_COMMAND_C_SS BIT(0)40 41#define PR_CLOCK_STATUS_C (0x0c * 2)42#define PR_CLOCK_STATUS_C_ENA_DRIFT BIT(12)43#define PR_CLOCK_STATUS_C_OFS_ACT BIT(13)44#define PR_CLOCK_STATUS_C_ENA_OFS BIT(14)45 46#define PR_CLOCK_READ_C (0x0d * 2)47#define PR_CLOCK_WRITE_C (0x0e * 2)48#define PR_CLOCK_OFFSET_C (0x0f * 2)49#define PR_CLOCK_DRIFT_C (0x10 * 2)50 51#define PR_SS_FREE_DATA_C (0x12 * 2)52#define PR_SS_SYNT_DATA_C (0x14 * 2)53#define PR_SS_SYNC_DATA_C (0x16 * 2)54#define PR_SS_DRAC_DATA_C (0x18 * 2)55 56#define STATUS_OUT (0x60 * 2)57#define STATUS_OUT_SYNC_GOOD BIT(0)58#define STATUS_OUT_IS_GM BIT(1)59 60int hellcreek_ptp_setup(struct hellcreek *hellcreek);61void hellcreek_ptp_free(struct hellcreek *hellcreek);62u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset);63void hellcreek_ptp_write(struct hellcreek *hellcreek, u16 data,64 unsigned int offset);65u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns);66 67#define ptp_to_hellcreek(ptp) \68 container_of(ptp, struct hellcreek, ptp_clock_info)69 70#define dw_overflow_to_hellcreek(dw) \71 container_of(dw, struct hellcreek, overflow_work)72 73#define led_to_hellcreek(ldev, led) \74 container_of(ldev, struct hellcreek, led)75 76#endif /* _HELLCREEK_PTP_H_ */77