lm85.c 47 KB

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