0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _TI_CPTS_H_
0009 #define _TI_CPTS_H_
0010
0011 #if IS_ENABLED(CONFIG_TI_CPTS)
0012
0013 #include <linux/clk.h>
0014 #include <linux/clkdev.h>
0015 #include <linux/clocksource.h>
0016 #include <linux/device.h>
0017 #include <linux/list.h>
0018 #include <linux/of.h>
0019 #include <linux/ptp_clock_kernel.h>
0020 #include <linux/skbuff.h>
0021 #include <linux/ptp_classify.h>
0022 #include <linux/timecounter.h>
0023
0024 struct cpsw_cpts {
0025 u32 idver;
0026 u32 control;
0027 u32 rftclk_sel;
0028 u32 ts_push;
0029 u32 ts_load_val;
0030 u32 ts_load_en;
0031 u32 res2[2];
0032 u32 intstat_raw;
0033 u32 intstat_masked;
0034 u32 int_enable;
0035 u32 res3;
0036 u32 event_pop;
0037 u32 event_low;
0038 u32 event_high;
0039 };
0040
0041
0042 #define TX_IDENT_SHIFT (16)
0043 #define TX_IDENT_MASK (0xffff)
0044 #define RTL_VER_SHIFT (11)
0045 #define RTL_VER_MASK (0x1f)
0046 #define MAJOR_VER_SHIFT (8)
0047 #define MAJOR_VER_MASK (0x7)
0048 #define MINOR_VER_SHIFT (0)
0049 #define MINOR_VER_MASK (0xff)
0050
0051
0052 #define HW4_TS_PUSH_EN (1<<11)
0053 #define HW3_TS_PUSH_EN (1<<10)
0054 #define HW2_TS_PUSH_EN (1<<9)
0055 #define HW1_TS_PUSH_EN (1<<8)
0056 #define INT_TEST (1<<1)
0057 #define CPTS_EN (1<<0)
0058
0059
0060
0061
0062
0063 #define TS_PUSH (1<<0)
0064 #define TS_LOAD_EN (1<<0)
0065 #define TS_PEND_RAW (1<<0)
0066 #define TS_PEND (1<<0)
0067 #define TS_PEND_EN (1<<0)
0068 #define EVENT_POP (1<<0)
0069
0070
0071 #define PORT_NUMBER_SHIFT (24)
0072 #define PORT_NUMBER_MASK (0x1f)
0073 #define EVENT_TYPE_SHIFT (20)
0074 #define EVENT_TYPE_MASK (0xf)
0075 #define MESSAGE_TYPE_SHIFT (16)
0076 #define MESSAGE_TYPE_MASK (0xf)
0077 #define SEQUENCE_ID_SHIFT (0)
0078 #define SEQUENCE_ID_MASK (0xffff)
0079
0080 enum {
0081 CPTS_EV_PUSH,
0082 CPTS_EV_ROLL,
0083 CPTS_EV_HALF,
0084 CPTS_EV_HW,
0085 CPTS_EV_RX,
0086 CPTS_EV_TX,
0087 };
0088
0089 #define CPTS_FIFO_DEPTH 16
0090 #define CPTS_MAX_EVENTS 32
0091
0092 struct cpts_event {
0093 struct list_head list;
0094 unsigned long tmo;
0095 u32 high;
0096 u32 low;
0097 u64 timestamp;
0098 };
0099
0100 struct cpts {
0101 struct device *dev;
0102 struct cpsw_cpts __iomem *reg;
0103 int tx_enable;
0104 int rx_enable;
0105 struct ptp_clock_info info;
0106 struct ptp_clock *clock;
0107 spinlock_t lock;
0108 u32 cc_mult;
0109 struct cyclecounter cc;
0110 struct timecounter tc;
0111 int phc_index;
0112 struct clk *refclk;
0113 struct list_head events;
0114 struct list_head pool;
0115 struct cpts_event pool_data[CPTS_MAX_EVENTS];
0116 unsigned long ov_check_period;
0117 struct sk_buff_head txq;
0118 u64 cur_timestamp;
0119 u32 mult_new;
0120 struct mutex ptp_clk_mutex;
0121 bool irq_poll;
0122 struct completion ts_push_complete;
0123 u32 hw_ts_enable;
0124 };
0125
0126 void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
0127 void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb);
0128 int cpts_register(struct cpts *cpts);
0129 void cpts_unregister(struct cpts *cpts);
0130 struct cpts *cpts_create(struct device *dev, void __iomem *regs,
0131 struct device_node *node, u32 n_ext_ts);
0132 void cpts_release(struct cpts *cpts);
0133 void cpts_misc_interrupt(struct cpts *cpts);
0134
0135 static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
0136 {
0137 unsigned int class = ptp_classify_raw(skb);
0138
0139 if (class == PTP_CLASS_NONE)
0140 return false;
0141
0142 return true;
0143 }
0144
0145 static inline void cpts_set_irqpoll(struct cpts *cpts, bool en)
0146 {
0147 cpts->irq_poll = en;
0148 }
0149
0150 #else
0151 struct cpts;
0152
0153 static inline void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb)
0154 {
0155 }
0156 static inline void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb)
0157 {
0158 }
0159
0160 static inline
0161 struct cpts *cpts_create(struct device *dev, void __iomem *regs,
0162 struct device_node *node, u32 n_ext_ts)
0163 {
0164 return NULL;
0165 }
0166
0167 static inline void cpts_release(struct cpts *cpts)
0168 {
0169 }
0170
0171 static inline int
0172 cpts_register(struct cpts *cpts)
0173 {
0174 return 0;
0175 }
0176
0177 static inline void cpts_unregister(struct cpts *cpts)
0178 {
0179 }
0180
0181 static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
0182 {
0183 return false;
0184 }
0185
0186 static inline void cpts_misc_interrupt(struct cpts *cpts)
0187 {
0188 }
0189
0190 static inline void cpts_set_irqpoll(struct cpts *cpts, bool en)
0191 {
0192 }
0193 #endif
0194
0195
0196 #endif