adt7462.c 59 KB

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