lm85.c 47 KB

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