xref: /linux/drivers/net/ethernet/ti/icssg/icss_iep.h (revision 9410645520e9b820069761f3450ef6661418e279)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Texas Instruments ICSSG Industrial Ethernet Peripheral (IEP) Driver
3  *
4  * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
5  *
6  */
7 
8 #ifndef __NET_TI_ICSS_IEP_H
9 #define __NET_TI_ICSS_IEP_H
10 
11 #include <linux/mutex.h>
12 #include <linux/ptp_clock_kernel.h>
13 #include <linux/regmap.h>
14 
15 enum {
16 	ICSS_IEP_GLOBAL_CFG_REG,
17 	ICSS_IEP_GLOBAL_STATUS_REG,
18 	ICSS_IEP_COMPEN_REG,
19 	ICSS_IEP_SLOW_COMPEN_REG,
20 	ICSS_IEP_COUNT_REG0,
21 	ICSS_IEP_COUNT_REG1,
22 	ICSS_IEP_CAPTURE_CFG_REG,
23 	ICSS_IEP_CAPTURE_STAT_REG,
24 
25 	ICSS_IEP_CAP6_RISE_REG0,
26 	ICSS_IEP_CAP6_RISE_REG1,
27 
28 	ICSS_IEP_CAP7_RISE_REG0,
29 	ICSS_IEP_CAP7_RISE_REG1,
30 
31 	ICSS_IEP_CMP_CFG_REG,
32 	ICSS_IEP_CMP_STAT_REG,
33 	ICSS_IEP_CMP0_REG0,
34 	ICSS_IEP_CMP0_REG1,
35 	ICSS_IEP_CMP1_REG0,
36 	ICSS_IEP_CMP1_REG1,
37 
38 	ICSS_IEP_CMP8_REG0,
39 	ICSS_IEP_CMP8_REG1,
40 	ICSS_IEP_SYNC_CTRL_REG,
41 	ICSS_IEP_SYNC0_STAT_REG,
42 	ICSS_IEP_SYNC1_STAT_REG,
43 	ICSS_IEP_SYNC_PWIDTH_REG,
44 	ICSS_IEP_SYNC0_PERIOD_REG,
45 	ICSS_IEP_SYNC1_DELAY_REG,
46 	ICSS_IEP_SYNC_START_REG,
47 	ICSS_IEP_MAX_REGS,
48 };
49 
50 /**
51  * struct icss_iep_plat_data - Plat data to handle SoC variants
52  * @config: Regmap configuration data
53  * @reg_offs: register offsets to capture offset differences across SoCs
54  * @flags: Flags to represent IEP properties
55  */
56 struct icss_iep_plat_data {
57 	const struct regmap_config *config;
58 	u32 reg_offs[ICSS_IEP_MAX_REGS];
59 	u32 flags;
60 };
61 
62 struct icss_iep {
63 	struct device *dev;
64 	void __iomem *base;
65 	const struct icss_iep_plat_data *plat_data;
66 	struct regmap *map;
67 	struct device_node *client_np;
68 	unsigned long refclk_freq;
69 	int clk_tick_time;	/* one refclk tick time in ns */
70 	struct ptp_clock_info ptp_info;
71 	struct ptp_clock *ptp_clock;
72 	struct mutex ptp_clk_mutex;	/* PHC access serializer */
73 	u32 def_inc;
74 	s16 slow_cmp_inc;
75 	u32 slow_cmp_count;
76 	const struct icss_iep_clockops *ops;
77 	void *clockops_data;
78 	u32 cycle_time_ns;
79 	u32 perout_enabled;
80 	bool pps_enabled;
81 	int cap_cmp_irq;
82 	u64 period;
83 	u32 latch_enable;
84 	struct work_struct work;
85 };
86 
87 extern const struct icss_iep_clockops prueth_iep_clockops;
88 
89 /* Firmware specific clock operations */
90 struct icss_iep_clockops {
91 	void (*settime)(void *clockops_data, u64 ns);
92 	void (*adjtime)(void *clockops_data, s64 delta);
93 	u64 (*gettime)(void *clockops_data, struct ptp_system_timestamp *sts);
94 	int (*perout_enable)(void *clockops_data,
95 			     struct ptp_perout_request *req, int on,
96 			     u64 *cmp);
97 	int (*extts_enable)(void *clockops_data, u32 index, int on);
98 };
99 
100 struct icss_iep *icss_iep_get(struct device_node *np);
101 struct icss_iep *icss_iep_get_idx(struct device_node *np, int idx);
102 void icss_iep_put(struct icss_iep *iep);
103 int icss_iep_init(struct icss_iep *iep, const struct icss_iep_clockops *clkops,
104 		  void *clockops_data, u32 cycle_time_ns);
105 int icss_iep_exit(struct icss_iep *iep);
106 int icss_iep_get_count_low(struct icss_iep *iep);
107 int icss_iep_get_count_hi(struct icss_iep *iep);
108 int icss_iep_get_ptp_clock_idx(struct icss_iep *iep);
109 void icss_iep_init_fw(struct icss_iep *iep);
110 void icss_iep_exit_fw(struct icss_iep *iep);
111 
112 #endif /* __NET_TI_ICSS_IEP_H */
113