1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2022 Nvidia Technologies Ltd.
8 #include <linux/device.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/gpio.h>
13 #include <linux/module.h>
14 #include <linux/platform_data/mlxcpld.h>
15 #include <linux/platform_data/mlxreg.h>
16 #include <linux/platform_device.h>
17 #include <linux/regmap.h>
19 /* SN2201 CPLD register offset. */
20 #define NVSW_SN2201_CPLD_LPC_I2C_BASE_ADRR 0x2000
21 #define NVSW_SN2201_CPLD_LPC_IO_RANGE 0x100
22 #define NVSW_SN2201_HW_VER_ID_OFFSET 0x00
23 #define NVSW_SN2201_BOARD_ID_OFFSET 0x01
24 #define NVSW_SN2201_CPLD_VER_OFFSET 0x02
25 #define NVSW_SN2201_CPLD_MVER_OFFSET 0x03
26 #define NVSW_SN2201_CPLD_ID_OFFSET 0x04
27 #define NVSW_SN2201_CPLD_PN_OFFSET 0x05
28 #define NVSW_SN2201_CPLD_PN1_OFFSET 0x06
29 #define NVSW_SN2201_PSU_CTRL_OFFSET 0x0a
30 #define NVSW_SN2201_QSFP28_STATUS_OFFSET 0x0b
31 #define NVSW_SN2201_QSFP28_INT_STATUS_OFFSET 0x0c
32 #define NVSW_SN2201_QSFP28_LP_STATUS_OFFSET 0x0d
33 #define NVSW_SN2201_QSFP28_RST_STATUS_OFFSET 0x0e
34 #define NVSW_SN2201_SYS_STATUS_OFFSET 0x0f
35 #define NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET 0x10
36 #define NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET 0x12
37 #define NVSW_SN2201_FRONT_UID_LED_CTRL_OFFSET 0x13
38 #define NVSW_SN2201_QSFP28_LED_TEST_STATUS_OFFSET 0x14
39 #define NVSW_SN2201_SYS_RST_STATUS_OFFSET 0x15
40 #define NVSW_SN2201_SYS_INT_STATUS_OFFSET 0x21
41 #define NVSW_SN2201_SYS_INT_MASK_OFFSET 0x22
42 #define NVSW_SN2201_ASIC_STATUS_OFFSET 0x24
43 #define NVSW_SN2201_ASIC_EVENT_OFFSET 0x25
44 #define NVSW_SN2201_ASIC_MAKS_OFFSET 0x26
45 #define NVSW_SN2201_THML_STATUS_OFFSET 0x27
46 #define NVSW_SN2201_THML_EVENT_OFFSET 0x28
47 #define NVSW_SN2201_THML_MASK_OFFSET 0x29
48 #define NVSW_SN2201_PS_ALT_STATUS_OFFSET 0x2a
49 #define NVSW_SN2201_PS_ALT_EVENT_OFFSET 0x2b
50 #define NVSW_SN2201_PS_ALT_MASK_OFFSET 0x2c
51 #define NVSW_SN2201_PS_PRSNT_STATUS_OFFSET 0x30
52 #define NVSW_SN2201_PS_PRSNT_EVENT_OFFSET 0x31
53 #define NVSW_SN2201_PS_PRSNT_MASK_OFFSET 0x32
54 #define NVSW_SN2201_PS_DC_OK_STATUS_OFFSET 0x33
55 #define NVSW_SN2201_PS_DC_OK_EVENT_OFFSET 0x34
56 #define NVSW_SN2201_PS_DC_OK_MASK_OFFSET 0x35
57 #define NVSW_SN2201_RST_CAUSE1_OFFSET 0x36
58 #define NVSW_SN2201_RST_CAUSE2_OFFSET 0x37
59 #define NVSW_SN2201_RST_SW_CTRL_OFFSET 0x38
60 #define NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET 0x3a
61 #define NVSW_SN2201_FAN_PRSNT_EVENT_OFFSET 0x3b
62 #define NVSW_SN2201_FAN_PRSNT_MASK_OFFSET 0x3c
63 #define NVSW_SN2201_WD_TMR_OFFSET_LSB 0x40
64 #define NVSW_SN2201_WD_TMR_OFFSET_MSB 0x41
65 #define NVSW_SN2201_WD_ACT_OFFSET 0x42
66 #define NVSW_SN2201_FAN_LED1_CTRL_OFFSET 0x50
67 #define NVSW_SN2201_FAN_LED2_CTRL_OFFSET 0x51
68 #define NVSW_SN2201_REG_MAX 0x52
70 /* Number of physical I2C busses. */
71 #define NVSW_SN2201_PHY_I2C_BUS_NUM 2
72 /* Number of main mux channels. */
73 #define NVSW_SN2201_MAIN_MUX_CHNL_NUM 8
75 #define NVSW_SN2201_MAIN_NR 0
76 #define NVSW_SN2201_MAIN_MUX_NR 1
77 #define NVSW_SN2201_MAIN_MUX_DEFER_NR (NVSW_SN2201_PHY_I2C_BUS_NUM + \
78 NVSW_SN2201_MAIN_MUX_CHNL_NUM - 1)
80 #define NVSW_SN2201_MAIN_MUX_CH0_NR NVSW_SN2201_PHY_I2C_BUS_NUM
81 #define NVSW_SN2201_MAIN_MUX_CH1_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 1)
82 #define NVSW_SN2201_MAIN_MUX_CH2_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 2)
83 #define NVSW_SN2201_MAIN_MUX_CH3_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 3)
84 #define NVSW_SN2201_MAIN_MUX_CH5_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 5)
85 #define NVSW_SN2201_MAIN_MUX_CH6_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 6)
86 #define NVSW_SN2201_MAIN_MUX_CH7_NR (NVSW_SN2201_MAIN_MUX_CH0_NR + 7)
87 #define NVSW_SN2201_2ND_MUX_CH0_NR (NVSW_SN2201_MAIN_MUX_CH7_NR + 1)
88 #define NVSW_SN2201_2ND_MUX_CH1_NR (NVSW_SN2201_MAIN_MUX_CH7_NR + 2)
89 #define NVSW_SN2201_2ND_MUX_CH2_NR (NVSW_SN2201_MAIN_MUX_CH7_NR + 3)
90 #define NVSW_SN2201_2ND_MUX_CH3_NR (NVSW_SN2201_MAIN_MUX_CH7_NR + 4)
92 #define NVSW_SN2201_CPLD_NR NVSW_SN2201_MAIN_MUX_CH0_NR
93 #define NVSW_SN2201_NR_NONE -1
95 /* Masks for aggregation, PSU presence and power, ASIC events
96 * in CPLD related registers.
98 #define NVSW_SN2201_CPLD_AGGR_ASIC_MASK_DEF 0xe0
99 #define NVSW_SN2201_CPLD_AGGR_PSU_MASK_DEF 0x04
100 #define NVSW_SN2201_CPLD_AGGR_PWR_MASK_DEF 0x02
101 #define NVSW_SN2201_CPLD_AGGR_FAN_MASK_DEF 0x10
102 #define NVSW_SN2201_CPLD_AGGR_MASK_DEF \
103 (NVSW_SN2201_CPLD_AGGR_ASIC_MASK_DEF \
104 | NVSW_SN2201_CPLD_AGGR_PSU_MASK_DEF \
105 | NVSW_SN2201_CPLD_AGGR_PWR_MASK_DEF \
106 | NVSW_SN2201_CPLD_AGGR_FAN_MASK_DEF)
108 #define NVSW_SN2201_CPLD_ASIC_MASK GENMASK(3, 1)
109 #define NVSW_SN2201_CPLD_PSU_MASK GENMASK(1, 0)
110 #define NVSW_SN2201_CPLD_PWR_MASK GENMASK(1, 0)
111 #define NVSW_SN2201_CPLD_FAN_MASK GENMASK(3, 0)
113 #define NVSW_SN2201_CPLD_SYSIRQ 26
114 #define NVSW_SN2201_LPC_SYSIRQ 28
115 #define NVSW_SN2201_CPLD_I2CADDR 0x41
117 #define NVSW_SN2201_WD_DFLT_TIMEOUT 600
119 /* nvsw_sn2201 - device private data
120 * @dev: platform device;
121 * @io_data: register access platform data;
122 * @led_data: LED platform data;
123 * @hotplug_data: hotplug platform data;
124 * @i2c_data: I2C controller platform data;
126 * @io_regs: register access device;
127 * @pdev_hotplug: hotplug device;
128 * @sn2201_devs: I2C devices for sn2201 devices;
129 * @sn2201_devs_num: number of I2C devices for sn2201 device;
130 * @main_mux_devs: I2C devices for main mux;
131 * @main_mux_devs_num: number of I2C devices for main mux;
132 * @cpld_devs: I2C devices for cpld;
133 * @cpld_devs_num: number of I2C devices for cpld;
134 * @main_mux_deferred_nr: I2C adapter number must be exist prior creating devices execution;
138 struct mlxreg_core_platform_data
*io_data
;
139 struct mlxreg_core_platform_data
*led_data
;
140 struct mlxreg_core_platform_data
*wd_data
;
141 struct mlxreg_core_hotplug_platform_data
*hotplug_data
;
142 struct mlxreg_core_hotplug_platform_data
*i2c_data
;
143 struct platform_device
*led
;
144 struct platform_device
*wd
;
145 struct platform_device
*io_regs
;
146 struct platform_device
*pdev_hotplug
;
147 struct platform_device
*pdev_i2c
;
148 struct mlxreg_hotplug_device
*sn2201_devs
;
150 struct mlxreg_hotplug_device
*main_mux_devs
;
151 int main_mux_devs_num
;
152 struct mlxreg_hotplug_device
*cpld_devs
;
154 int main_mux_deferred_nr
;
157 static bool nvsw_sn2201_writeable_reg(struct device
*dev
, unsigned int reg
)
160 case NVSW_SN2201_PSU_CTRL_OFFSET
:
161 case NVSW_SN2201_QSFP28_LP_STATUS_OFFSET
:
162 case NVSW_SN2201_QSFP28_RST_STATUS_OFFSET
:
163 case NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET
:
164 case NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET
:
165 case NVSW_SN2201_FRONT_UID_LED_CTRL_OFFSET
:
166 case NVSW_SN2201_QSFP28_LED_TEST_STATUS_OFFSET
:
167 case NVSW_SN2201_SYS_RST_STATUS_OFFSET
:
168 case NVSW_SN2201_SYS_INT_MASK_OFFSET
:
169 case NVSW_SN2201_ASIC_EVENT_OFFSET
:
170 case NVSW_SN2201_ASIC_MAKS_OFFSET
:
171 case NVSW_SN2201_THML_EVENT_OFFSET
:
172 case NVSW_SN2201_THML_MASK_OFFSET
:
173 case NVSW_SN2201_PS_ALT_EVENT_OFFSET
:
174 case NVSW_SN2201_PS_ALT_MASK_OFFSET
:
175 case NVSW_SN2201_PS_PRSNT_EVENT_OFFSET
:
176 case NVSW_SN2201_PS_PRSNT_MASK_OFFSET
:
177 case NVSW_SN2201_PS_DC_OK_EVENT_OFFSET
:
178 case NVSW_SN2201_PS_DC_OK_MASK_OFFSET
:
179 case NVSW_SN2201_RST_SW_CTRL_OFFSET
:
180 case NVSW_SN2201_FAN_PRSNT_EVENT_OFFSET
:
181 case NVSW_SN2201_FAN_PRSNT_MASK_OFFSET
:
182 case NVSW_SN2201_WD_TMR_OFFSET_LSB
:
183 case NVSW_SN2201_WD_TMR_OFFSET_MSB
:
184 case NVSW_SN2201_WD_ACT_OFFSET
:
185 case NVSW_SN2201_FAN_LED1_CTRL_OFFSET
:
186 case NVSW_SN2201_FAN_LED2_CTRL_OFFSET
:
192 static bool nvsw_sn2201_readable_reg(struct device
*dev
, unsigned int reg
)
195 case NVSW_SN2201_HW_VER_ID_OFFSET
:
196 case NVSW_SN2201_BOARD_ID_OFFSET
:
197 case NVSW_SN2201_CPLD_VER_OFFSET
:
198 case NVSW_SN2201_CPLD_MVER_OFFSET
:
199 case NVSW_SN2201_CPLD_ID_OFFSET
:
200 case NVSW_SN2201_CPLD_PN_OFFSET
:
201 case NVSW_SN2201_CPLD_PN1_OFFSET
:
202 case NVSW_SN2201_PSU_CTRL_OFFSET
:
203 case NVSW_SN2201_QSFP28_STATUS_OFFSET
:
204 case NVSW_SN2201_QSFP28_INT_STATUS_OFFSET
:
205 case NVSW_SN2201_QSFP28_LP_STATUS_OFFSET
:
206 case NVSW_SN2201_QSFP28_RST_STATUS_OFFSET
:
207 case NVSW_SN2201_SYS_STATUS_OFFSET
:
208 case NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET
:
209 case NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET
:
210 case NVSW_SN2201_FRONT_UID_LED_CTRL_OFFSET
:
211 case NVSW_SN2201_QSFP28_LED_TEST_STATUS_OFFSET
:
212 case NVSW_SN2201_SYS_RST_STATUS_OFFSET
:
213 case NVSW_SN2201_RST_CAUSE1_OFFSET
:
214 case NVSW_SN2201_RST_CAUSE2_OFFSET
:
215 case NVSW_SN2201_SYS_INT_STATUS_OFFSET
:
216 case NVSW_SN2201_SYS_INT_MASK_OFFSET
:
217 case NVSW_SN2201_ASIC_STATUS_OFFSET
:
218 case NVSW_SN2201_ASIC_EVENT_OFFSET
:
219 case NVSW_SN2201_ASIC_MAKS_OFFSET
:
220 case NVSW_SN2201_THML_STATUS_OFFSET
:
221 case NVSW_SN2201_THML_EVENT_OFFSET
:
222 case NVSW_SN2201_THML_MASK_OFFSET
:
223 case NVSW_SN2201_PS_ALT_STATUS_OFFSET
:
224 case NVSW_SN2201_PS_ALT_EVENT_OFFSET
:
225 case NVSW_SN2201_PS_ALT_MASK_OFFSET
:
226 case NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
:
227 case NVSW_SN2201_PS_PRSNT_EVENT_OFFSET
:
228 case NVSW_SN2201_PS_PRSNT_MASK_OFFSET
:
229 case NVSW_SN2201_PS_DC_OK_STATUS_OFFSET
:
230 case NVSW_SN2201_PS_DC_OK_EVENT_OFFSET
:
231 case NVSW_SN2201_PS_DC_OK_MASK_OFFSET
:
232 case NVSW_SN2201_RST_SW_CTRL_OFFSET
:
233 case NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
:
234 case NVSW_SN2201_FAN_PRSNT_EVENT_OFFSET
:
235 case NVSW_SN2201_FAN_PRSNT_MASK_OFFSET
:
236 case NVSW_SN2201_WD_TMR_OFFSET_LSB
:
237 case NVSW_SN2201_WD_TMR_OFFSET_MSB
:
238 case NVSW_SN2201_WD_ACT_OFFSET
:
239 case NVSW_SN2201_FAN_LED1_CTRL_OFFSET
:
240 case NVSW_SN2201_FAN_LED2_CTRL_OFFSET
:
246 static bool nvsw_sn2201_volatile_reg(struct device
*dev
, unsigned int reg
)
249 case NVSW_SN2201_HW_VER_ID_OFFSET
:
250 case NVSW_SN2201_BOARD_ID_OFFSET
:
251 case NVSW_SN2201_CPLD_VER_OFFSET
:
252 case NVSW_SN2201_CPLD_MVER_OFFSET
:
253 case NVSW_SN2201_CPLD_ID_OFFSET
:
254 case NVSW_SN2201_CPLD_PN_OFFSET
:
255 case NVSW_SN2201_CPLD_PN1_OFFSET
:
256 case NVSW_SN2201_PSU_CTRL_OFFSET
:
257 case NVSW_SN2201_QSFP28_STATUS_OFFSET
:
258 case NVSW_SN2201_QSFP28_INT_STATUS_OFFSET
:
259 case NVSW_SN2201_QSFP28_LP_STATUS_OFFSET
:
260 case NVSW_SN2201_QSFP28_RST_STATUS_OFFSET
:
261 case NVSW_SN2201_SYS_STATUS_OFFSET
:
262 case NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET
:
263 case NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET
:
264 case NVSW_SN2201_FRONT_UID_LED_CTRL_OFFSET
:
265 case NVSW_SN2201_QSFP28_LED_TEST_STATUS_OFFSET
:
266 case NVSW_SN2201_SYS_RST_STATUS_OFFSET
:
267 case NVSW_SN2201_RST_CAUSE1_OFFSET
:
268 case NVSW_SN2201_RST_CAUSE2_OFFSET
:
269 case NVSW_SN2201_SYS_INT_STATUS_OFFSET
:
270 case NVSW_SN2201_SYS_INT_MASK_OFFSET
:
271 case NVSW_SN2201_ASIC_STATUS_OFFSET
:
272 case NVSW_SN2201_ASIC_EVENT_OFFSET
:
273 case NVSW_SN2201_ASIC_MAKS_OFFSET
:
274 case NVSW_SN2201_THML_STATUS_OFFSET
:
275 case NVSW_SN2201_THML_EVENT_OFFSET
:
276 case NVSW_SN2201_THML_MASK_OFFSET
:
277 case NVSW_SN2201_PS_ALT_STATUS_OFFSET
:
278 case NVSW_SN2201_PS_ALT_EVENT_OFFSET
:
279 case NVSW_SN2201_PS_ALT_MASK_OFFSET
:
280 case NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
:
281 case NVSW_SN2201_PS_PRSNT_EVENT_OFFSET
:
282 case NVSW_SN2201_PS_PRSNT_MASK_OFFSET
:
283 case NVSW_SN2201_PS_DC_OK_STATUS_OFFSET
:
284 case NVSW_SN2201_PS_DC_OK_EVENT_OFFSET
:
285 case NVSW_SN2201_PS_DC_OK_MASK_OFFSET
:
286 case NVSW_SN2201_RST_SW_CTRL_OFFSET
:
287 case NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
:
288 case NVSW_SN2201_FAN_PRSNT_EVENT_OFFSET
:
289 case NVSW_SN2201_FAN_PRSNT_MASK_OFFSET
:
290 case NVSW_SN2201_WD_TMR_OFFSET_LSB
:
291 case NVSW_SN2201_WD_TMR_OFFSET_MSB
:
292 case NVSW_SN2201_FAN_LED1_CTRL_OFFSET
:
293 case NVSW_SN2201_FAN_LED2_CTRL_OFFSET
:
299 static const struct reg_default nvsw_sn2201_regmap_default
[] = {
300 { NVSW_SN2201_QSFP28_LED_TEST_STATUS_OFFSET
, 0x00 },
301 { NVSW_SN2201_WD_ACT_OFFSET
, 0x00 },
304 /* Configuration for the register map of a device with 1 bytes address space. */
305 static const struct regmap_config nvsw_sn2201_regmap_conf
= {
308 .max_register
= NVSW_SN2201_REG_MAX
,
309 .cache_type
= REGCACHE_FLAT
,
310 .writeable_reg
= nvsw_sn2201_writeable_reg
,
311 .readable_reg
= nvsw_sn2201_readable_reg
,
312 .volatile_reg
= nvsw_sn2201_volatile_reg
,
313 .reg_defaults
= nvsw_sn2201_regmap_default
,
314 .num_reg_defaults
= ARRAY_SIZE(nvsw_sn2201_regmap_default
),
317 /* Regions for LPC I2C controller and LPC base register space. */
318 static const struct resource nvsw_sn2201_lpc_io_resources
[] = {
319 [0] = DEFINE_RES_NAMED(NVSW_SN2201_CPLD_LPC_I2C_BASE_ADRR
,
320 NVSW_SN2201_CPLD_LPC_IO_RANGE
,
321 "mlxplat_cpld_lpc_i2c_ctrl", IORESOURCE_IO
),
324 static struct resource nvsw_sn2201_cpld_res
[] = {
325 [0] = DEFINE_RES_IRQ_NAMED(NVSW_SN2201_CPLD_SYSIRQ
, "mlxreg-hotplug"),
328 static struct resource nvsw_sn2201_lpc_res
[] = {
329 [0] = DEFINE_RES_IRQ_NAMED(NVSW_SN2201_LPC_SYSIRQ
, "i2c-mlxcpld"),
332 /* SN2201 I2C platform data. */
333 static struct mlxreg_core_hotplug_platform_data nvsw_sn2201_i2c_data
= {
334 .irq
= NVSW_SN2201_CPLD_SYSIRQ
,
337 /* SN2201 CPLD device. */
338 static struct i2c_board_info nvsw_sn2201_cpld_devices
[] = {
340 I2C_BOARD_INFO("nvsw-sn2201", 0x41),
344 /* SN2201 CPLD board info. */
345 static struct mlxreg_hotplug_device nvsw_sn2201_cpld_brdinfo
[] = {
347 .brdinfo
= &nvsw_sn2201_cpld_devices
[0],
348 .nr
= NVSW_SN2201_CPLD_NR
,
352 /* SN2201 main mux device. */
353 static struct i2c_board_info nvsw_sn2201_main_mux_devices
[] = {
355 I2C_BOARD_INFO("pca9548", 0x70),
359 /* SN2201 main mux board info. */
360 static struct mlxreg_hotplug_device nvsw_sn2201_main_mux_brdinfo
[] = {
362 .brdinfo
= &nvsw_sn2201_main_mux_devices
[0],
363 .nr
= NVSW_SN2201_MAIN_MUX_NR
,
367 /* SN2201 power devices. */
368 static struct i2c_board_info nvsw_sn2201_pwr_devices
[] = {
370 I2C_BOARD_INFO("pmbus", 0x58),
373 I2C_BOARD_INFO("pmbus", 0x58),
377 /* SN2201 fan devices. */
378 static struct i2c_board_info nvsw_sn2201_fan_devices
[] = {
380 I2C_BOARD_INFO("24c02", 0x50),
383 I2C_BOARD_INFO("24c02", 0x51),
386 I2C_BOARD_INFO("24c02", 0x52),
389 I2C_BOARD_INFO("24c02", 0x53),
393 /* SN2201 hotplug default data. */
394 static struct mlxreg_core_data nvsw_sn2201_psu_items_data
[] = {
397 .reg
= NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
,
399 .hpdev
.nr
= NVSW_SN2201_NR_NONE
,
403 .reg
= NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
,
405 .hpdev
.nr
= NVSW_SN2201_NR_NONE
,
409 static struct mlxreg_core_data nvsw_sn2201_pwr_items_data
[] = {
412 .reg
= NVSW_SN2201_PS_DC_OK_STATUS_OFFSET
,
414 .hpdev
.brdinfo
= &nvsw_sn2201_pwr_devices
[0],
415 .hpdev
.nr
= NVSW_SN2201_MAIN_MUX_CH1_NR
,
419 .reg
= NVSW_SN2201_PS_DC_OK_STATUS_OFFSET
,
421 .hpdev
.brdinfo
= &nvsw_sn2201_pwr_devices
[1],
422 .hpdev
.nr
= NVSW_SN2201_MAIN_MUX_CH2_NR
,
426 static struct mlxreg_core_data nvsw_sn2201_fan_items_data
[] = {
429 .reg
= NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
,
431 .hpdev
.brdinfo
= &nvsw_sn2201_fan_devices
[0],
432 .hpdev
.nr
= NVSW_SN2201_2ND_MUX_CH0_NR
,
436 .reg
= NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
,
438 .hpdev
.brdinfo
= &nvsw_sn2201_fan_devices
[1],
439 .hpdev
.nr
= NVSW_SN2201_2ND_MUX_CH1_NR
,
443 .reg
= NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
,
445 .hpdev
.brdinfo
= &nvsw_sn2201_fan_devices
[2],
446 .hpdev
.nr
= NVSW_SN2201_2ND_MUX_CH2_NR
,
450 .reg
= NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
,
452 .hpdev
.brdinfo
= &nvsw_sn2201_fan_devices
[3],
453 .hpdev
.nr
= NVSW_SN2201_2ND_MUX_CH3_NR
,
457 static struct mlxreg_core_data nvsw_sn2201_sys_items_data
[] = {
459 .label
= "nic_smb_alert",
460 .reg
= NVSW_SN2201_ASIC_STATUS_OFFSET
,
462 .hpdev
.nr
= NVSW_SN2201_NR_NONE
,
466 .reg
= NVSW_SN2201_ASIC_STATUS_OFFSET
,
468 .hpdev
.nr
= NVSW_SN2201_NR_NONE
,
471 .label
= "mac_health",
472 .reg
= NVSW_SN2201_ASIC_STATUS_OFFSET
,
474 .hpdev
.nr
= NVSW_SN2201_NR_NONE
,
478 static struct mlxreg_core_item nvsw_sn2201_items
[] = {
480 .data
= nvsw_sn2201_psu_items_data
,
481 .aggr_mask
= NVSW_SN2201_CPLD_AGGR_PSU_MASK_DEF
,
482 .reg
= NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
,
483 .mask
= NVSW_SN2201_CPLD_PSU_MASK
,
484 .count
= ARRAY_SIZE(nvsw_sn2201_psu_items_data
),
489 .data
= nvsw_sn2201_pwr_items_data
,
490 .aggr_mask
= NVSW_SN2201_CPLD_AGGR_PWR_MASK_DEF
,
491 .reg
= NVSW_SN2201_PS_DC_OK_STATUS_OFFSET
,
492 .mask
= NVSW_SN2201_CPLD_PWR_MASK
,
493 .count
= ARRAY_SIZE(nvsw_sn2201_pwr_items_data
),
498 .data
= nvsw_sn2201_fan_items_data
,
499 .aggr_mask
= NVSW_SN2201_CPLD_AGGR_FAN_MASK_DEF
,
500 .reg
= NVSW_SN2201_FAN_PRSNT_STATUS_OFFSET
,
501 .mask
= NVSW_SN2201_CPLD_FAN_MASK
,
502 .count
= ARRAY_SIZE(nvsw_sn2201_fan_items_data
),
507 .data
= nvsw_sn2201_sys_items_data
,
508 .aggr_mask
= NVSW_SN2201_CPLD_AGGR_ASIC_MASK_DEF
,
509 .reg
= NVSW_SN2201_ASIC_STATUS_OFFSET
,
510 .mask
= NVSW_SN2201_CPLD_ASIC_MASK
,
511 .count
= ARRAY_SIZE(nvsw_sn2201_sys_items_data
),
518 struct mlxreg_core_hotplug_platform_data nvsw_sn2201_hotplug
= {
519 .items
= nvsw_sn2201_items
,
520 .counter
= ARRAY_SIZE(nvsw_sn2201_items
),
521 .cell
= NVSW_SN2201_SYS_INT_STATUS_OFFSET
,
522 .mask
= NVSW_SN2201_CPLD_AGGR_MASK_DEF
,
525 /* SN2201 static devices. */
526 static struct i2c_board_info nvsw_sn2201_static_devices
[] = {
528 I2C_BOARD_INFO("24c02", 0x57),
531 I2C_BOARD_INFO("lm75", 0x4b),
534 I2C_BOARD_INFO("24c64", 0x56),
537 I2C_BOARD_INFO("ads1015", 0x49),
540 I2C_BOARD_INFO("pca9546", 0x71),
543 I2C_BOARD_INFO("emc2305", 0x4d),
546 I2C_BOARD_INFO("lm75", 0x49),
549 I2C_BOARD_INFO("pca9555", 0x27),
552 I2C_BOARD_INFO("powr1014", 0x37),
555 I2C_BOARD_INFO("lm75", 0x4f),
558 I2C_BOARD_INFO("pmbus", 0x40),
562 /* SN2201 default static board info. */
563 static struct mlxreg_hotplug_device nvsw_sn2201_static_brdinfo
[] = {
565 .brdinfo
= &nvsw_sn2201_static_devices
[0],
566 .nr
= NVSW_SN2201_MAIN_NR
,
569 .brdinfo
= &nvsw_sn2201_static_devices
[1],
570 .nr
= NVSW_SN2201_MAIN_MUX_CH0_NR
,
573 .brdinfo
= &nvsw_sn2201_static_devices
[2],
574 .nr
= NVSW_SN2201_MAIN_MUX_CH0_NR
,
577 .brdinfo
= &nvsw_sn2201_static_devices
[3],
578 .nr
= NVSW_SN2201_MAIN_MUX_CH0_NR
,
581 .brdinfo
= &nvsw_sn2201_static_devices
[4],
582 .nr
= NVSW_SN2201_MAIN_MUX_CH3_NR
,
585 .brdinfo
= &nvsw_sn2201_static_devices
[5],
586 .nr
= NVSW_SN2201_MAIN_MUX_CH5_NR
,
589 .brdinfo
= &nvsw_sn2201_static_devices
[6],
590 .nr
= NVSW_SN2201_MAIN_MUX_CH5_NR
,
593 .brdinfo
= &nvsw_sn2201_static_devices
[7],
594 .nr
= NVSW_SN2201_MAIN_MUX_CH5_NR
,
597 .brdinfo
= &nvsw_sn2201_static_devices
[8],
598 .nr
= NVSW_SN2201_MAIN_MUX_CH6_NR
,
601 .brdinfo
= &nvsw_sn2201_static_devices
[9],
602 .nr
= NVSW_SN2201_MAIN_MUX_CH6_NR
,
605 .brdinfo
= &nvsw_sn2201_static_devices
[10],
606 .nr
= NVSW_SN2201_MAIN_MUX_CH7_NR
,
610 /* LED default data. */
611 static struct mlxreg_core_data nvsw_sn2201_led_data
[] = {
613 .label
= "status:green",
614 .reg
= NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET
,
615 .mask
= GENMASK(7, 4),
618 .label
= "status:orange",
619 .reg
= NVSW_SN2201_FRONT_SYS_LED_CTRL_OFFSET
,
620 .mask
= GENMASK(7, 4),
623 .label
= "psu:green",
624 .reg
= NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET
,
625 .mask
= GENMASK(7, 4),
628 .label
= "psu:orange",
629 .reg
= NVSW_SN2201_FRONT_PSU_LED_CTRL_OFFSET
,
630 .mask
= GENMASK(7, 4),
634 .reg
= NVSW_SN2201_FRONT_UID_LED_CTRL_OFFSET
,
635 .mask
= GENMASK(7, 4),
638 .label
= "fan1:green",
639 .reg
= NVSW_SN2201_FAN_LED1_CTRL_OFFSET
,
640 .mask
= GENMASK(7, 4),
643 .label
= "fan1:orange",
644 .reg
= NVSW_SN2201_FAN_LED1_CTRL_OFFSET
,
645 .mask
= GENMASK(7, 4),
648 .label
= "fan2:green",
649 .reg
= NVSW_SN2201_FAN_LED1_CTRL_OFFSET
,
650 .mask
= GENMASK(3, 0),
653 .label
= "fan2:orange",
654 .reg
= NVSW_SN2201_FAN_LED1_CTRL_OFFSET
,
655 .mask
= GENMASK(3, 0),
658 .label
= "fan3:green",
659 .reg
= NVSW_SN2201_FAN_LED2_CTRL_OFFSET
,
660 .mask
= GENMASK(7, 4),
663 .label
= "fan3:orange",
664 .reg
= NVSW_SN2201_FAN_LED2_CTRL_OFFSET
,
665 .mask
= GENMASK(7, 4),
668 .label
= "fan4:green",
669 .reg
= NVSW_SN2201_FAN_LED2_CTRL_OFFSET
,
670 .mask
= GENMASK(3, 0),
673 .label
= "fan4:orange",
674 .reg
= NVSW_SN2201_FAN_LED2_CTRL_OFFSET
,
675 .mask
= GENMASK(3, 0),
679 static struct mlxreg_core_platform_data nvsw_sn2201_led
= {
680 .data
= nvsw_sn2201_led_data
,
681 .counter
= ARRAY_SIZE(nvsw_sn2201_led_data
),
684 /* Default register access data. */
685 static struct mlxreg_core_data nvsw_sn2201_io_data
[] = {
687 .label
= "cpld1_version",
688 .reg
= NVSW_SN2201_CPLD_VER_OFFSET
,
689 .bit
= GENMASK(7, 0),
693 .label
= "cpld1_version_min",
694 .reg
= NVSW_SN2201_CPLD_MVER_OFFSET
,
695 .bit
= GENMASK(7, 0),
700 .reg
= NVSW_SN2201_CPLD_PN_OFFSET
,
701 .bit
= GENMASK(15, 0),
707 .reg
= NVSW_SN2201_PSU_CTRL_OFFSET
,
708 .mask
= GENMASK(7, 0) & ~BIT(0),
713 .reg
= NVSW_SN2201_PSU_CTRL_OFFSET
,
714 .mask
= GENMASK(7, 0) & ~BIT(1),
718 .label
= "pwr_cycle",
719 .reg
= NVSW_SN2201_PSU_CTRL_OFFSET
,
720 .mask
= GENMASK(7, 0) & ~BIT(2),
724 .label
= "asic_health",
725 .reg
= NVSW_SN2201_SYS_STATUS_OFFSET
,
726 .mask
= GENMASK(4, 3),
731 .label
= "qsfp_pwr_good",
732 .reg
= NVSW_SN2201_SYS_STATUS_OFFSET
,
733 .mask
= GENMASK(7, 0) & ~BIT(0),
737 .label
= "phy_reset",
738 .reg
= NVSW_SN2201_SYS_RST_STATUS_OFFSET
,
739 .mask
= GENMASK(7, 0) & ~BIT(3),
743 .label
= "mac_reset",
744 .reg
= NVSW_SN2201_SYS_RST_STATUS_OFFSET
,
745 .mask
= GENMASK(7, 0) & ~BIT(2),
750 .reg
= NVSW_SN2201_RST_SW_CTRL_OFFSET
,
751 .mask
= GENMASK(7, 0) & ~BIT(0),
755 .label
= "reset_long_pb",
756 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
757 .mask
= GENMASK(7, 0) & ~BIT(0),
761 .label
= "reset_short_pb",
762 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
763 .mask
= GENMASK(7, 0) & ~BIT(1),
767 .label
= "reset_aux_pwr_or_fu",
768 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
769 .mask
= GENMASK(7, 0) & ~BIT(2),
773 .label
= "reset_swb_dc_dc_pwr_fail",
774 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
775 .mask
= GENMASK(7, 0) & ~BIT(3),
779 .label
= "reset_sw_reset",
780 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
781 .mask
= GENMASK(7, 0) & ~BIT(4),
785 .label
= "reset_fw_reset",
786 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
787 .mask
= GENMASK(7, 0) & ~BIT(5),
791 .label
= "reset_swb_wd",
792 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
793 .mask
= GENMASK(7, 0) & ~BIT(6),
797 .label
= "reset_asic_thermal",
798 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
799 .mask
= GENMASK(7, 0) & ~BIT(7),
803 .label
= "reset_system",
804 .reg
= NVSW_SN2201_RST_CAUSE2_OFFSET
,
805 .mask
= GENMASK(7, 0) & ~BIT(1),
809 .label
= "reset_sw_pwr_off",
810 .reg
= NVSW_SN2201_RST_CAUSE2_OFFSET
,
811 .mask
= GENMASK(7, 0) & ~BIT(2),
815 .label
= "reset_cpu_pwr_fail_thermal",
816 .reg
= NVSW_SN2201_RST_CAUSE2_OFFSET
,
817 .mask
= GENMASK(7, 0) & ~BIT(4),
821 .label
= "reset_reload_bios",
822 .reg
= NVSW_SN2201_RST_CAUSE2_OFFSET
,
823 .mask
= GENMASK(7, 0) & ~BIT(5),
827 .label
= "reset_ac_pwr_fail",
828 .reg
= NVSW_SN2201_RST_CAUSE2_OFFSET
,
829 .mask
= GENMASK(7, 0) & ~BIT(6),
834 .reg
= NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
,
835 .mask
= GENMASK(7, 0) & ~BIT(0),
840 .reg
= NVSW_SN2201_PS_PRSNT_STATUS_OFFSET
,
841 .mask
= GENMASK(7, 0) & ~BIT(1),
846 static struct mlxreg_core_platform_data nvsw_sn2201_regs_io
= {
847 .data
= nvsw_sn2201_io_data
,
848 .counter
= ARRAY_SIZE(nvsw_sn2201_io_data
),
851 /* Default watchdog data. */
852 static struct mlxreg_core_data nvsw_sn2201_wd_data
[] = {
855 .reg
= NVSW_SN2201_WD_ACT_OFFSET
,
856 .mask
= GENMASK(7, 1),
861 .reg
= NVSW_SN2201_WD_TMR_OFFSET_LSB
,
863 .health_cntr
= NVSW_SN2201_WD_DFLT_TIMEOUT
,
867 .reg
= NVSW_SN2201_WD_TMR_OFFSET_LSB
,
872 .reg
= NVSW_SN2201_WD_ACT_OFFSET
,
873 .mask
= GENMASK(7, 1),
878 .reg
= NVSW_SN2201_RST_CAUSE1_OFFSET
,
879 .mask
= GENMASK(7, 0) & ~BIT(6),
884 static struct mlxreg_core_platform_data nvsw_sn2201_wd
= {
885 .data
= nvsw_sn2201_wd_data
,
886 .counter
= ARRAY_SIZE(nvsw_sn2201_wd_data
),
887 .version
= MLX_WDT_TYPE3
,
888 .identity
= "mlx-wdt-main",
892 nvsw_sn2201_create_static_devices(struct nvsw_sn2201
*nvsw_sn2201
,
893 struct mlxreg_hotplug_device
*devs
,
896 struct mlxreg_hotplug_device
*dev
= devs
;
900 /* Create I2C static devices. */
901 for (i
= 0; i
< size
; i
++, dev
++) {
902 dev
->client
= i2c_new_client_device(dev
->adapter
, dev
->brdinfo
);
903 if (IS_ERR(dev
->client
)) {
904 dev_err(nvsw_sn2201
->dev
, "Failed to create client %s at bus %d at addr 0x%02x\n",
906 dev
->nr
, dev
->brdinfo
->addr
);
909 ret
= PTR_ERR(dev
->client
);
910 goto fail_create_static_devices
;
916 fail_create_static_devices
:
919 i2c_unregister_device(dev
->client
);
926 static void nvsw_sn2201_destroy_static_devices(struct nvsw_sn2201
*nvsw_sn2201
,
927 struct mlxreg_hotplug_device
*devs
, int size
)
929 struct mlxreg_hotplug_device
*dev
= devs
;
932 /* Destroy static I2C device for SN2201 static devices. */
933 for (i
= 0; i
< size
; i
++, dev
++) {
935 i2c_unregister_device(dev
->client
);
937 i2c_put_adapter(dev
->adapter
);
943 static int nvsw_sn2201_config_post_init(struct nvsw_sn2201
*nvsw_sn2201
)
945 struct mlxreg_hotplug_device
*sn2201_dev
;
946 struct i2c_adapter
*adap
;
950 dev
= nvsw_sn2201
->dev
;
951 adap
= i2c_get_adapter(nvsw_sn2201
->main_mux_deferred_nr
);
953 dev_err(dev
, "Failed to get adapter for bus %d\n",
954 nvsw_sn2201
->main_mux_deferred_nr
);
957 i2c_put_adapter(adap
);
959 /* Update board info. */
960 sn2201_dev
= nvsw_sn2201
->sn2201_devs
;
961 for (i
= 0; i
< nvsw_sn2201
->sn2201_devs_num
; i
++, sn2201_dev
++) {
962 sn2201_dev
->adapter
= i2c_get_adapter(sn2201_dev
->nr
);
963 if (!sn2201_dev
->adapter
)
965 i2c_put_adapter(sn2201_dev
->adapter
);
968 err
= nvsw_sn2201_create_static_devices(nvsw_sn2201
, nvsw_sn2201
->sn2201_devs
,
969 nvsw_sn2201
->sn2201_devs_num
);
971 dev_err(dev
, "Failed to create static devices\n");
976 static int nvsw_sn2201_config_init(struct nvsw_sn2201
*nvsw_sn2201
, void *regmap
)
978 struct device
*dev
= nvsw_sn2201
->dev
;
981 nvsw_sn2201
->io_data
= &nvsw_sn2201_regs_io
;
982 nvsw_sn2201
->led_data
= &nvsw_sn2201_led
;
983 nvsw_sn2201
->wd_data
= &nvsw_sn2201_wd
;
984 nvsw_sn2201
->hotplug_data
= &nvsw_sn2201_hotplug
;
986 /* Register IO access driver. */
987 if (nvsw_sn2201
->io_data
) {
988 nvsw_sn2201
->io_data
->regmap
= regmap
;
989 nvsw_sn2201
->io_regs
=
990 platform_device_register_resndata(dev
, "mlxreg-io", PLATFORM_DEVID_NONE
, NULL
, 0,
991 nvsw_sn2201
->io_data
,
992 sizeof(*nvsw_sn2201
->io_data
));
993 if (IS_ERR(nvsw_sn2201
->io_regs
)) {
994 err
= PTR_ERR(nvsw_sn2201
->io_regs
);
995 goto fail_register_io
;
999 /* Register LED driver. */
1000 if (nvsw_sn2201
->led_data
) {
1001 nvsw_sn2201
->led_data
->regmap
= regmap
;
1003 platform_device_register_resndata(dev
, "leds-mlxreg", PLATFORM_DEVID_NONE
, NULL
, 0,
1004 nvsw_sn2201
->led_data
,
1005 sizeof(*nvsw_sn2201
->led_data
));
1006 if (IS_ERR(nvsw_sn2201
->led
)) {
1007 err
= PTR_ERR(nvsw_sn2201
->led
);
1008 goto fail_register_led
;
1012 /* Register WD driver. */
1013 if (nvsw_sn2201
->wd_data
) {
1014 nvsw_sn2201
->wd_data
->regmap
= regmap
;
1016 platform_device_register_resndata(dev
, "mlx-wdt", PLATFORM_DEVID_NONE
, NULL
, 0,
1017 nvsw_sn2201
->wd_data
,
1018 sizeof(*nvsw_sn2201
->wd_data
));
1019 if (IS_ERR(nvsw_sn2201
->wd
)) {
1020 err
= PTR_ERR(nvsw_sn2201
->wd
);
1021 goto fail_register_wd
;
1025 /* Register hotplug driver. */
1026 if (nvsw_sn2201
->hotplug_data
) {
1027 nvsw_sn2201
->hotplug_data
->regmap
= regmap
;
1028 nvsw_sn2201
->pdev_hotplug
=
1029 platform_device_register_resndata(dev
, "mlxreg-hotplug", PLATFORM_DEVID_NONE
,
1030 nvsw_sn2201_cpld_res
,
1031 ARRAY_SIZE(nvsw_sn2201_cpld_res
),
1032 nvsw_sn2201
->hotplug_data
,
1033 sizeof(*nvsw_sn2201
->hotplug_data
));
1034 if (IS_ERR(nvsw_sn2201
->pdev_hotplug
)) {
1035 err
= PTR_ERR(nvsw_sn2201
->pdev_hotplug
);
1036 goto fail_register_hotplug
;
1040 return nvsw_sn2201_config_post_init(nvsw_sn2201
);
1042 fail_register_hotplug
:
1043 if (nvsw_sn2201
->wd
)
1044 platform_device_unregister(nvsw_sn2201
->wd
);
1046 if (nvsw_sn2201
->led
)
1047 platform_device_unregister(nvsw_sn2201
->led
);
1049 if (nvsw_sn2201
->io_regs
)
1050 platform_device_unregister(nvsw_sn2201
->io_regs
);
1056 static void nvsw_sn2201_config_exit(struct nvsw_sn2201
*nvsw_sn2201
)
1058 /* Unregister hotplug driver. */
1059 if (nvsw_sn2201
->pdev_hotplug
)
1060 platform_device_unregister(nvsw_sn2201
->pdev_hotplug
);
1061 /* Unregister WD driver. */
1062 if (nvsw_sn2201
->wd
)
1063 platform_device_unregister(nvsw_sn2201
->wd
);
1064 /* Unregister LED driver. */
1065 if (nvsw_sn2201
->led
)
1066 platform_device_unregister(nvsw_sn2201
->led
);
1067 /* Unregister IO access driver. */
1068 if (nvsw_sn2201
->io_regs
)
1069 platform_device_unregister(nvsw_sn2201
->io_regs
);
1073 * Initialization is divided into two parts:
1074 * - I2C main bus init.
1075 * - Mux creation and attaching devices to the mux,
1076 * which assumes that the main bus is already created.
1077 * This separation is required for synchronization between these two parts.
1078 * Completion notify callback is used to make this flow synchronized.
1080 static int nvsw_sn2201_i2c_completion_notify(void *handle
, int id
)
1082 struct nvsw_sn2201
*nvsw_sn2201
= handle
;
1086 /* Create main mux. */
1087 nvsw_sn2201
->main_mux_devs
->adapter
= i2c_get_adapter(nvsw_sn2201
->main_mux_devs
->nr
);
1088 if (!nvsw_sn2201
->main_mux_devs
->adapter
) {
1090 dev_err(nvsw_sn2201
->dev
, "Failed to get adapter for bus %d\n",
1091 nvsw_sn2201
->cpld_devs
->nr
);
1092 goto i2c_get_adapter_main_fail
;
1095 nvsw_sn2201
->main_mux_devs_num
= ARRAY_SIZE(nvsw_sn2201_main_mux_brdinfo
);
1096 err
= nvsw_sn2201_create_static_devices(nvsw_sn2201
, nvsw_sn2201
->main_mux_devs
,
1097 nvsw_sn2201
->main_mux_devs_num
);
1099 dev_err(nvsw_sn2201
->dev
, "Failed to create main mux devices\n");
1100 goto nvsw_sn2201_create_static_devices_fail
;
1103 nvsw_sn2201
->cpld_devs
->adapter
= i2c_get_adapter(nvsw_sn2201
->cpld_devs
->nr
);
1104 if (!nvsw_sn2201
->cpld_devs
->adapter
) {
1106 dev_err(nvsw_sn2201
->dev
, "Failed to get adapter for bus %d\n",
1107 nvsw_sn2201
->cpld_devs
->nr
);
1108 goto i2c_get_adapter_fail
;
1111 /* Create CPLD device. */
1112 nvsw_sn2201
->cpld_devs
->client
= i2c_new_dummy_device(nvsw_sn2201
->cpld_devs
->adapter
,
1113 NVSW_SN2201_CPLD_I2CADDR
);
1114 if (IS_ERR(nvsw_sn2201
->cpld_devs
->client
)) {
1115 err
= PTR_ERR(nvsw_sn2201
->cpld_devs
->client
);
1116 dev_err(nvsw_sn2201
->dev
, "Failed to create %s cpld device at bus %d at addr 0x%02x\n",
1117 nvsw_sn2201
->cpld_devs
->brdinfo
->type
, nvsw_sn2201
->cpld_devs
->nr
,
1118 nvsw_sn2201
->cpld_devs
->brdinfo
->addr
);
1119 goto i2c_new_dummy_fail
;
1122 regmap
= devm_regmap_init_i2c(nvsw_sn2201
->cpld_devs
->client
, &nvsw_sn2201_regmap_conf
);
1123 if (IS_ERR(regmap
)) {
1124 err
= PTR_ERR(regmap
);
1125 dev_err(nvsw_sn2201
->dev
, "Failed to initialise managed register map\n");
1126 goto devm_regmap_init_i2c_fail
;
1129 /* Set default registers. */
1130 for (i
= 0; i
< nvsw_sn2201_regmap_conf
.num_reg_defaults
; i
++) {
1131 err
= regmap_write(regmap
, nvsw_sn2201_regmap_default
[i
].reg
,
1132 nvsw_sn2201_regmap_default
[i
].def
);
1134 dev_err(nvsw_sn2201
->dev
, "Failed to set register at offset 0x%02x to default value: 0x%02x\n",
1135 nvsw_sn2201_regmap_default
[i
].reg
,
1136 nvsw_sn2201_regmap_default
[i
].def
);
1137 goto regmap_write_fail
;
1141 /* Sync registers with hardware. */
1142 regcache_mark_dirty(regmap
);
1143 err
= regcache_sync(regmap
);
1145 dev_err(nvsw_sn2201
->dev
, "Failed to Sync registers with hardware\n");
1146 goto regcache_sync_fail
;
1149 /* Configure SN2201 board. */
1150 err
= nvsw_sn2201_config_init(nvsw_sn2201
, regmap
);
1152 dev_err(nvsw_sn2201
->dev
, "Failed to configure board\n");
1153 goto nvsw_sn2201_config_init_fail
;
1158 nvsw_sn2201_config_init_fail
:
1159 nvsw_sn2201_config_exit(nvsw_sn2201
);
1162 devm_regmap_init_i2c_fail
:
1164 i2c_put_adapter(nvsw_sn2201
->cpld_devs
->adapter
);
1165 nvsw_sn2201
->cpld_devs
->adapter
= NULL
;
1166 i2c_get_adapter_fail
:
1167 /* Destroy SN2201 static I2C devices. */
1168 nvsw_sn2201_destroy_static_devices(nvsw_sn2201
, nvsw_sn2201
->sn2201_devs
,
1169 nvsw_sn2201
->sn2201_devs_num
);
1170 /* Destroy main mux device. */
1171 nvsw_sn2201_destroy_static_devices(nvsw_sn2201
, nvsw_sn2201
->main_mux_devs
,
1172 nvsw_sn2201
->main_mux_devs_num
);
1173 nvsw_sn2201_create_static_devices_fail
:
1174 i2c_put_adapter(nvsw_sn2201
->main_mux_devs
->adapter
);
1175 i2c_get_adapter_main_fail
:
1179 static int nvsw_sn2201_config_pre_init(struct nvsw_sn2201
*nvsw_sn2201
)
1181 nvsw_sn2201
->i2c_data
= &nvsw_sn2201_i2c_data
;
1183 /* Register I2C controller. */
1184 nvsw_sn2201
->i2c_data
->handle
= nvsw_sn2201
;
1185 nvsw_sn2201
->i2c_data
->completion_notify
= nvsw_sn2201_i2c_completion_notify
;
1186 nvsw_sn2201
->pdev_i2c
= platform_device_register_resndata(nvsw_sn2201
->dev
, "i2c_mlxcpld",
1187 NVSW_SN2201_MAIN_MUX_NR
,
1188 nvsw_sn2201_lpc_res
,
1189 ARRAY_SIZE(nvsw_sn2201_lpc_res
),
1190 nvsw_sn2201
->i2c_data
,
1191 sizeof(*nvsw_sn2201
->i2c_data
));
1192 if (IS_ERR(nvsw_sn2201
->pdev_i2c
))
1193 return PTR_ERR(nvsw_sn2201
->pdev_i2c
);
1198 static int nvsw_sn2201_probe(struct platform_device
*pdev
)
1200 struct nvsw_sn2201
*nvsw_sn2201
;
1203 nvsw_sn2201
= devm_kzalloc(&pdev
->dev
, sizeof(*nvsw_sn2201
), GFP_KERNEL
);
1207 nvsw_sn2201
->dev
= &pdev
->dev
;
1208 platform_set_drvdata(pdev
, nvsw_sn2201
);
1209 ret
= platform_device_add_resources(pdev
, nvsw_sn2201_lpc_io_resources
,
1210 ARRAY_SIZE(nvsw_sn2201_lpc_io_resources
));
1214 nvsw_sn2201
->main_mux_deferred_nr
= NVSW_SN2201_MAIN_MUX_DEFER_NR
;
1215 nvsw_sn2201
->main_mux_devs
= nvsw_sn2201_main_mux_brdinfo
;
1216 nvsw_sn2201
->cpld_devs
= nvsw_sn2201_cpld_brdinfo
;
1217 nvsw_sn2201
->sn2201_devs
= nvsw_sn2201_static_brdinfo
;
1218 nvsw_sn2201
->sn2201_devs_num
= ARRAY_SIZE(nvsw_sn2201_static_brdinfo
);
1220 return nvsw_sn2201_config_pre_init(nvsw_sn2201
);
1223 static void nvsw_sn2201_remove(struct platform_device
*pdev
)
1225 struct nvsw_sn2201
*nvsw_sn2201
= platform_get_drvdata(pdev
);
1227 /* Unregister underlying drivers. */
1228 nvsw_sn2201_config_exit(nvsw_sn2201
);
1230 /* Destroy SN2201 static I2C devices. */
1231 nvsw_sn2201_destroy_static_devices(nvsw_sn2201
,
1232 nvsw_sn2201
->sn2201_devs
,
1233 nvsw_sn2201
->sn2201_devs_num
);
1235 i2c_put_adapter(nvsw_sn2201
->cpld_devs
->adapter
);
1236 nvsw_sn2201
->cpld_devs
->adapter
= NULL
;
1237 /* Destroy main mux device. */
1238 nvsw_sn2201_destroy_static_devices(nvsw_sn2201
,
1239 nvsw_sn2201
->main_mux_devs
,
1240 nvsw_sn2201
->main_mux_devs_num
);
1242 /* Unregister I2C controller. */
1243 if (nvsw_sn2201
->pdev_i2c
)
1244 platform_device_unregister(nvsw_sn2201
->pdev_i2c
);
1247 static const struct acpi_device_id nvsw_sn2201_acpi_ids
[] = {
1252 MODULE_DEVICE_TABLE(acpi
, nvsw_sn2201_acpi_ids
);
1254 static struct platform_driver nvsw_sn2201_driver
= {
1255 .probe
= nvsw_sn2201_probe
,
1256 .remove
= nvsw_sn2201_remove
,
1258 .name
= "nvsw-sn2201",
1259 .acpi_match_table
= nvsw_sn2201_acpi_ids
,
1263 module_platform_driver(nvsw_sn2201_driver
);
1265 MODULE_AUTHOR("Nvidia");
1266 MODULE_DESCRIPTION("Nvidia sn2201 platform driver");
1267 MODULE_LICENSE("Dual BSD/GPL");
1268 MODULE_ALIAS("platform:nvsw-sn2201");