adt7462.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946
  1. /*
  2. * A hwmon driver for the Analog Devices ADT7462
  3. * Copyright (C) 2008 IBM
  4. *
  5. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/module.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/i2c.h>
  24. #include <linux/hwmon.h>
  25. #include <linux/hwmon-sysfs.h>
  26. #include <linux/err.h>
  27. #include <linux/mutex.h>
  28. #include <linux/log2.h>
  29. #include <linux/slab.h>
  30. /* Addresses to scan */
  31. static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
  32. /* ADT7462 registers */
  33. #define ADT7462_REG_DEVICE 0x3D
  34. #define ADT7462_REG_VENDOR 0x3E
  35. #define ADT7462_REG_REVISION 0x3F
  36. #define ADT7462_REG_MIN_TEMP_BASE_ADDR 0x44
  37. #define ADT7462_REG_MIN_TEMP_MAX_ADDR 0x47
  38. #define ADT7462_REG_MAX_TEMP_BASE_ADDR 0x48
  39. #define ADT7462_REG_MAX_TEMP_MAX_ADDR 0x4B
  40. #define ADT7462_REG_TEMP_BASE_ADDR 0x88
  41. #define ADT7462_REG_TEMP_MAX_ADDR 0x8F
  42. #define ADT7462_REG_FAN_BASE_ADDR 0x98
  43. #define ADT7462_REG_FAN_MAX_ADDR 0x9F
  44. #define ADT7462_REG_FAN2_BASE_ADDR 0xA2
  45. #define ADT7462_REG_FAN2_MAX_ADDR 0xA9
  46. #define ADT7462_REG_FAN_ENABLE 0x07
  47. #define ADT7462_REG_FAN_MIN_BASE_ADDR 0x78
  48. #define ADT7462_REG_FAN_MIN_MAX_ADDR 0x7F
  49. #define ADT7462_REG_CFG2 0x02
  50. #define ADT7462_FSPD_MASK 0x20
  51. #define ADT7462_REG_PWM_BASE_ADDR 0xAA
  52. #define ADT7462_REG_PWM_MAX_ADDR 0xAD
  53. #define ADT7462_REG_PWM_MIN_BASE_ADDR 0x28
  54. #define ADT7462_REG_PWM_MIN_MAX_ADDR 0x2B
  55. #define ADT7462_REG_PWM_MAX 0x2C
  56. #define ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR 0x5C
  57. #define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F
  58. #define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60
  59. #define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63
  60. #define ADT7462_PWM_HYST_MASK 0x0F
  61. #define ADT7462_PWM_RANGE_MASK 0xF0
  62. #define ADT7462_PWM_RANGE_SHIFT 4
  63. #define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21
  64. #define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24
  65. #define ADT7462_PWM_CHANNEL_MASK 0xE0
  66. #define ADT7462_PWM_CHANNEL_SHIFT 5
  67. #define ADT7462_REG_PIN_CFG_BASE_ADDR 0x10
  68. #define ADT7462_REG_PIN_CFG_MAX_ADDR 0x13
  69. #define ADT7462_PIN7_INPUT 0x01 /* cfg0 */
  70. #define ADT7462_DIODE3_INPUT 0x20
  71. #define ADT7462_DIODE1_INPUT 0x40
  72. #define ADT7462_VID_INPUT 0x80
  73. #define ADT7462_PIN22_INPUT 0x04 /* cfg1 */
  74. #define ADT7462_PIN21_INPUT 0x08
  75. #define ADT7462_PIN19_INPUT 0x10
  76. #define ADT7462_PIN15_INPUT 0x20
  77. #define ADT7462_PIN13_INPUT 0x40
  78. #define ADT7462_PIN8_INPUT 0x80
  79. #define ADT7462_PIN23_MASK 0x03
  80. #define ADT7462_PIN23_SHIFT 0
  81. #define ADT7462_PIN26_MASK 0x0C /* cfg2 */
  82. #define ADT7462_PIN26_SHIFT 2
  83. #define ADT7462_PIN25_MASK 0x30
  84. #define ADT7462_PIN25_SHIFT 4
  85. #define ADT7462_PIN24_MASK 0xC0
  86. #define ADT7462_PIN24_SHIFT 6
  87. #define ADT7462_PIN26_VOLT_INPUT 0x08
  88. #define ADT7462_PIN25_VOLT_INPUT 0x20
  89. #define ADT7462_PIN28_SHIFT 4 /* cfg3 */
  90. #define ADT7462_PIN28_VOLT 0x5
  91. #define ADT7462_REG_ALARM1 0xB8
  92. #define ADT7462_LT_ALARM 0x02
  93. #define ADT7462_R1T_ALARM 0x04
  94. #define ADT7462_R2T_ALARM 0x08
  95. #define ADT7462_R3T_ALARM 0x10
  96. #define ADT7462_REG_ALARM2 0xBB
  97. #define ADT7462_V0_ALARM 0x01
  98. #define ADT7462_V1_ALARM 0x02
  99. #define ADT7462_V2_ALARM 0x04
  100. #define ADT7462_V3_ALARM 0x08
  101. #define ADT7462_V4_ALARM 0x10
  102. #define ADT7462_V5_ALARM 0x20
  103. #define ADT7462_V6_ALARM 0x40
  104. #define ADT7462_V7_ALARM 0x80
  105. #define ADT7462_REG_ALARM3 0xBC
  106. #define ADT7462_V8_ALARM 0x08
  107. #define ADT7462_V9_ALARM 0x10
  108. #define ADT7462_V10_ALARM 0x20
  109. #define ADT7462_V11_ALARM 0x40
  110. #define ADT7462_V12_ALARM 0x80
  111. #define ADT7462_REG_ALARM4 0xBD
  112. #define ADT7462_F0_ALARM 0x01
  113. #define ADT7462_F1_ALARM 0x02
  114. #define ADT7462_F2_ALARM 0x04
  115. #define ADT7462_F3_ALARM 0x08
  116. #define ADT7462_F4_ALARM 0x10
  117. #define ADT7462_F5_ALARM 0x20
  118. #define ADT7462_F6_ALARM 0x40
  119. #define ADT7462_F7_ALARM 0x80
  120. #define ADT7462_ALARM1 0x0000
  121. #define ADT7462_ALARM2 0x0100
  122. #define ADT7462_ALARM3 0x0200
  123. #define ADT7462_ALARM4 0x0300
  124. #define ADT7462_ALARM_REG_SHIFT 8
  125. #define ADT7462_ALARM_FLAG_MASK 0x0F
  126. #define ADT7462_TEMP_COUNT 4
  127. #define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + ((x) * 2))
  128. #define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x))
  129. #define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x))
  130. #define TEMP_FRAC_OFFSET 6
  131. #define ADT7462_FAN_COUNT 8
  132. #define ADT7462_REG_FAN_MIN(x) (ADT7462_REG_FAN_MIN_BASE_ADDR + (x))
  133. #define ADT7462_PWM_COUNT 4
  134. #define ADT7462_REG_PWM(x) (ADT7462_REG_PWM_BASE_ADDR + (x))
  135. #define ADT7462_REG_PWM_MIN(x) (ADT7462_REG_PWM_MIN_BASE_ADDR + (x))
  136. #define ADT7462_REG_PWM_TMIN(x) \
  137. (ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
  138. #define ADT7462_REG_PWM_TRANGE(x) \
  139. (ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR + (x))
  140. #define ADT7462_PIN_CFG_REG_COUNT 4
  141. #define ADT7462_REG_PIN_CFG(x) (ADT7462_REG_PIN_CFG_BASE_ADDR + (x))
  142. #define ADT7462_REG_PWM_CFG(x) (ADT7462_REG_PWM_CFG_BASE_ADDR + (x))
  143. #define ADT7462_ALARM_REG_COUNT 4
  144. /*
  145. * The chip can measure 13 different voltage sources:
  146. *
  147. * 1. +12V1 (pin 7)
  148. * 2. Vccp1/+2.5V/+1.8V/+1.5V (pin 23)
  149. * 3. +12V3 (pin 22)
  150. * 4. +5V (pin 21)
  151. * 5. +1.25V/+0.9V (pin 19)
  152. * 6. +2.5V/+1.8V (pin 15)
  153. * 7. +3.3v (pin 13)
  154. * 8. +12V2 (pin 8)
  155. * 9. Vbatt/FSB_Vtt (pin 26)
  156. * A. +3.3V/+1.2V1 (pin 25)
  157. * B. Vccp2/+2.5V/+1.8V/+1.5V (pin 24)
  158. * C. +1.5V ICH (only if BOTH pin 28/29 are set to +1.5V)
  159. * D. +1.5V 3GPIO (only if BOTH pin 28/29 are set to +1.5V)
  160. *
  161. * Each of these 13 has a factor to convert raw to voltage. Even better,
  162. * the pins can be connected to other sensors (tach/gpio/hot/etc), which
  163. * makes the bookkeeping tricky.
  164. *
  165. * Some, but not all, of these voltages have low/high limits.
  166. */
  167. #define ADT7462_VOLT_COUNT 13
  168. #define ADT7462_VENDOR 0x41
  169. #define ADT7462_DEVICE 0x62
  170. /* datasheet only mentions a revision 4 */
  171. #define ADT7462_REVISION 0x04
  172. /* How often do we reread sensors values? (In jiffies) */
  173. #define SENSOR_REFRESH_INTERVAL (2 * HZ)
  174. /* How often do we reread sensor limit values? (In jiffies) */
  175. #define LIMIT_REFRESH_INTERVAL (60 * HZ)
  176. /* datasheet says to divide this number by the fan reading to get fan rpm */
  177. #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
  178. #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
  179. #define FAN_PERIOD_INVALID 65535
  180. #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
  181. #define MASK_AND_SHIFT(value, prefix) \
  182. (((value) & prefix##_MASK) >> prefix##_SHIFT)
  183. struct adt7462_data {
  184. struct i2c_client *client;
  185. struct mutex lock;
  186. char sensors_valid;
  187. char limits_valid;
  188. unsigned long sensors_last_updated; /* In jiffies */
  189. unsigned long limits_last_updated; /* In jiffies */
  190. u8 temp[ADT7462_TEMP_COUNT];
  191. /* bits 6-7 are quarter pieces of temp */
  192. u8 temp_frac[ADT7462_TEMP_COUNT];
  193. u8 temp_min[ADT7462_TEMP_COUNT];
  194. u8 temp_max[ADT7462_TEMP_COUNT];
  195. u16 fan[ADT7462_FAN_COUNT];
  196. u8 fan_enabled;
  197. u8 fan_min[ADT7462_FAN_COUNT];
  198. u8 cfg2;
  199. u8 pwm[ADT7462_PWM_COUNT];
  200. u8 pin_cfg[ADT7462_PIN_CFG_REG_COUNT];
  201. u8 voltages[ADT7462_VOLT_COUNT];
  202. u8 volt_max[ADT7462_VOLT_COUNT];
  203. u8 volt_min[ADT7462_VOLT_COUNT];
  204. u8 pwm_min[ADT7462_PWM_COUNT];
  205. u8 pwm_tmin[ADT7462_PWM_COUNT];
  206. u8 pwm_trange[ADT7462_PWM_COUNT];
  207. u8 pwm_max; /* only one per chip */
  208. u8 pwm_cfg[ADT7462_PWM_COUNT];
  209. u8 alarms[ADT7462_ALARM_REG_COUNT];
  210. };
  211. /*
  212. * 16-bit registers on the ADT7462 are low-byte first. The data sheet says
  213. * that the low byte must be read before the high byte.
  214. */
  215. static inline int adt7462_read_word_data(struct i2c_client *client, u8 reg)
  216. {
  217. u16 foo;
  218. foo = i2c_smbus_read_byte_data(client, reg);
  219. foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
  220. return foo;
  221. }
  222. /* For some reason these registers are not contiguous. */
  223. static int ADT7462_REG_FAN(int fan)
  224. {
  225. if (fan < 4)
  226. return ADT7462_REG_FAN_BASE_ADDR + (2 * fan);
  227. return ADT7462_REG_FAN2_BASE_ADDR + (2 * (fan - 4));
  228. }
  229. /* Voltage registers are scattered everywhere */
  230. static int ADT7462_REG_VOLT_MAX(struct adt7462_data *data, int which)
  231. {
  232. switch (which) {
  233. case 0:
  234. if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
  235. return 0x7C;
  236. break;
  237. case 1:
  238. return 0x69;
  239. case 2:
  240. if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
  241. return 0x7F;
  242. break;
  243. case 3:
  244. if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
  245. return 0x7E;
  246. break;
  247. case 4:
  248. if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
  249. return 0x4B;
  250. break;
  251. case 5:
  252. if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
  253. return 0x49;
  254. break;
  255. case 6:
  256. if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
  257. return 0x68;
  258. break;
  259. case 7:
  260. if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
  261. return 0x7D;
  262. break;
  263. case 8:
  264. if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
  265. return 0x6C;
  266. break;
  267. case 9:
  268. if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
  269. return 0x6B;
  270. break;
  271. case 10:
  272. return 0x6A;
  273. case 11:
  274. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  275. ADT7462_PIN28_VOLT &&
  276. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  277. return 0x50;
  278. break;
  279. case 12:
  280. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  281. ADT7462_PIN28_VOLT &&
  282. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  283. return 0x4C;
  284. break;
  285. }
  286. return 0;
  287. }
  288. static int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which)
  289. {
  290. switch (which) {
  291. case 0:
  292. if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
  293. return 0x6D;
  294. break;
  295. case 1:
  296. return 0x72;
  297. case 2:
  298. if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
  299. return 0x6F;
  300. break;
  301. case 3:
  302. if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
  303. return 0x71;
  304. break;
  305. case 4:
  306. if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
  307. return 0x47;
  308. break;
  309. case 5:
  310. if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
  311. return 0x45;
  312. break;
  313. case 6:
  314. if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
  315. return 0x70;
  316. break;
  317. case 7:
  318. if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
  319. return 0x6E;
  320. break;
  321. case 8:
  322. if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
  323. return 0x75;
  324. break;
  325. case 9:
  326. if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
  327. return 0x74;
  328. break;
  329. case 10:
  330. return 0x73;
  331. case 11:
  332. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  333. ADT7462_PIN28_VOLT &&
  334. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  335. return 0x76;
  336. break;
  337. case 12:
  338. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  339. ADT7462_PIN28_VOLT &&
  340. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  341. return 0x77;
  342. break;
  343. }
  344. return 0;
  345. }
  346. static int ADT7462_REG_VOLT(struct adt7462_data *data, int which)
  347. {
  348. switch (which) {
  349. case 0:
  350. if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
  351. return 0xA3;
  352. break;
  353. case 1:
  354. return 0x90;
  355. case 2:
  356. if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
  357. return 0xA9;
  358. break;
  359. case 3:
  360. if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
  361. return 0xA7;
  362. break;
  363. case 4:
  364. if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
  365. return 0x8F;
  366. break;
  367. case 5:
  368. if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
  369. return 0x8B;
  370. break;
  371. case 6:
  372. if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
  373. return 0x96;
  374. break;
  375. case 7:
  376. if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
  377. return 0xA5;
  378. break;
  379. case 8:
  380. if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
  381. return 0x93;
  382. break;
  383. case 9:
  384. if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
  385. return 0x92;
  386. break;
  387. case 10:
  388. return 0x91;
  389. case 11:
  390. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  391. ADT7462_PIN28_VOLT &&
  392. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  393. return 0x94;
  394. break;
  395. case 12:
  396. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  397. ADT7462_PIN28_VOLT &&
  398. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  399. return 0x95;
  400. break;
  401. }
  402. return -ENODEV;
  403. }
  404. /* Provide labels for sysfs */
  405. static const char *voltage_label(struct adt7462_data *data, int which)
  406. {
  407. switch (which) {
  408. case 0:
  409. if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
  410. return "+12V1";
  411. break;
  412. case 1:
  413. switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
  414. case 0:
  415. return "Vccp1";
  416. case 1:
  417. return "+2.5V";
  418. case 2:
  419. return "+1.8V";
  420. case 3:
  421. return "+1.5V";
  422. }
  423. case 2:
  424. if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
  425. return "+12V3";
  426. break;
  427. case 3:
  428. if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
  429. return "+5V";
  430. break;
  431. case 4:
  432. if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
  433. if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
  434. return "+0.9V";
  435. return "+1.25V";
  436. }
  437. break;
  438. case 5:
  439. if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
  440. if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
  441. return "+1.8V";
  442. return "+2.5V";
  443. }
  444. break;
  445. case 6:
  446. if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
  447. return "+3.3V";
  448. break;
  449. case 7:
  450. if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
  451. return "+12V2";
  452. break;
  453. case 8:
  454. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
  455. case 0:
  456. return "Vbatt";
  457. case 1:
  458. return "FSB_Vtt";
  459. }
  460. break;
  461. case 9:
  462. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
  463. case 0:
  464. return "+3.3V";
  465. case 1:
  466. return "+1.2V1";
  467. }
  468. break;
  469. case 10:
  470. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
  471. case 0:
  472. return "Vccp2";
  473. case 1:
  474. return "+2.5V";
  475. case 2:
  476. return "+1.8V";
  477. case 3:
  478. return "+1.5";
  479. }
  480. case 11:
  481. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  482. ADT7462_PIN28_VOLT &&
  483. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  484. return "+1.5V ICH";
  485. break;
  486. case 12:
  487. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  488. ADT7462_PIN28_VOLT &&
  489. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  490. return "+1.5V 3GPIO";
  491. break;
  492. }
  493. return "N/A";
  494. }
  495. /* Multipliers are actually in uV, not mV. */
  496. static int voltage_multiplier(struct adt7462_data *data, int which)
  497. {
  498. switch (which) {
  499. case 0:
  500. if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
  501. return 62500;
  502. break;
  503. case 1:
  504. switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
  505. case 0:
  506. if (data->pin_cfg[0] & ADT7462_VID_INPUT)
  507. return 12500;
  508. return 6250;
  509. case 1:
  510. return 13000;
  511. case 2:
  512. return 9400;
  513. case 3:
  514. return 7800;
  515. }
  516. case 2:
  517. if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
  518. return 62500;
  519. break;
  520. case 3:
  521. if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
  522. return 26000;
  523. break;
  524. case 4:
  525. if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
  526. if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
  527. return 4690;
  528. return 6500;
  529. }
  530. break;
  531. case 5:
  532. if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
  533. if (data->pin_cfg[1] & ADT7462_PIN15_INPUT)
  534. return 9400;
  535. return 13000;
  536. }
  537. break;
  538. case 6:
  539. if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
  540. return 17200;
  541. break;
  542. case 7:
  543. if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
  544. return 62500;
  545. break;
  546. case 8:
  547. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
  548. case 0:
  549. return 15600;
  550. case 1:
  551. return 6250;
  552. }
  553. break;
  554. case 9:
  555. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
  556. case 0:
  557. return 17200;
  558. case 1:
  559. return 6250;
  560. }
  561. break;
  562. case 10:
  563. switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
  564. case 0:
  565. return 6250;
  566. case 1:
  567. return 13000;
  568. case 2:
  569. return 9400;
  570. case 3:
  571. return 7800;
  572. }
  573. case 11:
  574. case 12:
  575. if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
  576. ADT7462_PIN28_VOLT &&
  577. !(data->pin_cfg[0] & ADT7462_VID_INPUT))
  578. return 7800;
  579. }
  580. return 0;
  581. }
  582. static int temp_enabled(struct adt7462_data *data, int which)
  583. {
  584. switch (which) {
  585. case 0:
  586. case 2:
  587. return 1;
  588. case 1:
  589. if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
  590. return 1;
  591. break;
  592. case 3:
  593. if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
  594. return 1;
  595. break;
  596. }
  597. return 0;
  598. }
  599. static const char *temp_label(struct adt7462_data *data, int which)
  600. {
  601. switch (which) {
  602. case 0:
  603. return "local";
  604. case 1:
  605. if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
  606. return "remote1";
  607. break;
  608. case 2:
  609. return "remote2";
  610. case 3:
  611. if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
  612. return "remote3";
  613. break;
  614. }
  615. return "N/A";
  616. }
  617. /* Map Trange register values to mC */
  618. #define NUM_TRANGE_VALUES 16
  619. static const int trange_values[NUM_TRANGE_VALUES] = {
  620. 2000,
  621. 2500,
  622. 3300,
  623. 4000,
  624. 5000,
  625. 6700,
  626. 8000,
  627. 10000,
  628. 13300,
  629. 16000,
  630. 20000,
  631. 26700,
  632. 32000,
  633. 40000,
  634. 53300,
  635. 80000
  636. };
  637. static int find_trange_value(int trange)
  638. {
  639. int i;
  640. for (i = 0; i < NUM_TRANGE_VALUES; i++)
  641. if (trange_values[i] == trange)
  642. return i;
  643. return -EINVAL;
  644. }
  645. static struct adt7462_data *adt7462_update_device(struct device *dev)
  646. {
  647. struct adt7462_data *data = dev_get_drvdata(dev);
  648. struct i2c_client *client = data->client;
  649. unsigned long local_jiffies = jiffies;
  650. int i;
  651. mutex_lock(&data->lock);
  652. if (time_before(local_jiffies, data->sensors_last_updated +
  653. SENSOR_REFRESH_INTERVAL)
  654. && data->sensors_valid)
  655. goto no_sensor_update;
  656. for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
  657. /*
  658. * Reading the fractional register locks the integral
  659. * register until both have been read.
  660. */
  661. data->temp_frac[i] = i2c_smbus_read_byte_data(client,
  662. ADT7462_TEMP_REG(i));
  663. data->temp[i] = i2c_smbus_read_byte_data(client,
  664. ADT7462_TEMP_REG(i) + 1);
  665. }
  666. for (i = 0; i < ADT7462_FAN_COUNT; i++)
  667. data->fan[i] = adt7462_read_word_data(client,
  668. ADT7462_REG_FAN(i));
  669. data->fan_enabled = i2c_smbus_read_byte_data(client,
  670. ADT7462_REG_FAN_ENABLE);
  671. for (i = 0; i < ADT7462_PWM_COUNT; i++)
  672. data->pwm[i] = i2c_smbus_read_byte_data(client,
  673. ADT7462_REG_PWM(i));
  674. for (i = 0; i < ADT7462_PIN_CFG_REG_COUNT; i++)
  675. data->pin_cfg[i] = i2c_smbus_read_byte_data(client,
  676. ADT7462_REG_PIN_CFG(i));
  677. for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
  678. int reg = ADT7462_REG_VOLT(data, i);
  679. if (!reg)
  680. data->voltages[i] = 0;
  681. else
  682. data->voltages[i] = i2c_smbus_read_byte_data(client,
  683. reg);
  684. }
  685. data->alarms[0] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM1);
  686. data->alarms[1] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM2);
  687. data->alarms[2] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM3);
  688. data->alarms[3] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM4);
  689. data->sensors_last_updated = local_jiffies;
  690. data->sensors_valid = 1;
  691. no_sensor_update:
  692. if (time_before(local_jiffies, data->limits_last_updated +
  693. LIMIT_REFRESH_INTERVAL)
  694. && data->limits_valid)
  695. goto out;
  696. for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
  697. data->temp_min[i] = i2c_smbus_read_byte_data(client,
  698. ADT7462_TEMP_MIN_REG(i));
  699. data->temp_max[i] = i2c_smbus_read_byte_data(client,
  700. ADT7462_TEMP_MAX_REG(i));
  701. }
  702. for (i = 0; i < ADT7462_FAN_COUNT; i++)
  703. data->fan_min[i] = i2c_smbus_read_byte_data(client,
  704. ADT7462_REG_FAN_MIN(i));
  705. for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
  706. int reg = ADT7462_REG_VOLT_MAX(data, i);
  707. data->volt_max[i] =
  708. (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
  709. reg = ADT7462_REG_VOLT_MIN(data, i);
  710. data->volt_min[i] =
  711. (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
  712. }
  713. for (i = 0; i < ADT7462_PWM_COUNT; i++) {
  714. data->pwm_min[i] = i2c_smbus_read_byte_data(client,
  715. ADT7462_REG_PWM_MIN(i));
  716. data->pwm_tmin[i] = i2c_smbus_read_byte_data(client,
  717. ADT7462_REG_PWM_TMIN(i));
  718. data->pwm_trange[i] = i2c_smbus_read_byte_data(client,
  719. ADT7462_REG_PWM_TRANGE(i));
  720. data->pwm_cfg[i] = i2c_smbus_read_byte_data(client,
  721. ADT7462_REG_PWM_CFG(i));
  722. }
  723. data->pwm_max = i2c_smbus_read_byte_data(client, ADT7462_REG_PWM_MAX);
  724. data->cfg2 = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
  725. data->limits_last_updated = local_jiffies;
  726. data->limits_valid = 1;
  727. out:
  728. mutex_unlock(&data->lock);
  729. return data;
  730. }
  731. static ssize_t show_temp_min(struct device *dev,
  732. struct device_attribute *devattr,
  733. char *buf)
  734. {
  735. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  736. struct adt7462_data *data = adt7462_update_device(dev);
  737. if (!temp_enabled(data, attr->index))
  738. return sprintf(buf, "0\n");
  739. return sprintf(buf, "%d\n", 1000 * (data->temp_min[attr->index] - 64));
  740. }
  741. static ssize_t set_temp_min(struct device *dev,
  742. struct device_attribute *devattr,
  743. const char *buf,
  744. size_t count)
  745. {
  746. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  747. struct adt7462_data *data = dev_get_drvdata(dev);
  748. struct i2c_client *client = data->client;
  749. long temp;
  750. if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
  751. return -EINVAL;
  752. temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
  753. temp = clamp_val(temp, 0, 255);
  754. mutex_lock(&data->lock);
  755. data->temp_min[attr->index] = temp;
  756. i2c_smbus_write_byte_data(client, ADT7462_TEMP_MIN_REG(attr->index),
  757. temp);
  758. mutex_unlock(&data->lock);
  759. return count;
  760. }
  761. static ssize_t show_temp_max(struct device *dev,
  762. struct device_attribute *devattr,
  763. char *buf)
  764. {
  765. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  766. struct adt7462_data *data = adt7462_update_device(dev);
  767. if (!temp_enabled(data, attr->index))
  768. return sprintf(buf, "0\n");
  769. return sprintf(buf, "%d\n", 1000 * (data->temp_max[attr->index] - 64));
  770. }
  771. static ssize_t set_temp_max(struct device *dev,
  772. struct device_attribute *devattr,
  773. const char *buf,
  774. size_t count)
  775. {
  776. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  777. struct adt7462_data *data = dev_get_drvdata(dev);
  778. struct i2c_client *client = data->client;
  779. long temp;
  780. if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
  781. return -EINVAL;
  782. temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
  783. temp = clamp_val(temp, 0, 255);
  784. mutex_lock(&data->lock);
  785. data->temp_max[attr->index] = temp;
  786. i2c_smbus_write_byte_data(client, ADT7462_TEMP_MAX_REG(attr->index),
  787. temp);
  788. mutex_unlock(&data->lock);
  789. return count;
  790. }
  791. static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
  792. char *buf)
  793. {
  794. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  795. struct adt7462_data *data = adt7462_update_device(dev);
  796. u8 frac = data->temp_frac[attr->index] >> TEMP_FRAC_OFFSET;
  797. if (!temp_enabled(data, attr->index))
  798. return sprintf(buf, "0\n");
  799. return sprintf(buf, "%d\n", 1000 * (data->temp[attr->index] - 64) +
  800. 250 * frac);
  801. }
  802. static ssize_t show_temp_label(struct device *dev,
  803. struct device_attribute *devattr,
  804. char *buf)
  805. {
  806. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  807. struct adt7462_data *data = adt7462_update_device(dev);
  808. return sprintf(buf, "%s\n", temp_label(data, attr->index));
  809. }
  810. static ssize_t show_volt_max(struct device *dev,
  811. struct device_attribute *devattr,
  812. char *buf)
  813. {
  814. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  815. struct adt7462_data *data = adt7462_update_device(dev);
  816. int x = voltage_multiplier(data, attr->index);
  817. x *= data->volt_max[attr->index];
  818. x /= 1000; /* convert from uV to mV */
  819. return sprintf(buf, "%d\n", x);
  820. }
  821. static ssize_t set_volt_max(struct device *dev,
  822. struct device_attribute *devattr,
  823. const char *buf,
  824. size_t count)
  825. {
  826. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  827. struct adt7462_data *data = dev_get_drvdata(dev);
  828. struct i2c_client *client = data->client;
  829. int x = voltage_multiplier(data, attr->index);
  830. long temp;
  831. if (kstrtol(buf, 10, &temp) || !x)
  832. return -EINVAL;
  833. temp *= 1000; /* convert mV to uV */
  834. temp = DIV_ROUND_CLOSEST(temp, x);
  835. temp = clamp_val(temp, 0, 255);
  836. mutex_lock(&data->lock);
  837. data->volt_max[attr->index] = temp;
  838. i2c_smbus_write_byte_data(client,
  839. ADT7462_REG_VOLT_MAX(data, attr->index),
  840. temp);
  841. mutex_unlock(&data->lock);
  842. return count;
  843. }
  844. static ssize_t show_volt_min(struct device *dev,
  845. struct device_attribute *devattr,
  846. char *buf)
  847. {
  848. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  849. struct adt7462_data *data = adt7462_update_device(dev);
  850. int x = voltage_multiplier(data, attr->index);
  851. x *= data->volt_min[attr->index];
  852. x /= 1000; /* convert from uV to mV */
  853. return sprintf(buf, "%d\n", x);
  854. }
  855. static ssize_t set_volt_min(struct device *dev,
  856. struct device_attribute *devattr,
  857. const char *buf,
  858. size_t count)
  859. {
  860. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  861. struct adt7462_data *data = dev_get_drvdata(dev);
  862. struct i2c_client *client = data->client;
  863. int x = voltage_multiplier(data, attr->index);
  864. long temp;
  865. if (kstrtol(buf, 10, &temp) || !x)
  866. return -EINVAL;
  867. temp *= 1000; /* convert mV to uV */
  868. temp = DIV_ROUND_CLOSEST(temp, x);
  869. temp = clamp_val(temp, 0, 255);
  870. mutex_lock(&data->lock);
  871. data->volt_min[attr->index] = temp;
  872. i2c_smbus_write_byte_data(client,
  873. ADT7462_REG_VOLT_MIN(data, attr->index),
  874. temp);
  875. mutex_unlock(&data->lock);
  876. return count;
  877. }
  878. static ssize_t show_voltage(struct device *dev,
  879. struct device_attribute *devattr,
  880. char *buf)
  881. {
  882. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  883. struct adt7462_data *data = adt7462_update_device(dev);
  884. int x = voltage_multiplier(data, attr->index);
  885. x *= data->voltages[attr->index];
  886. x /= 1000; /* convert from uV to mV */
  887. return sprintf(buf, "%d\n", x);
  888. }
  889. static ssize_t show_voltage_label(struct device *dev,
  890. struct device_attribute *devattr,
  891. char *buf)
  892. {
  893. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  894. struct adt7462_data *data = adt7462_update_device(dev);
  895. return sprintf(buf, "%s\n", voltage_label(data, attr->index));
  896. }
  897. static ssize_t show_alarm(struct device *dev,
  898. struct device_attribute *devattr,
  899. char *buf)
  900. {
  901. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  902. struct adt7462_data *data = adt7462_update_device(dev);
  903. int reg = attr->index >> ADT7462_ALARM_REG_SHIFT;
  904. int mask = attr->index & ADT7462_ALARM_FLAG_MASK;
  905. if (data->alarms[reg] & mask)
  906. return sprintf(buf, "1\n");
  907. else
  908. return sprintf(buf, "0\n");
  909. }
  910. static int fan_enabled(struct adt7462_data *data, int fan)
  911. {
  912. return data->fan_enabled & (1 << fan);
  913. }
  914. static ssize_t show_fan_min(struct device *dev,
  915. struct device_attribute *devattr,
  916. char *buf)
  917. {
  918. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  919. struct adt7462_data *data = adt7462_update_device(dev);
  920. u16 temp;
  921. /* Only the MSB of the min fan period is stored... */
  922. temp = data->fan_min[attr->index];
  923. temp <<= 8;
  924. if (!fan_enabled(data, attr->index) ||
  925. !FAN_DATA_VALID(temp))
  926. return sprintf(buf, "0\n");
  927. return sprintf(buf, "%d\n", FAN_PERIOD_TO_RPM(temp));
  928. }
  929. static ssize_t set_fan_min(struct device *dev,
  930. struct device_attribute *devattr,
  931. const char *buf, size_t count)
  932. {
  933. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  934. struct adt7462_data *data = dev_get_drvdata(dev);
  935. struct i2c_client *client = data->client;
  936. long temp;
  937. if (kstrtol(buf, 10, &temp) || !temp ||
  938. !fan_enabled(data, attr->index))
  939. return -EINVAL;
  940. temp = FAN_RPM_TO_PERIOD(temp);
  941. temp >>= 8;
  942. temp = clamp_val(temp, 1, 255);
  943. mutex_lock(&data->lock);
  944. data->fan_min[attr->index] = temp;
  945. i2c_smbus_write_byte_data(client, ADT7462_REG_FAN_MIN(attr->index),
  946. temp);
  947. mutex_unlock(&data->lock);
  948. return count;
  949. }
  950. static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
  951. char *buf)
  952. {
  953. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  954. struct adt7462_data *data = adt7462_update_device(dev);
  955. if (!fan_enabled(data, attr->index) ||
  956. !FAN_DATA_VALID(data->fan[attr->index]))
  957. return sprintf(buf, "0\n");
  958. return sprintf(buf, "%d\n",
  959. FAN_PERIOD_TO_RPM(data->fan[attr->index]));
  960. }
  961. static ssize_t show_force_pwm_max(struct device *dev,
  962. struct device_attribute *devattr,
  963. char *buf)
  964. {
  965. struct adt7462_data *data = adt7462_update_device(dev);
  966. return sprintf(buf, "%d\n", (data->cfg2 & ADT7462_FSPD_MASK ? 1 : 0));
  967. }
  968. static ssize_t set_force_pwm_max(struct device *dev,
  969. struct device_attribute *devattr,
  970. const char *buf,
  971. size_t count)
  972. {
  973. struct adt7462_data *data = dev_get_drvdata(dev);
  974. struct i2c_client *client = data->client;
  975. long temp;
  976. u8 reg;
  977. if (kstrtol(buf, 10, &temp))
  978. return -EINVAL;
  979. mutex_lock(&data->lock);
  980. reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
  981. if (temp)
  982. reg |= ADT7462_FSPD_MASK;
  983. else
  984. reg &= ~ADT7462_FSPD_MASK;
  985. data->cfg2 = reg;
  986. i2c_smbus_write_byte_data(client, ADT7462_REG_CFG2, reg);
  987. mutex_unlock(&data->lock);
  988. return count;
  989. }
  990. static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
  991. char *buf)
  992. {
  993. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  994. struct adt7462_data *data = adt7462_update_device(dev);
  995. return sprintf(buf, "%d\n", data->pwm[attr->index]);
  996. }
  997. static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
  998. const char *buf, size_t count)
  999. {
  1000. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1001. struct adt7462_data *data = dev_get_drvdata(dev);
  1002. struct i2c_client *client = data->client;
  1003. long temp;
  1004. if (kstrtol(buf, 10, &temp))
  1005. return -EINVAL;
  1006. temp = clamp_val(temp, 0, 255);
  1007. mutex_lock(&data->lock);
  1008. data->pwm[attr->index] = temp;
  1009. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM(attr->index), temp);
  1010. mutex_unlock(&data->lock);
  1011. return count;
  1012. }
  1013. static ssize_t show_pwm_max(struct device *dev,
  1014. struct device_attribute *devattr,
  1015. char *buf)
  1016. {
  1017. struct adt7462_data *data = adt7462_update_device(dev);
  1018. return sprintf(buf, "%d\n", data->pwm_max);
  1019. }
  1020. static ssize_t set_pwm_max(struct device *dev,
  1021. struct device_attribute *devattr,
  1022. const char *buf,
  1023. size_t count)
  1024. {
  1025. struct adt7462_data *data = dev_get_drvdata(dev);
  1026. struct i2c_client *client = data->client;
  1027. long temp;
  1028. if (kstrtol(buf, 10, &temp))
  1029. return -EINVAL;
  1030. temp = clamp_val(temp, 0, 255);
  1031. mutex_lock(&data->lock);
  1032. data->pwm_max = temp;
  1033. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MAX, temp);
  1034. mutex_unlock(&data->lock);
  1035. return count;
  1036. }
  1037. static ssize_t show_pwm_min(struct device *dev,
  1038. struct device_attribute *devattr,
  1039. char *buf)
  1040. {
  1041. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1042. struct adt7462_data *data = adt7462_update_device(dev);
  1043. return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
  1044. }
  1045. static ssize_t set_pwm_min(struct device *dev,
  1046. struct device_attribute *devattr,
  1047. const char *buf,
  1048. size_t count)
  1049. {
  1050. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1051. struct adt7462_data *data = dev_get_drvdata(dev);
  1052. struct i2c_client *client = data->client;
  1053. long temp;
  1054. if (kstrtol(buf, 10, &temp))
  1055. return -EINVAL;
  1056. temp = clamp_val(temp, 0, 255);
  1057. mutex_lock(&data->lock);
  1058. data->pwm_min[attr->index] = temp;
  1059. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MIN(attr->index),
  1060. temp);
  1061. mutex_unlock(&data->lock);
  1062. return count;
  1063. }
  1064. static ssize_t show_pwm_hyst(struct device *dev,
  1065. struct device_attribute *devattr,
  1066. char *buf)
  1067. {
  1068. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1069. struct adt7462_data *data = adt7462_update_device(dev);
  1070. return sprintf(buf, "%d\n", 1000 *
  1071. (data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK));
  1072. }
  1073. static ssize_t set_pwm_hyst(struct device *dev,
  1074. struct device_attribute *devattr,
  1075. const char *buf,
  1076. size_t count)
  1077. {
  1078. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1079. struct adt7462_data *data = dev_get_drvdata(dev);
  1080. struct i2c_client *client = data->client;
  1081. long temp;
  1082. if (kstrtol(buf, 10, &temp))
  1083. return -EINVAL;
  1084. temp = DIV_ROUND_CLOSEST(temp, 1000);
  1085. temp = clamp_val(temp, 0, 15);
  1086. /* package things up */
  1087. temp &= ADT7462_PWM_HYST_MASK;
  1088. temp |= data->pwm_trange[attr->index] & ADT7462_PWM_RANGE_MASK;
  1089. mutex_lock(&data->lock);
  1090. data->pwm_trange[attr->index] = temp;
  1091. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
  1092. temp);
  1093. mutex_unlock(&data->lock);
  1094. return count;
  1095. }
  1096. static ssize_t show_pwm_tmax(struct device *dev,
  1097. struct device_attribute *devattr,
  1098. char *buf)
  1099. {
  1100. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1101. struct adt7462_data *data = adt7462_update_device(dev);
  1102. /* tmax = tmin + trange */
  1103. int trange = trange_values[data->pwm_trange[attr->index] >>
  1104. ADT7462_PWM_RANGE_SHIFT];
  1105. int tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
  1106. return sprintf(buf, "%d\n", tmin + trange);
  1107. }
  1108. static ssize_t set_pwm_tmax(struct device *dev,
  1109. struct device_attribute *devattr,
  1110. const char *buf,
  1111. size_t count)
  1112. {
  1113. int temp;
  1114. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1115. struct adt7462_data *data = dev_get_drvdata(dev);
  1116. struct i2c_client *client = data->client;
  1117. int tmin, trange_value;
  1118. long trange;
  1119. if (kstrtol(buf, 10, &trange))
  1120. return -EINVAL;
  1121. /* trange = tmax - tmin */
  1122. tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
  1123. trange_value = find_trange_value(trange - tmin);
  1124. if (trange_value < 0)
  1125. return trange_value;
  1126. temp = trange_value << ADT7462_PWM_RANGE_SHIFT;
  1127. temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK;
  1128. mutex_lock(&data->lock);
  1129. data->pwm_trange[attr->index] = temp;
  1130. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
  1131. temp);
  1132. mutex_unlock(&data->lock);
  1133. return count;
  1134. }
  1135. static ssize_t show_pwm_tmin(struct device *dev,
  1136. struct device_attribute *devattr,
  1137. char *buf)
  1138. {
  1139. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1140. struct adt7462_data *data = adt7462_update_device(dev);
  1141. return sprintf(buf, "%d\n", 1000 * (data->pwm_tmin[attr->index] - 64));
  1142. }
  1143. static ssize_t set_pwm_tmin(struct device *dev,
  1144. struct device_attribute *devattr,
  1145. const char *buf,
  1146. size_t count)
  1147. {
  1148. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1149. struct adt7462_data *data = dev_get_drvdata(dev);
  1150. struct i2c_client *client = data->client;
  1151. long temp;
  1152. if (kstrtol(buf, 10, &temp))
  1153. return -EINVAL;
  1154. temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
  1155. temp = clamp_val(temp, 0, 255);
  1156. mutex_lock(&data->lock);
  1157. data->pwm_tmin[attr->index] = temp;
  1158. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TMIN(attr->index),
  1159. temp);
  1160. mutex_unlock(&data->lock);
  1161. return count;
  1162. }
  1163. static ssize_t show_pwm_auto(struct device *dev,
  1164. struct device_attribute *devattr,
  1165. char *buf)
  1166. {
  1167. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1168. struct adt7462_data *data = adt7462_update_device(dev);
  1169. int cfg = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
  1170. switch (cfg) {
  1171. case 4: /* off */
  1172. return sprintf(buf, "0\n");
  1173. case 7: /* manual */
  1174. return sprintf(buf, "1\n");
  1175. default: /* automatic */
  1176. return sprintf(buf, "2\n");
  1177. }
  1178. }
  1179. static void set_pwm_channel(struct i2c_client *client,
  1180. struct adt7462_data *data,
  1181. int which,
  1182. int value)
  1183. {
  1184. int temp = data->pwm_cfg[which] & ~ADT7462_PWM_CHANNEL_MASK;
  1185. temp |= value << ADT7462_PWM_CHANNEL_SHIFT;
  1186. mutex_lock(&data->lock);
  1187. data->pwm_cfg[which] = temp;
  1188. i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_CFG(which), temp);
  1189. mutex_unlock(&data->lock);
  1190. }
  1191. static ssize_t set_pwm_auto(struct device *dev,
  1192. struct device_attribute *devattr,
  1193. const char *buf,
  1194. size_t count)
  1195. {
  1196. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1197. struct adt7462_data *data = dev_get_drvdata(dev);
  1198. struct i2c_client *client = data->client;
  1199. long temp;
  1200. if (kstrtol(buf, 10, &temp))
  1201. return -EINVAL;
  1202. switch (temp) {
  1203. case 0: /* off */
  1204. set_pwm_channel(client, data, attr->index, 4);
  1205. return count;
  1206. case 1: /* manual */
  1207. set_pwm_channel(client, data, attr->index, 7);
  1208. return count;
  1209. default:
  1210. return -EINVAL;
  1211. }
  1212. }
  1213. static ssize_t show_pwm_auto_temp(struct device *dev,
  1214. struct device_attribute *devattr,
  1215. char *buf)
  1216. {
  1217. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1218. struct adt7462_data *data = adt7462_update_device(dev);
  1219. int channel = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
  1220. switch (channel) {
  1221. case 0: /* temp[1234] only */
  1222. case 1:
  1223. case 2:
  1224. case 3:
  1225. return sprintf(buf, "%d\n", (1 << channel));
  1226. case 5: /* temp1 & temp4 */
  1227. return sprintf(buf, "9\n");
  1228. case 6:
  1229. return sprintf(buf, "15\n");
  1230. default:
  1231. return sprintf(buf, "0\n");
  1232. }
  1233. }
  1234. static int cvt_auto_temp(int input)
  1235. {
  1236. if (input == 0xF)
  1237. return 6;
  1238. if (input == 0x9)
  1239. return 5;
  1240. if (input < 1 || !is_power_of_2(input))
  1241. return -EINVAL;
  1242. return ilog2(input);
  1243. }
  1244. static ssize_t set_pwm_auto_temp(struct device *dev,
  1245. struct device_attribute *devattr,
  1246. const char *buf,
  1247. size_t count)
  1248. {
  1249. struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  1250. struct adt7462_data *data = dev_get_drvdata(dev);
  1251. struct i2c_client *client = data->client;
  1252. long temp;
  1253. if (kstrtol(buf, 10, &temp))
  1254. return -EINVAL;
  1255. temp = cvt_auto_temp(temp);
  1256. if (temp < 0)
  1257. return temp;
  1258. set_pwm_channel(client, data, attr->index, temp);
  1259. return count;
  1260. }
  1261. static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
  1262. set_temp_max, 0);
  1263. static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
  1264. set_temp_max, 1);
  1265. static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
  1266. set_temp_max, 2);
  1267. static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,
  1268. set_temp_max, 3);
  1269. static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
  1270. set_temp_min, 0);
  1271. static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
  1272. set_temp_min, 1);
  1273. static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
  1274. set_temp_min, 2);
  1275. static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min,
  1276. set_temp_min, 3);
  1277. static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
  1278. static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
  1279. static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
  1280. static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
  1281. static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0);
  1282. static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1);
  1283. static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2);
  1284. static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3);
  1285. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
  1286. ADT7462_ALARM1 | ADT7462_LT_ALARM);
  1287. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
  1288. ADT7462_ALARM1 | ADT7462_R1T_ALARM);
  1289. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
  1290. ADT7462_ALARM1 | ADT7462_R2T_ALARM);
  1291. static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
  1292. ADT7462_ALARM1 | ADT7462_R3T_ALARM);
  1293. static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max,
  1294. set_volt_max, 0);
  1295. static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max,
  1296. set_volt_max, 1);
  1297. static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_volt_max,
  1298. set_volt_max, 2);
  1299. static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_volt_max,
  1300. set_volt_max, 3);
  1301. static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_volt_max,
  1302. set_volt_max, 4);
  1303. static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_volt_max,
  1304. set_volt_max, 5);
  1305. static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, show_volt_max,
  1306. set_volt_max, 6);
  1307. static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, show_volt_max,
  1308. set_volt_max, 7);
  1309. static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, show_volt_max,
  1310. set_volt_max, 8);
  1311. static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, show_volt_max,
  1312. set_volt_max, 9);
  1313. static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, show_volt_max,
  1314. set_volt_max, 10);
  1315. static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, show_volt_max,
  1316. set_volt_max, 11);
  1317. static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, show_volt_max,
  1318. set_volt_max, 12);
  1319. static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min,
  1320. set_volt_min, 0);
  1321. static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min,
  1322. set_volt_min, 1);
  1323. static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_volt_min,
  1324. set_volt_min, 2);
  1325. static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_volt_min,
  1326. set_volt_min, 3);
  1327. static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_volt_min,
  1328. set_volt_min, 4);
  1329. static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_volt_min,
  1330. set_volt_min, 5);
  1331. static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, show_volt_min,
  1332. set_volt_min, 6);
  1333. static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, show_volt_min,
  1334. set_volt_min, 7);
  1335. static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, show_volt_min,
  1336. set_volt_min, 8);
  1337. static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, show_volt_min,
  1338. set_volt_min, 9);
  1339. static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, show_volt_min,
  1340. set_volt_min, 10);
  1341. static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, show_volt_min,
  1342. set_volt_min, 11);
  1343. static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, show_volt_min,
  1344. set_volt_min, 12);
  1345. static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 0);
  1346. static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 1);
  1347. static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 2);
  1348. static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 3);
  1349. static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 4);
  1350. static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 5);
  1351. static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 6);
  1352. static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL, 7);
  1353. static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_voltage, NULL, 8);
  1354. static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_voltage, NULL, 9);
  1355. static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_voltage, NULL, 10);
  1356. static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_voltage, NULL, 11);
  1357. static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_voltage, NULL, 12);
  1358. static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, show_voltage_label, NULL, 0);
  1359. static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, show_voltage_label, NULL, 1);
  1360. static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_voltage_label, NULL, 2);
  1361. static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_voltage_label, NULL, 3);
  1362. static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_voltage_label, NULL, 4);
  1363. static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_voltage_label, NULL, 5);
  1364. static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_voltage_label, NULL, 6);
  1365. static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_voltage_label, NULL, 7);
  1366. static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_voltage_label, NULL, 8);
  1367. static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, show_voltage_label, NULL, 9);
  1368. static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, show_voltage_label, NULL, 10);
  1369. static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, show_voltage_label, NULL, 11);
  1370. static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, show_voltage_label, NULL, 12);
  1371. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL,
  1372. ADT7462_ALARM2 | ADT7462_V0_ALARM);
  1373. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL,
  1374. ADT7462_ALARM2 | ADT7462_V7_ALARM);
  1375. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL,
  1376. ADT7462_ALARM2 | ADT7462_V2_ALARM);
  1377. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL,
  1378. ADT7462_ALARM2 | ADT7462_V6_ALARM);
  1379. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL,
  1380. ADT7462_ALARM2 | ADT7462_V5_ALARM);
  1381. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL,
  1382. ADT7462_ALARM2 | ADT7462_V4_ALARM);
  1383. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL,
  1384. ADT7462_ALARM2 | ADT7462_V3_ALARM);
  1385. static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL,
  1386. ADT7462_ALARM2 | ADT7462_V1_ALARM);
  1387. static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL,
  1388. ADT7462_ALARM3 | ADT7462_V10_ALARM);
  1389. static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL,
  1390. ADT7462_ALARM3 | ADT7462_V9_ALARM);
  1391. static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL,
  1392. ADT7462_ALARM3 | ADT7462_V8_ALARM);
  1393. static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL,
  1394. ADT7462_ALARM3 | ADT7462_V11_ALARM);
  1395. static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL,
  1396. ADT7462_ALARM3 | ADT7462_V12_ALARM);
  1397. static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
  1398. set_fan_min, 0);
  1399. static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
  1400. set_fan_min, 1);
  1401. static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
  1402. set_fan_min, 2);
  1403. static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
  1404. set_fan_min, 3);
  1405. static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
  1406. set_fan_min, 4);
  1407. static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min,
  1408. set_fan_min, 5);
  1409. static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min,
  1410. set_fan_min, 6);
  1411. static SENSOR_DEVICE_ATTR(fan8_min, S_IWUSR | S_IRUGO, show_fan_min,
  1412. set_fan_min, 7);
  1413. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
  1414. static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
  1415. static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
  1416. static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
  1417. static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4);
  1418. static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 5);
  1419. static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 6);
  1420. static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan, NULL, 7);
  1421. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
  1422. ADT7462_ALARM4 | ADT7462_F0_ALARM);
  1423. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
  1424. ADT7462_ALARM4 | ADT7462_F1_ALARM);
  1425. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
  1426. ADT7462_ALARM4 | ADT7462_F2_ALARM);
  1427. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
  1428. ADT7462_ALARM4 | ADT7462_F3_ALARM);
  1429. static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL,
  1430. ADT7462_ALARM4 | ADT7462_F4_ALARM);
  1431. static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL,
  1432. ADT7462_ALARM4 | ADT7462_F5_ALARM);
  1433. static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL,
  1434. ADT7462_ALARM4 | ADT7462_F6_ALARM);
  1435. static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL,
  1436. ADT7462_ALARM4 | ADT7462_F7_ALARM);
  1437. static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
  1438. show_force_pwm_max, set_force_pwm_max, 0);
  1439. static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
  1440. static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
  1441. static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
  1442. static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
  1443. static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
  1444. show_pwm_min, set_pwm_min, 0);
  1445. static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
  1446. show_pwm_min, set_pwm_min, 1);
  1447. static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
  1448. show_pwm_min, set_pwm_min, 2);
  1449. static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
  1450. show_pwm_min, set_pwm_min, 3);
  1451. static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
  1452. show_pwm_max, set_pwm_max, 0);
  1453. static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
  1454. show_pwm_max, set_pwm_max, 1);
  1455. static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
  1456. show_pwm_max, set_pwm_max, 2);
  1457. static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
  1458. show_pwm_max, set_pwm_max, 3);
  1459. static SENSOR_DEVICE_ATTR(temp1_auto_point1_hyst, S_IWUSR | S_IRUGO,
  1460. show_pwm_hyst, set_pwm_hyst, 0);
  1461. static SENSOR_DEVICE_ATTR(temp2_auto_point1_hyst, S_IWUSR | S_IRUGO,
  1462. show_pwm_hyst, set_pwm_hyst, 1);
  1463. static SENSOR_DEVICE_ATTR(temp3_auto_point1_hyst, S_IWUSR | S_IRUGO,
  1464. show_pwm_hyst, set_pwm_hyst, 2);
  1465. static SENSOR_DEVICE_ATTR(temp4_auto_point1_hyst, S_IWUSR | S_IRUGO,
  1466. show_pwm_hyst, set_pwm_hyst, 3);
  1467. static SENSOR_DEVICE_ATTR(temp1_auto_point2_hyst, S_IWUSR | S_IRUGO,
  1468. show_pwm_hyst, set_pwm_hyst, 0);
  1469. static SENSOR_DEVICE_ATTR(temp2_auto_point2_hyst, S_IWUSR | S_IRUGO,
  1470. show_pwm_hyst, set_pwm_hyst, 1);
  1471. static SENSOR_DEVICE_ATTR(temp3_auto_point2_hyst, S_IWUSR | S_IRUGO,
  1472. show_pwm_hyst, set_pwm_hyst, 2);
  1473. static SENSOR_DEVICE_ATTR(temp4_auto_point2_hyst, S_IWUSR | S_IRUGO,
  1474. show_pwm_hyst, set_pwm_hyst, 3);
  1475. static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO,
  1476. show_pwm_tmin, set_pwm_tmin, 0);
  1477. static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
  1478. show_pwm_tmin, set_pwm_tmin, 1);
  1479. static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO,
  1480. show_pwm_tmin, set_pwm_tmin, 2);
  1481. static SENSOR_DEVICE_ATTR(temp4_auto_point1_temp, S_IWUSR | S_IRUGO,
  1482. show_pwm_tmin, set_pwm_tmin, 3);
  1483. static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
  1484. show_pwm_tmax, set_pwm_tmax, 0);
  1485. static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
  1486. show_pwm_tmax, set_pwm_tmax, 1);
  1487. static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO,
  1488. show_pwm_tmax, set_pwm_tmax, 2);
  1489. static SENSOR_DEVICE_ATTR(temp4_auto_point2_temp, S_IWUSR | S_IRUGO,
  1490. show_pwm_tmax, set_pwm_tmax, 3);
  1491. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
  1492. set_pwm_auto, 0);
  1493. static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
  1494. set_pwm_auto, 1);
  1495. static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
  1496. set_pwm_auto, 2);
  1497. static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
  1498. set_pwm_auto, 3);
  1499. static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
  1500. show_pwm_auto_temp, set_pwm_auto_temp, 0);
  1501. static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
  1502. show_pwm_auto_temp, set_pwm_auto_temp, 1);
  1503. static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
  1504. show_pwm_auto_temp, set_pwm_auto_temp, 2);
  1505. static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
  1506. show_pwm_auto_temp, set_pwm_auto_temp, 3);
  1507. static struct attribute *adt7462_attrs[] = {
  1508. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1509. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1510. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1511. &sensor_dev_attr_temp4_max.dev_attr.attr,
  1512. &sensor_dev_attr_temp1_min.dev_attr.attr,
  1513. &sensor_dev_attr_temp2_min.dev_attr.attr,
  1514. &sensor_dev_attr_temp3_min.dev_attr.attr,
  1515. &sensor_dev_attr_temp4_min.dev_attr.attr,
  1516. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1517. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1518. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1519. &sensor_dev_attr_temp4_input.dev_attr.attr,
  1520. &sensor_dev_attr_temp1_label.dev_attr.attr,
  1521. &sensor_dev_attr_temp2_label.dev_attr.attr,
  1522. &sensor_dev_attr_temp3_label.dev_attr.attr,
  1523. &sensor_dev_attr_temp4_label.dev_attr.attr,
  1524. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1525. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1526. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1527. &sensor_dev_attr_temp4_alarm.dev_attr.attr,
  1528. &sensor_dev_attr_in1_max.dev_attr.attr,
  1529. &sensor_dev_attr_in2_max.dev_attr.attr,
  1530. &sensor_dev_attr_in3_max.dev_attr.attr,
  1531. &sensor_dev_attr_in4_max.dev_attr.attr,
  1532. &sensor_dev_attr_in5_max.dev_attr.attr,
  1533. &sensor_dev_attr_in6_max.dev_attr.attr,
  1534. &sensor_dev_attr_in7_max.dev_attr.attr,
  1535. &sensor_dev_attr_in8_max.dev_attr.attr,
  1536. &sensor_dev_attr_in9_max.dev_attr.attr,
  1537. &sensor_dev_attr_in10_max.dev_attr.attr,
  1538. &sensor_dev_attr_in11_max.dev_attr.attr,
  1539. &sensor_dev_attr_in12_max.dev_attr.attr,
  1540. &sensor_dev_attr_in13_max.dev_attr.attr,
  1541. &sensor_dev_attr_in1_min.dev_attr.attr,
  1542. &sensor_dev_attr_in2_min.dev_attr.attr,
  1543. &sensor_dev_attr_in3_min.dev_attr.attr,
  1544. &sensor_dev_attr_in4_min.dev_attr.attr,
  1545. &sensor_dev_attr_in5_min.dev_attr.attr,
  1546. &sensor_dev_attr_in6_min.dev_attr.attr,
  1547. &sensor_dev_attr_in7_min.dev_attr.attr,
  1548. &sensor_dev_attr_in8_min.dev_attr.attr,
  1549. &sensor_dev_attr_in9_min.dev_attr.attr,
  1550. &sensor_dev_attr_in10_min.dev_attr.attr,
  1551. &sensor_dev_attr_in11_min.dev_attr.attr,
  1552. &sensor_dev_attr_in12_min.dev_attr.attr,
  1553. &sensor_dev_attr_in13_min.dev_attr.attr,
  1554. &sensor_dev_attr_in1_input.dev_attr.attr,
  1555. &sensor_dev_attr_in2_input.dev_attr.attr,
  1556. &sensor_dev_attr_in3_input.dev_attr.attr,
  1557. &sensor_dev_attr_in4_input.dev_attr.attr,
  1558. &sensor_dev_attr_in5_input.dev_attr.attr,
  1559. &sensor_dev_attr_in6_input.dev_attr.attr,
  1560. &sensor_dev_attr_in7_input.dev_attr.attr,
  1561. &sensor_dev_attr_in8_input.dev_attr.attr,
  1562. &sensor_dev_attr_in9_input.dev_attr.attr,
  1563. &sensor_dev_attr_in10_input.dev_attr.attr,
  1564. &sensor_dev_attr_in11_input.dev_attr.attr,
  1565. &sensor_dev_attr_in12_input.dev_attr.attr,
  1566. &sensor_dev_attr_in13_input.dev_attr.attr,
  1567. &sensor_dev_attr_in1_label.dev_attr.attr,
  1568. &sensor_dev_attr_in2_label.dev_attr.attr,
  1569. &sensor_dev_attr_in3_label.dev_attr.attr,
  1570. &sensor_dev_attr_in4_label.dev_attr.attr,
  1571. &sensor_dev_attr_in5_label.dev_attr.attr,
  1572. &sensor_dev_attr_in6_label.dev_attr.attr,
  1573. &sensor_dev_attr_in7_label.dev_attr.attr,
  1574. &sensor_dev_attr_in8_label.dev_attr.attr,
  1575. &sensor_dev_attr_in9_label.dev_attr.attr,
  1576. &sensor_dev_attr_in10_label.dev_attr.attr,
  1577. &sensor_dev_attr_in11_label.dev_attr.attr,
  1578. &sensor_dev_attr_in12_label.dev_attr.attr,
  1579. &sensor_dev_attr_in13_label.dev_attr.attr,
  1580. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1581. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1582. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1583. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1584. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1585. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1586. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1587. &sensor_dev_attr_in8_alarm.dev_attr.attr,
  1588. &sensor_dev_attr_in9_alarm.dev_attr.attr,
  1589. &sensor_dev_attr_in10_alarm.dev_attr.attr,
  1590. &sensor_dev_attr_in11_alarm.dev_attr.attr,
  1591. &sensor_dev_attr_in12_alarm.dev_attr.attr,
  1592. &sensor_dev_attr_in13_alarm.dev_attr.attr,
  1593. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1594. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1595. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1596. &sensor_dev_attr_fan4_min.dev_attr.attr,
  1597. &sensor_dev_attr_fan5_min.dev_attr.attr,
  1598. &sensor_dev_attr_fan6_min.dev_attr.attr,
  1599. &sensor_dev_attr_fan7_min.dev_attr.attr,
  1600. &sensor_dev_attr_fan8_min.dev_attr.attr,
  1601. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1602. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1603. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1604. &sensor_dev_attr_fan4_input.dev_attr.attr,
  1605. &sensor_dev_attr_fan5_input.dev_attr.attr,
  1606. &sensor_dev_attr_fan6_input.dev_attr.attr,
  1607. &sensor_dev_attr_fan7_input.dev_attr.attr,
  1608. &sensor_dev_attr_fan8_input.dev_attr.attr,
  1609. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1610. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1611. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1612. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1613. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1614. &sensor_dev_attr_fan6_alarm.dev_attr.attr,
  1615. &sensor_dev_attr_fan7_alarm.dev_attr.attr,
  1616. &sensor_dev_attr_fan8_alarm.dev_attr.attr,
  1617. &sensor_dev_attr_force_pwm_max.dev_attr.attr,
  1618. &sensor_dev_attr_pwm1.dev_attr.attr,
  1619. &sensor_dev_attr_pwm2.dev_attr.attr,
  1620. &sensor_dev_attr_pwm3.dev_attr.attr,
  1621. &sensor_dev_attr_pwm4.dev_attr.attr,
  1622. &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
  1623. &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
  1624. &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
  1625. &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr,
  1626. &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
  1627. &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
  1628. &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
  1629. &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr,
  1630. &sensor_dev_attr_temp1_auto_point1_hyst.dev_attr.attr,
  1631. &sensor_dev_attr_temp2_auto_point1_hyst.dev_attr.attr,
  1632. &sensor_dev_attr_temp3_auto_point1_hyst.dev_attr.attr,
  1633. &sensor_dev_attr_temp4_auto_point1_hyst.dev_attr.attr,
  1634. &sensor_dev_attr_temp1_auto_point2_hyst.dev_attr.attr,
  1635. &sensor_dev_attr_temp2_auto_point2_hyst.dev_attr.attr,
  1636. &sensor_dev_attr_temp3_auto_point2_hyst.dev_attr.attr,
  1637. &sensor_dev_attr_temp4_auto_point2_hyst.dev_attr.attr,
  1638. &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
  1639. &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
  1640. &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
  1641. &sensor_dev_attr_temp4_auto_point1_temp.dev_attr.attr,
  1642. &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
  1643. &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
  1644. &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
  1645. &sensor_dev_attr_temp4_auto_point2_temp.dev_attr.attr,
  1646. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1647. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1648. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1649. &sensor_dev_attr_pwm4_enable.dev_attr.attr,
  1650. &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
  1651. &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
  1652. &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
  1653. &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
  1654. NULL
  1655. };
  1656. ATTRIBUTE_GROUPS(adt7462);
  1657. /* Return 0 if detection is successful, -ENODEV otherwise */
  1658. static int adt7462_detect(struct i2c_client *client,
  1659. struct i2c_board_info *info)
  1660. {
  1661. struct i2c_adapter *adapter = client->adapter;
  1662. int vendor, device, revision;
  1663. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1664. return -ENODEV;
  1665. vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
  1666. if (vendor != ADT7462_VENDOR)
  1667. return -ENODEV;
  1668. device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE);
  1669. if (device != ADT7462_DEVICE)
  1670. return -ENODEV;
  1671. revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION);
  1672. if (revision != ADT7462_REVISION)
  1673. return -ENODEV;
  1674. strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
  1675. return 0;
  1676. }
  1677. static int adt7462_probe(struct i2c_client *client,
  1678. const struct i2c_device_id *id)
  1679. {
  1680. struct device *dev = &client->dev;
  1681. struct adt7462_data *data;
  1682. struct device *hwmon_dev;
  1683. data = devm_kzalloc(dev, sizeof(struct adt7462_data), GFP_KERNEL);
  1684. if (!data)
  1685. return -ENOMEM;
  1686. data->client = client;
  1687. mutex_init(&data->lock);
  1688. dev_info(&client->dev, "%s chip found\n", client->name);
  1689. hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
  1690. data,
  1691. adt7462_groups);
  1692. return PTR_ERR_OR_ZERO(hwmon_dev);
  1693. }
  1694. static const struct i2c_device_id adt7462_id[] = {
  1695. { "adt7462", 0 },
  1696. { }
  1697. };
  1698. MODULE_DEVICE_TABLE(i2c, adt7462_id);
  1699. static struct i2c_driver adt7462_driver = {
  1700. .class = I2C_CLASS_HWMON,
  1701. .driver = {
  1702. .name = "adt7462",
  1703. },
  1704. .probe = adt7462_probe,
  1705. .id_table = adt7462_id,
  1706. .detect = adt7462_detect,
  1707. .address_list = normal_i2c,
  1708. };
  1709. module_i2c_driver(adt7462_driver);
  1710. MODULE_AUTHOR("Darrick J. Wong <darrick.wong@oracle.com>");
  1711. MODULE_DESCRIPTION("ADT7462 driver");
  1712. MODULE_LICENSE("GPL");