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. alarms_show(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. intrusion0_alarm_show(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. intrusion0_alarm_store(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_RO(alarms);
  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_RW(intrusion0_alarm);
  953. static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
  954. static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
  955. static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
  956. static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3);
  957. static SENSOR_DEVICE_ATTR(pwm5, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 4);
  958. static SENSOR_DEVICE_ATTR(pwm6, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 5);
  959. static SENSOR_DEVICE_ATTR(pwm7, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 6);
  960. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
  961. show_pwmenable, store_pwmenable, 1);
  962. static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
  963. show_pwmenable, store_pwmenable, 2);
  964. static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
  965. show_pwmenable, store_pwmenable, 3);
  966. static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
  967. show_pwm_mode, store_pwm_mode, 0);
  968. static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
  969. show_pwm_mode, store_pwm_mode, 1);
  970. static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
  971. show_pwm_mode, store_pwm_mode, 2);
  972. static SENSOR_DEVICE_ATTR(pwm4_mode, S_IWUSR | S_IRUGO,
  973. show_pwm_mode, store_pwm_mode, 3);
  974. static SENSOR_DEVICE_ATTR(pwm5_mode, S_IWUSR | S_IRUGO,
  975. show_pwm_mode, store_pwm_mode, 4);
  976. static SENSOR_DEVICE_ATTR(pwm6_mode, S_IWUSR | S_IRUGO,
  977. show_pwm_mode, store_pwm_mode, 5);
  978. static SENSOR_DEVICE_ATTR(pwm7_mode, S_IWUSR | S_IRUGO,
  979. show_pwm_mode, store_pwm_mode, 6);
  980. static SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
  981. show_tolerance, store_tolerance, 1);
  982. static SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
  983. show_tolerance, store_tolerance, 2);
  984. static SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
  985. show_tolerance, store_tolerance, 3);
  986. static SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
  987. show_thermal_cruise, store_thermal_cruise, 1);
  988. static SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
  989. show_thermal_cruise, store_thermal_cruise, 2);
  990. static SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
  991. show_thermal_cruise, store_thermal_cruise, 3);
  992. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
  993. show_sf2_point, store_sf2_point, 1, 1);
  994. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
  995. show_sf2_point, store_sf2_point, 2, 1);
  996. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
  997. show_sf2_point, store_sf2_point, 3, 1);
  998. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
  999. show_sf2_point, store_sf2_point, 4, 1);
  1000. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
  1001. show_sf2_point, store_sf2_point, 1, 2);
  1002. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
  1003. show_sf2_point, store_sf2_point, 2, 2);
  1004. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
  1005. show_sf2_point, store_sf2_point, 3, 2);
  1006. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
  1007. show_sf2_point, store_sf2_point, 4, 2);
  1008. static SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
  1009. show_sf2_point, store_sf2_point, 1, 3);
  1010. static SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
  1011. show_sf2_point, store_sf2_point, 2, 3);
  1012. static SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
  1013. show_sf2_point, store_sf2_point, 3, 3);
  1014. static SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
  1015. show_sf2_point, store_sf2_point, 4, 3);
  1016. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
  1017. show_sf2_level, store_sf2_level, 1, 1);
  1018. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
  1019. show_sf2_level, store_sf2_level, 2, 1);
  1020. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
  1021. show_sf2_level, store_sf2_level, 3, 1);
  1022. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
  1023. show_sf2_level, store_sf2_level, 1, 2);
  1024. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
  1025. show_sf2_level, store_sf2_level, 2, 2);
  1026. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
  1027. show_sf2_level, store_sf2_level, 3, 2);
  1028. static SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
  1029. show_sf2_level, store_sf2_level, 1, 3);
  1030. static SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
  1031. show_sf2_level, store_sf2_level, 2, 3);
  1032. static SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
  1033. show_sf2_level, store_sf2_level, 3, 3);
  1034. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
  1035. static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
  1036. static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
  1037. static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
  1038. static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
  1039. static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
  1040. static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
  1041. static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
  1042. show_fan_min, store_fan_min, 1);
  1043. static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
  1044. show_fan_min, store_fan_min, 2);
  1045. static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
  1046. show_fan_min, store_fan_min, 3);
  1047. static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
  1048. show_fan_min, store_fan_min, 4);
  1049. static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
  1050. show_fan_min, store_fan_min, 5);
  1051. static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
  1052. show_fan_min, store_fan_min, 6);
  1053. static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
  1054. show_fan_min, store_fan_min, 7);
  1055. static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
  1056. show_fan_div, store_fan_div, 1);
  1057. static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
  1058. show_fan_div, store_fan_div, 2);
  1059. static SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
  1060. show_fan_div, store_fan_div, 3);
  1061. static SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
  1062. show_fan_div, store_fan_div, 4);
  1063. static SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
  1064. show_fan_div, store_fan_div, 5);
  1065. static SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
  1066. show_fan_div, store_fan_div, 6);
  1067. static SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
  1068. show_fan_div, store_fan_div, 7);
  1069. static struct attribute *w83792d_attributes_fan[4][7] = {
  1070. {
  1071. &sensor_dev_attr_fan4_input.dev_attr.attr,
  1072. &sensor_dev_attr_fan4_min.dev_attr.attr,
  1073. &sensor_dev_attr_fan4_div.dev_attr.attr,
  1074. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1075. &sensor_dev_attr_pwm4.dev_attr.attr,
  1076. &sensor_dev_attr_pwm4_mode.dev_attr.attr,
  1077. NULL
  1078. }, {
  1079. &sensor_dev_attr_fan5_input.dev_attr.attr,
  1080. &sensor_dev_attr_fan5_min.dev_attr.attr,
  1081. &sensor_dev_attr_fan5_div.dev_attr.attr,
  1082. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1083. &sensor_dev_attr_pwm5.dev_attr.attr,
  1084. &sensor_dev_attr_pwm5_mode.dev_attr.attr,
  1085. NULL
  1086. }, {
  1087. &sensor_dev_attr_fan6_input.dev_attr.attr,
  1088. &sensor_dev_attr_fan6_min.dev_attr.attr,
  1089. &sensor_dev_attr_fan6_div.dev_attr.attr,
  1090. &sensor_dev_attr_fan6_alarm.dev_attr.attr,
  1091. &sensor_dev_attr_pwm6.dev_attr.attr,
  1092. &sensor_dev_attr_pwm6_mode.dev_attr.attr,
  1093. NULL
  1094. }, {
  1095. &sensor_dev_attr_fan7_input.dev_attr.attr,
  1096. &sensor_dev_attr_fan7_min.dev_attr.attr,
  1097. &sensor_dev_attr_fan7_div.dev_attr.attr,
  1098. &sensor_dev_attr_fan7_alarm.dev_attr.attr,
  1099. &sensor_dev_attr_pwm7.dev_attr.attr,
  1100. &sensor_dev_attr_pwm7_mode.dev_attr.attr,
  1101. NULL
  1102. }
  1103. };
  1104. static const struct attribute_group w83792d_group_fan[4] = {
  1105. { .attrs = w83792d_attributes_fan[0] },
  1106. { .attrs = w83792d_attributes_fan[1] },
  1107. { .attrs = w83792d_attributes_fan[2] },
  1108. { .attrs = w83792d_attributes_fan[3] },
  1109. };
  1110. static struct attribute *w83792d_attributes[] = {
  1111. &sensor_dev_attr_in0_input.dev_attr.attr,
  1112. &sensor_dev_attr_in0_max.dev_attr.attr,
  1113. &sensor_dev_attr_in0_min.dev_attr.attr,
  1114. &sensor_dev_attr_in1_input.dev_attr.attr,
  1115. &sensor_dev_attr_in1_max.dev_attr.attr,
  1116. &sensor_dev_attr_in1_min.dev_attr.attr,
  1117. &sensor_dev_attr_in2_input.dev_attr.attr,
  1118. &sensor_dev_attr_in2_max.dev_attr.attr,
  1119. &sensor_dev_attr_in2_min.dev_attr.attr,
  1120. &sensor_dev_attr_in3_input.dev_attr.attr,
  1121. &sensor_dev_attr_in3_max.dev_attr.attr,
  1122. &sensor_dev_attr_in3_min.dev_attr.attr,
  1123. &sensor_dev_attr_in4_input.dev_attr.attr,
  1124. &sensor_dev_attr_in4_max.dev_attr.attr,
  1125. &sensor_dev_attr_in4_min.dev_attr.attr,
  1126. &sensor_dev_attr_in5_input.dev_attr.attr,
  1127. &sensor_dev_attr_in5_max.dev_attr.attr,
  1128. &sensor_dev_attr_in5_min.dev_attr.attr,
  1129. &sensor_dev_attr_in6_input.dev_attr.attr,
  1130. &sensor_dev_attr_in6_max.dev_attr.attr,
  1131. &sensor_dev_attr_in6_min.dev_attr.attr,
  1132. &sensor_dev_attr_in7_input.dev_attr.attr,
  1133. &sensor_dev_attr_in7_max.dev_attr.attr,
  1134. &sensor_dev_attr_in7_min.dev_attr.attr,
  1135. &sensor_dev_attr_in8_input.dev_attr.attr,
  1136. &sensor_dev_attr_in8_max.dev_attr.attr,
  1137. &sensor_dev_attr_in8_min.dev_attr.attr,
  1138. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  1139. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1140. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1141. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1142. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1143. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1144. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1145. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1146. &sensor_dev_attr_in8_alarm.dev_attr.attr,
  1147. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1148. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1149. &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
  1150. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1151. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1152. &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
  1153. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1154. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1155. &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
  1156. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1157. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1158. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1159. &sensor_dev_attr_pwm1.dev_attr.attr,
  1160. &sensor_dev_attr_pwm1_mode.dev_attr.attr,
  1161. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1162. &sensor_dev_attr_pwm2.dev_attr.attr,
  1163. &sensor_dev_attr_pwm2_mode.dev_attr.attr,
  1164. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1165. &sensor_dev_attr_pwm3.dev_attr.attr,
  1166. &sensor_dev_attr_pwm3_mode.dev_attr.attr,
  1167. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1168. &dev_attr_alarms.attr,
  1169. &dev_attr_intrusion0_alarm.attr,
  1170. &sensor_dev_attr_tolerance1.dev_attr.attr,
  1171. &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
  1172. &sensor_dev_attr_tolerance2.dev_attr.attr,
  1173. &sensor_dev_attr_thermal_cruise2.dev_attr.attr,
  1174. &sensor_dev_attr_tolerance3.dev_attr.attr,
  1175. &sensor_dev_attr_thermal_cruise3.dev_attr.attr,
  1176. &sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
  1177. &sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
  1178. &sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
  1179. &sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
  1180. &sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
  1181. &sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
  1182. &sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
  1183. &sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
  1184. &sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
  1185. &sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
  1186. &sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
  1187. &sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
  1188. &sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
  1189. &sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
  1190. &sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
  1191. &sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
  1192. &sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
  1193. &sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
  1194. &sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
  1195. &sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
  1196. &sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
  1197. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1198. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1199. &sensor_dev_attr_fan1_div.dev_attr.attr,
  1200. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1201. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1202. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1203. &sensor_dev_attr_fan2_div.dev_attr.attr,
  1204. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1205. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1206. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1207. &sensor_dev_attr_fan3_div.dev_attr.attr,
  1208. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1209. NULL
  1210. };
  1211. static const struct attribute_group w83792d_group = {
  1212. .attrs = w83792d_attributes,
  1213. };
  1214. /* Return 0 if detection is successful, -ENODEV otherwise */
  1215. static int
  1216. w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
  1217. {
  1218. struct i2c_adapter *adapter = client->adapter;
  1219. int val1, val2;
  1220. unsigned short address = client->addr;
  1221. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1222. return -ENODEV;
  1223. if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
  1224. return -ENODEV;
  1225. val1 = w83792d_read_value(client, W83792D_REG_BANK);
  1226. val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
  1227. /* Check for Winbond ID if in bank 0 */
  1228. if (!(val1 & 0x07)) { /* is Bank0 */
  1229. if ((!(val1 & 0x80) && val2 != 0xa3) ||
  1230. ((val1 & 0x80) && val2 != 0x5c))
  1231. return -ENODEV;
  1232. }
  1233. /*
  1234. * If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
  1235. * should match
  1236. */
  1237. if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
  1238. return -ENODEV;
  1239. /* Put it now into bank 0 and Vendor ID High Byte */
  1240. w83792d_write_value(client,
  1241. W83792D_REG_BANK,
  1242. (w83792d_read_value(client,
  1243. W83792D_REG_BANK) & 0x78) | 0x80);
  1244. /* Determine the chip type. */
  1245. val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
  1246. val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
  1247. if (val1 != 0x7a || val2 != 0x5c)
  1248. return -ENODEV;
  1249. strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
  1250. return 0;
  1251. }
  1252. static int
  1253. w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1254. {
  1255. struct w83792d_data *data;
  1256. struct device *dev = &client->dev;
  1257. int i, val1, err;
  1258. data = devm_kzalloc(dev, sizeof(struct w83792d_data), GFP_KERNEL);
  1259. if (!data)
  1260. return -ENOMEM;
  1261. i2c_set_clientdata(client, data);
  1262. mutex_init(&data->update_lock);
  1263. err = w83792d_detect_subclients(client);
  1264. if (err)
  1265. return err;
  1266. /* Initialize the chip */
  1267. w83792d_init_client(client);
  1268. /* A few vars need to be filled upon startup */
  1269. for (i = 0; i < 7; i++) {
  1270. data->fan_min[i] = w83792d_read_value(client,
  1271. W83792D_REG_FAN_MIN[i]);
  1272. }
  1273. /* Register sysfs hooks */
  1274. err = sysfs_create_group(&dev->kobj, &w83792d_group);
  1275. if (err)
  1276. goto exit_i2c_unregister;
  1277. /*
  1278. * Read GPIO enable register to check if pins for fan 4,5 are used as
  1279. * GPIO
  1280. */
  1281. val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
  1282. if (!(val1 & 0x40)) {
  1283. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]);
  1284. if (err)
  1285. goto exit_remove_files;
  1286. }
  1287. if (!(val1 & 0x20)) {
  1288. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]);
  1289. if (err)
  1290. goto exit_remove_files;
  1291. }
  1292. val1 = w83792d_read_value(client, W83792D_REG_PIN);
  1293. if (val1 & 0x40) {
  1294. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]);
  1295. if (err)
  1296. goto exit_remove_files;
  1297. }
  1298. if (val1 & 0x04) {
  1299. err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]);
  1300. if (err)
  1301. goto exit_remove_files;
  1302. }
  1303. data->hwmon_dev = hwmon_device_register(dev);
  1304. if (IS_ERR(data->hwmon_dev)) {
  1305. err = PTR_ERR(data->hwmon_dev);
  1306. goto exit_remove_files;
  1307. }
  1308. return 0;
  1309. exit_remove_files:
  1310. sysfs_remove_group(&dev->kobj, &w83792d_group);
  1311. for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
  1312. sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
  1313. exit_i2c_unregister:
  1314. if (data->lm75[0] != NULL)
  1315. i2c_unregister_device(data->lm75[0]);
  1316. if (data->lm75[1] != NULL)
  1317. i2c_unregister_device(data->lm75[1]);
  1318. return err;
  1319. }
  1320. static int
  1321. w83792d_remove(struct i2c_client *client)
  1322. {
  1323. struct w83792d_data *data = i2c_get_clientdata(client);
  1324. int i;
  1325. hwmon_device_unregister(data->hwmon_dev);
  1326. sysfs_remove_group(&client->dev.kobj, &w83792d_group);
  1327. for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
  1328. sysfs_remove_group(&client->dev.kobj,
  1329. &w83792d_group_fan[i]);
  1330. if (data->lm75[0] != NULL)
  1331. i2c_unregister_device(data->lm75[0]);
  1332. if (data->lm75[1] != NULL)
  1333. i2c_unregister_device(data->lm75[1]);
  1334. return 0;
  1335. }
  1336. static void
  1337. w83792d_init_client(struct i2c_client *client)
  1338. {
  1339. u8 temp2_cfg, temp3_cfg, vid_in_b;
  1340. if (init)
  1341. w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
  1342. /*
  1343. * Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
  1344. * W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
  1345. * vin0/vin1 can be modified by user;
  1346. * W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
  1347. * vin0/vin1 auto-updated, can NOT be modified by user.
  1348. */
  1349. vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
  1350. w83792d_write_value(client, W83792D_REG_VID_IN_B,
  1351. vid_in_b & 0xbf);
  1352. temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG);
  1353. temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG);
  1354. w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG,
  1355. temp2_cfg & 0xe6);
  1356. w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG,
  1357. temp3_cfg & 0xe6);
  1358. /* Start monitoring */
  1359. w83792d_write_value(client, W83792D_REG_CONFIG,
  1360. (w83792d_read_value(client,
  1361. W83792D_REG_CONFIG) & 0xf7)
  1362. | 0x01);
  1363. }
  1364. static struct w83792d_data *w83792d_update_device(struct device *dev)
  1365. {
  1366. struct i2c_client *client = to_i2c_client(dev);
  1367. struct w83792d_data *data = i2c_get_clientdata(client);
  1368. int i, j;
  1369. u8 reg_array_tmp[4], reg_tmp;
  1370. mutex_lock(&data->update_lock);
  1371. if (time_after
  1372. (jiffies - data->last_updated, (unsigned long) (HZ * 3))
  1373. || time_before(jiffies, data->last_updated) || !data->valid) {
  1374. dev_dbg(dev, "Starting device update\n");
  1375. /* Update the voltages measured value and limits */
  1376. for (i = 0; i < 9; i++) {
  1377. data->in[i] = w83792d_read_value(client,
  1378. W83792D_REG_IN[i]);
  1379. data->in_max[i] = w83792d_read_value(client,
  1380. W83792D_REG_IN_MAX[i]);
  1381. data->in_min[i] = w83792d_read_value(client,
  1382. W83792D_REG_IN_MIN[i]);
  1383. }
  1384. data->low_bits = w83792d_read_value(client,
  1385. W83792D_REG_LOW_BITS1) +
  1386. (w83792d_read_value(client,
  1387. W83792D_REG_LOW_BITS2) << 8);
  1388. for (i = 0; i < 7; i++) {
  1389. /* Update the Fan measured value and limits */
  1390. data->fan[i] = w83792d_read_value(client,
  1391. W83792D_REG_FAN[i]);
  1392. data->fan_min[i] = w83792d_read_value(client,
  1393. W83792D_REG_FAN_MIN[i]);
  1394. /* Update the PWM/DC Value and PWM/DC flag */
  1395. data->pwm[i] = w83792d_read_value(client,
  1396. W83792D_REG_PWM[i]);
  1397. }
  1398. reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
  1399. data->pwmenable[0] = reg_tmp & 0x03;
  1400. data->pwmenable[1] = (reg_tmp>>2) & 0x03;
  1401. data->pwmenable[2] = (reg_tmp>>4) & 0x03;
  1402. for (i = 0; i < 3; i++) {
  1403. data->temp1[i] = w83792d_read_value(client,
  1404. W83792D_REG_TEMP1[i]);
  1405. }
  1406. for (i = 0; i < 2; i++) {
  1407. for (j = 0; j < 6; j++) {
  1408. data->temp_add[i][j] = w83792d_read_value(
  1409. client, W83792D_REG_TEMP_ADD[i][j]);
  1410. }
  1411. }
  1412. /* Update the Fan Divisor */
  1413. for (i = 0; i < 4; i++) {
  1414. reg_array_tmp[i] = w83792d_read_value(client,
  1415. W83792D_REG_FAN_DIV[i]);
  1416. }
  1417. data->fan_div[0] = reg_array_tmp[0] & 0x07;
  1418. data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07;
  1419. data->fan_div[2] = reg_array_tmp[1] & 0x07;
  1420. data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07;
  1421. data->fan_div[4] = reg_array_tmp[2] & 0x07;
  1422. data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07;
  1423. data->fan_div[6] = reg_array_tmp[3] & 0x07;
  1424. /* Update the realtime status */
  1425. data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) +
  1426. (w83792d_read_value(client, W83792D_REG_ALARM2) << 8) +
  1427. (w83792d_read_value(client, W83792D_REG_ALARM3) << 16);
  1428. /* Update CaseOpen status and it's CLR_CHS. */
  1429. data->chassis = (w83792d_read_value(client,
  1430. W83792D_REG_CHASSIS) >> 5) & 0x01;
  1431. /* Update Thermal Cruise/Smart Fan I target value */
  1432. for (i = 0; i < 3; i++) {
  1433. data->thermal_cruise[i] =
  1434. w83792d_read_value(client,
  1435. W83792D_REG_THERMAL[i]) & 0x7f;
  1436. }
  1437. /* Update Smart Fan I/II tolerance */
  1438. reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]);
  1439. data->tolerance[0] = reg_tmp & 0x0f;
  1440. data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
  1441. data->tolerance[2] = w83792d_read_value(client,
  1442. W83792D_REG_TOLERANCE[2]) & 0x0f;
  1443. /* Update Smart Fan II temperature points */
  1444. for (i = 0; i < 3; i++) {
  1445. for (j = 0; j < 4; j++) {
  1446. data->sf2_points[i][j]
  1447. = w83792d_read_value(client,
  1448. W83792D_REG_POINTS[i][j]) & 0x7f;
  1449. }
  1450. }
  1451. /* Update Smart Fan II duty cycle levels */
  1452. for (i = 0; i < 3; i++) {
  1453. reg_tmp = w83792d_read_value(client,
  1454. W83792D_REG_LEVELS[i][0]);
  1455. data->sf2_levels[i][0] = reg_tmp & 0x0f;
  1456. data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f;
  1457. reg_tmp = w83792d_read_value(client,
  1458. W83792D_REG_LEVELS[i][2]);
  1459. data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f;
  1460. data->sf2_levels[i][3] = reg_tmp & 0x0f;
  1461. }
  1462. data->last_updated = jiffies;
  1463. data->valid = 1;
  1464. }
  1465. mutex_unlock(&data->update_lock);
  1466. #ifdef DEBUG
  1467. w83792d_print_debug(data, dev);
  1468. #endif
  1469. return data;
  1470. }
  1471. #ifdef DEBUG
  1472. static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
  1473. {
  1474. int i = 0, j = 0;
  1475. dev_dbg(dev, "==========The following is the debug message...========\n");
  1476. dev_dbg(dev, "9 set of Voltages: =====>\n");
  1477. for (i = 0; i < 9; i++) {
  1478. dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
  1479. dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
  1480. dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
  1481. }
  1482. dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
  1483. dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
  1484. dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
  1485. for (i = 0; i < 7; i++) {
  1486. dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
  1487. dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
  1488. dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]);
  1489. }
  1490. dev_dbg(dev, "3 set of Temperatures: =====>\n");
  1491. for (i = 0; i < 3; i++)
  1492. dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
  1493. for (i = 0; i < 2; i++) {
  1494. for (j = 0; j < 6; j++) {
  1495. dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
  1496. data->temp_add[i][j]);
  1497. }
  1498. }
  1499. for (i = 0; i < 7; i++)
  1500. dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
  1501. dev_dbg(dev, "==========End of the debug message...================\n");
  1502. dev_dbg(dev, "\n");
  1503. }
  1504. #endif
  1505. module_i2c_driver(w83792d_driver);
  1506. MODULE_AUTHOR("Shane Huang (Winbond)");
  1507. MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
  1508. MODULE_LICENSE("GPL");