nct6775.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __HWMON_NCT6775_H__
  3. #define __HWMON_NCT6775_H__
  4. #include <linux/types.h>
  5. enum kinds { nct6106, nct6116, nct6775, nct6776, nct6779, nct6791, nct6792,
  6. nct6793, nct6795, nct6796, nct6797, nct6798 };
  7. enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 };
  8. #define NUM_TEMP 10 /* Max number of temp attribute sets w/ limits*/
  9. #define NUM_TEMP_FIXED 6 /* Max number of fixed temp attribute sets */
  10. #define NUM_TSI_TEMP 8 /* Max number of TSI temp register pairs */
  11. #define NUM_REG_ALARM 7 /* Max number of alarm registers */
  12. #define NUM_REG_BEEP 5 /* Max number of beep registers */
  13. #define NUM_FAN 7
  14. struct nct6775_data {
  15. int addr; /* IO base of hw monitor block */
  16. int sioreg; /* SIO register address */
  17. enum kinds kind;
  18. const char *name;
  19. const struct attribute_group *groups[7];
  20. u8 num_groups;
  21. u16 reg_temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst,
  22. * 3=temp_crit, 4=temp_lcrit
  23. */
  24. u8 temp_src[NUM_TEMP];
  25. u16 reg_temp_config[NUM_TEMP];
  26. const char * const *temp_label;
  27. u32 temp_mask;
  28. u32 virt_temp_mask;
  29. u16 REG_CONFIG;
  30. u16 REG_VBAT;
  31. u16 REG_DIODE;
  32. u8 DIODE_MASK;
  33. const s8 *ALARM_BITS;
  34. const s8 *BEEP_BITS;
  35. const u16 *REG_VIN;
  36. const u16 *REG_IN_MINMAX[2];
  37. const u16 *REG_TARGET;
  38. const u16 *REG_FAN;
  39. const u16 *REG_FAN_MODE;
  40. const u16 *REG_FAN_MIN;
  41. const u16 *REG_FAN_PULSES;
  42. const u16 *FAN_PULSE_SHIFT;
  43. const u16 *REG_FAN_TIME[3];
  44. const u16 *REG_TOLERANCE_H;
  45. const u8 *REG_PWM_MODE;
  46. const u8 *PWM_MODE_MASK;
  47. const u16 *REG_PWM[7]; /* [0]=pwm, [1]=pwm_start, [2]=pwm_floor,
  48. * [3]=pwm_max, [4]=pwm_step,
  49. * [5]=weight_duty_step, [6]=weight_duty_base
  50. */
  51. const u16 *REG_PWM_READ;
  52. const u16 *REG_CRITICAL_PWM_ENABLE;
  53. u8 CRITICAL_PWM_ENABLE_MASK;
  54. const u16 *REG_CRITICAL_PWM;
  55. const u16 *REG_AUTO_TEMP;
  56. const u16 *REG_AUTO_PWM;
  57. const u16 *REG_CRITICAL_TEMP;
  58. const u16 *REG_CRITICAL_TEMP_TOLERANCE;
  59. const u16 *REG_TEMP_SOURCE; /* temp register sources */
  60. const u16 *REG_TEMP_SEL;
  61. const u16 *REG_WEIGHT_TEMP_SEL;
  62. const u16 *REG_WEIGHT_TEMP[3]; /* 0=base, 1=tolerance, 2=step */
  63. const u16 *REG_TEMP_OFFSET;
  64. const u16 *REG_ALARM;
  65. const u16 *REG_BEEP;
  66. const u16 *REG_TSI_TEMP;
  67. unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg);
  68. unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg);
  69. struct mutex update_lock;
  70. bool valid; /* true if following fields are valid */
  71. unsigned long last_updated; /* In jiffies */
  72. /* Register values */
  73. u8 bank; /* current register bank */
  74. u8 in_num; /* number of in inputs we have */
  75. u8 in[15][3]; /* [0]=in, [1]=in_max, [2]=in_min */
  76. unsigned int rpm[NUM_FAN];
  77. u16 fan_min[NUM_FAN];
  78. u8 fan_pulses[NUM_FAN];
  79. u8 fan_div[NUM_FAN];
  80. u8 has_pwm;
  81. u8 has_fan; /* some fan inputs can be disabled */
  82. u8 has_fan_min; /* some fans don't have min register */
  83. bool has_fan_div;
  84. u8 num_temp_alarms; /* 2, 3, or 6 */
  85. u8 num_temp_beeps; /* 2, 3, or 6 */
  86. u8 temp_fixed_num; /* 3 or 6 */
  87. u8 temp_type[NUM_TEMP_FIXED];
  88. s8 temp_offset[NUM_TEMP_FIXED];
  89. s16 temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst,
  90. * 3=temp_crit, 4=temp_lcrit
  91. */
  92. s16 tsi_temp[NUM_TSI_TEMP];
  93. u64 alarms;
  94. u64 beeps;
  95. u8 pwm_num; /* number of pwm */
  96. u8 pwm_mode[NUM_FAN]; /* 0->DC variable voltage,
  97. * 1->PWM variable duty cycle
  98. */
  99. enum pwm_enable pwm_enable[NUM_FAN];
  100. /* 0->off
  101. * 1->manual
  102. * 2->thermal cruise mode (also called SmartFan I)
  103. * 3->fan speed cruise mode
  104. * 4->SmartFan III
  105. * 5->enhanced variable thermal cruise (SmartFan IV)
  106. */
  107. u8 pwm[7][NUM_FAN]; /* [0]=pwm, [1]=pwm_start, [2]=pwm_floor,
  108. * [3]=pwm_max, [4]=pwm_step,
  109. * [5]=weight_duty_step, [6]=weight_duty_base
  110. */
  111. u8 target_temp[NUM_FAN];
  112. u8 target_temp_mask;
  113. u32 target_speed[NUM_FAN];
  114. u32 target_speed_tolerance[NUM_FAN];
  115. u8 speed_tolerance_limit;
  116. u8 temp_tolerance[2][NUM_FAN];
  117. u8 tolerance_mask;
  118. u8 fan_time[3][NUM_FAN]; /* 0 = stop_time, 1 = step_up, 2 = step_down */
  119. /* Automatic fan speed control registers */
  120. int auto_pwm_num;
  121. u8 auto_pwm[NUM_FAN][7];
  122. u8 auto_temp[NUM_FAN][7];
  123. u8 pwm_temp_sel[NUM_FAN];
  124. u8 pwm_weight_temp_sel[NUM_FAN];
  125. u8 weight_temp[3][NUM_FAN]; /* 0->temp_step, 1->temp_step_tol,
  126. * 2->temp_base
  127. */
  128. u8 vid;
  129. u8 vrm;
  130. bool have_vid;
  131. u16 have_temp;
  132. u16 have_temp_fixed;
  133. u16 have_tsi_temp;
  134. u16 have_in;
  135. /* Remember extra register values over suspend/resume */
  136. u8 vbat;
  137. u8 fandiv1;
  138. u8 fandiv2;
  139. u8 sio_reg_enable;
  140. struct regmap *regmap;
  141. bool read_only;
  142. /* driver-specific (platform, i2c) initialization hook and data */
  143. int (*driver_init)(struct nct6775_data *data);
  144. void *driver_data;
  145. };
  146. static inline int nct6775_read_value(struct nct6775_data *data, u16 reg, u16 *value)
  147. {
  148. unsigned int tmp;
  149. int ret = regmap_read(data->regmap, reg, &tmp);
  150. if (!ret)
  151. *value = tmp;
  152. return ret;
  153. }
  154. static inline int nct6775_write_value(struct nct6775_data *data, u16 reg, u16 value)
  155. {
  156. return regmap_write(data->regmap, reg, value);
  157. }
  158. struct nct6775_data *nct6775_update_device(struct device *dev);
  159. bool nct6775_reg_is_word_sized(struct nct6775_data *data, u16 reg);
  160. int nct6775_probe(struct device *dev, struct nct6775_data *data,
  161. const struct regmap_config *regmapcfg);
  162. ssize_t nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf);
  163. ssize_t nct6775_show_beep(struct device *dev, struct device_attribute *attr, char *buf);
  164. ssize_t nct6775_store_beep(struct device *dev, struct device_attribute *attr, const char *buf,
  165. size_t count);
  166. static inline int nct6775_write_temp(struct nct6775_data *data, u16 reg, u16 value)
  167. {
  168. if (!nct6775_reg_is_word_sized(data, reg))
  169. value >>= 8;
  170. return nct6775_write_value(data, reg, value);
  171. }
  172. static inline umode_t nct6775_attr_mode(struct nct6775_data *data, struct attribute *attr)
  173. {
  174. return data->read_only ? (attr->mode & ~0222) : attr->mode;
  175. }
  176. static inline int
  177. nct6775_add_attr_group(struct nct6775_data *data, const struct attribute_group *group)
  178. {
  179. /* Need to leave a NULL terminator at the end of data->groups */
  180. if (data->num_groups == ARRAY_SIZE(data->groups) - 1)
  181. return -ENOBUFS;
  182. data->groups[data->num_groups++] = group;
  183. return 0;
  184. }
  185. #define NCT6775_REG_BANK 0x4E
  186. #define NCT6775_REG_CONFIG 0x40
  187. #define NCT6775_REG_FANDIV1 0x506
  188. #define NCT6775_REG_FANDIV2 0x507
  189. #define NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE 0x28
  190. #define FAN_ALARM_BASE 16
  191. #define TEMP_ALARM_BASE 24
  192. #define INTRUSION_ALARM_BASE 30
  193. #define BEEP_ENABLE_BASE 15
  194. /*
  195. * Not currently used:
  196. * REG_MAN_ID has the value 0x5ca3 for all supported chips.
  197. * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model.
  198. * REG_MAN_ID is at port 0x4f
  199. * REG_CHIP_ID is at port 0x58
  200. */
  201. #endif /* __HWMON_NCT6775_H__ */