1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/device.h>
9 void nct7802y_init_peci(struct device
*const dev
)
11 const struct drivers_i2c_nct7802y_config
*const config
= dev
->chip_info
;
12 unsigned int i
, all_off
= 1;
14 /* Bank 1 can only be written to if PECI reading is enabled */
15 if (nct7802y_select_bank(dev
, 0) != CB_SUCCESS
)
17 nct7802y_update(dev
, PECI_ENABLE
, 0, PECI_ENABLE_AGENTx(0));
19 if (nct7802y_select_bank(dev
, 1) != CB_SUCCESS
)
22 for (i
= 0; i
< NCT7802Y_PECI_CNT
; ++i
) {
23 if (config
->peci
[i
].mode
!= PECI_DISABLED
) {
24 u8 ctrl3
= 0, style
= 0;
25 switch (config
->peci
[i
].mode
) {
27 ctrl3
= PECI_CTRL_3_EN_AGENTx(i
);
28 style
= PECI_TEMP_STYLE_DOM0_AGENTx(i
) |
29 PECI_TEMP_STYLE_SINGLE
;
32 ctrl3
= PECI_CTRL_3_EN_AGENTx(i
) |
33 PECI_CTRL_3_HAS_DOM1_AGENTx(i
);
34 style
= PECI_TEMP_STYLE_DOM1_AGENTx(i
) |
35 PECI_TEMP_STYLE_SINGLE
;
38 ctrl3
= PECI_CTRL_3_EN_AGENTx(i
) |
39 PECI_CTRL_3_HAS_DOM1_AGENTx(i
);
40 style
= PECI_TEMP_STYLE_HIGHEST
;
45 nct7802y_update(dev
, PECI_CTRL_1
,
46 PECI_CTRL_1_MANUAL_EN
,
48 PECI_CTRL_1_ROUTINE_EN
);
49 nct7802y_update(dev
, PECI_CTRL_3
,
50 PECI_CTRL_3_HAS_DOM1_AGENTx(i
), ctrl3
);
51 nct7802y_update(dev
, PECI_REPORT_TEMP_STYLE
,
52 PECI_TEMP_STYLE_DOM1_AGENTx(i
) |
53 PECI_TEMP_STYLE_HIGHEST
,
55 nct7802y_write(dev
, PECI_BASE_TEMP_AGENT(i
),
56 config
->peci
[i
].base_temp
);
59 nct7802y_update(dev
, PECI_CTRL_3
,
60 PECI_CTRL_3_EN_AGENTx(i
), 0);
65 nct7802y_update(dev
, PECI_CTRL_1
, PECI_CTRL_1_EN
, 0);
67 /* Disable PECI #0 reading if we only enabled it to access bank 1 */
68 if (config
->peci
[0].mode
== PECI_DISABLED
) {
69 if (nct7802y_select_bank(dev
, 0) != CB_SUCCESS
)
72 nct7802y_update(dev
, PECI_ENABLE
, PECI_ENABLE_AGENTx(0), 0);