1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /*
3  * Copyright (C) 2017-2020 Mellanox Technologies Ltd.
4  */
5 
6 #ifndef __LINUX_PLATFORM_DATA_MLXREG_H
7 #define __LINUX_PLATFORM_DATA_MLXREG_H
8 
9 #define MLXREG_CORE_LABEL_MAX_SIZE	32
10 #define MLXREG_CORE_WD_FEATURE_NOWAYOUT		BIT(0)
11 #define MLXREG_CORE_WD_FEATURE_START_AT_BOOT	BIT(1)
12 
13 /**
14  * enum mlxreg_wdt_type - type of HW watchdog
15  *
16  * TYPE1 HW watchdog implementation exist in old systems.
17  * All new systems have TYPE2 HW watchdog.
18  * TYPE3 HW watchdog can exist on all systems with new CPLD.
19  * TYPE3 is selected by WD capability bit.
20  */
21 enum mlxreg_wdt_type {
22 	MLX_WDT_TYPE1,
23 	MLX_WDT_TYPE2,
24 	MLX_WDT_TYPE3,
25 };
26 
27 /**
28  * enum mlxreg_hotplug_kind - kind of hotplug entry
29  *
30  * @MLXREG_HOTPLUG_DEVICE_NA: do not care;
31  * @MLXREG_HOTPLUG_LC_PRESENT: entry for line card presence in/out events;
32  * @MLXREG_HOTPLUG_LC_VERIFIED: entry for line card verification status events
33  *				coming after line card security signature validation;
34  * @MLXREG_HOTPLUG_LC_POWERED: entry for line card power on/off events;
35  * @MLXREG_HOTPLUG_LC_SYNCED: entry for line card synchronization events, coming
36  *			      after hardware-firmware synchronization handshake;
37  * @MLXREG_HOTPLUG_LC_READY: entry for line card ready events, indicating line card
38 			     PHYs ready / unready state;
39  * @MLXREG_HOTPLUG_LC_ACTIVE: entry for line card active events, indicating firmware
40  *			      availability / unavailability for the ports on line card;
41  * @MLXREG_HOTPLUG_LC_THERMAL: entry for line card thermal shutdown events, positive
42  *			       event indicates that system should power off the line
43  *			       card for which this event has been received;
44  */
45 enum mlxreg_hotplug_kind {
46 	MLXREG_HOTPLUG_DEVICE_NA = 0,
47 	MLXREG_HOTPLUG_LC_PRESENT = 1,
48 	MLXREG_HOTPLUG_LC_VERIFIED = 2,
49 	MLXREG_HOTPLUG_LC_POWERED = 3,
50 	MLXREG_HOTPLUG_LC_SYNCED = 4,
51 	MLXREG_HOTPLUG_LC_READY = 5,
52 	MLXREG_HOTPLUG_LC_ACTIVE = 6,
53 	MLXREG_HOTPLUG_LC_THERMAL = 7,
54 };
55 
56 /**
57  * enum mlxreg_hotplug_device_action - hotplug device action required for
58  *				       driver's connectivity
59  *
60  * @MLXREG_HOTPLUG_DEVICE_DEFAULT_ACTION: probe device for 'on' event, remove
61  *					  for 'off' event;
62  * @MLXREG_HOTPLUG_DEVICE_PLATFORM_ACTION: probe platform device for 'on'
63  *					   event, remove for 'off' event;
64  * @MLXREG_HOTPLUG_DEVICE_NO_ACTION: no connectivity action is required;
65  */
66 enum mlxreg_hotplug_device_action {
67 	MLXREG_HOTPLUG_DEVICE_DEFAULT_ACTION = 0,
68 	MLXREG_HOTPLUG_DEVICE_PLATFORM_ACTION = 1,
69 	MLXREG_HOTPLUG_DEVICE_NO_ACTION = 2,
70 };
71 
72 /**
73  * struct mlxreg_hotplug_device - I2C device data:
74  *
75  * @adapter: I2C device adapter;
76  * @client: I2C device client;
77  * @brdinfo: device board information;
78  * @nr: I2C device adapter number, to which device is to be attached;
79  * @action: action to be performed upon event receiving;
80  *
81  * Structure represents I2C hotplug device static data (board topology) and
82  * dynamic data (related kernel objects handles).
83  */
84 struct mlxreg_hotplug_device {
85 	struct i2c_adapter *adapter;
86 	struct i2c_client *client;
87 	struct i2c_board_info *brdinfo;
88 	int nr;
89 	enum mlxreg_hotplug_device_action action;
90 };
91 
92 /**
93  * struct mlxreg_core_data - attributes control data:
94  *
95  * @label: attribute label;
96  * @reg: attribute register;
97  * @mask: attribute access mask;
98  * @bit: attribute effective bit;
99  * @capability: attribute capability register;
100  * @reg_prsnt: attribute presence register;
101  * @reg_sync: attribute synch register;
102  * @reg_pwr: attribute power register;
103  * @reg_ena: attribute enable register;
104  * @mode: access mode;
105  * @np - pointer to node platform associated with attribute;
106  * @hpdev - hotplug device data;
107  * @health_cntr: dynamic device health indication counter;
108  * @attached: true if device has been attached after good health indication;
109  * @regnum: number of registers occupied by multi-register attribute;
110  * @slot: slot number, at which device is located;
111  */
112 struct mlxreg_core_data {
113 	char label[MLXREG_CORE_LABEL_MAX_SIZE];
114 	u32 reg;
115 	u32 mask;
116 	u32 bit;
117 	u32 capability;
118 	u32 reg_prsnt;
119 	u32 reg_sync;
120 	u32 reg_pwr;
121 	u32 reg_ena;
122 	umode_t	mode;
123 	struct device_node *np;
124 	struct mlxreg_hotplug_device hpdev;
125 	u32 health_cntr;
126 	bool attached;
127 	u8 regnum;
128 	u8 slot;
129 };
130 
131 /**
132  * struct mlxreg_core_item - same type components controlled by the driver:
133  *
134  * @data: component data;
135  * @kind: kind of hotplug attribute;
136  * @aggr_mask: group aggregation mask;
137  * @reg: group interrupt status register;
138  * @mask: group interrupt mask;
139  * @capability: group capability register;
140  * @cache: last status value for elements fro the same group;
141  * @count: number of available elements in the group;
142  * @ind: element's index inside the group;
143  * @inversed: if 0: 0 for signal status is OK, if 1 - 1 is OK;
144  * @health: true if device has health indication, false in other case;
145  */
146 struct mlxreg_core_item {
147 	struct mlxreg_core_data *data;
148 	enum mlxreg_hotplug_kind kind;
149 	u32 aggr_mask;
150 	u32 reg;
151 	u32 mask;
152 	u32 capability;
153 	u32 cache;
154 	u8 count;
155 	u8 ind;
156 	u8 inversed;
157 	u8 health;
158 };
159 
160 /**
161  * struct mlxreg_core_platform_data - platform data:
162  *
163  * @data: instance private data;
164  * @regmap: register map of parent device;
165  * @counter: number of instances;
166  * @features: supported features of device;
167  * @version: implementation version;
168  * @identity: device identity name;
169  * @capability: device capability register;
170  */
171 struct mlxreg_core_platform_data {
172 	struct mlxreg_core_data *data;
173 	void *regmap;
174 	int counter;
175 	u32 features;
176 	u32 version;
177 	char identity[MLXREG_CORE_LABEL_MAX_SIZE];
178 	u32 capability;
179 };
180 
181 /**
182  * struct mlxreg_core_hotplug_platform_data - hotplug platform data:
183  *
184  * @items: same type components with the hotplug capability;
185  * @irq: platform interrupt number;
186  * @regmap: register map of parent device;
187  * @counter: number of the components with the hotplug capability;
188  * @cell: location of top aggregation interrupt register;
189  * @mask: top aggregation interrupt common mask;
190  * @cell_low: location of low aggregation interrupt register;
191  * @mask_low: low aggregation interrupt common mask;
192  * @deferred_nr: I2C adapter number must be exist prior probing execution;
193  * @shift_nr: I2C adapter numbers must be incremented by this value;
194  */
195 struct mlxreg_core_hotplug_platform_data {
196 	struct mlxreg_core_item *items;
197 	int irq;
198 	void *regmap;
199 	int counter;
200 	u32 cell;
201 	u32 mask;
202 	u32 cell_low;
203 	u32 mask_low;
204 	int deferred_nr;
205 	int shift_nr;
206 };
207 
208 #endif /* __LINUX_PLATFORM_DATA_MLXREG_H */
209