lm85.c 52 KB

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