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. enum chips {
  35. any_chip, lm85b, lm85c,
  36. adm1027, adt7463, adt7468,
  37. emc6d100, emc6d102
  38. };
  39. /* The LM85 registers */
  40. #define LM85_REG_IN(nr) (0x20 + (nr))
  41. #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
  42. #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
  43. #define LM85_REG_TEMP(nr) (0x25 + (nr))
  44. #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
  45. #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
  46. /* Fan speeds are LSB, MSB (2 bytes) */
  47. #define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
  48. #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
  49. #define LM85_REG_PWM(nr) (0x30 + (nr))
  50. #define LM85_REG_COMPANY 0x3e
  51. #define LM85_REG_VERSTEP 0x3f
  52. #define ADT7468_REG_CFG5 0x7c
  53. #define ADT7468_OFF64 0x01
  54. #define IS_ADT7468_OFF64(data) \
  55. ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
  56. /* These are the recognized values for the above regs */
  57. #define LM85_COMPANY_NATIONAL 0x01
  58. #define LM85_COMPANY_ANALOG_DEV 0x41
  59. #define LM85_COMPANY_SMSC 0x5c
  60. #define LM85_VERSTEP_VMASK 0xf0
  61. #define LM85_VERSTEP_GENERIC 0x60
  62. #define LM85_VERSTEP_GENERIC2 0x70
  63. #define LM85_VERSTEP_LM85C 0x60
  64. #define LM85_VERSTEP_LM85B 0x62
  65. #define LM85_VERSTEP_LM96000_1 0x68
  66. #define LM85_VERSTEP_LM96000_2 0x69
  67. #define LM85_VERSTEP_ADM1027 0x60
  68. #define LM85_VERSTEP_ADT7463 0x62
  69. #define LM85_VERSTEP_ADT7463C 0x6A
  70. #define LM85_VERSTEP_ADT7468_1 0x71
  71. #define LM85_VERSTEP_ADT7468_2 0x72
  72. #define LM85_VERSTEP_EMC6D100_A0 0x60
  73. #define LM85_VERSTEP_EMC6D100_A1 0x61
  74. #define LM85_VERSTEP_EMC6D102 0x65
  75. #define LM85_REG_CONFIG 0x40
  76. #define LM85_REG_ALARM1 0x41
  77. #define LM85_REG_ALARM2 0x42
  78. #define LM85_REG_VID 0x43
  79. /* Automated FAN control */
  80. #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
  81. #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
  82. #define LM85_REG_AFAN_SPIKE1 0x62
  83. #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
  84. #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
  85. #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
  86. #define LM85_REG_AFAN_HYST1 0x6d
  87. #define LM85_REG_AFAN_HYST2 0x6e
  88. #define ADM1027_REG_EXTEND_ADC1 0x76
  89. #define ADM1027_REG_EXTEND_ADC2 0x77
  90. #define EMC6D100_REG_ALARM3 0x7d
  91. /* IN5, IN6 and IN7 */
  92. #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
  93. #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
  94. #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
  95. #define EMC6D102_REG_EXTEND_ADC1 0x85
  96. #define EMC6D102_REG_EXTEND_ADC2 0x86
  97. #define EMC6D102_REG_EXTEND_ADC3 0x87
  98. #define EMC6D102_REG_EXTEND_ADC4 0x88
  99. /* Conversions. Rounding and limit checking is only done on the TO_REG
  100. variants. Note that you should be a bit careful with which arguments
  101. these macros are called: arguments may be evaluated more than once.
  102. */
  103. /* IN are scaled acording to built-in resistors */
  104. static const int lm85_scaling[] = { /* .001 Volts */
  105. 2500, 2250, 3300, 5000, 12000,
  106. 3300, 1500, 1800 /*EMC6D100*/
  107. };
  108. #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
  109. #define INS_TO_REG(n, val) \
  110. SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
  111. #define INSEXT_FROM_REG(n, val, ext) \
  112. SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
  113. #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
  114. /* FAN speed is measured using 90kHz clock */
  115. static inline u16 FAN_TO_REG(unsigned long val)
  116. {
  117. if (!val)
  118. return 0xffff;
  119. return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
  120. }
  121. #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
  122. 5400000 / (val))
  123. /* Temperature is reported in .001 degC increments */
  124. #define TEMP_TO_REG(val) \
  125. SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
  126. #define TEMPEXT_FROM_REG(val, ext) \
  127. SCALE(((val) << 4) + (ext), 16, 1000)
  128. #define TEMP_FROM_REG(val) ((val) * 1000)
  129. #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
  130. #define PWM_FROM_REG(val) (val)
  131. /* ZONEs have the following parameters:
  132. * Limit (low) temp, 1. degC
  133. * Hysteresis (below limit), 1. degC (0-15)
  134. * Range of speed control, .1 degC (2-80)
  135. * Critical (high) temp, 1. degC
  136. *
  137. * FAN PWMs have the following parameters:
  138. * Reference Zone, 1, 2, 3, etc.
  139. * Spinup time, .05 sec
  140. * PWM value at limit/low temp, 1 count
  141. * PWM Frequency, 1. Hz
  142. * PWM is Min or OFF below limit, flag
  143. * Invert PWM output, flag
  144. *
  145. * Some chips filter the temp, others the fan.
  146. * Filter constant (or disabled) .1 seconds
  147. */
  148. /* These are the zone temperature range encodings in .001 degree C */
  149. static const int lm85_range_map[] = {
  150. 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
  151. 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
  152. };
  153. static int RANGE_TO_REG(int range)
  154. {
  155. int i;
  156. /* Find the closest match */
  157. for (i = 0; i < 15; ++i) {
  158. if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
  159. break;
  160. }
  161. return i;
  162. }
  163. #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
  164. /* These are the PWM frequency encodings */
  165. static const int lm85_freq_map[8] = { /* 1 Hz */
  166. 10, 15, 23, 30, 38, 47, 61, 94
  167. };
  168. static const int adm1027_freq_map[8] = { /* 1 Hz */
  169. 11, 15, 22, 29, 35, 44, 59, 88
  170. };
  171. static int FREQ_TO_REG(const int *map, int freq)
  172. {
  173. int i;
  174. /* Find the closest match */
  175. for (i = 0; i < 7; ++i)
  176. if (freq <= (map[i] + map[i + 1]) / 2)
  177. break;
  178. return i;
  179. }
  180. static int FREQ_FROM_REG(const int *map, u8 reg)
  181. {
  182. return map[reg & 0x07];
  183. }
  184. /* Since we can't use strings, I'm abusing these numbers
  185. * to stand in for the following meanings:
  186. * 1 -- PWM responds to Zone 1
  187. * 2 -- PWM responds to Zone 2
  188. * 3 -- PWM responds to Zone 3
  189. * 23 -- PWM responds to the higher temp of Zone 2 or 3
  190. * 123 -- PWM responds to highest of Zone 1, 2, or 3
  191. * 0 -- PWM is always at 0% (ie, off)
  192. * -1 -- PWM is always at 100%
  193. * -2 -- PWM responds to manual control
  194. */
  195. static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
  196. #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
  197. static int ZONE_TO_REG(int zone)
  198. {
  199. int i;
  200. for (i = 0; i <= 7; ++i)
  201. if (zone == lm85_zone_map[i])
  202. break;
  203. if (i > 7) /* Not found. */
  204. i = 3; /* Always 100% */
  205. return i << 5;
  206. }
  207. #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
  208. #define HYST_FROM_REG(val) ((val) * 1000)
  209. /* Chip sampling rates
  210. *
  211. * Some sensors are not updated more frequently than once per second
  212. * so it doesn't make sense to read them more often than that.
  213. * We cache the results and return the saved data if the driver
  214. * is called again before a second has elapsed.
  215. *
  216. * Also, there is significant configuration data for this chip
  217. * given the automatic PWM fan control that is possible. There
  218. * are about 47 bytes of config data to only 22 bytes of actual
  219. * readings. So, we keep the config data up to date in the cache
  220. * when it is written and only sample it once every 1 *minute*
  221. */
  222. #define LM85_DATA_INTERVAL (HZ + HZ / 2)
  223. #define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
  224. /* LM85 can automatically adjust fan speeds based on temperature
  225. * This structure encapsulates an entire Zone config. There are
  226. * three zones (one for each temperature input) on the lm85
  227. */
  228. struct lm85_zone {
  229. s8 limit; /* Low temp limit */
  230. u8 hyst; /* Low limit hysteresis. (0-15) */
  231. u8 range; /* Temp range, encoded */
  232. s8 critical; /* "All fans ON" temp limit */
  233. u8 off_desired; /* Actual "off" temperature specified. Preserved
  234. * to prevent "drift" as other autofan control
  235. * values change.
  236. */
  237. u8 max_desired; /* Actual "max" temperature specified. Preserved
  238. * to prevent "drift" as other autofan control
  239. * values change.
  240. */
  241. };
  242. struct lm85_autofan {
  243. u8 config; /* Register value */
  244. u8 min_pwm; /* Minimum PWM value, encoded */
  245. u8 min_off; /* Min PWM or OFF below "limit", flag */
  246. };
  247. /* For each registered chip, we need to keep some data in memory.
  248. The structure is dynamically allocated. */
  249. struct lm85_data {
  250. struct device *hwmon_dev;
  251. const int *freq_map;
  252. enum chips type;
  253. struct mutex update_lock;
  254. int valid; /* !=0 if following fields are valid */
  255. unsigned long last_reading; /* In jiffies */
  256. unsigned long last_config; /* In jiffies */
  257. u8 in[8]; /* Register value */
  258. u8 in_max[8]; /* Register value */
  259. u8 in_min[8]; /* Register value */
  260. s8 temp[3]; /* Register value */
  261. s8 temp_min[3]; /* Register value */
  262. s8 temp_max[3]; /* Register value */
  263. u16 fan[4]; /* Register value */
  264. u16 fan_min[4]; /* Register value */
  265. u8 pwm[3]; /* Register value */
  266. u8 pwm_freq[3]; /* Register encoding */
  267. u8 temp_ext[3]; /* Decoded values */
  268. u8 in_ext[8]; /* Decoded values */
  269. u8 vid; /* Register value */
  270. u8 vrm; /* VRM version */
  271. u32 alarms; /* Register encoding, combined */
  272. u8 cfg5; /* Config Register 5 on ADT7468 */
  273. struct lm85_autofan autofan[3];
  274. struct lm85_zone zone[3];
  275. };
  276. static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info);
  277. static int lm85_probe(struct i2c_client *client,
  278. const struct i2c_device_id *id);
  279. static int lm85_remove(struct i2c_client *client);
  280. static int lm85_read_value(struct i2c_client *client, u8 reg);
  281. static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
  282. static struct lm85_data *lm85_update_device(struct device *dev);
  283. static const struct i2c_device_id lm85_id[] = {
  284. { "adm1027", adm1027 },
  285. { "adt7463", adt7463 },
  286. { "adt7468", adt7468 },
  287. { "lm85", any_chip },
  288. { "lm85b", lm85b },
  289. { "lm85c", lm85c },
  290. { "emc6d100", emc6d100 },
  291. { "emc6d101", emc6d100 },
  292. { "emc6d102", emc6d102 },
  293. { }
  294. };
  295. MODULE_DEVICE_TABLE(i2c, lm85_id);
  296. static struct i2c_driver lm85_driver = {
  297. .class = I2C_CLASS_HWMON,
  298. .driver = {
  299. .name = "lm85",
  300. },
  301. .probe = lm85_probe,
  302. .remove = lm85_remove,
  303. .id_table = lm85_id,
  304. .detect = lm85_detect,
  305. .address_list = normal_i2c,
  306. };
  307. /* 4 Fans */
  308. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  309. char *buf)
  310. {
  311. int nr = to_sensor_dev_attr(attr)->index;
  312. struct lm85_data *data = lm85_update_device(dev);
  313. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
  314. }
  315. static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
  316. char *buf)
  317. {
  318. int nr = to_sensor_dev_attr(attr)->index;
  319. struct lm85_data *data = lm85_update_device(dev);
  320. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
  321. }
  322. static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
  323. const char *buf, size_t count)
  324. {
  325. int nr = to_sensor_dev_attr(attr)->index;
  326. struct i2c_client *client = to_i2c_client(dev);
  327. struct lm85_data *data = i2c_get_clientdata(client);
  328. unsigned long val = simple_strtoul(buf, NULL, 10);
  329. mutex_lock(&data->update_lock);
  330. data->fan_min[nr] = FAN_TO_REG(val);
  331. lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
  332. mutex_unlock(&data->update_lock);
  333. return count;
  334. }
  335. #define show_fan_offset(offset) \
  336. static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
  337. show_fan, NULL, offset - 1); \
  338. static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  339. show_fan_min, set_fan_min, offset - 1)
  340. show_fan_offset(1);
  341. show_fan_offset(2);
  342. show_fan_offset(3);
  343. show_fan_offset(4);
  344. /* vid, vrm, alarms */
  345. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  346. char *buf)
  347. {
  348. struct lm85_data *data = lm85_update_device(dev);
  349. int vid;
  350. if ((data->type == adt7463 || data->type == adt7468) &&
  351. (data->vid & 0x80)) {
  352. /* 6-pin VID (VRM 10) */
  353. vid = vid_from_reg(data->vid & 0x3f, data->vrm);
  354. } else {
  355. /* 5-pin VID (VRM 9) */
  356. vid = vid_from_reg(data->vid & 0x1f, data->vrm);
  357. }
  358. return sprintf(buf, "%d\n", vid);
  359. }
  360. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  361. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  362. char *buf)
  363. {
  364. struct lm85_data *data = dev_get_drvdata(dev);
  365. return sprintf(buf, "%ld\n", (long) data->vrm);
  366. }
  367. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  368. const char *buf, size_t count)
  369. {
  370. struct lm85_data *data = dev_get_drvdata(dev);
  371. data->vrm = simple_strtoul(buf, NULL, 10);
  372. return count;
  373. }
  374. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  375. static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
  376. *attr, char *buf)
  377. {
  378. struct lm85_data *data = lm85_update_device(dev);
  379. return sprintf(buf, "%u\n", data->alarms);
  380. }
  381. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
  382. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  383. char *buf)
  384. {
  385. int nr = to_sensor_dev_attr(attr)->index;
  386. struct lm85_data *data = lm85_update_device(dev);
  387. return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
  388. }
  389. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  390. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  391. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  392. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  393. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
  394. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
  395. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
  396. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
  397. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
  398. static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
  399. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
  400. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
  401. static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
  402. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
  403. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
  404. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
  405. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
  406. /* pwm */
  407. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  408. char *buf)
  409. {
  410. int nr = to_sensor_dev_attr(attr)->index;
  411. struct lm85_data *data = lm85_update_device(dev);
  412. return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
  413. }
  414. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  415. const char *buf, size_t count)
  416. {
  417. int nr = to_sensor_dev_attr(attr)->index;
  418. struct i2c_client *client = to_i2c_client(dev);
  419. struct lm85_data *data = i2c_get_clientdata(client);
  420. long val = simple_strtol(buf, NULL, 10);
  421. mutex_lock(&data->update_lock);
  422. data->pwm[nr] = PWM_TO_REG(val);
  423. lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
  424. mutex_unlock(&data->update_lock);
  425. return count;
  426. }
  427. static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
  428. *attr, char *buf)
  429. {
  430. int nr = to_sensor_dev_attr(attr)->index;
  431. struct lm85_data *data = lm85_update_device(dev);
  432. int pwm_zone, enable;
  433. pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
  434. switch (pwm_zone) {
  435. case -1: /* PWM is always at 100% */
  436. enable = 0;
  437. break;
  438. case 0: /* PWM is always at 0% */
  439. case -2: /* PWM responds to manual control */
  440. enable = 1;
  441. break;
  442. default: /* PWM in automatic mode */
  443. enable = 2;
  444. }
  445. return sprintf(buf, "%d\n", enable);
  446. }
  447. static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
  448. *attr, const char *buf, size_t count)
  449. {
  450. int nr = to_sensor_dev_attr(attr)->index;
  451. struct i2c_client *client = to_i2c_client(dev);
  452. struct lm85_data *data = i2c_get_clientdata(client);
  453. long val = simple_strtol(buf, NULL, 10);
  454. u8 config;
  455. switch (val) {
  456. case 0:
  457. config = 3;
  458. break;
  459. case 1:
  460. config = 7;
  461. break;
  462. case 2:
  463. /* Here we have to choose arbitrarily one of the 5 possible
  464. configurations; I go for the safest */
  465. config = 6;
  466. break;
  467. default:
  468. return -EINVAL;
  469. }
  470. mutex_lock(&data->update_lock);
  471. data->autofan[nr].config = lm85_read_value(client,
  472. LM85_REG_AFAN_CONFIG(nr));
  473. data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
  474. | (config << 5);
  475. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  476. data->autofan[nr].config);
  477. mutex_unlock(&data->update_lock);
  478. return count;
  479. }
  480. static ssize_t show_pwm_freq(struct device *dev,
  481. struct device_attribute *attr, char *buf)
  482. {
  483. int nr = to_sensor_dev_attr(attr)->index;
  484. struct lm85_data *data = lm85_update_device(dev);
  485. return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
  486. data->pwm_freq[nr]));
  487. }
  488. static ssize_t set_pwm_freq(struct device *dev,
  489. struct device_attribute *attr, const char *buf, size_t count)
  490. {
  491. int nr = to_sensor_dev_attr(attr)->index;
  492. struct i2c_client *client = to_i2c_client(dev);
  493. struct lm85_data *data = i2c_get_clientdata(client);
  494. long val = simple_strtol(buf, NULL, 10);
  495. mutex_lock(&data->update_lock);
  496. data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
  497. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  498. (data->zone[nr].range << 4)
  499. | data->pwm_freq[nr]);
  500. mutex_unlock(&data->update_lock);
  501. return count;
  502. }
  503. #define show_pwm_reg(offset) \
  504. static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  505. show_pwm, set_pwm, offset - 1); \
  506. static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
  507. show_pwm_enable, set_pwm_enable, offset - 1); \
  508. static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
  509. show_pwm_freq, set_pwm_freq, offset - 1)
  510. show_pwm_reg(1);
  511. show_pwm_reg(2);
  512. show_pwm_reg(3);
  513. /* Voltages */
  514. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  515. char *buf)
  516. {
  517. int nr = to_sensor_dev_attr(attr)->index;
  518. struct lm85_data *data = lm85_update_device(dev);
  519. return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
  520. data->in_ext[nr]));
  521. }
  522. static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
  523. char *buf)
  524. {
  525. int nr = to_sensor_dev_attr(attr)->index;
  526. struct lm85_data *data = lm85_update_device(dev);
  527. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
  528. }
  529. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  530. const char *buf, size_t count)
  531. {
  532. int nr = to_sensor_dev_attr(attr)->index;
  533. struct i2c_client *client = to_i2c_client(dev);
  534. struct lm85_data *data = i2c_get_clientdata(client);
  535. long val = simple_strtol(buf, NULL, 10);
  536. mutex_lock(&data->update_lock);
  537. data->in_min[nr] = INS_TO_REG(nr, val);
  538. lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
  539. mutex_unlock(&data->update_lock);
  540. return count;
  541. }
  542. static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
  543. char *buf)
  544. {
  545. int nr = to_sensor_dev_attr(attr)->index;
  546. struct lm85_data *data = lm85_update_device(dev);
  547. return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
  548. }
  549. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  550. const char *buf, size_t count)
  551. {
  552. int nr = to_sensor_dev_attr(attr)->index;
  553. struct i2c_client *client = to_i2c_client(dev);
  554. struct lm85_data *data = i2c_get_clientdata(client);
  555. long val = simple_strtol(buf, NULL, 10);
  556. mutex_lock(&data->update_lock);
  557. data->in_max[nr] = INS_TO_REG(nr, val);
  558. lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
  559. mutex_unlock(&data->update_lock);
  560. return count;
  561. }
  562. #define show_in_reg(offset) \
  563. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  564. show_in, NULL, offset); \
  565. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
  566. show_in_min, set_in_min, offset); \
  567. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
  568. show_in_max, set_in_max, offset)
  569. show_in_reg(0);
  570. show_in_reg(1);
  571. show_in_reg(2);
  572. show_in_reg(3);
  573. show_in_reg(4);
  574. show_in_reg(5);
  575. show_in_reg(6);
  576. show_in_reg(7);
  577. /* Temps */
  578. static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
  579. char *buf)
  580. {
  581. int nr = to_sensor_dev_attr(attr)->index;
  582. struct lm85_data *data = lm85_update_device(dev);
  583. return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
  584. data->temp_ext[nr]));
  585. }
  586. static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
  587. char *buf)
  588. {
  589. int nr = to_sensor_dev_attr(attr)->index;
  590. struct lm85_data *data = lm85_update_device(dev);
  591. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
  592. }
  593. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  594. const char *buf, size_t count)
  595. {
  596. int nr = to_sensor_dev_attr(attr)->index;
  597. struct i2c_client *client = to_i2c_client(dev);
  598. struct lm85_data *data = i2c_get_clientdata(client);
  599. long val = simple_strtol(buf, NULL, 10);
  600. if (IS_ADT7468_OFF64(data))
  601. val += 64;
  602. mutex_lock(&data->update_lock);
  603. data->temp_min[nr] = TEMP_TO_REG(val);
  604. lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
  605. mutex_unlock(&data->update_lock);
  606. return count;
  607. }
  608. static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
  609. char *buf)
  610. {
  611. int nr = to_sensor_dev_attr(attr)->index;
  612. struct lm85_data *data = lm85_update_device(dev);
  613. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
  614. }
  615. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  616. const char *buf, size_t count)
  617. {
  618. int nr = to_sensor_dev_attr(attr)->index;
  619. struct i2c_client *client = to_i2c_client(dev);
  620. struct lm85_data *data = i2c_get_clientdata(client);
  621. long val = simple_strtol(buf, NULL, 10);
  622. if (IS_ADT7468_OFF64(data))
  623. val += 64;
  624. mutex_lock(&data->update_lock);
  625. data->temp_max[nr] = TEMP_TO_REG(val);
  626. lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
  627. mutex_unlock(&data->update_lock);
  628. return count;
  629. }
  630. #define show_temp_reg(offset) \
  631. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  632. show_temp, NULL, offset - 1); \
  633. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
  634. show_temp_min, set_temp_min, offset - 1); \
  635. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
  636. show_temp_max, set_temp_max, offset - 1);
  637. show_temp_reg(1);
  638. show_temp_reg(2);
  639. show_temp_reg(3);
  640. /* Automatic PWM control */
  641. static ssize_t show_pwm_auto_channels(struct device *dev,
  642. struct device_attribute *attr, char *buf)
  643. {
  644. int nr = to_sensor_dev_attr(attr)->index;
  645. struct lm85_data *data = lm85_update_device(dev);
  646. return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
  647. }
  648. static ssize_t set_pwm_auto_channels(struct device *dev,
  649. struct device_attribute *attr, const char *buf, size_t count)
  650. {
  651. int nr = to_sensor_dev_attr(attr)->index;
  652. struct i2c_client *client = to_i2c_client(dev);
  653. struct lm85_data *data = i2c_get_clientdata(client);
  654. long val = simple_strtol(buf, NULL, 10);
  655. mutex_lock(&data->update_lock);
  656. data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
  657. | ZONE_TO_REG(val);
  658. lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
  659. data->autofan[nr].config);
  660. mutex_unlock(&data->update_lock);
  661. return count;
  662. }
  663. static ssize_t show_pwm_auto_pwm_min(struct device *dev,
  664. struct device_attribute *attr, char *buf)
  665. {
  666. int nr = to_sensor_dev_attr(attr)->index;
  667. struct lm85_data *data = lm85_update_device(dev);
  668. return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
  669. }
  670. static ssize_t set_pwm_auto_pwm_min(struct device *dev,
  671. struct device_attribute *attr, const char *buf, size_t count)
  672. {
  673. int nr = to_sensor_dev_attr(attr)->index;
  674. struct i2c_client *client = to_i2c_client(dev);
  675. struct lm85_data *data = i2c_get_clientdata(client);
  676. long val = simple_strtol(buf, NULL, 10);
  677. mutex_lock(&data->update_lock);
  678. data->autofan[nr].min_pwm = PWM_TO_REG(val);
  679. lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
  680. data->autofan[nr].min_pwm);
  681. mutex_unlock(&data->update_lock);
  682. return count;
  683. }
  684. static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
  685. struct device_attribute *attr, char *buf)
  686. {
  687. int nr = to_sensor_dev_attr(attr)->index;
  688. struct lm85_data *data = lm85_update_device(dev);
  689. return sprintf(buf, "%d\n", data->autofan[nr].min_off);
  690. }
  691. static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
  692. struct device_attribute *attr, const char *buf, size_t count)
  693. {
  694. int nr = to_sensor_dev_attr(attr)->index;
  695. struct i2c_client *client = to_i2c_client(dev);
  696. struct lm85_data *data = i2c_get_clientdata(client);
  697. long val = simple_strtol(buf, NULL, 10);
  698. u8 tmp;
  699. mutex_lock(&data->update_lock);
  700. data->autofan[nr].min_off = val;
  701. tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
  702. tmp &= ~(0x20 << nr);
  703. if (data->autofan[nr].min_off)
  704. tmp |= 0x20 << nr;
  705. lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
  706. mutex_unlock(&data->update_lock);
  707. return count;
  708. }
  709. #define pwm_auto(offset) \
  710. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
  711. S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
  712. set_pwm_auto_channels, offset - 1); \
  713. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
  714. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
  715. set_pwm_auto_pwm_min, offset - 1); \
  716. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
  717. S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
  718. set_pwm_auto_pwm_minctl, offset - 1)
  719. pwm_auto(1);
  720. pwm_auto(2);
  721. pwm_auto(3);
  722. /* Temperature settings for automatic PWM control */
  723. static ssize_t show_temp_auto_temp_off(struct device *dev,
  724. struct device_attribute *attr, char *buf)
  725. {
  726. int nr = to_sensor_dev_attr(attr)->index;
  727. struct lm85_data *data = lm85_update_device(dev);
  728. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
  729. HYST_FROM_REG(data->zone[nr].hyst));
  730. }
  731. static ssize_t set_temp_auto_temp_off(struct device *dev,
  732. struct device_attribute *attr, const char *buf, size_t count)
  733. {
  734. int nr = to_sensor_dev_attr(attr)->index;
  735. struct i2c_client *client = to_i2c_client(dev);
  736. struct lm85_data *data = i2c_get_clientdata(client);
  737. int min;
  738. long val = simple_strtol(buf, NULL, 10);
  739. mutex_lock(&data->update_lock);
  740. min = TEMP_FROM_REG(data->zone[nr].limit);
  741. data->zone[nr].off_desired = TEMP_TO_REG(val);
  742. data->zone[nr].hyst = HYST_TO_REG(min - val);
  743. if (nr == 0 || nr == 1) {
  744. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  745. (data->zone[0].hyst << 4)
  746. | data->zone[1].hyst);
  747. } else {
  748. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  749. (data->zone[2].hyst << 4));
  750. }
  751. mutex_unlock(&data->update_lock);
  752. return count;
  753. }
  754. static ssize_t show_temp_auto_temp_min(struct device *dev,
  755. struct device_attribute *attr, char *buf)
  756. {
  757. int nr = to_sensor_dev_attr(attr)->index;
  758. struct lm85_data *data = lm85_update_device(dev);
  759. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
  760. }
  761. static ssize_t set_temp_auto_temp_min(struct device *dev,
  762. struct device_attribute *attr, const char *buf, size_t count)
  763. {
  764. int nr = to_sensor_dev_attr(attr)->index;
  765. struct i2c_client *client = to_i2c_client(dev);
  766. struct lm85_data *data = i2c_get_clientdata(client);
  767. long val = simple_strtol(buf, NULL, 10);
  768. mutex_lock(&data->update_lock);
  769. data->zone[nr].limit = TEMP_TO_REG(val);
  770. lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
  771. data->zone[nr].limit);
  772. /* Update temp_auto_max and temp_auto_range */
  773. data->zone[nr].range = RANGE_TO_REG(
  774. TEMP_FROM_REG(data->zone[nr].max_desired) -
  775. TEMP_FROM_REG(data->zone[nr].limit));
  776. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  777. ((data->zone[nr].range & 0x0f) << 4)
  778. | (data->pwm_freq[nr] & 0x07));
  779. /* Update temp_auto_hyst and temp_auto_off */
  780. data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
  781. data->zone[nr].limit) - TEMP_FROM_REG(
  782. data->zone[nr].off_desired));
  783. if (nr == 0 || nr == 1) {
  784. lm85_write_value(client, LM85_REG_AFAN_HYST1,
  785. (data->zone[0].hyst << 4)
  786. | data->zone[1].hyst);
  787. } else {
  788. lm85_write_value(client, LM85_REG_AFAN_HYST2,
  789. (data->zone[2].hyst << 4));
  790. }
  791. mutex_unlock(&data->update_lock);
  792. return count;
  793. }
  794. static ssize_t show_temp_auto_temp_max(struct device *dev,
  795. struct device_attribute *attr, char *buf)
  796. {
  797. int nr = to_sensor_dev_attr(attr)->index;
  798. struct lm85_data *data = lm85_update_device(dev);
  799. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
  800. RANGE_FROM_REG(data->zone[nr].range));
  801. }
  802. static ssize_t set_temp_auto_temp_max(struct device *dev,
  803. struct device_attribute *attr, const char *buf, size_t count)
  804. {
  805. int nr = to_sensor_dev_attr(attr)->index;
  806. struct i2c_client *client = to_i2c_client(dev);
  807. struct lm85_data *data = i2c_get_clientdata(client);
  808. int min;
  809. long val = simple_strtol(buf, NULL, 10);
  810. mutex_lock(&data->update_lock);
  811. min = TEMP_FROM_REG(data->zone[nr].limit);
  812. data->zone[nr].max_desired = TEMP_TO_REG(val);
  813. data->zone[nr].range = RANGE_TO_REG(
  814. val - min);
  815. lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
  816. ((data->zone[nr].range & 0x0f) << 4)
  817. | (data->pwm_freq[nr] & 0x07));
  818. mutex_unlock(&data->update_lock);
  819. return count;
  820. }
  821. static ssize_t show_temp_auto_temp_crit(struct device *dev,
  822. struct device_attribute *attr, char *buf)
  823. {
  824. int nr = to_sensor_dev_attr(attr)->index;
  825. struct lm85_data *data = lm85_update_device(dev);
  826. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
  827. }
  828. static ssize_t set_temp_auto_temp_crit(struct device *dev,
  829. struct device_attribute *attr, const char *buf, size_t count)
  830. {
  831. int nr = to_sensor_dev_attr(attr)->index;
  832. struct i2c_client *client = to_i2c_client(dev);
  833. struct lm85_data *data = i2c_get_clientdata(client);
  834. long val = simple_strtol(buf, NULL, 10);
  835. mutex_lock(&data->update_lock);
  836. data->zone[nr].critical = TEMP_TO_REG(val);
  837. lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
  838. data->zone[nr].critical);
  839. mutex_unlock(&data->update_lock);
  840. return count;
  841. }
  842. #define temp_auto(offset) \
  843. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
  844. S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
  845. set_temp_auto_temp_off, offset - 1); \
  846. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
  847. S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
  848. set_temp_auto_temp_min, offset - 1); \
  849. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
  850. S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
  851. set_temp_auto_temp_max, offset - 1); \
  852. static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
  853. S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
  854. set_temp_auto_temp_crit, offset - 1);
  855. temp_auto(1);
  856. temp_auto(2);
  857. temp_auto(3);
  858. static struct attribute *lm85_attributes[] = {
  859. &sensor_dev_attr_fan1_input.dev_attr.attr,
  860. &sensor_dev_attr_fan2_input.dev_attr.attr,
  861. &sensor_dev_attr_fan3_input.dev_attr.attr,
  862. &sensor_dev_attr_fan4_input.dev_attr.attr,
  863. &sensor_dev_attr_fan1_min.dev_attr.attr,
  864. &sensor_dev_attr_fan2_min.dev_attr.attr,
  865. &sensor_dev_attr_fan3_min.dev_attr.attr,
  866. &sensor_dev_attr_fan4_min.dev_attr.attr,
  867. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  868. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  869. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  870. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  871. &sensor_dev_attr_pwm1.dev_attr.attr,
  872. &sensor_dev_attr_pwm2.dev_attr.attr,
  873. &sensor_dev_attr_pwm3.dev_attr.attr,
  874. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  875. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  876. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  877. &sensor_dev_attr_pwm1_freq.dev_attr.attr,
  878. &sensor_dev_attr_pwm2_freq.dev_attr.attr,
  879. &sensor_dev_attr_pwm3_freq.dev_attr.attr,
  880. &sensor_dev_attr_in0_input.dev_attr.attr,
  881. &sensor_dev_attr_in1_input.dev_attr.attr,
  882. &sensor_dev_attr_in2_input.dev_attr.attr,
  883. &sensor_dev_attr_in3_input.dev_attr.attr,
  884. &sensor_dev_attr_in0_min.dev_attr.attr,
  885. &sensor_dev_attr_in1_min.dev_attr.attr,
  886. &sensor_dev_attr_in2_min.dev_attr.attr,
  887. &sensor_dev_attr_in3_min.dev_attr.attr,
  888. &sensor_dev_attr_in0_max.dev_attr.attr,
  889. &sensor_dev_attr_in1_max.dev_attr.attr,
  890. &sensor_dev_attr_in2_max.dev_attr.attr,
  891. &sensor_dev_attr_in3_max.dev_attr.attr,
  892. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  893. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  894. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  895. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  896. &sensor_dev_attr_temp1_input.dev_attr.attr,
  897. &sensor_dev_attr_temp2_input.dev_attr.attr,
  898. &sensor_dev_attr_temp3_input.dev_attr.attr,
  899. &sensor_dev_attr_temp1_min.dev_attr.attr,
  900. &sensor_dev_attr_temp2_min.dev_attr.attr,
  901. &sensor_dev_attr_temp3_min.dev_attr.attr,
  902. &sensor_dev_attr_temp1_max.dev_attr.attr,
  903. &sensor_dev_attr_temp2_max.dev_attr.attr,
  904. &sensor_dev_attr_temp3_max.dev_attr.attr,
  905. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  906. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  907. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  908. &sensor_dev_attr_temp1_fault.dev_attr.attr,
  909. &sensor_dev_attr_temp3_fault.dev_attr.attr,
  910. &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
  911. &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
  912. &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
  913. &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
  914. &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
  915. &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
  916. &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
  917. &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
  918. &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
  919. &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
  920. &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
  921. &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
  922. &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
  923. &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
  924. &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
  925. &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
  926. &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
  927. &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
  928. &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
  929. &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
  930. &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
  931. &dev_attr_vrm.attr,
  932. &dev_attr_cpu0_vid.attr,
  933. &dev_attr_alarms.attr,
  934. NULL
  935. };
  936. static const struct attribute_group lm85_group = {
  937. .attrs = lm85_attributes,
  938. };
  939. static struct attribute *lm85_attributes_in4[] = {
  940. &sensor_dev_attr_in4_input.dev_attr.attr,
  941. &sensor_dev_attr_in4_min.dev_attr.attr,
  942. &sensor_dev_attr_in4_max.dev_attr.attr,
  943. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  944. NULL
  945. };
  946. static const struct attribute_group lm85_group_in4 = {
  947. .attrs = lm85_attributes_in4,
  948. };
  949. static struct attribute *lm85_attributes_in567[] = {
  950. &sensor_dev_attr_in5_input.dev_attr.attr,
  951. &sensor_dev_attr_in6_input.dev_attr.attr,
  952. &sensor_dev_attr_in7_input.dev_attr.attr,
  953. &sensor_dev_attr_in5_min.dev_attr.attr,
  954. &sensor_dev_attr_in6_min.dev_attr.attr,
  955. &sensor_dev_attr_in7_min.dev_attr.attr,
  956. &sensor_dev_attr_in5_max.dev_attr.attr,
  957. &sensor_dev_attr_in6_max.dev_attr.attr,
  958. &sensor_dev_attr_in7_max.dev_attr.attr,
  959. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  960. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  961. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  962. NULL
  963. };
  964. static const struct attribute_group lm85_group_in567 = {
  965. .attrs = lm85_attributes_in567,
  966. };
  967. static void lm85_init_client(struct i2c_client *client)
  968. {
  969. int value;
  970. /* Start monitoring if needed */
  971. value = lm85_read_value(client, LM85_REG_CONFIG);
  972. if (!(value & 0x01)) {
  973. dev_info(&client->dev, "Starting monitoring\n");
  974. lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
  975. }
  976. /* Warn about unusual configuration bits */
  977. if (value & 0x02)
  978. dev_warn(&client->dev, "Device configuration is locked\n");
  979. if (!(value & 0x04))
  980. dev_warn(&client->dev, "Device is not ready\n");
  981. }
  982. static int lm85_is_fake(struct i2c_client *client)
  983. {
  984. /*
  985. * Differenciate between real LM96000 and Winbond WPCD377I. The latter
  986. * emulate the former except that it has no hardware monitoring function
  987. * so the readings are always 0.
  988. */
  989. int i;
  990. u8 in_temp, fan;
  991. for (i = 0; i < 8; i++) {
  992. in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
  993. fan = i2c_smbus_read_byte_data(client, 0x28 + i);
  994. if (in_temp != 0x00 || fan != 0xff)
  995. return 0;
  996. }
  997. return 1;
  998. }
  999. /* Return 0 if detection is successful, -ENODEV otherwise */
  1000. static int lm85_detect(struct i2c_client *client, 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);