• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef DRIVERS_I2C_NCT7802Y_H
4 #define DRIVERS_I2C_NCT7802Y_H
5 
6 #include <types.h>
7 #include <console/console.h>
8 #include <device/device.h>
9 #include <device/i2c_bus.h>
10 
11 #define BANK_SELECT			0x00
12 
13 /* Bank 0 */
14 #define MODE_SELECTION			0x22
15 #define  MODE_SELECTION_LTD_EN		(1 << 6)
16 #define  MODE_SELECTION_RTDx(x, val)	((val) << (x) * 2)
17 
18 #define PECI_ENABLE			0x23
19 #define  PECI_ENABLE_AGENTx(x)		(1 << (x))
20 
21 #define FAN_ENABLE			0x24
22 #define  FANx_ENABLE(fan)		(1 << (fan))
23 
24 #define FAN_CTRL(fan)			(0x60 + (fan))
25 
26 #define CLOSE_LOOP_FAN_RPM_CTRL		0x63
27 #define  CLOSE_LOOP_FANx_EN(fan)	(1 << ((fan) + 5))
28 #define  CLOSE_LOOP_FANx_HIGH_RPM(fan)	(1 << ((fan) + 2))
29 #define  CLOSE_LOOP_FAN_PECI_ERR_MASK	(3 << 0)
30 #define  CLOSE_LOOP_FAN_PECI_ERR_CURR	(0 << 0)
31 #define  CLOSE_LOOP_FAN_PECI_ERR_VALUE	(1 << 0)
32 #define  CLOSE_LOOP_FAN_PECI_ERR_MAX	(2 << 0)
33 
34 #define TEMP_SHIFT(temp) (((temp) % 2) * 4)
35 #define TEMP_TO_FAN_MAP(temp)		(0x64 + (temp) / 2)
36 #define  TEMPx_TO_FAN_MAP_MASK(temp)	(7 << TEMP_SHIFT(temp))
37 #define  TEMPx_TO_FANy_MAP(temp, fan)	(1 << (TEMP_SHIFT(temp) + (fan)))
38 
39 #define FAN_CTRL_TEMP_SRC(temp)		(0x68 + (temp) / 2)
40 #define  FAN_CTRL_TEMPx_SRC_MASK(temp)	(7 << TEMP_SHIFT(temp))
41 #define  FAN_CTRL_TEMPx_SRCy(temp, src)	((src) << TEMP_SHIFT(temp))
42 
43 #define FAN_DUTY_ON_PECI_ERROR		0x7a
44 
45 #define TABLEx_TEMP_POINTy(fan, pt)	(0x80 + (0x10 * (fan)) + (pt))
46 #define TABLEx_TARGET_POINTy(fan, pt)	(0x85 + (0x10 * (fan)) + (pt))
47 
48 /* Bank 1 */
49 
50 #define PECI_CTRL_1			0x01
51 #define  PECI_CTRL_1_EN			(1 << 7)
52 #define  PECI_CTRL_1_MANUAL_EN		(1 << 1)
53 #define  PECI_CTRL_1_ROUTINE_EN		(1 << 0)
54 
55 #define PECI_CTRL_3			0x03
56 #define  PECI_CTRL_3_EN_AGENTx(x)	(1 << ((x) + 4))
57 #define  PECI_CTRL_3_HAS_DOM1_AGENTx(x)	(1 << (x))
58 
59 #define PECI_REPORT_TEMP_STYLE		0x04
60 #define  PECI_TEMP_STYLE_DOM0_AGENTx(x)	(0 << ((x) + 1))
61 #define  PECI_TEMP_STYLE_DOM1_AGENTx(x)	(1 << ((x) + 1))
62 #define  PECI_TEMP_STYLE_SINGLE		(0 << 0)
63 #define  PECI_TEMP_STYLE_HIGHEST	(1 << 0)
64 
65 #define PECI_BASE_TEMP_AGENT(x)		(0x09 + (x))
66 #define  PECI_BASE_TEMP_MAX		(0x7f << 0)
67 
nct7802y_select_bank(struct device * const dev,const u8 bank)68 static inline int nct7802y_select_bank(struct device *const dev, const u8 bank)
69 {
70 	const int ret = i2c_dev_writeb_at(dev, BANK_SELECT, bank);
71 	if (ret != CB_SUCCESS)
72 		printk(BIOS_NOTICE, "nct7802y: Select bank failed: %d\n", ret);
73 	return ret;
74 }
75 
nct7802y_write(struct device * const dev,const u8 reg,const u8 value)76 static inline int nct7802y_write(struct device *const dev,
77 				 const u8 reg, const u8 value)
78 {
79 	return i2c_dev_writeb_at(dev, reg, value);
80 }
81 
nct7802y_update(struct device * const dev,const u8 reg,const u8 clear_mask,const u8 set_mask)82 static inline int nct7802y_update(struct device *const dev, const u8 reg,
83 				  const u8 clear_mask, const u8 set_mask)
84 {
85 	const int val = i2c_dev_readb_at(dev, reg);
86 	if (val < 0)
87 		return val;
88 	return i2c_dev_writeb_at(dev, reg, (val & ~clear_mask) | set_mask);
89 }
90 
91 void nct7802y_init_fan(struct device *dev);
92 void nct7802y_init_peci(struct device *dev);
93 
94 #endif /* DRIVERS_I2C_NCT7802Y_H */
95