1
2
3
4
5
6#ifndef __PTP_QORIQ_H__
7#define __PTP_QORIQ_H__
8
9#include <linux/io.h>
10#include <linux/interrupt.h>
11#include <linux/ptp_clock_kernel.h>
12
13
14
15
16struct ctrl_regs {
17 u32 tmr_ctrl;
18 u32 tmr_tevent;
19 u32 tmr_temask;
20 u32 tmr_pevent;
21 u32 tmr_pemask;
22 u32 tmr_stat;
23 u32 tmr_cnt_h;
24 u32 tmr_cnt_l;
25 u32 tmr_add;
26 u32 tmr_acc;
27 u32 tmr_prsc;
28 u8 res1[4];
29 u32 tmroff_h;
30 u32 tmroff_l;
31};
32
33struct alarm_regs {
34 u32 tmr_alarm1_h;
35 u32 tmr_alarm1_l;
36 u32 tmr_alarm2_h;
37 u32 tmr_alarm2_l;
38};
39
40struct fiper_regs {
41 u32 tmr_fiper1;
42 u32 tmr_fiper2;
43 u32 tmr_fiper3;
44};
45
46struct etts_regs {
47 u32 tmr_etts1_h;
48 u32 tmr_etts1_l;
49 u32 tmr_etts2_h;
50 u32 tmr_etts2_l;
51};
52
53struct ptp_qoriq_registers {
54 struct ctrl_regs __iomem *ctrl_regs;
55 struct alarm_regs __iomem *alarm_regs;
56 struct fiper_regs __iomem *fiper_regs;
57 struct etts_regs __iomem *etts_regs;
58};
59
60
61#define ETSEC_CTRL_REGS_OFFSET 0x0
62#define ETSEC_ALARM_REGS_OFFSET 0x40
63#define ETSEC_FIPER_REGS_OFFSET 0x80
64#define ETSEC_ETTS_REGS_OFFSET 0xa0
65
66#define CTRL_REGS_OFFSET 0x80
67#define ALARM_REGS_OFFSET 0xb8
68#define FIPER_REGS_OFFSET 0xd0
69#define ETTS_REGS_OFFSET 0xe0
70
71
72
73#define ALM1P (1<<31)
74#define ALM2P (1<<30)
75#define FIPERST (1<<28)
76#define PP1L (1<<27)
77#define PP2L (1<<26)
78#define TCLK_PERIOD_SHIFT (16)
79#define TCLK_PERIOD_MASK (0x3ff)
80#define RTPE (1<<15)
81#define FRD (1<<14)
82#define ESFDP (1<<11)
83#define ESFDE (1<<10)
84#define ETEP2 (1<<9)
85#define ETEP1 (1<<8)
86#define COPH (1<<7)
87#define CIPH (1<<6)
88#define TMSR (1<<5)
89#define BYP (1<<3)
90#define TE (1<<2)
91#define CKSEL_SHIFT (0)
92#define CKSEL_MASK (0x3)
93
94
95#define ETS2 (1<<25)
96#define ETS1 (1<<24)
97#define ALM2 (1<<17)
98#define ALM1 (1<<16)
99#define PP1 (1<<7)
100#define PP2 (1<<6)
101#define PP3 (1<<5)
102
103
104#define ETS2EN (1<<25)
105#define ETS1EN (1<<24)
106#define ALM2EN (1<<17)
107#define ALM1EN (1<<16)
108#define PP1EN (1<<7)
109#define PP2EN (1<<6)
110
111
112#define TXP2 (1<<9)
113#define TXP1 (1<<8)
114#define RXP (1<<0)
115
116
117#define TXP2EN (1<<9)
118#define TXP1EN (1<<8)
119#define RXPEN (1<<0)
120
121
122#define STAT_VEC_SHIFT (0)
123#define STAT_VEC_MASK (0x3f)
124#define ETS1_VLD (1<<24)
125#define ETS2_VLD (1<<25)
126
127
128#define PRSC_OCK_SHIFT (0)
129#define PRSC_OCK_MASK (0xffff)
130
131
132#define DRIVER "ptp_qoriq"
133#define N_EXT_TS 2
134
135#define DEFAULT_CKSEL 1
136#define DEFAULT_TMR_PRSC 2
137#define DEFAULT_FIPER1_PERIOD 1000000000
138#define DEFAULT_FIPER2_PERIOD 1000000000
139#define DEFAULT_FIPER3_PERIOD 1000000000
140
141struct ptp_qoriq {
142 void __iomem *base;
143 struct ptp_qoriq_registers regs;
144 spinlock_t lock;
145 struct ptp_clock *clock;
146 struct ptp_clock_info caps;
147 struct resource *rsrc;
148 struct dentry *debugfs_root;
149 struct device *dev;
150 bool extts_fifo_support;
151 bool fiper3_support;
152 int irq;
153 int phc_index;
154 u32 tclk_period;
155 u32 tmr_prsc;
156 u32 tmr_add;
157 u32 cksel;
158 u32 tmr_fiper1;
159 u32 tmr_fiper2;
160 u32 tmr_fiper3;
161 u32 (*read)(unsigned __iomem *addr);
162 void (*write)(unsigned __iomem *addr, u32 val);
163};
164
165static inline u32 qoriq_read_be(unsigned __iomem *addr)
166{
167 return ioread32be(addr);
168}
169
170static inline void qoriq_write_be(unsigned __iomem *addr, u32 val)
171{
172 iowrite32be(val, addr);
173}
174
175static inline u32 qoriq_read_le(unsigned __iomem *addr)
176{
177 return ioread32(addr);
178}
179
180static inline void qoriq_write_le(unsigned __iomem *addr, u32 val)
181{
182 iowrite32(val, addr);
183}
184
185irqreturn_t ptp_qoriq_isr(int irq, void *priv);
186int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
187 const struct ptp_clock_info *caps);
188void ptp_qoriq_free(struct ptp_qoriq *ptp_qoriq);
189int ptp_qoriq_adjfine(struct ptp_clock_info *ptp, long scaled_ppm);
190int ptp_qoriq_adjtime(struct ptp_clock_info *ptp, s64 delta);
191int ptp_qoriq_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts);
192int ptp_qoriq_settime(struct ptp_clock_info *ptp,
193 const struct timespec64 *ts);
194int ptp_qoriq_enable(struct ptp_clock_info *ptp,
195 struct ptp_clock_request *rq, int on);
196int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index, bool update_event);
197#ifdef CONFIG_DEBUG_FS
198void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq);
199void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq);
200#else
201static inline void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
202{ }
203static inline void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
204{ }
205#endif
206
207#endif
208