lm90.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. /*
  2. * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
  3. * monitoring
  4. * Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
  5. *
  6. * Based on the lm83 driver. The LM90 is a sensor chip made by National
  7. * Semiconductor. It reports up to two temperatures (its own plus up to
  8. * one external one) with a 0.125 deg resolution (1 deg for local
  9. * temperature) and a 3-4 deg accuracy.
  10. *
  11. * This driver also supports the LM89 and LM99, two other sensor chips
  12. * made by National Semiconductor. Both have an increased remote
  13. * temperature measurement accuracy (1 degree), and the LM99
  14. * additionally shifts remote temperatures (measured and limits) by 16
  15. * degrees, which allows for higher temperatures measurement.
  16. * Note that there is no way to differentiate between both chips.
  17. * When device is auto-detected, the driver will assume an LM99.
  18. *
  19. * This driver also supports the LM86, another sensor chip made by
  20. * National Semiconductor. It is exactly similar to the LM90 except it
  21. * has a higher accuracy.
  22. *
  23. * This driver also supports the ADM1032, a sensor chip made by Analog
  24. * Devices. That chip is similar to the LM90, with a few differences
  25. * that are not handled by this driver. Among others, it has a higher
  26. * accuracy than the LM90, much like the LM86 does.
  27. *
  28. * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
  29. * chips made by Maxim. These chips are similar to the LM86.
  30. * Note that there is no easy way to differentiate between the three
  31. * variants. We use the device address to detect MAX6659, which will result
  32. * in a detection as max6657 if it is on address 0x4c. The extra address
  33. * and features of the MAX6659 are only supported if the chip is configured
  34. * explicitly as max6659, or if its address is not 0x4c.
  35. * These chips lack the remote temperature offset feature.
  36. *
  37. * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and
  38. * MAX6692 chips made by Maxim. These are again similar to the LM86,
  39. * but they use unsigned temperature values and can report temperatures
  40. * from 0 to 145 degrees.
  41. *
  42. * This driver also supports the MAX6680 and MAX6681, two other sensor
  43. * chips made by Maxim. These are quite similar to the other Maxim
  44. * chips. The MAX6680 and MAX6681 only differ in the pinout so they can
  45. * be treated identically.
  46. *
  47. * This driver also supports the MAX6695 and MAX6696, two other sensor
  48. * chips made by Maxim. These are also quite similar to other Maxim
  49. * chips, but support three temperature sensors instead of two. MAX6695
  50. * and MAX6696 only differ in the pinout so they can be treated identically.
  51. *
  52. * This driver also supports ADT7461 and ADT7461A from Analog Devices as well as
  53. * NCT1008 from ON Semiconductor. The chips are supported in both compatibility
  54. * and extended mode. They are mostly compatible with LM90 except for a data
  55. * format difference for the temperature value registers.
  56. *
  57. * This driver also supports the SA56004 from Philips. This device is
  58. * pin-compatible with the LM86, the ED/EDP parts are also address-compatible.
  59. *
  60. * This driver also supports the G781 from GMT. This device is compatible
  61. * with the ADM1032.
  62. *
  63. * Since the LM90 was the first chipset supported by this driver, most
  64. * comments will refer to this chipset, but are actually general and
  65. * concern all supported chipsets, unless mentioned otherwise.
  66. *
  67. * This program is free software; you can redistribute it and/or modify
  68. * it under the terms of the GNU General Public License as published by
  69. * the Free Software Foundation; either version 2 of the License, or
  70. * (at your option) any later version.
  71. *
  72. * This program is distributed in the hope that it will be useful,
  73. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  74. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  75. * GNU General Public License for more details.
  76. *
  77. * You should have received a copy of the GNU General Public License
  78. * along with this program; if not, write to the Free Software
  79. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  80. */
  81. #include <linux/module.h>
  82. #include <linux/init.h>
  83. #include <linux/slab.h>
  84. #include <linux/jiffies.h>
  85. #include <linux/i2c.h>
  86. #include <linux/hwmon-sysfs.h>
  87. #include <linux/hwmon.h>
  88. #include <linux/err.h>
  89. #include <linux/mutex.h>
  90. #include <linux/sysfs.h>
  91. #include <linux/interrupt.h>
  92. /*
  93. * Addresses to scan
  94. * Address is fully defined internally and cannot be changed except for
  95. * MAX6659, MAX6680 and MAX6681.
  96. * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, ADT7461A, MAX6649,
  97. * MAX6657, MAX6658, NCT1008 and W83L771 have address 0x4c.
  98. * ADM1032-2, ADT7461-2, ADT7461A-2, LM89-1, LM99-1, MAX6646, and NCT1008D
  99. * have address 0x4d.
  100. * MAX6647 has address 0x4e.
  101. * MAX6659 can have address 0x4c, 0x4d or 0x4e.
  102. * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
  103. * 0x4c, 0x4d or 0x4e.
  104. * SA56004 can have address 0x48 through 0x4F.
  105. */
  106. static const unsigned short normal_i2c[] = {
  107. 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x48, 0x49, 0x4a, 0x4b, 0x4c,
  108. 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
  109. enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
  110. max6646, w83l771, max6696, sa56004, g781 };
  111. /*
  112. * The LM90 registers
  113. */
  114. #define LM90_REG_R_MAN_ID 0xFE
  115. #define LM90_REG_R_CHIP_ID 0xFF
  116. #define LM90_REG_R_CONFIG1 0x03
  117. #define LM90_REG_W_CONFIG1 0x09
  118. #define LM90_REG_R_CONFIG2 0xBF
  119. #define LM90_REG_W_CONFIG2 0xBF
  120. #define LM90_REG_R_CONVRATE 0x04
  121. #define LM90_REG_W_CONVRATE 0x0A
  122. #define LM90_REG_R_STATUS 0x02
  123. #define LM90_REG_R_LOCAL_TEMP 0x00
  124. #define LM90_REG_R_LOCAL_HIGH 0x05
  125. #define LM90_REG_W_LOCAL_HIGH 0x0B
  126. #define LM90_REG_R_LOCAL_LOW 0x06
  127. #define LM90_REG_W_LOCAL_LOW 0x0C
  128. #define LM90_REG_R_LOCAL_CRIT 0x20
  129. #define LM90_REG_W_LOCAL_CRIT 0x20
  130. #define LM90_REG_R_REMOTE_TEMPH 0x01
  131. #define LM90_REG_R_REMOTE_TEMPL 0x10
  132. #define LM90_REG_R_REMOTE_OFFSH 0x11
  133. #define LM90_REG_W_REMOTE_OFFSH 0x11
  134. #define LM90_REG_R_REMOTE_OFFSL 0x12
  135. #define LM90_REG_W_REMOTE_OFFSL 0x12
  136. #define LM90_REG_R_REMOTE_HIGHH 0x07
  137. #define LM90_REG_W_REMOTE_HIGHH 0x0D
  138. #define LM90_REG_R_REMOTE_HIGHL 0x13
  139. #define LM90_REG_W_REMOTE_HIGHL 0x13
  140. #define LM90_REG_R_REMOTE_LOWH 0x08
  141. #define LM90_REG_W_REMOTE_LOWH 0x0E
  142. #define LM90_REG_R_REMOTE_LOWL 0x14
  143. #define LM90_REG_W_REMOTE_LOWL 0x14
  144. #define LM90_REG_R_REMOTE_CRIT 0x19
  145. #define LM90_REG_W_REMOTE_CRIT 0x19
  146. #define LM90_REG_R_TCRIT_HYST 0x21
  147. #define LM90_REG_W_TCRIT_HYST 0x21
  148. /* MAX6646/6647/6649/6657/6658/6659/6695/6696 registers */
  149. #define MAX6657_REG_R_LOCAL_TEMPL 0x11
  150. #define MAX6696_REG_R_STATUS2 0x12
  151. #define MAX6659_REG_R_REMOTE_EMERG 0x16
  152. #define MAX6659_REG_W_REMOTE_EMERG 0x16
  153. #define MAX6659_REG_R_LOCAL_EMERG 0x17
  154. #define MAX6659_REG_W_LOCAL_EMERG 0x17
  155. /* SA56004 registers */
  156. #define SA56004_REG_R_LOCAL_TEMPL 0x22
  157. #define LM90_DEF_CONVRATE_RVAL 6 /* Def conversion rate register value */
  158. #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */
  159. /*
  160. * Device flags
  161. */
  162. #define LM90_FLAG_ADT7461_EXT (1 << 0) /* ADT7461 extended mode */
  163. /* Device features */
  164. #define LM90_HAVE_OFFSET (1 << 1) /* temperature offset register */
  165. #define LM90_HAVE_REM_LIMIT_EXT (1 << 3) /* extended remote limit */
  166. #define LM90_HAVE_EMERGENCY (1 << 4) /* 3rd upper (emergency) limit */
  167. #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */
  168. #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */
  169. #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
  170. /* LM90 status */
  171. #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */
  172. #define LM90_STATUS_RTHRM (1 << 1) /* remote THERM limit tripped */
  173. #define LM90_STATUS_ROPEN (1 << 2) /* remote is an open circuit */
  174. #define LM90_STATUS_RLOW (1 << 3) /* remote low temp limit tripped */
  175. #define LM90_STATUS_RHIGH (1 << 4) /* remote high temp limit tripped */
  176. #define LM90_STATUS_LLOW (1 << 5) /* local low temp limit tripped */
  177. #define LM90_STATUS_LHIGH (1 << 6) /* local high temp limit tripped */
  178. #define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */
  179. #define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */
  180. #define MAX6696_STATUS2_R2LOW (1 << 3) /* remote2 low temp limit tripped */
  181. #define MAX6696_STATUS2_R2HIGH (1 << 4) /* remote2 high temp limit tripped */
  182. #define MAX6696_STATUS2_ROT2 (1 << 5) /* remote emergency limit tripped */
  183. #define MAX6696_STATUS2_R2OT2 (1 << 6) /* remote2 emergency limit tripped */
  184. #define MAX6696_STATUS2_LOT2 (1 << 7) /* local emergency limit tripped */
  185. /*
  186. * Driver data (common to all clients)
  187. */
  188. static const struct i2c_device_id lm90_id[] = {
  189. { "adm1032", adm1032 },
  190. { "adt7461", adt7461 },
  191. { "adt7461a", adt7461 },
  192. { "g781", g781 },
  193. { "lm90", lm90 },
  194. { "lm86", lm86 },
  195. { "lm89", lm86 },
  196. { "lm99", lm99 },
  197. { "max6646", max6646 },
  198. { "max6647", max6646 },
  199. { "max6649", max6646 },
  200. { "max6657", max6657 },
  201. { "max6658", max6657 },
  202. { "max6659", max6659 },
  203. { "max6680", max6680 },
  204. { "max6681", max6680 },
  205. { "max6695", max6696 },
  206. { "max6696", max6696 },
  207. { "nct1008", adt7461 },
  208. { "w83l771", w83l771 },
  209. { "sa56004", sa56004 },
  210. { }
  211. };
  212. MODULE_DEVICE_TABLE(i2c, lm90_id);
  213. /*
  214. * chip type specific parameters
  215. */
  216. struct lm90_params {
  217. u32 flags; /* Capabilities */
  218. u16 alert_alarms; /* Which alarm bits trigger ALERT# */
  219. /* Upper 8 bits for max6695/96 */
  220. u8 max_convrate; /* Maximum conversion rate register value */
  221. u8 reg_local_ext; /* Extended local temp register (optional) */
  222. };
  223. static const struct lm90_params lm90_params[] = {
  224. [adm1032] = {
  225. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
  226. | LM90_HAVE_BROKEN_ALERT,
  227. .alert_alarms = 0x7c,
  228. .max_convrate = 10,
  229. },
  230. [adt7461] = {
  231. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
  232. | LM90_HAVE_BROKEN_ALERT,
  233. .alert_alarms = 0x7c,
  234. .max_convrate = 10,
  235. },
  236. [g781] = {
  237. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
  238. | LM90_HAVE_BROKEN_ALERT,
  239. .alert_alarms = 0x7c,
  240. .max_convrate = 8,
  241. },
  242. [lm86] = {
  243. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
  244. .alert_alarms = 0x7b,
  245. .max_convrate = 9,
  246. },
  247. [lm90] = {
  248. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
  249. .alert_alarms = 0x7b,
  250. .max_convrate = 9,
  251. },
  252. [lm99] = {
  253. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
  254. .alert_alarms = 0x7b,
  255. .max_convrate = 9,
  256. },
  257. [max6646] = {
  258. .alert_alarms = 0x7c,
  259. .max_convrate = 6,
  260. .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
  261. },
  262. [max6657] = {
  263. .alert_alarms = 0x7c,
  264. .max_convrate = 8,
  265. .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
  266. },
  267. [max6659] = {
  268. .flags = LM90_HAVE_EMERGENCY,
  269. .alert_alarms = 0x7c,
  270. .max_convrate = 8,
  271. .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
  272. },
  273. [max6680] = {
  274. .flags = LM90_HAVE_OFFSET,
  275. .alert_alarms = 0x7c,
  276. .max_convrate = 7,
  277. },
  278. [max6696] = {
  279. .flags = LM90_HAVE_EMERGENCY
  280. | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3,
  281. .alert_alarms = 0x1c7c,
  282. .max_convrate = 6,
  283. .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
  284. },
  285. [w83l771] = {
  286. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
  287. .alert_alarms = 0x7c,
  288. .max_convrate = 8,
  289. },
  290. [sa56004] = {
  291. .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
  292. .alert_alarms = 0x7b,
  293. .max_convrate = 9,
  294. .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL,
  295. },
  296. };
  297. /*
  298. * Client data (each client gets its own)
  299. */
  300. struct lm90_data {
  301. struct device *hwmon_dev;
  302. struct mutex update_lock;
  303. char valid; /* zero until following fields are valid */
  304. unsigned long last_updated; /* in jiffies */
  305. int kind;
  306. u32 flags;
  307. int update_interval; /* in milliseconds */
  308. u8 config_orig; /* Original configuration register value */
  309. u8 convrate_orig; /* Original conversion rate register value */
  310. u16 alert_alarms; /* Which alarm bits trigger ALERT# */
  311. /* Upper 8 bits for max6695/96 */
  312. u8 max_convrate; /* Maximum conversion rate */
  313. u8 reg_local_ext; /* local extension register offset */
  314. /* registers values */
  315. s8 temp8[8]; /* 0: local low limit
  316. * 1: local high limit
  317. * 2: local critical limit
  318. * 3: remote critical limit
  319. * 4: local emergency limit (max6659 and max6695/96)
  320. * 5: remote emergency limit (max6659 and max6695/96)
  321. * 6: remote 2 critical limit (max6695/96 only)
  322. * 7: remote 2 emergency limit (max6695/96 only)
  323. */
  324. s16 temp11[8]; /* 0: remote input
  325. * 1: remote low limit
  326. * 2: remote high limit
  327. * 3: remote offset (except max6646, max6657/58/59,
  328. * and max6695/96)
  329. * 4: local input
  330. * 5: remote 2 input (max6695/96 only)
  331. * 6: remote 2 low limit (max6695/96 only)
  332. * 7: remote 2 high limit (max6695/96 only)
  333. */
  334. u8 temp_hyst;
  335. u16 alarms; /* bitvector (upper 8 bits for max6695/96) */
  336. };
  337. /*
  338. * Support functions
  339. */
  340. /*
  341. * The ADM1032 supports PEC but not on write byte transactions, so we need
  342. * to explicitly ask for a transaction without PEC.
  343. */
  344. static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value)
  345. {
  346. return i2c_smbus_xfer(client->adapter, client->addr,
  347. client->flags & ~I2C_CLIENT_PEC,
  348. I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
  349. }
  350. /*
  351. * It is assumed that client->update_lock is held (unless we are in
  352. * detection or initialization steps). This matters when PEC is enabled,
  353. * because we don't want the address pointer to change between the write
  354. * byte and the read byte transactions.
  355. */
  356. static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value)
  357. {
  358. int err;
  359. if (client->flags & I2C_CLIENT_PEC) {
  360. err = adm1032_write_byte(client, reg);
  361. if (err >= 0)
  362. err = i2c_smbus_read_byte(client);
  363. } else
  364. err = i2c_smbus_read_byte_data(client, reg);
  365. if (err < 0) {
  366. dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
  367. reg, err);
  368. return err;
  369. }
  370. *value = err;
  371. return 0;
  372. }
  373. static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  374. {
  375. int err;
  376. u8 oldh, newh, l;
  377. /*
  378. * There is a trick here. We have to read two registers to have the
  379. * sensor temperature, but we have to beware a conversion could occur
  380. * between the readings. The datasheet says we should either use
  381. * the one-shot conversion register, which we don't want to do
  382. * (disables hardware monitoring) or monitor the busy bit, which is
  383. * impossible (we can't read the values and monitor that bit at the
  384. * exact same time). So the solution used here is to read the high
  385. * byte once, then the low byte, then the high byte again. If the new
  386. * high byte matches the old one, then we have a valid reading. Else
  387. * we have to read the low byte again, and now we believe we have a
  388. * correct reading.
  389. */
  390. if ((err = lm90_read_reg(client, regh, &oldh))
  391. || (err = lm90_read_reg(client, regl, &l))
  392. || (err = lm90_read_reg(client, regh, &newh)))
  393. return err;
  394. if (oldh != newh) {
  395. err = lm90_read_reg(client, regl, &l);
  396. if (err)
  397. return err;
  398. }
  399. *value = (newh << 8) | l;
  400. return 0;
  401. }
  402. /*
  403. * client->update_lock must be held when calling this function (unless we are
  404. * in detection or initialization steps), and while a remote channel other
  405. * than channel 0 is selected. Also, calling code must make sure to re-select
  406. * external channel 0 before releasing the lock. This is necessary because
  407. * various registers have different meanings as a result of selecting a
  408. * non-default remote channel.
  409. */
  410. static inline void lm90_select_remote_channel(struct i2c_client *client,
  411. struct lm90_data *data,
  412. int channel)
  413. {
  414. u8 config;
  415. if (data->kind == max6696) {
  416. lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
  417. config &= ~0x08;
  418. if (channel)
  419. config |= 0x08;
  420. i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
  421. config);
  422. }
  423. }
  424. /*
  425. * Set conversion rate.
  426. * client->update_lock must be held when calling this function (unless we are
  427. * in detection or initialization steps).
  428. */
  429. static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
  430. unsigned int interval)
  431. {
  432. int i;
  433. unsigned int update_interval;
  434. /* Shift calculations to avoid rounding errors */
  435. interval <<= 6;
  436. /* find the nearest update rate */
  437. for (i = 0, update_interval = LM90_MAX_CONVRATE_MS << 6;
  438. i < data->max_convrate; i++, update_interval >>= 1)
  439. if (interval >= update_interval * 3 / 4)
  440. break;
  441. i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i);
  442. data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
  443. }
  444. static struct lm90_data *lm90_update_device(struct device *dev)
  445. {
  446. struct i2c_client *client = to_i2c_client(dev);
  447. struct lm90_data *data = i2c_get_clientdata(client);
  448. unsigned long next_update;
  449. mutex_lock(&data->update_lock);
  450. next_update = data->last_updated +
  451. msecs_to_jiffies(data->update_interval);
  452. if (time_after(jiffies, next_update) || !data->valid) {
  453. u8 h, l;
  454. u8 alarms;
  455. dev_dbg(&client->dev, "Updating lm90 data.\n");
  456. lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
  457. lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
  458. lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
  459. lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
  460. lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
  461. if (data->reg_local_ext) {
  462. lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
  463. data->reg_local_ext,
  464. &data->temp11[4]);
  465. } else {
  466. if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
  467. &h) == 0)
  468. data->temp11[4] = h << 8;
  469. }
  470. lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
  471. LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
  472. if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
  473. data->temp11[1] = h << 8;
  474. if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
  475. && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
  476. &l) == 0)
  477. data->temp11[1] |= l;
  478. }
  479. if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
  480. data->temp11[2] = h << 8;
  481. if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
  482. && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
  483. &l) == 0)
  484. data->temp11[2] |= l;
  485. }
  486. if (data->flags & LM90_HAVE_OFFSET) {
  487. if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
  488. &h) == 0
  489. && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
  490. &l) == 0)
  491. data->temp11[3] = (h << 8) | l;
  492. }
  493. if (data->flags & LM90_HAVE_EMERGENCY) {
  494. lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG,
  495. &data->temp8[4]);
  496. lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
  497. &data->temp8[5]);
  498. }
  499. lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
  500. data->alarms = alarms; /* save as 16 bit value */
  501. if (data->kind == max6696) {
  502. lm90_select_remote_channel(client, data, 1);
  503. lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
  504. &data->temp8[6]);
  505. lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
  506. &data->temp8[7]);
  507. lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
  508. LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]);
  509. if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h))
  510. data->temp11[6] = h << 8;
  511. if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h))
  512. data->temp11[7] = h << 8;
  513. lm90_select_remote_channel(client, data, 0);
  514. if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2,
  515. &alarms))
  516. data->alarms |= alarms << 8;
  517. }
  518. /*
  519. * Re-enable ALERT# output if it was originally enabled and
  520. * relevant alarms are all clear
  521. */
  522. if ((data->config_orig & 0x80) == 0
  523. && (data->alarms & data->alert_alarms) == 0) {
  524. u8 config;
  525. lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
  526. if (config & 0x80) {
  527. dev_dbg(&client->dev, "Re-enabling ALERT#\n");
  528. i2c_smbus_write_byte_data(client,
  529. LM90_REG_W_CONFIG1,
  530. config & ~0x80);
  531. }
  532. }
  533. data->last_updated = jiffies;
  534. data->valid = 1;
  535. }
  536. mutex_unlock(&data->update_lock);
  537. return data;
  538. }
  539. /*
  540. * Conversions
  541. * For local temperatures and limits, critical limits and the hysteresis
  542. * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
  543. * For remote temperatures and limits, it uses signed 11-bit values with
  544. * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
  545. * Maxim chips use unsigned values.
  546. */
  547. static inline int temp_from_s8(s8 val)
  548. {
  549. return val * 1000;
  550. }
  551. static inline int temp_from_u8(u8 val)
  552. {
  553. return val * 1000;
  554. }
  555. static inline int temp_from_s16(s16 val)
  556. {
  557. return val / 32 * 125;
  558. }
  559. static inline int temp_from_u16(u16 val)
  560. {
  561. return val / 32 * 125;
  562. }
  563. static s8 temp_to_s8(long val)
  564. {
  565. if (val <= -128000)
  566. return -128;
  567. if (val >= 127000)
  568. return 127;
  569. if (val < 0)
  570. return (val - 500) / 1000;
  571. return (val + 500) / 1000;
  572. }
  573. static u8 temp_to_u8(long val)
  574. {
  575. if (val <= 0)
  576. return 0;
  577. if (val >= 255000)
  578. return 255;
  579. return (val + 500) / 1000;
  580. }
  581. static s16 temp_to_s16(long val)
  582. {
  583. if (val <= -128000)
  584. return 0x8000;
  585. if (val >= 127875)
  586. return 0x7FE0;
  587. if (val < 0)
  588. return (val - 62) / 125 * 32;
  589. return (val + 62) / 125 * 32;
  590. }
  591. static u8 hyst_to_reg(long val)
  592. {
  593. if (val <= 0)
  594. return 0;
  595. if (val >= 30500)
  596. return 31;
  597. return (val + 500) / 1000;
  598. }
  599. /*
  600. * ADT7461 in compatibility mode is almost identical to LM90 except that
  601. * attempts to write values that are outside the range 0 < temp < 127 are
  602. * treated as the boundary value.
  603. *
  604. * ADT7461 in "extended mode" operation uses unsigned integers offset by
  605. * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
  606. */
  607. static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val)
  608. {
  609. if (data->flags & LM90_FLAG_ADT7461_EXT)
  610. return (val - 64) * 1000;
  611. else
  612. return temp_from_s8(val);
  613. }
  614. static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
  615. {
  616. if (data->flags & LM90_FLAG_ADT7461_EXT)
  617. return (val - 0x4000) / 64 * 250;
  618. else
  619. return temp_from_s16(val);
  620. }
  621. static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
  622. {
  623. if (data->flags & LM90_FLAG_ADT7461_EXT) {
  624. if (val <= -64000)
  625. return 0;
  626. if (val >= 191000)
  627. return 0xFF;
  628. return (val + 500 + 64000) / 1000;
  629. } else {
  630. if (val <= 0)
  631. return 0;
  632. if (val >= 127000)
  633. return 127;
  634. return (val + 500) / 1000;
  635. }
  636. }
  637. static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  638. {
  639. if (data->flags & LM90_FLAG_ADT7461_EXT) {
  640. if (val <= -64000)
  641. return 0;
  642. if (val >= 191750)
  643. return 0xFFC0;
  644. return (val + 64000 + 125) / 250 * 64;
  645. } else {
  646. if (val <= 0)
  647. return 0;
  648. if (val >= 127750)
  649. return 0x7FC0;
  650. return (val + 125) / 250 * 64;
  651. }
  652. }
  653. /*
  654. * Sysfs stuff
  655. */
  656. static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
  657. char *buf)
  658. {
  659. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  660. struct lm90_data *data = lm90_update_device(dev);
  661. int temp;
  662. if (data->kind == adt7461)
  663. temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
  664. else if (data->kind == max6646)
  665. temp = temp_from_u8(data->temp8[attr->index]);
  666. else
  667. temp = temp_from_s8(data->temp8[attr->index]);
  668. /* +16 degrees offset for temp2 for the LM99 */
  669. if (data->kind == lm99 && attr->index == 3)
  670. temp += 16000;
  671. return sprintf(buf, "%d\n", temp);
  672. }
  673. static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
  674. const char *buf, size_t count)
  675. {
  676. static const u8 reg[8] = {
  677. LM90_REG_W_LOCAL_LOW,
  678. LM90_REG_W_LOCAL_HIGH,
  679. LM90_REG_W_LOCAL_CRIT,
  680. LM90_REG_W_REMOTE_CRIT,
  681. MAX6659_REG_W_LOCAL_EMERG,
  682. MAX6659_REG_W_REMOTE_EMERG,
  683. LM90_REG_W_REMOTE_CRIT,
  684. MAX6659_REG_W_REMOTE_EMERG,
  685. };
  686. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  687. struct i2c_client *client = to_i2c_client(dev);
  688. struct lm90_data *data = i2c_get_clientdata(client);
  689. int nr = attr->index;
  690. long val;
  691. int err;
  692. err = kstrtol(buf, 10, &val);
  693. if (err < 0)
  694. return err;
  695. /* +16 degrees offset for temp2 for the LM99 */
  696. if (data->kind == lm99 && attr->index == 3)
  697. val -= 16000;
  698. mutex_lock(&data->update_lock);
  699. if (data->kind == adt7461)
  700. data->temp8[nr] = temp_to_u8_adt7461(data, val);
  701. else if (data->kind == max6646)
  702. data->temp8[nr] = temp_to_u8(val);
  703. else
  704. data->temp8[nr] = temp_to_s8(val);
  705. lm90_select_remote_channel(client, data, nr >= 6);
  706. i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
  707. lm90_select_remote_channel(client, data, 0);
  708. mutex_unlock(&data->update_lock);
  709. return count;
  710. }
  711. static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
  712. char *buf)
  713. {
  714. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  715. struct lm90_data *data = lm90_update_device(dev);
  716. int temp;
  717. if (data->kind == adt7461)
  718. temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
  719. else if (data->kind == max6646)
  720. temp = temp_from_u16(data->temp11[attr->index]);
  721. else
  722. temp = temp_from_s16(data->temp11[attr->index]);
  723. /* +16 degrees offset for temp2 for the LM99 */
  724. if (data->kind == lm99 && attr->index <= 2)
  725. temp += 16000;
  726. return sprintf(buf, "%d\n", temp);
  727. }
  728. static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
  729. const char *buf, size_t count)
  730. {
  731. struct {
  732. u8 high;
  733. u8 low;
  734. int channel;
  735. } reg[5] = {
  736. { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 0 },
  737. { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 0 },
  738. { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL, 0 },
  739. { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 1 },
  740. { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
  741. };
  742. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  743. struct i2c_client *client = to_i2c_client(dev);
  744. struct lm90_data *data = i2c_get_clientdata(client);
  745. int nr = attr->nr;
  746. int index = attr->index;
  747. long val;
  748. int err;
  749. err = kstrtol(buf, 10, &val);
  750. if (err < 0)
  751. return err;
  752. /* +16 degrees offset for temp2 for the LM99 */
  753. if (data->kind == lm99 && index <= 2)
  754. val -= 16000;
  755. mutex_lock(&data->update_lock);
  756. if (data->kind == adt7461)
  757. data->temp11[index] = temp_to_u16_adt7461(data, val);
  758. else if (data->kind == max6646)
  759. data->temp11[index] = temp_to_u8(val) << 8;
  760. else if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
  761. data->temp11[index] = temp_to_s16(val);
  762. else
  763. data->temp11[index] = temp_to_s8(val) << 8;
  764. lm90_select_remote_channel(client, data, reg[nr].channel);
  765. i2c_smbus_write_byte_data(client, reg[nr].high,
  766. data->temp11[index] >> 8);
  767. if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
  768. i2c_smbus_write_byte_data(client, reg[nr].low,
  769. data->temp11[index] & 0xff);
  770. lm90_select_remote_channel(client, data, 0);
  771. mutex_unlock(&data->update_lock);
  772. return count;
  773. }
  774. static ssize_t show_temphyst(struct device *dev,
  775. struct device_attribute *devattr,
  776. char *buf)
  777. {
  778. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  779. struct lm90_data *data = lm90_update_device(dev);
  780. int temp;
  781. if (data->kind == adt7461)
  782. temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
  783. else if (data->kind == max6646)
  784. temp = temp_from_u8(data->temp8[attr->index]);
  785. else
  786. temp = temp_from_s8(data->temp8[attr->index]);
  787. /* +16 degrees offset for temp2 for the LM99 */
  788. if (data->kind == lm99 && attr->index == 3)
  789. temp += 16000;
  790. return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
  791. }
  792. static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
  793. const char *buf, size_t count)
  794. {
  795. struct i2c_client *client = to_i2c_client(dev);
  796. struct lm90_data *data = i2c_get_clientdata(client);
  797. long val;
  798. int err;
  799. int temp;
  800. err = kstrtol(buf, 10, &val);
  801. if (err < 0)
  802. return err;
  803. mutex_lock(&data->update_lock);
  804. if (data->kind == adt7461)
  805. temp = temp_from_u8_adt7461(data, data->temp8[2]);
  806. else if (data->kind == max6646)
  807. temp = temp_from_u8(data->temp8[2]);
  808. else
  809. temp = temp_from_s8(data->temp8[2]);
  810. data->temp_hyst = hyst_to_reg(temp - val);
  811. i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
  812. data->temp_hyst);
  813. mutex_unlock(&data->update_lock);
  814. return count;
  815. }
  816. static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
  817. char *buf)
  818. {
  819. struct lm90_data *data = lm90_update_device(dev);
  820. return sprintf(buf, "%d\n", data->alarms);
  821. }
  822. static ssize_t show_alarm(struct device *dev, struct device_attribute
  823. *devattr, char *buf)
  824. {
  825. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  826. struct lm90_data *data = lm90_update_device(dev);
  827. int bitnr = attr->index;
  828. return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
  829. }
  830. static ssize_t show_update_interval(struct device *dev,
  831. struct device_attribute *attr, char *buf)
  832. {
  833. struct lm90_data *data = dev_get_drvdata(dev);
  834. return sprintf(buf, "%u\n", data->update_interval);
  835. }
  836. static ssize_t set_update_interval(struct device *dev,
  837. struct device_attribute *attr,
  838. const char *buf, size_t count)
  839. {
  840. struct i2c_client *client = to_i2c_client(dev);
  841. struct lm90_data *data = i2c_get_clientdata(client);
  842. unsigned long val;
  843. int err;
  844. err = kstrtoul(buf, 10, &val);
  845. if (err)
  846. return err;
  847. mutex_lock(&data->update_lock);
  848. lm90_set_convrate(client, data, clamp_val(val, 0, 100000));
  849. mutex_unlock(&data->update_lock);
  850. return count;
  851. }
  852. static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4);
  853. static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0);
  854. static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
  855. set_temp8, 0);
  856. static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
  857. set_temp11, 0, 1);
  858. static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
  859. set_temp8, 1);
  860. static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
  861. set_temp11, 1, 2);
  862. static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
  863. set_temp8, 2);
  864. static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
  865. set_temp8, 3);
  866. static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
  867. set_temphyst, 2);
  868. static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
  869. static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
  870. set_temp11, 2, 3);
  871. /* Individual alarm files */
  872. static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
  873. static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
  874. static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
  875. static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
  876. static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
  877. static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
  878. static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
  879. /* Raw alarm file for compatibility */
  880. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  881. static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval,
  882. set_update_interval);
  883. static struct attribute *lm90_attributes[] = {
  884. &sensor_dev_attr_temp1_input.dev_attr.attr,
  885. &sensor_dev_attr_temp2_input.dev_attr.attr,
  886. &sensor_dev_attr_temp1_min.dev_attr.attr,
  887. &sensor_dev_attr_temp2_min.dev_attr.attr,
  888. &sensor_dev_attr_temp1_max.dev_attr.attr,
  889. &sensor_dev_attr_temp2_max.dev_attr.attr,
  890. &sensor_dev_attr_temp1_crit.dev_attr.attr,
  891. &sensor_dev_attr_temp2_crit.dev_attr.attr,
  892. &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
  893. &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
  894. &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
  895. &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
  896. &sensor_dev_attr_temp2_fault.dev_attr.attr,
  897. &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
  898. &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
  899. &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
  900. &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  901. &dev_attr_alarms.attr,
  902. &dev_attr_update_interval.attr,
  903. NULL
  904. };
  905. static const struct attribute_group lm90_group = {
  906. .attrs = lm90_attributes,
  907. };
  908. /*
  909. * Additional attributes for devices with emergency sensors
  910. */
  911. static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8,
  912. set_temp8, 4);
  913. static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8,
  914. set_temp8, 5);
  915. static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst,
  916. NULL, 4);
  917. static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst,
  918. NULL, 5);
  919. static struct attribute *lm90_emergency_attributes[] = {
  920. &sensor_dev_attr_temp1_emergency.dev_attr.attr,
  921. &sensor_dev_attr_temp2_emergency.dev_attr.attr,
  922. &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr,
  923. &sensor_dev_attr_temp2_emergency_hyst.dev_attr.attr,
  924. NULL
  925. };
  926. static const struct attribute_group lm90_emergency_group = {
  927. .attrs = lm90_emergency_attributes,
  928. };
  929. static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, show_alarm, NULL, 15);
  930. static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 13);
  931. static struct attribute *lm90_emergency_alarm_attributes[] = {
  932. &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr,
  933. &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
  934. NULL
  935. };
  936. static const struct attribute_group lm90_emergency_alarm_group = {
  937. .attrs = lm90_emergency_alarm_attributes,
  938. };
  939. /*
  940. * Additional attributes for devices with 3 temperature sensors
  941. */
  942. static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL, 0, 5);
  943. static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11,
  944. set_temp11, 3, 6);
  945. static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11,
  946. set_temp11, 4, 7);
  947. static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8,
  948. set_temp8, 6);
  949. static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL, 6);
  950. static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8,
  951. set_temp8, 7);
  952. static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst,
  953. NULL, 7);
  954. static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
  955. static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10);
  956. static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
  957. static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 12);
  958. static SENSOR_DEVICE_ATTR(temp3_emergency_alarm, S_IRUGO, show_alarm, NULL, 14);
  959. static struct attribute *lm90_temp3_attributes[] = {
  960. &sensor_dev_attr_temp3_input.dev_attr.attr,
  961. &sensor_dev_attr_temp3_min.dev_attr.attr,
  962. &sensor_dev_attr_temp3_max.dev_attr.attr,
  963. &sensor_dev_attr_temp3_crit.dev_attr.attr,
  964. &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
  965. &sensor_dev_attr_temp3_emergency.dev_attr.attr,
  966. &sensor_dev_attr_temp3_emergency_hyst.dev_attr.attr,
  967. &sensor_dev_attr_temp3_fault.dev_attr.attr,
  968. &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
  969. &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
  970. &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
  971. &sensor_dev_attr_temp3_emergency_alarm.dev_attr.attr,
  972. NULL
  973. };
  974. static const struct attribute_group lm90_temp3_group = {
  975. .attrs = lm90_temp3_attributes,
  976. };
  977. /* pec used for ADM1032 only */
  978. static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
  979. char *buf)
  980. {
  981. struct i2c_client *client = to_i2c_client(dev);
  982. return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
  983. }
  984. static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
  985. const char *buf, size_t count)
  986. {
  987. struct i2c_client *client = to_i2c_client(dev);
  988. long val;
  989. int err;
  990. err = kstrtol(buf, 10, &val);
  991. if (err < 0)
  992. return err;
  993. switch (val) {
  994. case 0:
  995. client->flags &= ~I2C_CLIENT_PEC;
  996. break;
  997. case 1:
  998. client->flags |= I2C_CLIENT_PEC;
  999. break;
  1000. default:
  1001. return -EINVAL;
  1002. }
  1003. return count;
  1004. }
  1005. static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
  1006. /*
  1007. * Real code
  1008. */
  1009. /* Return 0 if detection is successful, -ENODEV otherwise */
  1010. static int lm90_detect(struct i2c_client *client,
  1011. struct i2c_board_info *info)
  1012. {
  1013. struct i2c_adapter *adapter = client->adapter;
  1014. int address = client->addr;
  1015. const char *name = NULL;
  1016. int man_id, chip_id, config1, config2, convrate;
  1017. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1018. return -ENODEV;
  1019. /* detection and identification */
  1020. man_id = i2c_smbus_read_byte_data(client, LM90_REG_R_MAN_ID);
  1021. chip_id = i2c_smbus_read_byte_data(client, LM90_REG_R_CHIP_ID);
  1022. config1 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1);
  1023. convrate = i2c_smbus_read_byte_data(client, LM90_REG_R_CONVRATE);
  1024. if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0)
  1025. return -ENODEV;
  1026. if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) {
  1027. config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2);
  1028. if (config2 < 0)
  1029. return -ENODEV;
  1030. } else
  1031. config2 = 0; /* Make compiler happy */
  1032. if ((address == 0x4C || address == 0x4D)
  1033. && man_id == 0x01) { /* National Semiconductor */
  1034. if ((config1 & 0x2A) == 0x00
  1035. && (config2 & 0xF8) == 0x00
  1036. && convrate <= 0x09) {
  1037. if (address == 0x4C
  1038. && (chip_id & 0xF0) == 0x20) { /* LM90 */
  1039. name = "lm90";
  1040. } else
  1041. if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
  1042. name = "lm99";
  1043. dev_info(&adapter->dev,
  1044. "Assuming LM99 chip at 0x%02x\n",
  1045. address);
  1046. dev_info(&adapter->dev,
  1047. "If it is an LM89, instantiate it "
  1048. "with the new_device sysfs "
  1049. "interface\n");
  1050. } else
  1051. if (address == 0x4C
  1052. && (chip_id & 0xF0) == 0x10) { /* LM86 */
  1053. name = "lm86";
  1054. }
  1055. }
  1056. } else
  1057. if ((address == 0x4C || address == 0x4D)
  1058. && man_id == 0x41) { /* Analog Devices */
  1059. if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
  1060. && (config1 & 0x3F) == 0x00
  1061. && convrate <= 0x0A) {
  1062. name = "adm1032";
  1063. /*
  1064. * The ADM1032 supports PEC, but only if combined
  1065. * transactions are not used.
  1066. */
  1067. if (i2c_check_functionality(adapter,
  1068. I2C_FUNC_SMBUS_BYTE))
  1069. info->flags |= I2C_CLIENT_PEC;
  1070. } else
  1071. if (chip_id == 0x51 /* ADT7461 */
  1072. && (config1 & 0x1B) == 0x00
  1073. && convrate <= 0x0A) {
  1074. name = "adt7461";
  1075. } else
  1076. if (chip_id == 0x57 /* ADT7461A, NCT1008 */
  1077. && (config1 & 0x1B) == 0x00
  1078. && convrate <= 0x0A) {
  1079. name = "adt7461a";
  1080. }
  1081. } else
  1082. if (man_id == 0x4D) { /* Maxim */
  1083. int emerg, emerg2, status2;
  1084. /*
  1085. * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read
  1086. * LM90_REG_R_MAN_ID in between. If MAX6659_REG_R_REMOTE_EMERG
  1087. * exists, both readings will reflect the same value. Otherwise,
  1088. * the readings will be different.
  1089. */
  1090. emerg = i2c_smbus_read_byte_data(client,
  1091. MAX6659_REG_R_REMOTE_EMERG);
  1092. man_id = i2c_smbus_read_byte_data(client,
  1093. LM90_REG_R_MAN_ID);
  1094. emerg2 = i2c_smbus_read_byte_data(client,
  1095. MAX6659_REG_R_REMOTE_EMERG);
  1096. status2 = i2c_smbus_read_byte_data(client,
  1097. MAX6696_REG_R_STATUS2);
  1098. if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0)
  1099. return -ENODEV;
  1100. /*
  1101. * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id
  1102. * register. Reading from that address will return the last
  1103. * read value, which in our case is those of the man_id
  1104. * register. Likewise, the config1 register seems to lack a
  1105. * low nibble, so the value will be those of the previous
  1106. * read, so in our case those of the man_id register.
  1107. * MAX6659 has a third set of upper temperature limit registers.
  1108. * Those registers also return values on MAX6657 and MAX6658,
  1109. * thus the only way to detect MAX6659 is by its address.
  1110. * For this reason it will be mis-detected as MAX6657 if its
  1111. * address is 0x4C.
  1112. */
  1113. if (chip_id == man_id
  1114. && (address == 0x4C || address == 0x4D || address == 0x4E)
  1115. && (config1 & 0x1F) == (man_id & 0x0F)
  1116. && convrate <= 0x09) {
  1117. if (address == 0x4C)
  1118. name = "max6657";
  1119. else
  1120. name = "max6659";
  1121. } else
  1122. /*
  1123. * Even though MAX6695 and MAX6696 do not have a chip ID
  1124. * register, reading it returns 0x01. Bit 4 of the config1
  1125. * register is unused and should return zero when read. Bit 0 of
  1126. * the status2 register is unused and should return zero when
  1127. * read.
  1128. *
  1129. * MAX6695 and MAX6696 have an additional set of temperature
  1130. * limit registers. We can detect those chips by checking if
  1131. * one of those registers exists.
  1132. */
  1133. if (chip_id == 0x01
  1134. && (config1 & 0x10) == 0x00
  1135. && (status2 & 0x01) == 0x00
  1136. && emerg == emerg2
  1137. && convrate <= 0x07) {
  1138. name = "max6696";
  1139. } else
  1140. /*
  1141. * The chip_id register of the MAX6680 and MAX6681 holds the
  1142. * revision of the chip. The lowest bit of the config1 register
  1143. * is unused and should return zero when read, so should the
  1144. * second to last bit of config1 (software reset).
  1145. */
  1146. if (chip_id == 0x01
  1147. && (config1 & 0x03) == 0x00
  1148. && convrate <= 0x07) {
  1149. name = "max6680";
  1150. } else
  1151. /*
  1152. * The chip_id register of the MAX6646/6647/6649 holds the
  1153. * revision of the chip. The lowest 6 bits of the config1
  1154. * register are unused and should return zero when read.
  1155. */
  1156. if (chip_id == 0x59
  1157. && (config1 & 0x3f) == 0x00
  1158. && convrate <= 0x07) {
  1159. name = "max6646";
  1160. }
  1161. } else
  1162. if (address == 0x4C
  1163. && man_id == 0x5C) { /* Winbond/Nuvoton */
  1164. if ((config1 & 0x2A) == 0x00
  1165. && (config2 & 0xF8) == 0x00) {
  1166. if (chip_id == 0x01 /* W83L771W/G */
  1167. && convrate <= 0x09) {
  1168. name = "w83l771";
  1169. } else
  1170. if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
  1171. && convrate <= 0x08) {
  1172. name = "w83l771";
  1173. }
  1174. }
  1175. } else
  1176. if (address >= 0x48 && address <= 0x4F
  1177. && man_id == 0xA1) { /* NXP Semiconductor/Philips */
  1178. if (chip_id == 0x00
  1179. && (config1 & 0x2A) == 0x00
  1180. && (config2 & 0xFE) == 0x00
  1181. && convrate <= 0x09) {
  1182. name = "sa56004";
  1183. }
  1184. } else
  1185. if ((address == 0x4C || address == 0x4D)
  1186. && man_id == 0x47) { /* GMT */
  1187. if (chip_id == 0x01 /* G781 */
  1188. && (config1 & 0x3F) == 0x00
  1189. && convrate <= 0x08)
  1190. name = "g781";
  1191. }
  1192. if (!name) { /* identification failed */
  1193. dev_dbg(&adapter->dev,
  1194. "Unsupported chip at 0x%02x (man_id=0x%02X, "
  1195. "chip_id=0x%02X)\n", address, man_id, chip_id);
  1196. return -ENODEV;
  1197. }
  1198. strlcpy(info->type, name, I2C_NAME_SIZE);
  1199. return 0;
  1200. }
  1201. static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
  1202. {
  1203. struct device *dev = &client->dev;
  1204. if (data->flags & LM90_HAVE_TEMP3)
  1205. sysfs_remove_group(&dev->kobj, &lm90_temp3_group);
  1206. if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
  1207. sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group);
  1208. if (data->flags & LM90_HAVE_EMERGENCY)
  1209. sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
  1210. if (data->flags & LM90_HAVE_OFFSET)
  1211. device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
  1212. device_remove_file(dev, &dev_attr_pec);
  1213. sysfs_remove_group(&dev->kobj, &lm90_group);
  1214. }
  1215. static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
  1216. {
  1217. /* Restore initial configuration */
  1218. i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
  1219. data->convrate_orig);
  1220. i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
  1221. data->config_orig);
  1222. }
  1223. static void lm90_init_client(struct i2c_client *client)
  1224. {
  1225. u8 config, convrate;
  1226. struct lm90_data *data = i2c_get_clientdata(client);
  1227. if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
  1228. dev_warn(&client->dev, "Failed to read convrate register!\n");
  1229. convrate = LM90_DEF_CONVRATE_RVAL;
  1230. }
  1231. data->convrate_orig = convrate;
  1232. /*
  1233. * Start the conversions.
  1234. */
  1235. lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */
  1236. if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
  1237. dev_warn(&client->dev, "Initialization failed!\n");
  1238. return;
  1239. }
  1240. data->config_orig = config;
  1241. /* Check Temperature Range Select */
  1242. if (data->kind == adt7461) {
  1243. if (config & 0x04)
  1244. data->flags |= LM90_FLAG_ADT7461_EXT;
  1245. }
  1246. /*
  1247. * Put MAX6680/MAX8881 into extended resolution (bit 0x10,
  1248. * 0.125 degree resolution) and range (0x08, extend range
  1249. * to -64 degree) mode for the remote temperature sensor.
  1250. */
  1251. if (data->kind == max6680)
  1252. config |= 0x18;
  1253. /*
  1254. * Select external channel 0 for max6695/96
  1255. */
  1256. if (data->kind == max6696)
  1257. config &= ~0x08;
  1258. config &= 0xBF; /* run */
  1259. if (config != data->config_orig) /* Only write if changed */
  1260. i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
  1261. }
  1262. static bool lm90_is_tripped(struct i2c_client *client, u16 *status)
  1263. {
  1264. struct lm90_data *data = i2c_get_clientdata(client);
  1265. u8 st, st2 = 0;
  1266. lm90_read_reg(client, LM90_REG_R_STATUS, &st);
  1267. if (data->kind == max6696)
  1268. lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2);
  1269. *status = st | (st2 << 8);
  1270. if ((st & 0x7f) == 0 && (st2 & 0xfe) == 0)
  1271. return false;
  1272. if ((st & (LM90_STATUS_LLOW | LM90_STATUS_LHIGH | LM90_STATUS_LTHRM)) ||
  1273. (st2 & MAX6696_STATUS2_LOT2))
  1274. dev_warn(&client->dev,
  1275. "temp%d out of range, please check!\n", 1);
  1276. if ((st & (LM90_STATUS_RLOW | LM90_STATUS_RHIGH | LM90_STATUS_RTHRM)) ||
  1277. (st2 & MAX6696_STATUS2_ROT2))
  1278. dev_warn(&client->dev,
  1279. "temp%d out of range, please check!\n", 2);
  1280. if (st & LM90_STATUS_ROPEN)
  1281. dev_warn(&client->dev,
  1282. "temp%d diode open, please check!\n", 2);
  1283. if (st2 & (MAX6696_STATUS2_R2LOW | MAX6696_STATUS2_R2HIGH |
  1284. MAX6696_STATUS2_R2THRM | MAX6696_STATUS2_R2OT2))
  1285. dev_warn(&client->dev,
  1286. "temp%d out of range, please check!\n", 3);
  1287. if (st2 & MAX6696_STATUS2_R2OPEN)
  1288. dev_warn(&client->dev,
  1289. "temp%d diode open, please check!\n", 3);
  1290. return true;
  1291. }
  1292. static irqreturn_t lm90_irq_thread(int irq, void *dev_id)
  1293. {
  1294. struct i2c_client *client = dev_id;
  1295. u16 status;
  1296. if (lm90_is_tripped(client, &status))
  1297. return IRQ_HANDLED;
  1298. else
  1299. return IRQ_NONE;
  1300. }
  1301. static int lm90_probe(struct i2c_client *client,
  1302. const struct i2c_device_id *id)
  1303. {
  1304. struct device *dev = &client->dev;
  1305. struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
  1306. struct lm90_data *data;
  1307. int err;
  1308. data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
  1309. if (!data)
  1310. return -ENOMEM;
  1311. i2c_set_clientdata(client, data);
  1312. mutex_init(&data->update_lock);
  1313. /* Set the device type */
  1314. data->kind = id->driver_data;
  1315. if (data->kind == adm1032) {
  1316. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
  1317. client->flags &= ~I2C_CLIENT_PEC;
  1318. }
  1319. /*
  1320. * Different devices have different alarm bits triggering the
  1321. * ALERT# output
  1322. */
  1323. data->alert_alarms = lm90_params[data->kind].alert_alarms;
  1324. /* Set chip capabilities */
  1325. data->flags = lm90_params[data->kind].flags;
  1326. data->reg_local_ext = lm90_params[data->kind].reg_local_ext;
  1327. /* Set maximum conversion rate */
  1328. data->max_convrate = lm90_params[data->kind].max_convrate;
  1329. /* Initialize the LM90 chip */
  1330. lm90_init_client(client);
  1331. /* Register sysfs hooks */
  1332. err = sysfs_create_group(&dev->kobj, &lm90_group);
  1333. if (err)
  1334. goto exit_restore;
  1335. if (client->flags & I2C_CLIENT_PEC) {
  1336. err = device_create_file(dev, &dev_attr_pec);
  1337. if (err)
  1338. goto exit_remove_files;
  1339. }
  1340. if (data->flags & LM90_HAVE_OFFSET) {
  1341. err = device_create_file(dev,
  1342. &sensor_dev_attr_temp2_offset.dev_attr);
  1343. if (err)
  1344. goto exit_remove_files;
  1345. }
  1346. if (data->flags & LM90_HAVE_EMERGENCY) {
  1347. err = sysfs_create_group(&dev->kobj, &lm90_emergency_group);
  1348. if (err)
  1349. goto exit_remove_files;
  1350. }
  1351. if (data->flags & LM90_HAVE_EMERGENCY_ALARM) {
  1352. err = sysfs_create_group(&dev->kobj,
  1353. &lm90_emergency_alarm_group);
  1354. if (err)
  1355. goto exit_remove_files;
  1356. }
  1357. if (data->flags & LM90_HAVE_TEMP3) {
  1358. err = sysfs_create_group(&dev->kobj, &lm90_temp3_group);
  1359. if (err)
  1360. goto exit_remove_files;
  1361. }
  1362. data->hwmon_dev = hwmon_device_register(dev);
  1363. if (IS_ERR(data->hwmon_dev)) {
  1364. err = PTR_ERR(data->hwmon_dev);
  1365. goto exit_remove_files;
  1366. }
  1367. if (client->irq) {
  1368. dev_dbg(dev, "IRQ: %d\n", client->irq);
  1369. err = devm_request_threaded_irq(dev, client->irq,
  1370. NULL, lm90_irq_thread,
  1371. IRQF_TRIGGER_LOW | IRQF_ONESHOT,
  1372. "lm90", client);
  1373. if (err < 0) {
  1374. dev_err(dev, "cannot request IRQ %d\n", client->irq);
  1375. goto exit_remove_files;
  1376. }
  1377. }
  1378. return 0;
  1379. exit_remove_files:
  1380. lm90_remove_files(client, data);
  1381. exit_restore:
  1382. lm90_restore_conf(client, data);
  1383. return err;
  1384. }
  1385. static int lm90_remove(struct i2c_client *client)
  1386. {
  1387. struct lm90_data *data = i2c_get_clientdata(client);
  1388. hwmon_device_unregister(data->hwmon_dev);
  1389. lm90_remove_files(client, data);
  1390. lm90_restore_conf(client, data);
  1391. return 0;
  1392. }
  1393. static void lm90_alert(struct i2c_client *client, unsigned int flag)
  1394. {
  1395. u16 alarms;
  1396. if (lm90_is_tripped(client, &alarms)) {
  1397. /*
  1398. * Disable ALERT# output, because these chips don't implement
  1399. * SMBus alert correctly; they should only hold the alert line
  1400. * low briefly.
  1401. */
  1402. struct lm90_data *data = i2c_get_clientdata(client);
  1403. if ((data->flags & LM90_HAVE_BROKEN_ALERT)
  1404. && (alarms & data->alert_alarms)) {
  1405. u8 config;
  1406. dev_dbg(&client->dev, "Disabling ALERT#\n");
  1407. lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
  1408. i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
  1409. config | 0x80);
  1410. }
  1411. } else {
  1412. dev_info(&client->dev, "Everything OK\n");
  1413. }
  1414. }
  1415. static struct i2c_driver lm90_driver = {
  1416. .class = I2C_CLASS_HWMON,
  1417. .driver = {
  1418. .name = "lm90",
  1419. },
  1420. .probe = lm90_probe,
  1421. .remove = lm90_remove,
  1422. .alert = lm90_alert,
  1423. .id_table = lm90_id,
  1424. .detect = lm90_detect,
  1425. .address_list = normal_i2c,
  1426. };
  1427. module_i2c_driver(lm90_driver);
  1428. MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
  1429. MODULE_DESCRIPTION("LM90/ADM1032 driver");
  1430. MODULE_LICENSE("GPL");