lm85.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  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. /* LM85 can automatically adjust fan speeds based on temperature
  254. * This structure encapsulates an entire Zone config. There are
  255. * three zones (one for each temperature input) on the lm85
  256. */
  257. struct lm85_zone {
  258. s8 limit; /* Low temp limit */
  259. u8 hyst; /* Low limit hysteresis. (0-15) */
  260. u8 range; /* Temp range, encoded */
  261. s8 critical; /* "All fans ON" temp limit */
  262. u8 off_desired; /* Actual "off" temperature specified. Preserved
  263. * to prevent "drift" as other autofan control
  264. * values change.
  265. */
  266. u8 max_desired; /* Actual "max" temperature specified. Preserved
  267. * to prevent "drift" as other autofan control
  268. * values change.
  269. */
  270. };
  271. struct lm85_autofan {
  272. u8 config; /* Register value */
  273. u8 freq; /* PWM frequency, encoded */
  274. u8 min_pwm; /* Minimum PWM value, encoded */
  275. u8 min_off; /* Min PWM or OFF below "limit", flag */
  276. };
  277. /* For each registered chip, we need to keep some data in memory.
  278. The structure is dynamically allocated. */
  279. struct lm85_data {
  280. struct i2c_client client;
  281. struct class_device *class_dev;
  282. enum chips type;
  283. struct mutex update_lock;
  284. int valid; /* !=0 if following fields are valid */
  285. unsigned long last_reading; /* In jiffies */
  286. unsigned long last_config; /* In jiffies */
  287. u8 in[8]; /* Register value */
  288. u8 in_max[8]; /* Register value */
  289. u8 in_min[8]; /* Register value */
  290. s8 temp[3]; /* Register value */
  291. s8 temp_min[3]; /* Register value */
  292. s8 temp_max[3]; /* Register value */
  293. s8 temp_offset[3]; /* Register value */
  294. u16 fan[4]; /* Register value */
  295. u16 fan_min[4]; /* Register value */
  296. u8 pwm[3]; /* Register value */
  297. u8 spinup_ctl; /* Register encoding, combined */
  298. u8 tach_mode; /* Register encoding, combined */
  299. u8 temp_ext[3]; /* Decoded values */
  300. u8 in_ext[8]; /* Decoded values */
  301. u8 adc_scale; /* ADC Extended bits scaling factor */
  302. u8 fan_ppr; /* Register value */
  303. u8 smooth[3]; /* Register encoding */
  304. u8 vid; /* Register value */
  305. u8 vrm; /* VRM version */
  306. u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */
  307. u8 oppoint[3]; /* Register value */
  308. u16 tmin_ctl; /* Register value */
  309. unsigned long therm_total; /* Cummulative therm count */
  310. u8 therm_limit; /* Register value */
  311. u32 alarms; /* Register encoding, combined */
  312. struct lm85_autofan autofan[3];
  313. struct lm85_zone zone[3];
  314. };
  315. static int lm85_attach_adapter(struct i2c_adapter *adapter);
  316. static int lm85_detect(struct i2c_adapter *adapter, int address,
  317. int kind);
  318. static int lm85_detach_client(struct i2c_client *client);
  319. static int lm85_read_value(struct i2c_client *client, u8 reg);
  320. static int lm85_write_value(struct i2c_client *client, u8 reg, int value);
  321. static struct lm85_data *lm85_update_device(struct device *dev);
  322. static void lm85_init_client(struct i2c_client *client);
  323. static struct i2c_driver lm85_driver = {
  324. .driver = {
  325. .name = "lm85",
  326. },
  327. .id = I2C_DRIVERID_LM85,
  328. .attach_adapter = lm85_attach_adapter,
  329. .detach_client = lm85_detach_client,
  330. };
  331. /* 4 Fans */
  332. static ssize_t show_fan(struct device *dev, char *buf, int nr)
  333. {
  334. struct lm85_data *data = lm85_update_device(dev);
  335. return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) );
  336. }
  337. static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
  338. {
  339. struct lm85_data *data = lm85_update_device(dev);
  340. return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) );
  341. }
  342. static ssize_t set_fan_min(struct device *dev, const char *buf,
  343. size_t count, int nr)
  344. {
  345. struct i2c_client *client = to_i2c_client(dev);
  346. struct lm85_data *data = i2c_get_clientdata(client);
  347. long val = simple_strtol(buf, NULL, 10);
  348. mutex_lock(&data->update_lock);
  349. data->fan_min[nr] = FAN_TO_REG(val);
  350. lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
  351. mutex_unlock(&data->update_lock);
  352. return count;
  353. }
  354. #define show_fan_offset(offset) \
  355. static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
  356. { \
  357. return show_fan(dev, buf, offset - 1); \
  358. } \
  359. static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
  360. { \
  361. return show_fan_min(dev, buf, offset - 1); \
  362. } \
  363. static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
  364. const char *buf, size_t count) \
  365. { \
  366. return set_fan_min(dev, buf, count, offset - 1); \
  367. } \
  368. static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
  369. NULL); \
  370. static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  371. show_fan_##offset##_min, set_fan_##offset##_min);
  372. show_fan_offset(1);
  373. show_fan_offset(2);
  374. show_fan_offset(3);
  375. show_fan_offset(4);
  376. /* vid, vrm, alarms */
  377. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
  378. {
  379. struct lm85_data *data = lm85_update_device(dev);
  380. int vid;
  381. if (data->type == adt7463 && (data->vid & 0x80)) {
  382. /* 6-pin VID (VRM 10) */
  383. vid = vid_from_reg(data->vid & 0x3f, data->vrm);
  384. } else {
  385. /* 5-pin VID (VRM 9) */
  386. vid = vid_from_reg(data->vid & 0x1f, data->vrm);
  387. }
  388. return sprintf(buf, "%d\n", vid);
  389. }
  390. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  391. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
  392. {
  393. struct lm85_data *data = lm85_update_device(dev);
  394. return sprintf(buf, "%ld\n", (long) data->vrm);
  395. }
  396. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  397. {
  398. struct i2c_client *client = to_i2c_client(dev);
  399. struct lm85_data *data = i2c_get_clientdata(client);
  400. u32 val;
  401. val = simple_strtoul(buf, NULL, 10);
  402. data->vrm = val;
  403. return count;
  404. }
  405. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  406. static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
  407. {
  408. struct lm85_data *data = lm85_update_device(dev);
  409. return sprintf(buf, "%u\n", data->alarms);
  410. }
  411. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
  412. /* pwm */
  413. static ssize_t show_pwm(struct device *dev, char *buf, int nr)
  414. {
  415. struct lm85_data *data = lm85_update_device(dev);
  416. return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) );
  417. }
  418. static ssize_t set_pwm(struct device *dev, const char *buf,
  419. size_t count, int nr)
  420. {
  421. struct i2c_client *client = to_i2c_client(dev);
  422. struct lm85_data *data = i2c_get_clientdata(client);
  423. long val = simple_strtol(buf, NULL, 10);
  424. mutex_lock(&data->update_lock);
  425. data->pwm[nr] = PWM_TO_REG(val);
  426. lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
  427. mutex_unlock(&data->update_lock);
  428. return count;
  429. }
  430. static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
  431. {
  432. struct lm85_data *data = lm85_update_device(dev);
  433. int pwm_zone;
  434. pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
  435. return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) );
  436. }
  437. #define show_pwm_reg(offset) \
  438. static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
  439. { \
  440. return show_pwm(dev, buf, offset - 1); \
  441. } \
  442. static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr, \
  443. const char *buf, size_t count) \
  444. { \
  445. return set_pwm(dev, buf, count, offset - 1); \
  446. } \
  447. static ssize_t show_pwm_enable##offset (struct device *dev, struct device_attribute *attr, char *buf) \
  448. { \
  449. return show_pwm_enable(dev, buf, offset - 1); \
  450. } \
  451. static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  452. show_pwm_##offset, set_pwm_##offset); \
  453. static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \
  454. show_pwm_enable##offset, NULL);
  455. show_pwm_reg(1);
  456. show_pwm_reg(2);
  457. show_pwm_reg(3);
  458. /* Voltages */
  459. static ssize_t show_in(struct device *dev, char *buf, int nr)
  460. {
  461. struct lm85_data *data = lm85_update_device(dev);
  462. return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr,
  463. data->in[nr],
  464. data->in_ext[nr],
  465. data->adc_scale) );
  466. }
  467. static ssize_t show_in_min(struct device *dev, char *buf, int nr)
  468. {
  469. struct lm85_data *data = lm85_update_device(dev);
  470. return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) );
  471. }
  472. static ssize_t set_in_min(struct device *dev, const char *buf,
  473. size_t count, int nr)
  474. {
  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, char *buf, int nr)
  485. {
  486. struct lm85_data *data = lm85_update_device(dev);
  487. return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) );
  488. }
  489. static ssize_t set_in_max(struct device *dev, const char *buf,
  490. size_t count, int nr)
  491. {
  492. struct i2c_client *client = to_i2c_client(dev);
  493. struct lm85_data *data = i2c_get_clientdata(client);
  494. long val = simple_strtol(buf, NULL, 10);
  495. mutex_lock(&data->update_lock);
  496. data->in_max[nr] = INS_TO_REG(nr, val);
  497. lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
  498. mutex_unlock(&data->update_lock);
  499. return count;
  500. }
  501. #define show_in_reg(offset) \
  502. static ssize_t show_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
  503. { \
  504. return show_in(dev, buf, offset); \
  505. } \
  506. static ssize_t show_in_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
  507. { \
  508. return show_in_min(dev, buf, offset); \
  509. } \
  510. static ssize_t show_in_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
  511. { \
  512. return show_in_max(dev, buf, offset); \
  513. } \
  514. static ssize_t set_in_##offset##_min (struct device *dev, struct device_attribute *attr, \
  515. const char *buf, size_t count) \
  516. { \
  517. return set_in_min(dev, buf, count, offset); \
  518. } \
  519. static ssize_t set_in_##offset##_max (struct device *dev, struct device_attribute *attr, \
  520. const char *buf, size_t count) \
  521. { \
  522. return set_in_max(dev, buf, count, offset); \
  523. } \
  524. static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in_##offset, \
  525. NULL); \
  526. static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
  527. show_in_##offset##_min, set_in_##offset##_min); \
  528. static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
  529. show_in_##offset##_max, set_in_##offset##_max);
  530. show_in_reg(0);
  531. show_in_reg(1);
  532. show_in_reg(2);
  533. show_in_reg(3);
  534. show_in_reg(4);
  535. /* Temps */
  536. static ssize_t show_temp(struct device *dev, char *buf, int nr)
  537. {
  538. struct lm85_data *data = lm85_update_device(dev);
  539. return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr],
  540. data->temp_ext[nr],
  541. data->adc_scale) );
  542. }
  543. static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
  544. {
  545. struct lm85_data *data = lm85_update_device(dev);
  546. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
  547. }
  548. static ssize_t set_temp_min(struct device *dev, const char *buf,
  549. size_t count, int nr)
  550. {
  551. struct i2c_client *client = to_i2c_client(dev);
  552. struct lm85_data *data = i2c_get_clientdata(client);
  553. long val = simple_strtol(buf, NULL, 10);
  554. mutex_lock(&data->update_lock);
  555. data->temp_min[nr] = TEMP_TO_REG(val);
  556. lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
  557. mutex_unlock(&data->update_lock);
  558. return count;
  559. }
  560. static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
  561. {
  562. struct lm85_data *data = lm85_update_device(dev);
  563. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
  564. }
  565. static ssize_t set_temp_max(struct device *dev, const char *buf,
  566. size_t count, int nr)
  567. {
  568. struct i2c_client *client = to_i2c_client(dev);
  569. struct lm85_data *data = i2c_get_clientdata(client);
  570. long val = simple_strtol(buf, NULL, 10);
  571. mutex_lock(&data->update_lock);
  572. data->temp_max[nr] = TEMP_TO_REG(val);
  573. lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
  574. mutex_unlock(&data->update_lock);
  575. return count;
  576. }
  577. #define show_temp_reg(offset) \
  578. static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
  579. { \
  580. return show_temp(dev, buf, offset - 1); \
  581. } \
  582. static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
  583. { \
  584. return show_temp_min(dev, buf, offset - 1); \
  585. } \
  586. static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
  587. { \
  588. return show_temp_max(dev, buf, offset - 1); \
  589. } \
  590. static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
  591. const char *buf, size_t count) \
  592. { \
  593. return set_temp_min(dev, buf, count, offset - 1); \
  594. } \
  595. static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
  596. const char *buf, size_t count) \
  597. { \
  598. return set_temp_max(dev, buf, count, offset - 1); \
  599. } \
  600. static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
  601. NULL); \
  602. static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
  603. show_temp_##offset##_min, set_temp_##offset##_min); \
  604. static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
  605. show_temp_##offset##_max, set_temp_##offset##_max);
  606. show_temp_reg(1);
  607. show_temp_reg(2);
  608. show_temp_reg(3);
  609. /* Automatic PWM control */
  610. static ssize_t show_pwm_auto_channels(struct device *dev, char *buf, int nr)
  611. {
  612. struct lm85_data *data = lm85_update_device(dev);
  613. return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config));
  614. }
  615. static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
  616. size_t count, int nr)
  617. {
  618. struct i2c_client *client = to_i2c_client(dev);
  619. struct lm85_data *data = i2c_get_clientdata(client);
  620. long val = simple_strtol(buf, NULL, 10);
  621. mutex_lock(&data->update_lock);
  622. data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
  623. | ZONE_TO_REG(val) ;
  624. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  625. data->autofan[nr].config);
  626. mutex_unlock(&data->update_lock);
  627. return count;
  628. }
  629. static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr)
  630. {
  631. struct lm85_data *data = lm85_update_device(dev);
  632. return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
  633. }
  634. static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
  635. size_t count, int nr)
  636. {
  637. struct i2c_client *client = to_i2c_client(dev);
  638. struct lm85_data *data = i2c_get_clientdata(client);
  639. long val = simple_strtol(buf, NULL, 10);
  640. mutex_lock(&data->update_lock);
  641. data->autofan[nr].min_pwm = PWM_TO_REG(val);
  642. lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
  643. data->autofan[nr].min_pwm);
  644. mutex_unlock(&data->update_lock);
  645. return count;
  646. }
  647. static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr)
  648. {
  649. struct lm85_data *data = lm85_update_device(dev);
  650. return sprintf(buf,"%d\n", data->autofan[nr].min_off);
  651. }
  652. static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
  653. size_t count, int nr)
  654. {
  655. struct i2c_client *client = to_i2c_client(dev);
  656. struct lm85_data *data = i2c_get_clientdata(client);
  657. long val = simple_strtol(buf, NULL, 10);
  658. mutex_lock(&data->update_lock);
  659. data->autofan[nr].min_off = val;
  660. lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0]
  661. | data->syncpwm3
  662. | (data->autofan[0].min_off ? 0x20 : 0)
  663. | (data->autofan[1].min_off ? 0x40 : 0)
  664. | (data->autofan[2].min_off ? 0x80 : 0)
  665. );
  666. mutex_unlock(&data->update_lock);
  667. return count;
  668. }
  669. static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr)
  670. {
  671. struct lm85_data *data = lm85_update_device(dev);
  672. return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
  673. }
  674. static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
  675. size_t count, int nr)
  676. {
  677. struct i2c_client *client = to_i2c_client(dev);
  678. struct lm85_data *data = i2c_get_clientdata(client);
  679. long val = simple_strtol(buf, NULL, 10);
  680. mutex_lock(&data->update_lock);
  681. data->autofan[nr].freq = FREQ_TO_REG(val);
  682. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  683. (data->zone[nr].range << 4)
  684. | data->autofan[nr].freq
  685. );
  686. mutex_unlock(&data->update_lock);
  687. return count;
  688. }
  689. #define pwm_auto(offset) \
  690. static ssize_t show_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \
  691. char *buf) \
  692. { \
  693. return show_pwm_auto_channels(dev, buf, offset - 1); \
  694. } \
  695. static ssize_t set_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \
  696. const char *buf, size_t count) \
  697. { \
  698. return set_pwm_auto_channels(dev, buf, count, offset - 1); \
  699. } \
  700. static ssize_t show_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \
  701. char *buf) \
  702. { \
  703. return show_pwm_auto_pwm_min(dev, buf, offset - 1); \
  704. } \
  705. static ssize_t set_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \
  706. const char *buf, size_t count) \
  707. { \
  708. return set_pwm_auto_pwm_min(dev, buf, count, offset - 1); \
  709. } \
  710. static ssize_t show_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
  711. char *buf) \
  712. { \
  713. return show_pwm_auto_pwm_minctl(dev, buf, offset - 1); \
  714. } \
  715. static ssize_t set_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
  716. const char *buf, size_t count) \
  717. { \
  718. return set_pwm_auto_pwm_minctl(dev, buf, count, offset - 1); \
  719. } \
  720. static ssize_t show_pwm##offset##_auto_pwm_freq (struct device *dev, struct device_attribute *attr, \
  721. char *buf) \
  722. { \
  723. return show_pwm_auto_pwm_freq(dev, buf, offset - 1); \
  724. } \
  725. static ssize_t set_pwm##offset##_auto_pwm_freq(struct device *dev, struct device_attribute *attr, \
  726. const char *buf, size_t count) \
  727. { \
  728. return set_pwm_auto_pwm_freq(dev, buf, count, offset - 1); \
  729. } \
  730. static DEVICE_ATTR(pwm##offset##_auto_channels, S_IRUGO | S_IWUSR, \
  731. show_pwm##offset##_auto_channels, \
  732. set_pwm##offset##_auto_channels); \
  733. static DEVICE_ATTR(pwm##offset##_auto_pwm_min, S_IRUGO | S_IWUSR, \
  734. show_pwm##offset##_auto_pwm_min, \
  735. set_pwm##offset##_auto_pwm_min); \
  736. static DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, S_IRUGO | S_IWUSR, \
  737. show_pwm##offset##_auto_pwm_minctl, \
  738. set_pwm##offset##_auto_pwm_minctl); \
  739. static DEVICE_ATTR(pwm##offset##_auto_pwm_freq, S_IRUGO | S_IWUSR, \
  740. show_pwm##offset##_auto_pwm_freq, \
  741. set_pwm##offset##_auto_pwm_freq);
  742. pwm_auto(1);
  743. pwm_auto(2);
  744. pwm_auto(3);
  745. /* Temperature settings for automatic PWM control */
  746. static ssize_t show_temp_auto_temp_off(struct device *dev, char *buf, int nr)
  747. {
  748. struct lm85_data *data = lm85_update_device(dev);
  749. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
  750. HYST_FROM_REG(data->zone[nr].hyst));
  751. }
  752. static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
  753. size_t count, int nr)
  754. {
  755. struct i2c_client *client = to_i2c_client(dev);
  756. struct lm85_data *data = i2c_get_clientdata(client);
  757. int min;
  758. long val = simple_strtol(buf, NULL, 10);
  759. mutex_lock(&data->update_lock);
  760. min = TEMP_FROM_REG(data->zone[nr].limit);
  761. data->zone[nr].off_desired = TEMP_TO_REG(val);
  762. data->zone[nr].hyst = HYST_TO_REG(min - val);
  763. if ( nr == 0 || nr == 1 ) {
  764. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  765. (data->zone[0].hyst << 4)
  766. | data->zone[1].hyst
  767. );
  768. } else {
  769. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  770. (data->zone[2].hyst << 4)
  771. );
  772. }
  773. mutex_unlock(&data->update_lock);
  774. return count;
  775. }
  776. static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr)
  777. {
  778. struct lm85_data *data = lm85_update_device(dev);
  779. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) );
  780. }
  781. static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
  782. size_t count, int nr)
  783. {
  784. struct i2c_client *client = to_i2c_client(dev);
  785. struct lm85_data *data = i2c_get_clientdata(client);
  786. long val = simple_strtol(buf, NULL, 10);
  787. mutex_lock(&data->update_lock);
  788. data->zone[nr].limit = TEMP_TO_REG(val);
  789. lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
  790. data->zone[nr].limit);
  791. /* Update temp_auto_max and temp_auto_range */
  792. data->zone[nr].range = RANGE_TO_REG(
  793. TEMP_FROM_REG(data->zone[nr].max_desired) -
  794. TEMP_FROM_REG(data->zone[nr].limit));
  795. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  796. ((data->zone[nr].range & 0x0f) << 4)
  797. | (data->autofan[nr].freq & 0x07));
  798. /* Update temp_auto_hyst and temp_auto_off */
  799. data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
  800. data->zone[nr].limit) - TEMP_FROM_REG(
  801. data->zone[nr].off_desired));
  802. if ( nr == 0 || nr == 1 ) {
  803. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  804. (data->zone[0].hyst << 4)
  805. | data->zone[1].hyst
  806. );
  807. } else {
  808. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  809. (data->zone[2].hyst << 4)
  810. );
  811. }
  812. mutex_unlock(&data->update_lock);
  813. return count;
  814. }
  815. static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr)
  816. {
  817. struct lm85_data *data = lm85_update_device(dev);
  818. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
  819. RANGE_FROM_REG(data->zone[nr].range));
  820. }
  821. static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
  822. size_t count, int nr)
  823. {
  824. struct i2c_client *client = to_i2c_client(dev);
  825. struct lm85_data *data = i2c_get_clientdata(client);
  826. int min;
  827. long val = simple_strtol(buf, NULL, 10);
  828. mutex_lock(&data->update_lock);
  829. min = TEMP_FROM_REG(data->zone[nr].limit);
  830. data->zone[nr].max_desired = TEMP_TO_REG(val);
  831. data->zone[nr].range = RANGE_TO_REG(
  832. val - min);
  833. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  834. ((data->zone[nr].range & 0x0f) << 4)
  835. | (data->autofan[nr].freq & 0x07));
  836. mutex_unlock(&data->update_lock);
  837. return count;
  838. }
  839. static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr)
  840. {
  841. struct lm85_data *data = lm85_update_device(dev);
  842. return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical));
  843. }
  844. static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
  845. size_t count, int nr)
  846. {
  847. struct i2c_client *client = to_i2c_client(dev);
  848. struct lm85_data *data = i2c_get_clientdata(client);
  849. long val = simple_strtol(buf, NULL, 10);
  850. mutex_lock(&data->update_lock);
  851. data->zone[nr].critical = TEMP_TO_REG(val);
  852. lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
  853. data->zone[nr].critical);
  854. mutex_unlock(&data->update_lock);
  855. return count;
  856. }
  857. #define temp_auto(offset) \
  858. static ssize_t show_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \
  859. char *buf) \
  860. { \
  861. return show_temp_auto_temp_off(dev, buf, offset - 1); \
  862. } \
  863. static ssize_t set_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \
  864. const char *buf, size_t count) \
  865. { \
  866. return set_temp_auto_temp_off(dev, buf, count, offset - 1); \
  867. } \
  868. static ssize_t show_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \
  869. char *buf) \
  870. { \
  871. return show_temp_auto_temp_min(dev, buf, offset - 1); \
  872. } \
  873. static ssize_t set_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \
  874. const char *buf, size_t count) \
  875. { \
  876. return set_temp_auto_temp_min(dev, buf, count, offset - 1); \
  877. } \
  878. static ssize_t show_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
  879. char *buf) \
  880. { \
  881. return show_temp_auto_temp_max(dev, buf, offset - 1); \
  882. } \
  883. static ssize_t set_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
  884. const char *buf, size_t count) \
  885. { \
  886. return set_temp_auto_temp_max(dev, buf, count, offset - 1); \
  887. } \
  888. static ssize_t show_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
  889. char *buf) \
  890. { \
  891. return show_temp_auto_temp_crit(dev, buf, offset - 1); \
  892. } \
  893. static ssize_t set_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
  894. const char *buf, size_t count) \
  895. { \
  896. return set_temp_auto_temp_crit(dev, buf, count, offset - 1); \
  897. } \
  898. static DEVICE_ATTR(temp##offset##_auto_temp_off, S_IRUGO | S_IWUSR, \
  899. show_temp##offset##_auto_temp_off, \
  900. set_temp##offset##_auto_temp_off); \
  901. static DEVICE_ATTR(temp##offset##_auto_temp_min, S_IRUGO | S_IWUSR, \
  902. show_temp##offset##_auto_temp_min, \
  903. set_temp##offset##_auto_temp_min); \
  904. static DEVICE_ATTR(temp##offset##_auto_temp_max, S_IRUGO | S_IWUSR, \
  905. show_temp##offset##_auto_temp_max, \
  906. set_temp##offset##_auto_temp_max); \
  907. static DEVICE_ATTR(temp##offset##_auto_temp_crit, S_IRUGO | S_IWUSR, \
  908. show_temp##offset##_auto_temp_crit, \
  909. set_temp##offset##_auto_temp_crit);
  910. temp_auto(1);
  911. temp_auto(2);
  912. temp_auto(3);
  913. static int lm85_attach_adapter(struct i2c_adapter *adapter)
  914. {
  915. if (!(adapter->class & I2C_CLASS_HWMON))
  916. return 0;
  917. return i2c_probe(adapter, &addr_data, lm85_detect);
  918. }
  919. static struct attribute *lm85_attributes[] = {
  920. &dev_attr_fan1_input.attr,
  921. &dev_attr_fan2_input.attr,
  922. &dev_attr_fan3_input.attr,
  923. &dev_attr_fan4_input.attr,
  924. &dev_attr_fan1_min.attr,
  925. &dev_attr_fan2_min.attr,
  926. &dev_attr_fan3_min.attr,
  927. &dev_attr_fan4_min.attr,
  928. &dev_attr_pwm1.attr,
  929. &dev_attr_pwm2.attr,
  930. &dev_attr_pwm3.attr,
  931. &dev_attr_pwm1_enable.attr,
  932. &dev_attr_pwm2_enable.attr,
  933. &dev_attr_pwm3_enable.attr,
  934. &dev_attr_in0_input.attr,
  935. &dev_attr_in1_input.attr,
  936. &dev_attr_in2_input.attr,
  937. &dev_attr_in3_input.attr,
  938. &dev_attr_in0_min.attr,
  939. &dev_attr_in1_min.attr,
  940. &dev_attr_in2_min.attr,
  941. &dev_attr_in3_min.attr,
  942. &dev_attr_in0_max.attr,
  943. &dev_attr_in1_max.attr,
  944. &dev_attr_in2_max.attr,
  945. &dev_attr_in3_max.attr,
  946. &dev_attr_temp1_input.attr,
  947. &dev_attr_temp2_input.attr,
  948. &dev_attr_temp3_input.attr,
  949. &dev_attr_temp1_min.attr,
  950. &dev_attr_temp2_min.attr,
  951. &dev_attr_temp3_min.attr,
  952. &dev_attr_temp1_max.attr,
  953. &dev_attr_temp2_max.attr,
  954. &dev_attr_temp3_max.attr,
  955. &dev_attr_vrm.attr,
  956. &dev_attr_cpu0_vid.attr,
  957. &dev_attr_alarms.attr,
  958. &dev_attr_pwm1_auto_channels.attr,
  959. &dev_attr_pwm2_auto_channels.attr,
  960. &dev_attr_pwm3_auto_channels.attr,
  961. &dev_attr_pwm1_auto_pwm_min.attr,
  962. &dev_attr_pwm2_auto_pwm_min.attr,
  963. &dev_attr_pwm3_auto_pwm_min.attr,
  964. &dev_attr_pwm1_auto_pwm_minctl.attr,
  965. &dev_attr_pwm2_auto_pwm_minctl.attr,
  966. &dev_attr_pwm3_auto_pwm_minctl.attr,
  967. &dev_attr_pwm1_auto_pwm_freq.attr,
  968. &dev_attr_pwm2_auto_pwm_freq.attr,
  969. &dev_attr_pwm3_auto_pwm_freq.attr,
  970. &dev_attr_temp1_auto_temp_off.attr,
  971. &dev_attr_temp2_auto_temp_off.attr,
  972. &dev_attr_temp3_auto_temp_off.attr,
  973. &dev_attr_temp1_auto_temp_min.attr,
  974. &dev_attr_temp2_auto_temp_min.attr,
  975. &dev_attr_temp3_auto_temp_min.attr,
  976. &dev_attr_temp1_auto_temp_max.attr,
  977. &dev_attr_temp2_auto_temp_max.attr,
  978. &dev_attr_temp3_auto_temp_max.attr,
  979. &dev_attr_temp1_auto_temp_crit.attr,
  980. &dev_attr_temp2_auto_temp_crit.attr,
  981. &dev_attr_temp3_auto_temp_crit.attr,
  982. NULL
  983. };
  984. static const struct attribute_group lm85_group = {
  985. .attrs = lm85_attributes,
  986. };
  987. static struct attribute *lm85_attributes_opt[] = {
  988. &dev_attr_in4_input.attr,
  989. &dev_attr_in4_min.attr,
  990. &dev_attr_in4_max.attr,
  991. NULL
  992. };
  993. static const struct attribute_group lm85_group_opt = {
  994. .attrs = lm85_attributes_opt,
  995. };
  996. static int lm85_detect(struct i2c_adapter *adapter, int address,
  997. int kind)
  998. {
  999. int company, verstep ;
  1000. struct i2c_client *new_client = NULL;
  1001. struct lm85_data *data;
  1002. int err = 0;
  1003. const char *type_name = "";
  1004. if (!i2c_check_functionality(adapter,
  1005. I2C_FUNC_SMBUS_BYTE_DATA)) {
  1006. /* We need to be able to do byte I/O */
  1007. goto ERROR0 ;
  1008. };
  1009. /* OK. For now, we presume we have a valid client. We now create the
  1010. client structure, even though we cannot fill it completely yet.
  1011. But it allows us to access lm85_{read,write}_value. */
  1012. if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
  1013. err = -ENOMEM;
  1014. goto ERROR0;
  1015. }
  1016. new_client = &data->client;
  1017. i2c_set_clientdata(new_client, data);
  1018. new_client->addr = address;
  1019. new_client->adapter = adapter;
  1020. new_client->driver = &lm85_driver;
  1021. new_client->flags = 0;
  1022. /* Now, we do the remaining detection. */
  1023. company = lm85_read_value(new_client, LM85_REG_COMPANY);
  1024. verstep = lm85_read_value(new_client, LM85_REG_VERSTEP);
  1025. dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
  1026. " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
  1027. i2c_adapter_id(new_client->adapter), new_client->addr,
  1028. company, verstep);
  1029. /* If auto-detecting, Determine the chip type. */
  1030. if (kind <= 0) {
  1031. dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n",
  1032. i2c_adapter_id(adapter), address );
  1033. if( company == LM85_COMPANY_NATIONAL
  1034. && verstep == LM85_VERSTEP_LM85C ) {
  1035. kind = lm85c ;
  1036. } else if( company == LM85_COMPANY_NATIONAL
  1037. && verstep == LM85_VERSTEP_LM85B ) {
  1038. kind = lm85b ;
  1039. } else if( company == LM85_COMPANY_NATIONAL
  1040. && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
  1041. dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
  1042. " Defaulting to LM85.\n", verstep);
  1043. kind = any_chip ;
  1044. } else if( company == LM85_COMPANY_ANALOG_DEV
  1045. && verstep == LM85_VERSTEP_ADM1027 ) {
  1046. kind = adm1027 ;
  1047. } else if( company == LM85_COMPANY_ANALOG_DEV
  1048. && (verstep == LM85_VERSTEP_ADT7463
  1049. || verstep == LM85_VERSTEP_ADT7463C) ) {
  1050. kind = adt7463 ;
  1051. } else if( company == LM85_COMPANY_ANALOG_DEV
  1052. && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
  1053. dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
  1054. " Defaulting to Generic LM85.\n", verstep );
  1055. kind = any_chip ;
  1056. } else if( company == LM85_COMPANY_SMSC
  1057. && (verstep == LM85_VERSTEP_EMC6D100_A0
  1058. || verstep == LM85_VERSTEP_EMC6D100_A1) ) {
  1059. /* Unfortunately, we can't tell a '100 from a '101
  1060. * from the registers. Since a '101 is a '100
  1061. * in a package with fewer pins and therefore no
  1062. * 3.3V, 1.5V or 1.8V inputs, perhaps if those
  1063. * inputs read 0, then it's a '101.
  1064. */
  1065. kind = emc6d100 ;
  1066. } else if( company == LM85_COMPANY_SMSC
  1067. && verstep == LM85_VERSTEP_EMC6D102) {
  1068. kind = emc6d102 ;
  1069. } else if( company == LM85_COMPANY_SMSC
  1070. && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
  1071. dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
  1072. dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
  1073. " Defaulting to Generic LM85.\n", verstep );
  1074. kind = any_chip ;
  1075. } else if( kind == any_chip
  1076. && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
  1077. dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
  1078. /* Leave kind as "any_chip" */
  1079. } else {
  1080. dev_dbg(&adapter->dev, "Autodetection failed\n");
  1081. /* Not an LM85 ... */
  1082. if( kind == any_chip ) { /* User used force=x,y */
  1083. dev_err(&adapter->dev, "Generic LM85 Version 6 not"
  1084. " found at %d,0x%02x. Try force_lm85c.\n",
  1085. i2c_adapter_id(adapter), address );
  1086. }
  1087. err = 0 ;
  1088. goto ERROR1;
  1089. }
  1090. }
  1091. /* Fill in the chip specific driver values */
  1092. if ( kind == any_chip ) {
  1093. type_name = "lm85";
  1094. } else if ( kind == lm85b ) {
  1095. type_name = "lm85b";
  1096. } else if ( kind == lm85c ) {
  1097. type_name = "lm85c";
  1098. } else if ( kind == adm1027 ) {
  1099. type_name = "adm1027";
  1100. } else if ( kind == adt7463 ) {
  1101. type_name = "adt7463";
  1102. } else if ( kind == emc6d100){
  1103. type_name = "emc6d100";
  1104. } else if ( kind == emc6d102 ) {
  1105. type_name = "emc6d102";
  1106. }
  1107. strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
  1108. /* Fill in the remaining client fields */
  1109. data->type = kind;
  1110. data->valid = 0;
  1111. mutex_init(&data->update_lock);
  1112. /* Tell the I2C layer a new client has arrived */
  1113. if ((err = i2c_attach_client(new_client)))
  1114. goto ERROR1;
  1115. /* Set the VRM version */
  1116. data->vrm = vid_which_vrm();
  1117. /* Initialize the LM85 chip */
  1118. lm85_init_client(new_client);
  1119. /* Register sysfs hooks */
  1120. if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group)))
  1121. goto ERROR2;
  1122. /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
  1123. as a sixth digital VID input rather than an analog input. */
  1124. data->vid = lm85_read_value(new_client, LM85_REG_VID);
  1125. if (!(kind == adt7463 && (data->vid & 0x80)))
  1126. if ((err = device_create_file(&new_client->dev,
  1127. &dev_attr_in4_input))
  1128. || (err = device_create_file(&new_client->dev,
  1129. &dev_attr_in4_min))
  1130. || (err = device_create_file(&new_client->dev,
  1131. &dev_attr_in4_max)))
  1132. goto ERROR3;
  1133. data->class_dev = hwmon_device_register(&new_client->dev);
  1134. if (IS_ERR(data->class_dev)) {
  1135. err = PTR_ERR(data->class_dev);
  1136. goto ERROR3;
  1137. }
  1138. return 0;
  1139. /* Error out and cleanup code */
  1140. ERROR3:
  1141. sysfs_remove_group(&new_client->dev.kobj, &lm85_group);
  1142. sysfs_remove_group(&new_client->dev.kobj, &lm85_group_opt);
  1143. ERROR2:
  1144. i2c_detach_client(new_client);
  1145. ERROR1:
  1146. kfree(data);
  1147. ERROR0:
  1148. return err;
  1149. }
  1150. static int lm85_detach_client(struct i2c_client *client)
  1151. {
  1152. struct lm85_data *data = i2c_get_clientdata(client);
  1153. hwmon_device_unregister(data->class_dev);
  1154. sysfs_remove_group(&client->dev.kobj, &lm85_group);
  1155. sysfs_remove_group(&client->dev.kobj, &lm85_group_opt);
  1156. i2c_detach_client(client);
  1157. kfree(data);
  1158. return 0;
  1159. }
  1160. static int lm85_read_value(struct i2c_client *client, u8 reg)
  1161. {
  1162. int res;
  1163. /* What size location is it? */
  1164. switch( reg ) {
  1165. case LM85_REG_FAN(0) : /* Read WORD data */
  1166. case LM85_REG_FAN(1) :
  1167. case LM85_REG_FAN(2) :
  1168. case LM85_REG_FAN(3) :
  1169. case LM85_REG_FAN_MIN(0) :
  1170. case LM85_REG_FAN_MIN(1) :
  1171. case LM85_REG_FAN_MIN(2) :
  1172. case LM85_REG_FAN_MIN(3) :
  1173. case LM85_REG_ALARM1 : /* Read both bytes at once */
  1174. res = i2c_smbus_read_byte_data(client, reg) & 0xff ;
  1175. res |= i2c_smbus_read_byte_data(client, reg+1) << 8 ;
  1176. break ;
  1177. case ADT7463_REG_TMIN_CTL1 : /* Read WORD MSB, LSB */
  1178. res = i2c_smbus_read_byte_data(client, reg) << 8 ;
  1179. res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ;
  1180. break ;
  1181. default: /* Read BYTE data */
  1182. res = i2c_smbus_read_byte_data(client, reg);
  1183. break ;
  1184. }
  1185. return res ;
  1186. }
  1187. static int lm85_write_value(struct i2c_client *client, u8 reg, int value)
  1188. {
  1189. int res ;
  1190. switch( reg ) {
  1191. case LM85_REG_FAN(0) : /* Write WORD data */
  1192. case LM85_REG_FAN(1) :
  1193. case LM85_REG_FAN(2) :
  1194. case LM85_REG_FAN(3) :
  1195. case LM85_REG_FAN_MIN(0) :
  1196. case LM85_REG_FAN_MIN(1) :
  1197. case LM85_REG_FAN_MIN(2) :
  1198. case LM85_REG_FAN_MIN(3) :
  1199. /* NOTE: ALARM is read only, so not included here */
  1200. res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ;
  1201. res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ;
  1202. break ;
  1203. case ADT7463_REG_TMIN_CTL1 : /* Write WORD MSB, LSB */
  1204. res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff);
  1205. res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ;
  1206. break ;
  1207. default: /* Write BYTE data */
  1208. res = i2c_smbus_write_byte_data(client, reg, value);
  1209. break ;
  1210. }
  1211. return res ;
  1212. }
  1213. static void lm85_init_client(struct i2c_client *client)
  1214. {
  1215. int value;
  1216. struct lm85_data *data = i2c_get_clientdata(client);
  1217. dev_dbg(&client->dev, "Initializing device\n");
  1218. /* Warn if part was not "READY" */
  1219. value = lm85_read_value(client, LM85_REG_CONFIG);
  1220. dev_dbg(&client->dev, "LM85_REG_CONFIG is: 0x%02x\n", value);
  1221. if( value & 0x02 ) {
  1222. dev_err(&client->dev, "Client (%d,0x%02x) config is locked.\n",
  1223. i2c_adapter_id(client->adapter), client->addr );
  1224. };
  1225. if( ! (value & 0x04) ) {
  1226. dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n",
  1227. i2c_adapter_id(client->adapter), client->addr );
  1228. };
  1229. if( value & 0x10
  1230. && ( data->type == adm1027
  1231. || data->type == adt7463 ) ) {
  1232. dev_err(&client->dev, "Client (%d,0x%02x) VxI mode is set. "
  1233. "Please report this to the lm85 maintainer.\n",
  1234. i2c_adapter_id(client->adapter), client->addr );
  1235. };
  1236. /* WE INTENTIONALLY make no changes to the limits,
  1237. * offsets, pwms, fans and zones. If they were
  1238. * configured, we don't want to mess with them.
  1239. * If they weren't, the default is 100% PWM, no
  1240. * control and will suffice until 'sensors -s'
  1241. * can be run by the user.
  1242. */
  1243. /* Start monitoring */
  1244. value = lm85_read_value(client, LM85_REG_CONFIG);
  1245. /* Try to clear LOCK, Set START, save everything else */
  1246. value = (value & ~ 0x02) | 0x01 ;
  1247. dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
  1248. lm85_write_value(client, LM85_REG_CONFIG, value);
  1249. }
  1250. static struct lm85_data *lm85_update_device(struct device *dev)
  1251. {
  1252. struct i2c_client *client = to_i2c_client(dev);
  1253. struct lm85_data *data = i2c_get_clientdata(client);
  1254. int i;
  1255. mutex_lock(&data->update_lock);
  1256. if ( !data->valid ||
  1257. time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) {
  1258. /* Things that change quickly */
  1259. dev_dbg(&client->dev, "Reading sensor values\n");
  1260. /* Have to read extended bits first to "freeze" the
  1261. * more significant bits that are read later.
  1262. */
  1263. if ( (data->type == adm1027) || (data->type == adt7463) ) {
  1264. int ext1 = lm85_read_value(client,
  1265. ADM1027_REG_EXTEND_ADC1);
  1266. int ext2 = lm85_read_value(client,
  1267. ADM1027_REG_EXTEND_ADC2);
  1268. int val = (ext1 << 8) + ext2;
  1269. for(i = 0; i <= 4; i++)
  1270. data->in_ext[i] = (val>>(i * 2))&0x03;
  1271. for(i = 0; i <= 2; i++)
  1272. data->temp_ext[i] = (val>>((i + 5) * 2))&0x03;
  1273. }
  1274. /* adc_scale is 2^(number of LSBs). There are 4 extra bits in
  1275. the emc6d102 and 2 in the adt7463 and adm1027. In all
  1276. other chips ext is always 0 and the value of scale is
  1277. irrelevant. So it is left in 4*/
  1278. data->adc_scale = (data->type == emc6d102 ) ? 16 : 4;
  1279. data->vid = lm85_read_value(client, LM85_REG_VID);
  1280. for (i = 0; i <= 3; ++i) {
  1281. data->in[i] =
  1282. lm85_read_value(client, LM85_REG_IN(i));
  1283. }
  1284. if (!(data->type == adt7463 && (data->vid & 0x80))) {
  1285. data->in[4] = lm85_read_value(client,
  1286. LM85_REG_IN(4));
  1287. }
  1288. for (i = 0; i <= 3; ++i) {
  1289. data->fan[i] =
  1290. lm85_read_value(client, LM85_REG_FAN(i));
  1291. }
  1292. for (i = 0; i <= 2; ++i) {
  1293. data->temp[i] =
  1294. lm85_read_value(client, LM85_REG_TEMP(i));
  1295. }
  1296. for (i = 0; i <= 2; ++i) {
  1297. data->pwm[i] =
  1298. lm85_read_value(client, LM85_REG_PWM(i));
  1299. }
  1300. data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
  1301. if ( data->type == adt7463 ) {
  1302. if( data->therm_total < ULONG_MAX - 256 ) {
  1303. data->therm_total +=
  1304. lm85_read_value(client, ADT7463_REG_THERM );
  1305. }
  1306. } else if ( data->type == emc6d100 ) {
  1307. /* Three more voltage sensors */
  1308. for (i = 5; i <= 7; ++i) {
  1309. data->in[i] =
  1310. lm85_read_value(client, EMC6D100_REG_IN(i));
  1311. }
  1312. /* More alarm bits */
  1313. data->alarms |=
  1314. lm85_read_value(client, EMC6D100_REG_ALARM3) << 16;
  1315. } else if (data->type == emc6d102 ) {
  1316. /* Have to read LSB bits after the MSB ones because
  1317. the reading of the MSB bits has frozen the
  1318. LSBs (backward from the ADM1027).
  1319. */
  1320. int ext1 = lm85_read_value(client,
  1321. EMC6D102_REG_EXTEND_ADC1);
  1322. int ext2 = lm85_read_value(client,
  1323. EMC6D102_REG_EXTEND_ADC2);
  1324. int ext3 = lm85_read_value(client,
  1325. EMC6D102_REG_EXTEND_ADC3);
  1326. int ext4 = lm85_read_value(client,
  1327. EMC6D102_REG_EXTEND_ADC4);
  1328. data->in_ext[0] = ext3 & 0x0f;
  1329. data->in_ext[1] = ext4 & 0x0f;
  1330. data->in_ext[2] = (ext4 >> 4) & 0x0f;
  1331. data->in_ext[3] = (ext3 >> 4) & 0x0f;
  1332. data->in_ext[4] = (ext2 >> 4) & 0x0f;
  1333. data->temp_ext[0] = ext1 & 0x0f;
  1334. data->temp_ext[1] = ext2 & 0x0f;
  1335. data->temp_ext[2] = (ext1 >> 4) & 0x0f;
  1336. }
  1337. data->last_reading = jiffies ;
  1338. }; /* last_reading */
  1339. if ( !data->valid ||
  1340. time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL) ) {
  1341. /* Things that don't change often */
  1342. dev_dbg(&client->dev, "Reading config values\n");
  1343. for (i = 0; i <= 3; ++i) {
  1344. data->in_min[i] =
  1345. lm85_read_value(client, LM85_REG_IN_MIN(i));
  1346. data->in_max[i] =
  1347. lm85_read_value(client, LM85_REG_IN_MAX(i));
  1348. }
  1349. if (!(data->type == adt7463 && (data->vid & 0x80))) {
  1350. data->in_min[4] = lm85_read_value(client,
  1351. LM85_REG_IN_MIN(4));
  1352. data->in_max[4] = lm85_read_value(client,
  1353. LM85_REG_IN_MAX(4));
  1354. }
  1355. if ( data->type == emc6d100 ) {
  1356. for (i = 5; i <= 7; ++i) {
  1357. data->in_min[i] =
  1358. lm85_read_value(client, EMC6D100_REG_IN_MIN(i));
  1359. data->in_max[i] =
  1360. lm85_read_value(client, EMC6D100_REG_IN_MAX(i));
  1361. }
  1362. }
  1363. for (i = 0; i <= 3; ++i) {
  1364. data->fan_min[i] =
  1365. lm85_read_value(client, LM85_REG_FAN_MIN(i));
  1366. }
  1367. for (i = 0; i <= 2; ++i) {
  1368. data->temp_min[i] =
  1369. lm85_read_value(client, LM85_REG_TEMP_MIN(i));
  1370. data->temp_max[i] =
  1371. lm85_read_value(client, LM85_REG_TEMP_MAX(i));
  1372. }
  1373. for (i = 0; i <= 2; ++i) {
  1374. int val ;
  1375. data->autofan[i].config =
  1376. lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
  1377. val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
  1378. data->autofan[i].freq = val & 0x07 ;
  1379. data->zone[i].range = (val >> 4) & 0x0f ;
  1380. data->autofan[i].min_pwm =
  1381. lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
  1382. data->zone[i].limit =
  1383. lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
  1384. data->zone[i].critical =
  1385. lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
  1386. }
  1387. i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  1388. data->smooth[0] = i & 0x0f ;
  1389. data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */
  1390. data->autofan[0].min_off = (i & 0x20) != 0 ;
  1391. data->autofan[1].min_off = (i & 0x40) != 0 ;
  1392. data->autofan[2].min_off = (i & 0x80) != 0 ;
  1393. i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2);
  1394. data->smooth[1] = (i>>4) & 0x0f ;
  1395. data->smooth[2] = i & 0x0f ;
  1396. i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
  1397. data->zone[0].hyst = (i>>4) & 0x0f ;
  1398. data->zone[1].hyst = i & 0x0f ;
  1399. i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
  1400. data->zone[2].hyst = (i>>4) & 0x0f ;
  1401. if ( (data->type == lm85b) || (data->type == lm85c) ) {
  1402. data->tach_mode = lm85_read_value(client,
  1403. LM85_REG_TACH_MODE );
  1404. data->spinup_ctl = lm85_read_value(client,
  1405. LM85_REG_SPINUP_CTL );
  1406. } else if ( (data->type == adt7463) || (data->type == adm1027) ) {
  1407. if ( data->type == adt7463 ) {
  1408. for (i = 0; i <= 2; ++i) {
  1409. data->oppoint[i] = lm85_read_value(client,
  1410. ADT7463_REG_OPPOINT(i) );
  1411. }
  1412. data->tmin_ctl = lm85_read_value(client,
  1413. ADT7463_REG_TMIN_CTL1 );
  1414. data->therm_limit = lm85_read_value(client,
  1415. ADT7463_REG_THERM_LIMIT );
  1416. }
  1417. for (i = 0; i <= 2; ++i) {
  1418. data->temp_offset[i] = lm85_read_value(client,
  1419. ADM1027_REG_TEMP_OFFSET(i) );
  1420. }
  1421. data->tach_mode = lm85_read_value(client,
  1422. ADM1027_REG_CONFIG3 );
  1423. data->fan_ppr = lm85_read_value(client,
  1424. ADM1027_REG_FAN_PPR );
  1425. }
  1426. data->last_config = jiffies;
  1427. }; /* last_config */
  1428. data->valid = 1;
  1429. mutex_unlock(&data->update_lock);
  1430. return data;
  1431. }
  1432. static int __init sm_lm85_init(void)
  1433. {
  1434. return i2c_add_driver(&lm85_driver);
  1435. }
  1436. static void __exit sm_lm85_exit(void)
  1437. {
  1438. i2c_del_driver(&lm85_driver);
  1439. }
  1440. /* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
  1441. * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
  1442. * post 2.7.0 CVS changes.
  1443. */
  1444. MODULE_LICENSE("GPL");
  1445. MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com");
  1446. MODULE_DESCRIPTION("LM85-B, LM85-C driver");
  1447. module_init(sm_lm85_init);
  1448. module_exit(sm_lm85_exit);