lm85.c 51 KB

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