lm85.c 48 KB

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