lm85.c 48 KB

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