1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _TI_CPTS_H_
21#define _TI_CPTS_H_
22
23#include <linux/clk.h>
24#include <linux/clkdev.h>
25#include <linux/clocksource.h>
26#include <linux/device.h>
27#include <linux/list.h>
28#include <linux/ptp_clock_kernel.h>
29#include <linux/skbuff.h>
30
31struct cpsw_cpts {
32 u32 idver;
33 u32 control;
34 u32 res1;
35 u32 ts_push;
36 u32 ts_load_val;
37 u32 ts_load_en;
38 u32 res2[2];
39 u32 intstat_raw;
40 u32 intstat_masked;
41 u32 int_enable;
42 u32 res3;
43 u32 event_pop;
44 u32 event_low;
45 u32 event_high;
46};
47
48
49#define TX_IDENT_SHIFT (16)
50#define TX_IDENT_MASK (0xffff)
51#define RTL_VER_SHIFT (11)
52#define RTL_VER_MASK (0x1f)
53#define MAJOR_VER_SHIFT (8)
54#define MAJOR_VER_MASK (0x7)
55#define MINOR_VER_SHIFT (0)
56#define MINOR_VER_MASK (0xff)
57
58
59#define HW4_TS_PUSH_EN (1<<11)
60#define HW3_TS_PUSH_EN (1<<10)
61#define HW2_TS_PUSH_EN (1<<9)
62#define HW1_TS_PUSH_EN (1<<8)
63#define INT_TEST (1<<1)
64#define CPTS_EN (1<<0)
65
66
67
68
69
70#define TS_PUSH (1<<0)
71#define TS_LOAD_EN (1<<0)
72#define TS_PEND_RAW (1<<0)
73#define TS_PEND (1<<0)
74#define TS_PEND_EN (1<<0)
75#define EVENT_POP (1<<0)
76
77
78#define PORT_NUMBER_SHIFT (24)
79#define PORT_NUMBER_MASK (0x1f)
80#define EVENT_TYPE_SHIFT (20)
81#define EVENT_TYPE_MASK (0xf)
82#define MESSAGE_TYPE_SHIFT (16)
83#define MESSAGE_TYPE_MASK (0xf)
84#define SEQUENCE_ID_SHIFT (0)
85#define SEQUENCE_ID_MASK (0xffff)
86
87enum {
88 CPTS_EV_PUSH,
89 CPTS_EV_ROLL,
90 CPTS_EV_HALF,
91 CPTS_EV_HW,
92 CPTS_EV_RX,
93 CPTS_EV_TX,
94};
95
96
97#define CPTS_OVERFLOW_PERIOD (HZ * 8)
98
99#define CPTS_FIFO_DEPTH 16
100#define CPTS_MAX_EVENTS 32
101
102struct cpts_event {
103 struct list_head list;
104 unsigned long tmo;
105 u32 high;
106 u32 low;
107};
108
109struct cpts {
110 struct cpsw_cpts __iomem *reg;
111 int tx_enable;
112 int rx_enable;
113#ifdef CONFIG_TI_CPTS
114 struct ptp_clock_info info;
115 struct ptp_clock *clock;
116 spinlock_t lock;
117 u32 cc_mult;
118 struct cyclecounter cc;
119 struct timecounter tc;
120 struct delayed_work overflow_work;
121 int phc_index;
122 struct clk *refclk;
123 struct list_head events;
124 struct list_head pool;
125 struct cpts_event pool_data[CPTS_MAX_EVENTS];
126#endif
127};
128
129#ifdef CONFIG_TI_CPTS
130void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
131void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb);
132#else
133static inline void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb)
134{
135}
136static inline void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb)
137{
138}
139#endif
140
141int cpts_register(struct device *dev, struct cpts *cpts, u32 mult, u32 shift);
142void cpts_unregister(struct cpts *cpts);
143
144#endif
145