xref: /linux/drivers/net/dsa/mv88e6xxx/ptp.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
22fa8d3afSBrandon Streiff /*
32fa8d3afSBrandon Streiff  * Marvell 88E6xxx Switch PTP support
42fa8d3afSBrandon Streiff  *
52fa8d3afSBrandon Streiff  * Copyright (c) 2008 Marvell Semiconductor
62fa8d3afSBrandon Streiff  *
72fa8d3afSBrandon Streiff  * Copyright (c) 2017 National Instruments
82fa8d3afSBrandon Streiff  *      Erik Hons <erik.hons@ni.com>
92fa8d3afSBrandon Streiff  *      Brandon Streiff <brandon.streiff@ni.com>
102fa8d3afSBrandon Streiff  *      Dane Wagner <dane.wagner@ni.com>
112fa8d3afSBrandon Streiff  */
122fa8d3afSBrandon Streiff 
132fa8d3afSBrandon Streiff #ifndef _MV88E6XXX_PTP_H
142fa8d3afSBrandon Streiff #define _MV88E6XXX_PTP_H
152fa8d3afSBrandon Streiff 
162fa8d3afSBrandon Streiff #include "chip.h"
172fa8d3afSBrandon Streiff 
182fa8d3afSBrandon Streiff /* Offset 0x00: TAI Global Config */
192fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_CFG			0x00
204eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_CAP_OVERWRITE		0x8000
214eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_CAP_CTR_START		0x4000
224eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_EVREQ_FALLING		0x2000
234eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_TRIG_ACTIVE_LO	0x1000
244eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_IRL_ENABLE		0x0400
254eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_TRIG_IRQ_EN		0x0200
264eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_EVREQ_IRQ_EN		0x0100
274eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_TRIG_LOCK		0x0080
284eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_BLOCK_UPDATE		0x0008
294eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_MULTI_PTP		0x0004
304eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_TRIG_MODE_ONESHOT	0x0002
314eb3be29SBrandon Streiff #define MV88E6XXX_TAI_CFG_TRIG_ENABLE		0x0001
322fa8d3afSBrandon Streiff 
332fa8d3afSBrandon Streiff /* Offset 0x01: Timestamp Clock Period (ps) */
342fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_CLOCK_PERIOD		0x01
352fa8d3afSBrandon Streiff 
362fa8d3afSBrandon Streiff /* Offset 0x02/0x03: Trigger Generation Amount */
372fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_GEN_AMOUNT_LO	0x02
382fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_GEN_AMOUNT_HI	0x03
392fa8d3afSBrandon Streiff 
402fa8d3afSBrandon Streiff /* Offset 0x04: Clock Compensation */
412fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_CLOCK_COMP		0x04
422fa8d3afSBrandon Streiff 
432fa8d3afSBrandon Streiff /* Offset 0x05: Trigger Configuration */
442fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_CFG			0x05
452fa8d3afSBrandon Streiff 
462fa8d3afSBrandon Streiff /* Offset 0x06: Ingress Rate Limiter Clock Generation Amount */
472fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_IRL_AMOUNT		0x06
482fa8d3afSBrandon Streiff 
492fa8d3afSBrandon Streiff /* Offset 0x07: Ingress Rate Limiter Compensation */
502fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_IRL_COMP			0x07
512fa8d3afSBrandon Streiff 
522fa8d3afSBrandon Streiff /* Offset 0x08: Ingress Rate Limiter Compensation */
532fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_IRL_COMP_PS		0x08
542fa8d3afSBrandon Streiff 
552fa8d3afSBrandon Streiff /* Offset 0x09: Event Status */
562fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_EVENT_STATUS		0x09
574eb3be29SBrandon Streiff #define MV88E6XXX_TAI_EVENT_STATUS_CAP_TRIG	0x4000
584eb3be29SBrandon Streiff #define MV88E6XXX_TAI_EVENT_STATUS_ERROR	0x0200
594eb3be29SBrandon Streiff #define MV88E6XXX_TAI_EVENT_STATUS_VALID	0x0100
604eb3be29SBrandon Streiff #define MV88E6XXX_TAI_EVENT_STATUS_CTR_MASK	0x00ff
612fa8d3afSBrandon Streiff 
622fa8d3afSBrandon Streiff /* Offset 0x0A/0x0B: Event Time */
632fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_EVENT_TIME_LO		0x0a
642fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_EVENT_TYPE_HI		0x0b
652fa8d3afSBrandon Streiff 
662fa8d3afSBrandon Streiff /* Offset 0x0E/0x0F: PTP Global Time */
672fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TIME_LO			0x0e
682fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TIME_HI			0x0f
692fa8d3afSBrandon Streiff 
702fa8d3afSBrandon Streiff /* Offset 0x10/0x11: Trig Generation Time */
712fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_TIME_LO		0x10
722fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_TRIG_TIME_HI		0x11
732fa8d3afSBrandon Streiff 
742fa8d3afSBrandon Streiff /* Offset 0x12: Lock Status */
752fa8d3afSBrandon Streiff #define MV88E6XXX_TAI_LOCK_STATUS		0x12
762fa8d3afSBrandon Streiff 
77dfa54348SAndrew Lunn /* Offset 0x00: Ether Type */
78dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_ETYPE			0x00
79dfa54348SAndrew Lunn 
80e2294a8bSAndrew Lunn /* 6165 Global Control Registers */
812dbed245SAndrew Lunn /* Offset 0x00: Ether Type */
822dbed245SAndrew Lunn #define MV88E6XXX_PTP_GC_ETYPE			0x00
832dbed245SAndrew Lunn 
84dfa54348SAndrew Lunn /* Offset 0x01: Message ID */
85dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_MESSAGE_ID		0x01
86dfa54348SAndrew Lunn 
87dfa54348SAndrew Lunn /* Offset 0x02: Time Stamp Arrive Time */
88dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_TS_ARR_PTR		0x02
89dfa54348SAndrew Lunn 
90dfa54348SAndrew Lunn /* Offset 0x03: Port Arrival Interrupt Enable */
91dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_PORT_ARR_INT_EN	0x03
92dfa54348SAndrew Lunn 
93dfa54348SAndrew Lunn /* Offset 0x04: Port Departure Interrupt Enable */
94dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_PORT_DEP_INT_EN	0x04
95dfa54348SAndrew Lunn 
96dfa54348SAndrew Lunn /* Offset 0x05: Configuration */
97dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_CONFIG			0x05
98dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_CONFIG_DIS_OVERWRITE	BIT(1)
99dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_CONFIG_DIS_TS		BIT(0)
100dfa54348SAndrew Lunn 
101dfa54348SAndrew Lunn /* Offset 0x8: Interrupt Status */
102dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_INT_STATUS		0x08
103dfa54348SAndrew Lunn 
104dfa54348SAndrew Lunn /* Offset 0x9/0xa: Global Time */
105dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_TIME_LO		0x09
106dfa54348SAndrew Lunn #define MV88E6XXX_PTP_GC_TIME_HI		0x0A
107dfa54348SAndrew Lunn 
108e2294a8bSAndrew Lunn /* 6165 Per Port Registers */
109e2294a8bSAndrew Lunn /* Offset 0: Arrival Time 0 Status */
110e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR0_STS	0x00
111e2294a8bSAndrew Lunn 
112e2294a8bSAndrew Lunn /* Offset 0x01/0x02: PTP Arrival 0 Time */
113e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR0_TIME_LO	0x01
114e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR0_TIME_HI	0x02
115e2294a8bSAndrew Lunn 
116e2294a8bSAndrew Lunn /* Offset 0x03: PTP Arrival 0 Sequence ID */
117e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR0_SEQID	0x03
118e2294a8bSAndrew Lunn 
119e2294a8bSAndrew Lunn /* Offset 0x04: PTP Arrival 1 Status */
120e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR1_STS	0x04
121e2294a8bSAndrew Lunn 
122e2294a8bSAndrew Lunn /* Offset 0x05/0x6E: PTP Arrival 1 Time */
123e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR1_TIME_LO	0x05
124e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR1_TIME_HI	0x06
125e2294a8bSAndrew Lunn 
126e2294a8bSAndrew Lunn /* Offset 0x07: PTP Arrival 1 Sequence ID */
127e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_ARR1_SEQID	0x07
128e2294a8bSAndrew Lunn 
129e2294a8bSAndrew Lunn /* Offset 0x08: PTP Departure Status */
130e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_DEP_STS	0x08
131e2294a8bSAndrew Lunn 
132e2294a8bSAndrew Lunn /* Offset 0x09/0x0a: PTP Deperture Time */
133e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_DEP_TIME_LO	0x09
134e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_DEP_TIME_HI	0x0a
135e2294a8bSAndrew Lunn 
136e2294a8bSAndrew Lunn /* Offset 0x0b: PTP Departure Sequence ID */
137e2294a8bSAndrew Lunn #define MV88E6165_PORT_PTP_DEP_SEQID	0x0b
138e2294a8bSAndrew Lunn 
139e2294a8bSAndrew Lunn /* Offset 0x0d: Port Status */
140e2294a8bSAndrew Lunn #define MV88E6164_PORT_STATUS		0x0d
141e2294a8bSAndrew Lunn 
1422fa8d3afSBrandon Streiff #ifdef CONFIG_NET_DSA_MV88E6XXX_PTP
1432fa8d3afSBrandon Streiff 
144c6fe0ad2SBrandon Streiff long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp);
1452fa8d3afSBrandon Streiff int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip);
1462fa8d3afSBrandon Streiff void mv88e6xxx_ptp_free(struct mv88e6xxx_chip *chip);
1472fa8d3afSBrandon Streiff 
148c6fe0ad2SBrandon Streiff #define ptp_to_chip(ptp) container_of(ptp, struct mv88e6xxx_chip,	\
149c6fe0ad2SBrandon Streiff 				      ptp_clock_info)
150c6fe0ad2SBrandon Streiff 
151dfa54348SAndrew Lunn extern const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops;
15271509614SHubert Feurstein extern const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops;
1538858ccc8SHubert Feurstein extern const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops;
154*9627c981SKurt Kanzenbach extern const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops;
1556d2ac8eeSAndrew Lunn 
1562fa8d3afSBrandon Streiff #else /* !CONFIG_NET_DSA_MV88E6XXX_PTP */
1572fa8d3afSBrandon Streiff 
mv88e6xxx_hwtstamp_work(struct ptp_clock_info * ptp)15846182452SArnd Bergmann static inline long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp)
159c6fe0ad2SBrandon Streiff {
160c6fe0ad2SBrandon Streiff 	return -1;
161c6fe0ad2SBrandon Streiff }
162c6fe0ad2SBrandon Streiff 
mv88e6xxx_ptp_setup(struct mv88e6xxx_chip * chip)1632fa8d3afSBrandon Streiff static inline int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
1642fa8d3afSBrandon Streiff {
1652fa8d3afSBrandon Streiff 	return 0;
1662fa8d3afSBrandon Streiff }
1672fa8d3afSBrandon Streiff 
mv88e6xxx_ptp_free(struct mv88e6xxx_chip * chip)16846182452SArnd Bergmann static inline void mv88e6xxx_ptp_free(struct mv88e6xxx_chip *chip)
1692fa8d3afSBrandon Streiff {
1702fa8d3afSBrandon Streiff }
1712fa8d3afSBrandon Streiff 
172dfa54348SAndrew Lunn static const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {};
17371509614SHubert Feurstein static const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {};
1748858ccc8SHubert Feurstein static const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {};
175*9627c981SKurt Kanzenbach static const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {};
1766d2ac8eeSAndrew Lunn 
1772fa8d3afSBrandon Streiff #endif /* CONFIG_NET_DSA_MV88E6XXX_PTP */
1782fa8d3afSBrandon Streiff 
1792fa8d3afSBrandon Streiff #endif /* _MV88E6XXX_PTP_H */
180