lm85.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  1. /*
  2. lm85.c - Part of lm_sensors, Linux kernel modules for hardware
  3. monitoring
  4. Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
  5. Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
  6. Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
  7. Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
  8. Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org>
  9. Chip details at <http://www.national.com/ds/LM/LM85.pdf>
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/i2c.h>
  27. #include <linux/hwmon.h>
  28. #include <linux/hwmon-vid.h>
  29. #include <linux/hwmon-sysfs.h>
  30. #include <linux/err.h>
  31. #include <linux/mutex.h>
  32. /* Addresses to scan */
  33. static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
  34. enum chips {
  35. any_chip, lm85b, lm85c,
  36. adm1027, adt7463, adt7468,
  37. emc6d100, emc6d102, emc6d103
  38. };
  39. /* The LM85 registers */
  40. #define LM85_REG_IN(nr) (0x20 + (nr))
  41. #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
  42. #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
  43. #define LM85_REG_TEMP(nr) (0x25 + (nr))
  44. #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
  45. #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
  46. /* Fan speeds are LSB, MSB (2 bytes) */
  47. #define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
  48. #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
  49. #define LM85_REG_PWM(nr) (0x30 + (nr))
  50. #define LM85_REG_COMPANY 0x3e
  51. #define LM85_REG_VERSTEP 0x3f
  52. #define ADT7468_REG_CFG5 0x7c
  53. #define ADT7468_OFF64 (1 << 0)
  54. #define ADT7468_HFPWM (1 << 1)
  55. #define IS_ADT7468_OFF64(data) \
  56. ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
  57. #define IS_ADT7468_HFPWM(data) \
  58. ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
  59. /* These are the recognized values for the above regs */
  60. #define LM85_COMPANY_NATIONAL 0x01
  61. #define LM85_COMPANY_ANALOG_DEV 0x41
  62. #define LM85_COMPANY_SMSC 0x5c
  63. #define LM85_VERSTEP_VMASK 0xf0
  64. #define LM85_VERSTEP_GENERIC 0x60
  65. #define LM85_VERSTEP_GENERIC2 0x70
  66. #define LM85_VERSTEP_LM85C 0x60
  67. #define LM85_VERSTEP_LM85B 0x62
  68. #define LM85_VERSTEP_LM96000_1 0x68
  69. #define LM85_VERSTEP_LM96000_2 0x69
  70. #define LM85_VERSTEP_ADM1027 0x60
  71. #define LM85_VERSTEP_ADT7463 0x62
  72. #define LM85_VERSTEP_ADT7463C 0x6A
  73. #define LM85_VERSTEP_ADT7468_1 0x71
  74. #define LM85_VERSTEP_ADT7468_2 0x72
  75. #define LM85_VERSTEP_EMC6D100_A0 0x60
  76. #define LM85_VERSTEP_EMC6D100_A1 0x61
  77. #define LM85_VERSTEP_EMC6D102 0x65
  78. #define LM85_VERSTEP_EMC6D103_A0 0x68
  79. #define LM85_VERSTEP_EMC6D103_A1 0x69
  80. #define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */
  81. #define LM85_REG_CONFIG 0x40
  82. #define LM85_REG_ALARM1 0x41
  83. #define LM85_REG_ALARM2 0x42
  84. #define LM85_REG_VID 0x43
  85. /* Automated FAN control */
  86. #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
  87. #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
  88. #define LM85_REG_AFAN_SPIKE1 0x62
  89. #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
  90. #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
  91. #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
  92. #define LM85_REG_AFAN_HYST1 0x6d
  93. #define LM85_REG_AFAN_HYST2 0x6e
  94. #define ADM1027_REG_EXTEND_ADC1 0x76
  95. #define ADM1027_REG_EXTEND_ADC2 0x77
  96. #define EMC6D100_REG_ALARM3 0x7d
  97. /* IN5, IN6 and IN7 */
  98. #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
  99. #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
  100. #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
  101. #define EMC6D102_REG_EXTEND_ADC1 0x85
  102. #define EMC6D102_REG_EXTEND_ADC2 0x86
  103. #define EMC6D102_REG_EXTEND_ADC3 0x87
  104. #define EMC6D102_REG_EXTEND_ADC4 0x88
  105. /* Conversions. Rounding and limit checking is only done on the TO_REG
  106. variants. Note that you should be a bit careful with which arguments
  107. these macros are called: arguments may be evaluated more than once.
  108. */
  109. /* IN are scaled acording to built-in resistors */
  110. static const int lm85_scaling[] = { /* .001 Volts */
  111. 2500, 2250, 3300, 5000, 12000,
  112. 3300, 1500, 1800 /*EMC6D100*/
  113. };
  114. #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
  115. #define INS_TO_REG(n, val) \
  116. SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
  117. #define INSEXT_FROM_REG(n, val, ext) \
  118. SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
  119. #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
  120. /* FAN speed is measured using 90kHz clock */
  121. static inline u16 FAN_TO_REG(unsigned long val)
  122. {
  123. if (!val)
  124. return 0xffff;
  125. return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
  126. }
  127. #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
  128. 5400000 / (val))
  129. /* Temperature is reported in .001 degC increments */
  130. #define TEMP_TO_REG(val) \
  131. SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
  132. #define TEMPEXT_FROM_REG(val, ext) \
  133. SCALE(((val) << 4) + (ext), 16, 1000)
  134. #define TEMP_FROM_REG(val) ((val) * 1000)
  135. #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
  136. #define PWM_FROM_REG(val) (val)
  137. /* ZONEs have the following parameters:
  138. * Limit (low) temp, 1. degC
  139. * Hysteresis (below limit), 1. degC (0-15)
  140. * Range of speed control, .1 degC (2-80)
  141. * Critical (high) temp, 1. degC
  142. *
  143. * FAN PWMs have the following parameters:
  144. * Reference Zone, 1, 2, 3, etc.
  145. * Spinup time, .05 sec
  146. * PWM value at limit/low temp, 1 count
  147. * PWM Frequency, 1. Hz
  148. * PWM is Min or OFF below limit, flag
  149. * Invert PWM output, flag
  150. *
  151. * Some chips filter the temp, others the fan.
  152. * Filter constant (or disabled) .1 seconds
  153. */
  154. /* These are the zone temperature range encodings in .001 degree C */
  155. static const int lm85_range_map[] = {
  156. 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
  157. 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
  158. };
  159. static int RANGE_TO_REG(int range)
  160. {
  161. int i;
  162. /* Find the closest match */
  163. for (i = 0; i < 15; ++i) {
  164. if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
  165. break;
  166. }
  167. return i;
  168. }
  169. #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
  170. /* These are the PWM frequency encodings */
  171. static const int lm85_freq_map[8] = { /* 1 Hz */
  172. 10, 15, 23, 30, 38, 47, 61, 94
  173. };
  174. static const int adm1027_freq_map[8] = { /* 1 Hz */
  175. 11, 15, 22, 29, 35, 44, 59, 88
  176. };
  177. static int FREQ_TO_REG(const int *map, int freq)
  178. {
  179. int i;
  180. /* Find the closest match */
  181. for (i = 0; i < 7; ++i)
  182. if (freq <= (map[i] + map[i + 1]) / 2)
  183. break;
  184. return i;
  185. }
  186. static int FREQ_FROM_REG(const int *map, u8 reg)
  187. {
  188. return map[reg & 0x07];
  189. }
  190. /* Since we can't use strings, I'm abusing these numbers
  191. * to stand in for the following meanings:
  192. * 1 -- PWM responds to Zone 1
  193. * 2 -- PWM responds to Zone 2
  194. * 3 -- PWM responds to Zone 3
  195. * 23 -- PWM responds to the higher temp of Zone 2 or 3
  196. * 123 -- PWM responds to highest of Zone 1, 2, or 3
  197. * 0 -- PWM is always at 0% (ie, off)
  198. * -1 -- PWM is always at 100%
  199. * -2 -- PWM responds to manual control
  200. */
  201. static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
  202. #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
  203. static int ZONE_TO_REG(int zone)
  204. {
  205. int i;
  206. for (i = 0; i <= 7; ++i)
  207. if (zone == lm85_zone_map[i])
  208. break;
  209. if (i > 7) /* Not found. */
  210. i = 3; /* Always 100% */
  211. return i << 5;
  212. }
  213. #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
  214. #define HYST_FROM_REG(val) ((val) * 1000)
  215. /* Chip sampling rates
  216. *
  217. * Some sensors are not updated more frequently than once per second
  218. * so it doesn't make sense to read them more often than that.
  219. * We cache the results and return the saved data if the driver
  220. * is called again before a second has elapsed.
  221. *
  222. * Also, there is significant configuration data for this chip
  223. * given the automatic PWM fan control that is possible. There
  224. * are about 47 bytes of config data to only 22 bytes of actual
  225. * readings. So, we keep the config data up to date in the cache
  226. * when it is written and only sample it once every 1 *minute*
  227. */
  228. #define LM85_DATA_INTERVAL (HZ + HZ / 2)
  229. #define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
  230. /* LM85 can automatically adjust fan speeds based on temperature
  231. * This structure encapsulates an entire Zone config. There are
  232. * three zones (one for each temperature input) on the lm85
  233. */
  234. struct lm85_zone {
  235. s8 limit; /* Low temp limit */
  236. u8 hyst; /* Low limit hysteresis. (0-15) */
  237. u8 range; /* Temp range, encoded */
  238. s8 critical; /* "All fans ON" temp limit */
  239. u8 max_desired; /* Actual "max" temperature specified. Preserved
  240. * to prevent "drift" as other autofan control
  241. * values change.
  242. */
  243. };
  244. struct lm85_autofan {
  245. u8 config; /* Register value */
  246. u8 min_pwm; /* Minimum PWM value, encoded */
  247. u8 min_off; /* Min PWM or OFF below "limit", flag */
  248. };
  249. /* For each registered chip, we need to keep some data in memory.
  250. The structure is dynamically allocated. */
  251. struct lm85_data {
  252. struct device *hwmon_dev;
  253. const int *freq_map;
  254. enum chips type;
  255. bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */
  256. struct mutex update_lock;
  257. int valid; /* !=0 if following fields are valid */
  258. unsigned long last_reading; /* In jiffies */
  259. unsigned long last_config; /* In jiffies */
  260. u8 in[8]; /* Register value */
  261. u8 in_max[8]; /* Register value */
  262. u8 in_min[8]; /* Register value */
  263. s8 temp[3]; /* Register value */
  264. s8 temp_min[3]; /* Register value */
  265. s8 temp_max[3]; /* Register value */
  266. u16 fan[4]; /* Register value */
  267. u16 fan_min[4]; /* Register value */
  268. u8 pwm[3]; /* Register value */
  269. u8 pwm_freq[3]; /* Register encoding */
  270. u8 temp_ext[3]; /* Decoded values */
  271. u8 in_ext[8]; /* Decoded values */
  272. u8 vid; /* Register value */
  273. u8 vrm; /* VRM version */
  274. u32 alarms; /* Register encoding, combined */
  275. u8 cfg5; /* Config Register 5 on ADT7468 */
  276. struct lm85_autofan autofan[3];
  277. struct lm85_zone zone[3];
  278. };
  279. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info);
  280. static int lm85_probe(struct i2c_client *client,
  281. const struct i2c_device_id *id);
  282. static int lm85_remove(struct i2c_client *client);
  283. static int lm85_read_value(struct i2c_client *client, u8 reg);
  284. static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
  285. static struct lm85_data *lm85_update_device(struct device *dev);
  286. static const struct i2c_device_id lm85_id[] = {
  287. { "adm1027", adm1027 },
  288. { "adt7463", adt7463 },
  289. { "adt7468", adt7468 },
  290. { "lm85", any_chip },
  291. { "lm85b", lm85b },
  292. { "lm85c", lm85c },
  293. { "emc6d100", emc6d100 },
  294. { "emc6d101", emc6d100 },
  295. { "emc6d102", emc6d102 },
  296. { "emc6d103", emc6d103 },
  297. { }
  298. };
  299. MODULE_DEVICE_TABLE(i2c, lm85_id);
  300. static struct i2c_driver lm85_driver = {
  301. .class = I2C_CLASS_HWMON,
  302. .driver = {
  303. .name = "lm85",
  304. },
  305. .probe = lm85_probe,
  306. .remove = lm85_remove,
  307. .id_table = lm85_id,
  308. .detect = lm85_detect,
  309. .address_list = normal_i2c,
  310. };
  311. /* 4 Fans */
  312. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  313. char *buf)
  314. {
  315. int nr = to_sensor_dev_attr(attr)->index;
  316. struct lm85_data *data = lm85_update_device(dev);
  317. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
  318. }
  319. static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
  320. char *buf)
  321. {
  322. int nr = to_sensor_dev_attr(attr)->index;
  323. struct lm85_data *data = lm85_update_device(dev);
  324. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
  325. }
  326. static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
  327. const char *buf, size_t count)
  328. {
  329. int nr = to_sensor_dev_attr(attr)->index;
  330. struct i2c_client *client = to_i2c_client(dev);
  331. struct lm85_data *data = i2c_get_clientdata(client);
  332. unsigned long val = simple_strtoul(buf, NULL, 10);
  333. mutex_lock(&data->update_lock);
  334. data->fan_min[nr] = FAN_TO_REG(val);
  335. lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
  336. mutex_unlock(&data->update_lock);
  337. return count;
  338. }
  339. #define show_fan_offset(offset) \
  340. static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
  341. show_fan, NULL, offset - 1); \
  342. static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  343. show_fan_min, set_fan_min, offset - 1)
  344. show_fan_offset(1);
  345. show_fan_offset(2);
  346. show_fan_offset(3);
  347. show_fan_offset(4);
  348. /* vid, vrm, alarms */
  349. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  350. char *buf)
  351. {
  352. struct lm85_data *data = lm85_update_device(dev);
  353. int vid;
  354. if (data->has_vid5) {
  355. /* 6-pin VID (VRM 10) */
  356. vid = vid_from_reg(data->vid & 0x3f, data->vrm);
  357. } else {
  358. /* 5-pin VID (VRM 9) */
  359. vid = vid_from_reg(data->vid & 0x1f, data->vrm);
  360. }
  361. return sprintf(buf, "%d\n", vid);
  362. }
  363. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  364. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  365. char *buf)
  366. {
  367. struct lm85_data *data = dev_get_drvdata(dev);
  368. return sprintf(buf, "%ld\n", (long) data->vrm);
  369. }
  370. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  371. const char *buf, size_t count)
  372. {
  373. struct lm85_data *data = dev_get_drvdata(dev);
  374. data->vrm = simple_strtoul(buf, NULL, 10);
  375. return count;
  376. }
  377. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  378. static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
  379. *attr, char *buf)
  380. {
  381. struct lm85_data *data = lm85_update_device(dev);
  382. return sprintf(buf, "%u\n", data->alarms);
  383. }
  384. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
  385. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  386. char *buf)
  387. {
  388. int nr = to_sensor_dev_attr(attr)->index;
  389. struct lm85_data *data = lm85_update_device(dev);
  390. return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
  391. }
  392. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  393. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  394. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  395. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  396. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
  397. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
  398. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
  399. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
  400. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
  401. static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
  402. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
  403. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
  404. static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
  405. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
  406. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
  407. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
  408. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
  409. /* pwm */
  410. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  411. char *buf)
  412. {
  413. int nr = to_sensor_dev_attr(attr)->index;
  414. struct lm85_data *data = lm85_update_device(dev);
  415. return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
  416. }
  417. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  418. const char *buf, size_t count)
  419. {
  420. int nr = to_sensor_dev_attr(attr)->index;
  421. struct i2c_client *client = to_i2c_client(dev);
  422. struct lm85_data *data = i2c_get_clientdata(client);
  423. long val = simple_strtol(buf, NULL, 10);
  424. mutex_lock(&data->update_lock);
  425. data->pwm[nr] = PWM_TO_REG(val);
  426. lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
  427. mutex_unlock(&data->update_lock);
  428. return count;
  429. }
  430. static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
  431. *attr, char *buf)
  432. {
  433. int nr = to_sensor_dev_attr(attr)->index;
  434. struct lm85_data *data = lm85_update_device(dev);
  435. int pwm_zone, enable;
  436. pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
  437. switch (pwm_zone) {
  438. case -1: /* PWM is always at 100% */
  439. enable = 0;
  440. break;
  441. case 0: /* PWM is always at 0% */
  442. case -2: /* PWM responds to manual control */
  443. enable = 1;
  444. break;
  445. default: /* PWM in automatic mode */
  446. enable = 2;
  447. }
  448. return sprintf(buf, "%d\n", enable);
  449. }
  450. static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
  451. *attr, const char *buf, size_t count)
  452. {
  453. int nr = to_sensor_dev_attr(attr)->index;
  454. struct i2c_client *client = to_i2c_client(dev);
  455. struct lm85_data *data = i2c_get_clientdata(client);
  456. long val = simple_strtol(buf, NULL, 10);
  457. u8 config;
  458. switch (val) {
  459. case 0:
  460. config = 3;
  461. break;
  462. case 1:
  463. config = 7;
  464. break;
  465. case 2:
  466. /* Here we have to choose arbitrarily one of the 5 possible
  467. configurations; I go for the safest */
  468. config = 6;
  469. break;
  470. default:
  471. return -EINVAL;
  472. }
  473. mutex_lock(&data->update_lock);
  474. data->autofan[nr].config = lm85_read_value(client,
  475. LM85_REG_AFAN_CONFIG(nr));
  476. data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
  477. | (config << 5);
  478. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  479. data->autofan[nr].config);
  480. mutex_unlock(&data->update_lock);
  481. return count;
  482. }
  483. static ssize_t show_pwm_freq(struct device *dev,
  484. struct device_attribute *attr, char *buf)
  485. {
  486. int nr = to_sensor_dev_attr(attr)->index;
  487. struct lm85_data *data = lm85_update_device(dev);
  488. int freq;
  489. if (IS_ADT7468_HFPWM(data))
  490. freq = 22500;
  491. else
  492. freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]);
  493. return sprintf(buf, "%d\n", freq);
  494. }
  495. static ssize_t set_pwm_freq(struct device *dev,
  496. struct device_attribute *attr, const char *buf, size_t count)
  497. {
  498. int nr = to_sensor_dev_attr(attr)->index;
  499. struct i2c_client *client = to_i2c_client(dev);
  500. struct lm85_data *data = i2c_get_clientdata(client);
  501. long val = simple_strtol(buf, NULL, 10);
  502. mutex_lock(&data->update_lock);
  503. /* The ADT7468 has a special high-frequency PWM output mode,
  504. * where all PWM outputs are driven by a 22.5 kHz clock.
  505. * This might confuse the user, but there's not much we can do. */
  506. if (data->type == adt7468 && val >= 11300) { /* High freq. mode */
  507. data->cfg5 &= ~ADT7468_HFPWM;
  508. lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
  509. } else { /* Low freq. mode */
  510. data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
  511. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  512. (data->zone[nr].range << 4)
  513. | data->pwm_freq[nr]);
  514. if (data->type == adt7468) {
  515. data->cfg5 |= ADT7468_HFPWM;
  516. lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
  517. }
  518. }
  519. mutex_unlock(&data->update_lock);
  520. return count;
  521. }
  522. #define show_pwm_reg(offset) \
  523. static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  524. show_pwm, set_pwm, offset - 1); \
  525. static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
  526. show_pwm_enable, set_pwm_enable, offset - 1); \
  527. static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
  528. show_pwm_freq, set_pwm_freq, offset - 1)
  529. show_pwm_reg(1);
  530. show_pwm_reg(2);
  531. show_pwm_reg(3);
  532. /* Voltages */
  533. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  534. char *buf)
  535. {
  536. int nr = to_sensor_dev_attr(attr)->index;
  537. struct lm85_data *data = lm85_update_device(dev);
  538. return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
  539. data->in_ext[nr]));
  540. }
  541. static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
  542. char *buf)
  543. {
  544. int nr = to_sensor_dev_attr(attr)->index;
  545. struct lm85_data *data = lm85_update_device(dev);
  546. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
  547. }
  548. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  549. const char *buf, size_t count)
  550. {
  551. int nr = to_sensor_dev_attr(attr)->index;
  552. struct i2c_client *client = to_i2c_client(dev);
  553. struct lm85_data *data = i2c_get_clientdata(client);
  554. long val = simple_strtol(buf, NULL, 10);
  555. mutex_lock(&data->update_lock);
  556. data->in_min[nr] = INS_TO_REG(nr, val);
  557. lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
  558. mutex_unlock(&data->update_lock);
  559. return count;
  560. }
  561. static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
  562. char *buf)
  563. {
  564. int nr = to_sensor_dev_attr(attr)->index;
  565. struct lm85_data *data = lm85_update_device(dev);
  566. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
  567. }
  568. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  569. const char *buf, size_t count)
  570. {
  571. int nr = to_sensor_dev_attr(attr)->index;
  572. struct i2c_client *client = to_i2c_client(dev);
  573. struct lm85_data *data = i2c_get_clientdata(client);
  574. long val = simple_strtol(buf, NULL, 10);
  575. mutex_lock(&data->update_lock);
  576. data->in_max[nr] = INS_TO_REG(nr, val);
  577. lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
  578. mutex_unlock(&data->update_lock);
  579. return count;
  580. }
  581. #define show_in_reg(offset) \
  582. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  583. show_in, NULL, offset); \
  584. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
  585. show_in_min, set_in_min, offset); \
  586. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
  587. show_in_max, set_in_max, offset)
  588. show_in_reg(0);
  589. show_in_reg(1);
  590. show_in_reg(2);
  591. show_in_reg(3);
  592. show_in_reg(4);
  593. show_in_reg(5);
  594. show_in_reg(6);
  595. show_in_reg(7);
  596. /* Temps */
  597. static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
  598. char *buf)
  599. {
  600. int nr = to_sensor_dev_attr(attr)->index;
  601. struct lm85_data *data = lm85_update_device(dev);
  602. return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
  603. data->temp_ext[nr]));
  604. }
  605. static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
  606. char *buf)
  607. {
  608. int nr = to_sensor_dev_attr(attr)->index;
  609. struct lm85_data *data = lm85_update_device(dev);
  610. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
  611. }
  612. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  613. const char *buf, size_t count)
  614. {
  615. int nr = to_sensor_dev_attr(attr)->index;
  616. struct i2c_client *client = to_i2c_client(dev);
  617. struct lm85_data *data = i2c_get_clientdata(client);
  618. long val = simple_strtol(buf, NULL, 10);
  619. if (IS_ADT7468_OFF64(data))
  620. val += 64;
  621. mutex_lock(&data->update_lock);
  622. data->temp_min[nr] = TEMP_TO_REG(val);
  623. lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
  624. mutex_unlock(&data->update_lock);
  625. return count;
  626. }
  627. static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
  628. char *buf)
  629. {
  630. int nr = to_sensor_dev_attr(attr)->index;
  631. struct lm85_data *data = lm85_update_device(dev);
  632. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
  633. }
  634. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  635. const char *buf, size_t count)
  636. {
  637. int nr = to_sensor_dev_attr(attr)->index;
  638. struct i2c_client *client = to_i2c_client(dev);
  639. struct lm85_data *data = i2c_get_clientdata(client);
  640. long val = simple_strtol(buf, NULL, 10);
  641. if (IS_ADT7468_OFF64(data))
  642. val += 64;
  643. mutex_lock(&data->update_lock);
  644. data->temp_max[nr] = TEMP_TO_REG(val);
  645. lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
  646. mutex_unlock(&data->update_lock);
  647. return count;
  648. }
  649. #define show_temp_reg(offset) \
  650. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  651. show_temp, NULL, offset - 1); \
  652. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
  653. show_temp_min, set_temp_min, offset - 1); \
  654. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
  655. show_temp_max, set_temp_max, offset - 1);
  656. show_temp_reg(1);
  657. show_temp_reg(2);
  658. show_temp_reg(3);
  659. /* Automatic PWM control */
  660. static ssize_t show_pwm_auto_channels(struct device *dev,
  661. struct device_attribute *attr, char *buf)
  662. {
  663. int nr = to_sensor_dev_attr(attr)->index;
  664. struct lm85_data *data = lm85_update_device(dev);
  665. return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
  666. }
  667. static ssize_t set_pwm_auto_channels(struct device *dev,
  668. struct device_attribute *attr, const char *buf, size_t count)
  669. {
  670. int nr = to_sensor_dev_attr(attr)->index;
  671. struct i2c_client *client = to_i2c_client(dev);
  672. struct lm85_data *data = i2c_get_clientdata(client);
  673. long val = simple_strtol(buf, NULL, 10);
  674. mutex_lock(&data->update_lock);
  675. data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
  676. | ZONE_TO_REG(val);
  677. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  678. data->autofan[nr].config);
  679. mutex_unlock(&data->update_lock);
  680. return count;
  681. }
  682. static ssize_t show_pwm_auto_pwm_min(struct device *dev,
  683. struct device_attribute *attr, char *buf)
  684. {
  685. int nr = to_sensor_dev_attr(attr)->index;
  686. struct lm85_data *data = lm85_update_device(dev);
  687. return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
  688. }
  689. static ssize_t set_pwm_auto_pwm_min(struct device *dev,
  690. struct device_attribute *attr, const char *buf, size_t count)
  691. {
  692. int nr = to_sensor_dev_attr(attr)->index;
  693. struct i2c_client *client = to_i2c_client(dev);
  694. struct lm85_data *data = i2c_get_clientdata(client);
  695. long val = simple_strtol(buf, NULL, 10);
  696. mutex_lock(&data->update_lock);
  697. data->autofan[nr].min_pwm = PWM_TO_REG(val);
  698. lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
  699. data->autofan[nr].min_pwm);
  700. mutex_unlock(&data->update_lock);
  701. return count;
  702. }
  703. static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
  704. struct device_attribute *attr, char *buf)
  705. {
  706. int nr = to_sensor_dev_attr(attr)->index;
  707. struct lm85_data *data = lm85_update_device(dev);
  708. return sprintf(buf, "%d\n", data->autofan[nr].min_off);
  709. }
  710. static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
  711. struct device_attribute *attr, const char *buf, size_t count)
  712. {
  713. int nr = to_sensor_dev_attr(attr)->index;
  714. struct i2c_client *client = to_i2c_client(dev);
  715. struct lm85_data *data = i2c_get_clientdata(client);
  716. long val = simple_strtol(buf, NULL, 10);
  717. u8 tmp;
  718. mutex_lock(&data->update_lock);
  719. data->autofan[nr].min_off = val;
  720. tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  721. tmp &= ~(0x20 << nr);
  722. if (data->autofan[nr].min_off)
  723. tmp |= 0x20 << nr;
  724. lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
  725. mutex_unlock(&data->update_lock);
  726. return count;
  727. }
  728. #define pwm_auto(offset) \
  729. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
  730. S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
  731. set_pwm_auto_channels, offset - 1); \
  732. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
  733. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
  734. set_pwm_auto_pwm_min, offset - 1); \
  735. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
  736. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
  737. set_pwm_auto_pwm_minctl, offset - 1)
  738. pwm_auto(1);
  739. pwm_auto(2);
  740. pwm_auto(3);
  741. /* Temperature settings for automatic PWM control */
  742. static ssize_t show_temp_auto_temp_off(struct device *dev,
  743. struct device_attribute *attr, char *buf)
  744. {
  745. int nr = to_sensor_dev_attr(attr)->index;
  746. struct lm85_data *data = lm85_update_device(dev);
  747. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
  748. HYST_FROM_REG(data->zone[nr].hyst));
  749. }
  750. static ssize_t set_temp_auto_temp_off(struct device *dev,
  751. struct device_attribute *attr, const char *buf, size_t count)
  752. {
  753. int nr = to_sensor_dev_attr(attr)->index;
  754. struct i2c_client *client = to_i2c_client(dev);
  755. struct lm85_data *data = i2c_get_clientdata(client);
  756. int min;
  757. long val = simple_strtol(buf, NULL, 10);
  758. mutex_lock(&data->update_lock);
  759. min = TEMP_FROM_REG(data->zone[nr].limit);
  760. data->zone[nr].hyst = HYST_TO_REG(min - val);
  761. if (nr == 0 || nr == 1) {
  762. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  763. (data->zone[0].hyst << 4)
  764. | data->zone[1].hyst);
  765. } else {
  766. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  767. (data->zone[2].hyst << 4));
  768. }
  769. mutex_unlock(&data->update_lock);
  770. return count;
  771. }
  772. static ssize_t show_temp_auto_temp_min(struct device *dev,
  773. struct device_attribute *attr, char *buf)
  774. {
  775. int nr = to_sensor_dev_attr(attr)->index;
  776. struct lm85_data *data = lm85_update_device(dev);
  777. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
  778. }
  779. static ssize_t set_temp_auto_temp_min(struct device *dev,
  780. struct device_attribute *attr, const char *buf, size_t count)
  781. {
  782. int nr = to_sensor_dev_attr(attr)->index;
  783. struct i2c_client *client = to_i2c_client(dev);
  784. struct lm85_data *data = i2c_get_clientdata(client);
  785. long val = simple_strtol(buf, NULL, 10);
  786. mutex_lock(&data->update_lock);
  787. data->zone[nr].limit = TEMP_TO_REG(val);
  788. lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
  789. data->zone[nr].limit);
  790. /* Update temp_auto_max and temp_auto_range */
  791. data->zone[nr].range = RANGE_TO_REG(
  792. TEMP_FROM_REG(data->zone[nr].max_desired) -
  793. TEMP_FROM_REG(data->zone[nr].limit));
  794. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  795. ((data->zone[nr].range & 0x0f) << 4)
  796. | (data->pwm_freq[nr] & 0x07));
  797. mutex_unlock(&data->update_lock);
  798. return count;
  799. }
  800. static ssize_t show_temp_auto_temp_max(struct device *dev,
  801. struct device_attribute *attr, char *buf)
  802. {
  803. int nr = to_sensor_dev_attr(attr)->index;
  804. struct lm85_data *data = lm85_update_device(dev);
  805. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
  806. RANGE_FROM_REG(data->zone[nr].range));
  807. }
  808. static ssize_t set_temp_auto_temp_max(struct device *dev,
  809. struct device_attribute *attr, const char *buf, size_t count)
  810. {
  811. int nr = to_sensor_dev_attr(attr)->index;
  812. struct i2c_client *client = to_i2c_client(dev);
  813. struct lm85_data *data = i2c_get_clientdata(client);
  814. int min;
  815. long val = simple_strtol(buf, NULL, 10);
  816. mutex_lock(&data->update_lock);
  817. min = TEMP_FROM_REG(data->zone[nr].limit);
  818. data->zone[nr].max_desired = TEMP_TO_REG(val);
  819. data->zone[nr].range = RANGE_TO_REG(
  820. val - min);
  821. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  822. ((data->zone[nr].range & 0x0f) << 4)
  823. | (data->pwm_freq[nr] & 0x07));
  824. mutex_unlock(&data->update_lock);
  825. return count;
  826. }
  827. static ssize_t show_temp_auto_temp_crit(struct device *dev,
  828. struct device_attribute *attr, char *buf)
  829. {
  830. int nr = to_sensor_dev_attr(attr)->index;
  831. struct lm85_data *data = lm85_update_device(dev);
  832. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
  833. }
  834. static ssize_t set_temp_auto_temp_crit(struct device *dev,
  835. struct device_attribute *attr, const char *buf, size_t count)
  836. {
  837. int nr = to_sensor_dev_attr(attr)->index;
  838. struct i2c_client *client = to_i2c_client(dev);
  839. struct lm85_data *data = i2c_get_clientdata(client);
  840. long val = simple_strtol(buf, NULL, 10);
  841. mutex_lock(&data->update_lock);
  842. data->zone[nr].critical = TEMP_TO_REG(val);
  843. lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
  844. data->zone[nr].critical);
  845. mutex_unlock(&data->update_lock);
  846. return count;
  847. }
  848. #define temp_auto(offset) \
  849. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
  850. S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
  851. set_temp_auto_temp_off, offset - 1); \
  852. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
  853. S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
  854. set_temp_auto_temp_min, offset - 1); \
  855. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
  856. S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
  857. set_temp_auto_temp_max, offset - 1); \
  858. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
  859. S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
  860. set_temp_auto_temp_crit, offset - 1);
  861. temp_auto(1);
  862. temp_auto(2);
  863. temp_auto(3);
  864. static struct attribute *lm85_attributes[] = {
  865. &sensor_dev_attr_fan1_input.dev_attr.attr,
  866. &sensor_dev_attr_fan2_input.dev_attr.attr,
  867. &sensor_dev_attr_fan3_input.dev_attr.attr,
  868. &sensor_dev_attr_fan4_input.dev_attr.attr,
  869. &sensor_dev_attr_fan1_min.dev_attr.attr,
  870. &sensor_dev_attr_fan2_min.dev_attr.attr,
  871. &sensor_dev_attr_fan3_min.dev_attr.attr,
  872. &sensor_dev_attr_fan4_min.dev_attr.attr,
  873. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  874. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  875. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  876. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  877. &sensor_dev_attr_pwm1.dev_attr.attr,
  878. &sensor_dev_attr_pwm2.dev_attr.attr,
  879. &sensor_dev_attr_pwm3.dev_attr.attr,
  880. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  881. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  882. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  883. &sensor_dev_attr_pwm1_freq.dev_attr.attr,
  884. &sensor_dev_attr_pwm2_freq.dev_attr.attr,
  885. &sensor_dev_attr_pwm3_freq.dev_attr.attr,
  886. &sensor_dev_attr_in0_input.dev_attr.attr,
  887. &sensor_dev_attr_in1_input.dev_attr.attr,
  888. &sensor_dev_attr_in2_input.dev_attr.attr,
  889. &sensor_dev_attr_in3_input.dev_attr.attr,
  890. &sensor_dev_attr_in0_min.dev_attr.attr,
  891. &sensor_dev_attr_in1_min.dev_attr.attr,
  892. &sensor_dev_attr_in2_min.dev_attr.attr,
  893. &sensor_dev_attr_in3_min.dev_attr.attr,
  894. &sensor_dev_attr_in0_max.dev_attr.attr,
  895. &sensor_dev_attr_in1_max.dev_attr.attr,
  896. &sensor_dev_attr_in2_max.dev_attr.attr,
  897. &sensor_dev_attr_in3_max.dev_attr.attr,
  898. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  899. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  900. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  901. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  902. &sensor_dev_attr_temp1_input.dev_attr.attr,
  903. &sensor_dev_attr_temp2_input.dev_attr.attr,
  904. &sensor_dev_attr_temp3_input.dev_attr.attr,
  905. &sensor_dev_attr_temp1_min.dev_attr.attr,
  906. &sensor_dev_attr_temp2_min.dev_attr.attr,
  907. &sensor_dev_attr_temp3_min.dev_attr.attr,
  908. &sensor_dev_attr_temp1_max.dev_attr.attr,
  909. &sensor_dev_attr_temp2_max.dev_attr.attr,
  910. &sensor_dev_attr_temp3_max.dev_attr.attr,
  911. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  912. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  913. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  914. &sensor_dev_attr_temp1_fault.dev_attr.attr,
  915. &sensor_dev_attr_temp3_fault.dev_attr.attr,
  916. &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
  917. &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
  918. &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
  919. &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
  920. &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
  921. &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
  922. &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
  923. &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
  924. &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
  925. &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
  926. &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
  927. &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
  928. &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
  929. &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
  930. &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
  931. &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
  932. &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
  933. &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
  934. &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
  935. &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
  936. &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
  937. &dev_attr_vrm.attr,
  938. &dev_attr_cpu0_vid.attr,
  939. &dev_attr_alarms.attr,
  940. NULL
  941. };
  942. static const struct attribute_group lm85_group = {
  943. .attrs = lm85_attributes,
  944. };
  945. static struct attribute *lm85_attributes_in4[] = {
  946. &sensor_dev_attr_in4_input.dev_attr.attr,
  947. &sensor_dev_attr_in4_min.dev_attr.attr,
  948. &sensor_dev_attr_in4_max.dev_attr.attr,
  949. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  950. NULL
  951. };
  952. static const struct attribute_group lm85_group_in4 = {
  953. .attrs = lm85_attributes_in4,
  954. };
  955. static struct attribute *lm85_attributes_in567[] = {
  956. &sensor_dev_attr_in5_input.dev_attr.attr,
  957. &sensor_dev_attr_in6_input.dev_attr.attr,
  958. &sensor_dev_attr_in7_input.dev_attr.attr,
  959. &sensor_dev_attr_in5_min.dev_attr.attr,
  960. &sensor_dev_attr_in6_min.dev_attr.attr,
  961. &sensor_dev_attr_in7_min.dev_attr.attr,
  962. &sensor_dev_attr_in5_max.dev_attr.attr,
  963. &sensor_dev_attr_in6_max.dev_attr.attr,
  964. &sensor_dev_attr_in7_max.dev_attr.attr,
  965. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  966. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  967. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  968. NULL
  969. };
  970. static const struct attribute_group lm85_group_in567 = {
  971. .attrs = lm85_attributes_in567,
  972. };
  973. static void lm85_init_client(struct i2c_client *client)
  974. {
  975. int value;
  976. /* Start monitoring if needed */
  977. value = lm85_read_value(client, LM85_REG_CONFIG);
  978. if (!(value & 0x01)) {
  979. dev_info(&client->dev, "Starting monitoring\n");
  980. lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
  981. }
  982. /* Warn about unusual configuration bits */
  983. if (value & 0x02)
  984. dev_warn(&client->dev, "Device configuration is locked\n");
  985. if (!(value & 0x04))
  986. dev_warn(&client->dev, "Device is not ready\n");
  987. }
  988. static int lm85_is_fake(struct i2c_client *client)
  989. {
  990. /*
  991. * Differenciate between real LM96000 and Winbond WPCD377I. The latter
  992. * emulate the former except that it has no hardware monitoring function
  993. * so the readings are always 0.
  994. */
  995. int i;
  996. u8 in_temp, fan;
  997. for (i = 0; i < 8; i++) {
  998. in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
  999. fan = i2c_smbus_read_byte_data(client, 0x28 + i);
  1000. if (in_temp != 0x00 || fan != 0xff)
  1001. return 0;
  1002. }
  1003. return 1;
  1004. }
  1005. /* Return 0 if detection is successful, -ENODEV otherwise */
  1006. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
  1007. {
  1008. struct i2c_adapter *adapter = client->adapter;
  1009. int address = client->addr;
  1010. const char *type_name;
  1011. int company, verstep;
  1012. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1013. /* We need to be able to do byte I/O */
  1014. return -ENODEV;
  1015. }
  1016. /* Determine the chip type */
  1017. company = lm85_read_value(client, LM85_REG_COMPANY);
  1018. verstep = lm85_read_value(client, LM85_REG_VERSTEP);
  1019. dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
  1020. "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
  1021. address, company, verstep);
  1022. /* All supported chips have the version in common */
  1023. if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
  1024. (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
  1025. dev_dbg(&adapter->dev,
  1026. "Autodetection failed: unsupported version\n");
  1027. return -ENODEV;
  1028. }
  1029. type_name = "lm85";
  1030. /* Now, refine the detection */
  1031. if (company == LM85_COMPANY_NATIONAL) {
  1032. switch (verstep) {
  1033. case LM85_VERSTEP_LM85C:
  1034. type_name = "lm85c";
  1035. break;
  1036. case LM85_VERSTEP_LM85B:
  1037. type_name = "lm85b";
  1038. break;
  1039. case LM85_VERSTEP_LM96000_1:
  1040. case LM85_VERSTEP_LM96000_2:
  1041. /* Check for Winbond WPCD377I */
  1042. if (lm85_is_fake(client)) {
  1043. dev_dbg(&adapter->dev,
  1044. "Found Winbond WPCD377I, ignoring\n");
  1045. return -ENODEV;
  1046. }
  1047. break;
  1048. }
  1049. } else if (company == LM85_COMPANY_ANALOG_DEV) {
  1050. switch (verstep) {
  1051. case LM85_VERSTEP_ADM1027:
  1052. type_name = "adm1027";
  1053. break;
  1054. case LM85_VERSTEP_ADT7463:
  1055. case LM85_VERSTEP_ADT7463C:
  1056. type_name = "adt7463";
  1057. break;
  1058. case LM85_VERSTEP_ADT7468_1:
  1059. case LM85_VERSTEP_ADT7468_2:
  1060. type_name = "adt7468";
  1061. break;
  1062. }
  1063. } else if (company == LM85_COMPANY_SMSC) {
  1064. switch (verstep) {
  1065. case LM85_VERSTEP_EMC6D100_A0:
  1066. case LM85_VERSTEP_EMC6D100_A1:
  1067. /* Note: we can't tell a '100 from a '101 */
  1068. type_name = "emc6d100";
  1069. break;
  1070. case LM85_VERSTEP_EMC6D102:
  1071. type_name = "emc6d102";
  1072. break;
  1073. case LM85_VERSTEP_EMC6D103_A0:
  1074. case LM85_VERSTEP_EMC6D103_A1:
  1075. type_name = "emc6d103";
  1076. break;
  1077. /*
  1078. * Registers apparently missing in EMC6D103S/EMC6D103:A2
  1079. * compared to EMC6D103:A0, EMC6D103:A1, and EMC6D102
  1080. * (according to the data sheets), but used unconditionally
  1081. * in the driver: 62[5:7], 6D[0:7], and 6E[0:7].
  1082. * So skip EMC6D103S for now.
  1083. case LM85_VERSTEP_EMC6D103S:
  1084. type_name = "emc6d103s";
  1085. break;
  1086. */
  1087. }
  1088. } else {
  1089. dev_dbg(&adapter->dev,
  1090. "Autodetection failed: unknown vendor\n");
  1091. return -ENODEV;
  1092. }
  1093. strlcpy(info->type, type_name, I2C_NAME_SIZE);
  1094. return 0;
  1095. }
  1096. static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data)
  1097. {
  1098. sysfs_remove_group(&client->dev.kobj, &lm85_group);
  1099. if (!data->has_vid5)
  1100. sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
  1101. if (data->type == emc6d100)
  1102. sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
  1103. }
  1104. static int lm85_probe(struct i2c_client *client,
  1105. const struct i2c_device_id *id)
  1106. {
  1107. struct lm85_data *data;
  1108. int err;
  1109. data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
  1110. if (!data)
  1111. return -ENOMEM;
  1112. i2c_set_clientdata(client, data);
  1113. data->type = id->driver_data;
  1114. mutex_init(&data->update_lock);
  1115. /* Fill in the chip specific driver values */
  1116. switch (data->type) {
  1117. case adm1027:
  1118. case adt7463:
  1119. case adt7468:
  1120. case emc6d100:
  1121. case emc6d102:
  1122. case emc6d103:
  1123. data->freq_map = adm1027_freq_map;
  1124. break;
  1125. default:
  1126. data->freq_map = lm85_freq_map;
  1127. }
  1128. /* Set the VRM version */
  1129. data->vrm = vid_which_vrm();
  1130. /* Initialize the LM85 chip */
  1131. lm85_init_client(client);
  1132. /* Register sysfs hooks */
  1133. err = sysfs_create_group(&client->dev.kobj, &lm85_group);
  1134. if (err)
  1135. goto err_kfree;
  1136. /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
  1137. as a sixth digital VID input rather than an analog input. */
  1138. if (data->type == adt7463 || data->type == adt7468) {
  1139. u8 vid = lm85_read_value(client, LM85_REG_VID);
  1140. if (vid & 0x80)
  1141. data->has_vid5 = true;
  1142. }
  1143. if (!data->has_vid5)
  1144. if ((err = sysfs_create_group(&client->dev.kobj,
  1145. &lm85_group_in4)))
  1146. goto err_remove_files;
  1147. /* The EMC6D100 has 3 additional voltage inputs */
  1148. if (data->type == emc6d100)
  1149. if ((err = sysfs_create_group(&client->dev.kobj,
  1150. &lm85_group_in567)))
  1151. goto err_remove_files;
  1152. data->hwmon_dev = hwmon_device_register(&client->dev);
  1153. if (IS_ERR(data->hwmon_dev)) {
  1154. err = PTR_ERR(data->hwmon_dev);
  1155. goto err_remove_files;
  1156. }
  1157. return 0;
  1158. /* Error out and cleanup code */
  1159. err_remove_files:
  1160. lm85_remove_files(client, data);
  1161. err_kfree:
  1162. kfree(data);
  1163. return err;
  1164. }
  1165. static int lm85_remove(struct i2c_client *client)
  1166. {
  1167. struct lm85_data *data = i2c_get_clientdata(client);
  1168. hwmon_device_unregister(data->hwmon_dev);
  1169. lm85_remove_files(client, data);
  1170. kfree(data);
  1171. return 0;
  1172. }
  1173. static int lm85_read_value(struct i2c_client *client, u8 reg)
  1174. {
  1175. int res;
  1176. /* What size location is it? */
  1177. switch (reg) {
  1178. case LM85_REG_FAN(0): /* Read WORD data */
  1179. case LM85_REG_FAN(1):
  1180. case LM85_REG_FAN(2):
  1181. case LM85_REG_FAN(3):
  1182. case LM85_REG_FAN_MIN(0):
  1183. case LM85_REG_FAN_MIN(1):
  1184. case LM85_REG_FAN_MIN(2):
  1185. case LM85_REG_FAN_MIN(3):
  1186. case LM85_REG_ALARM1: /* Read both bytes at once */
  1187. res = i2c_smbus_read_byte_data(client, reg) & 0xff;
  1188. res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
  1189. break;
  1190. default: /* Read BYTE data */
  1191. res = i2c_smbus_read_byte_data(client, reg);
  1192. break;
  1193. }
  1194. return res;
  1195. }
  1196. static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
  1197. {
  1198. switch (reg) {
  1199. case LM85_REG_FAN(0): /* Write WORD data */
  1200. case LM85_REG_FAN(1):
  1201. case LM85_REG_FAN(2):
  1202. case LM85_REG_FAN(3):
  1203. case LM85_REG_FAN_MIN(0):
  1204. case LM85_REG_FAN_MIN(1):
  1205. case LM85_REG_FAN_MIN(2):
  1206. case LM85_REG_FAN_MIN(3):
  1207. /* NOTE: ALARM is read only, so not included here */
  1208. i2c_smbus_write_byte_data(client, reg, value & 0xff);
  1209. i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
  1210. break;
  1211. default: /* Write BYTE data */
  1212. i2c_smbus_write_byte_data(client, reg, value);
  1213. break;
  1214. }
  1215. }
  1216. static struct lm85_data *lm85_update_device(struct device *dev)
  1217. {
  1218. struct i2c_client *client = to_i2c_client(dev);
  1219. struct lm85_data *data = i2c_get_clientdata(client);
  1220. int i;
  1221. mutex_lock(&data->update_lock);
  1222. if (!data->valid ||
  1223. time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
  1224. /* Things that change quickly */
  1225. dev_dbg(&client->dev, "Reading sensor values\n");
  1226. /* Have to read extended bits first to "freeze" the
  1227. * more significant bits that are read later.
  1228. * There are 2 additional resolution bits per channel and we
  1229. * have room for 4, so we shift them to the left.
  1230. */
  1231. if (data->type == adm1027 || data->type == adt7463 ||
  1232. data->type == adt7468) {
  1233. int ext1 = lm85_read_value(client,
  1234. ADM1027_REG_EXTEND_ADC1);
  1235. int ext2 = lm85_read_value(client,
  1236. ADM1027_REG_EXTEND_ADC2);
  1237. int val = (ext1 << 8) + ext2;
  1238. for (i = 0; i <= 4; i++)
  1239. data->in_ext[i] =
  1240. ((val >> (i * 2)) & 0x03) << 2;
  1241. for (i = 0; i <= 2; i++)
  1242. data->temp_ext[i] =
  1243. (val >> ((i + 4) * 2)) & 0x0c;
  1244. }
  1245. data->vid = lm85_read_value(client, LM85_REG_VID);
  1246. for (i = 0; i <= 3; ++i) {
  1247. data->in[i] =
  1248. lm85_read_value(client, LM85_REG_IN(i));
  1249. data->fan[i] =
  1250. lm85_read_value(client, LM85_REG_FAN(i));
  1251. }
  1252. if (!data->has_vid5)
  1253. data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
  1254. if (data->type == adt7468)
  1255. data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
  1256. for (i = 0; i <= 2; ++i) {
  1257. data->temp[i] =
  1258. lm85_read_value(client, LM85_REG_TEMP(i));
  1259. data->pwm[i] =
  1260. lm85_read_value(client, LM85_REG_PWM(i));
  1261. if (IS_ADT7468_OFF64(data))
  1262. data->temp[i] -= 64;
  1263. }
  1264. data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
  1265. if (data->type == emc6d100) {
  1266. /* Three more voltage sensors */
  1267. for (i = 5; i <= 7; ++i) {
  1268. data->in[i] = lm85_read_value(client,
  1269. EMC6D100_REG_IN(i));
  1270. }
  1271. /* More alarm bits */
  1272. data->alarms |= lm85_read_value(client,
  1273. EMC6D100_REG_ALARM3) << 16;
  1274. } else if (data->type == emc6d102 || data->type == emc6d103) {
  1275. /* Have to read LSB bits after the MSB ones because
  1276. the reading of the MSB bits has frozen the
  1277. LSBs (backward from the ADM1027).
  1278. */
  1279. int ext1 = lm85_read_value(client,
  1280. EMC6D102_REG_EXTEND_ADC1);
  1281. int ext2 = lm85_read_value(client,
  1282. EMC6D102_REG_EXTEND_ADC2);
  1283. int ext3 = lm85_read_value(client,
  1284. EMC6D102_REG_EXTEND_ADC3);
  1285. int ext4 = lm85_read_value(client,
  1286. EMC6D102_REG_EXTEND_ADC4);
  1287. data->in_ext[0] = ext3 & 0x0f;
  1288. data->in_ext[1] = ext4 & 0x0f;
  1289. data->in_ext[2] = ext4 >> 4;
  1290. data->in_ext[3] = ext3 >> 4;
  1291. data->in_ext[4] = ext2 >> 4;
  1292. data->temp_ext[0] = ext1 & 0x0f;
  1293. data->temp_ext[1] = ext2 & 0x0f;
  1294. data->temp_ext[2] = ext1 >> 4;
  1295. }
  1296. data->last_reading = jiffies;
  1297. } /* last_reading */
  1298. if (!data->valid ||
  1299. time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
  1300. /* Things that don't change often */
  1301. dev_dbg(&client->dev, "Reading config values\n");
  1302. for (i = 0; i <= 3; ++i) {
  1303. data->in_min[i] =
  1304. lm85_read_value(client, LM85_REG_IN_MIN(i));
  1305. data->in_max[i] =
  1306. lm85_read_value(client, LM85_REG_IN_MAX(i));
  1307. data->fan_min[i] =
  1308. lm85_read_value(client, LM85_REG_FAN_MIN(i));
  1309. }
  1310. if (!data->has_vid5) {
  1311. data->in_min[4] = lm85_read_value(client,
  1312. LM85_REG_IN_MIN(4));
  1313. data->in_max[4] = lm85_read_value(client,
  1314. LM85_REG_IN_MAX(4));
  1315. }
  1316. if (data->type == emc6d100) {
  1317. for (i = 5; i <= 7; ++i) {
  1318. data->in_min[i] = lm85_read_value(client,
  1319. EMC6D100_REG_IN_MIN(i));
  1320. data->in_max[i] = lm85_read_value(client,
  1321. EMC6D100_REG_IN_MAX(i));
  1322. }
  1323. }
  1324. for (i = 0; i <= 2; ++i) {
  1325. int val;
  1326. data->temp_min[i] =
  1327. lm85_read_value(client, LM85_REG_TEMP_MIN(i));
  1328. data->temp_max[i] =
  1329. lm85_read_value(client, LM85_REG_TEMP_MAX(i));
  1330. data->autofan[i].config =
  1331. lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
  1332. val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
  1333. data->pwm_freq[i] = val & 0x07;
  1334. data->zone[i].range = val >> 4;
  1335. data->autofan[i].min_pwm =
  1336. lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
  1337. data->zone[i].limit =
  1338. lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
  1339. data->zone[i].critical =
  1340. lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
  1341. if (IS_ADT7468_OFF64(data)) {
  1342. data->temp_min[i] -= 64;
  1343. data->temp_max[i] -= 64;
  1344. data->zone[i].limit -= 64;
  1345. data->zone[i].critical -= 64;
  1346. }
  1347. }
  1348. i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  1349. data->autofan[0].min_off = (i & 0x20) != 0;
  1350. data->autofan[1].min_off = (i & 0x40) != 0;
  1351. data->autofan[2].min_off = (i & 0x80) != 0;
  1352. i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
  1353. data->zone[0].hyst = i >> 4;
  1354. data->zone[1].hyst = i & 0x0f;
  1355. i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
  1356. data->zone[2].hyst = i >> 4;
  1357. data->last_config = jiffies;
  1358. } /* last_config */
  1359. data->valid = 1;
  1360. mutex_unlock(&data->update_lock);
  1361. return data;
  1362. }
  1363. static int __init sm_lm85_init(void)
  1364. {
  1365. return i2c_add_driver(&lm85_driver);
  1366. }
  1367. static void __exit sm_lm85_exit(void)
  1368. {
  1369. i2c_del_driver(&lm85_driver);
  1370. }
  1371. MODULE_LICENSE("GPL");
  1372. MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
  1373. "Margit Schubert-While <margitsw@t-online.de>, "
  1374. "Justin Thiessen <jthiessen@penguincomputing.com>");
  1375. MODULE_DESCRIPTION("LM85-B, LM85-C driver");
  1376. module_init(sm_lm85_init);
  1377. module_exit(sm_lm85_exit);