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