lm85.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  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 acording to built-in resistors */
  110. static const int lm85_scaling[] = { /* .001 Volts */
  111. 2500, 2250, 3300, 5000, 12000,
  112. 3300, 1500, 1800 /*EMC6D100*/
  113. };
  114. #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
  115. #define INS_TO_REG(n, val) \
  116. SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
  117. #define INSEXT_FROM_REG(n, val, ext) \
  118. SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
  119. #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
  120. /* FAN speed is measured using 90kHz clock */
  121. static inline u16 FAN_TO_REG(unsigned long val)
  122. {
  123. if (!val)
  124. return 0xffff;
  125. return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
  126. }
  127. #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
  128. 5400000 / (val))
  129. /* Temperature is reported in .001 degC increments */
  130. #define TEMP_TO_REG(val) \
  131. SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
  132. #define TEMPEXT_FROM_REG(val, ext) \
  133. SCALE(((val) << 4) + (ext), 16, 1000)
  134. #define TEMP_FROM_REG(val) ((val) * 1000)
  135. #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
  136. #define PWM_FROM_REG(val) (val)
  137. /* ZONEs have the following parameters:
  138. * Limit (low) temp, 1. degC
  139. * Hysteresis (below limit), 1. degC (0-15)
  140. * Range of speed control, .1 degC (2-80)
  141. * Critical (high) temp, 1. degC
  142. *
  143. * FAN PWMs have the following parameters:
  144. * Reference Zone, 1, 2, 3, etc.
  145. * Spinup time, .05 sec
  146. * PWM value at limit/low temp, 1 count
  147. * PWM Frequency, 1. Hz
  148. * PWM is Min or OFF below limit, flag
  149. * Invert PWM output, flag
  150. *
  151. * Some chips filter the temp, others the fan.
  152. * Filter constant (or disabled) .1 seconds
  153. */
  154. /* These are the zone temperature range encodings in .001 degree C */
  155. static const int lm85_range_map[] = {
  156. 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
  157. 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
  158. };
  159. static int RANGE_TO_REG(int range)
  160. {
  161. int i;
  162. /* Find the closest match */
  163. for (i = 0; i < 15; ++i) {
  164. if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
  165. break;
  166. }
  167. return i;
  168. }
  169. #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
  170. /* These are the PWM frequency encodings */
  171. static const int lm85_freq_map[8] = { /* 1 Hz */
  172. 10, 15, 23, 30, 38, 47, 61, 94
  173. };
  174. static const int adm1027_freq_map[8] = { /* 1 Hz */
  175. 11, 15, 22, 29, 35, 44, 59, 88
  176. };
  177. static int FREQ_TO_REG(const int *map, int freq)
  178. {
  179. int i;
  180. /* Find the closest match */
  181. for (i = 0; i < 7; ++i)
  182. if (freq <= (map[i] + map[i + 1]) / 2)
  183. break;
  184. return i;
  185. }
  186. static int FREQ_FROM_REG(const int *map, u8 reg)
  187. {
  188. return map[reg & 0x07];
  189. }
  190. /* Since we can't use strings, I'm abusing these numbers
  191. * to stand in for the following meanings:
  192. * 1 -- PWM responds to Zone 1
  193. * 2 -- PWM responds to Zone 2
  194. * 3 -- PWM responds to Zone 3
  195. * 23 -- PWM responds to the higher temp of Zone 2 or 3
  196. * 123 -- PWM responds to highest of Zone 1, 2, or 3
  197. * 0 -- PWM is always at 0% (ie, off)
  198. * -1 -- PWM is always at 100%
  199. * -2 -- PWM responds to manual control
  200. */
  201. static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
  202. #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
  203. static int ZONE_TO_REG(int zone)
  204. {
  205. int i;
  206. for (i = 0; i <= 7; ++i)
  207. if (zone == lm85_zone_map[i])
  208. break;
  209. if (i > 7) /* Not found. */
  210. i = 3; /* Always 100% */
  211. return i << 5;
  212. }
  213. #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
  214. #define HYST_FROM_REG(val) ((val) * 1000)
  215. /* Chip sampling rates
  216. *
  217. * Some sensors are not updated more frequently than once per second
  218. * so it doesn't make sense to read them more often than that.
  219. * We cache the results and return the saved data if the driver
  220. * is called again before a second has elapsed.
  221. *
  222. * Also, there is significant configuration data for this chip
  223. * given the automatic PWM fan control that is possible. There
  224. * are about 47 bytes of config data to only 22 bytes of actual
  225. * readings. So, we keep the config data up to date in the cache
  226. * when it is written and only sample it once every 1 *minute*
  227. */
  228. #define LM85_DATA_INTERVAL (HZ + HZ / 2)
  229. #define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
  230. /* LM85 can automatically adjust fan speeds based on temperature
  231. * This structure encapsulates an entire Zone config. There are
  232. * three zones (one for each temperature input) on the lm85
  233. */
  234. struct lm85_zone {
  235. s8 limit; /* Low temp limit */
  236. u8 hyst; /* Low limit hysteresis. (0-15) */
  237. u8 range; /* Temp range, encoded */
  238. s8 critical; /* "All fans ON" temp limit */
  239. u8 max_desired; /* Actual "max" temperature specified. Preserved
  240. * to prevent "drift" as other autofan control
  241. * values change.
  242. */
  243. };
  244. struct lm85_autofan {
  245. u8 config; /* Register value */
  246. u8 min_pwm; /* Minimum PWM value, encoded */
  247. u8 min_off; /* Min PWM or OFF below "limit", flag */
  248. };
  249. /* For each registered chip, we need to keep some data in memory.
  250. The structure is dynamically allocated. */
  251. struct lm85_data {
  252. struct device *hwmon_dev;
  253. const int *freq_map;
  254. enum chips type;
  255. bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */
  256. struct mutex update_lock;
  257. int valid; /* !=0 if following fields are valid */
  258. unsigned long last_reading; /* In jiffies */
  259. unsigned long last_config; /* In jiffies */
  260. u8 in[8]; /* Register value */
  261. u8 in_max[8]; /* Register value */
  262. u8 in_min[8]; /* Register value */
  263. s8 temp[3]; /* Register value */
  264. s8 temp_min[3]; /* Register value */
  265. s8 temp_max[3]; /* Register value */
  266. u16 fan[4]; /* Register value */
  267. u16 fan_min[4]; /* Register value */
  268. u8 pwm[3]; /* Register value */
  269. u8 pwm_freq[3]; /* Register encoding */
  270. u8 temp_ext[3]; /* Decoded values */
  271. u8 in_ext[8]; /* Decoded values */
  272. u8 vid; /* Register value */
  273. u8 vrm; /* VRM version */
  274. u32 alarms; /* Register encoding, combined */
  275. u8 cfg5; /* Config Register 5 on ADT7468 */
  276. struct lm85_autofan autofan[3];
  277. struct lm85_zone zone[3];
  278. };
  279. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info);
  280. static int lm85_probe(struct i2c_client *client,
  281. const struct i2c_device_id *id);
  282. static int lm85_remove(struct i2c_client *client);
  283. static int lm85_read_value(struct i2c_client *client, u8 reg);
  284. static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
  285. static struct lm85_data *lm85_update_device(struct device *dev);
  286. static const struct i2c_device_id lm85_id[] = {
  287. { "adm1027", adm1027 },
  288. { "adt7463", adt7463 },
  289. { "adt7468", adt7468 },
  290. { "lm85", any_chip },
  291. { "lm85b", lm85b },
  292. { "lm85c", lm85c },
  293. { "emc6d100", emc6d100 },
  294. { "emc6d101", emc6d100 },
  295. { "emc6d102", emc6d102 },
  296. { "emc6d103", emc6d103 },
  297. { "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. };
  945. static const struct attribute_group lm85_group_minctl = {
  946. .attrs = lm85_attributes_minctl,
  947. };
  948. static struct attribute *lm85_attributes_temp_off[] = {
  949. &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
  950. &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
  951. &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
  952. };
  953. static const struct attribute_group lm85_group_temp_off = {
  954. .attrs = lm85_attributes_temp_off,
  955. };
  956. static struct attribute *lm85_attributes_in4[] = {
  957. &sensor_dev_attr_in4_input.dev_attr.attr,
  958. &sensor_dev_attr_in4_min.dev_attr.attr,
  959. &sensor_dev_attr_in4_max.dev_attr.attr,
  960. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  961. NULL
  962. };
  963. static const struct attribute_group lm85_group_in4 = {
  964. .attrs = lm85_attributes_in4,
  965. };
  966. static struct attribute *lm85_attributes_in567[] = {
  967. &sensor_dev_attr_in5_input.dev_attr.attr,
  968. &sensor_dev_attr_in6_input.dev_attr.attr,
  969. &sensor_dev_attr_in7_input.dev_attr.attr,
  970. &sensor_dev_attr_in5_min.dev_attr.attr,
  971. &sensor_dev_attr_in6_min.dev_attr.attr,
  972. &sensor_dev_attr_in7_min.dev_attr.attr,
  973. &sensor_dev_attr_in5_max.dev_attr.attr,
  974. &sensor_dev_attr_in6_max.dev_attr.attr,
  975. &sensor_dev_attr_in7_max.dev_attr.attr,
  976. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  977. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  978. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  979. NULL
  980. };
  981. static const struct attribute_group lm85_group_in567 = {
  982. .attrs = lm85_attributes_in567,
  983. };
  984. static void lm85_init_client(struct i2c_client *client)
  985. {
  986. int value;
  987. /* Start monitoring if needed */
  988. value = lm85_read_value(client, LM85_REG_CONFIG);
  989. if (!(value & 0x01)) {
  990. dev_info(&client->dev, "Starting monitoring\n");
  991. lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
  992. }
  993. /* Warn about unusual configuration bits */
  994. if (value & 0x02)
  995. dev_warn(&client->dev, "Device configuration is locked\n");
  996. if (!(value & 0x04))
  997. dev_warn(&client->dev, "Device is not ready\n");
  998. }
  999. static int lm85_is_fake(struct i2c_client *client)
  1000. {
  1001. /*
  1002. * Differenciate between real LM96000 and Winbond WPCD377I. The latter
  1003. * emulate the former except that it has no hardware monitoring function
  1004. * so the readings are always 0.
  1005. */
  1006. int i;
  1007. u8 in_temp, fan;
  1008. for (i = 0; i < 8; i++) {
  1009. in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
  1010. fan = i2c_smbus_read_byte_data(client, 0x28 + i);
  1011. if (in_temp != 0x00 || fan != 0xff)
  1012. return 0;
  1013. }
  1014. return 1;
  1015. }
  1016. /* Return 0 if detection is successful, -ENODEV otherwise */
  1017. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
  1018. {
  1019. struct i2c_adapter *adapter = client->adapter;
  1020. int address = client->addr;
  1021. const char *type_name;
  1022. int company, verstep;
  1023. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1024. /* We need to be able to do byte I/O */
  1025. return -ENODEV;
  1026. }
  1027. /* Determine the chip type */
  1028. company = lm85_read_value(client, LM85_REG_COMPANY);
  1029. verstep = lm85_read_value(client, LM85_REG_VERSTEP);
  1030. dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
  1031. "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
  1032. address, company, verstep);
  1033. /* All supported chips have the version in common */
  1034. if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
  1035. (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
  1036. dev_dbg(&adapter->dev,
  1037. "Autodetection failed: unsupported version\n");
  1038. return -ENODEV;
  1039. }
  1040. type_name = "lm85";
  1041. /* Now, refine the detection */
  1042. if (company == LM85_COMPANY_NATIONAL) {
  1043. switch (verstep) {
  1044. case LM85_VERSTEP_LM85C:
  1045. type_name = "lm85c";
  1046. break;
  1047. case LM85_VERSTEP_LM85B:
  1048. type_name = "lm85b";
  1049. break;
  1050. case LM85_VERSTEP_LM96000_1:
  1051. case LM85_VERSTEP_LM96000_2:
  1052. /* Check for Winbond WPCD377I */
  1053. if (lm85_is_fake(client)) {
  1054. dev_dbg(&adapter->dev,
  1055. "Found Winbond WPCD377I, ignoring\n");
  1056. return -ENODEV;
  1057. }
  1058. break;
  1059. }
  1060. } else if (company == LM85_COMPANY_ANALOG_DEV) {
  1061. switch (verstep) {
  1062. case LM85_VERSTEP_ADM1027:
  1063. type_name = "adm1027";
  1064. break;
  1065. case LM85_VERSTEP_ADT7463:
  1066. case LM85_VERSTEP_ADT7463C:
  1067. type_name = "adt7463";
  1068. break;
  1069. case LM85_VERSTEP_ADT7468_1:
  1070. case LM85_VERSTEP_ADT7468_2:
  1071. type_name = "adt7468";
  1072. break;
  1073. }
  1074. } else if (company == LM85_COMPANY_SMSC) {
  1075. switch (verstep) {
  1076. case LM85_VERSTEP_EMC6D100_A0:
  1077. case LM85_VERSTEP_EMC6D100_A1:
  1078. /* Note: we can't tell a '100 from a '101 */
  1079. type_name = "emc6d100";
  1080. break;
  1081. case LM85_VERSTEP_EMC6D102:
  1082. type_name = "emc6d102";
  1083. break;
  1084. case LM85_VERSTEP_EMC6D103_A0:
  1085. case LM85_VERSTEP_EMC6D103_A1:
  1086. type_name = "emc6d103";
  1087. break;
  1088. case LM85_VERSTEP_EMC6D103S:
  1089. type_name = "emc6d103s";
  1090. break;
  1091. }
  1092. } else {
  1093. dev_dbg(&adapter->dev,
  1094. "Autodetection failed: unknown vendor\n");
  1095. return -ENODEV;
  1096. }
  1097. strlcpy(info->type, type_name, I2C_NAME_SIZE);
  1098. return 0;
  1099. }
  1100. static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data)
  1101. {
  1102. sysfs_remove_group(&client->dev.kobj, &lm85_group);
  1103. if (data->type != emc6d103s) {
  1104. sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl);
  1105. sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off);
  1106. }
  1107. if (!data->has_vid5)
  1108. sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
  1109. if (data->type == emc6d100)
  1110. sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
  1111. }
  1112. static int lm85_probe(struct i2c_client *client,
  1113. const struct i2c_device_id *id)
  1114. {
  1115. struct lm85_data *data;
  1116. int err;
  1117. data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
  1118. if (!data)
  1119. return -ENOMEM;
  1120. i2c_set_clientdata(client, data);
  1121. data->type = id->driver_data;
  1122. mutex_init(&data->update_lock);
  1123. /* Fill in the chip specific driver values */
  1124. switch (data->type) {
  1125. case adm1027:
  1126. case adt7463:
  1127. case adt7468:
  1128. case emc6d100:
  1129. case emc6d102:
  1130. case emc6d103:
  1131. case emc6d103s:
  1132. data->freq_map = adm1027_freq_map;
  1133. break;
  1134. default:
  1135. data->freq_map = lm85_freq_map;
  1136. }
  1137. /* Set the VRM version */
  1138. data->vrm = vid_which_vrm();
  1139. /* Initialize the LM85 chip */
  1140. lm85_init_client(client);
  1141. /* Register sysfs hooks */
  1142. err = sysfs_create_group(&client->dev.kobj, &lm85_group);
  1143. if (err)
  1144. goto err_kfree;
  1145. /* minctl and temp_off exist on all chips except emc6d103s */
  1146. if (data->type != emc6d103s) {
  1147. err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl);
  1148. if (err)
  1149. goto err_kfree;
  1150. err = sysfs_create_group(&client->dev.kobj,
  1151. &lm85_group_temp_off);
  1152. if (err)
  1153. goto err_kfree;
  1154. }
  1155. /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
  1156. as a sixth digital VID input rather than an analog input. */
  1157. if (data->type == adt7463 || data->type == adt7468) {
  1158. u8 vid = lm85_read_value(client, LM85_REG_VID);
  1159. if (vid & 0x80)
  1160. data->has_vid5 = true;
  1161. }
  1162. if (!data->has_vid5)
  1163. if ((err = sysfs_create_group(&client->dev.kobj,
  1164. &lm85_group_in4)))
  1165. goto err_remove_files;
  1166. /* The EMC6D100 has 3 additional voltage inputs */
  1167. if (data->type == emc6d100)
  1168. if ((err = sysfs_create_group(&client->dev.kobj,
  1169. &lm85_group_in567)))
  1170. goto err_remove_files;
  1171. data->hwmon_dev = hwmon_device_register(&client->dev);
  1172. if (IS_ERR(data->hwmon_dev)) {
  1173. err = PTR_ERR(data->hwmon_dev);
  1174. goto err_remove_files;
  1175. }
  1176. return 0;
  1177. /* Error out and cleanup code */
  1178. err_remove_files:
  1179. lm85_remove_files(client, data);
  1180. err_kfree:
  1181. kfree(data);
  1182. return err;
  1183. }
  1184. static int lm85_remove(struct i2c_client *client)
  1185. {
  1186. struct lm85_data *data = i2c_get_clientdata(client);
  1187. hwmon_device_unregister(data->hwmon_dev);
  1188. lm85_remove_files(client, data);
  1189. kfree(data);
  1190. return 0;
  1191. }
  1192. static int lm85_read_value(struct i2c_client *client, u8 reg)
  1193. {
  1194. int res;
  1195. /* What size location is it? */
  1196. switch (reg) {
  1197. case LM85_REG_FAN(0): /* Read WORD data */
  1198. case LM85_REG_FAN(1):
  1199. case LM85_REG_FAN(2):
  1200. case LM85_REG_FAN(3):
  1201. case LM85_REG_FAN_MIN(0):
  1202. case LM85_REG_FAN_MIN(1):
  1203. case LM85_REG_FAN_MIN(2):
  1204. case LM85_REG_FAN_MIN(3):
  1205. case LM85_REG_ALARM1: /* Read both bytes at once */
  1206. res = i2c_smbus_read_byte_data(client, reg) & 0xff;
  1207. res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
  1208. break;
  1209. default: /* Read BYTE data */
  1210. res = i2c_smbus_read_byte_data(client, reg);
  1211. break;
  1212. }
  1213. return res;
  1214. }
  1215. static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
  1216. {
  1217. switch (reg) {
  1218. case LM85_REG_FAN(0): /* Write WORD data */
  1219. case LM85_REG_FAN(1):
  1220. case LM85_REG_FAN(2):
  1221. case LM85_REG_FAN(3):
  1222. case LM85_REG_FAN_MIN(0):
  1223. case LM85_REG_FAN_MIN(1):
  1224. case LM85_REG_FAN_MIN(2):
  1225. case LM85_REG_FAN_MIN(3):
  1226. /* NOTE: ALARM is read only, so not included here */
  1227. i2c_smbus_write_byte_data(client, reg, value & 0xff);
  1228. i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
  1229. break;
  1230. default: /* Write BYTE data */
  1231. i2c_smbus_write_byte_data(client, reg, value);
  1232. break;
  1233. }
  1234. }
  1235. static struct lm85_data *lm85_update_device(struct device *dev)
  1236. {
  1237. struct i2c_client *client = to_i2c_client(dev);
  1238. struct lm85_data *data = i2c_get_clientdata(client);
  1239. int i;
  1240. mutex_lock(&data->update_lock);
  1241. if (!data->valid ||
  1242. time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
  1243. /* Things that change quickly */
  1244. dev_dbg(&client->dev, "Reading sensor values\n");
  1245. /* Have to read extended bits first to "freeze" the
  1246. * more significant bits that are read later.
  1247. * There are 2 additional resolution bits per channel and we
  1248. * have room for 4, so we shift them to the left.
  1249. */
  1250. if (data->type == adm1027 || data->type == adt7463 ||
  1251. data->type == adt7468) {
  1252. int ext1 = lm85_read_value(client,
  1253. ADM1027_REG_EXTEND_ADC1);
  1254. int ext2 = lm85_read_value(client,
  1255. ADM1027_REG_EXTEND_ADC2);
  1256. int val = (ext1 << 8) + ext2;
  1257. for (i = 0; i <= 4; i++)
  1258. data->in_ext[i] =
  1259. ((val >> (i * 2)) & 0x03) << 2;
  1260. for (i = 0; i <= 2; i++)
  1261. data->temp_ext[i] =
  1262. (val >> ((i + 4) * 2)) & 0x0c;
  1263. }
  1264. data->vid = lm85_read_value(client, LM85_REG_VID);
  1265. for (i = 0; i <= 3; ++i) {
  1266. data->in[i] =
  1267. lm85_read_value(client, LM85_REG_IN(i));
  1268. data->fan[i] =
  1269. lm85_read_value(client, LM85_REG_FAN(i));
  1270. }
  1271. if (!data->has_vid5)
  1272. data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
  1273. if (data->type == adt7468)
  1274. data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
  1275. for (i = 0; i <= 2; ++i) {
  1276. data->temp[i] =
  1277. lm85_read_value(client, LM85_REG_TEMP(i));
  1278. data->pwm[i] =
  1279. lm85_read_value(client, LM85_REG_PWM(i));
  1280. if (IS_ADT7468_OFF64(data))
  1281. data->temp[i] -= 64;
  1282. }
  1283. data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
  1284. if (data->type == emc6d100) {
  1285. /* Three more voltage sensors */
  1286. for (i = 5; i <= 7; ++i) {
  1287. data->in[i] = lm85_read_value(client,
  1288. EMC6D100_REG_IN(i));
  1289. }
  1290. /* More alarm bits */
  1291. data->alarms |= lm85_read_value(client,
  1292. EMC6D100_REG_ALARM3) << 16;
  1293. } else if (data->type == emc6d102 || data->type == emc6d103 ||
  1294. data->type == emc6d103s) {
  1295. /* Have to read LSB bits after the MSB ones because
  1296. the reading of the MSB bits has frozen the
  1297. LSBs (backward from the ADM1027).
  1298. */
  1299. int ext1 = lm85_read_value(client,
  1300. EMC6D102_REG_EXTEND_ADC1);
  1301. int ext2 = lm85_read_value(client,
  1302. EMC6D102_REG_EXTEND_ADC2);
  1303. int ext3 = lm85_read_value(client,
  1304. EMC6D102_REG_EXTEND_ADC3);
  1305. int ext4 = lm85_read_value(client,
  1306. EMC6D102_REG_EXTEND_ADC4);
  1307. data->in_ext[0] = ext3 & 0x0f;
  1308. data->in_ext[1] = ext4 & 0x0f;
  1309. data->in_ext[2] = ext4 >> 4;
  1310. data->in_ext[3] = ext3 >> 4;
  1311. data->in_ext[4] = ext2 >> 4;
  1312. data->temp_ext[0] = ext1 & 0x0f;
  1313. data->temp_ext[1] = ext2 & 0x0f;
  1314. data->temp_ext[2] = ext1 >> 4;
  1315. }
  1316. data->last_reading = jiffies;
  1317. } /* last_reading */
  1318. if (!data->valid ||
  1319. time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
  1320. /* Things that don't change often */
  1321. dev_dbg(&client->dev, "Reading config values\n");
  1322. for (i = 0; i <= 3; ++i) {
  1323. data->in_min[i] =
  1324. lm85_read_value(client, LM85_REG_IN_MIN(i));
  1325. data->in_max[i] =
  1326. lm85_read_value(client, LM85_REG_IN_MAX(i));
  1327. data->fan_min[i] =
  1328. lm85_read_value(client, LM85_REG_FAN_MIN(i));
  1329. }
  1330. if (!data->has_vid5) {
  1331. data->in_min[4] = lm85_read_value(client,
  1332. LM85_REG_IN_MIN(4));
  1333. data->in_max[4] = lm85_read_value(client,
  1334. LM85_REG_IN_MAX(4));
  1335. }
  1336. if (data->type == emc6d100) {
  1337. for (i = 5; i <= 7; ++i) {
  1338. data->in_min[i] = lm85_read_value(client,
  1339. EMC6D100_REG_IN_MIN(i));
  1340. data->in_max[i] = lm85_read_value(client,
  1341. EMC6D100_REG_IN_MAX(i));
  1342. }
  1343. }
  1344. for (i = 0; i <= 2; ++i) {
  1345. int val;
  1346. data->temp_min[i] =
  1347. lm85_read_value(client, LM85_REG_TEMP_MIN(i));
  1348. data->temp_max[i] =
  1349. lm85_read_value(client, LM85_REG_TEMP_MAX(i));
  1350. data->autofan[i].config =
  1351. lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
  1352. val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
  1353. data->pwm_freq[i] = val & 0x07;
  1354. data->zone[i].range = val >> 4;
  1355. data->autofan[i].min_pwm =
  1356. lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
  1357. data->zone[i].limit =
  1358. lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
  1359. data->zone[i].critical =
  1360. lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
  1361. if (IS_ADT7468_OFF64(data)) {
  1362. data->temp_min[i] -= 64;
  1363. data->temp_max[i] -= 64;
  1364. data->zone[i].limit -= 64;
  1365. data->zone[i].critical -= 64;
  1366. }
  1367. }
  1368. if (data->type != emc6d103s) {
  1369. i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  1370. data->autofan[0].min_off = (i & 0x20) != 0;
  1371. data->autofan[1].min_off = (i & 0x40) != 0;
  1372. data->autofan[2].min_off = (i & 0x80) != 0;
  1373. i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
  1374. data->zone[0].hyst = i >> 4;
  1375. data->zone[1].hyst = i & 0x0f;
  1376. i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
  1377. data->zone[2].hyst = i >> 4;
  1378. }
  1379. data->last_config = jiffies;
  1380. } /* last_config */
  1381. data->valid = 1;
  1382. mutex_unlock(&data->update_lock);
  1383. return data;
  1384. }
  1385. static int __init sm_lm85_init(void)
  1386. {
  1387. return i2c_add_driver(&lm85_driver);
  1388. }
  1389. static void __exit sm_lm85_exit(void)
  1390. {
  1391. i2c_del_driver(&lm85_driver);
  1392. }
  1393. MODULE_LICENSE("GPL");
  1394. MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
  1395. "Margit Schubert-While <margitsw@t-online.de>, "
  1396. "Justin Thiessen <jthiessen@penguincomputing.com>");
  1397. MODULE_DESCRIPTION("LM85-B, LM85-C driver");
  1398. module_init(sm_lm85_init);
  1399. module_exit(sm_lm85_exit);