lm85.c 49 KB

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