w83793.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200
  1. /*
  2. * w83793.c - Linux kernel driver for hardware monitoring
  3. * Copyright (C) 2006 Winbond Electronics Corp.
  4. * Yuan Mu
  5. * Rudolf Marek <r.marek@assembler.cz>
  6. * Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG.
  7. * Watchdog driver part
  8. * (Based partially on fschmd driver,
  9. * Copyright 2007-2008 by Hans de Goede)
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation - version 2.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  23. * 02110-1301 USA.
  24. */
  25. /*
  26. * Supports following chips:
  27. *
  28. * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
  29. * w83793 10 12 8 6 0x7b 0x5ca3 yes no
  30. */
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/i2c.h>
  35. #include <linux/hwmon.h>
  36. #include <linux/hwmon-vid.h>
  37. #include <linux/hwmon-sysfs.h>
  38. #include <linux/err.h>
  39. #include <linux/mutex.h>
  40. #include <linux/fs.h>
  41. #include <linux/watchdog.h>
  42. #include <linux/miscdevice.h>
  43. #include <linux/uaccess.h>
  44. #include <linux/kref.h>
  45. #include <linux/notifier.h>
  46. #include <linux/reboot.h>
  47. /* Default values */
  48. #define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
  49. /* Addresses to scan */
  50. static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
  51. I2C_CLIENT_END };
  52. /* Insmod parameters */
  53. static unsigned short force_subclients[4];
  54. module_param_array(force_subclients, short, NULL, 0);
  55. MODULE_PARM_DESC(force_subclients, "List of subclient addresses: "
  56. "{bus, clientaddr, subclientaddr1, subclientaddr2}");
  57. static bool reset;
  58. module_param(reset, bool, 0);
  59. MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
  60. static int timeout = WATCHDOG_TIMEOUT; /* default timeout in minutes */
  61. module_param(timeout, int, 0);
  62. MODULE_PARM_DESC(timeout,
  63. "Watchdog timeout in minutes. 2<= timeout <=255 (default="
  64. __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
  65. static bool nowayout = WATCHDOG_NOWAYOUT;
  66. module_param(nowayout, bool, 0);
  67. MODULE_PARM_DESC(nowayout,
  68. "Watchdog cannot be stopped once started (default="
  69. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  70. /*
  71. * Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
  72. * as ID, Bank Select registers
  73. */
  74. #define W83793_REG_BANKSEL 0x00
  75. #define W83793_REG_VENDORID 0x0d
  76. #define W83793_REG_CHIPID 0x0e
  77. #define W83793_REG_DEVICEID 0x0f
  78. #define W83793_REG_CONFIG 0x40
  79. #define W83793_REG_MFC 0x58
  80. #define W83793_REG_FANIN_CTRL 0x5c
  81. #define W83793_REG_FANIN_SEL 0x5d
  82. #define W83793_REG_I2C_ADDR 0x0b
  83. #define W83793_REG_I2C_SUBADDR 0x0c
  84. #define W83793_REG_VID_INA 0x05
  85. #define W83793_REG_VID_INB 0x06
  86. #define W83793_REG_VID_LATCHA 0x07
  87. #define W83793_REG_VID_LATCHB 0x08
  88. #define W83793_REG_VID_CTRL 0x59
  89. #define W83793_REG_WDT_LOCK 0x01
  90. #define W83793_REG_WDT_ENABLE 0x02
  91. #define W83793_REG_WDT_STATUS 0x03
  92. #define W83793_REG_WDT_TIMEOUT 0x04
  93. static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
  94. #define TEMP_READ 0
  95. #define TEMP_CRIT 1
  96. #define TEMP_CRIT_HYST 2
  97. #define TEMP_WARN 3
  98. #define TEMP_WARN_HYST 4
  99. /*
  100. * only crit and crit_hyst affect real-time alarm status
  101. * current crit crit_hyst warn warn_hyst
  102. */
  103. static u16 W83793_REG_TEMP[][5] = {
  104. {0x1c, 0x78, 0x79, 0x7a, 0x7b},
  105. {0x1d, 0x7c, 0x7d, 0x7e, 0x7f},
  106. {0x1e, 0x80, 0x81, 0x82, 0x83},
  107. {0x1f, 0x84, 0x85, 0x86, 0x87},
  108. {0x20, 0x88, 0x89, 0x8a, 0x8b},
  109. {0x21, 0x8c, 0x8d, 0x8e, 0x8f},
  110. };
  111. #define W83793_REG_TEMP_LOW_BITS 0x22
  112. #define W83793_REG_BEEP(index) (0x53 + (index))
  113. #define W83793_REG_ALARM(index) (0x4b + (index))
  114. #define W83793_REG_CLR_CHASSIS 0x4a /* SMI MASK4 */
  115. #define W83793_REG_IRQ_CTRL 0x50
  116. #define W83793_REG_OVT_CTRL 0x51
  117. #define W83793_REG_OVT_BEEP 0x52
  118. #define IN_READ 0
  119. #define IN_MAX 1
  120. #define IN_LOW 2
  121. static const u16 W83793_REG_IN[][3] = {
  122. /* Current, High, Low */
  123. {0x10, 0x60, 0x61}, /* Vcore A */
  124. {0x11, 0x62, 0x63}, /* Vcore B */
  125. {0x12, 0x64, 0x65}, /* Vtt */
  126. {0x14, 0x6a, 0x6b}, /* VSEN1 */
  127. {0x15, 0x6c, 0x6d}, /* VSEN2 */
  128. {0x16, 0x6e, 0x6f}, /* +3VSEN */
  129. {0x17, 0x70, 0x71}, /* +12VSEN */
  130. {0x18, 0x72, 0x73}, /* 5VDD */
  131. {0x19, 0x74, 0x75}, /* 5VSB */
  132. {0x1a, 0x76, 0x77}, /* VBAT */
  133. };
  134. /* Low Bits of Vcore A/B Vtt Read/High/Low */
  135. static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 };
  136. static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 };
  137. static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
  138. #define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */
  139. #define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */
  140. #define W83793_REG_PWM_DEFAULT 0xb2
  141. #define W83793_REG_PWM_ENABLE 0x207
  142. #define W83793_REG_PWM_UPTIME 0xc3 /* Unit in 0.1 second */
  143. #define W83793_REG_PWM_DOWNTIME 0xc4 /* Unit in 0.1 second */
  144. #define W83793_REG_TEMP_CRITICAL 0xc5
  145. #define PWM_DUTY 0
  146. #define PWM_START 1
  147. #define PWM_NONSTOP 2
  148. #define PWM_STOP_TIME 3
  149. #define W83793_REG_PWM(index, nr) (((nr) == 0 ? 0xb3 : \
  150. (nr) == 1 ? 0x220 : 0x218) + (index))
  151. /* bit field, fan1 is bit0, fan2 is bit1 ... */
  152. #define W83793_REG_TEMP_FAN_MAP(index) (0x201 + (index))
  153. #define W83793_REG_TEMP_TOL(index) (0x208 + (index))
  154. #define W83793_REG_TEMP_CRUISE(index) (0x210 + (index))
  155. #define W83793_REG_PWM_STOP_TIME(index) (0x228 + (index))
  156. #define W83793_REG_SF2_TEMP(index, nr) (0x230 + ((index) << 4) + (nr))
  157. #define W83793_REG_SF2_PWM(index, nr) (0x238 + ((index) << 4) + (nr))
  158. static inline unsigned long FAN_FROM_REG(u16 val)
  159. {
  160. if ((val >= 0xfff) || (val == 0))
  161. return 0;
  162. return 1350000UL / val;
  163. }
  164. static inline u16 FAN_TO_REG(long rpm)
  165. {
  166. if (rpm <= 0)
  167. return 0x0fff;
  168. return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe);
  169. }
  170. static inline unsigned long TIME_FROM_REG(u8 reg)
  171. {
  172. return reg * 100;
  173. }
  174. static inline u8 TIME_TO_REG(unsigned long val)
  175. {
  176. return SENSORS_LIMIT((val + 50) / 100, 0, 0xff);
  177. }
  178. static inline long TEMP_FROM_REG(s8 reg)
  179. {
  180. return reg * 1000;
  181. }
  182. static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
  183. {
  184. return SENSORS_LIMIT((val + (val < 0 ? -500 : 500)) / 1000, min, max);
  185. }
  186. struct w83793_data {
  187. struct i2c_client *lm75[2];
  188. struct device *hwmon_dev;
  189. struct mutex update_lock;
  190. char valid; /* !=0 if following fields are valid */
  191. unsigned long last_updated; /* In jiffies */
  192. unsigned long last_nonvolatile; /* In jiffies, last time we update the
  193. * nonvolatile registers
  194. */
  195. u8 bank;
  196. u8 vrm;
  197. u8 vid[2];
  198. u8 in[10][3]; /* Register value, read/high/low */
  199. u8 in_low_bits[3]; /* Additional resolution for VCore A/B Vtt */
  200. u16 has_fan; /* Only fan1- fan5 has own pins */
  201. u16 fan[12]; /* Register value combine */
  202. u16 fan_min[12]; /* Register value combine */
  203. s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */
  204. u8 temp_low_bits; /* Additional resolution TD1-TD4 */
  205. u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits
  206. * byte 1: Temp R1,R2 mode, each has 1 bit
  207. */
  208. u8 temp_critical; /* If reached all fan will be at full speed */
  209. u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */
  210. u8 has_pwm;
  211. u8 has_temp;
  212. u8 has_vid;
  213. u8 pwm_enable; /* Register value, each Temp has 1 bit */
  214. u8 pwm_uptime; /* Register value */
  215. u8 pwm_downtime; /* Register value */
  216. u8 pwm_default; /* All fan default pwm, next poweron valid */
  217. u8 pwm[8][3]; /* Register value */
  218. u8 pwm_stop_time[8];
  219. u8 temp_cruise[6];
  220. u8 alarms[5]; /* realtime status registers */
  221. u8 beeps[5];
  222. u8 beep_enable;
  223. u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */
  224. u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */
  225. u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */
  226. /* watchdog */
  227. struct i2c_client *client;
  228. struct mutex watchdog_lock;
  229. struct list_head list; /* member of the watchdog_data_list */
  230. struct kref kref;
  231. struct miscdevice watchdog_miscdev;
  232. unsigned long watchdog_is_open;
  233. char watchdog_expect_close;
  234. char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
  235. unsigned int watchdog_caused_reboot;
  236. int watchdog_timeout; /* watchdog timeout in minutes */
  237. };
  238. /*
  239. * Somewhat ugly :( global data pointer list with all devices, so that
  240. * we can find our device data as when using misc_register. There is no
  241. * other method to get to one's device data from the open file-op and
  242. * for usage in the reboot notifier callback.
  243. */
  244. static LIST_HEAD(watchdog_data_list);
  245. /* Note this lock not only protect list access, but also data.kref access */
  246. static DEFINE_MUTEX(watchdog_data_mutex);
  247. /*
  248. * Release our data struct when we're detached from the i2c client *and* all
  249. * references to our watchdog device are released
  250. */
  251. static void w83793_release_resources(struct kref *ref)
  252. {
  253. struct w83793_data *data = container_of(ref, struct w83793_data, kref);
  254. kfree(data);
  255. }
  256. static u8 w83793_read_value(struct i2c_client *client, u16 reg);
  257. static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
  258. static int w83793_probe(struct i2c_client *client,
  259. const struct i2c_device_id *id);
  260. static int w83793_detect(struct i2c_client *client,
  261. struct i2c_board_info *info);
  262. static int w83793_remove(struct i2c_client *client);
  263. static void w83793_init_client(struct i2c_client *client);
  264. static void w83793_update_nonvolatile(struct device *dev);
  265. static struct w83793_data *w83793_update_device(struct device *dev);
  266. static const struct i2c_device_id w83793_id[] = {
  267. { "w83793", 0 },
  268. { }
  269. };
  270. MODULE_DEVICE_TABLE(i2c, w83793_id);
  271. static struct i2c_driver w83793_driver = {
  272. .class = I2C_CLASS_HWMON,
  273. .driver = {
  274. .name = "w83793",
  275. },
  276. .probe = w83793_probe,
  277. .remove = w83793_remove,
  278. .id_table = w83793_id,
  279. .detect = w83793_detect,
  280. .address_list = normal_i2c,
  281. };
  282. static ssize_t
  283. show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
  284. {
  285. struct w83793_data *data = dev_get_drvdata(dev);
  286. return sprintf(buf, "%d\n", data->vrm);
  287. }
  288. static ssize_t
  289. show_vid(struct device *dev, struct device_attribute *attr, char *buf)
  290. {
  291. struct w83793_data *data = w83793_update_device(dev);
  292. struct sensor_device_attribute_2 *sensor_attr =
  293. to_sensor_dev_attr_2(attr);
  294. int index = sensor_attr->index;
  295. return sprintf(buf, "%d\n", vid_from_reg(data->vid[index], data->vrm));
  296. }
  297. static ssize_t
  298. store_vrm(struct device *dev, struct device_attribute *attr,
  299. const char *buf, size_t count)
  300. {
  301. struct w83793_data *data = dev_get_drvdata(dev);
  302. unsigned long val;
  303. int err;
  304. err = kstrtoul(buf, 10, &val);
  305. if (err)
  306. return err;
  307. data->vrm = val;
  308. return count;
  309. }
  310. #define ALARM_STATUS 0
  311. #define BEEP_ENABLE 1
  312. static ssize_t
  313. show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf)
  314. {
  315. struct w83793_data *data = w83793_update_device(dev);
  316. struct sensor_device_attribute_2 *sensor_attr =
  317. to_sensor_dev_attr_2(attr);
  318. int nr = sensor_attr->nr;
  319. int index = sensor_attr->index >> 3;
  320. int bit = sensor_attr->index & 0x07;
  321. u8 val;
  322. if (nr == ALARM_STATUS) {
  323. val = (data->alarms[index] >> (bit)) & 1;
  324. } else { /* BEEP_ENABLE */
  325. val = (data->beeps[index] >> (bit)) & 1;
  326. }
  327. return sprintf(buf, "%u\n", val);
  328. }
  329. static ssize_t
  330. store_beep(struct device *dev, struct device_attribute *attr,
  331. const char *buf, size_t count)
  332. {
  333. struct i2c_client *client = to_i2c_client(dev);
  334. struct w83793_data *data = i2c_get_clientdata(client);
  335. struct sensor_device_attribute_2 *sensor_attr =
  336. to_sensor_dev_attr_2(attr);
  337. int index = sensor_attr->index >> 3;
  338. int shift = sensor_attr->index & 0x07;
  339. u8 beep_bit = 1 << shift;
  340. unsigned long val;
  341. int err;
  342. err = kstrtoul(buf, 10, &val);
  343. if (err)
  344. return err;
  345. if (val > 1)
  346. return -EINVAL;
  347. mutex_lock(&data->update_lock);
  348. data->beeps[index] = w83793_read_value(client, W83793_REG_BEEP(index));
  349. data->beeps[index] &= ~beep_bit;
  350. data->beeps[index] |= val << shift;
  351. w83793_write_value(client, W83793_REG_BEEP(index), data->beeps[index]);
  352. mutex_unlock(&data->update_lock);
  353. return count;
  354. }
  355. static ssize_t
  356. show_beep_enable(struct device *dev, struct device_attribute *attr, char *buf)
  357. {
  358. struct w83793_data *data = w83793_update_device(dev);
  359. return sprintf(buf, "%u\n", (data->beep_enable >> 1) & 0x01);
  360. }
  361. static ssize_t
  362. store_beep_enable(struct device *dev, struct device_attribute *attr,
  363. const char *buf, size_t count)
  364. {
  365. struct i2c_client *client = to_i2c_client(dev);
  366. struct w83793_data *data = i2c_get_clientdata(client);
  367. unsigned long val;
  368. int err;
  369. err = kstrtoul(buf, 10, &val);
  370. if (err)
  371. return err;
  372. if (val > 1)
  373. return -EINVAL;
  374. mutex_lock(&data->update_lock);
  375. data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP)
  376. & 0xfd;
  377. data->beep_enable |= val << 1;
  378. w83793_write_value(client, W83793_REG_OVT_BEEP, data->beep_enable);
  379. mutex_unlock(&data->update_lock);
  380. return count;
  381. }
  382. /* Write any value to clear chassis alarm */
  383. static ssize_t
  384. store_chassis_clear_legacy(struct device *dev,
  385. struct device_attribute *attr, const char *buf,
  386. size_t count)
  387. {
  388. struct i2c_client *client = to_i2c_client(dev);
  389. struct w83793_data *data = i2c_get_clientdata(client);
  390. u8 val;
  391. dev_warn(dev, "Attribute chassis is deprecated, "
  392. "use intrusion0_alarm instead\n");
  393. mutex_lock(&data->update_lock);
  394. val = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
  395. val |= 0x80;
  396. w83793_write_value(client, W83793_REG_CLR_CHASSIS, val);
  397. mutex_unlock(&data->update_lock);
  398. return count;
  399. }
  400. /* Write 0 to clear chassis alarm */
  401. static ssize_t
  402. store_chassis_clear(struct device *dev,
  403. struct device_attribute *attr, const char *buf,
  404. size_t count)
  405. {
  406. struct i2c_client *client = to_i2c_client(dev);
  407. struct w83793_data *data = i2c_get_clientdata(client);
  408. unsigned long val;
  409. u8 reg;
  410. int err;
  411. err = kstrtoul(buf, 10, &val);
  412. if (err)
  413. return err;
  414. if (val)
  415. return -EINVAL;
  416. mutex_lock(&data->update_lock);
  417. reg = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
  418. w83793_write_value(client, W83793_REG_CLR_CHASSIS, reg | 0x80);
  419. data->valid = 0; /* Force cache refresh */
  420. mutex_unlock(&data->update_lock);
  421. return count;
  422. }
  423. #define FAN_INPUT 0
  424. #define FAN_MIN 1
  425. static ssize_t
  426. show_fan(struct device *dev, struct device_attribute *attr, char *buf)
  427. {
  428. struct sensor_device_attribute_2 *sensor_attr =
  429. to_sensor_dev_attr_2(attr);
  430. int nr = sensor_attr->nr;
  431. int index = sensor_attr->index;
  432. struct w83793_data *data = w83793_update_device(dev);
  433. u16 val;
  434. if (nr == FAN_INPUT)
  435. val = data->fan[index] & 0x0fff;
  436. else
  437. val = data->fan_min[index] & 0x0fff;
  438. return sprintf(buf, "%lu\n", FAN_FROM_REG(val));
  439. }
  440. static ssize_t
  441. store_fan_min(struct device *dev, struct device_attribute *attr,
  442. const char *buf, size_t count)
  443. {
  444. struct sensor_device_attribute_2 *sensor_attr =
  445. to_sensor_dev_attr_2(attr);
  446. int index = sensor_attr->index;
  447. struct i2c_client *client = to_i2c_client(dev);
  448. struct w83793_data *data = i2c_get_clientdata(client);
  449. unsigned long val;
  450. int err;
  451. err = kstrtoul(buf, 10, &val);
  452. if (err)
  453. return err;
  454. val = FAN_TO_REG(val);
  455. mutex_lock(&data->update_lock);
  456. data->fan_min[index] = val;
  457. w83793_write_value(client, W83793_REG_FAN_MIN(index),
  458. (val >> 8) & 0xff);
  459. w83793_write_value(client, W83793_REG_FAN_MIN(index) + 1, val & 0xff);
  460. mutex_unlock(&data->update_lock);
  461. return count;
  462. }
  463. static ssize_t
  464. show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
  465. {
  466. struct sensor_device_attribute_2 *sensor_attr =
  467. to_sensor_dev_attr_2(attr);
  468. struct w83793_data *data = w83793_update_device(dev);
  469. u16 val;
  470. int nr = sensor_attr->nr;
  471. int index = sensor_attr->index;
  472. if (nr == PWM_STOP_TIME)
  473. val = TIME_FROM_REG(data->pwm_stop_time[index]);
  474. else
  475. val = (data->pwm[index][nr] & 0x3f) << 2;
  476. return sprintf(buf, "%d\n", val);
  477. }
  478. static ssize_t
  479. store_pwm(struct device *dev, struct device_attribute *attr,
  480. const char *buf, size_t count)
  481. {
  482. struct i2c_client *client = to_i2c_client(dev);
  483. struct w83793_data *data = i2c_get_clientdata(client);
  484. struct sensor_device_attribute_2 *sensor_attr =
  485. to_sensor_dev_attr_2(attr);
  486. int nr = sensor_attr->nr;
  487. int index = sensor_attr->index;
  488. unsigned long val;
  489. int err;
  490. err = kstrtoul(buf, 10, &val);
  491. if (err)
  492. return err;
  493. mutex_lock(&data->update_lock);
  494. if (nr == PWM_STOP_TIME) {
  495. val = TIME_TO_REG(val);
  496. data->pwm_stop_time[index] = val;
  497. w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index),
  498. val);
  499. } else {
  500. val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
  501. data->pwm[index][nr] =
  502. w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0;
  503. data->pwm[index][nr] |= val;
  504. w83793_write_value(client, W83793_REG_PWM(index, nr),
  505. data->pwm[index][nr]);
  506. }
  507. mutex_unlock(&data->update_lock);
  508. return count;
  509. }
  510. static ssize_t
  511. show_temp(struct device *dev, struct device_attribute *attr, char *buf)
  512. {
  513. struct sensor_device_attribute_2 *sensor_attr =
  514. to_sensor_dev_attr_2(attr);
  515. int nr = sensor_attr->nr;
  516. int index = sensor_attr->index;
  517. struct w83793_data *data = w83793_update_device(dev);
  518. long temp = TEMP_FROM_REG(data->temp[index][nr]);
  519. if (nr == TEMP_READ && index < 4) { /* Only TD1-TD4 have low bits */
  520. int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250;
  521. temp += temp > 0 ? low : -low;
  522. }
  523. return sprintf(buf, "%ld\n", temp);
  524. }
  525. static ssize_t
  526. store_temp(struct device *dev, struct device_attribute *attr,
  527. const char *buf, size_t count)
  528. {
  529. struct sensor_device_attribute_2 *sensor_attr =
  530. to_sensor_dev_attr_2(attr);
  531. int nr = sensor_attr->nr;
  532. int index = sensor_attr->index;
  533. struct i2c_client *client = to_i2c_client(dev);
  534. struct w83793_data *data = i2c_get_clientdata(client);
  535. long tmp;
  536. int err;
  537. err = kstrtol(buf, 10, &tmp);
  538. if (err)
  539. return err;
  540. mutex_lock(&data->update_lock);
  541. data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127);
  542. w83793_write_value(client, W83793_REG_TEMP[index][nr],
  543. data->temp[index][nr]);
  544. mutex_unlock(&data->update_lock);
  545. return count;
  546. }
  547. /*
  548. * TD1-TD4
  549. * each has 4 mode:(2 bits)
  550. * 0: Stop monitor
  551. * 1: Use internal temp sensor(default)
  552. * 2: Reserved
  553. * 3: Use sensor in Intel CPU and get result by PECI
  554. *
  555. * TR1-TR2
  556. * each has 2 mode:(1 bit)
  557. * 0: Disable temp sensor monitor
  558. * 1: To enable temp sensors monitor
  559. */
  560. /* 0 disable, 6 PECI */
  561. static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
  562. static ssize_t
  563. show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
  564. {
  565. struct w83793_data *data = w83793_update_device(dev);
  566. struct sensor_device_attribute_2 *sensor_attr =
  567. to_sensor_dev_attr_2(attr);
  568. int index = sensor_attr->index;
  569. u8 mask = (index < 4) ? 0x03 : 0x01;
  570. u8 shift = (index < 4) ? (2 * index) : (index - 4);
  571. u8 tmp;
  572. index = (index < 4) ? 0 : 1;
  573. tmp = (data->temp_mode[index] >> shift) & mask;
  574. /* for the internal sensor, found out if diode or thermistor */
  575. if (tmp == 1)
  576. tmp = index == 0 ? 3 : 4;
  577. else
  578. tmp = TO_TEMP_MODE[tmp];
  579. return sprintf(buf, "%d\n", tmp);
  580. }
  581. static ssize_t
  582. store_temp_mode(struct device *dev, struct device_attribute *attr,
  583. const char *buf, size_t count)
  584. {
  585. struct i2c_client *client = to_i2c_client(dev);
  586. struct w83793_data *data = i2c_get_clientdata(client);
  587. struct sensor_device_attribute_2 *sensor_attr =
  588. to_sensor_dev_attr_2(attr);
  589. int index = sensor_attr->index;
  590. u8 mask = (index < 4) ? 0x03 : 0x01;
  591. u8 shift = (index < 4) ? (2 * index) : (index - 4);
  592. unsigned long val;
  593. int err;
  594. err = kstrtoul(buf, 10, &val);
  595. if (err)
  596. return err;
  597. /* transform the sysfs interface values into table above */
  598. if ((val == 6) && (index < 4)) {
  599. val -= 3;
  600. } else if ((val == 3 && index < 4)
  601. || (val == 4 && index >= 4)) {
  602. /* transform diode or thermistor into internal enable */
  603. val = !!val;
  604. } else {
  605. return -EINVAL;
  606. }
  607. index = (index < 4) ? 0 : 1;
  608. mutex_lock(&data->update_lock);
  609. data->temp_mode[index] =
  610. w83793_read_value(client, W83793_REG_TEMP_MODE[index]);
  611. data->temp_mode[index] &= ~(mask << shift);
  612. data->temp_mode[index] |= val << shift;
  613. w83793_write_value(client, W83793_REG_TEMP_MODE[index],
  614. data->temp_mode[index]);
  615. mutex_unlock(&data->update_lock);
  616. return count;
  617. }
  618. #define SETUP_PWM_DEFAULT 0
  619. #define SETUP_PWM_UPTIME 1 /* Unit in 0.1s */
  620. #define SETUP_PWM_DOWNTIME 2 /* Unit in 0.1s */
  621. #define SETUP_TEMP_CRITICAL 3
  622. static ssize_t
  623. show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf)
  624. {
  625. struct sensor_device_attribute_2 *sensor_attr =
  626. to_sensor_dev_attr_2(attr);
  627. int nr = sensor_attr->nr;
  628. struct w83793_data *data = w83793_update_device(dev);
  629. u32 val = 0;
  630. if (nr == SETUP_PWM_DEFAULT)
  631. val = (data->pwm_default & 0x3f) << 2;
  632. else if (nr == SETUP_PWM_UPTIME)
  633. val = TIME_FROM_REG(data->pwm_uptime);
  634. else if (nr == SETUP_PWM_DOWNTIME)
  635. val = TIME_FROM_REG(data->pwm_downtime);
  636. else if (nr == SETUP_TEMP_CRITICAL)
  637. val = TEMP_FROM_REG(data->temp_critical & 0x7f);
  638. return sprintf(buf, "%d\n", val);
  639. }
  640. static ssize_t
  641. store_sf_setup(struct device *dev, struct device_attribute *attr,
  642. const char *buf, size_t count)
  643. {
  644. struct sensor_device_attribute_2 *sensor_attr =
  645. to_sensor_dev_attr_2(attr);
  646. int nr = sensor_attr->nr;
  647. struct i2c_client *client = to_i2c_client(dev);
  648. struct w83793_data *data = i2c_get_clientdata(client);
  649. long val;
  650. int err;
  651. err = kstrtol(buf, 10, &val);
  652. if (err)
  653. return err;
  654. mutex_lock(&data->update_lock);
  655. if (nr == SETUP_PWM_DEFAULT) {
  656. data->pwm_default =
  657. w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0;
  658. data->pwm_default |= SENSORS_LIMIT(val, 0, 0xff) >> 2;
  659. w83793_write_value(client, W83793_REG_PWM_DEFAULT,
  660. data->pwm_default);
  661. } else if (nr == SETUP_PWM_UPTIME) {
  662. data->pwm_uptime = TIME_TO_REG(val);
  663. data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0;
  664. w83793_write_value(client, W83793_REG_PWM_UPTIME,
  665. data->pwm_uptime);
  666. } else if (nr == SETUP_PWM_DOWNTIME) {
  667. data->pwm_downtime = TIME_TO_REG(val);
  668. data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0;
  669. w83793_write_value(client, W83793_REG_PWM_DOWNTIME,
  670. data->pwm_downtime);
  671. } else { /* SETUP_TEMP_CRITICAL */
  672. data->temp_critical =
  673. w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80;
  674. data->temp_critical |= TEMP_TO_REG(val, 0, 0x7f);
  675. w83793_write_value(client, W83793_REG_TEMP_CRITICAL,
  676. data->temp_critical);
  677. }
  678. mutex_unlock(&data->update_lock);
  679. return count;
  680. }
  681. /*
  682. * Temp SmartFan control
  683. * TEMP_FAN_MAP
  684. * Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1...
  685. * It's possible two or more temp channels control the same fan, w83793
  686. * always prefers to pick the most critical request and applies it to
  687. * the related Fan.
  688. * It's possible one fan is not in any mapping of 6 temp channels, this
  689. * means the fan is manual mode
  690. *
  691. * TEMP_PWM_ENABLE
  692. * Each temp channel has its own SmartFan mode, and temp channel
  693. * control fans that are set by TEMP_FAN_MAP
  694. * 0: SmartFanII mode
  695. * 1: Thermal Cruise Mode
  696. *
  697. * TEMP_CRUISE
  698. * Target temperature in thermal cruise mode, w83793 will try to turn
  699. * fan speed to keep the temperature of target device around this
  700. * temperature.
  701. *
  702. * TEMP_TOLERANCE
  703. * If Temp higher or lower than target with this tolerance, w83793
  704. * will take actions to speed up or slow down the fan to keep the
  705. * temperature within the tolerance range.
  706. */
  707. #define TEMP_FAN_MAP 0
  708. #define TEMP_PWM_ENABLE 1
  709. #define TEMP_CRUISE 2
  710. #define TEMP_TOLERANCE 3
  711. static ssize_t
  712. show_sf_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
  713. {
  714. struct sensor_device_attribute_2 *sensor_attr =
  715. to_sensor_dev_attr_2(attr);
  716. int nr = sensor_attr->nr;
  717. int index = sensor_attr->index;
  718. struct w83793_data *data = w83793_update_device(dev);
  719. u32 val;
  720. if (nr == TEMP_FAN_MAP) {
  721. val = data->temp_fan_map[index];
  722. } else if (nr == TEMP_PWM_ENABLE) {
  723. /* +2 to transfrom into 2 and 3 to conform with sysfs intf */
  724. val = ((data->pwm_enable >> index) & 0x01) + 2;
  725. } else if (nr == TEMP_CRUISE) {
  726. val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f);
  727. } else { /* TEMP_TOLERANCE */
  728. val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0);
  729. val = TEMP_FROM_REG(val & 0x0f);
  730. }
  731. return sprintf(buf, "%d\n", val);
  732. }
  733. static ssize_t
  734. store_sf_ctrl(struct device *dev, struct device_attribute *attr,
  735. const char *buf, size_t count)
  736. {
  737. struct sensor_device_attribute_2 *sensor_attr =
  738. to_sensor_dev_attr_2(attr);
  739. int nr = sensor_attr->nr;
  740. int index = sensor_attr->index;
  741. struct i2c_client *client = to_i2c_client(dev);
  742. struct w83793_data *data = i2c_get_clientdata(client);
  743. long val;
  744. int err;
  745. err = kstrtol(buf, 10, &val);
  746. if (err)
  747. return err;
  748. mutex_lock(&data->update_lock);
  749. if (nr == TEMP_FAN_MAP) {
  750. val = SENSORS_LIMIT(val, 0, 255);
  751. w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val);
  752. data->temp_fan_map[index] = val;
  753. } else if (nr == TEMP_PWM_ENABLE) {
  754. if (val == 2 || val == 3) {
  755. data->pwm_enable =
  756. w83793_read_value(client, W83793_REG_PWM_ENABLE);
  757. if (val - 2)
  758. data->pwm_enable |= 1 << index;
  759. else
  760. data->pwm_enable &= ~(1 << index);
  761. w83793_write_value(client, W83793_REG_PWM_ENABLE,
  762. data->pwm_enable);
  763. } else {
  764. mutex_unlock(&data->update_lock);
  765. return -EINVAL;
  766. }
  767. } else if (nr == TEMP_CRUISE) {
  768. data->temp_cruise[index] =
  769. w83793_read_value(client, W83793_REG_TEMP_CRUISE(index));
  770. data->temp_cruise[index] &= 0x80;
  771. data->temp_cruise[index] |= TEMP_TO_REG(val, 0, 0x7f);
  772. w83793_write_value(client, W83793_REG_TEMP_CRUISE(index),
  773. data->temp_cruise[index]);
  774. } else { /* TEMP_TOLERANCE */
  775. int i = index >> 1;
  776. u8 shift = (index & 0x01) ? 4 : 0;
  777. data->tolerance[i] =
  778. w83793_read_value(client, W83793_REG_TEMP_TOL(i));
  779. data->tolerance[i] &= ~(0x0f << shift);
  780. data->tolerance[i] |= TEMP_TO_REG(val, 0, 0x0f) << shift;
  781. w83793_write_value(client, W83793_REG_TEMP_TOL(i),
  782. data->tolerance[i]);
  783. }
  784. mutex_unlock(&data->update_lock);
  785. return count;
  786. }
  787. static ssize_t
  788. show_sf2_pwm(struct device *dev, struct device_attribute *attr, char *buf)
  789. {
  790. struct sensor_device_attribute_2 *sensor_attr =
  791. to_sensor_dev_attr_2(attr);
  792. int nr = sensor_attr->nr;
  793. int index = sensor_attr->index;
  794. struct w83793_data *data = w83793_update_device(dev);
  795. return sprintf(buf, "%d\n", (data->sf2_pwm[index][nr] & 0x3f) << 2);
  796. }
  797. static ssize_t
  798. store_sf2_pwm(struct device *dev, struct device_attribute *attr,
  799. const char *buf, size_t count)
  800. {
  801. struct i2c_client *client = to_i2c_client(dev);
  802. struct w83793_data *data = i2c_get_clientdata(client);
  803. struct sensor_device_attribute_2 *sensor_attr =
  804. to_sensor_dev_attr_2(attr);
  805. int nr = sensor_attr->nr;
  806. int index = sensor_attr->index;
  807. unsigned long val;
  808. int err;
  809. err = kstrtoul(buf, 10, &val);
  810. if (err)
  811. return err;
  812. val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
  813. mutex_lock(&data->update_lock);
  814. data->sf2_pwm[index][nr] =
  815. w83793_read_value(client, W83793_REG_SF2_PWM(index, nr)) & 0xc0;
  816. data->sf2_pwm[index][nr] |= val;
  817. w83793_write_value(client, W83793_REG_SF2_PWM(index, nr),
  818. data->sf2_pwm[index][nr]);
  819. mutex_unlock(&data->update_lock);
  820. return count;
  821. }
  822. static ssize_t
  823. show_sf2_temp(struct device *dev, struct device_attribute *attr, char *buf)
  824. {
  825. struct sensor_device_attribute_2 *sensor_attr =
  826. to_sensor_dev_attr_2(attr);
  827. int nr = sensor_attr->nr;
  828. int index = sensor_attr->index;
  829. struct w83793_data *data = w83793_update_device(dev);
  830. return sprintf(buf, "%ld\n",
  831. TEMP_FROM_REG(data->sf2_temp[index][nr] & 0x7f));
  832. }
  833. static ssize_t
  834. store_sf2_temp(struct device *dev, struct device_attribute *attr,
  835. const char *buf, size_t count)
  836. {
  837. struct i2c_client *client = to_i2c_client(dev);
  838. struct w83793_data *data = i2c_get_clientdata(client);
  839. struct sensor_device_attribute_2 *sensor_attr =
  840. to_sensor_dev_attr_2(attr);
  841. int nr = sensor_attr->nr;
  842. int index = sensor_attr->index;
  843. long val;
  844. int err;
  845. err = kstrtol(buf, 10, &val);
  846. if (err)
  847. return err;
  848. val = TEMP_TO_REG(val, 0, 0x7f);
  849. mutex_lock(&data->update_lock);
  850. data->sf2_temp[index][nr] =
  851. w83793_read_value(client, W83793_REG_SF2_TEMP(index, nr)) & 0x80;
  852. data->sf2_temp[index][nr] |= val;
  853. w83793_write_value(client, W83793_REG_SF2_TEMP(index, nr),
  854. data->sf2_temp[index][nr]);
  855. mutex_unlock(&data->update_lock);
  856. return count;
  857. }
  858. /* only Vcore A/B and Vtt have additional 2 bits precision */
  859. static ssize_t
  860. show_in(struct device *dev, struct device_attribute *attr, char *buf)
  861. {
  862. struct sensor_device_attribute_2 *sensor_attr =
  863. to_sensor_dev_attr_2(attr);
  864. int nr = sensor_attr->nr;
  865. int index = sensor_attr->index;
  866. struct w83793_data *data = w83793_update_device(dev);
  867. u16 val = data->in[index][nr];
  868. if (index < 3) {
  869. val <<= 2;
  870. val += (data->in_low_bits[nr] >> (index * 2)) & 0x3;
  871. }
  872. /* voltage inputs 5VDD and 5VSB needs 150mV offset */
  873. val = val * scale_in[index] + scale_in_add[index];
  874. return sprintf(buf, "%d\n", val);
  875. }
  876. static ssize_t
  877. store_in(struct device *dev, struct device_attribute *attr,
  878. const char *buf, size_t count)
  879. {
  880. struct sensor_device_attribute_2 *sensor_attr =
  881. to_sensor_dev_attr_2(attr);
  882. int nr = sensor_attr->nr;
  883. int index = sensor_attr->index;
  884. struct i2c_client *client = to_i2c_client(dev);
  885. struct w83793_data *data = i2c_get_clientdata(client);
  886. unsigned long val;
  887. int err;
  888. err = kstrtoul(buf, 10, &val);
  889. if (err)
  890. return err;
  891. val = (val + scale_in[index] / 2) / scale_in[index];
  892. mutex_lock(&data->update_lock);
  893. if (index > 2) {
  894. /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
  895. if (nr == 1 || nr == 2)
  896. val -= scale_in_add[index] / scale_in[index];
  897. val = SENSORS_LIMIT(val, 0, 255);
  898. } else {
  899. val = SENSORS_LIMIT(val, 0, 0x3FF);
  900. data->in_low_bits[nr] =
  901. w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]);
  902. data->in_low_bits[nr] &= ~(0x03 << (2 * index));
  903. data->in_low_bits[nr] |= (val & 0x03) << (2 * index);
  904. w83793_write_value(client, W83793_REG_IN_LOW_BITS[nr],
  905. data->in_low_bits[nr]);
  906. val >>= 2;
  907. }
  908. data->in[index][nr] = val;
  909. w83793_write_value(client, W83793_REG_IN[index][nr],
  910. data->in[index][nr]);
  911. mutex_unlock(&data->update_lock);
  912. return count;
  913. }
  914. #define NOT_USED -1
  915. #define SENSOR_ATTR_IN(index) \
  916. SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
  917. IN_READ, index), \
  918. SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \
  919. store_in, IN_MAX, index), \
  920. SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \
  921. store_in, IN_LOW, index), \
  922. SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \
  923. NULL, ALARM_STATUS, index + ((index > 2) ? 1 : 0)), \
  924. SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \
  925. show_alarm_beep, store_beep, BEEP_ENABLE, \
  926. index + ((index > 2) ? 1 : 0))
  927. #define SENSOR_ATTR_FAN(index) \
  928. SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \
  929. NULL, ALARM_STATUS, index + 17), \
  930. SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \
  931. show_alarm_beep, store_beep, BEEP_ENABLE, index + 17), \
  932. SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
  933. NULL, FAN_INPUT, index - 1), \
  934. SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \
  935. show_fan, store_fan_min, FAN_MIN, index - 1)
  936. #define SENSOR_ATTR_PWM(index) \
  937. SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \
  938. store_pwm, PWM_DUTY, index - 1), \
  939. SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \
  940. show_pwm, store_pwm, PWM_NONSTOP, index - 1), \
  941. SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \
  942. show_pwm, store_pwm, PWM_START, index - 1), \
  943. SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \
  944. show_pwm, store_pwm, PWM_STOP_TIME, index - 1)
  945. #define SENSOR_ATTR_TEMP(index) \
  946. SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \
  947. show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
  948. SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \
  949. NULL, TEMP_READ, index - 1), \
  950. SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \
  951. store_temp, TEMP_CRIT, index - 1), \
  952. SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
  953. show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \
  954. SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_temp, \
  955. store_temp, TEMP_WARN, index - 1), \
  956. SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR, \
  957. show_temp, store_temp, TEMP_WARN_HYST, index - 1), \
  958. SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
  959. show_alarm_beep, NULL, ALARM_STATUS, index + 11), \
  960. SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
  961. show_alarm_beep, store_beep, BEEP_ENABLE, index + 11), \
  962. SENSOR_ATTR_2(temp##index##_auto_channels_pwm, \
  963. S_IRUGO | S_IWUSR, show_sf_ctrl, store_sf_ctrl, \
  964. TEMP_FAN_MAP, index - 1), \
  965. SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
  966. show_sf_ctrl, store_sf_ctrl, TEMP_PWM_ENABLE, \
  967. index - 1), \
  968. SENSOR_ATTR_2(thermal_cruise##index, S_IRUGO | S_IWUSR, \
  969. show_sf_ctrl, store_sf_ctrl, TEMP_CRUISE, index - 1), \
  970. SENSOR_ATTR_2(tolerance##index, S_IRUGO | S_IWUSR, show_sf_ctrl,\
  971. store_sf_ctrl, TEMP_TOLERANCE, index - 1), \
  972. SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \
  973. show_sf2_pwm, store_sf2_pwm, 0, index - 1), \
  974. SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \
  975. show_sf2_pwm, store_sf2_pwm, 1, index - 1), \
  976. SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \
  977. show_sf2_pwm, store_sf2_pwm, 2, index - 1), \
  978. SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \
  979. show_sf2_pwm, store_sf2_pwm, 3, index - 1), \
  980. SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \
  981. show_sf2_pwm, store_sf2_pwm, 4, index - 1), \
  982. SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \
  983. show_sf2_pwm, store_sf2_pwm, 5, index - 1), \
  984. SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \
  985. show_sf2_pwm, store_sf2_pwm, 6, index - 1), \
  986. SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\
  987. show_sf2_temp, store_sf2_temp, 0, index - 1), \
  988. SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\
  989. show_sf2_temp, store_sf2_temp, 1, index - 1), \
  990. SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\
  991. show_sf2_temp, store_sf2_temp, 2, index - 1), \
  992. SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\
  993. show_sf2_temp, store_sf2_temp, 3, index - 1), \
  994. SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\
  995. show_sf2_temp, store_sf2_temp, 4, index - 1), \
  996. SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\
  997. show_sf2_temp, store_sf2_temp, 5, index - 1), \
  998. SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\
  999. show_sf2_temp, store_sf2_temp, 6, index - 1)
  1000. static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
  1001. SENSOR_ATTR_IN(0),
  1002. SENSOR_ATTR_IN(1),
  1003. SENSOR_ATTR_IN(2),
  1004. SENSOR_ATTR_IN(3),
  1005. SENSOR_ATTR_IN(4),
  1006. SENSOR_ATTR_IN(5),
  1007. SENSOR_ATTR_IN(6),
  1008. SENSOR_ATTR_IN(7),
  1009. SENSOR_ATTR_IN(8),
  1010. SENSOR_ATTR_IN(9),
  1011. SENSOR_ATTR_FAN(1),
  1012. SENSOR_ATTR_FAN(2),
  1013. SENSOR_ATTR_FAN(3),
  1014. SENSOR_ATTR_FAN(4),
  1015. SENSOR_ATTR_FAN(5),
  1016. SENSOR_ATTR_PWM(1),
  1017. SENSOR_ATTR_PWM(2),
  1018. SENSOR_ATTR_PWM(3),
  1019. };
  1020. static struct sensor_device_attribute_2 w83793_temp[] = {
  1021. SENSOR_ATTR_TEMP(1),
  1022. SENSOR_ATTR_TEMP(2),
  1023. SENSOR_ATTR_TEMP(3),
  1024. SENSOR_ATTR_TEMP(4),
  1025. SENSOR_ATTR_TEMP(5),
  1026. SENSOR_ATTR_TEMP(6),
  1027. };
  1028. /* Fan6-Fan12 */
  1029. static struct sensor_device_attribute_2 w83793_left_fan[] = {
  1030. SENSOR_ATTR_FAN(6),
  1031. SENSOR_ATTR_FAN(7),
  1032. SENSOR_ATTR_FAN(8),
  1033. SENSOR_ATTR_FAN(9),
  1034. SENSOR_ATTR_FAN(10),
  1035. SENSOR_ATTR_FAN(11),
  1036. SENSOR_ATTR_FAN(12),
  1037. };
  1038. /* Pwm4-Pwm8 */
  1039. static struct sensor_device_attribute_2 w83793_left_pwm[] = {
  1040. SENSOR_ATTR_PWM(4),
  1041. SENSOR_ATTR_PWM(5),
  1042. SENSOR_ATTR_PWM(6),
  1043. SENSOR_ATTR_PWM(7),
  1044. SENSOR_ATTR_PWM(8),
  1045. };
  1046. static struct sensor_device_attribute_2 w83793_vid[] = {
  1047. SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0),
  1048. SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1),
  1049. };
  1050. static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm);
  1051. static struct sensor_device_attribute_2 sda_single_files[] = {
  1052. SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
  1053. store_chassis_clear_legacy, ALARM_STATUS, 30),
  1054. SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep,
  1055. store_chassis_clear, ALARM_STATUS, 30),
  1056. SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
  1057. store_beep_enable, NOT_USED, NOT_USED),
  1058. SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup,
  1059. store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED),
  1060. SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup,
  1061. store_sf_setup, SETUP_PWM_UPTIME, NOT_USED),
  1062. SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup,
  1063. store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED),
  1064. SENSOR_ATTR_2(temp_critical, S_IWUSR | S_IRUGO, show_sf_setup,
  1065. store_sf_setup, SETUP_TEMP_CRITICAL, NOT_USED),
  1066. };
  1067. static void w83793_init_client(struct i2c_client *client)
  1068. {
  1069. if (reset)
  1070. w83793_write_value(client, W83793_REG_CONFIG, 0x80);
  1071. /* Start monitoring */
  1072. w83793_write_value(client, W83793_REG_CONFIG,
  1073. w83793_read_value(client, W83793_REG_CONFIG) | 0x01);
  1074. }
  1075. /*
  1076. * Watchdog routines
  1077. */
  1078. static int watchdog_set_timeout(struct w83793_data *data, int timeout)
  1079. {
  1080. int ret, mtimeout;
  1081. mtimeout = DIV_ROUND_UP(timeout, 60);
  1082. if (mtimeout > 255)
  1083. return -EINVAL;
  1084. mutex_lock(&data->watchdog_lock);
  1085. if (!data->client) {
  1086. ret = -ENODEV;
  1087. goto leave;
  1088. }
  1089. data->watchdog_timeout = mtimeout;
  1090. /* Set Timeout value (in Minutes) */
  1091. w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
  1092. data->watchdog_timeout);
  1093. ret = mtimeout * 60;
  1094. leave:
  1095. mutex_unlock(&data->watchdog_lock);
  1096. return ret;
  1097. }
  1098. static int watchdog_get_timeout(struct w83793_data *data)
  1099. {
  1100. int timeout;
  1101. mutex_lock(&data->watchdog_lock);
  1102. timeout = data->watchdog_timeout * 60;
  1103. mutex_unlock(&data->watchdog_lock);
  1104. return timeout;
  1105. }
  1106. static int watchdog_trigger(struct w83793_data *data)
  1107. {
  1108. int ret = 0;
  1109. mutex_lock(&data->watchdog_lock);
  1110. if (!data->client) {
  1111. ret = -ENODEV;
  1112. goto leave;
  1113. }
  1114. /* Set Timeout value (in Minutes) */
  1115. w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
  1116. data->watchdog_timeout);
  1117. leave:
  1118. mutex_unlock(&data->watchdog_lock);
  1119. return ret;
  1120. }
  1121. static int watchdog_enable(struct w83793_data *data)
  1122. {
  1123. int ret = 0;
  1124. mutex_lock(&data->watchdog_lock);
  1125. if (!data->client) {
  1126. ret = -ENODEV;
  1127. goto leave;
  1128. }
  1129. /* Set initial timeout */
  1130. w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
  1131. data->watchdog_timeout);
  1132. /* Enable Soft Watchdog */
  1133. w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0x55);
  1134. leave:
  1135. mutex_unlock(&data->watchdog_lock);
  1136. return ret;
  1137. }
  1138. static int watchdog_disable(struct w83793_data *data)
  1139. {
  1140. int ret = 0;
  1141. mutex_lock(&data->watchdog_lock);
  1142. if (!data->client) {
  1143. ret = -ENODEV;
  1144. goto leave;
  1145. }
  1146. /* Disable Soft Watchdog */
  1147. w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0xAA);
  1148. leave:
  1149. mutex_unlock(&data->watchdog_lock);
  1150. return ret;
  1151. }
  1152. static int watchdog_open(struct inode *inode, struct file *filp)
  1153. {
  1154. struct w83793_data *pos, *data = NULL;
  1155. int watchdog_is_open;
  1156. /*
  1157. * We get called from drivers/char/misc.c with misc_mtx hold, and we
  1158. * call misc_register() from w83793_probe() with watchdog_data_mutex
  1159. * hold, as misc_register() takes the misc_mtx lock, this is a possible
  1160. * deadlock, so we use mutex_trylock here.
  1161. */
  1162. if (!mutex_trylock(&watchdog_data_mutex))
  1163. return -ERESTARTSYS;
  1164. list_for_each_entry(pos, &watchdog_data_list, list) {
  1165. if (pos->watchdog_miscdev.minor == iminor(inode)) {
  1166. data = pos;
  1167. break;
  1168. }
  1169. }
  1170. /* Check, if device is already open */
  1171. watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
  1172. /*
  1173. * Increase data reference counter (if not already done).
  1174. * Note we can never not have found data, so we don't check for this
  1175. */
  1176. if (!watchdog_is_open)
  1177. kref_get(&data->kref);
  1178. mutex_unlock(&watchdog_data_mutex);
  1179. /* Check, if device is already open and possibly issue error */
  1180. if (watchdog_is_open)
  1181. return -EBUSY;
  1182. /* Enable Soft Watchdog */
  1183. watchdog_enable(data);
  1184. /* Store pointer to data into filp's private data */
  1185. filp->private_data = data;
  1186. return nonseekable_open(inode, filp);
  1187. }
  1188. static int watchdog_close(struct inode *inode, struct file *filp)
  1189. {
  1190. struct w83793_data *data = filp->private_data;
  1191. if (data->watchdog_expect_close) {
  1192. watchdog_disable(data);
  1193. data->watchdog_expect_close = 0;
  1194. } else {
  1195. watchdog_trigger(data);
  1196. dev_crit(&data->client->dev,
  1197. "unexpected close, not stopping watchdog!\n");
  1198. }
  1199. clear_bit(0, &data->watchdog_is_open);
  1200. /* Decrease data reference counter */
  1201. mutex_lock(&watchdog_data_mutex);
  1202. kref_put(&data->kref, w83793_release_resources);
  1203. mutex_unlock(&watchdog_data_mutex);
  1204. return 0;
  1205. }
  1206. static ssize_t watchdog_write(struct file *filp, const char __user *buf,
  1207. size_t count, loff_t *offset)
  1208. {
  1209. ssize_t ret;
  1210. struct w83793_data *data = filp->private_data;
  1211. if (count) {
  1212. if (!nowayout) {
  1213. size_t i;
  1214. /* Clear it in case it was set with a previous write */
  1215. data->watchdog_expect_close = 0;
  1216. for (i = 0; i != count; i++) {
  1217. char c;
  1218. if (get_user(c, buf + i))
  1219. return -EFAULT;
  1220. if (c == 'V')
  1221. data->watchdog_expect_close = 1;
  1222. }
  1223. }
  1224. ret = watchdog_trigger(data);
  1225. if (ret < 0)
  1226. return ret;
  1227. }
  1228. return count;
  1229. }
  1230. static long watchdog_ioctl(struct file *filp, unsigned int cmd,
  1231. unsigned long arg)
  1232. {
  1233. struct watchdog_info ident = {
  1234. .options = WDIOF_KEEPALIVEPING |
  1235. WDIOF_SETTIMEOUT |
  1236. WDIOF_CARDRESET,
  1237. .identity = "w83793 watchdog"
  1238. };
  1239. int val, ret = 0;
  1240. struct w83793_data *data = filp->private_data;
  1241. switch (cmd) {
  1242. case WDIOC_GETSUPPORT:
  1243. if (!nowayout)
  1244. ident.options |= WDIOF_MAGICCLOSE;
  1245. if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
  1246. ret = -EFAULT;
  1247. break;
  1248. case WDIOC_GETSTATUS:
  1249. val = data->watchdog_caused_reboot ? WDIOF_CARDRESET : 0;
  1250. ret = put_user(val, (int __user *)arg);
  1251. break;
  1252. case WDIOC_GETBOOTSTATUS:
  1253. ret = put_user(0, (int __user *)arg);
  1254. break;
  1255. case WDIOC_KEEPALIVE:
  1256. ret = watchdog_trigger(data);
  1257. break;
  1258. case WDIOC_GETTIMEOUT:
  1259. val = watchdog_get_timeout(data);
  1260. ret = put_user(val, (int __user *)arg);
  1261. break;
  1262. case WDIOC_SETTIMEOUT:
  1263. if (get_user(val, (int __user *)arg)) {
  1264. ret = -EFAULT;
  1265. break;
  1266. }
  1267. ret = watchdog_set_timeout(data, val);
  1268. if (ret > 0)
  1269. ret = put_user(ret, (int __user *)arg);
  1270. break;
  1271. case WDIOC_SETOPTIONS:
  1272. if (get_user(val, (int __user *)arg)) {
  1273. ret = -EFAULT;
  1274. break;
  1275. }
  1276. if (val & WDIOS_DISABLECARD)
  1277. ret = watchdog_disable(data);
  1278. else if (val & WDIOS_ENABLECARD)
  1279. ret = watchdog_enable(data);
  1280. else
  1281. ret = -EINVAL;
  1282. break;
  1283. default:
  1284. ret = -ENOTTY;
  1285. }
  1286. return ret;
  1287. }
  1288. static const struct file_operations watchdog_fops = {
  1289. .owner = THIS_MODULE,
  1290. .llseek = no_llseek,
  1291. .open = watchdog_open,
  1292. .release = watchdog_close,
  1293. .write = watchdog_write,
  1294. .unlocked_ioctl = watchdog_ioctl,
  1295. };
  1296. /*
  1297. * Notifier for system down
  1298. */
  1299. static int watchdog_notify_sys(struct notifier_block *this, unsigned long code,
  1300. void *unused)
  1301. {
  1302. struct w83793_data *data = NULL;
  1303. if (code == SYS_DOWN || code == SYS_HALT) {
  1304. /* Disable each registered watchdog */
  1305. mutex_lock(&watchdog_data_mutex);
  1306. list_for_each_entry(data, &watchdog_data_list, list) {
  1307. if (data->watchdog_miscdev.minor)
  1308. watchdog_disable(data);
  1309. }
  1310. mutex_unlock(&watchdog_data_mutex);
  1311. }
  1312. return NOTIFY_DONE;
  1313. }
  1314. /*
  1315. * The WDT needs to learn about soft shutdowns in order to
  1316. * turn the timebomb registers off.
  1317. */
  1318. static struct notifier_block watchdog_notifier = {
  1319. .notifier_call = watchdog_notify_sys,
  1320. };
  1321. /*
  1322. * Init / remove routines
  1323. */
  1324. static int w83793_remove(struct i2c_client *client)
  1325. {
  1326. struct w83793_data *data = i2c_get_clientdata(client);
  1327. struct device *dev = &client->dev;
  1328. int i, tmp;
  1329. /* Unregister the watchdog (if registered) */
  1330. if (data->watchdog_miscdev.minor) {
  1331. misc_deregister(&data->watchdog_miscdev);
  1332. if (data->watchdog_is_open) {
  1333. dev_warn(&client->dev,
  1334. "i2c client detached with watchdog open! "
  1335. "Stopping watchdog.\n");
  1336. watchdog_disable(data);
  1337. }
  1338. mutex_lock(&watchdog_data_mutex);
  1339. list_del(&data->list);
  1340. mutex_unlock(&watchdog_data_mutex);
  1341. /* Tell the watchdog code the client is gone */
  1342. mutex_lock(&data->watchdog_lock);
  1343. data->client = NULL;
  1344. mutex_unlock(&data->watchdog_lock);
  1345. }
  1346. /* Reset Configuration Register to Disable Watch Dog Registers */
  1347. tmp = w83793_read_value(client, W83793_REG_CONFIG);
  1348. w83793_write_value(client, W83793_REG_CONFIG, tmp & ~0x04);
  1349. unregister_reboot_notifier(&watchdog_notifier);
  1350. hwmon_device_unregister(data->hwmon_dev);
  1351. for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++)
  1352. device_remove_file(dev,
  1353. &w83793_sensor_attr_2[i].dev_attr);
  1354. for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
  1355. device_remove_file(dev, &sda_single_files[i].dev_attr);
  1356. for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
  1357. device_remove_file(dev, &w83793_vid[i].dev_attr);
  1358. device_remove_file(dev, &dev_attr_vrm);
  1359. for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
  1360. device_remove_file(dev, &w83793_left_fan[i].dev_attr);
  1361. for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
  1362. device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
  1363. for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
  1364. device_remove_file(dev, &w83793_temp[i].dev_attr);
  1365. if (data->lm75[0] != NULL)
  1366. i2c_unregister_device(data->lm75[0]);
  1367. if (data->lm75[1] != NULL)
  1368. i2c_unregister_device(data->lm75[1]);
  1369. /* Decrease data reference counter */
  1370. mutex_lock(&watchdog_data_mutex);
  1371. kref_put(&data->kref, w83793_release_resources);
  1372. mutex_unlock(&watchdog_data_mutex);
  1373. return 0;
  1374. }
  1375. static int
  1376. w83793_detect_subclients(struct i2c_client *client)
  1377. {
  1378. int i, id, err;
  1379. int address = client->addr;
  1380. u8 tmp;
  1381. struct i2c_adapter *adapter = client->adapter;
  1382. struct w83793_data *data = i2c_get_clientdata(client);
  1383. id = i2c_adapter_id(adapter);
  1384. if (force_subclients[0] == id && force_subclients[1] == address) {
  1385. for (i = 2; i <= 3; i++) {
  1386. if (force_subclients[i] < 0x48
  1387. || force_subclients[i] > 0x4f) {
  1388. dev_err(&client->dev,
  1389. "invalid subclient "
  1390. "address %d; must be 0x48-0x4f\n",
  1391. force_subclients[i]);
  1392. err = -EINVAL;
  1393. goto ERROR_SC_0;
  1394. }
  1395. }
  1396. w83793_write_value(client, W83793_REG_I2C_SUBADDR,
  1397. (force_subclients[2] & 0x07) |
  1398. ((force_subclients[3] & 0x07) << 4));
  1399. }
  1400. tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
  1401. if (!(tmp & 0x08))
  1402. data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
  1403. if (!(tmp & 0x80)) {
  1404. if ((data->lm75[0] != NULL)
  1405. && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
  1406. dev_err(&client->dev,
  1407. "duplicate addresses 0x%x, "
  1408. "use force_subclients\n", data->lm75[0]->addr);
  1409. err = -ENODEV;
  1410. goto ERROR_SC_1;
  1411. }
  1412. data->lm75[1] = i2c_new_dummy(adapter,
  1413. 0x48 + ((tmp >> 4) & 0x7));
  1414. }
  1415. return 0;
  1416. /* Undo inits in case of errors */
  1417. ERROR_SC_1:
  1418. if (data->lm75[0] != NULL)
  1419. i2c_unregister_device(data->lm75[0]);
  1420. ERROR_SC_0:
  1421. return err;
  1422. }
  1423. /* Return 0 if detection is successful, -ENODEV otherwise */
  1424. static int w83793_detect(struct i2c_client *client,
  1425. struct i2c_board_info *info)
  1426. {
  1427. u8 tmp, bank, chip_id;
  1428. struct i2c_adapter *adapter = client->adapter;
  1429. unsigned short address = client->addr;
  1430. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1431. return -ENODEV;
  1432. bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
  1433. tmp = bank & 0x80 ? 0x5c : 0xa3;
  1434. /* Check Winbond vendor ID */
  1435. if (tmp != i2c_smbus_read_byte_data(client, W83793_REG_VENDORID)) {
  1436. pr_debug("w83793: Detection failed at check vendor id\n");
  1437. return -ENODEV;
  1438. }
  1439. /*
  1440. * If Winbond chip, address of chip and W83793_REG_I2C_ADDR
  1441. * should match
  1442. */
  1443. if ((bank & 0x07) == 0
  1444. && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
  1445. (address << 1)) {
  1446. pr_debug("w83793: Detection failed at check i2c addr\n");
  1447. return -ENODEV;
  1448. }
  1449. /* Determine the chip type now */
  1450. chip_id = i2c_smbus_read_byte_data(client, W83793_REG_CHIPID);
  1451. if (chip_id != 0x7b)
  1452. return -ENODEV;
  1453. strlcpy(info->type, "w83793", I2C_NAME_SIZE);
  1454. return 0;
  1455. }
  1456. static int w83793_probe(struct i2c_client *client,
  1457. const struct i2c_device_id *id)
  1458. {
  1459. struct device *dev = &client->dev;
  1460. const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
  1461. struct w83793_data *data;
  1462. int i, tmp, val, err;
  1463. int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
  1464. int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5;
  1465. int files_temp = ARRAY_SIZE(w83793_temp) / 6;
  1466. data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL);
  1467. if (!data) {
  1468. err = -ENOMEM;
  1469. goto exit;
  1470. }
  1471. i2c_set_clientdata(client, data);
  1472. data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
  1473. mutex_init(&data->update_lock);
  1474. mutex_init(&data->watchdog_lock);
  1475. INIT_LIST_HEAD(&data->list);
  1476. kref_init(&data->kref);
  1477. /*
  1478. * Store client pointer in our data struct for watchdog usage
  1479. * (where the client is found through a data ptr instead of the
  1480. * otherway around)
  1481. */
  1482. data->client = client;
  1483. err = w83793_detect_subclients(client);
  1484. if (err)
  1485. goto free_mem;
  1486. /* Initialize the chip */
  1487. w83793_init_client(client);
  1488. /*
  1489. * Only fan 1-5 has their own input pins,
  1490. * Pwm 1-3 has their own pins
  1491. */
  1492. data->has_fan = 0x1f;
  1493. data->has_pwm = 0x07;
  1494. tmp = w83793_read_value(client, W83793_REG_MFC);
  1495. val = w83793_read_value(client, W83793_REG_FANIN_CTRL);
  1496. /* check the function of pins 49-56 */
  1497. if (tmp & 0x80) {
  1498. data->has_vid |= 0x2; /* has VIDB */
  1499. } else {
  1500. data->has_pwm |= 0x18; /* pwm 4,5 */
  1501. if (val & 0x01) { /* fan 6 */
  1502. data->has_fan |= 0x20;
  1503. data->has_pwm |= 0x20;
  1504. }
  1505. if (val & 0x02) { /* fan 7 */
  1506. data->has_fan |= 0x40;
  1507. data->has_pwm |= 0x40;
  1508. }
  1509. if (!(tmp & 0x40) && (val & 0x04)) { /* fan 8 */
  1510. data->has_fan |= 0x80;
  1511. data->has_pwm |= 0x80;
  1512. }
  1513. }
  1514. /* check the function of pins 37-40 */
  1515. if (!(tmp & 0x29))
  1516. data->has_vid |= 0x1; /* has VIDA */
  1517. if (0x08 == (tmp & 0x0c)) {
  1518. if (val & 0x08) /* fan 9 */
  1519. data->has_fan |= 0x100;
  1520. if (val & 0x10) /* fan 10 */
  1521. data->has_fan |= 0x200;
  1522. }
  1523. if (0x20 == (tmp & 0x30)) {
  1524. if (val & 0x20) /* fan 11 */
  1525. data->has_fan |= 0x400;
  1526. if (val & 0x40) /* fan 12 */
  1527. data->has_fan |= 0x800;
  1528. }
  1529. if ((tmp & 0x01) && (val & 0x04)) { /* fan 8, second location */
  1530. data->has_fan |= 0x80;
  1531. data->has_pwm |= 0x80;
  1532. }
  1533. tmp = w83793_read_value(client, W83793_REG_FANIN_SEL);
  1534. if ((tmp & 0x01) && (val & 0x08)) { /* fan 9, second location */
  1535. data->has_fan |= 0x100;
  1536. }
  1537. if ((tmp & 0x02) && (val & 0x10)) { /* fan 10, second location */
  1538. data->has_fan |= 0x200;
  1539. }
  1540. if ((tmp & 0x04) && (val & 0x20)) { /* fan 11, second location */
  1541. data->has_fan |= 0x400;
  1542. }
  1543. if ((tmp & 0x08) && (val & 0x40)) { /* fan 12, second location */
  1544. data->has_fan |= 0x800;
  1545. }
  1546. /* check the temp1-6 mode, ignore former AMDSI selected inputs */
  1547. tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[0]);
  1548. if (tmp & 0x01)
  1549. data->has_temp |= 0x01;
  1550. if (tmp & 0x04)
  1551. data->has_temp |= 0x02;
  1552. if (tmp & 0x10)
  1553. data->has_temp |= 0x04;
  1554. if (tmp & 0x40)
  1555. data->has_temp |= 0x08;
  1556. tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[1]);
  1557. if (tmp & 0x01)
  1558. data->has_temp |= 0x10;
  1559. if (tmp & 0x02)
  1560. data->has_temp |= 0x20;
  1561. /* Register sysfs hooks */
  1562. for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) {
  1563. err = device_create_file(dev,
  1564. &w83793_sensor_attr_2[i].dev_attr);
  1565. if (err)
  1566. goto exit_remove;
  1567. }
  1568. for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) {
  1569. if (!(data->has_vid & (1 << i)))
  1570. continue;
  1571. err = device_create_file(dev, &w83793_vid[i].dev_attr);
  1572. if (err)
  1573. goto exit_remove;
  1574. }
  1575. if (data->has_vid) {
  1576. data->vrm = vid_which_vrm();
  1577. err = device_create_file(dev, &dev_attr_vrm);
  1578. if (err)
  1579. goto exit_remove;
  1580. }
  1581. for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
  1582. err = device_create_file(dev, &sda_single_files[i].dev_attr);
  1583. if (err)
  1584. goto exit_remove;
  1585. }
  1586. for (i = 0; i < 6; i++) {
  1587. int j;
  1588. if (!(data->has_temp & (1 << i)))
  1589. continue;
  1590. for (j = 0; j < files_temp; j++) {
  1591. err = device_create_file(dev,
  1592. &w83793_temp[(i) * files_temp
  1593. + j].dev_attr);
  1594. if (err)
  1595. goto exit_remove;
  1596. }
  1597. }
  1598. for (i = 5; i < 12; i++) {
  1599. int j;
  1600. if (!(data->has_fan & (1 << i)))
  1601. continue;
  1602. for (j = 0; j < files_fan; j++) {
  1603. err = device_create_file(dev,
  1604. &w83793_left_fan[(i - 5) * files_fan
  1605. + j].dev_attr);
  1606. if (err)
  1607. goto exit_remove;
  1608. }
  1609. }
  1610. for (i = 3; i < 8; i++) {
  1611. int j;
  1612. if (!(data->has_pwm & (1 << i)))
  1613. continue;
  1614. for (j = 0; j < files_pwm; j++) {
  1615. err = device_create_file(dev,
  1616. &w83793_left_pwm[(i - 3) * files_pwm
  1617. + j].dev_attr);
  1618. if (err)
  1619. goto exit_remove;
  1620. }
  1621. }
  1622. data->hwmon_dev = hwmon_device_register(dev);
  1623. if (IS_ERR(data->hwmon_dev)) {
  1624. err = PTR_ERR(data->hwmon_dev);
  1625. goto exit_remove;
  1626. }
  1627. /* Watchdog initialization */
  1628. /* Register boot notifier */
  1629. err = register_reboot_notifier(&watchdog_notifier);
  1630. if (err != 0) {
  1631. dev_err(&client->dev,
  1632. "cannot register reboot notifier (err=%d)\n", err);
  1633. goto exit_devunreg;
  1634. }
  1635. /*
  1636. * Enable Watchdog registers.
  1637. * Set Configuration Register to Enable Watch Dog Registers
  1638. * (Bit 2) = XXXX, X1XX.
  1639. */
  1640. tmp = w83793_read_value(client, W83793_REG_CONFIG);
  1641. w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04);
  1642. /* Set the default watchdog timeout */
  1643. data->watchdog_timeout = timeout;
  1644. /* Check, if last reboot was caused by watchdog */
  1645. data->watchdog_caused_reboot =
  1646. w83793_read_value(data->client, W83793_REG_WDT_STATUS) & 0x01;
  1647. /* Disable Soft Watchdog during initialiation */
  1648. watchdog_disable(data);
  1649. /*
  1650. * We take the data_mutex lock early so that watchdog_open() cannot
  1651. * run when misc_register() has completed, but we've not yet added
  1652. * our data to the watchdog_data_list (and set the default timeout)
  1653. */
  1654. mutex_lock(&watchdog_data_mutex);
  1655. for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
  1656. /* Register our watchdog part */
  1657. snprintf(data->watchdog_name, sizeof(data->watchdog_name),
  1658. "watchdog%c", (i == 0) ? '\0' : ('0' + i));
  1659. data->watchdog_miscdev.name = data->watchdog_name;
  1660. data->watchdog_miscdev.fops = &watchdog_fops;
  1661. data->watchdog_miscdev.minor = watchdog_minors[i];
  1662. err = misc_register(&data->watchdog_miscdev);
  1663. if (err == -EBUSY)
  1664. continue;
  1665. if (err) {
  1666. data->watchdog_miscdev.minor = 0;
  1667. dev_err(&client->dev,
  1668. "Registering watchdog chardev: %d\n", err);
  1669. break;
  1670. }
  1671. list_add(&data->list, &watchdog_data_list);
  1672. dev_info(&client->dev,
  1673. "Registered watchdog chardev major 10, minor: %d\n",
  1674. watchdog_minors[i]);
  1675. break;
  1676. }
  1677. if (i == ARRAY_SIZE(watchdog_minors)) {
  1678. data->watchdog_miscdev.minor = 0;
  1679. dev_warn(&client->dev, "Couldn't register watchdog chardev "
  1680. "(due to no free minor)\n");
  1681. }
  1682. mutex_unlock(&watchdog_data_mutex);
  1683. return 0;
  1684. /* Unregister hwmon device */
  1685. exit_devunreg:
  1686. hwmon_device_unregister(data->hwmon_dev);
  1687. /* Unregister sysfs hooks */
  1688. exit_remove:
  1689. for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++)
  1690. device_remove_file(dev, &w83793_sensor_attr_2[i].dev_attr);
  1691. for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
  1692. device_remove_file(dev, &sda_single_files[i].dev_attr);
  1693. for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
  1694. device_remove_file(dev, &w83793_vid[i].dev_attr);
  1695. for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
  1696. device_remove_file(dev, &w83793_left_fan[i].dev_attr);
  1697. for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
  1698. device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
  1699. for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
  1700. device_remove_file(dev, &w83793_temp[i].dev_attr);
  1701. if (data->lm75[0] != NULL)
  1702. i2c_unregister_device(data->lm75[0]);
  1703. if (data->lm75[1] != NULL)
  1704. i2c_unregister_device(data->lm75[1]);
  1705. free_mem:
  1706. kfree(data);
  1707. exit:
  1708. return err;
  1709. }
  1710. static void w83793_update_nonvolatile(struct device *dev)
  1711. {
  1712. struct i2c_client *client = to_i2c_client(dev);
  1713. struct w83793_data *data = i2c_get_clientdata(client);
  1714. int i, j;
  1715. /*
  1716. * They are somewhat "stable" registers, and to update them every time
  1717. * takes so much time, it's just not worthy. Update them in a long
  1718. * interval to avoid exception.
  1719. */
  1720. if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300)
  1721. || !data->valid))
  1722. return;
  1723. /* update voltage limits */
  1724. for (i = 1; i < 3; i++) {
  1725. for (j = 0; j < ARRAY_SIZE(data->in); j++) {
  1726. data->in[j][i] =
  1727. w83793_read_value(client, W83793_REG_IN[j][i]);
  1728. }
  1729. data->in_low_bits[i] =
  1730. w83793_read_value(client, W83793_REG_IN_LOW_BITS[i]);
  1731. }
  1732. for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) {
  1733. /* Update the Fan measured value and limits */
  1734. if (!(data->has_fan & (1 << i)))
  1735. continue;
  1736. data->fan_min[i] =
  1737. w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8;
  1738. data->fan_min[i] |=
  1739. w83793_read_value(client, W83793_REG_FAN_MIN(i) + 1);
  1740. }
  1741. for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) {
  1742. if (!(data->has_temp & (1 << i)))
  1743. continue;
  1744. data->temp_fan_map[i] =
  1745. w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i));
  1746. for (j = 1; j < 5; j++) {
  1747. data->temp[i][j] =
  1748. w83793_read_value(client, W83793_REG_TEMP[i][j]);
  1749. }
  1750. data->temp_cruise[i] =
  1751. w83793_read_value(client, W83793_REG_TEMP_CRUISE(i));
  1752. for (j = 0; j < 7; j++) {
  1753. data->sf2_pwm[i][j] =
  1754. w83793_read_value(client, W83793_REG_SF2_PWM(i, j));
  1755. data->sf2_temp[i][j] =
  1756. w83793_read_value(client,
  1757. W83793_REG_SF2_TEMP(i, j));
  1758. }
  1759. }
  1760. for (i = 0; i < ARRAY_SIZE(data->temp_mode); i++)
  1761. data->temp_mode[i] =
  1762. w83793_read_value(client, W83793_REG_TEMP_MODE[i]);
  1763. for (i = 0; i < ARRAY_SIZE(data->tolerance); i++) {
  1764. data->tolerance[i] =
  1765. w83793_read_value(client, W83793_REG_TEMP_TOL(i));
  1766. }
  1767. for (i = 0; i < ARRAY_SIZE(data->pwm); i++) {
  1768. if (!(data->has_pwm & (1 << i)))
  1769. continue;
  1770. data->pwm[i][PWM_NONSTOP] =
  1771. w83793_read_value(client, W83793_REG_PWM(i, PWM_NONSTOP));
  1772. data->pwm[i][PWM_START] =
  1773. w83793_read_value(client, W83793_REG_PWM(i, PWM_START));
  1774. data->pwm_stop_time[i] =
  1775. w83793_read_value(client, W83793_REG_PWM_STOP_TIME(i));
  1776. }
  1777. data->pwm_default = w83793_read_value(client, W83793_REG_PWM_DEFAULT);
  1778. data->pwm_enable = w83793_read_value(client, W83793_REG_PWM_ENABLE);
  1779. data->pwm_uptime = w83793_read_value(client, W83793_REG_PWM_UPTIME);
  1780. data->pwm_downtime = w83793_read_value(client, W83793_REG_PWM_DOWNTIME);
  1781. data->temp_critical =
  1782. w83793_read_value(client, W83793_REG_TEMP_CRITICAL);
  1783. data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP);
  1784. for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
  1785. data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i));
  1786. data->last_nonvolatile = jiffies;
  1787. }
  1788. static struct w83793_data *w83793_update_device(struct device *dev)
  1789. {
  1790. struct i2c_client *client = to_i2c_client(dev);
  1791. struct w83793_data *data = i2c_get_clientdata(client);
  1792. int i;
  1793. mutex_lock(&data->update_lock);
  1794. if (!(time_after(jiffies, data->last_updated + HZ * 2)
  1795. || !data->valid))
  1796. goto END;
  1797. /* Update the voltages measured value and limits */
  1798. for (i = 0; i < ARRAY_SIZE(data->in); i++)
  1799. data->in[i][IN_READ] =
  1800. w83793_read_value(client, W83793_REG_IN[i][IN_READ]);
  1801. data->in_low_bits[IN_READ] =
  1802. w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]);
  1803. for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
  1804. if (!(data->has_fan & (1 << i)))
  1805. continue;
  1806. data->fan[i] =
  1807. w83793_read_value(client, W83793_REG_FAN(i)) << 8;
  1808. data->fan[i] |=
  1809. w83793_read_value(client, W83793_REG_FAN(i) + 1);
  1810. }
  1811. for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
  1812. if (!(data->has_temp & (1 << i)))
  1813. continue;
  1814. data->temp[i][TEMP_READ] =
  1815. w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]);
  1816. }
  1817. data->temp_low_bits =
  1818. w83793_read_value(client, W83793_REG_TEMP_LOW_BITS);
  1819. for (i = 0; i < ARRAY_SIZE(data->pwm); i++) {
  1820. if (data->has_pwm & (1 << i))
  1821. data->pwm[i][PWM_DUTY] =
  1822. w83793_read_value(client,
  1823. W83793_REG_PWM(i, PWM_DUTY));
  1824. }
  1825. for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
  1826. data->alarms[i] =
  1827. w83793_read_value(client, W83793_REG_ALARM(i));
  1828. if (data->has_vid & 0x01)
  1829. data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA);
  1830. if (data->has_vid & 0x02)
  1831. data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB);
  1832. w83793_update_nonvolatile(dev);
  1833. data->last_updated = jiffies;
  1834. data->valid = 1;
  1835. END:
  1836. mutex_unlock(&data->update_lock);
  1837. return data;
  1838. }
  1839. /*
  1840. * Ignore the possibility that somebody change bank outside the driver
  1841. * Must be called with data->update_lock held, except during initialization
  1842. */
  1843. static u8 w83793_read_value(struct i2c_client *client, u16 reg)
  1844. {
  1845. struct w83793_data *data = i2c_get_clientdata(client);
  1846. u8 res = 0xff;
  1847. u8 new_bank = reg >> 8;
  1848. new_bank |= data->bank & 0xfc;
  1849. if (data->bank != new_bank) {
  1850. if (i2c_smbus_write_byte_data
  1851. (client, W83793_REG_BANKSEL, new_bank) >= 0)
  1852. data->bank = new_bank;
  1853. else {
  1854. dev_err(&client->dev,
  1855. "set bank to %d failed, fall back "
  1856. "to bank %d, read reg 0x%x error\n",
  1857. new_bank, data->bank, reg);
  1858. res = 0x0; /* read 0x0 from the chip */
  1859. goto END;
  1860. }
  1861. }
  1862. res = i2c_smbus_read_byte_data(client, reg & 0xff);
  1863. END:
  1864. return res;
  1865. }
  1866. /* Must be called with data->update_lock held, except during initialization */
  1867. static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value)
  1868. {
  1869. struct w83793_data *data = i2c_get_clientdata(client);
  1870. int res;
  1871. u8 new_bank = reg >> 8;
  1872. new_bank |= data->bank & 0xfc;
  1873. if (data->bank != new_bank) {
  1874. res = i2c_smbus_write_byte_data(client, W83793_REG_BANKSEL,
  1875. new_bank);
  1876. if (res < 0) {
  1877. dev_err(&client->dev,
  1878. "set bank to %d failed, fall back "
  1879. "to bank %d, write reg 0x%x error\n",
  1880. new_bank, data->bank, reg);
  1881. goto END;
  1882. }
  1883. data->bank = new_bank;
  1884. }
  1885. res = i2c_smbus_write_byte_data(client, reg & 0xff, value);
  1886. END:
  1887. return res;
  1888. }
  1889. module_i2c_driver(w83793_driver);
  1890. MODULE_AUTHOR("Yuan Mu, Sven Anders");
  1891. MODULE_DESCRIPTION("w83793 driver");
  1892. MODULE_LICENSE("GPL");