it87.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101
  1. /*
  2. * it87.c - Part of lm_sensors, Linux kernel modules for hardware
  3. * monitoring.
  4. *
  5. * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
  6. * parallel port, an IR port, a MIDI port, a floppy controller, etc., in
  7. * addition to an Environment Controller (Enhanced Hardware Monitor and
  8. * Fan Controller)
  9. *
  10. * This driver supports only the Environment Controller in the IT8705F and
  11. * similar parts. The other devices are supported by different drivers.
  12. *
  13. * Supports: IT8705F Super I/O chip w/LPC interface
  14. * IT8712F Super I/O chip w/LPC interface
  15. * IT8716F Super I/O chip w/LPC interface
  16. * IT8718F Super I/O chip w/LPC interface
  17. * IT8720F Super I/O chip w/LPC interface
  18. * IT8726F Super I/O chip w/LPC interface
  19. * Sis950 A clone of the IT8705F
  20. *
  21. * Copyright (C) 2001 Chris Gauthron
  22. * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
  23. *
  24. * This program is free software; you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation; either version 2 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License
  35. * along with this program; if not, write to the Free Software
  36. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. */
  38. #include <linux/module.h>
  39. #include <linux/init.h>
  40. #include <linux/slab.h>
  41. #include <linux/jiffies.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/hwmon.h>
  44. #include <linux/hwmon-sysfs.h>
  45. #include <linux/hwmon-vid.h>
  46. #include <linux/err.h>
  47. #include <linux/mutex.h>
  48. #include <linux/sysfs.h>
  49. #include <linux/string.h>
  50. #include <linux/dmi.h>
  51. #include <linux/acpi.h>
  52. #include <linux/io.h>
  53. #define DRVNAME "it87"
  54. enum chips { it87, it8712, it8716, it8718, it8720 };
  55. static unsigned short force_id;
  56. module_param(force_id, ushort, 0);
  57. MODULE_PARM_DESC(force_id, "Override the detected device ID");
  58. static struct platform_device *pdev;
  59. #define REG 0x2e /* The register to read/write */
  60. #define DEV 0x07 /* Register: Logical device select */
  61. #define VAL 0x2f /* The value to read/write */
  62. #define PME 0x04 /* The device with the fan registers in it */
  63. /* The device with the IT8718F/IT8720F VID value in it */
  64. #define GPIO 0x07
  65. #define DEVID 0x20 /* Register: Device ID */
  66. #define DEVREV 0x22 /* Register: Device Revision */
  67. static inline int
  68. superio_inb(int reg)
  69. {
  70. outb(reg, REG);
  71. return inb(VAL);
  72. }
  73. static int superio_inw(int reg)
  74. {
  75. int val;
  76. outb(reg++, REG);
  77. val = inb(VAL) << 8;
  78. outb(reg, REG);
  79. val |= inb(VAL);
  80. return val;
  81. }
  82. static inline void
  83. superio_select(int ldn)
  84. {
  85. outb(DEV, REG);
  86. outb(ldn, VAL);
  87. }
  88. static inline void
  89. superio_enter(void)
  90. {
  91. outb(0x87, REG);
  92. outb(0x01, REG);
  93. outb(0x55, REG);
  94. outb(0x55, REG);
  95. }
  96. static inline void
  97. superio_exit(void)
  98. {
  99. outb(0x02, REG);
  100. outb(0x02, VAL);
  101. }
  102. /* Logical device 4 registers */
  103. #define IT8712F_DEVID 0x8712
  104. #define IT8705F_DEVID 0x8705
  105. #define IT8716F_DEVID 0x8716
  106. #define IT8718F_DEVID 0x8718
  107. #define IT8720F_DEVID 0x8720
  108. #define IT8726F_DEVID 0x8726
  109. #define IT87_ACT_REG 0x30
  110. #define IT87_BASE_REG 0x60
  111. /* Logical device 7 registers (IT8712F and later) */
  112. #define IT87_SIO_GPIO3_REG 0x27
  113. #define IT87_SIO_GPIO5_REG 0x29
  114. #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
  115. #define IT87_SIO_VID_REG 0xfc /* VID value */
  116. #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
  117. /* Update battery voltage after every reading if true */
  118. static int update_vbat;
  119. /* Not all BIOSes properly configure the PWM registers */
  120. static int fix_pwm_polarity;
  121. /* Many IT87 constants specified below */
  122. /* Length of ISA address segment */
  123. #define IT87_EXTENT 8
  124. /* Length of ISA address segment for Environmental Controller */
  125. #define IT87_EC_EXTENT 2
  126. /* Offset of EC registers from ISA base address */
  127. #define IT87_EC_OFFSET 5
  128. /* Where are the ISA address/data registers relative to the EC base address */
  129. #define IT87_ADDR_REG_OFFSET 0
  130. #define IT87_DATA_REG_OFFSET 1
  131. /*----- The IT87 registers -----*/
  132. #define IT87_REG_CONFIG 0x00
  133. #define IT87_REG_ALARM1 0x01
  134. #define IT87_REG_ALARM2 0x02
  135. #define IT87_REG_ALARM3 0x03
  136. /* The IT8718F and IT8720F have the VID value in a different register, in
  137. Super-I/O configuration space. */
  138. #define IT87_REG_VID 0x0a
  139. /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
  140. for fan divisors. Later IT8712F revisions must use 16-bit tachometer
  141. mode. */
  142. #define IT87_REG_FAN_DIV 0x0b
  143. #define IT87_REG_FAN_16BIT 0x0c
  144. /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
  145. static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
  146. static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
  147. static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
  148. static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
  149. #define IT87_REG_FAN_MAIN_CTRL 0x13
  150. #define IT87_REG_FAN_CTL 0x14
  151. #define IT87_REG_PWM(nr) (0x15 + (nr))
  152. #define IT87_REG_VIN(nr) (0x20 + (nr))
  153. #define IT87_REG_TEMP(nr) (0x29 + (nr))
  154. #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
  155. #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
  156. #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
  157. #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
  158. #define IT87_REG_VIN_ENABLE 0x50
  159. #define IT87_REG_TEMP_ENABLE 0x51
  160. #define IT87_REG_BEEP_ENABLE 0x5c
  161. #define IT87_REG_CHIPID 0x58
  162. #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
  163. #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
  164. #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
  165. #define IN_FROM_REG(val) ((val) * 16)
  166. static inline u8 FAN_TO_REG(long rpm, int div)
  167. {
  168. if (rpm == 0)
  169. return 255;
  170. rpm = SENSORS_LIMIT(rpm, 1, 1000000);
  171. return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
  172. 254);
  173. }
  174. static inline u16 FAN16_TO_REG(long rpm)
  175. {
  176. if (rpm == 0)
  177. return 0xffff;
  178. return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
  179. }
  180. #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
  181. /* The divider is fixed to 2 in 16-bit mode */
  182. #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
  183. #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
  184. ((val)+500)/1000),-128,127))
  185. #define TEMP_FROM_REG(val) ((val) * 1000)
  186. #define PWM_TO_REG(val) ((val) >> 1)
  187. #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
  188. static int DIV_TO_REG(int val)
  189. {
  190. int answer = 0;
  191. while (answer < 7 && (val >>= 1))
  192. answer++;
  193. return answer;
  194. }
  195. #define DIV_FROM_REG(val) (1 << (val))
  196. static const unsigned int pwm_freq[8] = {
  197. 48000000 / 128,
  198. 24000000 / 128,
  199. 12000000 / 128,
  200. 8000000 / 128,
  201. 6000000 / 128,
  202. 3000000 / 128,
  203. 1500000 / 128,
  204. 750000 / 128,
  205. };
  206. struct it87_sio_data {
  207. enum chips type;
  208. /* Values read from Super-I/O config space */
  209. u8 revision;
  210. u8 vid_value;
  211. u8 beep_pin;
  212. /* Features skipped based on config or DMI */
  213. u8 skip_vid;
  214. u8 skip_fan;
  215. u8 skip_pwm;
  216. };
  217. /* For each registered chip, we need to keep some data in memory.
  218. The structure is dynamically allocated. */
  219. struct it87_data {
  220. struct device *hwmon_dev;
  221. enum chips type;
  222. u8 revision;
  223. unsigned short addr;
  224. const char *name;
  225. struct mutex update_lock;
  226. char valid; /* !=0 if following fields are valid */
  227. unsigned long last_updated; /* In jiffies */
  228. u8 in[9]; /* Register value */
  229. u8 in_max[8]; /* Register value */
  230. u8 in_min[8]; /* Register value */
  231. u8 has_fan; /* Bitfield, fans enabled */
  232. u16 fan[5]; /* Register values, possibly combined */
  233. u16 fan_min[5]; /* Register values, possibly combined */
  234. s8 temp[3]; /* Register value */
  235. s8 temp_high[3]; /* Register value */
  236. s8 temp_low[3]; /* Register value */
  237. u8 sensor; /* Register value */
  238. u8 fan_div[3]; /* Register encoding, shifted right */
  239. u8 vid; /* Register encoding, combined */
  240. u8 vrm;
  241. u32 alarms; /* Register encoding, combined */
  242. u8 beeps; /* Register encoding */
  243. u8 fan_main_ctrl; /* Register value */
  244. u8 fan_ctl; /* Register value */
  245. /* The following 3 arrays correspond to the same registers. The
  246. * meaning of bits 6-0 depends on the value of bit 7, and we want
  247. * to preserve settings on mode changes, so we have to track all
  248. * values separately. */
  249. u8 pwm_ctrl[3]; /* Register value */
  250. u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */
  251. u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
  252. /* Automatic fan speed control registers */
  253. u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
  254. s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
  255. };
  256. static inline int has_16bit_fans(const struct it87_data *data)
  257. {
  258. /* IT8705F Datasheet 0.4.1, 3h == Version G.
  259. IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
  260. These are the first revisions with 16bit tachometer support. */
  261. return (data->type == it87 && data->revision >= 0x03)
  262. || (data->type == it8712 && data->revision >= 0x08)
  263. || data->type == it8716
  264. || data->type == it8718
  265. || data->type == it8720;
  266. }
  267. static inline int has_old_autopwm(const struct it87_data *data)
  268. {
  269. /* The old automatic fan speed control interface is implemented
  270. by IT8705F chips up to revision F and IT8712F chips up to
  271. revision G. */
  272. return (data->type == it87 && data->revision < 0x03)
  273. || (data->type == it8712 && data->revision < 0x08);
  274. }
  275. static int it87_probe(struct platform_device *pdev);
  276. static int __devexit it87_remove(struct platform_device *pdev);
  277. static int it87_read_value(struct it87_data *data, u8 reg);
  278. static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
  279. static struct it87_data *it87_update_device(struct device *dev);
  280. static int it87_check_pwm(struct device *dev);
  281. static void it87_init_device(struct platform_device *pdev);
  282. static struct platform_driver it87_driver = {
  283. .driver = {
  284. .owner = THIS_MODULE,
  285. .name = DRVNAME,
  286. },
  287. .probe = it87_probe,
  288. .remove = __devexit_p(it87_remove),
  289. };
  290. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  291. char *buf)
  292. {
  293. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  294. int nr = sensor_attr->index;
  295. struct it87_data *data = it87_update_device(dev);
  296. return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
  297. }
  298. static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
  299. char *buf)
  300. {
  301. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  302. int nr = sensor_attr->index;
  303. struct it87_data *data = it87_update_device(dev);
  304. return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
  305. }
  306. static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
  307. char *buf)
  308. {
  309. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  310. int nr = sensor_attr->index;
  311. struct it87_data *data = it87_update_device(dev);
  312. return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
  313. }
  314. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  315. const char *buf, size_t count)
  316. {
  317. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  318. int nr = sensor_attr->index;
  319. struct it87_data *data = dev_get_drvdata(dev);
  320. unsigned long val;
  321. if (strict_strtoul(buf, 10, &val) < 0)
  322. return -EINVAL;
  323. mutex_lock(&data->update_lock);
  324. data->in_min[nr] = IN_TO_REG(val);
  325. it87_write_value(data, IT87_REG_VIN_MIN(nr),
  326. data->in_min[nr]);
  327. mutex_unlock(&data->update_lock);
  328. return count;
  329. }
  330. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  331. const char *buf, size_t count)
  332. {
  333. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  334. int nr = sensor_attr->index;
  335. struct it87_data *data = dev_get_drvdata(dev);
  336. unsigned long val;
  337. if (strict_strtoul(buf, 10, &val) < 0)
  338. return -EINVAL;
  339. mutex_lock(&data->update_lock);
  340. data->in_max[nr] = IN_TO_REG(val);
  341. it87_write_value(data, IT87_REG_VIN_MAX(nr),
  342. data->in_max[nr]);
  343. mutex_unlock(&data->update_lock);
  344. return count;
  345. }
  346. #define show_in_offset(offset) \
  347. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  348. show_in, NULL, offset);
  349. #define limit_in_offset(offset) \
  350. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
  351. show_in_min, set_in_min, offset); \
  352. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
  353. show_in_max, set_in_max, offset);
  354. show_in_offset(0);
  355. limit_in_offset(0);
  356. show_in_offset(1);
  357. limit_in_offset(1);
  358. show_in_offset(2);
  359. limit_in_offset(2);
  360. show_in_offset(3);
  361. limit_in_offset(3);
  362. show_in_offset(4);
  363. limit_in_offset(4);
  364. show_in_offset(5);
  365. limit_in_offset(5);
  366. show_in_offset(6);
  367. limit_in_offset(6);
  368. show_in_offset(7);
  369. limit_in_offset(7);
  370. show_in_offset(8);
  371. /* 3 temperatures */
  372. static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
  373. char *buf)
  374. {
  375. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  376. int nr = sensor_attr->index;
  377. struct it87_data *data = it87_update_device(dev);
  378. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
  379. }
  380. static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
  381. char *buf)
  382. {
  383. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  384. int nr = sensor_attr->index;
  385. struct it87_data *data = it87_update_device(dev);
  386. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
  387. }
  388. static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
  389. char *buf)
  390. {
  391. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  392. int nr = sensor_attr->index;
  393. struct it87_data *data = it87_update_device(dev);
  394. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
  395. }
  396. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  397. const char *buf, size_t count)
  398. {
  399. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  400. int nr = sensor_attr->index;
  401. struct it87_data *data = dev_get_drvdata(dev);
  402. long val;
  403. if (strict_strtol(buf, 10, &val) < 0)
  404. return -EINVAL;
  405. mutex_lock(&data->update_lock);
  406. data->temp_high[nr] = TEMP_TO_REG(val);
  407. it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
  408. mutex_unlock(&data->update_lock);
  409. return count;
  410. }
  411. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  412. const char *buf, size_t count)
  413. {
  414. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  415. int nr = sensor_attr->index;
  416. struct it87_data *data = dev_get_drvdata(dev);
  417. long val;
  418. if (strict_strtol(buf, 10, &val) < 0)
  419. return -EINVAL;
  420. mutex_lock(&data->update_lock);
  421. data->temp_low[nr] = TEMP_TO_REG(val);
  422. it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
  423. mutex_unlock(&data->update_lock);
  424. return count;
  425. }
  426. #define show_temp_offset(offset) \
  427. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  428. show_temp, NULL, offset - 1); \
  429. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
  430. show_temp_max, set_temp_max, offset - 1); \
  431. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
  432. show_temp_min, set_temp_min, offset - 1);
  433. show_temp_offset(1);
  434. show_temp_offset(2);
  435. show_temp_offset(3);
  436. static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
  437. char *buf)
  438. {
  439. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  440. int nr = sensor_attr->index;
  441. struct it87_data *data = it87_update_device(dev);
  442. u8 reg = data->sensor; /* In case the value is updated while
  443. we use it */
  444. if (reg & (1 << nr))
  445. return sprintf(buf, "3\n"); /* thermal diode */
  446. if (reg & (8 << nr))
  447. return sprintf(buf, "4\n"); /* thermistor */
  448. return sprintf(buf, "0\n"); /* disabled */
  449. }
  450. static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
  451. const char *buf, size_t count)
  452. {
  453. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  454. int nr = sensor_attr->index;
  455. struct it87_data *data = dev_get_drvdata(dev);
  456. long val;
  457. if (strict_strtol(buf, 10, &val) < 0)
  458. return -EINVAL;
  459. mutex_lock(&data->update_lock);
  460. data->sensor &= ~(1 << nr);
  461. data->sensor &= ~(8 << nr);
  462. if (val == 2) { /* backwards compatibility */
  463. dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
  464. "instead\n");
  465. val = 4;
  466. }
  467. /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
  468. if (val == 3)
  469. data->sensor |= 1 << nr;
  470. else if (val == 4)
  471. data->sensor |= 8 << nr;
  472. else if (val != 0) {
  473. mutex_unlock(&data->update_lock);
  474. return -EINVAL;
  475. }
  476. it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
  477. mutex_unlock(&data->update_lock);
  478. return count;
  479. }
  480. #define show_sensor_offset(offset) \
  481. static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
  482. show_sensor, set_sensor, offset - 1);
  483. show_sensor_offset(1);
  484. show_sensor_offset(2);
  485. show_sensor_offset(3);
  486. /* 3 Fans */
  487. static int pwm_mode(const struct it87_data *data, int nr)
  488. {
  489. int ctrl = data->fan_main_ctrl & (1 << nr);
  490. if (ctrl == 0) /* Full speed */
  491. return 0;
  492. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  493. return 2;
  494. else /* Manual mode */
  495. return 1;
  496. }
  497. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  498. char *buf)
  499. {
  500. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  501. int nr = sensor_attr->index;
  502. struct it87_data *data = it87_update_device(dev);
  503. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
  504. DIV_FROM_REG(data->fan_div[nr])));
  505. }
  506. static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
  507. char *buf)
  508. {
  509. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  510. int nr = sensor_attr->index;
  511. struct it87_data *data = it87_update_device(dev);
  512. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
  513. DIV_FROM_REG(data->fan_div[nr])));
  514. }
  515. static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
  516. char *buf)
  517. {
  518. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  519. int nr = sensor_attr->index;
  520. struct it87_data *data = it87_update_device(dev);
  521. return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
  522. }
  523. static ssize_t show_pwm_enable(struct device *dev,
  524. struct device_attribute *attr, char *buf)
  525. {
  526. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  527. int nr = sensor_attr->index;
  528. struct it87_data *data = it87_update_device(dev);
  529. return sprintf(buf, "%d\n", pwm_mode(data, nr));
  530. }
  531. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  532. char *buf)
  533. {
  534. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  535. int nr = sensor_attr->index;
  536. struct it87_data *data = it87_update_device(dev);
  537. return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr]));
  538. }
  539. static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
  540. char *buf)
  541. {
  542. struct it87_data *data = it87_update_device(dev);
  543. int index = (data->fan_ctl >> 4) & 0x07;
  544. return sprintf(buf, "%u\n", pwm_freq[index]);
  545. }
  546. static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
  547. const char *buf, size_t count)
  548. {
  549. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  550. int nr = sensor_attr->index;
  551. struct it87_data *data = dev_get_drvdata(dev);
  552. long val;
  553. u8 reg;
  554. if (strict_strtol(buf, 10, &val) < 0)
  555. return -EINVAL;
  556. mutex_lock(&data->update_lock);
  557. reg = it87_read_value(data, IT87_REG_FAN_DIV);
  558. switch (nr) {
  559. case 0:
  560. data->fan_div[nr] = reg & 0x07;
  561. break;
  562. case 1:
  563. data->fan_div[nr] = (reg >> 3) & 0x07;
  564. break;
  565. case 2:
  566. data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
  567. break;
  568. }
  569. data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
  570. it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
  571. mutex_unlock(&data->update_lock);
  572. return count;
  573. }
  574. static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
  575. const char *buf, size_t count)
  576. {
  577. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  578. int nr = sensor_attr->index;
  579. struct it87_data *data = dev_get_drvdata(dev);
  580. unsigned long val;
  581. int min;
  582. u8 old;
  583. if (strict_strtoul(buf, 10, &val) < 0)
  584. return -EINVAL;
  585. mutex_lock(&data->update_lock);
  586. old = it87_read_value(data, IT87_REG_FAN_DIV);
  587. /* Save fan min limit */
  588. min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
  589. switch (nr) {
  590. case 0:
  591. case 1:
  592. data->fan_div[nr] = DIV_TO_REG(val);
  593. break;
  594. case 2:
  595. if (val < 8)
  596. data->fan_div[nr] = 1;
  597. else
  598. data->fan_div[nr] = 3;
  599. }
  600. val = old & 0x80;
  601. val |= (data->fan_div[0] & 0x07);
  602. val |= (data->fan_div[1] & 0x07) << 3;
  603. if (data->fan_div[2] == 3)
  604. val |= 0x1 << 6;
  605. it87_write_value(data, IT87_REG_FAN_DIV, val);
  606. /* Restore fan min limit */
  607. data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
  608. it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
  609. mutex_unlock(&data->update_lock);
  610. return count;
  611. }
  612. /* Returns 0 if OK, -EINVAL otherwise */
  613. static int check_trip_points(struct device *dev, int nr)
  614. {
  615. const struct it87_data *data = dev_get_drvdata(dev);
  616. int i, err = 0;
  617. if (has_old_autopwm(data)) {
  618. for (i = 0; i < 3; i++) {
  619. if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
  620. err = -EINVAL;
  621. }
  622. for (i = 0; i < 2; i++) {
  623. if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
  624. err = -EINVAL;
  625. }
  626. }
  627. if (err) {
  628. dev_err(dev, "Inconsistent trip points, not switching to "
  629. "automatic mode\n");
  630. dev_err(dev, "Adjust the trip points and try again\n");
  631. }
  632. return err;
  633. }
  634. static ssize_t set_pwm_enable(struct device *dev,
  635. struct device_attribute *attr, const char *buf, size_t count)
  636. {
  637. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  638. int nr = sensor_attr->index;
  639. struct it87_data *data = dev_get_drvdata(dev);
  640. long val;
  641. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
  642. return -EINVAL;
  643. /* Check trip points before switching to automatic mode */
  644. if (val == 2) {
  645. if (check_trip_points(dev, nr) < 0)
  646. return -EINVAL;
  647. }
  648. mutex_lock(&data->update_lock);
  649. if (val == 0) {
  650. int tmp;
  651. /* make sure the fan is on when in on/off mode */
  652. tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  653. it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
  654. /* set on/off mode */
  655. data->fan_main_ctrl &= ~(1 << nr);
  656. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  657. data->fan_main_ctrl);
  658. } else {
  659. if (val == 1) /* Manual mode */
  660. data->pwm_ctrl[nr] = data->pwm_duty[nr];
  661. else /* Automatic mode */
  662. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  663. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  664. /* set SmartGuardian mode */
  665. data->fan_main_ctrl |= (1 << nr);
  666. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  667. data->fan_main_ctrl);
  668. }
  669. mutex_unlock(&data->update_lock);
  670. return count;
  671. }
  672. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  673. const char *buf, size_t count)
  674. {
  675. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  676. int nr = sensor_attr->index;
  677. struct it87_data *data = dev_get_drvdata(dev);
  678. long val;
  679. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  680. return -EINVAL;
  681. mutex_lock(&data->update_lock);
  682. data->pwm_duty[nr] = PWM_TO_REG(val);
  683. /* If we are in manual mode, write the duty cycle immediately;
  684. * otherwise, just store it for later use. */
  685. if (!(data->pwm_ctrl[nr] & 0x80)) {
  686. data->pwm_ctrl[nr] = data->pwm_duty[nr];
  687. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  688. }
  689. mutex_unlock(&data->update_lock);
  690. return count;
  691. }
  692. static ssize_t set_pwm_freq(struct device *dev,
  693. struct device_attribute *attr, const char *buf, size_t count)
  694. {
  695. struct it87_data *data = dev_get_drvdata(dev);
  696. unsigned long val;
  697. int i;
  698. if (strict_strtoul(buf, 10, &val) < 0)
  699. return -EINVAL;
  700. /* Search for the nearest available frequency */
  701. for (i = 0; i < 7; i++) {
  702. if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
  703. break;
  704. }
  705. mutex_lock(&data->update_lock);
  706. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
  707. data->fan_ctl |= i << 4;
  708. it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
  709. mutex_unlock(&data->update_lock);
  710. return count;
  711. }
  712. static ssize_t show_pwm_temp_map(struct device *dev,
  713. struct device_attribute *attr, char *buf)
  714. {
  715. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  716. int nr = sensor_attr->index;
  717. struct it87_data *data = it87_update_device(dev);
  718. int map;
  719. if (data->pwm_temp_map[nr] < 3)
  720. map = 1 << data->pwm_temp_map[nr];
  721. else
  722. map = 0; /* Should never happen */
  723. return sprintf(buf, "%d\n", map);
  724. }
  725. static ssize_t set_pwm_temp_map(struct device *dev,
  726. struct device_attribute *attr, const char *buf, size_t count)
  727. {
  728. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  729. int nr = sensor_attr->index;
  730. struct it87_data *data = dev_get_drvdata(dev);
  731. long val;
  732. u8 reg;
  733. /* This check can go away if we ever support automatic fan speed
  734. control on newer chips. */
  735. if (!has_old_autopwm(data)) {
  736. dev_notice(dev, "Mapping change disabled for safety reasons\n");
  737. return -EINVAL;
  738. }
  739. if (strict_strtol(buf, 10, &val) < 0)
  740. return -EINVAL;
  741. switch (val) {
  742. case (1 << 0):
  743. reg = 0x00;
  744. break;
  745. case (1 << 1):
  746. reg = 0x01;
  747. break;
  748. case (1 << 2):
  749. reg = 0x02;
  750. break;
  751. default:
  752. return -EINVAL;
  753. }
  754. mutex_lock(&data->update_lock);
  755. data->pwm_temp_map[nr] = reg;
  756. /* If we are in automatic mode, write the temp mapping immediately;
  757. * otherwise, just store it for later use. */
  758. if (data->pwm_ctrl[nr] & 0x80) {
  759. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  760. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  761. }
  762. mutex_unlock(&data->update_lock);
  763. return count;
  764. }
  765. static ssize_t show_auto_pwm(struct device *dev,
  766. struct device_attribute *attr, char *buf)
  767. {
  768. struct it87_data *data = it87_update_device(dev);
  769. struct sensor_device_attribute_2 *sensor_attr =
  770. to_sensor_dev_attr_2(attr);
  771. int nr = sensor_attr->nr;
  772. int point = sensor_attr->index;
  773. return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point]));
  774. }
  775. static ssize_t set_auto_pwm(struct device *dev,
  776. struct device_attribute *attr, const char *buf, size_t count)
  777. {
  778. struct it87_data *data = dev_get_drvdata(dev);
  779. struct sensor_device_attribute_2 *sensor_attr =
  780. to_sensor_dev_attr_2(attr);
  781. int nr = sensor_attr->nr;
  782. int point = sensor_attr->index;
  783. long val;
  784. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  785. return -EINVAL;
  786. mutex_lock(&data->update_lock);
  787. data->auto_pwm[nr][point] = PWM_TO_REG(val);
  788. it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
  789. data->auto_pwm[nr][point]);
  790. mutex_unlock(&data->update_lock);
  791. return count;
  792. }
  793. static ssize_t show_auto_temp(struct device *dev,
  794. struct device_attribute *attr, char *buf)
  795. {
  796. struct it87_data *data = it87_update_device(dev);
  797. struct sensor_device_attribute_2 *sensor_attr =
  798. to_sensor_dev_attr_2(attr);
  799. int nr = sensor_attr->nr;
  800. int point = sensor_attr->index;
  801. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
  802. }
  803. static ssize_t set_auto_temp(struct device *dev,
  804. struct device_attribute *attr, const char *buf, size_t count)
  805. {
  806. struct it87_data *data = dev_get_drvdata(dev);
  807. struct sensor_device_attribute_2 *sensor_attr =
  808. to_sensor_dev_attr_2(attr);
  809. int nr = sensor_attr->nr;
  810. int point = sensor_attr->index;
  811. long val;
  812. if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
  813. return -EINVAL;
  814. mutex_lock(&data->update_lock);
  815. data->auto_temp[nr][point] = TEMP_TO_REG(val);
  816. it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
  817. data->auto_temp[nr][point]);
  818. mutex_unlock(&data->update_lock);
  819. return count;
  820. }
  821. #define show_fan_offset(offset) \
  822. static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
  823. show_fan, NULL, offset - 1); \
  824. static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  825. show_fan_min, set_fan_min, offset - 1); \
  826. static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
  827. show_fan_div, set_fan_div, offset - 1);
  828. show_fan_offset(1);
  829. show_fan_offset(2);
  830. show_fan_offset(3);
  831. #define show_pwm_offset(offset) \
  832. static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
  833. show_pwm_enable, set_pwm_enable, offset - 1); \
  834. static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  835. show_pwm, set_pwm, offset - 1); \
  836. static DEVICE_ATTR(pwm##offset##_freq, \
  837. (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
  838. show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
  839. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
  840. S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
  841. offset - 1); \
  842. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
  843. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  844. offset - 1, 0); \
  845. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
  846. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  847. offset - 1, 1); \
  848. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
  849. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  850. offset - 1, 2); \
  851. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
  852. S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
  853. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
  854. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  855. offset - 1, 1); \
  856. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
  857. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  858. offset - 1, 0); \
  859. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
  860. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  861. offset - 1, 2); \
  862. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
  863. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  864. offset - 1, 3); \
  865. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
  866. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  867. offset - 1, 4);
  868. show_pwm_offset(1);
  869. show_pwm_offset(2);
  870. show_pwm_offset(3);
  871. /* A different set of callbacks for 16-bit fans */
  872. static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
  873. char *buf)
  874. {
  875. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  876. int nr = sensor_attr->index;
  877. struct it87_data *data = it87_update_device(dev);
  878. return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
  879. }
  880. static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
  881. char *buf)
  882. {
  883. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  884. int nr = sensor_attr->index;
  885. struct it87_data *data = it87_update_device(dev);
  886. return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
  887. }
  888. static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
  889. const char *buf, size_t count)
  890. {
  891. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  892. int nr = sensor_attr->index;
  893. struct it87_data *data = dev_get_drvdata(dev);
  894. long val;
  895. if (strict_strtol(buf, 10, &val) < 0)
  896. return -EINVAL;
  897. mutex_lock(&data->update_lock);
  898. data->fan_min[nr] = FAN16_TO_REG(val);
  899. it87_write_value(data, IT87_REG_FAN_MIN[nr],
  900. data->fan_min[nr] & 0xff);
  901. it87_write_value(data, IT87_REG_FANX_MIN[nr],
  902. data->fan_min[nr] >> 8);
  903. mutex_unlock(&data->update_lock);
  904. return count;
  905. }
  906. /* We want to use the same sysfs file names as 8-bit fans, but we need
  907. different variable names, so we have to use SENSOR_ATTR instead of
  908. SENSOR_DEVICE_ATTR. */
  909. #define show_fan16_offset(offset) \
  910. static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
  911. = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
  912. show_fan16, NULL, offset - 1); \
  913. static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
  914. = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  915. show_fan16_min, set_fan16_min, offset - 1)
  916. show_fan16_offset(1);
  917. show_fan16_offset(2);
  918. show_fan16_offset(3);
  919. show_fan16_offset(4);
  920. show_fan16_offset(5);
  921. /* Alarms */
  922. static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
  923. char *buf)
  924. {
  925. struct it87_data *data = it87_update_device(dev);
  926. return sprintf(buf, "%u\n", data->alarms);
  927. }
  928. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  929. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  930. char *buf)
  931. {
  932. int bitnr = to_sensor_dev_attr(attr)->index;
  933. struct it87_data *data = it87_update_device(dev);
  934. return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  935. }
  936. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
  937. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
  938. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
  939. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
  940. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
  941. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
  942. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
  943. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
  944. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
  945. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
  946. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
  947. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
  948. static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
  949. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
  950. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
  951. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
  952. static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
  953. char *buf)
  954. {
  955. int bitnr = to_sensor_dev_attr(attr)->index;
  956. struct it87_data *data = it87_update_device(dev);
  957. return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
  958. }
  959. static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
  960. const char *buf, size_t count)
  961. {
  962. int bitnr = to_sensor_dev_attr(attr)->index;
  963. struct it87_data *data = dev_get_drvdata(dev);
  964. long val;
  965. if (strict_strtol(buf, 10, &val) < 0
  966. || (val != 0 && val != 1))
  967. return -EINVAL;
  968. mutex_lock(&data->update_lock);
  969. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  970. if (val)
  971. data->beeps |= (1 << bitnr);
  972. else
  973. data->beeps &= ~(1 << bitnr);
  974. it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
  975. mutex_unlock(&data->update_lock);
  976. return count;
  977. }
  978. static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
  979. show_beep, set_beep, 1);
  980. static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
  981. static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
  982. static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
  983. static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
  984. static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
  985. static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
  986. static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
  987. /* fanX_beep writability is set later */
  988. static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
  989. static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
  990. static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
  991. static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
  992. static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
  993. static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
  994. show_beep, set_beep, 2);
  995. static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
  996. static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
  997. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  998. char *buf)
  999. {
  1000. struct it87_data *data = dev_get_drvdata(dev);
  1001. return sprintf(buf, "%u\n", data->vrm);
  1002. }
  1003. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  1004. const char *buf, size_t count)
  1005. {
  1006. struct it87_data *data = dev_get_drvdata(dev);
  1007. unsigned long val;
  1008. if (strict_strtoul(buf, 10, &val) < 0)
  1009. return -EINVAL;
  1010. data->vrm = val;
  1011. return count;
  1012. }
  1013. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  1014. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  1015. char *buf)
  1016. {
  1017. struct it87_data *data = it87_update_device(dev);
  1018. return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
  1019. }
  1020. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  1021. static ssize_t show_name(struct device *dev, struct device_attribute
  1022. *devattr, char *buf)
  1023. {
  1024. struct it87_data *data = dev_get_drvdata(dev);
  1025. return sprintf(buf, "%s\n", data->name);
  1026. }
  1027. static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  1028. static struct attribute *it87_attributes[] = {
  1029. &sensor_dev_attr_in0_input.dev_attr.attr,
  1030. &sensor_dev_attr_in1_input.dev_attr.attr,
  1031. &sensor_dev_attr_in2_input.dev_attr.attr,
  1032. &sensor_dev_attr_in3_input.dev_attr.attr,
  1033. &sensor_dev_attr_in4_input.dev_attr.attr,
  1034. &sensor_dev_attr_in5_input.dev_attr.attr,
  1035. &sensor_dev_attr_in6_input.dev_attr.attr,
  1036. &sensor_dev_attr_in7_input.dev_attr.attr,
  1037. &sensor_dev_attr_in8_input.dev_attr.attr,
  1038. &sensor_dev_attr_in0_min.dev_attr.attr,
  1039. &sensor_dev_attr_in1_min.dev_attr.attr,
  1040. &sensor_dev_attr_in2_min.dev_attr.attr,
  1041. &sensor_dev_attr_in3_min.dev_attr.attr,
  1042. &sensor_dev_attr_in4_min.dev_attr.attr,
  1043. &sensor_dev_attr_in5_min.dev_attr.attr,
  1044. &sensor_dev_attr_in6_min.dev_attr.attr,
  1045. &sensor_dev_attr_in7_min.dev_attr.attr,
  1046. &sensor_dev_attr_in0_max.dev_attr.attr,
  1047. &sensor_dev_attr_in1_max.dev_attr.attr,
  1048. &sensor_dev_attr_in2_max.dev_attr.attr,
  1049. &sensor_dev_attr_in3_max.dev_attr.attr,
  1050. &sensor_dev_attr_in4_max.dev_attr.attr,
  1051. &sensor_dev_attr_in5_max.dev_attr.attr,
  1052. &sensor_dev_attr_in6_max.dev_attr.attr,
  1053. &sensor_dev_attr_in7_max.dev_attr.attr,
  1054. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  1055. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1056. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1057. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1058. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1059. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1060. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1061. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1062. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1063. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1064. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1065. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1066. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1067. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1068. &sensor_dev_attr_temp1_min.dev_attr.attr,
  1069. &sensor_dev_attr_temp2_min.dev_attr.attr,
  1070. &sensor_dev_attr_temp3_min.dev_attr.attr,
  1071. &sensor_dev_attr_temp1_type.dev_attr.attr,
  1072. &sensor_dev_attr_temp2_type.dev_attr.attr,
  1073. &sensor_dev_attr_temp3_type.dev_attr.attr,
  1074. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1075. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1076. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1077. &dev_attr_alarms.attr,
  1078. &dev_attr_name.attr,
  1079. NULL
  1080. };
  1081. static const struct attribute_group it87_group = {
  1082. .attrs = it87_attributes,
  1083. };
  1084. static struct attribute *it87_attributes_beep[] = {
  1085. &sensor_dev_attr_in0_beep.dev_attr.attr,
  1086. &sensor_dev_attr_in1_beep.dev_attr.attr,
  1087. &sensor_dev_attr_in2_beep.dev_attr.attr,
  1088. &sensor_dev_attr_in3_beep.dev_attr.attr,
  1089. &sensor_dev_attr_in4_beep.dev_attr.attr,
  1090. &sensor_dev_attr_in5_beep.dev_attr.attr,
  1091. &sensor_dev_attr_in6_beep.dev_attr.attr,
  1092. &sensor_dev_attr_in7_beep.dev_attr.attr,
  1093. &sensor_dev_attr_temp1_beep.dev_attr.attr,
  1094. &sensor_dev_attr_temp2_beep.dev_attr.attr,
  1095. &sensor_dev_attr_temp3_beep.dev_attr.attr,
  1096. NULL
  1097. };
  1098. static const struct attribute_group it87_group_beep = {
  1099. .attrs = it87_attributes_beep,
  1100. };
  1101. static struct attribute *it87_attributes_fan16[5][3+1] = { {
  1102. &sensor_dev_attr_fan1_input16.dev_attr.attr,
  1103. &sensor_dev_attr_fan1_min16.dev_attr.attr,
  1104. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1105. NULL
  1106. }, {
  1107. &sensor_dev_attr_fan2_input16.dev_attr.attr,
  1108. &sensor_dev_attr_fan2_min16.dev_attr.attr,
  1109. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1110. NULL
  1111. }, {
  1112. &sensor_dev_attr_fan3_input16.dev_attr.attr,
  1113. &sensor_dev_attr_fan3_min16.dev_attr.attr,
  1114. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1115. NULL
  1116. }, {
  1117. &sensor_dev_attr_fan4_input16.dev_attr.attr,
  1118. &sensor_dev_attr_fan4_min16.dev_attr.attr,
  1119. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1120. NULL
  1121. }, {
  1122. &sensor_dev_attr_fan5_input16.dev_attr.attr,
  1123. &sensor_dev_attr_fan5_min16.dev_attr.attr,
  1124. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1125. NULL
  1126. } };
  1127. static const struct attribute_group it87_group_fan16[5] = {
  1128. { .attrs = it87_attributes_fan16[0] },
  1129. { .attrs = it87_attributes_fan16[1] },
  1130. { .attrs = it87_attributes_fan16[2] },
  1131. { .attrs = it87_attributes_fan16[3] },
  1132. { .attrs = it87_attributes_fan16[4] },
  1133. };
  1134. static struct attribute *it87_attributes_fan[3][4+1] = { {
  1135. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1136. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1137. &sensor_dev_attr_fan1_div.dev_attr.attr,
  1138. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1139. NULL
  1140. }, {
  1141. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1142. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1143. &sensor_dev_attr_fan2_div.dev_attr.attr,
  1144. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1145. NULL
  1146. }, {
  1147. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1148. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1149. &sensor_dev_attr_fan3_div.dev_attr.attr,
  1150. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1151. NULL
  1152. } };
  1153. static const struct attribute_group it87_group_fan[3] = {
  1154. { .attrs = it87_attributes_fan[0] },
  1155. { .attrs = it87_attributes_fan[1] },
  1156. { .attrs = it87_attributes_fan[2] },
  1157. };
  1158. static const struct attribute_group *
  1159. it87_get_fan_group(const struct it87_data *data)
  1160. {
  1161. return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
  1162. }
  1163. static struct attribute *it87_attributes_pwm[3][4+1] = { {
  1164. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1165. &sensor_dev_attr_pwm1.dev_attr.attr,
  1166. &dev_attr_pwm1_freq.attr,
  1167. &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
  1168. NULL
  1169. }, {
  1170. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1171. &sensor_dev_attr_pwm2.dev_attr.attr,
  1172. &dev_attr_pwm2_freq.attr,
  1173. &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
  1174. NULL
  1175. }, {
  1176. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1177. &sensor_dev_attr_pwm3.dev_attr.attr,
  1178. &dev_attr_pwm3_freq.attr,
  1179. &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
  1180. NULL
  1181. } };
  1182. static const struct attribute_group it87_group_pwm[3] = {
  1183. { .attrs = it87_attributes_pwm[0] },
  1184. { .attrs = it87_attributes_pwm[1] },
  1185. { .attrs = it87_attributes_pwm[2] },
  1186. };
  1187. static struct attribute *it87_attributes_autopwm[3][9+1] = { {
  1188. &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
  1189. &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
  1190. &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
  1191. &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
  1192. &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
  1193. &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
  1194. &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
  1195. &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
  1196. &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
  1197. NULL
  1198. }, {
  1199. &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
  1200. &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
  1201. &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
  1202. &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
  1203. &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
  1204. &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
  1205. &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
  1206. &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
  1207. &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
  1208. NULL
  1209. }, {
  1210. &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
  1211. &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
  1212. &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
  1213. &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
  1214. &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
  1215. &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
  1216. &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
  1217. &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
  1218. &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
  1219. NULL
  1220. } };
  1221. static const struct attribute_group it87_group_autopwm[3] = {
  1222. { .attrs = it87_attributes_autopwm[0] },
  1223. { .attrs = it87_attributes_autopwm[1] },
  1224. { .attrs = it87_attributes_autopwm[2] },
  1225. };
  1226. static struct attribute *it87_attributes_fan_beep[] = {
  1227. &sensor_dev_attr_fan1_beep.dev_attr.attr,
  1228. &sensor_dev_attr_fan2_beep.dev_attr.attr,
  1229. &sensor_dev_attr_fan3_beep.dev_attr.attr,
  1230. &sensor_dev_attr_fan4_beep.dev_attr.attr,
  1231. &sensor_dev_attr_fan5_beep.dev_attr.attr,
  1232. };
  1233. static struct attribute *it87_attributes_vid[] = {
  1234. &dev_attr_vrm.attr,
  1235. &dev_attr_cpu0_vid.attr,
  1236. NULL
  1237. };
  1238. static const struct attribute_group it87_group_vid = {
  1239. .attrs = it87_attributes_vid,
  1240. };
  1241. /* SuperIO detection - will change isa_address if a chip is found */
  1242. static int __init it87_find(unsigned short *address,
  1243. struct it87_sio_data *sio_data)
  1244. {
  1245. int err = -ENODEV;
  1246. u16 chip_type;
  1247. const char *board_vendor, *board_name;
  1248. superio_enter();
  1249. chip_type = force_id ? force_id : superio_inw(DEVID);
  1250. switch (chip_type) {
  1251. case IT8705F_DEVID:
  1252. sio_data->type = it87;
  1253. break;
  1254. case IT8712F_DEVID:
  1255. sio_data->type = it8712;
  1256. break;
  1257. case IT8716F_DEVID:
  1258. case IT8726F_DEVID:
  1259. sio_data->type = it8716;
  1260. break;
  1261. case IT8718F_DEVID:
  1262. sio_data->type = it8718;
  1263. break;
  1264. case IT8720F_DEVID:
  1265. sio_data->type = it8720;
  1266. break;
  1267. case 0xffff: /* No device at all */
  1268. goto exit;
  1269. default:
  1270. pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
  1271. chip_type);
  1272. goto exit;
  1273. }
  1274. superio_select(PME);
  1275. if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
  1276. pr_info("it87: Device not activated, skipping\n");
  1277. goto exit;
  1278. }
  1279. *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
  1280. if (*address == 0) {
  1281. pr_info("it87: Base address not set, skipping\n");
  1282. goto exit;
  1283. }
  1284. err = 0;
  1285. sio_data->revision = superio_inb(DEVREV) & 0x0f;
  1286. pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
  1287. chip_type, *address, sio_data->revision);
  1288. /* Read GPIO config and VID value from LDN 7 (GPIO) */
  1289. if (sio_data->type == it87) {
  1290. /* The IT8705F doesn't have VID pins at all */
  1291. sio_data->skip_vid = 1;
  1292. /* The IT8705F has a different LD number for GPIO */
  1293. superio_select(5);
  1294. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1295. } else {
  1296. int reg;
  1297. superio_select(GPIO);
  1298. /* We need at least 4 VID pins */
  1299. reg = superio_inb(IT87_SIO_GPIO3_REG);
  1300. if (reg & 0x0f) {
  1301. pr_info("it87: VID is disabled (pins used for GPIO)\n");
  1302. sio_data->skip_vid = 1;
  1303. }
  1304. /* Check if fan3 is there or not */
  1305. if (reg & (1 << 6))
  1306. sio_data->skip_pwm |= (1 << 2);
  1307. if (reg & (1 << 7))
  1308. sio_data->skip_fan |= (1 << 2);
  1309. /* Check if fan2 is there or not */
  1310. reg = superio_inb(IT87_SIO_GPIO5_REG);
  1311. if (reg & (1 << 1))
  1312. sio_data->skip_pwm |= (1 << 1);
  1313. if (reg & (1 << 2))
  1314. sio_data->skip_fan |= (1 << 1);
  1315. if ((sio_data->type == it8718 || sio_data->type == it8720)
  1316. && !(sio_data->skip_vid))
  1317. sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
  1318. reg = superio_inb(IT87_SIO_PINX2_REG);
  1319. if (reg & (1 << 0))
  1320. pr_info("it87: in3 is VCC (+5V)\n");
  1321. if (reg & (1 << 1))
  1322. pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
  1323. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1324. }
  1325. if (sio_data->beep_pin)
  1326. pr_info("it87: Beeping is supported\n");
  1327. /* Disable specific features based on DMI strings */
  1328. board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1329. board_name = dmi_get_system_info(DMI_BOARD_NAME);
  1330. if (board_vendor && board_name) {
  1331. if (strcmp(board_vendor, "nVIDIA") == 0
  1332. && strcmp(board_name, "FN68PT") == 0) {
  1333. /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
  1334. connected to a fan, but to something else. One user
  1335. has reported instant system power-off when changing
  1336. the PWM2 duty cycle, so we disable it.
  1337. I use the board name string as the trigger in case
  1338. the same board is ever used in other systems. */
  1339. pr_info("it87: Disabling pwm2 due to "
  1340. "hardware constraints\n");
  1341. sio_data->skip_pwm = (1 << 1);
  1342. }
  1343. }
  1344. exit:
  1345. superio_exit();
  1346. return err;
  1347. }
  1348. static void it87_remove_files(struct device *dev)
  1349. {
  1350. struct it87_data *data = platform_get_drvdata(pdev);
  1351. struct it87_sio_data *sio_data = dev->platform_data;
  1352. const struct attribute_group *fan_group = it87_get_fan_group(data);
  1353. int i;
  1354. sysfs_remove_group(&dev->kobj, &it87_group);
  1355. if (sio_data->beep_pin)
  1356. sysfs_remove_group(&dev->kobj, &it87_group_beep);
  1357. for (i = 0; i < 5; i++) {
  1358. if (!(data->has_fan & (1 << i)))
  1359. continue;
  1360. sysfs_remove_group(&dev->kobj, &fan_group[i]);
  1361. if (sio_data->beep_pin)
  1362. sysfs_remove_file(&dev->kobj,
  1363. it87_attributes_fan_beep[i]);
  1364. }
  1365. for (i = 0; i < 3; i++) {
  1366. if (sio_data->skip_pwm & (1 << 0))
  1367. continue;
  1368. sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
  1369. if (has_old_autopwm(data))
  1370. sysfs_remove_group(&dev->kobj,
  1371. &it87_group_autopwm[i]);
  1372. }
  1373. if (!sio_data->skip_vid)
  1374. sysfs_remove_group(&dev->kobj, &it87_group_vid);
  1375. }
  1376. static int __devinit it87_probe(struct platform_device *pdev)
  1377. {
  1378. struct it87_data *data;
  1379. struct resource *res;
  1380. struct device *dev = &pdev->dev;
  1381. struct it87_sio_data *sio_data = dev->platform_data;
  1382. const struct attribute_group *fan_group;
  1383. int err = 0, i;
  1384. int enable_pwm_interface;
  1385. int fan_beep_need_rw;
  1386. static const char *names[] = {
  1387. "it87",
  1388. "it8712",
  1389. "it8716",
  1390. "it8718",
  1391. "it8720",
  1392. };
  1393. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  1394. if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
  1395. dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
  1396. (unsigned long)res->start,
  1397. (unsigned long)(res->start + IT87_EC_EXTENT - 1));
  1398. err = -EBUSY;
  1399. goto ERROR0;
  1400. }
  1401. data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
  1402. if (!data) {
  1403. err = -ENOMEM;
  1404. goto ERROR1;
  1405. }
  1406. data->addr = res->start;
  1407. data->type = sio_data->type;
  1408. data->revision = sio_data->revision;
  1409. data->name = names[sio_data->type];
  1410. /* Now, we do the remaining detection. */
  1411. if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
  1412. || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
  1413. err = -ENODEV;
  1414. goto ERROR2;
  1415. }
  1416. platform_set_drvdata(pdev, data);
  1417. mutex_init(&data->update_lock);
  1418. /* Check PWM configuration */
  1419. enable_pwm_interface = it87_check_pwm(dev);
  1420. /* Initialize the IT87 chip */
  1421. it87_init_device(pdev);
  1422. /* Register sysfs hooks */
  1423. err = sysfs_create_group(&dev->kobj, &it87_group);
  1424. if (err)
  1425. goto ERROR2;
  1426. if (sio_data->beep_pin) {
  1427. err = sysfs_create_group(&dev->kobj, &it87_group_beep);
  1428. if (err)
  1429. goto ERROR4;
  1430. }
  1431. /* Do not create fan files for disabled fans */
  1432. fan_group = it87_get_fan_group(data);
  1433. fan_beep_need_rw = 1;
  1434. for (i = 0; i < 5; i++) {
  1435. if (!(data->has_fan & (1 << i)))
  1436. continue;
  1437. err = sysfs_create_group(&dev->kobj, &fan_group[i]);
  1438. if (err)
  1439. goto ERROR4;
  1440. if (sio_data->beep_pin) {
  1441. err = sysfs_create_file(&dev->kobj,
  1442. it87_attributes_fan_beep[i]);
  1443. if (err)
  1444. goto ERROR4;
  1445. if (!fan_beep_need_rw)
  1446. continue;
  1447. /* As we have a single beep enable bit for all fans,
  1448. * only the first enabled fan has a writable attribute
  1449. * for it. */
  1450. if (sysfs_chmod_file(&dev->kobj,
  1451. it87_attributes_fan_beep[i],
  1452. S_IRUGO | S_IWUSR))
  1453. dev_dbg(dev, "chmod +w fan%d_beep failed\n",
  1454. i + 1);
  1455. fan_beep_need_rw = 0;
  1456. }
  1457. }
  1458. if (enable_pwm_interface) {
  1459. for (i = 0; i < 3; i++) {
  1460. if (sio_data->skip_pwm & (1 << i))
  1461. continue;
  1462. err = sysfs_create_group(&dev->kobj,
  1463. &it87_group_pwm[i]);
  1464. if (err)
  1465. goto ERROR4;
  1466. if (!has_old_autopwm(data))
  1467. continue;
  1468. err = sysfs_create_group(&dev->kobj,
  1469. &it87_group_autopwm[i]);
  1470. if (err)
  1471. goto ERROR4;
  1472. }
  1473. }
  1474. if (!sio_data->skip_vid) {
  1475. data->vrm = vid_which_vrm();
  1476. /* VID reading from Super-I/O config space if available */
  1477. data->vid = sio_data->vid_value;
  1478. err = sysfs_create_group(&dev->kobj, &it87_group_vid);
  1479. if (err)
  1480. goto ERROR4;
  1481. }
  1482. data->hwmon_dev = hwmon_device_register(dev);
  1483. if (IS_ERR(data->hwmon_dev)) {
  1484. err = PTR_ERR(data->hwmon_dev);
  1485. goto ERROR4;
  1486. }
  1487. return 0;
  1488. ERROR4:
  1489. it87_remove_files(dev);
  1490. ERROR2:
  1491. platform_set_drvdata(pdev, NULL);
  1492. kfree(data);
  1493. ERROR1:
  1494. release_region(res->start, IT87_EC_EXTENT);
  1495. ERROR0:
  1496. return err;
  1497. }
  1498. static int __devexit it87_remove(struct platform_device *pdev)
  1499. {
  1500. struct it87_data *data = platform_get_drvdata(pdev);
  1501. hwmon_device_unregister(data->hwmon_dev);
  1502. it87_remove_files(&pdev->dev);
  1503. release_region(data->addr, IT87_EC_EXTENT);
  1504. platform_set_drvdata(pdev, NULL);
  1505. kfree(data);
  1506. return 0;
  1507. }
  1508. /* Must be called with data->update_lock held, except during initialization.
  1509. We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1510. would slow down the IT87 access and should not be necessary. */
  1511. static int it87_read_value(struct it87_data *data, u8 reg)
  1512. {
  1513. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1514. return inb_p(data->addr + IT87_DATA_REG_OFFSET);
  1515. }
  1516. /* Must be called with data->update_lock held, except during initialization.
  1517. We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1518. would slow down the IT87 access and should not be necessary. */
  1519. static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
  1520. {
  1521. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1522. outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
  1523. }
  1524. /* Return 1 if and only if the PWM interface is safe to use */
  1525. static int __devinit it87_check_pwm(struct device *dev)
  1526. {
  1527. struct it87_data *data = dev_get_drvdata(dev);
  1528. /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
  1529. * and polarity set to active low is sign that this is the case so we
  1530. * disable pwm control to protect the user. */
  1531. int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  1532. if ((tmp & 0x87) == 0) {
  1533. if (fix_pwm_polarity) {
  1534. /* The user asks us to attempt a chip reconfiguration.
  1535. * This means switching to active high polarity and
  1536. * inverting all fan speed values. */
  1537. int i;
  1538. u8 pwm[3];
  1539. for (i = 0; i < 3; i++)
  1540. pwm[i] = it87_read_value(data,
  1541. IT87_REG_PWM(i));
  1542. /* If any fan is in automatic pwm mode, the polarity
  1543. * might be correct, as suspicious as it seems, so we
  1544. * better don't change anything (but still disable the
  1545. * PWM interface). */
  1546. if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
  1547. dev_info(dev, "Reconfiguring PWM to "
  1548. "active high polarity\n");
  1549. it87_write_value(data, IT87_REG_FAN_CTL,
  1550. tmp | 0x87);
  1551. for (i = 0; i < 3; i++)
  1552. it87_write_value(data,
  1553. IT87_REG_PWM(i),
  1554. 0x7f & ~pwm[i]);
  1555. return 1;
  1556. }
  1557. dev_info(dev, "PWM configuration is "
  1558. "too broken to be fixed\n");
  1559. }
  1560. dev_info(dev, "Detected broken BIOS "
  1561. "defaults, disabling PWM interface\n");
  1562. return 0;
  1563. } else if (fix_pwm_polarity) {
  1564. dev_info(dev, "PWM configuration looks "
  1565. "sane, won't touch\n");
  1566. }
  1567. return 1;
  1568. }
  1569. /* Called when we have found a new IT87. */
  1570. static void __devinit it87_init_device(struct platform_device *pdev)
  1571. {
  1572. struct it87_sio_data *sio_data = pdev->dev.platform_data;
  1573. struct it87_data *data = platform_get_drvdata(pdev);
  1574. int tmp, i;
  1575. u8 mask;
  1576. /* For each PWM channel:
  1577. * - If it is in automatic mode, setting to manual mode should set
  1578. * the fan to full speed by default.
  1579. * - If it is in manual mode, we need a mapping to temperature
  1580. * channels to use when later setting to automatic mode later.
  1581. * Use a 1:1 mapping by default (we are clueless.)
  1582. * In both cases, the value can (and should) be changed by the user
  1583. * prior to switching to a different mode. */
  1584. for (i = 0; i < 3; i++) {
  1585. data->pwm_temp_map[i] = i;
  1586. data->pwm_duty[i] = 0x7f; /* Full speed */
  1587. data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
  1588. }
  1589. /* Some chips seem to have default value 0xff for all limit
  1590. * registers. For low voltage limits it makes no sense and triggers
  1591. * alarms, so change to 0 instead. For high temperature limits, it
  1592. * means -1 degree C, which surprisingly doesn't trigger an alarm,
  1593. * but is still confusing, so change to 127 degrees C. */
  1594. for (i = 0; i < 8; i++) {
  1595. tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
  1596. if (tmp == 0xff)
  1597. it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
  1598. }
  1599. for (i = 0; i < 3; i++) {
  1600. tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  1601. if (tmp == 0xff)
  1602. it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
  1603. }
  1604. /* Check if temperature channels are reset manually or by some reason */
  1605. tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  1606. if ((tmp & 0x3f) == 0) {
  1607. /* Temp1,Temp3=thermistor; Temp2=thermal diode */
  1608. tmp = (tmp & 0xc0) | 0x2a;
  1609. it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
  1610. }
  1611. data->sensor = tmp;
  1612. /* Check if voltage monitors are reset manually or by some reason */
  1613. tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
  1614. if ((tmp & 0xff) == 0) {
  1615. /* Enable all voltage monitors */
  1616. it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
  1617. }
  1618. /* Check if tachometers are reset manually or by some reason */
  1619. mask = 0x70 & ~(sio_data->skip_fan << 4);
  1620. data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
  1621. if ((data->fan_main_ctrl & mask) == 0) {
  1622. /* Enable all fan tachometers */
  1623. data->fan_main_ctrl |= mask;
  1624. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  1625. data->fan_main_ctrl);
  1626. }
  1627. data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
  1628. /* Set tachometers to 16-bit mode if needed */
  1629. if (has_16bit_fans(data)) {
  1630. tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
  1631. if (~tmp & 0x07 & data->has_fan) {
  1632. dev_dbg(&pdev->dev,
  1633. "Setting fan1-3 to 16-bit mode\n");
  1634. it87_write_value(data, IT87_REG_FAN_16BIT,
  1635. tmp | 0x07);
  1636. }
  1637. /* IT8705F only supports three fans. */
  1638. if (data->type != it87) {
  1639. if (tmp & (1 << 4))
  1640. data->has_fan |= (1 << 3); /* fan4 enabled */
  1641. if (tmp & (1 << 5))
  1642. data->has_fan |= (1 << 4); /* fan5 enabled */
  1643. }
  1644. }
  1645. /* Fan input pins may be used for alternative functions */
  1646. data->has_fan &= ~sio_data->skip_fan;
  1647. /* Start monitoring */
  1648. it87_write_value(data, IT87_REG_CONFIG,
  1649. (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
  1650. | (update_vbat ? 0x41 : 0x01));
  1651. }
  1652. static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
  1653. {
  1654. data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
  1655. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  1656. data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
  1657. else /* Manual mode */
  1658. data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
  1659. if (has_old_autopwm(data)) {
  1660. int i;
  1661. for (i = 0; i < 5 ; i++)
  1662. data->auto_temp[nr][i] = it87_read_value(data,
  1663. IT87_REG_AUTO_TEMP(nr, i));
  1664. for (i = 0; i < 3 ; i++)
  1665. data->auto_pwm[nr][i] = it87_read_value(data,
  1666. IT87_REG_AUTO_PWM(nr, i));
  1667. }
  1668. }
  1669. static struct it87_data *it87_update_device(struct device *dev)
  1670. {
  1671. struct it87_data *data = dev_get_drvdata(dev);
  1672. int i;
  1673. mutex_lock(&data->update_lock);
  1674. if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
  1675. || !data->valid) {
  1676. if (update_vbat) {
  1677. /* Cleared after each update, so reenable. Value
  1678. returned by this read will be previous value */
  1679. it87_write_value(data, IT87_REG_CONFIG,
  1680. it87_read_value(data, IT87_REG_CONFIG) | 0x40);
  1681. }
  1682. for (i = 0; i <= 7; i++) {
  1683. data->in[i] =
  1684. it87_read_value(data, IT87_REG_VIN(i));
  1685. data->in_min[i] =
  1686. it87_read_value(data, IT87_REG_VIN_MIN(i));
  1687. data->in_max[i] =
  1688. it87_read_value(data, IT87_REG_VIN_MAX(i));
  1689. }
  1690. /* in8 (battery) has no limit registers */
  1691. data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
  1692. for (i = 0; i < 5; i++) {
  1693. /* Skip disabled fans */
  1694. if (!(data->has_fan & (1 << i)))
  1695. continue;
  1696. data->fan_min[i] =
  1697. it87_read_value(data, IT87_REG_FAN_MIN[i]);
  1698. data->fan[i] = it87_read_value(data,
  1699. IT87_REG_FAN[i]);
  1700. /* Add high byte if in 16-bit mode */
  1701. if (has_16bit_fans(data)) {
  1702. data->fan[i] |= it87_read_value(data,
  1703. IT87_REG_FANX[i]) << 8;
  1704. data->fan_min[i] |= it87_read_value(data,
  1705. IT87_REG_FANX_MIN[i]) << 8;
  1706. }
  1707. }
  1708. for (i = 0; i < 3; i++) {
  1709. data->temp[i] =
  1710. it87_read_value(data, IT87_REG_TEMP(i));
  1711. data->temp_high[i] =
  1712. it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  1713. data->temp_low[i] =
  1714. it87_read_value(data, IT87_REG_TEMP_LOW(i));
  1715. }
  1716. /* Newer chips don't have clock dividers */
  1717. if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
  1718. i = it87_read_value(data, IT87_REG_FAN_DIV);
  1719. data->fan_div[0] = i & 0x07;
  1720. data->fan_div[1] = (i >> 3) & 0x07;
  1721. data->fan_div[2] = (i & 0x40) ? 3 : 1;
  1722. }
  1723. data->alarms =
  1724. it87_read_value(data, IT87_REG_ALARM1) |
  1725. (it87_read_value(data, IT87_REG_ALARM2) << 8) |
  1726. (it87_read_value(data, IT87_REG_ALARM3) << 16);
  1727. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  1728. data->fan_main_ctrl = it87_read_value(data,
  1729. IT87_REG_FAN_MAIN_CTRL);
  1730. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
  1731. for (i = 0; i < 3; i++)
  1732. it87_update_pwm_ctrl(data, i);
  1733. data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  1734. /* The 8705 does not have VID capability.
  1735. The 8718 and the 8720 don't use IT87_REG_VID for the
  1736. same purpose. */
  1737. if (data->type == it8712 || data->type == it8716) {
  1738. data->vid = it87_read_value(data, IT87_REG_VID);
  1739. /* The older IT8712F revisions had only 5 VID pins,
  1740. but we assume it is always safe to read 6 bits. */
  1741. data->vid &= 0x3f;
  1742. }
  1743. data->last_updated = jiffies;
  1744. data->valid = 1;
  1745. }
  1746. mutex_unlock(&data->update_lock);
  1747. return data;
  1748. }
  1749. static int __init it87_device_add(unsigned short address,
  1750. const struct it87_sio_data *sio_data)
  1751. {
  1752. struct resource res = {
  1753. .start = address + IT87_EC_OFFSET,
  1754. .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
  1755. .name = DRVNAME,
  1756. .flags = IORESOURCE_IO,
  1757. };
  1758. int err;
  1759. err = acpi_check_resource_conflict(&res);
  1760. if (err)
  1761. goto exit;
  1762. pdev = platform_device_alloc(DRVNAME, address);
  1763. if (!pdev) {
  1764. err = -ENOMEM;
  1765. printk(KERN_ERR DRVNAME ": Device allocation failed\n");
  1766. goto exit;
  1767. }
  1768. err = platform_device_add_resources(pdev, &res, 1);
  1769. if (err) {
  1770. printk(KERN_ERR DRVNAME ": Device resource addition failed "
  1771. "(%d)\n", err);
  1772. goto exit_device_put;
  1773. }
  1774. err = platform_device_add_data(pdev, sio_data,
  1775. sizeof(struct it87_sio_data));
  1776. if (err) {
  1777. printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
  1778. goto exit_device_put;
  1779. }
  1780. err = platform_device_add(pdev);
  1781. if (err) {
  1782. printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
  1783. err);
  1784. goto exit_device_put;
  1785. }
  1786. return 0;
  1787. exit_device_put:
  1788. platform_device_put(pdev);
  1789. exit:
  1790. return err;
  1791. }
  1792. static int __init sm_it87_init(void)
  1793. {
  1794. int err;
  1795. unsigned short isa_address = 0;
  1796. struct it87_sio_data sio_data;
  1797. memset(&sio_data, 0, sizeof(struct it87_sio_data));
  1798. err = it87_find(&isa_address, &sio_data);
  1799. if (err)
  1800. return err;
  1801. err = platform_driver_register(&it87_driver);
  1802. if (err)
  1803. return err;
  1804. err = it87_device_add(isa_address, &sio_data);
  1805. if (err) {
  1806. platform_driver_unregister(&it87_driver);
  1807. return err;
  1808. }
  1809. return 0;
  1810. }
  1811. static void __exit sm_it87_exit(void)
  1812. {
  1813. platform_device_unregister(pdev);
  1814. platform_driver_unregister(&it87_driver);
  1815. }
  1816. MODULE_AUTHOR("Chris Gauthron, "
  1817. "Jean Delvare <khali@linux-fr.org>");
  1818. MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
  1819. module_param(update_vbat, bool, 0);
  1820. MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
  1821. module_param(fix_pwm_polarity, bool, 0);
  1822. MODULE_PARM_DESC(fix_pwm_polarity,
  1823. "Force PWM polarity to active high (DANGEROUS)");
  1824. MODULE_LICENSE("GPL");
  1825. module_init(sm_it87_init);
  1826. module_exit(sm_it87_exit);