lm85.c 53 KB

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