162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * PTP 1588 clock using the IXP46X
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2010 OMICRON electronics GmbH
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _IXP46X_TS_H_
962306a36Sopenharmony_ci#define _IXP46X_TS_H_
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define DEFAULT_ADDEND 0xF0000029
1262306a36Sopenharmony_ci#define TICKS_NS_SHIFT 4
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistruct ixp46x_channel_ctl {
1562306a36Sopenharmony_ci	u32 ch_control;  /* 0x40 Time Synchronization Channel Control */
1662306a36Sopenharmony_ci	u32 ch_event;    /* 0x44 Time Synchronization Channel Event */
1762306a36Sopenharmony_ci	u32 tx_snap_lo;  /* 0x48 Transmit Snapshot Low Register */
1862306a36Sopenharmony_ci	u32 tx_snap_hi;  /* 0x4C Transmit Snapshot High Register */
1962306a36Sopenharmony_ci	u32 rx_snap_lo;  /* 0x50 Receive Snapshot Low Register */
2062306a36Sopenharmony_ci	u32 rx_snap_hi;  /* 0x54 Receive Snapshot High Register */
2162306a36Sopenharmony_ci	u32 src_uuid_lo; /* 0x58 Source UUID0 Low Register */
2262306a36Sopenharmony_ci	u32 src_uuid_hi; /* 0x5C Sequence Identifier/Source UUID0 High */
2362306a36Sopenharmony_ci};
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cistruct ixp46x_ts_regs {
2662306a36Sopenharmony_ci	u32 control;     /* 0x00 Time Sync Control Register */
2762306a36Sopenharmony_ci	u32 event;       /* 0x04 Time Sync Event Register */
2862306a36Sopenharmony_ci	u32 addend;      /* 0x08 Time Sync Addend Register */
2962306a36Sopenharmony_ci	u32 accum;       /* 0x0C Time Sync Accumulator Register */
3062306a36Sopenharmony_ci	u32 test;        /* 0x10 Time Sync Test Register */
3162306a36Sopenharmony_ci	u32 unused;      /* 0x14 */
3262306a36Sopenharmony_ci	u32 rsystime_lo; /* 0x18 RawSystemTime_Low Register */
3362306a36Sopenharmony_ci	u32 rsystime_hi; /* 0x1C RawSystemTime_High Register */
3462306a36Sopenharmony_ci	u32 systime_lo;  /* 0x20 SystemTime_Low Register */
3562306a36Sopenharmony_ci	u32 systime_hi;  /* 0x24 SystemTime_High Register */
3662306a36Sopenharmony_ci	u32 trgt_lo;     /* 0x28 TargetTime_Low Register */
3762306a36Sopenharmony_ci	u32 trgt_hi;     /* 0x2C TargetTime_High Register */
3862306a36Sopenharmony_ci	u32 asms_lo;     /* 0x30 Auxiliary Slave Mode Snapshot Low  */
3962306a36Sopenharmony_ci	u32 asms_hi;     /* 0x34 Auxiliary Slave Mode Snapshot High */
4062306a36Sopenharmony_ci	u32 amms_lo;     /* 0x38 Auxiliary Master Mode Snapshot Low */
4162306a36Sopenharmony_ci	u32 amms_hi;     /* 0x3C Auxiliary Master Mode Snapshot High */
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	struct ixp46x_channel_ctl channel[3];
4462306a36Sopenharmony_ci};
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* 0x00 Time Sync Control Register Bits */
4762306a36Sopenharmony_ci#define TSCR_AMM (1<<3)
4862306a36Sopenharmony_ci#define TSCR_ASM (1<<2)
4962306a36Sopenharmony_ci#define TSCR_TTM (1<<1)
5062306a36Sopenharmony_ci#define TSCR_RST (1<<0)
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* 0x04 Time Sync Event Register Bits */
5362306a36Sopenharmony_ci#define TSER_SNM (1<<3)
5462306a36Sopenharmony_ci#define TSER_SNS (1<<2)
5562306a36Sopenharmony_ci#define TTIPEND  (1<<1)
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* 0x40 Time Synchronization Channel Control Register Bits */
5862306a36Sopenharmony_ci#define MASTER_MODE   (1<<0)
5962306a36Sopenharmony_ci#define TIMESTAMP_ALL (1<<1)
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* 0x44 Time Synchronization Channel Event Register Bits */
6262306a36Sopenharmony_ci#define TX_SNAPSHOT_LOCKED (1<<0)
6362306a36Sopenharmony_ci#define RX_SNAPSHOT_LOCKED (1<<1)
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_PTP_1588_CLOCK_IXP46X)
6662306a36Sopenharmony_ciint ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index);
6762306a36Sopenharmony_ci#else
6862306a36Sopenharmony_cistatic inline int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	*regs = NULL;
7162306a36Sopenharmony_ci	*phc_index = -1;
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	return -ENODEV;
7462306a36Sopenharmony_ci}
7562306a36Sopenharmony_ci#endif
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#endif
78