lm85.c 49 KB

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