lm85.c 49 KB

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