w83792d.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. /*
  2. * w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
  3. * monitoring
  4. * Copyright (C) 2004, 2005 Winbond Electronics Corp.
  5. * Shane Huang,
  6. * Rudolf Marek <r.marek@assembler.cz>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * Note:
  23. * 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
  24. * 2. This driver is only for Winbond W83792D C version device, there
  25. * are also some motherboards with B version W83792D device. The
  26. * calculation method to in6-in7(measured value, limits) is a little
  27. * different between C and B version. C or B version can be identified
  28. * by CR[0x49h].
  29. */
  30. /*
  31. * Supports following chips:
  32. *
  33. * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
  34. * w83792d 9 7 7 3 0x7a 0x5ca3 yes no
  35. */
  36. #include <linux/module.h>
  37. #include <linux/init.h>
  38. #include <linux/slab.h>
  39. #include <linux/i2c.h>
  40. #include <linux/hwmon.h>
  41. #include <linux/hwmon-sysfs.h>
  42. #include <linux/err.h>
  43. #include <linux/mutex.h>
  44. #include <linux/sysfs.h>
  45. #include <linux/jiffies.h>
  46. /* Addresses to scan */
  47. static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
  48. I2C_CLIENT_END };
  49. /* Insmod parameters */
  50. static unsigned short force_subclients[4];
  51. module_param_array(force_subclients, short, NULL, 0);
  52. MODULE_PARM_DESC(force_subclients,
  53. "List of subclient addresses: {bus, clientaddr, subclientaddr1, subclientaddr2}");
  54. static bool init;
  55. module_param(init, bool, 0);
  56. MODULE_PARM_DESC(init, "Set to one to force chip initialization");
  57. /* The W83792D registers */
  58. static const u8 W83792D_REG_IN[9] = {
  59. 0x20, /* Vcore A in DataSheet */
  60. 0x21, /* Vcore B in DataSheet */
  61. 0x22, /* VIN0 in DataSheet */
  62. 0x23, /* VIN1 in DataSheet */
  63. 0x24, /* VIN2 in DataSheet */
  64. 0x25, /* VIN3 in DataSheet */
  65. 0x26, /* 5VCC in DataSheet */
  66. 0xB0, /* 5VSB in DataSheet */
  67. 0xB1 /* VBAT in DataSheet */
  68. };
  69. #define W83792D_REG_LOW_BITS1 0x3E /* Low Bits I in DataSheet */
  70. #define W83792D_REG_LOW_BITS2 0x3F /* Low Bits II in DataSheet */
  71. static const u8 W83792D_REG_IN_MAX[9] = {
  72. 0x2B, /* Vcore A High Limit in DataSheet */
  73. 0x2D, /* Vcore B High Limit in DataSheet */
  74. 0x2F, /* VIN0 High Limit in DataSheet */
  75. 0x31, /* VIN1 High Limit in DataSheet */
  76. 0x33, /* VIN2 High Limit in DataSheet */
  77. 0x35, /* VIN3 High Limit in DataSheet */
  78. 0x37, /* 5VCC High Limit in DataSheet */
  79. 0xB4, /* 5VSB High Limit in DataSheet */
  80. 0xB6 /* VBAT High Limit in DataSheet */
  81. };
  82. static const u8 W83792D_REG_IN_MIN[9] = {
  83. 0x2C, /* Vcore A Low Limit in DataSheet */
  84. 0x2E, /* Vcore B Low Limit in DataSheet */
  85. 0x30, /* VIN0 Low Limit in DataSheet */
  86. 0x32, /* VIN1 Low Limit in DataSheet */
  87. 0x34, /* VIN2 Low Limit in DataSheet */
  88. 0x36, /* VIN3 Low Limit in DataSheet */
  89. 0x38, /* 5VCC Low Limit in DataSheet */
  90. 0xB5, /* 5VSB Low Limit in DataSheet */
  91. 0xB7 /* VBAT Low Limit in DataSheet */
  92. };
  93. static const u8 W83792D_REG_FAN[7] = {
  94. 0x28, /* FAN 1 Count in DataSheet */
  95. 0x29, /* FAN 2 Count in DataSheet */
  96. 0x2A, /* FAN 3 Count in DataSheet */
  97. 0xB8, /* FAN 4 Count in DataSheet */
  98. 0xB9, /* FAN 5 Count in DataSheet */
  99. 0xBA, /* FAN 6 Count in DataSheet */
  100. 0xBE /* FAN 7 Count in DataSheet */
  101. };
  102. static const u8 W83792D_REG_FAN_MIN[7] = {
  103. 0x3B, /* FAN 1 Count Low Limit in DataSheet */
  104. 0x3C, /* FAN 2 Count Low Limit in DataSheet */
  105. 0x3D, /* FAN 3 Count Low Limit in DataSheet */
  106. 0xBB, /* FAN 4 Count Low Limit in DataSheet */
  107. 0xBC, /* FAN 5 Count Low Limit in DataSheet */
  108. 0xBD, /* FAN 6 Count Low Limit in DataSheet */
  109. 0xBF /* FAN 7 Count Low Limit in DataSheet */
  110. };
  111. #define W83792D_REG_FAN_CFG 0x84 /* FAN Configuration in DataSheet */
  112. static const u8 W83792D_REG_FAN_DIV[4] = {
  113. 0x47, /* contains FAN2 and FAN1 Divisor */
  114. 0x5B, /* contains FAN4 and FAN3 Divisor */
  115. 0x5C, /* contains FAN6 and FAN5 Divisor */
  116. 0x9E /* contains FAN7 Divisor. */
  117. };
  118. static const u8 W83792D_REG_PWM[7] = {
  119. 0x81, /* FAN 1 Duty Cycle, be used to control */
  120. 0x83, /* FAN 2 Duty Cycle, be used to control */
  121. 0x94, /* FAN 3 Duty Cycle, be used to control */
  122. 0xA3, /* FAN 4 Duty Cycle, be used to control */
  123. 0xA4, /* FAN 5 Duty Cycle, be used to control */
  124. 0xA5, /* FAN 6 Duty Cycle, be used to control */
  125. 0xA6 /* FAN 7 Duty Cycle, be used to control */
  126. };
  127. #define W83792D_REG_BANK 0x4E
  128. #define W83792D_REG_TEMP2_CONFIG 0xC2
  129. #define W83792D_REG_TEMP3_CONFIG 0xCA
  130. static const u8 W83792D_REG_TEMP1[3] = {
  131. 0x27, /* TEMP 1 in DataSheet */
  132. 0x39, /* TEMP 1 Over in DataSheet */
  133. 0x3A, /* TEMP 1 Hyst in DataSheet */
  134. };
  135. static const u8 W83792D_REG_TEMP_ADD[2][6] = {
  136. { 0xC0, /* TEMP 2 in DataSheet */
  137. 0xC1, /* TEMP 2(0.5 deg) in DataSheet */
  138. 0xC5, /* TEMP 2 Over High part in DataSheet */
  139. 0xC6, /* TEMP 2 Over Low part in DataSheet */
  140. 0xC3, /* TEMP 2 Thyst High part in DataSheet */
  141. 0xC4 }, /* TEMP 2 Thyst Low part in DataSheet */
  142. { 0xC8, /* TEMP 3 in DataSheet */
  143. 0xC9, /* TEMP 3(0.5 deg) in DataSheet */
  144. 0xCD, /* TEMP 3 Over High part in DataSheet */
  145. 0xCE, /* TEMP 3 Over Low part in DataSheet */
  146. 0xCB, /* TEMP 3 Thyst High part in DataSheet */
  147. 0xCC } /* TEMP 3 Thyst Low part in DataSheet */
  148. };
  149. static const u8 W83792D_REG_THERMAL[3] = {
  150. 0x85, /* SmartFanI: Fan1 target value */
  151. 0x86, /* SmartFanI: Fan2 target value */
  152. 0x96 /* SmartFanI: Fan3 target value */
  153. };
  154. static const u8 W83792D_REG_TOLERANCE[3] = {
  155. 0x87, /* (bit3-0)SmartFan Fan1 tolerance */
  156. 0x87, /* (bit7-4)SmartFan Fan2 tolerance */
  157. 0x97 /* (bit3-0)SmartFan Fan3 tolerance */
  158. };
  159. static const u8 W83792D_REG_POINTS[3][4] = {
  160. { 0x85, /* SmartFanII: Fan1 temp point 1 */
  161. 0xE3, /* SmartFanII: Fan1 temp point 2 */
  162. 0xE4, /* SmartFanII: Fan1 temp point 3 */
  163. 0xE5 }, /* SmartFanII: Fan1 temp point 4 */
  164. { 0x86, /* SmartFanII: Fan2 temp point 1 */
  165. 0xE6, /* SmartFanII: Fan2 temp point 2 */
  166. 0xE7, /* SmartFanII: Fan2 temp point 3 */
  167. 0xE8 }, /* SmartFanII: Fan2 temp point 4 */
  168. { 0x96, /* SmartFanII: Fan3 temp point 1 */
  169. 0xE9, /* SmartFanII: Fan3 temp point 2 */
  170. 0xEA, /* SmartFanII: Fan3 temp point 3 */
  171. 0xEB } /* SmartFanII: Fan3 temp point 4 */
  172. };
  173. static const u8 W83792D_REG_LEVELS[3][4] = {
  174. { 0x88, /* (bit3-0) SmartFanII: Fan1 Non-Stop */
  175. 0x88, /* (bit7-4) SmartFanII: Fan1 Level 1 */
  176. 0xE0, /* (bit7-4) SmartFanII: Fan1 Level 2 */
  177. 0xE0 }, /* (bit3-0) SmartFanII: Fan1 Level 3 */
  178. { 0x89, /* (bit3-0) SmartFanII: Fan2 Non-Stop */
  179. 0x89, /* (bit7-4) SmartFanII: Fan2 Level 1 */
  180. 0xE1, /* (bit7-4) SmartFanII: Fan2 Level 2 */
  181. 0xE1 }, /* (bit3-0) SmartFanII: Fan2 Level 3 */
  182. { 0x98, /* (bit3-0) SmartFanII: Fan3 Non-Stop */
  183. 0x98, /* (bit7-4) SmartFanII: Fan3 Level 1 */
  184. 0xE2, /* (bit7-4) SmartFanII: Fan3 Level 2 */
  185. 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */
  186. };
  187. #define W83792D_REG_GPIO_EN 0x1A
  188. #define W83792D_REG_CONFIG 0x40
  189. #define W83792D_REG_VID_FANDIV 0x47
  190. #define W83792D_REG_CHIPID 0x49
  191. #define W83792D_REG_WCHIPID 0x58
  192. #define W83792D_REG_CHIPMAN 0x4F
  193. #define W83792D_REG_PIN 0x4B
  194. #define W83792D_REG_I2C_SUBADDR 0x4A
  195. #define W83792D_REG_ALARM1 0xA9 /* realtime status register1 */
  196. #define W83792D_REG_ALARM2 0xAA /* realtime status register2 */
  197. #define W83792D_REG_ALARM3 0xAB /* realtime status register3 */
  198. #define W83792D_REG_CHASSIS 0x42 /* Bit 5: Case Open status bit */
  199. #define W83792D_REG_CHASSIS_CLR 0x44 /* Bit 7: Case Open CLR_CHS/Reset bit */
  200. /* control in0/in1 's limit modifiability */
  201. #define W83792D_REG_VID_IN_B 0x17
  202. #define W83792D_REG_VBAT 0x5D
  203. #define W83792D_REG_I2C_ADDR 0x48
  204. /*
  205. * Conversions. Rounding and limit checking is only done on the TO_REG
  206. * variants. Note that you should be a bit careful with which arguments
  207. * these macros are called: arguments may be evaluated more than once.
  208. * Fixing this is just not worth it.
  209. */
  210. #define IN_FROM_REG(nr, val) (((nr) <= 1) ? ((val) * 2) : \
  211. ((((nr) == 6) || ((nr) == 7)) ? ((val) * 6) : ((val) * 4)))
  212. #define IN_TO_REG(nr, val) (((nr) <= 1) ? ((val) / 2) : \
  213. ((((nr) == 6) || ((nr) == 7)) ? ((val) / 6) : ((val) / 4)))
  214. static inline u8
  215. FAN_TO_REG(long rpm, int div)
  216. {
  217. if (rpm == 0)
  218. return 255;
  219. rpm = clamp_val(rpm, 1, 1000000);
  220. return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
  221. }
  222. #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
  223. ((val) == 255 ? 0 : \
  224. 1350000 / ((val) * (div))))
  225. /* for temp1 */
  226. #define TEMP1_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
  227. : (val)) / 1000, 0, 0xff))
  228. #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
  229. /* for temp2 and temp3, because they need additional resolution */
  230. #define TEMP_ADD_FROM_REG(val1, val2) \
  231. ((((val1) & 0x80 ? (val1)-0x100 \
  232. : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0))
  233. #define TEMP_ADD_TO_REG_HIGH(val) \
  234. (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 : (val)) / 1000, 0, 0xff))
  235. #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00)
  236. #define DIV_FROM_REG(val) (1 << (val))
  237. static inline u8
  238. DIV_TO_REG(long val)
  239. {
  240. int i;
  241. val = clamp_val(val, 1, 128) >> 1;
  242. for (i = 0; i < 7; i++) {
  243. if (val == 0)
  244. break;
  245. val >>= 1;
  246. }
  247. return (u8)i;
  248. }
  249. struct w83792d_data {
  250. struct device *hwmon_dev;
  251. struct mutex update_lock;
  252. char valid; /* !=0 if following fields are valid */
  253. unsigned long last_updated; /* In jiffies */
  254. /* array of 2 pointers to subclients */
  255. struct i2c_client *lm75[2];
  256. u8 in[9]; /* Register value */
  257. u8 in_max[9]; /* Register value */
  258. u8 in_min[9]; /* Register value */
  259. u16 low_bits; /* Additional resolution to voltage in6-0 */
  260. u8 fan[7]; /* Register value */
  261. u8 fan_min[7]; /* Register value */
  262. u8 temp1[3]; /* current, over, thyst */
  263. u8 temp_add[2][6]; /* Register value */
  264. u8 fan_div[7]; /* Register encoding, shifted right */
  265. u8 pwm[7]; /* The 7 PWM outputs */
  266. u8 pwmenable[3];
  267. u32 alarms; /* realtime status register encoding,combined */
  268. u8 chassis; /* Chassis status */
  269. u8 thermal_cruise[3]; /* Smart FanI: Fan1,2,3 target value */
  270. u8 tolerance[3]; /* Fan1,2,3 tolerance(Smart Fan I/II) */
  271. u8 sf2_points[3][4]; /* Smart FanII: Fan1,2,3 temperature points */
  272. u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */
  273. };
  274. static int w83792d_probe(struct i2c_client *client,
  275. const struct i2c_device_id *id);
  276. static int w83792d_detect(struct i2c_client *client,
  277. struct i2c_board_info *info);
  278. static int w83792d_remove(struct i2c_client *client);
  279. static struct w83792d_data *w83792d_update_device(struct device *dev);
  280. #ifdef DEBUG
  281. static void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
  282. #endif
  283. static void w83792d_init_client(struct i2c_client *client);
  284. static const struct i2c_device_id w83792d_id[] = {
  285. { "w83792d", 0 },
  286. { }
  287. };
  288. MODULE_DEVICE_TABLE(i2c, w83792d_id);
  289. static struct i2c_driver w83792d_driver = {
  290. .class = I2C_CLASS_HWMON,
  291. .driver = {
  292. .name = "w83792d",
  293. },
  294. .probe = w83792d_probe,
  295. .remove = w83792d_remove,
  296. .id_table = w83792d_id,
  297. .detect = w83792d_detect,
  298. .address_list = normal_i2c,
  299. };
  300. static inline long in_count_from_reg(int nr, struct w83792d_data *data)
  301. {
  302. /* in7 and in8 do not have low bits, but the formula still works */
  303. return (data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03);
  304. }
  305. /*
  306. * The SMBus locks itself. The Winbond W83792D chip has a bank register,
  307. * but the driver only accesses registers in bank 0, so we don't have
  308. * to switch banks and lock access between switches.
  309. */
  310. static inline int w83792d_read_value(struct i2c_client *client, u8 reg)
  311. {
  312. return i2c_smbus_read_byte_data(client, reg);
  313. }
  314. static inline int
  315. w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
  316. {
  317. return i2c_smbus_write_byte_data(client, reg, value);
  318. }
  319. /* following are the sysfs callback functions */
  320. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  321. char *buf)
  322. {
  323. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  324. int nr = sensor_attr->index;
  325. struct w83792d_data *data = w83792d_update_device(dev);
  326. return sprintf(buf, "%ld\n",
  327. IN_FROM_REG(nr, in_count_from_reg(nr, data)));
  328. }
  329. #define show_in_reg(reg) \
  330. static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
  331. char *buf) \
  332. { \
  333. struct sensor_device_attribute *sensor_attr \
  334. = to_sensor_dev_attr(attr); \
  335. int nr = sensor_attr->index; \
  336. struct w83792d_data *data = w83792d_update_device(dev); \
  337. return sprintf(buf, "%ld\n", \
  338. (long)(IN_FROM_REG(nr, data->reg[nr]) * 4)); \
  339. }
  340. show_in_reg(in_min);
  341. show_in_reg(in_max);
  342. #define store_in_reg(REG, reg) \
  343. static ssize_t store_in_##reg(struct device *dev, \
  344. struct device_attribute *attr, \
  345. const char *buf, size_t count) \
  346. { \
  347. struct sensor_device_attribute *sensor_attr \
  348. = to_sensor_dev_attr(attr); \
  349. int nr = sensor_attr->index; \
  350. struct i2c_client *client = to_i2c_client(dev); \
  351. struct w83792d_data *data = i2c_get_clientdata(client); \
  352. unsigned long val; \
  353. int err = kstrtoul(buf, 10, &val); \
  354. if (err) \
  355. return err; \
  356. mutex_lock(&data->update_lock); \
  357. data->in_##reg[nr] = clamp_val(IN_TO_REG(nr, val) / 4, 0, 255); \
  358. w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \
  359. data->in_##reg[nr]); \
  360. mutex_unlock(&data->update_lock); \
  361. \
  362. return count; \
  363. }
  364. store_in_reg(MIN, min);
  365. store_in_reg(MAX, max);
  366. #define show_fan_reg(reg) \
  367. static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
  368. char *buf) \
  369. { \
  370. struct sensor_device_attribute *sensor_attr \
  371. = to_sensor_dev_attr(attr); \
  372. int nr = sensor_attr->index - 1; \
  373. struct w83792d_data *data = w83792d_update_device(dev); \
  374. return sprintf(buf, "%d\n", \
  375. FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
  376. }
  377. show_fan_reg(fan);
  378. show_fan_reg(fan_min);
  379. static ssize_t
  380. store_fan_min(struct device *dev, struct device_attribute *attr,
  381. const char *buf, size_t count)
  382. {
  383. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  384. int nr = sensor_attr->index - 1;
  385. struct i2c_client *client = to_i2c_client(dev);
  386. struct w83792d_data *data = i2c_get_clientdata(client);
  387. unsigned long val;
  388. int err;
  389. err = kstrtoul(buf, 10, &val);
  390. if (err)
  391. return err;
  392. mutex_lock(&data->update_lock);
  393. data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
  394. w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
  395. data->fan_min[nr]);
  396. mutex_unlock(&data->update_lock);
  397. return count;
  398. }
  399. static ssize_t
  400. show_fan_div(struct device *dev, struct device_attribute *attr,
  401. char *buf)
  402. {
  403. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  404. int nr = sensor_attr->index;
  405. struct w83792d_data *data = w83792d_update_device(dev);
  406. return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
  407. }
  408. /*
  409. * Note: we save and restore the fan minimum here, because its value is
  410. * determined in part by the fan divisor. This follows the principle of
  411. * least surprise; the user doesn't expect the fan minimum to change just
  412. * because the divisor changed.
  413. */
  414. static ssize_t
  415. store_fan_div(struct device *dev, struct device_attribute *attr,
  416. const char *buf, size_t count)
  417. {
  418. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  419. int nr = sensor_attr->index - 1;
  420. struct i2c_client *client = to_i2c_client(dev);
  421. struct w83792d_data *data = i2c_get_clientdata(client);
  422. unsigned long min;
  423. /*u8 reg;*/
  424. u8 fan_div_reg = 0;
  425. u8 tmp_fan_div;
  426. unsigned long val;
  427. int err;
  428. err = kstrtoul(buf, 10, &val);
  429. if (err)
  430. return err;
  431. /* Save fan_min */
  432. mutex_lock(&data->update_lock);
  433. min = FAN_FROM_REG(data->fan_min[nr],
  434. DIV_FROM_REG(data->fan_div[nr]));
  435. data->fan_div[nr] = DIV_TO_REG(val);
  436. fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
  437. fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
  438. tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70)
  439. : ((data->fan_div[nr]) & 0x07);
  440. w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1],
  441. fan_div_reg | tmp_fan_div);
  442. /* Restore fan_min */
  443. data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
  444. w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]);
  445. mutex_unlock(&data->update_lock);
  446. return count;
  447. }
  448. /* read/write the temperature1, includes measured value and limits */
  449. static ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
  450. char *buf)
  451. {
  452. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  453. int nr = sensor_attr->index;
  454. struct w83792d_data *data = w83792d_update_device(dev);
  455. return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr]));
  456. }
  457. static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
  458. const char *buf, size_t count)
  459. {
  460. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  461. int nr = sensor_attr->index;
  462. struct i2c_client *client = to_i2c_client(dev);
  463. struct w83792d_data *data = i2c_get_clientdata(client);
  464. long val;
  465. int err;
  466. err = kstrtol(buf, 10, &val);
  467. if (err)
  468. return err;
  469. mutex_lock(&data->update_lock);
  470. data->temp1[nr] = TEMP1_TO_REG(val);
  471. w83792d_write_value(client, W83792D_REG_TEMP1[nr],
  472. data->temp1[nr]);
  473. mutex_unlock(&data->update_lock);
  474. return count;
  475. }
  476. /* read/write the temperature2-3, includes measured value and limits */
  477. static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
  478. char *buf)
  479. {
  480. struct sensor_device_attribute_2 *sensor_attr
  481. = to_sensor_dev_attr_2(attr);
  482. int nr = sensor_attr->nr;
  483. int index = sensor_attr->index;
  484. struct w83792d_data *data = w83792d_update_device(dev);
  485. return sprintf(buf, "%ld\n",
  486. (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
  487. data->temp_add[nr][index+1]));
  488. }
  489. static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
  490. const char *buf, size_t count)
  491. {
  492. struct sensor_device_attribute_2 *sensor_attr
  493. = to_sensor_dev_attr_2(attr);
  494. int nr = sensor_attr->nr;
  495. int index = sensor_attr->index;
  496. struct i2c_client *client = to_i2c_client(dev);
  497. struct w83792d_data *data = i2c_get_clientdata(client);
  498. long val;
  499. int err;
  500. err = kstrtol(buf, 10, &val);
  501. if (err)
  502. return err;
  503. mutex_lock(&data->update_lock);
  504. data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
  505. data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
  506. w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index],
  507. data->temp_add[nr][index]);
  508. w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1],
  509. data->temp_add[nr][index+1]);
  510. mutex_unlock(&data->update_lock);
  511. return count;
  512. }
  513. /* get realtime status of all sensors items: voltage, temp, fan */
  514. static ssize_t
  515. show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
  516. {
  517. struct w83792d_data *data = w83792d_update_device(dev);
  518. return sprintf(buf, "%d\n", data->alarms);
  519. }
  520. static ssize_t show_alarm(struct device *dev,
  521. struct device_attribute *attr, char *buf)
  522. {
  523. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  524. int nr = sensor_attr->index;
  525. struct w83792d_data *data = w83792d_update_device(dev);
  526. return sprintf(buf, "%d\n", (data->alarms >> nr) & 1);
  527. }
  528. static ssize_t
  529. show_pwm(struct device *dev, struct device_attribute *attr,
  530. char *buf)
  531. {
  532. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  533. int nr = sensor_attr->index;
  534. struct w83792d_data *data = w83792d_update_device(dev);
  535. return sprintf(buf, "%d\n", (data->pwm[nr] & 0x0f) << 4);
  536. }
  537. static ssize_t
  538. show_pwmenable(struct device *dev, struct device_attribute *attr,
  539. char *buf)
  540. {
  541. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  542. int nr = sensor_attr->index - 1;
  543. struct w83792d_data *data = w83792d_update_device(dev);
  544. long pwm_enable_tmp = 1;
  545. switch (data->pwmenable[nr]) {
  546. case 0:
  547. pwm_enable_tmp = 1; /* manual mode */
  548. break;
  549. case 1:
  550. pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */
  551. break;
  552. case 2:
  553. pwm_enable_tmp = 2; /* Smart Fan II */
  554. break;
  555. }
  556. return sprintf(buf, "%ld\n", pwm_enable_tmp);
  557. }
  558. static ssize_t
  559. store_pwm(struct device *dev, struct device_attribute *attr,
  560. const char *buf, size_t count)
  561. {
  562. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  563. int nr = sensor_attr->index;
  564. struct i2c_client *client = to_i2c_client(dev);
  565. struct w83792d_data *data = i2c_get_clientdata(client);
  566. unsigned long val;
  567. int err;
  568. err = kstrtoul(buf, 10, &val);
  569. if (err)
  570. return err;
  571. val = clamp_val(val, 0, 255) >> 4;
  572. mutex_lock(&data->update_lock);
  573. val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0;
  574. data->pwm[nr] = val;
  575. w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
  576. mutex_unlock(&data->update_lock);
  577. return count;
  578. }
  579. static ssize_t
  580. store_pwmenable(struct device *dev, struct device_attribute *attr,
  581. const char *buf, size_t count)
  582. {
  583. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  584. int nr = sensor_attr->index - 1;
  585. struct i2c_client *client = to_i2c_client(dev);
  586. struct w83792d_data *data = i2c_get_clientdata(client);
  587. u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
  588. unsigned long val;
  589. int err;
  590. err = kstrtoul(buf, 10, &val);
  591. if (err)
  592. return err;
  593. if (val < 1 || val > 3)
  594. return -EINVAL;
  595. mutex_lock(&data->update_lock);
  596. switch (val) {
  597. case 1:
  598. data->pwmenable[nr] = 0; /* manual mode */
  599. break;
  600. case 2:
  601. data->pwmenable[nr] = 2; /* Smart Fan II */
  602. break;
  603. case 3:
  604. data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */
  605. break;
  606. }
  607. cfg1_tmp = data->pwmenable[0];
  608. cfg2_tmp = (data->pwmenable[1]) << 2;
  609. cfg3_tmp = (data->pwmenable[2]) << 4;
  610. cfg4_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG) & 0xc0;
  611. fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
  612. w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
  613. mutex_unlock(&data->update_lock);
  614. return count;
  615. }
  616. static ssize_t
  617. show_pwm_mode(struct device *dev, struct device_attribute *attr,
  618. char *buf)
  619. {
  620. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  621. int nr = sensor_attr->index;
  622. struct w83792d_data *data = w83792d_update_device(dev);
  623. return sprintf(buf, "%d\n", data->pwm[nr] >> 7);
  624. }
  625. static ssize_t
  626. store_pwm_mode(struct device *dev, struct device_attribute *attr,
  627. const char *buf, size_t count)
  628. {
  629. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  630. int nr = sensor_attr->index;
  631. struct i2c_client *client = to_i2c_client(dev);
  632. struct w83792d_data *data = i2c_get_clientdata(client);
  633. unsigned long val;
  634. int err;
  635. err = kstrtoul(buf, 10, &val);
  636. if (err)
  637. return err;
  638. if (val > 1)
  639. return -EINVAL;
  640. mutex_lock(&data->update_lock);
  641. data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]);
  642. if (val) { /* PWM mode */
  643. data->pwm[nr] |= 0x80;
  644. } else { /* DC mode */
  645. data->pwm[nr] &= 0x7f;
  646. }
  647. w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
  648. mutex_unlock(&data->update_lock);
  649. return count;
  650. }
  651. static ssize_t
  652. show_chassis_clear(struct device *dev, struct device_attribute *attr,
  653. char *buf)
  654. {
  655. struct w83792d_data *data = w83792d_update_device(dev);
  656. return sprintf(buf, "%d\n", data->chassis);
  657. }
  658. static ssize_t
  659. store_chassis_clear(struct device *dev, struct device_attribute *attr,
  660. const char *buf, size_t count)
  661. {
  662. struct i2c_client *client = to_i2c_client(dev);
  663. struct w83792d_data *data = i2c_get_clientdata(client);
  664. unsigned long val;
  665. u8 reg;
  666. if (kstrtoul(buf, 10, &val) || val != 0)
  667. return -EINVAL;
  668. mutex_lock(&data->update_lock);
  669. reg = w83792d_read_value(client, W83792D_REG_CHASSIS_CLR);
  670. w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, reg | 0x80);
  671. data->valid = 0; /* Force cache refresh */
  672. mutex_unlock(&data->update_lock);
  673. return count;
  674. }
  675. /* For Smart Fan I / Thermal Cruise */
  676. static ssize_t
  677. show_thermal_cruise(struct device *dev, struct device_attribute *attr,
  678. char *buf)
  679. {
  680. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  681. int nr = sensor_attr->index;
  682. struct w83792d_data *data = w83792d_update_device(dev);
  683. return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]);
  684. }
  685. static ssize_t
  686. store_thermal_cruise(struct device *dev, struct device_attribute *attr,
  687. const char *buf, size_t count)
  688. {
  689. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  690. int nr = sensor_attr->index - 1;
  691. struct i2c_client *client = to_i2c_client(dev);
  692. struct w83792d_data *data = i2c_get_clientdata(client);
  693. u8 target_tmp = 0, target_mask = 0;
  694. unsigned long val;
  695. int err;
  696. err = kstrtoul(buf, 10, &val);
  697. if (err)
  698. return err;
  699. target_tmp = val;
  700. target_tmp = target_tmp & 0x7f;
  701. mutex_lock(&data->update_lock);
  702. target_mask = w83792d_read_value(client,
  703. W83792D_REG_THERMAL[nr]) & 0x80;
  704. data->thermal_cruise[nr] = clamp_val(target_tmp, 0, 255);
  705. w83792d_write_value(client, W83792D_REG_THERMAL[nr],
  706. (data->thermal_cruise[nr]) | target_mask);
  707. mutex_unlock(&data->update_lock);
  708. return count;
  709. }
  710. /* For Smart Fan I/Thermal Cruise and Smart Fan II */
  711. static ssize_t
  712. show_tolerance(struct device *dev, struct device_attribute *attr,
  713. char *buf)
  714. {
  715. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  716. int nr = sensor_attr->index;
  717. struct w83792d_data *data = w83792d_update_device(dev);
  718. return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]);
  719. }
  720. static ssize_t
  721. store_tolerance(struct device *dev, struct device_attribute *attr,
  722. const char *buf, size_t count)
  723. {
  724. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  725. int nr = sensor_attr->index - 1;
  726. struct i2c_client *client = to_i2c_client(dev);
  727. struct w83792d_data *data = i2c_get_clientdata(client);
  728. u8 tol_tmp, tol_mask;
  729. unsigned long val;
  730. int err;
  731. err = kstrtoul(buf, 10, &val);
  732. if (err)
  733. return err;
  734. mutex_lock(&data->update_lock);
  735. tol_mask = w83792d_read_value(client,
  736. W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
  737. tol_tmp = clamp_val(val, 0, 15);
  738. tol_tmp &= 0x0f;
  739. data->tolerance[nr] = tol_tmp;
  740. if (nr == 1)
  741. tol_tmp <<= 4;
  742. w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
  743. tol_mask | tol_tmp);
  744. mutex_unlock(&data->update_lock);
  745. return count;
  746. }
  747. /* For Smart Fan II */
  748. static ssize_t
  749. show_sf2_point(struct device *dev, struct device_attribute *attr,
  750. char *buf)
  751. {
  752. struct sensor_device_attribute_2 *sensor_attr
  753. = to_sensor_dev_attr_2(attr);
  754. int nr = sensor_attr->nr;
  755. int index = sensor_attr->index;
  756. struct w83792d_data *data = w83792d_update_device(dev);
  757. return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]);
  758. }
  759. static ssize_t
  760. store_sf2_point(struct device *dev, struct device_attribute *attr,
  761. const char *buf, size_t count)
  762. {
  763. struct sensor_device_attribute_2 *sensor_attr
  764. = to_sensor_dev_attr_2(attr);
  765. int nr = sensor_attr->nr - 1;
  766. int index = sensor_attr->index - 1;
  767. struct i2c_client *client = to_i2c_client(dev);
  768. struct w83792d_data *data = i2c_get_clientdata(client);
  769. u8 mask_tmp = 0;
  770. unsigned long val;
  771. int err;
  772. err = kstrtoul(buf, 10, &val);
  773. if (err)
  774. return err;
  775. mutex_lock(&data->update_lock);
  776. data->sf2_points[index][nr] = clamp_val(val, 0, 127);
  777. mask_tmp = w83792d_read_value(client,
  778. W83792D_REG_POINTS[index][nr]) & 0x80;
  779. w83792d_write_value(client, W83792D_REG_POINTS[index][nr],
  780. mask_tmp|data->sf2_points[index][nr]);
  781. mutex_unlock(&data->update_lock);
  782. return count;
  783. }
  784. static ssize_t
  785. show_sf2_level(struct device *dev, struct device_attribute *attr,
  786. char *buf)
  787. {
  788. struct sensor_device_attribute_2 *sensor_attr
  789. = to_sensor_dev_attr_2(attr);
  790. int nr = sensor_attr->nr;
  791. int index = sensor_attr->index;
  792. struct w83792d_data *data = w83792d_update_device(dev);
  793. return sprintf(buf, "%d\n",
  794. (((data->sf2_levels[index-1][nr]) * 100) / 15));
  795. }
  796. static ssize_t
  797. store_sf2_level(struct device *dev, struct device_attribute *attr,
  798. const char *buf, size_t count)
  799. {
  800. struct sensor_device_attribute_2 *sensor_attr
  801. = to_sensor_dev_attr_2(attr);
  802. int nr = sensor_attr->nr;
  803. int index = sensor_attr->index - 1;
  804. struct i2c_client *client = to_i2c_client(dev);
  805. struct w83792d_data *data = i2c_get_clientdata(client);
  806. u8 mask_tmp = 0, level_tmp = 0;
  807. unsigned long val;
  808. int err;
  809. err = kstrtoul(buf, 10, &val);
  810. if (err)
  811. return err;
  812. mutex_lock(&data->update_lock);
  813. data->sf2_levels[index][nr] = clamp_val((val * 15) / 100, 0, 15);
  814. mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
  815. & ((nr == 3) ? 0xf0 : 0x0f);
  816. if (nr == 3)
  817. level_tmp = data->sf2_levels[index][nr];
  818. else
  819. level_tmp = data->sf2_levels[index][nr] << 4;
  820. w83792d_write_value(client, W83792D_REG_LEVELS[index][nr],
  821. level_tmp | mask_tmp);
  822. mutex_unlock(&data->update_lock);
  823. return count;
  824. }
  825. static int
  826. w83792d_detect_subclients(struct i2c_client *new_client)
  827. {
  828. int i, id, err;
  829. int address = new_client->addr;
  830. u8 val;
  831. struct i2c_adapter *adapter = new_client->adapter;
  832. struct w83792d_data *data = i2c_get_clientdata(new_client);
  833. id = i2c_adapter_id(adapter);
  834. if (force_subclients[0] == id && force_subclients[1] == address) {
  835. for (i = 2; i <= 3; i++) {
  836. if (force_subclients[i] < 0x48 ||
  837. force_subclients[i] > 0x4f) {
  838. dev_err(&new_client->dev,
  839. "invalid subclient address %d; must be 0x48-0x4f\n",
  840. force_subclients[i]);
  841. err = -ENODEV;
  842. goto ERROR_SC_0;
  843. }
  844. }
  845. w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR,
  846. (force_subclients[2] & 0x07) |
  847. ((force_subclients[3] & 0x07) << 4));
  848. }
  849. val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
  850. if (!(val & 0x08))
  851. data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
  852. if (!(val & 0x80)) {
  853. if ((data->lm75[0] != NULL) &&
  854. ((val & 0x7) == ((val >> 4) & 0x7))) {
  855. dev_err(&new_client->dev,
  856. "duplicate addresses 0x%x, use force_subclient\n",
  857. data->lm75[0]->addr);
  858. err = -ENODEV;
  859. goto ERROR_SC_1;
  860. }
  861. data->lm75[1] = i2c_new_dummy(adapter,
  862. 0x48 + ((val >> 4) & 0x7));
  863. }
  864. return 0;
  865. /* Undo inits in case of errors */
  866. ERROR_SC_1:
  867. if (data->lm75[0] != NULL)
  868. i2c_unregister_device(data->lm75[0]);
  869. ERROR_SC_0:
  870. return err;
  871. }
  872. static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
  873. static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
  874. static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
  875. static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
  876. static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
  877. static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
  878. static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
  879. static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
  880. static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
  881. static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
  882. show_in_min, store_in_min, 0);
  883. static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
  884. show_in_min, store_in_min, 1);
  885. static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
  886. show_in_min, store_in_min, 2);
  887. static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
  888. show_in_min, store_in_min, 3);
  889. static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
  890. show_in_min, store_in_min, 4);
  891. static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
  892. show_in_min, store_in_min, 5);
  893. static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
  894. show_in_min, store_in_min, 6);
  895. static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
  896. show_in_min, store_in_min, 7);
  897. static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
  898. show_in_min, store_in_min, 8);
  899. static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
  900. show_in_max, store_in_max, 0);
  901. static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
  902. show_in_max, store_in_max, 1);
  903. static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
  904. show_in_max, store_in_max, 2);
  905. static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
  906. show_in_max, store_in_max, 3);
  907. static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
  908. show_in_max, store_in_max, 4);
  909. static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
  910. show_in_max, store_in_max, 5);
  911. static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
  912. show_in_max, store_in_max, 6);
  913. static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
  914. show_in_max, store_in_max, 7);
  915. static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
  916. show_in_max, store_in_max, 8);
  917. static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0);
  918. static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0);
  919. static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0);
  920. static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
  921. show_temp1, store_temp1, 0, 1);
  922. static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23,
  923. store_temp23, 0, 2);
  924. static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23,
  925. store_temp23, 1, 2);
  926. static SENSOR_DEVICE_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
  927. show_temp1, store_temp1, 0, 2);
  928. static SENSOR_DEVICE_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
  929. show_temp23, store_temp23, 0, 4);
  930. static SENSOR_DEVICE_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR,
  931. show_temp23, store_temp23, 1, 4);
  932. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
  933. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  934. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  935. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 2);
  936. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 3);
  937. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 4);
  938. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5);
  939. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6);
  940. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 7);
  941. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 8);
  942. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 9);
  943. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 10);
  944. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 11);
  945. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 12);
  946. static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 15);
  947. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 19);
  948. static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 20);
  949. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 21);
  950. static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22);
  951. static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23);
  952. static DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
  953. show_chassis_clear, store_chassis_clear);
  954. static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
  955. static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
  956. static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
  957. static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3);
  958. static SENSOR_DEVICE_ATTR(pwm5, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 4);
  959. static SENSOR_DEVICE_ATTR(pwm6, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 5);
  960. static SENSOR_DEVICE_ATTR(pwm7, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 6);
  961. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
  962. show_pwmenable, store_pwmenable, 1);
  963. static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
  964. show_pwmenable, store_pwmenable, 2);
  965. static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
  966. show_pwmenable, store_pwmenable, 3);
  967. static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
  968. show_pwm_mode, store_pwm_mode, 0);
  969. static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
  970. show_pwm_mode, store_pwm_mode, 1);
  971. static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
  972. show_pwm_mode, store_pwm_mode, 2);
  973. static SENSOR_DEVICE_ATTR(pwm4_mode, S_IWUSR | S_IRUGO,
  974. show_pwm_mode, store_pwm_mode, 3);
  975. static SENSOR_DEVICE_ATTR(pwm5_mode, S_IWUSR | S_IRUGO,
  976. show_pwm_mode, store_pwm_mode, 4);
  977. static SENSOR_DEVICE_ATTR(pwm6_mode, S_IWUSR | S_IRUGO,
  978. show_pwm_mode, store_pwm_mode, 5);
  979. static SENSOR_DEVICE_ATTR(pwm7_mode, S_IWUSR | S_IRUGO,
  980. show_pwm_mode, store_pwm_mode, 6);
  981. static SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
  982. show_tolerance, store_tolerance, 1);
  983. static SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
  984. show_tolerance, store_tolerance, 2);
  985. static SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
  986. show_tolerance, store_tolerance, 3);
  987. static SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
  988. show_thermal_cruise, store_thermal_cruise, 1);
  989. static SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
  990. show_thermal_cruise, store_thermal_cruise, 2);
  991. static SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
  992. show_thermal_cruise, store_thermal_cruise, 3);
  993. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
  994. show_sf2_point, store_sf2_point, 1, 1);
  995. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
  996. show_sf2_point, store_sf2_point, 2, 1);
  997. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
  998. show_sf2_point, store_sf2_point, 3, 1);
  999. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
  1000. show_sf2_point, store_sf2_point, 4, 1);
  1001. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
  1002. show_sf2_point, store_sf2_point, 1, 2);
  1003. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
  1004. show_sf2_point, store_sf2_point, 2, 2);
  1005. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
  1006. show_sf2_point, store_sf2_point, 3, 2);
  1007. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
  1008. show_sf2_point, store_sf2_point, 4, 2);
  1009. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
  1010. show_sf2_point, store_sf2_point, 1, 3);
  1011. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
  1012. show_sf2_point, store_sf2_point, 2, 3);
  1013. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
  1014. show_sf2_point, store_sf2_point, 3, 3);
  1015. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
  1016. show_sf2_point, store_sf2_point, 4, 3);
  1017. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
  1018. show_sf2_level, store_sf2_level, 1, 1);
  1019. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
  1020. show_sf2_level, store_sf2_level, 2, 1);
  1021. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
  1022. show_sf2_level, store_sf2_level, 3, 1);
  1023. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
  1024. show_sf2_level, store_sf2_level, 1, 2);
  1025. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
  1026. show_sf2_level, store_sf2_level, 2, 2);
  1027. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
  1028. show_sf2_level, store_sf2_level, 3, 2);
  1029. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
  1030. show_sf2_level, store_sf2_level, 1, 3);
  1031. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
  1032. show_sf2_level, store_sf2_level, 2, 3);
  1033. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
  1034. show_sf2_level, store_sf2_level, 3, 3);
  1035. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
  1036. static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
  1037. static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
  1038. static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
  1039. static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
  1040. static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
  1041. static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
  1042. static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
  1043. show_fan_min, store_fan_min, 1);
  1044. static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
  1045. show_fan_min, store_fan_min, 2);
  1046. static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
  1047. show_fan_min, store_fan_min, 3);
  1048. static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
  1049. show_fan_min, store_fan_min, 4);
  1050. static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
  1051. show_fan_min, store_fan_min, 5);
  1052. static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
  1053. show_fan_min, store_fan_min, 6);
  1054. static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
  1055. show_fan_min, store_fan_min, 7);
  1056. static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
  1057. show_fan_div, store_fan_div, 1);
  1058. static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
  1059. show_fan_div, store_fan_div, 2);
  1060. static SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
  1061. show_fan_div, store_fan_div, 3);
  1062. static SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
  1063. show_fan_div, store_fan_div, 4);
  1064. static SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
  1065. show_fan_div, store_fan_div, 5);
  1066. static SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
  1067. show_fan_div, store_fan_div, 6);
  1068. static SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
  1069. show_fan_div, store_fan_div, 7);
  1070. static struct attribute *w83792d_attributes_fan[4][7] = {
  1071. {
  1072. &sensor_dev_attr_fan4_input.dev_attr.attr,
  1073. &sensor_dev_attr_fan4_min.dev_attr.attr,
  1074. &sensor_dev_attr_fan4_div.dev_attr.attr,
  1075. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1076. &sensor_dev_attr_pwm4.dev_attr.attr,
  1077. &sensor_dev_attr_pwm4_mode.dev_attr.attr,
  1078. NULL
  1079. }, {
  1080. &sensor_dev_attr_fan5_input.dev_attr.attr,
  1081. &sensor_dev_attr_fan5_min.dev_attr.attr,
  1082. &sensor_dev_attr_fan5_div.dev_attr.attr,
  1083. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1084. &sensor_dev_attr_pwm5.dev_attr.attr,
  1085. &sensor_dev_attr_pwm5_mode.dev_attr.attr,
  1086. NULL
  1087. }, {
  1088. &sensor_dev_attr_fan6_input.dev_attr.attr,
  1089. &sensor_dev_attr_fan6_min.dev_attr.attr,
  1090. &sensor_dev_attr_fan6_div.dev_attr.attr,
  1091. &sensor_dev_attr_fan6_alarm.dev_attr.attr,
  1092. &sensor_dev_attr_pwm6.dev_attr.attr,
  1093. &sensor_dev_attr_pwm6_mode.dev_attr.attr,
  1094. NULL
  1095. }, {
  1096. &sensor_dev_attr_fan7_input.dev_attr.attr,
  1097. &sensor_dev_attr_fan7_min.dev_attr.attr,
  1098. &sensor_dev_attr_fan7_div.dev_attr.attr,
  1099. &sensor_dev_attr_fan7_alarm.dev_attr.attr,
  1100. &sensor_dev_attr_pwm7.dev_attr.attr,
  1101. &sensor_dev_attr_pwm7_mode.dev_attr.attr,
  1102. NULL
  1103. }
  1104. };
  1105. static const struct attribute_group w83792d_group_fan[4] = {
  1106. { .attrs = w83792d_attributes_fan[0] },
  1107. { .attrs = w83792d_attributes_fan[1] },
  1108. { .attrs = w83792d_attributes_fan[2] },
  1109. { .attrs = w83792d_attributes_fan[3] },
  1110. };
  1111. static struct attribute *w83792d_attributes[] = {
  1112. &sensor_dev_attr_in0_input.dev_attr.attr,
  1113. &sensor_dev_attr_in0_max.dev_attr.attr,
  1114. &sensor_dev_attr_in0_min.dev_attr.attr,
  1115. &sensor_dev_attr_in1_input.dev_attr.attr,
  1116. &sensor_dev_attr_in1_max.dev_attr.attr,
  1117. &sensor_dev_attr_in1_min.dev_attr.attr,
  1118. &sensor_dev_attr_in2_input.dev_attr.attr,
  1119. &sensor_dev_attr_in2_max.dev_attr.attr,
  1120. &sensor_dev_attr_in2_min.dev_attr.attr,
  1121. &sensor_dev_attr_in3_input.dev_attr.attr,
  1122. &sensor_dev_attr_in3_max.dev_attr.attr,
  1123. &sensor_dev_attr_in3_min.dev_attr.attr,
  1124. &sensor_dev_attr_in4_input.dev_attr.attr,
  1125. &sensor_dev_attr_in4_max.dev_attr.attr,
  1126. &sensor_dev_attr_in4_min.dev_attr.attr,
  1127. &sensor_dev_attr_in5_input.dev_attr.attr,
  1128. &sensor_dev_attr_in5_max.dev_attr.attr,
  1129. &sensor_dev_attr_in5_min.dev_attr.attr,
  1130. &sensor_dev_attr_in6_input.dev_attr.attr,
  1131. &sensor_dev_attr_in6_max.dev_attr.attr,
  1132. &sensor_dev_attr_in6_min.dev_attr.attr,
  1133. &sensor_dev_attr_in7_input.dev_attr.attr,
  1134. &sensor_dev_attr_in7_max.dev_attr.attr,
  1135. &sensor_dev_attr_in7_min.dev_attr.attr,
  1136. &sensor_dev_attr_in8_input.dev_attr.attr,
  1137. &sensor_dev_attr_in8_max.dev_attr.attr,
  1138. &sensor_dev_attr_in8_min.dev_attr.attr,
  1139. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  1140. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1141. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1142. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1143. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1144. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1145. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1146. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1147. &sensor_dev_attr_in8_alarm.dev_attr.attr,
  1148. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1149. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1150. &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
  1151. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1152. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1153. &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
  1154. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1155. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1156. &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
  1157. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1158. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1159. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1160. &sensor_dev_attr_pwm1.dev_attr.attr,
  1161. &sensor_dev_attr_pwm1_mode.dev_attr.attr,
  1162. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1163. &sensor_dev_attr_pwm2.dev_attr.attr,
  1164. &sensor_dev_attr_pwm2_mode.dev_attr.attr,
  1165. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1166. &sensor_dev_attr_pwm3.dev_attr.attr,
  1167. &sensor_dev_attr_pwm3_mode.dev_attr.attr,
  1168. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1169. &dev_attr_alarms.attr,
  1170. &dev_attr_intrusion0_alarm.attr,
  1171. &sensor_dev_attr_tolerance1.dev_attr.attr,
  1172. &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
  1173. &sensor_dev_attr_tolerance2.dev_attr.attr,
  1174. &sensor_dev_attr_thermal_cruise2.dev_attr.attr,
  1175. &sensor_dev_attr_tolerance3.dev_attr.attr,
  1176. &sensor_dev_attr_thermal_cruise3.dev_attr.attr,
  1177. &sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
  1178. &sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
  1179. &sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
  1180. &sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
  1181. &sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
  1182. &sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
  1183. &sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
  1184. &sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
  1185. &sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
  1186. &sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
  1187. &sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
  1188. &sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
  1189. &sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
  1190. &sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
  1191. &sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
  1192. &sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
  1193. &sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
  1194. &sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
  1195. &sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
  1196. &sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
  1197. &sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
  1198. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1199. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1200. &sensor_dev_attr_fan1_div.dev_attr.attr,
  1201. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1202. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1203. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1204. &sensor_dev_attr_fan2_div.dev_attr.attr,
  1205. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1206. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1207. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1208. &sensor_dev_attr_fan3_div.dev_attr.attr,
  1209. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1210. NULL
  1211. };
  1212. static const struct attribute_group w83792d_group = {
  1213. .attrs = w83792d_attributes,
  1214. };
  1215. /* Return 0 if detection is successful, -ENODEV otherwise */
  1216. static int
  1217. w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
  1218. {
  1219. struct i2c_adapter *adapter = client->adapter;
  1220. int val1, val2;
  1221. unsigned short address = client->addr;
  1222. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1223. return -ENODEV;
  1224. if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
  1225. return -ENODEV;
  1226. val1 = w83792d_read_value(client, W83792D_REG_BANK);
  1227. val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
  1228. /* Check for Winbond ID if in bank 0 */
  1229. if (!(val1 & 0x07)) { /* is Bank0 */
  1230. if ((!(val1 & 0x80) && val2 != 0xa3) ||
  1231. ((val1 & 0x80) && val2 != 0x5c))
  1232. return -ENODEV;
  1233. }
  1234. /*
  1235. * If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
  1236. * should match
  1237. */
  1238. if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
  1239. return -ENODEV;
  1240. /* Put it now into bank 0 and Vendor ID High Byte */
  1241. w83792d_write_value(client,
  1242. W83792D_REG_BANK,
  1243. (w83792d_read_value(client,
  1244. W83792D_REG_BANK) & 0x78) | 0x80);
  1245. /* Determine the chip type. */
  1246. val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
  1247. val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
  1248. if (val1 != 0x7a || val2 != 0x5c)
  1249. return -ENODEV;
  1250. strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
  1251. return 0;
  1252. }
  1253. static int
  1254. w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1255. {
  1256. struct w83792d_data *data;
  1257. struct device *dev = &client->dev;
  1258. int i, val1, err;
  1259. data = devm_kzalloc(dev, sizeof(struct w83792d_data), GFP_KERNEL);
  1260. if (!data)
  1261. return -ENOMEM;
  1262. i2c_set_clientdata(client, data);
  1263. mutex_init(&data->update_lock);
  1264. err = w83792d_detect_subclients(client);
  1265. if (err)
  1266. return err;
  1267. /* Initialize the chip */
  1268. w83792d_init_client(client);
  1269. /* A few vars need to be filled upon startup */
  1270. for (i = 0; i < 7; i++) {
  1271. data->fan_min[i] = w83792d_read_value(client,
  1272. W83792D_REG_FAN_MIN[i]);
  1273. }
  1274. /* Register sysfs hooks */
  1275. err = sysfs_create_group(&dev->kobj, &w83792d_group);
  1276. if (err)
  1277. goto exit_i2c_unregister;
  1278. /*
  1279. * Read GPIO enable register to check if pins for fan 4,5 are used as
  1280. * GPIO
  1281. */
  1282. val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
  1283. if (!(val1 & 0x40)) {
  1284. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]);
  1285. if (err)
  1286. goto exit_remove_files;
  1287. }
  1288. if (!(val1 & 0x20)) {
  1289. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]);
  1290. if (err)
  1291. goto exit_remove_files;
  1292. }
  1293. val1 = w83792d_read_value(client, W83792D_REG_PIN);
  1294. if (val1 & 0x40) {
  1295. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]);
  1296. if (err)
  1297. goto exit_remove_files;
  1298. }
  1299. if (val1 & 0x04) {
  1300. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]);
  1301. if (err)
  1302. goto exit_remove_files;
  1303. }
  1304. data->hwmon_dev = hwmon_device_register(dev);
  1305. if (IS_ERR(data->hwmon_dev)) {
  1306. err = PTR_ERR(data->hwmon_dev);
  1307. goto exit_remove_files;
  1308. }
  1309. return 0;
  1310. exit_remove_files:
  1311. sysfs_remove_group(&dev->kobj, &w83792d_group);
  1312. for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
  1313. sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
  1314. exit_i2c_unregister:
  1315. if (data->lm75[0] != NULL)
  1316. i2c_unregister_device(data->lm75[0]);
  1317. if (data->lm75[1] != NULL)
  1318. i2c_unregister_device(data->lm75[1]);
  1319. return err;
  1320. }
  1321. static int
  1322. w83792d_remove(struct i2c_client *client)
  1323. {
  1324. struct w83792d_data *data = i2c_get_clientdata(client);
  1325. int i;
  1326. hwmon_device_unregister(data->hwmon_dev);
  1327. sysfs_remove_group(&client->dev.kobj, &w83792d_group);
  1328. for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
  1329. sysfs_remove_group(&client->dev.kobj,
  1330. &w83792d_group_fan[i]);
  1331. if (data->lm75[0] != NULL)
  1332. i2c_unregister_device(data->lm75[0]);
  1333. if (data->lm75[1] != NULL)
  1334. i2c_unregister_device(data->lm75[1]);
  1335. return 0;
  1336. }
  1337. static void
  1338. w83792d_init_client(struct i2c_client *client)
  1339. {
  1340. u8 temp2_cfg, temp3_cfg, vid_in_b;
  1341. if (init)
  1342. w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
  1343. /*
  1344. * Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
  1345. * W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
  1346. * vin0/vin1 can be modified by user;
  1347. * W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
  1348. * vin0/vin1 auto-updated, can NOT be modified by user.
  1349. */
  1350. vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
  1351. w83792d_write_value(client, W83792D_REG_VID_IN_B,
  1352. vid_in_b & 0xbf);
  1353. temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG);
  1354. temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG);
  1355. w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG,
  1356. temp2_cfg & 0xe6);
  1357. w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG,
  1358. temp3_cfg & 0xe6);
  1359. /* Start monitoring */
  1360. w83792d_write_value(client, W83792D_REG_CONFIG,
  1361. (w83792d_read_value(client,
  1362. W83792D_REG_CONFIG) & 0xf7)
  1363. | 0x01);
  1364. }
  1365. static struct w83792d_data *w83792d_update_device(struct device *dev)
  1366. {
  1367. struct i2c_client *client = to_i2c_client(dev);
  1368. struct w83792d_data *data = i2c_get_clientdata(client);
  1369. int i, j;
  1370. u8 reg_array_tmp[4], reg_tmp;
  1371. mutex_lock(&data->update_lock);
  1372. if (time_after
  1373. (jiffies - data->last_updated, (unsigned long) (HZ * 3))
  1374. || time_before(jiffies, data->last_updated) || !data->valid) {
  1375. dev_dbg(dev, "Starting device update\n");
  1376. /* Update the voltages measured value and limits */
  1377. for (i = 0; i < 9; i++) {
  1378. data->in[i] = w83792d_read_value(client,
  1379. W83792D_REG_IN[i]);
  1380. data->in_max[i] = w83792d_read_value(client,
  1381. W83792D_REG_IN_MAX[i]);
  1382. data->in_min[i] = w83792d_read_value(client,
  1383. W83792D_REG_IN_MIN[i]);
  1384. }
  1385. data->low_bits = w83792d_read_value(client,
  1386. W83792D_REG_LOW_BITS1) +
  1387. (w83792d_read_value(client,
  1388. W83792D_REG_LOW_BITS2) << 8);
  1389. for (i = 0; i < 7; i++) {
  1390. /* Update the Fan measured value and limits */
  1391. data->fan[i] = w83792d_read_value(client,
  1392. W83792D_REG_FAN[i]);
  1393. data->fan_min[i] = w83792d_read_value(client,
  1394. W83792D_REG_FAN_MIN[i]);
  1395. /* Update the PWM/DC Value and PWM/DC flag */
  1396. data->pwm[i] = w83792d_read_value(client,
  1397. W83792D_REG_PWM[i]);
  1398. }
  1399. reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
  1400. data->pwmenable[0] = reg_tmp & 0x03;
  1401. data->pwmenable[1] = (reg_tmp>>2) & 0x03;
  1402. data->pwmenable[2] = (reg_tmp>>4) & 0x03;
  1403. for (i = 0; i < 3; i++) {
  1404. data->temp1[i] = w83792d_read_value(client,
  1405. W83792D_REG_TEMP1[i]);
  1406. }
  1407. for (i = 0; i < 2; i++) {
  1408. for (j = 0; j < 6; j++) {
  1409. data->temp_add[i][j] = w83792d_read_value(
  1410. client, W83792D_REG_TEMP_ADD[i][j]);
  1411. }
  1412. }
  1413. /* Update the Fan Divisor */
  1414. for (i = 0; i < 4; i++) {
  1415. reg_array_tmp[i] = w83792d_read_value(client,
  1416. W83792D_REG_FAN_DIV[i]);
  1417. }
  1418. data->fan_div[0] = reg_array_tmp[0] & 0x07;
  1419. data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07;
  1420. data->fan_div[2] = reg_array_tmp[1] & 0x07;
  1421. data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07;
  1422. data->fan_div[4] = reg_array_tmp[2] & 0x07;
  1423. data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07;
  1424. data->fan_div[6] = reg_array_tmp[3] & 0x07;
  1425. /* Update the realtime status */
  1426. data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) +
  1427. (w83792d_read_value(client, W83792D_REG_ALARM2) << 8) +
  1428. (w83792d_read_value(client, W83792D_REG_ALARM3) << 16);
  1429. /* Update CaseOpen status and it's CLR_CHS. */
  1430. data->chassis = (w83792d_read_value(client,
  1431. W83792D_REG_CHASSIS) >> 5) & 0x01;
  1432. /* Update Thermal Cruise/Smart Fan I target value */
  1433. for (i = 0; i < 3; i++) {
  1434. data->thermal_cruise[i] =
  1435. w83792d_read_value(client,
  1436. W83792D_REG_THERMAL[i]) & 0x7f;
  1437. }
  1438. /* Update Smart Fan I/II tolerance */
  1439. reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]);
  1440. data->tolerance[0] = reg_tmp & 0x0f;
  1441. data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
  1442. data->tolerance[2] = w83792d_read_value(client,
  1443. W83792D_REG_TOLERANCE[2]) & 0x0f;
  1444. /* Update Smart Fan II temperature points */
  1445. for (i = 0; i < 3; i++) {
  1446. for (j = 0; j < 4; j++) {
  1447. data->sf2_points[i][j]
  1448. = w83792d_read_value(client,
  1449. W83792D_REG_POINTS[i][j]) & 0x7f;
  1450. }
  1451. }
  1452. /* Update Smart Fan II duty cycle levels */
  1453. for (i = 0; i < 3; i++) {
  1454. reg_tmp = w83792d_read_value(client,
  1455. W83792D_REG_LEVELS[i][0]);
  1456. data->sf2_levels[i][0] = reg_tmp & 0x0f;
  1457. data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f;
  1458. reg_tmp = w83792d_read_value(client,
  1459. W83792D_REG_LEVELS[i][2]);
  1460. data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f;
  1461. data->sf2_levels[i][3] = reg_tmp & 0x0f;
  1462. }
  1463. data->last_updated = jiffies;
  1464. data->valid = 1;
  1465. }
  1466. mutex_unlock(&data->update_lock);
  1467. #ifdef DEBUG
  1468. w83792d_print_debug(data, dev);
  1469. #endif
  1470. return data;
  1471. }
  1472. #ifdef DEBUG
  1473. static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
  1474. {
  1475. int i = 0, j = 0;
  1476. dev_dbg(dev, "==========The following is the debug message...========\n");
  1477. dev_dbg(dev, "9 set of Voltages: =====>\n");
  1478. for (i = 0; i < 9; i++) {
  1479. dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
  1480. dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
  1481. dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
  1482. }
  1483. dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
  1484. dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
  1485. dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
  1486. for (i = 0; i < 7; i++) {
  1487. dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
  1488. dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
  1489. dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]);
  1490. }
  1491. dev_dbg(dev, "3 set of Temperatures: =====>\n");
  1492. for (i = 0; i < 3; i++)
  1493. dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
  1494. for (i = 0; i < 2; i++) {
  1495. for (j = 0; j < 6; j++) {
  1496. dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
  1497. data->temp_add[i][j]);
  1498. }
  1499. }
  1500. for (i = 0; i < 7; i++)
  1501. dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
  1502. dev_dbg(dev, "==========End of the debug message...================\n");
  1503. dev_dbg(dev, "\n");
  1504. }
  1505. #endif
  1506. module_i2c_driver(w83792d_driver);
  1507. MODULE_AUTHOR("Shane Huang (Winbond)");
  1508. MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
  1509. MODULE_LICENSE("GPL");