mb/google/brya: Create rull variant
[coreboot2.git] / src / drivers / i2c / nct7802y / nct7802y_peci.c
blob840dc2f83a6b97985ae9dbdfaa9a4813c643f711
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <types.h>
4 #include <device/device.h>
6 #include "nct7802y.h"
7 #include "chip.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)
16 return;
17 nct7802y_update(dev, PECI_ENABLE, 0, PECI_ENABLE_AGENTx(0));
19 if (nct7802y_select_bank(dev, 1) != CB_SUCCESS)
20 return;
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) {
26 case PECI_DOMAIN_0:
27 ctrl3 = PECI_CTRL_3_EN_AGENTx(i);
28 style = PECI_TEMP_STYLE_DOM0_AGENTx(i) |
29 PECI_TEMP_STYLE_SINGLE;
30 break;
31 case PECI_DOMAIN_1:
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;
36 break;
37 case PECI_HIGHEST:
38 ctrl3 = PECI_CTRL_3_EN_AGENTx(i) |
39 PECI_CTRL_3_HAS_DOM1_AGENTx(i);
40 style = PECI_TEMP_STYLE_HIGHEST;
41 break;
42 default:
43 break;
45 nct7802y_update(dev, PECI_CTRL_1,
46 PECI_CTRL_1_MANUAL_EN,
47 PECI_CTRL_1_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,
54 style);
55 nct7802y_write(dev, PECI_BASE_TEMP_AGENT(i),
56 config->peci[i].base_temp);
57 all_off = 0;
58 } else {
59 nct7802y_update(dev, PECI_CTRL_3,
60 PECI_CTRL_3_EN_AGENTx(i), 0);
64 if (all_off)
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)
70 return;
72 nct7802y_update(dev, PECI_ENABLE, PECI_ENABLE_AGENTx(0), 0);