lm85.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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, emc6d103s
  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 according 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. { "emc6d103s", emc6d103s },
  298. { }
  299. };
  300. MODULE_DEVICE_TABLE(i2c, lm85_id);
  301. static struct i2c_driver lm85_driver = {
  302. .class = I2C_CLASS_HWMON,
  303. .driver = {
  304. .name = "lm85",
  305. },
  306. .probe = lm85_probe,
  307. .remove = lm85_remove,
  308. .id_table = lm85_id,
  309. .detect = lm85_detect,
  310. .address_list = normal_i2c,
  311. };
  312. /* 4 Fans */
  313. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  314. char *buf)
  315. {
  316. int nr = to_sensor_dev_attr(attr)->index;
  317. struct lm85_data *data = lm85_update_device(dev);
  318. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
  319. }
  320. static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
  321. char *buf)
  322. {
  323. int nr = to_sensor_dev_attr(attr)->index;
  324. struct lm85_data *data = lm85_update_device(dev);
  325. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
  326. }
  327. static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
  328. const char *buf, size_t count)
  329. {
  330. int nr = to_sensor_dev_attr(attr)->index;
  331. struct i2c_client *client = to_i2c_client(dev);
  332. struct lm85_data *data = i2c_get_clientdata(client);
  333. unsigned long val = simple_strtoul(buf, NULL, 10);
  334. mutex_lock(&data->update_lock);
  335. data->fan_min[nr] = FAN_TO_REG(val);
  336. lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
  337. mutex_unlock(&data->update_lock);
  338. return count;
  339. }
  340. #define show_fan_offset(offset) \
  341. static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
  342. show_fan, NULL, offset - 1); \
  343. static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  344. show_fan_min, set_fan_min, offset - 1)
  345. show_fan_offset(1);
  346. show_fan_offset(2);
  347. show_fan_offset(3);
  348. show_fan_offset(4);
  349. /* vid, vrm, alarms */
  350. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  351. char *buf)
  352. {
  353. struct lm85_data *data = lm85_update_device(dev);
  354. int vid;
  355. if (data->has_vid5) {
  356. /* 6-pin VID (VRM 10) */
  357. vid = vid_from_reg(data->vid & 0x3f, data->vrm);
  358. } else {
  359. /* 5-pin VID (VRM 9) */
  360. vid = vid_from_reg(data->vid & 0x1f, data->vrm);
  361. }
  362. return sprintf(buf, "%d\n", vid);
  363. }
  364. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  365. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  366. char *buf)
  367. {
  368. struct lm85_data *data = dev_get_drvdata(dev);
  369. return sprintf(buf, "%ld\n", (long) data->vrm);
  370. }
  371. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  372. const char *buf, size_t count)
  373. {
  374. struct lm85_data *data = dev_get_drvdata(dev);
  375. data->vrm = simple_strtoul(buf, NULL, 10);
  376. return count;
  377. }
  378. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  379. static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
  380. *attr, char *buf)
  381. {
  382. struct lm85_data *data = lm85_update_device(dev);
  383. return sprintf(buf, "%u\n", data->alarms);
  384. }
  385. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
  386. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  387. char *buf)
  388. {
  389. int nr = to_sensor_dev_attr(attr)->index;
  390. struct lm85_data *data = lm85_update_device(dev);
  391. return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
  392. }
  393. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  394. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  395. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  396. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  397. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
  398. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
  399. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
  400. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
  401. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
  402. static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
  403. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
  404. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
  405. static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
  406. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
  407. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
  408. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
  409. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
  410. /* pwm */
  411. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  412. char *buf)
  413. {
  414. int nr = to_sensor_dev_attr(attr)->index;
  415. struct lm85_data *data = lm85_update_device(dev);
  416. return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
  417. }
  418. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  419. const char *buf, size_t count)
  420. {
  421. int nr = to_sensor_dev_attr(attr)->index;
  422. struct i2c_client *client = to_i2c_client(dev);
  423. struct lm85_data *data = i2c_get_clientdata(client);
  424. long val = simple_strtol(buf, NULL, 10);
  425. mutex_lock(&data->update_lock);
  426. data->pwm[nr] = PWM_TO_REG(val);
  427. lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
  428. mutex_unlock(&data->update_lock);
  429. return count;
  430. }
  431. static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
  432. *attr, char *buf)
  433. {
  434. int nr = to_sensor_dev_attr(attr)->index;
  435. struct lm85_data *data = lm85_update_device(dev);
  436. int pwm_zone, enable;
  437. pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
  438. switch (pwm_zone) {
  439. case -1: /* PWM is always at 100% */
  440. enable = 0;
  441. break;
  442. case 0: /* PWM is always at 0% */
  443. case -2: /* PWM responds to manual control */
  444. enable = 1;
  445. break;
  446. default: /* PWM in automatic mode */
  447. enable = 2;
  448. }
  449. return sprintf(buf, "%d\n", enable);
  450. }
  451. static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
  452. *attr, const char *buf, size_t count)
  453. {
  454. int nr = to_sensor_dev_attr(attr)->index;
  455. struct i2c_client *client = to_i2c_client(dev);
  456. struct lm85_data *data = i2c_get_clientdata(client);
  457. long val = simple_strtol(buf, NULL, 10);
  458. u8 config;
  459. switch (val) {
  460. case 0:
  461. config = 3;
  462. break;
  463. case 1:
  464. config = 7;
  465. break;
  466. case 2:
  467. /* Here we have to choose arbitrarily one of the 5 possible
  468. configurations; I go for the safest */
  469. config = 6;
  470. break;
  471. default:
  472. return -EINVAL;
  473. }
  474. mutex_lock(&data->update_lock);
  475. data->autofan[nr].config = lm85_read_value(client,
  476. LM85_REG_AFAN_CONFIG(nr));
  477. data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
  478. | (config << 5);
  479. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  480. data->autofan[nr].config);
  481. mutex_unlock(&data->update_lock);
  482. return count;
  483. }
  484. static ssize_t show_pwm_freq(struct device *dev,
  485. struct device_attribute *attr, char *buf)
  486. {
  487. int nr = to_sensor_dev_attr(attr)->index;
  488. struct lm85_data *data = lm85_update_device(dev);
  489. int freq;
  490. if (IS_ADT7468_HFPWM(data))
  491. freq = 22500;
  492. else
  493. freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]);
  494. return sprintf(buf, "%d\n", freq);
  495. }
  496. static ssize_t set_pwm_freq(struct device *dev,
  497. struct device_attribute *attr, const char *buf, size_t count)
  498. {
  499. int nr = to_sensor_dev_attr(attr)->index;
  500. struct i2c_client *client = to_i2c_client(dev);
  501. struct lm85_data *data = i2c_get_clientdata(client);
  502. long val = simple_strtol(buf, NULL, 10);
  503. mutex_lock(&data->update_lock);
  504. /* The ADT7468 has a special high-frequency PWM output mode,
  505. * where all PWM outputs are driven by a 22.5 kHz clock.
  506. * This might confuse the user, but there's not much we can do. */
  507. if (data->type == adt7468 && val >= 11300) { /* High freq. mode */
  508. data->cfg5 &= ~ADT7468_HFPWM;
  509. lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
  510. } else { /* Low freq. mode */
  511. data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
  512. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  513. (data->zone[nr].range << 4)
  514. | data->pwm_freq[nr]);
  515. if (data->type == adt7468) {
  516. data->cfg5 |= ADT7468_HFPWM;
  517. lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
  518. }
  519. }
  520. mutex_unlock(&data->update_lock);
  521. return count;
  522. }
  523. #define show_pwm_reg(offset) \
  524. static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  525. show_pwm, set_pwm, offset - 1); \
  526. static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
  527. show_pwm_enable, set_pwm_enable, offset - 1); \
  528. static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
  529. show_pwm_freq, set_pwm_freq, offset - 1)
  530. show_pwm_reg(1);
  531. show_pwm_reg(2);
  532. show_pwm_reg(3);
  533. /* Voltages */
  534. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  535. char *buf)
  536. {
  537. int nr = to_sensor_dev_attr(attr)->index;
  538. struct lm85_data *data = lm85_update_device(dev);
  539. return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
  540. data->in_ext[nr]));
  541. }
  542. static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
  543. char *buf)
  544. {
  545. int nr = to_sensor_dev_attr(attr)->index;
  546. struct lm85_data *data = lm85_update_device(dev);
  547. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
  548. }
  549. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  550. const char *buf, size_t count)
  551. {
  552. int nr = to_sensor_dev_attr(attr)->index;
  553. struct i2c_client *client = to_i2c_client(dev);
  554. struct lm85_data *data = i2c_get_clientdata(client);
  555. long val = simple_strtol(buf, NULL, 10);
  556. mutex_lock(&data->update_lock);
  557. data->in_min[nr] = INS_TO_REG(nr, val);
  558. lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
  559. mutex_unlock(&data->update_lock);
  560. return count;
  561. }
  562. static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
  563. char *buf)
  564. {
  565. int nr = to_sensor_dev_attr(attr)->index;
  566. struct lm85_data *data = lm85_update_device(dev);
  567. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
  568. }
  569. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  570. const char *buf, size_t count)
  571. {
  572. int nr = to_sensor_dev_attr(attr)->index;
  573. struct i2c_client *client = to_i2c_client(dev);
  574. struct lm85_data *data = i2c_get_clientdata(client);
  575. long val = simple_strtol(buf, NULL, 10);
  576. mutex_lock(&data->update_lock);
  577. data->in_max[nr] = INS_TO_REG(nr, val);
  578. lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
  579. mutex_unlock(&data->update_lock);
  580. return count;
  581. }
  582. #define show_in_reg(offset) \
  583. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  584. show_in, NULL, offset); \
  585. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
  586. show_in_min, set_in_min, offset); \
  587. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
  588. show_in_max, set_in_max, offset)
  589. show_in_reg(0);
  590. show_in_reg(1);
  591. show_in_reg(2);
  592. show_in_reg(3);
  593. show_in_reg(4);
  594. show_in_reg(5);
  595. show_in_reg(6);
  596. show_in_reg(7);
  597. /* Temps */
  598. static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
  599. char *buf)
  600. {
  601. int nr = to_sensor_dev_attr(attr)->index;
  602. struct lm85_data *data = lm85_update_device(dev);
  603. return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
  604. data->temp_ext[nr]));
  605. }
  606. static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
  607. char *buf)
  608. {
  609. int nr = to_sensor_dev_attr(attr)->index;
  610. struct lm85_data *data = lm85_update_device(dev);
  611. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
  612. }
  613. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  614. const char *buf, size_t count)
  615. {
  616. int nr = to_sensor_dev_attr(attr)->index;
  617. struct i2c_client *client = to_i2c_client(dev);
  618. struct lm85_data *data = i2c_get_clientdata(client);
  619. long val = simple_strtol(buf, NULL, 10);
  620. if (IS_ADT7468_OFF64(data))
  621. val += 64;
  622. mutex_lock(&data->update_lock);
  623. data->temp_min[nr] = TEMP_TO_REG(val);
  624. lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
  625. mutex_unlock(&data->update_lock);
  626. return count;
  627. }
  628. static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
  629. char *buf)
  630. {
  631. int nr = to_sensor_dev_attr(attr)->index;
  632. struct lm85_data *data = lm85_update_device(dev);
  633. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
  634. }
  635. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  636. const char *buf, size_t count)
  637. {
  638. int nr = to_sensor_dev_attr(attr)->index;
  639. struct i2c_client *client = to_i2c_client(dev);
  640. struct lm85_data *data = i2c_get_clientdata(client);
  641. long val = simple_strtol(buf, NULL, 10);
  642. if (IS_ADT7468_OFF64(data))
  643. val += 64;
  644. mutex_lock(&data->update_lock);
  645. data->temp_max[nr] = TEMP_TO_REG(val);
  646. lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
  647. mutex_unlock(&data->update_lock);
  648. return count;
  649. }
  650. #define show_temp_reg(offset) \
  651. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  652. show_temp, NULL, offset - 1); \
  653. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
  654. show_temp_min, set_temp_min, offset - 1); \
  655. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
  656. show_temp_max, set_temp_max, offset - 1);
  657. show_temp_reg(1);
  658. show_temp_reg(2);
  659. show_temp_reg(3);
  660. /* Automatic PWM control */
  661. static ssize_t show_pwm_auto_channels(struct device *dev,
  662. struct device_attribute *attr, char *buf)
  663. {
  664. int nr = to_sensor_dev_attr(attr)->index;
  665. struct lm85_data *data = lm85_update_device(dev);
  666. return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
  667. }
  668. static ssize_t set_pwm_auto_channels(struct device *dev,
  669. struct device_attribute *attr, const char *buf, size_t count)
  670. {
  671. int nr = to_sensor_dev_attr(attr)->index;
  672. struct i2c_client *client = to_i2c_client(dev);
  673. struct lm85_data *data = i2c_get_clientdata(client);
  674. long val = simple_strtol(buf, NULL, 10);
  675. mutex_lock(&data->update_lock);
  676. data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
  677. | ZONE_TO_REG(val);
  678. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  679. data->autofan[nr].config);
  680. mutex_unlock(&data->update_lock);
  681. return count;
  682. }
  683. static ssize_t show_pwm_auto_pwm_min(struct device *dev,
  684. struct device_attribute *attr, char *buf)
  685. {
  686. int nr = to_sensor_dev_attr(attr)->index;
  687. struct lm85_data *data = lm85_update_device(dev);
  688. return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
  689. }
  690. static ssize_t set_pwm_auto_pwm_min(struct device *dev,
  691. struct device_attribute *attr, const char *buf, size_t count)
  692. {
  693. int nr = to_sensor_dev_attr(attr)->index;
  694. struct i2c_client *client = to_i2c_client(dev);
  695. struct lm85_data *data = i2c_get_clientdata(client);
  696. long val = simple_strtol(buf, NULL, 10);
  697. mutex_lock(&data->update_lock);
  698. data->autofan[nr].min_pwm = PWM_TO_REG(val);
  699. lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
  700. data->autofan[nr].min_pwm);
  701. mutex_unlock(&data->update_lock);
  702. return count;
  703. }
  704. static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
  705. struct device_attribute *attr, char *buf)
  706. {
  707. int nr = to_sensor_dev_attr(attr)->index;
  708. struct lm85_data *data = lm85_update_device(dev);
  709. return sprintf(buf, "%d\n", data->autofan[nr].min_off);
  710. }
  711. static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
  712. struct device_attribute *attr, const char *buf, size_t count)
  713. {
  714. int nr = to_sensor_dev_attr(attr)->index;
  715. struct i2c_client *client = to_i2c_client(dev);
  716. struct lm85_data *data = i2c_get_clientdata(client);
  717. long val = simple_strtol(buf, NULL, 10);
  718. u8 tmp;
  719. mutex_lock(&data->update_lock);
  720. data->autofan[nr].min_off = val;
  721. tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  722. tmp &= ~(0x20 << nr);
  723. if (data->autofan[nr].min_off)
  724. tmp |= 0x20 << nr;
  725. lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
  726. mutex_unlock(&data->update_lock);
  727. return count;
  728. }
  729. #define pwm_auto(offset) \
  730. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
  731. S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
  732. set_pwm_auto_channels, offset - 1); \
  733. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
  734. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
  735. set_pwm_auto_pwm_min, offset - 1); \
  736. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
  737. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
  738. set_pwm_auto_pwm_minctl, offset - 1)
  739. pwm_auto(1);
  740. pwm_auto(2);
  741. pwm_auto(3);
  742. /* Temperature settings for automatic PWM control */
  743. static ssize_t show_temp_auto_temp_off(struct device *dev,
  744. struct device_attribute *attr, char *buf)
  745. {
  746. int nr = to_sensor_dev_attr(attr)->index;
  747. struct lm85_data *data = lm85_update_device(dev);
  748. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
  749. HYST_FROM_REG(data->zone[nr].hyst));
  750. }
  751. static ssize_t set_temp_auto_temp_off(struct device *dev,
  752. struct device_attribute *attr, const char *buf, size_t count)
  753. {
  754. int nr = to_sensor_dev_attr(attr)->index;
  755. struct i2c_client *client = to_i2c_client(dev);
  756. struct lm85_data *data = i2c_get_clientdata(client);
  757. int min;
  758. long val = simple_strtol(buf, NULL, 10);
  759. mutex_lock(&data->update_lock);
  760. min = TEMP_FROM_REG(data->zone[nr].limit);
  761. data->zone[nr].hyst = HYST_TO_REG(min - val);
  762. if (nr == 0 || nr == 1) {
  763. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  764. (data->zone[0].hyst << 4)
  765. | data->zone[1].hyst);
  766. } else {
  767. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  768. (data->zone[2].hyst << 4));
  769. }
  770. mutex_unlock(&data->update_lock);
  771. return count;
  772. }
  773. static ssize_t show_temp_auto_temp_min(struct device *dev,
  774. struct device_attribute *attr, char *buf)
  775. {
  776. int nr = to_sensor_dev_attr(attr)->index;
  777. struct lm85_data *data = lm85_update_device(dev);
  778. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
  779. }
  780. static ssize_t set_temp_auto_temp_min(struct device *dev,
  781. struct device_attribute *attr, const char *buf, size_t count)
  782. {
  783. int nr = to_sensor_dev_attr(attr)->index;
  784. struct i2c_client *client = to_i2c_client(dev);
  785. struct lm85_data *data = i2c_get_clientdata(client);
  786. long val = simple_strtol(buf, NULL, 10);
  787. mutex_lock(&data->update_lock);
  788. data->zone[nr].limit = TEMP_TO_REG(val);
  789. lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
  790. data->zone[nr].limit);
  791. /* Update temp_auto_max and temp_auto_range */
  792. data->zone[nr].range = RANGE_TO_REG(
  793. TEMP_FROM_REG(data->zone[nr].max_desired) -
  794. TEMP_FROM_REG(data->zone[nr].limit));
  795. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  796. ((data->zone[nr].range & 0x0f) << 4)
  797. | (data->pwm_freq[nr] & 0x07));
  798. mutex_unlock(&data->update_lock);
  799. return count;
  800. }
  801. static ssize_t show_temp_auto_temp_max(struct device *dev,
  802. struct device_attribute *attr, char *buf)
  803. {
  804. int nr = to_sensor_dev_attr(attr)->index;
  805. struct lm85_data *data = lm85_update_device(dev);
  806. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
  807. RANGE_FROM_REG(data->zone[nr].range));
  808. }
  809. static ssize_t set_temp_auto_temp_max(struct device *dev,
  810. struct device_attribute *attr, const char *buf, size_t count)
  811. {
  812. int nr = to_sensor_dev_attr(attr)->index;
  813. struct i2c_client *client = to_i2c_client(dev);
  814. struct lm85_data *data = i2c_get_clientdata(client);
  815. int min;
  816. long val = simple_strtol(buf, NULL, 10);
  817. mutex_lock(&data->update_lock);
  818. min = TEMP_FROM_REG(data->zone[nr].limit);
  819. data->zone[nr].max_desired = TEMP_TO_REG(val);
  820. data->zone[nr].range = RANGE_TO_REG(
  821. val - min);
  822. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  823. ((data->zone[nr].range & 0x0f) << 4)
  824. | (data->pwm_freq[nr] & 0x07));
  825. mutex_unlock(&data->update_lock);
  826. return count;
  827. }
  828. static ssize_t show_temp_auto_temp_crit(struct device *dev,
  829. struct device_attribute *attr, char *buf)
  830. {
  831. int nr = to_sensor_dev_attr(attr)->index;
  832. struct lm85_data *data = lm85_update_device(dev);
  833. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
  834. }
  835. static ssize_t set_temp_auto_temp_crit(struct device *dev,
  836. struct device_attribute *attr, const char *buf, size_t count)
  837. {
  838. int nr = to_sensor_dev_attr(attr)->index;
  839. struct i2c_client *client = to_i2c_client(dev);
  840. struct lm85_data *data = i2c_get_clientdata(client);
  841. long val = simple_strtol(buf, NULL, 10);
  842. mutex_lock(&data->update_lock);
  843. data->zone[nr].critical = TEMP_TO_REG(val);
  844. lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
  845. data->zone[nr].critical);
  846. mutex_unlock(&data->update_lock);
  847. return count;
  848. }
  849. #define temp_auto(offset) \
  850. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
  851. S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
  852. set_temp_auto_temp_off, offset - 1); \
  853. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
  854. S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
  855. set_temp_auto_temp_min, offset - 1); \
  856. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
  857. S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
  858. set_temp_auto_temp_max, offset - 1); \
  859. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
  860. S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
  861. set_temp_auto_temp_crit, offset - 1);
  862. temp_auto(1);
  863. temp_auto(2);
  864. temp_auto(3);
  865. static struct attribute *lm85_attributes[] = {
  866. &sensor_dev_attr_fan1_input.dev_attr.attr,
  867. &sensor_dev_attr_fan2_input.dev_attr.attr,
  868. &sensor_dev_attr_fan3_input.dev_attr.attr,
  869. &sensor_dev_attr_fan4_input.dev_attr.attr,
  870. &sensor_dev_attr_fan1_min.dev_attr.attr,
  871. &sensor_dev_attr_fan2_min.dev_attr.attr,
  872. &sensor_dev_attr_fan3_min.dev_attr.attr,
  873. &sensor_dev_attr_fan4_min.dev_attr.attr,
  874. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  875. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  876. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  877. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  878. &sensor_dev_attr_pwm1.dev_attr.attr,
  879. &sensor_dev_attr_pwm2.dev_attr.attr,
  880. &sensor_dev_attr_pwm3.dev_attr.attr,
  881. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  882. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  883. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  884. &sensor_dev_attr_pwm1_freq.dev_attr.attr,
  885. &sensor_dev_attr_pwm2_freq.dev_attr.attr,
  886. &sensor_dev_attr_pwm3_freq.dev_attr.attr,
  887. &sensor_dev_attr_in0_input.dev_attr.attr,
  888. &sensor_dev_attr_in1_input.dev_attr.attr,
  889. &sensor_dev_attr_in2_input.dev_attr.attr,
  890. &sensor_dev_attr_in3_input.dev_attr.attr,
  891. &sensor_dev_attr_in0_min.dev_attr.attr,
  892. &sensor_dev_attr_in1_min.dev_attr.attr,
  893. &sensor_dev_attr_in2_min.dev_attr.attr,
  894. &sensor_dev_attr_in3_min.dev_attr.attr,
  895. &sensor_dev_attr_in0_max.dev_attr.attr,
  896. &sensor_dev_attr_in1_max.dev_attr.attr,
  897. &sensor_dev_attr_in2_max.dev_attr.attr,
  898. &sensor_dev_attr_in3_max.dev_attr.attr,
  899. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  900. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  901. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  902. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  903. &sensor_dev_attr_temp1_input.dev_attr.attr,
  904. &sensor_dev_attr_temp2_input.dev_attr.attr,
  905. &sensor_dev_attr_temp3_input.dev_attr.attr,
  906. &sensor_dev_attr_temp1_min.dev_attr.attr,
  907. &sensor_dev_attr_temp2_min.dev_attr.attr,
  908. &sensor_dev_attr_temp3_min.dev_attr.attr,
  909. &sensor_dev_attr_temp1_max.dev_attr.attr,
  910. &sensor_dev_attr_temp2_max.dev_attr.attr,
  911. &sensor_dev_attr_temp3_max.dev_attr.attr,
  912. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  913. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  914. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  915. &sensor_dev_attr_temp1_fault.dev_attr.attr,
  916. &sensor_dev_attr_temp3_fault.dev_attr.attr,
  917. &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
  918. &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
  919. &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
  920. &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
  921. &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
  922. &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
  923. &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
  924. &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
  925. &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
  926. &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
  927. &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
  928. &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
  929. &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
  930. &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
  931. &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
  932. &dev_attr_vrm.attr,
  933. &dev_attr_cpu0_vid.attr,
  934. &dev_attr_alarms.attr,
  935. NULL
  936. };
  937. static const struct attribute_group lm85_group = {
  938. .attrs = lm85_attributes,
  939. };
  940. static struct attribute *lm85_attributes_minctl[] = {
  941. &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
  942. &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
  943. &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
  944. NULL
  945. };
  946. static const struct attribute_group lm85_group_minctl = {
  947. .attrs = lm85_attributes_minctl,
  948. };
  949. static struct attribute *lm85_attributes_temp_off[] = {
  950. &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
  951. &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
  952. &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
  953. NULL
  954. };
  955. static const struct attribute_group lm85_group_temp_off = {
  956. .attrs = lm85_attributes_temp_off,
  957. };
  958. static struct attribute *lm85_attributes_in4[] = {
  959. &sensor_dev_attr_in4_input.dev_attr.attr,
  960. &sensor_dev_attr_in4_min.dev_attr.attr,
  961. &sensor_dev_attr_in4_max.dev_attr.attr,
  962. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  963. NULL
  964. };
  965. static const struct attribute_group lm85_group_in4 = {
  966. .attrs = lm85_attributes_in4,
  967. };
  968. static struct attribute *lm85_attributes_in567[] = {
  969. &sensor_dev_attr_in5_input.dev_attr.attr,
  970. &sensor_dev_attr_in6_input.dev_attr.attr,
  971. &sensor_dev_attr_in7_input.dev_attr.attr,
  972. &sensor_dev_attr_in5_min.dev_attr.attr,
  973. &sensor_dev_attr_in6_min.dev_attr.attr,
  974. &sensor_dev_attr_in7_min.dev_attr.attr,
  975. &sensor_dev_attr_in5_max.dev_attr.attr,
  976. &sensor_dev_attr_in6_max.dev_attr.attr,
  977. &sensor_dev_attr_in7_max.dev_attr.attr,
  978. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  979. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  980. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  981. NULL
  982. };
  983. static const struct attribute_group lm85_group_in567 = {
  984. .attrs = lm85_attributes_in567,
  985. };
  986. static void lm85_init_client(struct i2c_client *client)
  987. {
  988. int value;
  989. /* Start monitoring if needed */
  990. value = lm85_read_value(client, LM85_REG_CONFIG);
  991. if (!(value & 0x01)) {
  992. dev_info(&client->dev, "Starting monitoring\n");
  993. lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
  994. }
  995. /* Warn about unusual configuration bits */
  996. if (value & 0x02)
  997. dev_warn(&client->dev, "Device configuration is locked\n");
  998. if (!(value & 0x04))
  999. dev_warn(&client->dev, "Device is not ready\n");
  1000. }
  1001. static int lm85_is_fake(struct i2c_client *client)
  1002. {
  1003. /*
  1004. * Differenciate between real LM96000 and Winbond WPCD377I. The latter
  1005. * emulate the former except that it has no hardware monitoring function
  1006. * so the readings are always 0.
  1007. */
  1008. int i;
  1009. u8 in_temp, fan;
  1010. for (i = 0; i < 8; i++) {
  1011. in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
  1012. fan = i2c_smbus_read_byte_data(client, 0x28 + i);
  1013. if (in_temp != 0x00 || fan != 0xff)
  1014. return 0;
  1015. }
  1016. return 1;
  1017. }
  1018. /* Return 0 if detection is successful, -ENODEV otherwise */
  1019. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
  1020. {
  1021. struct i2c_adapter *adapter = client->adapter;
  1022. int address = client->addr;
  1023. const char *type_name;
  1024. int company, verstep;
  1025. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1026. /* We need to be able to do byte I/O */
  1027. return -ENODEV;
  1028. }
  1029. /* Determine the chip type */
  1030. company = lm85_read_value(client, LM85_REG_COMPANY);
  1031. verstep = lm85_read_value(client, LM85_REG_VERSTEP);
  1032. dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
  1033. "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
  1034. address, company, verstep);
  1035. /* All supported chips have the version in common */
  1036. if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
  1037. (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
  1038. dev_dbg(&adapter->dev,
  1039. "Autodetection failed: unsupported version\n");
  1040. return -ENODEV;
  1041. }
  1042. type_name = "lm85";
  1043. /* Now, refine the detection */
  1044. if (company == LM85_COMPANY_NATIONAL) {
  1045. switch (verstep) {
  1046. case LM85_VERSTEP_LM85C:
  1047. type_name = "lm85c";
  1048. break;
  1049. case LM85_VERSTEP_LM85B:
  1050. type_name = "lm85b";
  1051. break;
  1052. case LM85_VERSTEP_LM96000_1:
  1053. case LM85_VERSTEP_LM96000_2:
  1054. /* Check for Winbond WPCD377I */
  1055. if (lm85_is_fake(client)) {
  1056. dev_dbg(&adapter->dev,
  1057. "Found Winbond WPCD377I, ignoring\n");
  1058. return -ENODEV;
  1059. }
  1060. break;
  1061. }
  1062. } else if (company == LM85_COMPANY_ANALOG_DEV) {
  1063. switch (verstep) {
  1064. case LM85_VERSTEP_ADM1027:
  1065. type_name = "adm1027";
  1066. break;
  1067. case LM85_VERSTEP_ADT7463:
  1068. case LM85_VERSTEP_ADT7463C:
  1069. type_name = "adt7463";
  1070. break;
  1071. case LM85_VERSTEP_ADT7468_1:
  1072. case LM85_VERSTEP_ADT7468_2:
  1073. type_name = "adt7468";
  1074. break;
  1075. }
  1076. } else if (company == LM85_COMPANY_SMSC) {
  1077. switch (verstep) {
  1078. case LM85_VERSTEP_EMC6D100_A0:
  1079. case LM85_VERSTEP_EMC6D100_A1:
  1080. /* Note: we can't tell a '100 from a '101 */
  1081. type_name = "emc6d100";
  1082. break;
  1083. case LM85_VERSTEP_EMC6D102:
  1084. type_name = "emc6d102";
  1085. break;
  1086. case LM85_VERSTEP_EMC6D103_A0:
  1087. case LM85_VERSTEP_EMC6D103_A1:
  1088. type_name = "emc6d103";
  1089. break;
  1090. case LM85_VERSTEP_EMC6D103S:
  1091. type_name = "emc6d103s";
  1092. break;
  1093. }
  1094. } else {
  1095. dev_dbg(&adapter->dev,
  1096. "Autodetection failed: unknown vendor\n");
  1097. return -ENODEV;
  1098. }
  1099. strlcpy(info->type, type_name, I2C_NAME_SIZE);
  1100. return 0;
  1101. }
  1102. static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data)
  1103. {
  1104. sysfs_remove_group(&client->dev.kobj, &lm85_group);
  1105. if (data->type != emc6d103s) {
  1106. sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl);
  1107. sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off);
  1108. }
  1109. if (!data->has_vid5)
  1110. sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
  1111. if (data->type == emc6d100)
  1112. sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
  1113. }
  1114. static int lm85_probe(struct i2c_client *client,
  1115. const struct i2c_device_id *id)
  1116. {
  1117. struct lm85_data *data;
  1118. int err;
  1119. data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
  1120. if (!data)
  1121. return -ENOMEM;
  1122. i2c_set_clientdata(client, data);
  1123. data->type = id->driver_data;
  1124. mutex_init(&data->update_lock);
  1125. /* Fill in the chip specific driver values */
  1126. switch (data->type) {
  1127. case adm1027:
  1128. case adt7463:
  1129. case adt7468:
  1130. case emc6d100:
  1131. case emc6d102:
  1132. case emc6d103:
  1133. case emc6d103s:
  1134. data->freq_map = adm1027_freq_map;
  1135. break;
  1136. default:
  1137. data->freq_map = lm85_freq_map;
  1138. }
  1139. /* Set the VRM version */
  1140. data->vrm = vid_which_vrm();
  1141. /* Initialize the LM85 chip */
  1142. lm85_init_client(client);
  1143. /* Register sysfs hooks */
  1144. err = sysfs_create_group(&client->dev.kobj, &lm85_group);
  1145. if (err)
  1146. goto err_kfree;
  1147. /* minctl and temp_off exist on all chips except emc6d103s */
  1148. if (data->type != emc6d103s) {
  1149. err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl);
  1150. if (err)
  1151. goto err_remove_files;
  1152. err = sysfs_create_group(&client->dev.kobj,
  1153. &lm85_group_temp_off);
  1154. if (err)
  1155. goto err_remove_files;
  1156. }
  1157. /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
  1158. as a sixth digital VID input rather than an analog input. */
  1159. if (data->type == adt7463 || data->type == adt7468) {
  1160. u8 vid = lm85_read_value(client, LM85_REG_VID);
  1161. if (vid & 0x80)
  1162. data->has_vid5 = true;
  1163. }
  1164. if (!data->has_vid5)
  1165. if ((err = sysfs_create_group(&client->dev.kobj,
  1166. &lm85_group_in4)))
  1167. goto err_remove_files;
  1168. /* The EMC6D100 has 3 additional voltage inputs */
  1169. if (data->type == emc6d100)
  1170. if ((err = sysfs_create_group(&client->dev.kobj,
  1171. &lm85_group_in567)))
  1172. goto err_remove_files;
  1173. data->hwmon_dev = hwmon_device_register(&client->dev);
  1174. if (IS_ERR(data->hwmon_dev)) {
  1175. err = PTR_ERR(data->hwmon_dev);
  1176. goto err_remove_files;
  1177. }
  1178. return 0;
  1179. /* Error out and cleanup code */
  1180. err_remove_files:
  1181. lm85_remove_files(client, data);
  1182. err_kfree:
  1183. kfree(data);
  1184. return err;
  1185. }
  1186. static int lm85_remove(struct i2c_client *client)
  1187. {
  1188. struct lm85_data *data = i2c_get_clientdata(client);
  1189. hwmon_device_unregister(data->hwmon_dev);
  1190. lm85_remove_files(client, data);
  1191. kfree(data);
  1192. return 0;
  1193. }
  1194. static int lm85_read_value(struct i2c_client *client, u8 reg)
  1195. {
  1196. int res;
  1197. /* What size location is it? */
  1198. switch (reg) {
  1199. case LM85_REG_FAN(0): /* Read 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. case LM85_REG_ALARM1: /* Read both bytes at once */
  1208. res = i2c_smbus_read_byte_data(client, reg) & 0xff;
  1209. res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
  1210. break;
  1211. default: /* Read BYTE data */
  1212. res = i2c_smbus_read_byte_data(client, reg);
  1213. break;
  1214. }
  1215. return res;
  1216. }
  1217. static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
  1218. {
  1219. switch (reg) {
  1220. case LM85_REG_FAN(0): /* Write WORD data */
  1221. case LM85_REG_FAN(1):
  1222. case LM85_REG_FAN(2):
  1223. case LM85_REG_FAN(3):
  1224. case LM85_REG_FAN_MIN(0):
  1225. case LM85_REG_FAN_MIN(1):
  1226. case LM85_REG_FAN_MIN(2):
  1227. case LM85_REG_FAN_MIN(3):
  1228. /* NOTE: ALARM is read only, so not included here */
  1229. i2c_smbus_write_byte_data(client, reg, value & 0xff);
  1230. i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
  1231. break;
  1232. default: /* Write BYTE data */
  1233. i2c_smbus_write_byte_data(client, reg, value);
  1234. break;
  1235. }
  1236. }
  1237. static struct lm85_data *lm85_update_device(struct device *dev)
  1238. {
  1239. struct i2c_client *client = to_i2c_client(dev);
  1240. struct lm85_data *data = i2c_get_clientdata(client);
  1241. int i;
  1242. mutex_lock(&data->update_lock);
  1243. if (!data->valid ||
  1244. time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
  1245. /* Things that change quickly */
  1246. dev_dbg(&client->dev, "Reading sensor values\n");
  1247. /* Have to read extended bits first to "freeze" the
  1248. * more significant bits that are read later.
  1249. * There are 2 additional resolution bits per channel and we
  1250. * have room for 4, so we shift them to the left.
  1251. */
  1252. if (data->type == adm1027 || data->type == adt7463 ||
  1253. data->type == adt7468) {
  1254. int ext1 = lm85_read_value(client,
  1255. ADM1027_REG_EXTEND_ADC1);
  1256. int ext2 = lm85_read_value(client,
  1257. ADM1027_REG_EXTEND_ADC2);
  1258. int val = (ext1 << 8) + ext2;
  1259. for (i = 0; i <= 4; i++)
  1260. data->in_ext[i] =
  1261. ((val >> (i * 2)) & 0x03) << 2;
  1262. for (i = 0; i <= 2; i++)
  1263. data->temp_ext[i] =
  1264. (val >> ((i + 4) * 2)) & 0x0c;
  1265. }
  1266. data->vid = lm85_read_value(client, LM85_REG_VID);
  1267. for (i = 0; i <= 3; ++i) {
  1268. data->in[i] =
  1269. lm85_read_value(client, LM85_REG_IN(i));
  1270. data->fan[i] =
  1271. lm85_read_value(client, LM85_REG_FAN(i));
  1272. }
  1273. if (!data->has_vid5)
  1274. data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
  1275. if (data->type == adt7468)
  1276. data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
  1277. for (i = 0; i <= 2; ++i) {
  1278. data->temp[i] =
  1279. lm85_read_value(client, LM85_REG_TEMP(i));
  1280. data->pwm[i] =
  1281. lm85_read_value(client, LM85_REG_PWM(i));
  1282. if (IS_ADT7468_OFF64(data))
  1283. data->temp[i] -= 64;
  1284. }
  1285. data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
  1286. if (data->type == emc6d100) {
  1287. /* Three more voltage sensors */
  1288. for (i = 5; i <= 7; ++i) {
  1289. data->in[i] = lm85_read_value(client,
  1290. EMC6D100_REG_IN(i));
  1291. }
  1292. /* More alarm bits */
  1293. data->alarms |= lm85_read_value(client,
  1294. EMC6D100_REG_ALARM3) << 16;
  1295. } else if (data->type == emc6d102 || data->type == emc6d103 ||
  1296. data->type == emc6d103s) {
  1297. /* Have to read LSB bits after the MSB ones because
  1298. the reading of the MSB bits has frozen the
  1299. LSBs (backward from the ADM1027).
  1300. */
  1301. int ext1 = lm85_read_value(client,
  1302. EMC6D102_REG_EXTEND_ADC1);
  1303. int ext2 = lm85_read_value(client,
  1304. EMC6D102_REG_EXTEND_ADC2);
  1305. int ext3 = lm85_read_value(client,
  1306. EMC6D102_REG_EXTEND_ADC3);
  1307. int ext4 = lm85_read_value(client,
  1308. EMC6D102_REG_EXTEND_ADC4);
  1309. data->in_ext[0] = ext3 & 0x0f;
  1310. data->in_ext[1] = ext4 & 0x0f;
  1311. data->in_ext[2] = ext4 >> 4;
  1312. data->in_ext[3] = ext3 >> 4;
  1313. data->in_ext[4] = ext2 >> 4;
  1314. data->temp_ext[0] = ext1 & 0x0f;
  1315. data->temp_ext[1] = ext2 & 0x0f;
  1316. data->temp_ext[2] = ext1 >> 4;
  1317. }
  1318. data->last_reading = jiffies;
  1319. } /* last_reading */
  1320. if (!data->valid ||
  1321. time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
  1322. /* Things that don't change often */
  1323. dev_dbg(&client->dev, "Reading config values\n");
  1324. for (i = 0; i <= 3; ++i) {
  1325. data->in_min[i] =
  1326. lm85_read_value(client, LM85_REG_IN_MIN(i));
  1327. data->in_max[i] =
  1328. lm85_read_value(client, LM85_REG_IN_MAX(i));
  1329. data->fan_min[i] =
  1330. lm85_read_value(client, LM85_REG_FAN_MIN(i));
  1331. }
  1332. if (!data->has_vid5) {
  1333. data->in_min[4] = lm85_read_value(client,
  1334. LM85_REG_IN_MIN(4));
  1335. data->in_max[4] = lm85_read_value(client,
  1336. LM85_REG_IN_MAX(4));
  1337. }
  1338. if (data->type == emc6d100) {
  1339. for (i = 5; i <= 7; ++i) {
  1340. data->in_min[i] = lm85_read_value(client,
  1341. EMC6D100_REG_IN_MIN(i));
  1342. data->in_max[i] = lm85_read_value(client,
  1343. EMC6D100_REG_IN_MAX(i));
  1344. }
  1345. }
  1346. for (i = 0; i <= 2; ++i) {
  1347. int val;
  1348. data->temp_min[i] =
  1349. lm85_read_value(client, LM85_REG_TEMP_MIN(i));
  1350. data->temp_max[i] =
  1351. lm85_read_value(client, LM85_REG_TEMP_MAX(i));
  1352. data->autofan[i].config =
  1353. lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
  1354. val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
  1355. data->pwm_freq[i] = val & 0x07;
  1356. data->zone[i].range = val >> 4;
  1357. data->autofan[i].min_pwm =
  1358. lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
  1359. data->zone[i].limit =
  1360. lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
  1361. data->zone[i].critical =
  1362. lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
  1363. if (IS_ADT7468_OFF64(data)) {
  1364. data->temp_min[i] -= 64;
  1365. data->temp_max[i] -= 64;
  1366. data->zone[i].limit -= 64;
  1367. data->zone[i].critical -= 64;
  1368. }
  1369. }
  1370. if (data->type != emc6d103s) {
  1371. i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  1372. data->autofan[0].min_off = (i & 0x20) != 0;
  1373. data->autofan[1].min_off = (i & 0x40) != 0;
  1374. data->autofan[2].min_off = (i & 0x80) != 0;
  1375. i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
  1376. data->zone[0].hyst = i >> 4;
  1377. data->zone[1].hyst = i & 0x0f;
  1378. i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
  1379. data->zone[2].hyst = i >> 4;
  1380. }
  1381. data->last_config = jiffies;
  1382. } /* last_config */
  1383. data->valid = 1;
  1384. mutex_unlock(&data->update_lock);
  1385. return data;
  1386. }
  1387. static int __init sm_lm85_init(void)
  1388. {
  1389. return i2c_add_driver(&lm85_driver);
  1390. }
  1391. static void __exit sm_lm85_exit(void)
  1392. {
  1393. i2c_del_driver(&lm85_driver);
  1394. }
  1395. MODULE_LICENSE("GPL");
  1396. MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
  1397. "Margit Schubert-While <margitsw@t-online.de>, "
  1398. "Justin Thiessen <jthiessen@penguincomputing.com>");
  1399. MODULE_DESCRIPTION("LM85-B, LM85-C driver");
  1400. module_init(sm_lm85_init);
  1401. module_exit(sm_lm85_exit);