lm85.c 52 KB

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