/drivers/hwmon/f71882fg.c

http://github.com/mirrors/linux · C · 2798 lines · 2413 code · 292 blank · 93 comment · 192 complexity · 704a96931ed4f77e68ef954b2f9e51d6 MD5 · raw file

Large files are truncated click here to view the full file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /***************************************************************************
  3. * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
  4. * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
  5. * *
  6. ***************************************************************************/
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <linux/jiffies.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/hwmon.h>
  14. #include <linux/hwmon-sysfs.h>
  15. #include <linux/err.h>
  16. #include <linux/mutex.h>
  17. #include <linux/io.h>
  18. #include <linux/acpi.h>
  19. #define DRVNAME "f71882fg"
  20. #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
  21. #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
  22. #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
  23. #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
  24. #define SIO_REG_LDSEL 0x07 /* Logical device select */
  25. #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
  26. #define SIO_REG_DEVREV 0x22 /* Device revision */
  27. #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
  28. #define SIO_REG_ENABLE 0x30 /* Logical device enable */
  29. #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
  30. #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
  31. #define SIO_F71808E_ID 0x0901 /* Chipset ID */
  32. #define SIO_F71808A_ID 0x1001 /* Chipset ID */
  33. #define SIO_F71858_ID 0x0507 /* Chipset ID */
  34. #define SIO_F71862_ID 0x0601 /* Chipset ID */
  35. #define SIO_F71868_ID 0x1106 /* Chipset ID */
  36. #define SIO_F71869_ID 0x0814 /* Chipset ID */
  37. #define SIO_F71869A_ID 0x1007 /* Chipset ID */
  38. #define SIO_F71882_ID 0x0541 /* Chipset ID */
  39. #define SIO_F71889_ID 0x0723 /* Chipset ID */
  40. #define SIO_F71889E_ID 0x0909 /* Chipset ID */
  41. #define SIO_F71889A_ID 0x1005 /* Chipset ID */
  42. #define SIO_F8000_ID 0x0581 /* Chipset ID */
  43. #define SIO_F81768D_ID 0x1210 /* Chipset ID */
  44. #define SIO_F81865_ID 0x0704 /* Chipset ID */
  45. #define SIO_F81866_ID 0x1010 /* Chipset ID */
  46. #define REGION_LENGTH 8
  47. #define ADDR_REG_OFFSET 5
  48. #define DATA_REG_OFFSET 6
  49. #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
  50. #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
  51. #define F71882FG_REG_IN(nr) (0x20 + (nr))
  52. #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
  53. #define F81866_REG_IN_STATUS 0x16 /* F81866 only */
  54. #define F81866_REG_IN_BEEP 0x17 /* F81866 only */
  55. #define F81866_REG_IN1_HIGH 0x3a /* F81866 only */
  56. #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
  57. #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
  58. #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
  59. #define F71882FG_REG_FAN_STATUS 0x92
  60. #define F71882FG_REG_FAN_BEEP 0x93
  61. #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
  62. #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
  63. #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
  64. #define F71882FG_REG_TEMP_STATUS 0x62
  65. #define F71882FG_REG_TEMP_BEEP 0x63
  66. #define F71882FG_REG_TEMP_CONFIG 0x69
  67. #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
  68. #define F71882FG_REG_TEMP_TYPE 0x6B
  69. #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
  70. #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
  71. #define F71882FG_REG_PWM_TYPE 0x94
  72. #define F71882FG_REG_PWM_ENABLE 0x96
  73. #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
  74. #define F71882FG_REG_FAN_FAULT_T 0x9F
  75. #define F71882FG_FAN_NEG_TEMP_EN 0x20
  76. #define F71882FG_FAN_PROG_SEL 0x80
  77. #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
  78. #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
  79. #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
  80. #define F71882FG_REG_START 0x01
  81. #define F71882FG_MAX_INS 11
  82. #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
  83. static unsigned short force_id;
  84. module_param(force_id, ushort, 0);
  85. MODULE_PARM_DESC(force_id, "Override the detected device ID");
  86. enum chips { f71808e, f71808a, f71858fg, f71862fg, f71868a, f71869, f71869a,
  87. f71882fg, f71889fg, f71889ed, f71889a, f8000, f81768d, f81865f,
  88. f81866a};
  89. static const char *const f71882fg_names[] = {
  90. "f71808e",
  91. "f71808a",
  92. "f71858fg",
  93. "f71862fg",
  94. "f71868a",
  95. "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
  96. "f71869a",
  97. "f71882fg",
  98. "f71889fg", /* f81801u too, same id */
  99. "f71889ed",
  100. "f71889a",
  101. "f8000",
  102. "f81768d",
  103. "f81865f",
  104. "f81866a",
  105. };
  106. static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
  107. [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0 },
  108. [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0 },
  109. [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  110. [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  111. [f71868a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
  112. [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  113. [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  114. [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  115. [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  116. [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  117. [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  118. [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  119. [f81768d] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  120. [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
  121. [f81866a] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
  122. };
  123. static const char f71882fg_has_in1_alarm[] = {
  124. [f71808e] = 0,
  125. [f71808a] = 0,
  126. [f71858fg] = 0,
  127. [f71862fg] = 0,
  128. [f71868a] = 0,
  129. [f71869] = 0,
  130. [f71869a] = 0,
  131. [f71882fg] = 1,
  132. [f71889fg] = 1,
  133. [f71889ed] = 1,
  134. [f71889a] = 1,
  135. [f8000] = 0,
  136. [f81768d] = 1,
  137. [f81865f] = 1,
  138. [f81866a] = 1,
  139. };
  140. static const char f71882fg_fan_has_beep[] = {
  141. [f71808e] = 0,
  142. [f71808a] = 0,
  143. [f71858fg] = 0,
  144. [f71862fg] = 1,
  145. [f71868a] = 1,
  146. [f71869] = 1,
  147. [f71869a] = 1,
  148. [f71882fg] = 1,
  149. [f71889fg] = 1,
  150. [f71889ed] = 1,
  151. [f71889a] = 1,
  152. [f8000] = 0,
  153. [f81768d] = 1,
  154. [f81865f] = 1,
  155. [f81866a] = 1,
  156. };
  157. static const char f71882fg_nr_fans[] = {
  158. [f71808e] = 3,
  159. [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
  160. [f71858fg] = 3,
  161. [f71862fg] = 3,
  162. [f71868a] = 3,
  163. [f71869] = 3,
  164. [f71869a] = 3,
  165. [f71882fg] = 4,
  166. [f71889fg] = 3,
  167. [f71889ed] = 3,
  168. [f71889a] = 3,
  169. [f8000] = 3, /* +1 fan which is monitor only */
  170. [f81768d] = 3,
  171. [f81865f] = 2,
  172. [f81866a] = 3,
  173. };
  174. static const char f71882fg_temp_has_beep[] = {
  175. [f71808e] = 0,
  176. [f71808a] = 1,
  177. [f71858fg] = 0,
  178. [f71862fg] = 1,
  179. [f71868a] = 1,
  180. [f71869] = 1,
  181. [f71869a] = 1,
  182. [f71882fg] = 1,
  183. [f71889fg] = 1,
  184. [f71889ed] = 1,
  185. [f71889a] = 1,
  186. [f8000] = 0,
  187. [f81768d] = 1,
  188. [f81865f] = 1,
  189. [f81866a] = 1,
  190. };
  191. static const char f71882fg_nr_temps[] = {
  192. [f71808e] = 2,
  193. [f71808a] = 2,
  194. [f71858fg] = 3,
  195. [f71862fg] = 3,
  196. [f71868a] = 3,
  197. [f71869] = 3,
  198. [f71869a] = 3,
  199. [f71882fg] = 3,
  200. [f71889fg] = 3,
  201. [f71889ed] = 3,
  202. [f71889a] = 3,
  203. [f8000] = 3,
  204. [f81768d] = 3,
  205. [f81865f] = 2,
  206. [f81866a] = 3,
  207. };
  208. static struct platform_device *f71882fg_pdev;
  209. /* Super-I/O Function prototypes */
  210. static inline int superio_inb(int base, int reg);
  211. static inline int superio_inw(int base, int reg);
  212. static inline int superio_enter(int base);
  213. static inline void superio_select(int base, int ld);
  214. static inline void superio_exit(int base);
  215. struct f71882fg_sio_data {
  216. enum chips type;
  217. };
  218. struct f71882fg_data {
  219. unsigned short addr;
  220. enum chips type;
  221. struct device *hwmon_dev;
  222. struct mutex update_lock;
  223. int temp_start; /* temp numbering start (0 or 1) */
  224. char valid; /* !=0 if following fields are valid */
  225. char auto_point_temp_signed;
  226. unsigned long last_updated; /* In jiffies */
  227. unsigned long last_limits; /* In jiffies */
  228. /* Register Values */
  229. u8 in[F71882FG_MAX_INS];
  230. u8 in1_max;
  231. u8 in_status;
  232. u8 in_beep;
  233. u16 fan[4];
  234. u16 fan_target[4];
  235. u16 fan_full_speed[4];
  236. u8 fan_status;
  237. u8 fan_beep;
  238. /*
  239. * Note: all models have max 3 temperature channels, but on some
  240. * they are addressed as 0-2 and on others as 1-3, so for coding
  241. * convenience we reserve space for 4 channels
  242. */
  243. u16 temp[4];
  244. u8 temp_ovt[4];
  245. u8 temp_high[4];
  246. u8 temp_hyst[2]; /* 2 hysts stored per reg */
  247. u8 temp_type[4];
  248. u8 temp_status;
  249. u8 temp_beep;
  250. u8 temp_diode_open;
  251. u8 temp_config;
  252. u8 pwm[4];
  253. u8 pwm_enable;
  254. u8 pwm_auto_point_hyst[2];
  255. u8 pwm_auto_point_mapping[4];
  256. u8 pwm_auto_point_pwm[4][5];
  257. s8 pwm_auto_point_temp[4][4];
  258. };
  259. /* Sysfs in */
  260. static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
  261. char *buf);
  262. static ssize_t show_in_max(struct device *dev, struct device_attribute
  263. *devattr, char *buf);
  264. static ssize_t store_in_max(struct device *dev, struct device_attribute
  265. *devattr, const char *buf, size_t count);
  266. static ssize_t show_in_beep(struct device *dev, struct device_attribute
  267. *devattr, char *buf);
  268. static ssize_t store_in_beep(struct device *dev, struct device_attribute
  269. *devattr, const char *buf, size_t count);
  270. static ssize_t show_in_alarm(struct device *dev, struct device_attribute
  271. *devattr, char *buf);
  272. /* Sysfs Fan */
  273. static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
  274. char *buf);
  275. static ssize_t show_fan_full_speed(struct device *dev,
  276. struct device_attribute *devattr, char *buf);
  277. static ssize_t store_fan_full_speed(struct device *dev,
  278. struct device_attribute *devattr, const char *buf, size_t count);
  279. static ssize_t show_fan_beep(struct device *dev, struct device_attribute
  280. *devattr, char *buf);
  281. static ssize_t store_fan_beep(struct device *dev, struct device_attribute
  282. *devattr, const char *buf, size_t count);
  283. static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
  284. *devattr, char *buf);
  285. /* Sysfs Temp */
  286. static ssize_t show_temp(struct device *dev, struct device_attribute
  287. *devattr, char *buf);
  288. static ssize_t show_temp_max(struct device *dev, struct device_attribute
  289. *devattr, char *buf);
  290. static ssize_t store_temp_max(struct device *dev, struct device_attribute
  291. *devattr, const char *buf, size_t count);
  292. static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
  293. *devattr, char *buf);
  294. static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
  295. *devattr, const char *buf, size_t count);
  296. static ssize_t show_temp_crit(struct device *dev, struct device_attribute
  297. *devattr, char *buf);
  298. static ssize_t store_temp_crit(struct device *dev, struct device_attribute
  299. *devattr, const char *buf, size_t count);
  300. static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
  301. *devattr, char *buf);
  302. static ssize_t show_temp_type(struct device *dev, struct device_attribute
  303. *devattr, char *buf);
  304. static ssize_t show_temp_beep(struct device *dev, struct device_attribute
  305. *devattr, char *buf);
  306. static ssize_t store_temp_beep(struct device *dev, struct device_attribute
  307. *devattr, const char *buf, size_t count);
  308. static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
  309. *devattr, char *buf);
  310. static ssize_t show_temp_fault(struct device *dev, struct device_attribute
  311. *devattr, char *buf);
  312. /* PWM and Auto point control */
  313. static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
  314. char *buf);
  315. static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
  316. const char *buf, size_t count);
  317. static ssize_t show_simple_pwm(struct device *dev,
  318. struct device_attribute *devattr, char *buf);
  319. static ssize_t store_simple_pwm(struct device *dev,
  320. struct device_attribute *devattr, const char *buf, size_t count);
  321. static ssize_t show_pwm_enable(struct device *dev,
  322. struct device_attribute *devattr, char *buf);
  323. static ssize_t store_pwm_enable(struct device *dev,
  324. struct device_attribute *devattr, const char *buf, size_t count);
  325. static ssize_t show_pwm_interpolate(struct device *dev,
  326. struct device_attribute *devattr, char *buf);
  327. static ssize_t store_pwm_interpolate(struct device *dev,
  328. struct device_attribute *devattr, const char *buf, size_t count);
  329. static ssize_t show_pwm_auto_point_channel(struct device *dev,
  330. struct device_attribute *devattr, char *buf);
  331. static ssize_t store_pwm_auto_point_channel(struct device *dev,
  332. struct device_attribute *devattr, const char *buf, size_t count);
  333. static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
  334. struct device_attribute *devattr, char *buf);
  335. static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
  336. struct device_attribute *devattr, const char *buf, size_t count);
  337. static ssize_t show_pwm_auto_point_pwm(struct device *dev,
  338. struct device_attribute *devattr, char *buf);
  339. static ssize_t store_pwm_auto_point_pwm(struct device *dev,
  340. struct device_attribute *devattr, const char *buf, size_t count);
  341. static ssize_t show_pwm_auto_point_temp(struct device *dev,
  342. struct device_attribute *devattr, char *buf);
  343. static ssize_t store_pwm_auto_point_temp(struct device *dev,
  344. struct device_attribute *devattr, const char *buf, size_t count);
  345. /* Sysfs misc */
  346. static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
  347. char *buf);
  348. static int f71882fg_probe(struct platform_device *pdev);
  349. static int f71882fg_remove(struct platform_device *pdev);
  350. static struct platform_driver f71882fg_driver = {
  351. .driver = {
  352. .name = DRVNAME,
  353. },
  354. .probe = f71882fg_probe,
  355. .remove = f71882fg_remove,
  356. };
  357. static DEVICE_ATTR_RO(name);
  358. /*
  359. * Temp attr for the f71858fg, the f71858fg is special as it has its
  360. * temperature indexes start at 0 (the others start at 1)
  361. */
  362. static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
  363. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
  364. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
  365. store_temp_max, 0, 0),
  366. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  367. store_temp_max_hyst, 0, 0),
  368. SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
  369. SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  370. store_temp_crit, 0, 0),
  371. SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  372. 0, 0),
  373. SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
  374. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
  375. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
  376. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
  377. store_temp_max, 0, 1),
  378. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  379. store_temp_max_hyst, 0, 1),
  380. SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
  381. SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  382. store_temp_crit, 0, 1),
  383. SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  384. 0, 1),
  385. SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  386. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  387. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
  388. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
  389. store_temp_max, 0, 2),
  390. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  391. store_temp_max_hyst, 0, 2),
  392. SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
  393. SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  394. store_temp_crit, 0, 2),
  395. SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  396. 0, 2),
  397. SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  398. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  399. };
  400. /* Temp attr for the standard models */
  401. static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
  402. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
  403. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
  404. store_temp_max, 0, 1),
  405. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  406. store_temp_max_hyst, 0, 1),
  407. /*
  408. * Should really be temp1_max_alarm, but older versions did not handle
  409. * the max and crit alarms separately and lm_sensors v2 depends on the
  410. * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
  411. */
  412. SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
  413. SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  414. store_temp_crit, 0, 1),
  415. SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  416. 0, 1),
  417. SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  418. SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
  419. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  420. }, {
  421. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
  422. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
  423. store_temp_max, 0, 2),
  424. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  425. store_temp_max_hyst, 0, 2),
  426. /* Should be temp2_max_alarm, see temp1_alarm note */
  427. SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
  428. SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  429. store_temp_crit, 0, 2),
  430. SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  431. 0, 2),
  432. SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  433. SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
  434. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  435. }, {
  436. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
  437. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
  438. store_temp_max, 0, 3),
  439. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  440. store_temp_max_hyst, 0, 3),
  441. /* Should be temp3_max_alarm, see temp1_alarm note */
  442. SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
  443. SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  444. store_temp_crit, 0, 3),
  445. SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  446. 0, 3),
  447. SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
  448. SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
  449. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
  450. } };
  451. /* Temp attr for models which can beep on temp alarm */
  452. static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
  453. SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  454. store_temp_beep, 0, 1),
  455. SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  456. store_temp_beep, 0, 5),
  457. }, {
  458. SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  459. store_temp_beep, 0, 2),
  460. SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  461. store_temp_beep, 0, 6),
  462. }, {
  463. SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  464. store_temp_beep, 0, 3),
  465. SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  466. store_temp_beep, 0, 7),
  467. } };
  468. static struct sensor_device_attribute_2 f81866_temp_beep_attr[3][2] = { {
  469. SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  470. store_temp_beep, 0, 0),
  471. SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  472. store_temp_beep, 0, 4),
  473. }, {
  474. SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  475. store_temp_beep, 0, 1),
  476. SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  477. store_temp_beep, 0, 5),
  478. }, {
  479. SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  480. store_temp_beep, 0, 2),
  481. SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  482. store_temp_beep, 0, 6),
  483. } };
  484. /*
  485. * Temp attr for the f8000
  486. * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
  487. * is used as hysteresis value to clear alarms
  488. * Also like the f71858fg its temperature indexes start at 0
  489. */
  490. static struct sensor_device_attribute_2 f8000_temp_attr[] = {
  491. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
  492. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
  493. store_temp_crit, 0, 0),
  494. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  495. store_temp_max, 0, 0),
  496. SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
  497. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
  498. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
  499. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
  500. store_temp_crit, 0, 1),
  501. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  502. store_temp_max, 0, 1),
  503. SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  504. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  505. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
  506. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
  507. store_temp_crit, 0, 2),
  508. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  509. store_temp_max, 0, 2),
  510. SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  511. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  512. };
  513. /* in attr for all models */
  514. static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
  515. SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
  516. SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
  517. SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
  518. SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
  519. SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
  520. SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
  521. SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
  522. SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
  523. SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
  524. SENSOR_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 0, 9),
  525. SENSOR_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 0, 10),
  526. };
  527. /* For models with in1 alarm capability */
  528. static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
  529. SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
  530. 0, 1),
  531. SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
  532. 0, 1),
  533. SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
  534. };
  535. /* Fan / PWM attr common to all models */
  536. static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
  537. SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
  538. SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
  539. show_fan_full_speed,
  540. store_fan_full_speed, 0, 0),
  541. SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
  542. SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
  543. SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  544. store_pwm_enable, 0, 0),
  545. SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
  546. show_pwm_interpolate, store_pwm_interpolate, 0, 0),
  547. }, {
  548. SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
  549. SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
  550. show_fan_full_speed,
  551. store_fan_full_speed, 0, 1),
  552. SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
  553. SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
  554. SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  555. store_pwm_enable, 0, 1),
  556. SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
  557. show_pwm_interpolate, store_pwm_interpolate, 0, 1),
  558. }, {
  559. SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
  560. SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
  561. show_fan_full_speed,
  562. store_fan_full_speed, 0, 2),
  563. SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
  564. SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
  565. SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  566. store_pwm_enable, 0, 2),
  567. SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
  568. show_pwm_interpolate, store_pwm_interpolate, 0, 2),
  569. }, {
  570. SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
  571. SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
  572. show_fan_full_speed,
  573. store_fan_full_speed, 0, 3),
  574. SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
  575. SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
  576. SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  577. store_pwm_enable, 0, 3),
  578. SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
  579. show_pwm_interpolate, store_pwm_interpolate, 0, 3),
  580. } };
  581. /* Attr for the third fan of the f71808a, which only has manual pwm */
  582. static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
  583. SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
  584. SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
  585. SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
  586. show_simple_pwm, store_simple_pwm, 0, 2),
  587. };
  588. /* Attr for models which can beep on Fan alarm */
  589. static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
  590. SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  591. store_fan_beep, 0, 0),
  592. SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  593. store_fan_beep, 0, 1),
  594. SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  595. store_fan_beep, 0, 2),
  596. SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  597. store_fan_beep, 0, 3),
  598. };
  599. /*
  600. * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
  601. * standard models
  602. */
  603. static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
  604. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  605. show_pwm_auto_point_channel,
  606. store_pwm_auto_point_channel, 0, 0),
  607. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  608. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  609. 1, 0),
  610. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  611. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  612. 4, 0),
  613. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  614. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  615. 0, 0),
  616. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  617. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  618. 3, 0),
  619. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  620. show_pwm_auto_point_temp_hyst,
  621. store_pwm_auto_point_temp_hyst,
  622. 0, 0),
  623. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  624. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  625. }, {
  626. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  627. show_pwm_auto_point_channel,
  628. store_pwm_auto_point_channel, 0, 1),
  629. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  630. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  631. 1, 1),
  632. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  633. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  634. 4, 1),
  635. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  636. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  637. 0, 1),
  638. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  639. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  640. 3, 1),
  641. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  642. show_pwm_auto_point_temp_hyst,
  643. store_pwm_auto_point_temp_hyst,
  644. 0, 1),
  645. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  646. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  647. }, {
  648. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  649. show_pwm_auto_point_channel,
  650. store_pwm_auto_point_channel, 0, 2),
  651. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  652. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  653. 1, 2),
  654. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  655. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  656. 4, 2),
  657. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  658. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  659. 0, 2),
  660. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  661. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  662. 3, 2),
  663. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  664. show_pwm_auto_point_temp_hyst,
  665. store_pwm_auto_point_temp_hyst,
  666. 0, 2),
  667. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  668. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  669. } };
  670. /*
  671. * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
  672. * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
  673. * programmed instead of being hardcoded to 0xff
  674. */
  675. static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
  676. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  677. show_pwm_auto_point_channel,
  678. store_pwm_auto_point_channel, 0, 0),
  679. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  680. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  681. 0, 0),
  682. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  683. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  684. 1, 0),
  685. SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  686. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  687. 4, 0),
  688. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  689. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  690. 0, 0),
  691. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  692. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  693. 3, 0),
  694. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  695. show_pwm_auto_point_temp_hyst,
  696. store_pwm_auto_point_temp_hyst,
  697. 0, 0),
  698. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  699. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  700. }, {
  701. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  702. show_pwm_auto_point_channel,
  703. store_pwm_auto_point_channel, 0, 1),
  704. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  705. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  706. 0, 1),
  707. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  708. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  709. 1, 1),
  710. SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  711. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  712. 4, 1),
  713. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  714. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  715. 0, 1),
  716. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  717. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  718. 3, 1),
  719. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  720. show_pwm_auto_point_temp_hyst,
  721. store_pwm_auto_point_temp_hyst,
  722. 0, 1),
  723. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  724. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  725. }, {
  726. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  727. show_pwm_auto_point_channel,
  728. store_pwm_auto_point_channel, 0, 2),
  729. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  730. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  731. 0, 2),
  732. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  733. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  734. 1, 2),
  735. SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  736. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  737. 4, 2),
  738. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  739. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  740. 0, 2),
  741. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  742. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  743. 3, 2),
  744. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  745. show_pwm_auto_point_temp_hyst,
  746. store_pwm_auto_point_temp_hyst,
  747. 0, 2),
  748. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  749. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  750. } };
  751. /* PWM attr for the standard models */
  752. static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
  753. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  754. show_pwm_auto_point_channel,
  755. store_pwm_auto_point_channel, 0, 0),
  756. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  757. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  758. 0, 0),
  759. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  760. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  761. 1, 0),
  762. SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  763. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  764. 2, 0),
  765. SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
  766. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  767. 3, 0),
  768. SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
  769. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  770. 4, 0),
  771. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  772. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  773. 0, 0),
  774. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  775. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  776. 1, 0),
  777. SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
  778. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  779. 2, 0),
  780. SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
  781. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  782. 3, 0),
  783. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  784. show_pwm_auto_point_temp_hyst,
  785. store_pwm_auto_point_temp_hyst,
  786. 0, 0),
  787. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  788. show_pwm_auto_point_temp_hyst, NULL, 1, 0),
  789. SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
  790. show_pwm_auto_point_temp_hyst, NULL, 2, 0),
  791. SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
  792. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  793. }, {
  794. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  795. show_pwm_auto_point_channel,
  796. store_pwm_auto_point_channel, 0, 1),
  797. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  798. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  799. 0, 1),
  800. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  801. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  802. 1, 1),
  803. SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  804. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  805. 2, 1),
  806. SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
  807. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  808. 3, 1),
  809. SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
  810. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  811. 4, 1),
  812. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  813. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  814. 0, 1),
  815. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  816. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  817. 1, 1),
  818. SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
  819. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  820. 2, 1),
  821. SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
  822. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  823. 3, 1),
  824. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  825. show_pwm_auto_point_temp_hyst,
  826. store_pwm_auto_point_temp_hyst,
  827. 0, 1),
  828. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  829. show_pwm_auto_point_temp_hyst, NULL, 1, 1),
  830. SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
  831. show_pwm_auto_point_temp_hyst, NULL, 2, 1),
  832. SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
  833. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  834. }, {
  835. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  836. show_pwm_auto_point_channel,
  837. store_pwm_auto_point_channel, 0, 2),
  838. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  839. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  840. 0, 2),
  841. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  842. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  843. 1, 2),
  844. SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  845. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  846. 2, 2),
  847. SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
  848. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  849. 3, 2),
  850. SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
  851. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  852. 4, 2),
  853. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  854. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  855. 0, 2),
  856. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  857. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  858. 1, 2),
  859. SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
  860. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  861. 2, 2),
  862. SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
  863. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  864. 3, 2),
  865. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  866. show_pwm_auto_point_temp_hyst,
  867. store_pwm_auto_point_temp_hyst,
  868. 0, 2),
  869. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  870. show_pwm_auto_point_temp_hyst, NULL, 1, 2),
  871. SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
  872. show_pwm_auto_point_temp_hyst, NULL, 2, 2),
  873. SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
  874. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  875. }, {
  876. SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
  877. show_pwm_auto_point_channel,
  878. store_pwm_auto_point_channel, 0, 3),
  879. SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
  880. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  881. 0, 3),
  882. SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
  883. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  884. 1, 3),
  885. SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
  886. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  887. 2, 3),
  888. SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
  889. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  890. 3, 3),
  891. SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
  892. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  893. 4, 3),
  894. SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
  895. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  896. 0, 3),
  897. SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
  898. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  899. 1, 3),
  900. SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
  901. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  902. 2, 3),
  903. SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
  904. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  905. 3, 3),
  906. SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  907. show_pwm_auto_point_temp_hyst,
  908. store_pwm_auto_point_temp_hyst,
  909. 0, 3),
  910. SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
  911. show_pwm_auto_point_temp_hyst, NULL, 1, 3),
  912. SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
  913. show_pwm_auto_point_temp_hyst, NULL, 2, 3),
  914. SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
  915. show_pwm_auto_point_temp_hyst, NULL, 3, 3),
  916. } };
  917. /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
  918. static struct sensor_device_attribute_2 f8000_fan_attr[] = {
  919. SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
  920. };
  921. /*
  922. * PWM attr for the f8000, zones mapped to temp instead of to pwm!
  923. * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
  924. * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
  925. */
  926. static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
  927. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  928. show_pwm_auto_point_channel,
  929. store_pwm_auto_point_channel, 0, 0),
  930. SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  931. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  932. 0, 2),
  933. SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  934. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  935. 1, 2),
  936. SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  937. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  938. 2, 2),
  939. SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
  940. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  941. 3, 2),
  942. SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
  943. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  944. 4, 2),
  945. SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
  946. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  947. 0, 2),
  948. SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
  949. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  950. 1, 2),
  951. SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
  952. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  953. 2, 2),
  954. SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
  955. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  956. 3, 2),
  957. SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  958. show_pwm_auto_point_temp_hyst,
  959. store_pwm_auto_point_temp_hyst,
  960. 0, 2),
  961. SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
  962. show_pwm_auto_point_temp_hyst, NULL, 1, 2),
  963. SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
  964. show_pwm_auto_point_temp_hyst, NULL, 2, 2),
  965. SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
  966. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  967. }, {
  968. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  969. show_pwm_auto_point_channel,
  970. store_pwm_auto_point_channel, 0, 1),
  971. SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  972. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  973. 0, 0),
  974. SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  975. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  976. 1, 0),
  977. SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  978. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  979. 2, 0),
  980. SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
  981. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  982. 3, 0),
  983. SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
  984. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  985. 4, 0),
  986. SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
  987. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  988. 0, 0),
  989. SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
  990. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  991. 1, 0),
  992. SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
  993. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  994. 2, 0),
  995. SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
  996. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  997. 3, 0),
  998. SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  999. show_pwm_auto_point_temp_hyst,
  1000. store_pwm_auto_point_temp_hyst,
  1001. 0, 0),
  1002. SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
  1003. show_pwm_auto_point_temp_hyst, NULL, 1, 0),
  1004. SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
  1005. show_pwm_auto_point_temp_hyst, NULL, 2, 0),
  1006. SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
  1007. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  1008. }, {
  1009. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  1010. show_pwm_auto_point_channel,
  1011. store_pwm_auto_point_channel, 0, 2),
  1012. SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  1013. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  1014. 0, 1),
  1015. SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  1016. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  1017. 1, 1),
  1018. SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  1019. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  1020. 2, 1),
  1021. SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
  1022. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  1023. 3, 1),
  1024. SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
  1025. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  1026. 4, 1),
  1027. SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
  1028. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1029. 0, 1),
  1030. SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
  1031. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1032. 1, 1),
  1033. SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
  1034. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1035. 2, 1),
  1036. SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
  1037. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1038. 3, 1),
  1039. SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  1040. show_pwm_auto_point_temp_hyst,
  1041. store_pwm_auto_point_temp_hyst,
  1042. 0, 1),
  1043. SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
  1044. show_pwm_auto_point_temp_hyst, NULL, 1, 1),
  1045. SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
  1046. show_pwm_auto_point_temp_hyst, NULL, 2, 1),
  1047. SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
  1048. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  1049. } };
  1050. /* Super I/O functions */
  1051. static inline int superio_inb(int base, int reg)
  1052. {
  1053. outb(reg, base);
  1054. return inb(base + 1);
  1055. }
  1056. static int superio_inw(int base, int reg)
  1057. {
  1058. int val;
  1059. val = superio_inb(base, reg) << 8;
  1060. val |= superio_inb(base, reg + 1);
  1061. return val;
  1062. }
  1063. static inline int superio_enter(int base)
  1064. {
  1065. /* Don't step on other drivers' I/O space by accident */
  1066. if (!request_muxed_region(base, 2, DRVNAME)) {
  1067. pr_err("I/O address 0x%04x already in use\n", base);
  1068. return -EBUSY;
  1069. }
  1070. /* according to the datasheet the key must be send twice! */
  1071. outb(SIO_UNLOCK_KEY, base);
  1072. outb(SIO_UNLOCK_KEY, base);
  1073. return 0;
  1074. }
  1075. static inline void superio_select(int base, int ld)
  1076. {
  1077. outb(SIO_REG_LDSEL, base);
  1078. outb(ld, base + 1);
  1079. }
  1080. static inline void superio_exit(int base)
  1081. {
  1082. outb(SIO_LOCK_KEY, base);
  1083. release_region(base, 2);
  1084. }
  1085. static inline int fan_from_reg(u16 reg)
  1086. {
  1087. return reg ? (1500000 / reg) : 0;
  1088. }
  1089. static inline u16 fan_to_reg(int fan)
  1090. {
  1091. return fan ? (1500000 / fan) : 0;
  1092. }
  1093. static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
  1094. {
  1095. u8 val;
  1096. outb(reg, data->addr + ADDR_REG_OFFSET);
  1097. val = inb(data->addr + DATA_REG_OFFSET);
  1098. return val;
  1099. }
  1100. static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
  1101. {
  1102. u16 val;
  1103. val = f71882fg_read8(data, reg) << 8;
  1104. val |= f71882fg_read8(data, reg + 1);
  1105. return val;
  1106. }
  1107. static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
  1108. {
  1109. outb(reg, data->addr + ADDR_REG_OFFSET);
  1110. outb(val, data->addr + DATA_REG_OFFSET);
  1111. }
  1112. static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
  1113. {
  1114. f71882fg_write8(data, reg, val >> 8);
  1115. f71882fg_write8(data, reg + 1, val & 0xff);
  1116. }
  1117. static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
  1118. {
  1119. if (data->type == f71858fg)
  1120. return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
  1121. else
  1122. return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
  1123. }
  1124. static struct f71882fg_data *f71882fg_update_device(struct device *dev)
  1125. {
  1126. struct f71882fg_data *data = dev_get_drvdata(dev);
  1127. int nr_fans = f71882fg_nr_fans[data->type];
  1128. int nr_temps = f71882fg_nr_temps[data->type];
  1129. int nr, reg, point;
  1130. mutex_lock(&data->update_lock);
  1131. /* Update once every 60 seconds */
  1132. if (time_after(jiffies, data->last_limits + 60 * HZ) ||
  1133. !data->valid) {
  1134. if (f71882fg_has_in1_alarm[data->type]) {
  1135. if (data->type == f81866a) {
  1136. data->in1_max =
  1137. f71882fg_read8(data,
  1138. F81866_REG_IN1_HIGH);
  1139. data->in_beep =
  1140. f71882fg_read8(data,
  1141. F81866_REG_IN_BEEP);
  1142. } else {
  1143. data->in1_max =
  1144. f71882fg_read8(data,
  1145. F71882FG_REG_IN1_HIGH);
  1146. data->in_beep =
  1147. f71882fg_read8(data,
  1148. F71882FG_REG_IN_BEEP);
  1149. }
  1150. }
  1151. /* Get High & boundary temps*/
  1152. for (nr = data->temp_start; nr < nr_temps + data->temp_start;
  1153. nr++) {
  1154. data->temp_ovt[nr] = f71882fg_read8(data,
  1155. F71882FG_REG_TEMP_OVT(nr));
  1156. data->temp_high[nr] = f71882fg_read8(data,
  1157. F71882FG_REG_TEMP_HIGH(nr));
  1158. }
  1159. if (data->type != f8000) {
  1160. data->temp_hyst[0] = f71882fg_read8(data,
  1161. F71882FG_REG_TEMP_HYST(0));
  1162. data->temp_hyst[1] = f71882fg_read8(data,
  1163. F71882FG_REG_TEMP_HYST(1));
  1164. }
  1165. /* All but the f71858fg / f8000 have this register */
  1166. if ((data->type != f71858fg) && (data->type != f8000)) {
  1167. reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
  1168. data->temp_type[1] = (reg & 0x02) ? 2 : 4;
  1169. data->temp_type[2] = (reg & 0x04) ? 2 : 4;
  1170. data->temp_type[3] = (reg & 0x08) ? 2 : 4;
  1171. }
  1172. if (f71882fg_fan_has_beep[data->type])
  1173. data->fan_beep = f71882fg_read8(data,
  1174. F71882FG_REG_FAN_BEEP);
  1175. if (f71882fg_temp_has_beep[data->type])
  1176. data->temp_beep = f71882fg_read8(data,
  1177. F71882FG_REG_TEMP_BEEP);
  1178. data->pwm_enable = f71882fg_read8(data,
  1179. F71882FG_REG_PWM_ENABLE);
  1180. data->pwm_auto_point_hyst[0] =
  1181. f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
  1182. data->pwm_auto_point_hyst[1] =
  1183. f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
  1184. for (nr = 0; nr < nr_fans; nr++) {
  1185. data->pwm_auto_point_mapping[nr] =
  1186. f71882fg_read8(data,
  1187. F71882FG_REG_POINT_MAPPING(nr));
  1188. switch (data->type) {
  1189. default:
  1190. for (point = 0; point < 5; point++) {
  1191. data->pwm_auto_point_pwm[nr][point] =
  1192. f71882fg_read8(data,
  1193. F71882FG_REG_POINT_PWM
  1194. (nr, point));
  1195. }
  1196. for (point = 0; point < 4; point++) {
  1197. data->pwm_auto_point_temp[nr][point] =
  1198. f71882fg_read8(data,
  1199. F71882FG_REG_POINT_TEMP
  1200. (nr, point));
  1201. }
  1202. break;
  1203. case f71808e:
  1204. case f71869:
  1205. data->pwm_auto_point_pwm[nr][0] =
  1206. f71882fg_read8(data,
  1207. F71882FG_REG_POINT_PWM(nr, 0));
  1208. /* Fall through */
  1209. case f71862fg:
  1210. data->pwm_auto_point_pwm[nr][1] =
  1211. f71882fg_read8(data,
  1212. F71882FG_REG_POINT_PWM
  1213. (nr, 1));
  1214. data->pwm_auto_point_pwm[nr][4] =
  1215. f71882fg_read8(data,
  1216. F71882FG_REG_POINT_PWM
  1217. (nr, 4));
  1218. data->pwm_auto_point_temp[nr][0] =
  1219. f71882fg_read8(data,
  1220. F71882FG_REG_POINT_TEMP
  1221. (nr, 0));
  1222. data->pwm_auto_point_temp[nr][3] =
  1223. f71882fg_read8(data,
  1224. F71882FG_REG_POINT_TEMP
  1225. (nr, 3));
  1226. break;
  1227. }
  1228. }
  1229. data->last_limits = jiffies;
  1230. }
  1231. /* Update every second */
  1232. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  1233. data->temp_status = f71882fg_read8(data,
  1234. F71882FG_REG_TEMP_STATUS);
  1235. data->temp_diode_open = f71882fg_read8(data,
  1236. F71882FG_REG_TEMP_DIODE_OPEN);
  1237. for (nr = data->temp_start; nr < nr_temps + data->temp_start;
  1238. nr++)
  1239. data->temp[nr] = f71882fg_read_temp(data, nr);
  1240. data->fan_status = f71882fg_read8(data,
  1241. F71882FG_REG_FAN_STATUS);
  1242. for (nr = 0; nr < nr_fans; nr++) {
  1243. data->fan[nr] = f71882fg_read16(data,
  1244. F71882FG_REG_FAN(nr));
  1245. data->fan_target[nr] =
  1246. f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
  1247. data->fan_full_speed[nr] =
  1248. f71882fg_read16(data,
  1249. F71882FG_REG_FAN_FULL_SPEED(nr));
  1250. data->pwm[nr] =
  1251. f71882fg_read8(data, F71882FG_REG_PWM(nr));
  1252. }
  1253. /* Some models have 1 more fan with limited capabilities */
  1254. if (data->type == f71808a) {
  1255. data->fan[2] = f71882fg_read16(data,
  1256. F71882FG_REG_FAN(2));
  1257. data->pwm[2] = f7