162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Microsemi Ocelot Switch driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * License: Dual MIT/GPL
662306a36Sopenharmony_ci * Copyright (c) 2017 Microsemi Corporation
762306a36Sopenharmony_ci * Copyright 2020 NXP
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _MSCC_OCELOT_PTP_H_
1162306a36Sopenharmony_ci#define _MSCC_OCELOT_PTP_H_
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/ptp_clock_kernel.h>
1462306a36Sopenharmony_ci#include <soc/mscc/ocelot.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define OCELOT_MAX_PTP_ID		63
1762306a36Sopenharmony_ci#define OCELOT_PTP_FIFO_SIZE		128
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define PTP_PIN_CFG_RSZ			0x20
2062306a36Sopenharmony_ci#define PTP_PIN_TOD_SEC_MSB_RSZ		PTP_PIN_CFG_RSZ
2162306a36Sopenharmony_ci#define PTP_PIN_TOD_SEC_LSB_RSZ		PTP_PIN_CFG_RSZ
2262306a36Sopenharmony_ci#define PTP_PIN_TOD_NSEC_RSZ		PTP_PIN_CFG_RSZ
2362306a36Sopenharmony_ci#define PTP_PIN_WF_HIGH_PERIOD_RSZ	PTP_PIN_CFG_RSZ
2462306a36Sopenharmony_ci#define PTP_PIN_WF_LOW_PERIOD_RSZ	PTP_PIN_CFG_RSZ
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define PTP_PIN_CFG_DOM			BIT(0)
2762306a36Sopenharmony_ci#define PTP_PIN_CFG_SYNC		BIT(2)
2862306a36Sopenharmony_ci#define PTP_PIN_CFG_ACTION(x)		((x) << 3)
2962306a36Sopenharmony_ci#define PTP_PIN_CFG_ACTION_MASK		PTP_PIN_CFG_ACTION(0x7)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cienum {
3262306a36Sopenharmony_ci	PTP_PIN_ACTION_IDLE = 0,
3362306a36Sopenharmony_ci	PTP_PIN_ACTION_LOAD,
3462306a36Sopenharmony_ci	PTP_PIN_ACTION_SAVE,
3562306a36Sopenharmony_ci	PTP_PIN_ACTION_CLOCK,
3662306a36Sopenharmony_ci	PTP_PIN_ACTION_DELTA,
3762306a36Sopenharmony_ci	PTP_PIN_ACTION_NOSYNC,
3862306a36Sopenharmony_ci	PTP_PIN_ACTION_SYNC,
3962306a36Sopenharmony_ci};
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define PTP_CFG_MISC_PTP_EN		BIT(2)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define PTP_CFG_CLK_ADJ_CFG_ENA		BIT(0)
4462306a36Sopenharmony_ci#define PTP_CFG_CLK_ADJ_CFG_DIR		BIT(1)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define PTP_CFG_CLK_ADJ_FREQ_NS		BIT(30)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciint ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
4962306a36Sopenharmony_ciint ocelot_ptp_settime64(struct ptp_clock_info *ptp,
5062306a36Sopenharmony_ci			 const struct timespec64 *ts);
5162306a36Sopenharmony_ciint ocelot_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta);
5262306a36Sopenharmony_ciint ocelot_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm);
5362306a36Sopenharmony_ciint ocelot_ptp_verify(struct ptp_clock_info *ptp, unsigned int pin,
5462306a36Sopenharmony_ci		      enum ptp_pin_function func, unsigned int chan);
5562306a36Sopenharmony_ciint ocelot_ptp_enable(struct ptp_clock_info *ptp,
5662306a36Sopenharmony_ci		      struct ptp_clock_request *rq, int on);
5762306a36Sopenharmony_ciint ocelot_init_timestamp(struct ocelot *ocelot,
5862306a36Sopenharmony_ci			  const struct ptp_clock_info *info);
5962306a36Sopenharmony_ciint ocelot_deinit_timestamp(struct ocelot *ocelot);
6062306a36Sopenharmony_ci#endif
61