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 */
21enum 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 */
45enum 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 */
66enum 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_core_hotplug_notifier - hotplug notifier block:
74 *
75 * @identity: notifier identity name;
76 * @handle: user handle to be passed by user handler function;
77 * @user_handler: user handler function associated with the event;
78 */
79struct mlxreg_core_hotplug_notifier {
80	char identity[MLXREG_CORE_LABEL_MAX_SIZE];
81	void *handle;
82	int (*user_handler)(void *handle, enum mlxreg_hotplug_kind kind, u8 action);
83};
84
85/**
86 * struct mlxreg_hotplug_device - I2C device data:
87 *
88 * @adapter: I2C device adapter;
89 * @client: I2C device client;
90 * @brdinfo: device board information;
91 * @nr: I2C device adapter number, to which device is to be attached;
92 * @pdev: platform device, if device is instantiated as a platform device;
93 * @action: action to be performed upon event receiving;
94 * @handle: user handle to be passed by user handler function;
95 * @user_handler: user handler function associated with the event;
96 * @notifier: pointer to event notifier block;
97 *
98 * Structure represents I2C hotplug device static data (board topology) and
99 * dynamic data (related kernel objects handles).
100 */
101struct mlxreg_hotplug_device {
102	struct i2c_adapter *adapter;
103	struct i2c_client *client;
104	struct i2c_board_info *brdinfo;
105	int nr;
106	struct platform_device *pdev;
107	enum mlxreg_hotplug_device_action action;
108	void *handle;
109	int (*user_handler)(void *handle, enum mlxreg_hotplug_kind kind, u8 action);
110	struct mlxreg_core_hotplug_notifier *notifier;
111};
112
113/**
114 * struct mlxreg_core_data - attributes control data:
115 *
116 * @label: attribute label;
117 * @reg: attribute register;
118 * @mask: attribute access mask;
119 * @bit: attribute effective bit;
120 * @capability: attribute capability register;
121 * @reg_prsnt: attribute presence register;
122 * @reg_sync: attribute synch register;
123 * @reg_pwr: attribute power register;
124 * @reg_ena: attribute enable register;
125 * @mode: access mode;
126 * @np - pointer to node platform associated with attribute;
127 * @hpdev - hotplug device data;
128 * @notifier: pointer to event notifier block;
129 * @health_cntr: dynamic device health indication counter;
130 * @attached: true if device has been attached after good health indication;
131 * @regnum: number of registers occupied by multi-register attribute;
132 * @slot: slot number, at which device is located;
133 * @secured: if set indicates that entry access is secured;
134 */
135struct mlxreg_core_data {
136	char label[MLXREG_CORE_LABEL_MAX_SIZE];
137	u32 reg;
138	u32 mask;
139	u32 bit;
140	u32 capability;
141	u32 reg_prsnt;
142	u32 reg_sync;
143	u32 reg_pwr;
144	u32 reg_ena;
145	umode_t	mode;
146	struct device_node *np;
147	struct mlxreg_hotplug_device hpdev;
148	struct mlxreg_core_hotplug_notifier *notifier;
149	u32 health_cntr;
150	bool attached;
151	u8 regnum;
152	u8 slot;
153	u8 secured;
154};
155
156/**
157 * struct mlxreg_core_item - same type components controlled by the driver:
158 *
159 * @data: component data;
160 * @kind: kind of hotplug attribute;
161 * @aggr_mask: group aggregation mask;
162 * @reg: group interrupt status register;
163 * @mask: group interrupt mask;
164 * @capability: group capability register;
165 * @cache: last status value for elements fro the same group;
166 * @count: number of available elements in the group;
167 * @ind: element's index inside the group;
168 * @inversed: if 0: 0 for signal status is OK, if 1 - 1 is OK;
169 * @health: true if device has health indication, false in other case;
170 */
171struct mlxreg_core_item {
172	struct mlxreg_core_data *data;
173	enum mlxreg_hotplug_kind kind;
174	u32 aggr_mask;
175	u32 reg;
176	u32 mask;
177	u32 capability;
178	u32 cache;
179	u8 count;
180	u8 ind;
181	u8 inversed;
182	u8 health;
183};
184
185/**
186 * struct mlxreg_core_platform_data - platform data:
187 *
188 * @data: instance private data;
189 * @regmap: register map of parent device;
190 * @counter: number of instances;
191 * @features: supported features of device;
192 * @version: implementation version;
193 * @identity: device identity name;
194 * @capability: device capability register;
195 */
196struct mlxreg_core_platform_data {
197	struct mlxreg_core_data *data;
198	void *regmap;
199	int counter;
200	u32 features;
201	u32 version;
202	char identity[MLXREG_CORE_LABEL_MAX_SIZE];
203	u32 capability;
204};
205
206/**
207 * struct mlxreg_core_hotplug_platform_data - hotplug platform data:
208 *
209 * @items: same type components with the hotplug capability;
210 * @irq: platform interrupt number;
211 * @regmap: register map of parent device;
212 * @counter: number of the components with the hotplug capability;
213 * @cell: location of top aggregation interrupt register;
214 * @mask: top aggregation interrupt common mask;
215 * @cell_low: location of low aggregation interrupt register;
216 * @mask_low: low aggregation interrupt common mask;
217 * @deferred_nr: I2C adapter number must be exist prior probing execution;
218 * @shift_nr: I2C adapter numbers must be incremented by this value;
219 * @addr: mapped resource address;
220 * @handle: handle to be passed by callback;
221 * @completion_notify: callback to notify when platform driver probing is done;
222 */
223struct mlxreg_core_hotplug_platform_data {
224	struct mlxreg_core_item *items;
225	int irq;
226	void *regmap;
227	int counter;
228	u32 cell;
229	u32 mask;
230	u32 cell_low;
231	u32 mask_low;
232	int deferred_nr;
233	int shift_nr;
234	void __iomem *addr;
235	void *handle;
236	int (*completion_notify)(void *handle, int id);
237};
238
239#endif /* __LINUX_PLATFORM_DATA_MLXREG_H */
240