adt7462.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  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");