it87.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  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. u8 reg;
  458. if (strict_strtol(buf, 10, &val) < 0)
  459. return -EINVAL;
  460. reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  461. reg &= ~(1 << nr);
  462. reg &= ~(8 << nr);
  463. if (val == 2) { /* backwards compatibility */
  464. dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
  465. "instead\n");
  466. val = 4;
  467. }
  468. /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
  469. if (val == 3)
  470. reg |= 1 << nr;
  471. else if (val == 4)
  472. reg |= 8 << nr;
  473. else if (val != 0)
  474. return -EINVAL;
  475. mutex_lock(&data->update_lock);
  476. data->sensor = reg;
  477. it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
  478. mutex_unlock(&data->update_lock);
  479. return count;
  480. }
  481. #define show_sensor_offset(offset) \
  482. static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
  483. show_sensor, set_sensor, offset - 1);
  484. show_sensor_offset(1);
  485. show_sensor_offset(2);
  486. show_sensor_offset(3);
  487. /* 3 Fans */
  488. static int pwm_mode(const struct it87_data *data, int nr)
  489. {
  490. int ctrl = data->fan_main_ctrl & (1 << nr);
  491. if (ctrl == 0) /* Full speed */
  492. return 0;
  493. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  494. return 2;
  495. else /* Manual mode */
  496. return 1;
  497. }
  498. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  499. char *buf)
  500. {
  501. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  502. int nr = sensor_attr->index;
  503. struct it87_data *data = it87_update_device(dev);
  504. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
  505. DIV_FROM_REG(data->fan_div[nr])));
  506. }
  507. static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
  508. char *buf)
  509. {
  510. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  511. int nr = sensor_attr->index;
  512. struct it87_data *data = it87_update_device(dev);
  513. return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
  514. DIV_FROM_REG(data->fan_div[nr])));
  515. }
  516. static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
  517. char *buf)
  518. {
  519. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  520. int nr = sensor_attr->index;
  521. struct it87_data *data = it87_update_device(dev);
  522. return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
  523. }
  524. static ssize_t show_pwm_enable(struct device *dev,
  525. struct device_attribute *attr, char *buf)
  526. {
  527. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  528. int nr = sensor_attr->index;
  529. struct it87_data *data = it87_update_device(dev);
  530. return sprintf(buf, "%d\n", pwm_mode(data, nr));
  531. }
  532. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  533. char *buf)
  534. {
  535. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  536. int nr = sensor_attr->index;
  537. struct it87_data *data = it87_update_device(dev);
  538. return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr]));
  539. }
  540. static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
  541. char *buf)
  542. {
  543. struct it87_data *data = it87_update_device(dev);
  544. int index = (data->fan_ctl >> 4) & 0x07;
  545. return sprintf(buf, "%u\n", pwm_freq[index]);
  546. }
  547. static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
  548. const char *buf, size_t count)
  549. {
  550. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  551. int nr = sensor_attr->index;
  552. struct it87_data *data = dev_get_drvdata(dev);
  553. long val;
  554. u8 reg;
  555. if (strict_strtol(buf, 10, &val) < 0)
  556. return -EINVAL;
  557. mutex_lock(&data->update_lock);
  558. reg = it87_read_value(data, IT87_REG_FAN_DIV);
  559. switch (nr) {
  560. case 0:
  561. data->fan_div[nr] = reg & 0x07;
  562. break;
  563. case 1:
  564. data->fan_div[nr] = (reg >> 3) & 0x07;
  565. break;
  566. case 2:
  567. data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
  568. break;
  569. }
  570. data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
  571. it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
  572. mutex_unlock(&data->update_lock);
  573. return count;
  574. }
  575. static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
  576. const char *buf, size_t count)
  577. {
  578. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  579. int nr = sensor_attr->index;
  580. struct it87_data *data = dev_get_drvdata(dev);
  581. unsigned long val;
  582. int min;
  583. u8 old;
  584. if (strict_strtoul(buf, 10, &val) < 0)
  585. return -EINVAL;
  586. mutex_lock(&data->update_lock);
  587. old = it87_read_value(data, IT87_REG_FAN_DIV);
  588. /* Save fan min limit */
  589. min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
  590. switch (nr) {
  591. case 0:
  592. case 1:
  593. data->fan_div[nr] = DIV_TO_REG(val);
  594. break;
  595. case 2:
  596. if (val < 8)
  597. data->fan_div[nr] = 1;
  598. else
  599. data->fan_div[nr] = 3;
  600. }
  601. val = old & 0x80;
  602. val |= (data->fan_div[0] & 0x07);
  603. val |= (data->fan_div[1] & 0x07) << 3;
  604. if (data->fan_div[2] == 3)
  605. val |= 0x1 << 6;
  606. it87_write_value(data, IT87_REG_FAN_DIV, val);
  607. /* Restore fan min limit */
  608. data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
  609. it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
  610. mutex_unlock(&data->update_lock);
  611. return count;
  612. }
  613. /* Returns 0 if OK, -EINVAL otherwise */
  614. static int check_trip_points(struct device *dev, int nr)
  615. {
  616. const struct it87_data *data = dev_get_drvdata(dev);
  617. int i, err = 0;
  618. if (has_old_autopwm(data)) {
  619. for (i = 0; i < 3; i++) {
  620. if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
  621. err = -EINVAL;
  622. }
  623. for (i = 0; i < 2; i++) {
  624. if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
  625. err = -EINVAL;
  626. }
  627. }
  628. if (err) {
  629. dev_err(dev, "Inconsistent trip points, not switching to "
  630. "automatic mode\n");
  631. dev_err(dev, "Adjust the trip points and try again\n");
  632. }
  633. return err;
  634. }
  635. static ssize_t set_pwm_enable(struct device *dev,
  636. struct device_attribute *attr, const char *buf, size_t count)
  637. {
  638. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  639. int nr = sensor_attr->index;
  640. struct it87_data *data = dev_get_drvdata(dev);
  641. long val;
  642. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
  643. return -EINVAL;
  644. /* Check trip points before switching to automatic mode */
  645. if (val == 2) {
  646. if (check_trip_points(dev, nr) < 0)
  647. return -EINVAL;
  648. }
  649. mutex_lock(&data->update_lock);
  650. if (val == 0) {
  651. int tmp;
  652. /* make sure the fan is on when in on/off mode */
  653. tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  654. it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
  655. /* set on/off mode */
  656. data->fan_main_ctrl &= ~(1 << nr);
  657. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  658. data->fan_main_ctrl);
  659. } else {
  660. if (val == 1) /* Manual mode */
  661. data->pwm_ctrl[nr] = data->pwm_duty[nr];
  662. else /* Automatic mode */
  663. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  664. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  665. /* set SmartGuardian mode */
  666. data->fan_main_ctrl |= (1 << nr);
  667. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  668. data->fan_main_ctrl);
  669. }
  670. mutex_unlock(&data->update_lock);
  671. return count;
  672. }
  673. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  674. const char *buf, size_t count)
  675. {
  676. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  677. int nr = sensor_attr->index;
  678. struct it87_data *data = dev_get_drvdata(dev);
  679. long val;
  680. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  681. return -EINVAL;
  682. mutex_lock(&data->update_lock);
  683. data->pwm_duty[nr] = PWM_TO_REG(val);
  684. /* If we are in manual mode, write the duty cycle immediately;
  685. * otherwise, just store it for later use. */
  686. if (!(data->pwm_ctrl[nr] & 0x80)) {
  687. data->pwm_ctrl[nr] = data->pwm_duty[nr];
  688. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  689. }
  690. mutex_unlock(&data->update_lock);
  691. return count;
  692. }
  693. static ssize_t set_pwm_freq(struct device *dev,
  694. struct device_attribute *attr, const char *buf, size_t count)
  695. {
  696. struct it87_data *data = dev_get_drvdata(dev);
  697. unsigned long val;
  698. int i;
  699. if (strict_strtoul(buf, 10, &val) < 0)
  700. return -EINVAL;
  701. /* Search for the nearest available frequency */
  702. for (i = 0; i < 7; i++) {
  703. if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
  704. break;
  705. }
  706. mutex_lock(&data->update_lock);
  707. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
  708. data->fan_ctl |= i << 4;
  709. it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
  710. mutex_unlock(&data->update_lock);
  711. return count;
  712. }
  713. static ssize_t show_pwm_temp_map(struct device *dev,
  714. struct device_attribute *attr, char *buf)
  715. {
  716. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  717. int nr = sensor_attr->index;
  718. struct it87_data *data = it87_update_device(dev);
  719. int map;
  720. if (data->pwm_temp_map[nr] < 3)
  721. map = 1 << data->pwm_temp_map[nr];
  722. else
  723. map = 0; /* Should never happen */
  724. return sprintf(buf, "%d\n", map);
  725. }
  726. static ssize_t set_pwm_temp_map(struct device *dev,
  727. struct device_attribute *attr, const char *buf, size_t count)
  728. {
  729. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  730. int nr = sensor_attr->index;
  731. struct it87_data *data = dev_get_drvdata(dev);
  732. long val;
  733. u8 reg;
  734. /* This check can go away if we ever support automatic fan speed
  735. control on newer chips. */
  736. if (!has_old_autopwm(data)) {
  737. dev_notice(dev, "Mapping change disabled for safety reasons\n");
  738. return -EINVAL;
  739. }
  740. if (strict_strtol(buf, 10, &val) < 0)
  741. return -EINVAL;
  742. switch (val) {
  743. case (1 << 0):
  744. reg = 0x00;
  745. break;
  746. case (1 << 1):
  747. reg = 0x01;
  748. break;
  749. case (1 << 2):
  750. reg = 0x02;
  751. break;
  752. default:
  753. return -EINVAL;
  754. }
  755. mutex_lock(&data->update_lock);
  756. data->pwm_temp_map[nr] = reg;
  757. /* If we are in automatic mode, write the temp mapping immediately;
  758. * otherwise, just store it for later use. */
  759. if (data->pwm_ctrl[nr] & 0x80) {
  760. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  761. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  762. }
  763. mutex_unlock(&data->update_lock);
  764. return count;
  765. }
  766. static ssize_t show_auto_pwm(struct device *dev,
  767. struct device_attribute *attr, char *buf)
  768. {
  769. struct it87_data *data = it87_update_device(dev);
  770. struct sensor_device_attribute_2 *sensor_attr =
  771. to_sensor_dev_attr_2(attr);
  772. int nr = sensor_attr->nr;
  773. int point = sensor_attr->index;
  774. return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point]));
  775. }
  776. static ssize_t set_auto_pwm(struct device *dev,
  777. struct device_attribute *attr, const char *buf, size_t count)
  778. {
  779. struct it87_data *data = dev_get_drvdata(dev);
  780. struct sensor_device_attribute_2 *sensor_attr =
  781. to_sensor_dev_attr_2(attr);
  782. int nr = sensor_attr->nr;
  783. int point = sensor_attr->index;
  784. long val;
  785. if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  786. return -EINVAL;
  787. mutex_lock(&data->update_lock);
  788. data->auto_pwm[nr][point] = PWM_TO_REG(val);
  789. it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
  790. data->auto_pwm[nr][point]);
  791. mutex_unlock(&data->update_lock);
  792. return count;
  793. }
  794. static ssize_t show_auto_temp(struct device *dev,
  795. struct device_attribute *attr, char *buf)
  796. {
  797. struct it87_data *data = it87_update_device(dev);
  798. struct sensor_device_attribute_2 *sensor_attr =
  799. to_sensor_dev_attr_2(attr);
  800. int nr = sensor_attr->nr;
  801. int point = sensor_attr->index;
  802. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
  803. }
  804. static ssize_t set_auto_temp(struct device *dev,
  805. struct device_attribute *attr, const char *buf, size_t count)
  806. {
  807. struct it87_data *data = dev_get_drvdata(dev);
  808. struct sensor_device_attribute_2 *sensor_attr =
  809. to_sensor_dev_attr_2(attr);
  810. int nr = sensor_attr->nr;
  811. int point = sensor_attr->index;
  812. long val;
  813. if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
  814. return -EINVAL;
  815. mutex_lock(&data->update_lock);
  816. data->auto_temp[nr][point] = TEMP_TO_REG(val);
  817. it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
  818. data->auto_temp[nr][point]);
  819. mutex_unlock(&data->update_lock);
  820. return count;
  821. }
  822. #define show_fan_offset(offset) \
  823. static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
  824. show_fan, NULL, offset - 1); \
  825. static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  826. show_fan_min, set_fan_min, offset - 1); \
  827. static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
  828. show_fan_div, set_fan_div, offset - 1);
  829. show_fan_offset(1);
  830. show_fan_offset(2);
  831. show_fan_offset(3);
  832. #define show_pwm_offset(offset) \
  833. static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
  834. show_pwm_enable, set_pwm_enable, offset - 1); \
  835. static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
  836. show_pwm, set_pwm, offset - 1); \
  837. static DEVICE_ATTR(pwm##offset##_freq, \
  838. (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
  839. show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
  840. static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
  841. S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
  842. offset - 1); \
  843. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
  844. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  845. offset - 1, 0); \
  846. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
  847. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  848. offset - 1, 1); \
  849. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
  850. S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
  851. offset - 1, 2); \
  852. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
  853. S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
  854. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
  855. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  856. offset - 1, 1); \
  857. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
  858. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  859. offset - 1, 0); \
  860. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
  861. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  862. offset - 1, 2); \
  863. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
  864. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  865. offset - 1, 3); \
  866. static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
  867. S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
  868. offset - 1, 4);
  869. show_pwm_offset(1);
  870. show_pwm_offset(2);
  871. show_pwm_offset(3);
  872. /* A different set of callbacks for 16-bit fans */
  873. static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
  874. char *buf)
  875. {
  876. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  877. int nr = sensor_attr->index;
  878. struct it87_data *data = it87_update_device(dev);
  879. return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
  880. }
  881. static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
  882. char *buf)
  883. {
  884. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  885. int nr = sensor_attr->index;
  886. struct it87_data *data = it87_update_device(dev);
  887. return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
  888. }
  889. static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
  890. const char *buf, size_t count)
  891. {
  892. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  893. int nr = sensor_attr->index;
  894. struct it87_data *data = dev_get_drvdata(dev);
  895. long val;
  896. if (strict_strtol(buf, 10, &val) < 0)
  897. return -EINVAL;
  898. mutex_lock(&data->update_lock);
  899. data->fan_min[nr] = FAN16_TO_REG(val);
  900. it87_write_value(data, IT87_REG_FAN_MIN[nr],
  901. data->fan_min[nr] & 0xff);
  902. it87_write_value(data, IT87_REG_FANX_MIN[nr],
  903. data->fan_min[nr] >> 8);
  904. mutex_unlock(&data->update_lock);
  905. return count;
  906. }
  907. /* We want to use the same sysfs file names as 8-bit fans, but we need
  908. different variable names, so we have to use SENSOR_ATTR instead of
  909. SENSOR_DEVICE_ATTR. */
  910. #define show_fan16_offset(offset) \
  911. static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
  912. = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
  913. show_fan16, NULL, offset - 1); \
  914. static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
  915. = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
  916. show_fan16_min, set_fan16_min, offset - 1)
  917. show_fan16_offset(1);
  918. show_fan16_offset(2);
  919. show_fan16_offset(3);
  920. show_fan16_offset(4);
  921. show_fan16_offset(5);
  922. /* Alarms */
  923. static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
  924. char *buf)
  925. {
  926. struct it87_data *data = it87_update_device(dev);
  927. return sprintf(buf, "%u\n", data->alarms);
  928. }
  929. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  930. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  931. char *buf)
  932. {
  933. int bitnr = to_sensor_dev_attr(attr)->index;
  934. struct it87_data *data = it87_update_device(dev);
  935. return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  936. }
  937. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
  938. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
  939. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
  940. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
  941. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
  942. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
  943. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
  944. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
  945. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
  946. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
  947. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
  948. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
  949. static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
  950. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
  951. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
  952. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
  953. static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
  954. char *buf)
  955. {
  956. int bitnr = to_sensor_dev_attr(attr)->index;
  957. struct it87_data *data = it87_update_device(dev);
  958. return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
  959. }
  960. static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
  961. const char *buf, size_t count)
  962. {
  963. int bitnr = to_sensor_dev_attr(attr)->index;
  964. struct it87_data *data = dev_get_drvdata(dev);
  965. long val;
  966. if (strict_strtol(buf, 10, &val) < 0
  967. || (val != 0 && val != 1))
  968. return -EINVAL;
  969. mutex_lock(&data->update_lock);
  970. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  971. if (val)
  972. data->beeps |= (1 << bitnr);
  973. else
  974. data->beeps &= ~(1 << bitnr);
  975. it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
  976. mutex_unlock(&data->update_lock);
  977. return count;
  978. }
  979. static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
  980. show_beep, set_beep, 1);
  981. static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
  982. static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
  983. static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
  984. static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
  985. static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
  986. static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
  987. static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
  988. /* fanX_beep writability is set later */
  989. static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
  990. static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
  991. static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
  992. static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
  993. static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
  994. static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
  995. show_beep, set_beep, 2);
  996. static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
  997. static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
  998. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  999. char *buf)
  1000. {
  1001. struct it87_data *data = dev_get_drvdata(dev);
  1002. return sprintf(buf, "%u\n", data->vrm);
  1003. }
  1004. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  1005. const char *buf, size_t count)
  1006. {
  1007. struct it87_data *data = dev_get_drvdata(dev);
  1008. unsigned long val;
  1009. if (strict_strtoul(buf, 10, &val) < 0)
  1010. return -EINVAL;
  1011. data->vrm = val;
  1012. return count;
  1013. }
  1014. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  1015. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  1016. char *buf)
  1017. {
  1018. struct it87_data *data = it87_update_device(dev);
  1019. return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
  1020. }
  1021. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  1022. static ssize_t show_name(struct device *dev, struct device_attribute
  1023. *devattr, char *buf)
  1024. {
  1025. struct it87_data *data = dev_get_drvdata(dev);
  1026. return sprintf(buf, "%s\n", data->name);
  1027. }
  1028. static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  1029. static struct attribute *it87_attributes[] = {
  1030. &sensor_dev_attr_in0_input.dev_attr.attr,
  1031. &sensor_dev_attr_in1_input.dev_attr.attr,
  1032. &sensor_dev_attr_in2_input.dev_attr.attr,
  1033. &sensor_dev_attr_in3_input.dev_attr.attr,
  1034. &sensor_dev_attr_in4_input.dev_attr.attr,
  1035. &sensor_dev_attr_in5_input.dev_attr.attr,
  1036. &sensor_dev_attr_in6_input.dev_attr.attr,
  1037. &sensor_dev_attr_in7_input.dev_attr.attr,
  1038. &sensor_dev_attr_in8_input.dev_attr.attr,
  1039. &sensor_dev_attr_in0_min.dev_attr.attr,
  1040. &sensor_dev_attr_in1_min.dev_attr.attr,
  1041. &sensor_dev_attr_in2_min.dev_attr.attr,
  1042. &sensor_dev_attr_in3_min.dev_attr.attr,
  1043. &sensor_dev_attr_in4_min.dev_attr.attr,
  1044. &sensor_dev_attr_in5_min.dev_attr.attr,
  1045. &sensor_dev_attr_in6_min.dev_attr.attr,
  1046. &sensor_dev_attr_in7_min.dev_attr.attr,
  1047. &sensor_dev_attr_in0_max.dev_attr.attr,
  1048. &sensor_dev_attr_in1_max.dev_attr.attr,
  1049. &sensor_dev_attr_in2_max.dev_attr.attr,
  1050. &sensor_dev_attr_in3_max.dev_attr.attr,
  1051. &sensor_dev_attr_in4_max.dev_attr.attr,
  1052. &sensor_dev_attr_in5_max.dev_attr.attr,
  1053. &sensor_dev_attr_in6_max.dev_attr.attr,
  1054. &sensor_dev_attr_in7_max.dev_attr.attr,
  1055. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  1056. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1057. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1058. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1059. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1060. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1061. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1062. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1063. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1064. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1065. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1066. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1067. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1068. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1069. &sensor_dev_attr_temp1_min.dev_attr.attr,
  1070. &sensor_dev_attr_temp2_min.dev_attr.attr,
  1071. &sensor_dev_attr_temp3_min.dev_attr.attr,
  1072. &sensor_dev_attr_temp1_type.dev_attr.attr,
  1073. &sensor_dev_attr_temp2_type.dev_attr.attr,
  1074. &sensor_dev_attr_temp3_type.dev_attr.attr,
  1075. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1076. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1077. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1078. &dev_attr_alarms.attr,
  1079. &dev_attr_name.attr,
  1080. NULL
  1081. };
  1082. static const struct attribute_group it87_group = {
  1083. .attrs = it87_attributes,
  1084. };
  1085. static struct attribute *it87_attributes_beep[] = {
  1086. &sensor_dev_attr_in0_beep.dev_attr.attr,
  1087. &sensor_dev_attr_in1_beep.dev_attr.attr,
  1088. &sensor_dev_attr_in2_beep.dev_attr.attr,
  1089. &sensor_dev_attr_in3_beep.dev_attr.attr,
  1090. &sensor_dev_attr_in4_beep.dev_attr.attr,
  1091. &sensor_dev_attr_in5_beep.dev_attr.attr,
  1092. &sensor_dev_attr_in6_beep.dev_attr.attr,
  1093. &sensor_dev_attr_in7_beep.dev_attr.attr,
  1094. &sensor_dev_attr_temp1_beep.dev_attr.attr,
  1095. &sensor_dev_attr_temp2_beep.dev_attr.attr,
  1096. &sensor_dev_attr_temp3_beep.dev_attr.attr,
  1097. NULL
  1098. };
  1099. static const struct attribute_group it87_group_beep = {
  1100. .attrs = it87_attributes_beep,
  1101. };
  1102. static struct attribute *it87_attributes_fan16[5][3+1] = { {
  1103. &sensor_dev_attr_fan1_input16.dev_attr.attr,
  1104. &sensor_dev_attr_fan1_min16.dev_attr.attr,
  1105. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1106. NULL
  1107. }, {
  1108. &sensor_dev_attr_fan2_input16.dev_attr.attr,
  1109. &sensor_dev_attr_fan2_min16.dev_attr.attr,
  1110. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1111. NULL
  1112. }, {
  1113. &sensor_dev_attr_fan3_input16.dev_attr.attr,
  1114. &sensor_dev_attr_fan3_min16.dev_attr.attr,
  1115. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1116. NULL
  1117. }, {
  1118. &sensor_dev_attr_fan4_input16.dev_attr.attr,
  1119. &sensor_dev_attr_fan4_min16.dev_attr.attr,
  1120. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1121. NULL
  1122. }, {
  1123. &sensor_dev_attr_fan5_input16.dev_attr.attr,
  1124. &sensor_dev_attr_fan5_min16.dev_attr.attr,
  1125. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1126. NULL
  1127. } };
  1128. static const struct attribute_group it87_group_fan16[5] = {
  1129. { .attrs = it87_attributes_fan16[0] },
  1130. { .attrs = it87_attributes_fan16[1] },
  1131. { .attrs = it87_attributes_fan16[2] },
  1132. { .attrs = it87_attributes_fan16[3] },
  1133. { .attrs = it87_attributes_fan16[4] },
  1134. };
  1135. static struct attribute *it87_attributes_fan[3][4+1] = { {
  1136. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1137. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1138. &sensor_dev_attr_fan1_div.dev_attr.attr,
  1139. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1140. NULL
  1141. }, {
  1142. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1143. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1144. &sensor_dev_attr_fan2_div.dev_attr.attr,
  1145. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1146. NULL
  1147. }, {
  1148. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1149. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1150. &sensor_dev_attr_fan3_div.dev_attr.attr,
  1151. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1152. NULL
  1153. } };
  1154. static const struct attribute_group it87_group_fan[3] = {
  1155. { .attrs = it87_attributes_fan[0] },
  1156. { .attrs = it87_attributes_fan[1] },
  1157. { .attrs = it87_attributes_fan[2] },
  1158. };
  1159. static const struct attribute_group *
  1160. it87_get_fan_group(const struct it87_data *data)
  1161. {
  1162. return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
  1163. }
  1164. static struct attribute *it87_attributes_pwm[3][4+1] = { {
  1165. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1166. &sensor_dev_attr_pwm1.dev_attr.attr,
  1167. &dev_attr_pwm1_freq.attr,
  1168. &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
  1169. NULL
  1170. }, {
  1171. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1172. &sensor_dev_attr_pwm2.dev_attr.attr,
  1173. &dev_attr_pwm2_freq.attr,
  1174. &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
  1175. NULL
  1176. }, {
  1177. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1178. &sensor_dev_attr_pwm3.dev_attr.attr,
  1179. &dev_attr_pwm3_freq.attr,
  1180. &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
  1181. NULL
  1182. } };
  1183. static const struct attribute_group it87_group_pwm[3] = {
  1184. { .attrs = it87_attributes_pwm[0] },
  1185. { .attrs = it87_attributes_pwm[1] },
  1186. { .attrs = it87_attributes_pwm[2] },
  1187. };
  1188. static struct attribute *it87_attributes_autopwm[3][9+1] = { {
  1189. &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
  1190. &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
  1191. &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
  1192. &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
  1193. &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
  1194. &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
  1195. &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
  1196. &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
  1197. &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
  1198. NULL
  1199. }, {
  1200. &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
  1201. &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
  1202. &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
  1203. &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
  1204. &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
  1205. &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
  1206. &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
  1207. &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
  1208. &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
  1209. NULL
  1210. }, {
  1211. &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
  1212. &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
  1213. &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
  1214. &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
  1215. &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
  1216. &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
  1217. &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
  1218. &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
  1219. &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
  1220. NULL
  1221. } };
  1222. static const struct attribute_group it87_group_autopwm[3] = {
  1223. { .attrs = it87_attributes_autopwm[0] },
  1224. { .attrs = it87_attributes_autopwm[1] },
  1225. { .attrs = it87_attributes_autopwm[2] },
  1226. };
  1227. static struct attribute *it87_attributes_fan_beep[] = {
  1228. &sensor_dev_attr_fan1_beep.dev_attr.attr,
  1229. &sensor_dev_attr_fan2_beep.dev_attr.attr,
  1230. &sensor_dev_attr_fan3_beep.dev_attr.attr,
  1231. &sensor_dev_attr_fan4_beep.dev_attr.attr,
  1232. &sensor_dev_attr_fan5_beep.dev_attr.attr,
  1233. };
  1234. static struct attribute *it87_attributes_vid[] = {
  1235. &dev_attr_vrm.attr,
  1236. &dev_attr_cpu0_vid.attr,
  1237. NULL
  1238. };
  1239. static const struct attribute_group it87_group_vid = {
  1240. .attrs = it87_attributes_vid,
  1241. };
  1242. /* SuperIO detection - will change isa_address if a chip is found */
  1243. static int __init it87_find(unsigned short *address,
  1244. struct it87_sio_data *sio_data)
  1245. {
  1246. int err = -ENODEV;
  1247. u16 chip_type;
  1248. const char *board_vendor, *board_name;
  1249. superio_enter();
  1250. chip_type = force_id ? force_id : superio_inw(DEVID);
  1251. switch (chip_type) {
  1252. case IT8705F_DEVID:
  1253. sio_data->type = it87;
  1254. break;
  1255. case IT8712F_DEVID:
  1256. sio_data->type = it8712;
  1257. break;
  1258. case IT8716F_DEVID:
  1259. case IT8726F_DEVID:
  1260. sio_data->type = it8716;
  1261. break;
  1262. case IT8718F_DEVID:
  1263. sio_data->type = it8718;
  1264. break;
  1265. case IT8720F_DEVID:
  1266. sio_data->type = it8720;
  1267. break;
  1268. case 0xffff: /* No device at all */
  1269. goto exit;
  1270. default:
  1271. pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
  1272. chip_type);
  1273. goto exit;
  1274. }
  1275. superio_select(PME);
  1276. if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
  1277. pr_info("it87: Device not activated, skipping\n");
  1278. goto exit;
  1279. }
  1280. *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
  1281. if (*address == 0) {
  1282. pr_info("it87: Base address not set, skipping\n");
  1283. goto exit;
  1284. }
  1285. err = 0;
  1286. sio_data->revision = superio_inb(DEVREV) & 0x0f;
  1287. pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
  1288. chip_type, *address, sio_data->revision);
  1289. /* Read GPIO config and VID value from LDN 7 (GPIO) */
  1290. if (sio_data->type == it87) {
  1291. /* The IT8705F doesn't have VID pins at all */
  1292. sio_data->skip_vid = 1;
  1293. /* The IT8705F has a different LD number for GPIO */
  1294. superio_select(5);
  1295. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1296. } else {
  1297. int reg;
  1298. superio_select(GPIO);
  1299. /* We need at least 4 VID pins */
  1300. reg = superio_inb(IT87_SIO_GPIO3_REG);
  1301. if (reg & 0x0f) {
  1302. pr_info("it87: VID is disabled (pins used for GPIO)\n");
  1303. sio_data->skip_vid = 1;
  1304. }
  1305. /* Check if fan3 is there or not */
  1306. if (reg & (1 << 6))
  1307. sio_data->skip_pwm |= (1 << 2);
  1308. if (reg & (1 << 7))
  1309. sio_data->skip_fan |= (1 << 2);
  1310. /* Check if fan2 is there or not */
  1311. reg = superio_inb(IT87_SIO_GPIO5_REG);
  1312. if (reg & (1 << 1))
  1313. sio_data->skip_pwm |= (1 << 1);
  1314. if (reg & (1 << 2))
  1315. sio_data->skip_fan |= (1 << 1);
  1316. if ((sio_data->type == it8718 || sio_data->type == it8720)
  1317. && !(sio_data->skip_vid))
  1318. sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
  1319. reg = superio_inb(IT87_SIO_PINX2_REG);
  1320. if (reg & (1 << 0))
  1321. pr_info("it87: in3 is VCC (+5V)\n");
  1322. if (reg & (1 << 1))
  1323. pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
  1324. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1325. }
  1326. if (sio_data->beep_pin)
  1327. pr_info("it87: Beeping is supported\n");
  1328. /* Disable specific features based on DMI strings */
  1329. board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1330. board_name = dmi_get_system_info(DMI_BOARD_NAME);
  1331. if (board_vendor && board_name) {
  1332. if (strcmp(board_vendor, "nVIDIA") == 0
  1333. && strcmp(board_name, "FN68PT") == 0) {
  1334. /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
  1335. connected to a fan, but to something else. One user
  1336. has reported instant system power-off when changing
  1337. the PWM2 duty cycle, so we disable it.
  1338. I use the board name string as the trigger in case
  1339. the same board is ever used in other systems. */
  1340. pr_info("it87: Disabling pwm2 due to "
  1341. "hardware constraints\n");
  1342. sio_data->skip_pwm = (1 << 1);
  1343. }
  1344. }
  1345. exit:
  1346. superio_exit();
  1347. return err;
  1348. }
  1349. static void it87_remove_files(struct device *dev)
  1350. {
  1351. struct it87_data *data = platform_get_drvdata(pdev);
  1352. struct it87_sio_data *sio_data = dev->platform_data;
  1353. const struct attribute_group *fan_group = it87_get_fan_group(data);
  1354. int i;
  1355. sysfs_remove_group(&dev->kobj, &it87_group);
  1356. if (sio_data->beep_pin)
  1357. sysfs_remove_group(&dev->kobj, &it87_group_beep);
  1358. for (i = 0; i < 5; i++) {
  1359. if (!(data->has_fan & (1 << i)))
  1360. continue;
  1361. sysfs_remove_group(&dev->kobj, &fan_group[i]);
  1362. if (sio_data->beep_pin)
  1363. sysfs_remove_file(&dev->kobj,
  1364. it87_attributes_fan_beep[i]);
  1365. }
  1366. for (i = 0; i < 3; i++) {
  1367. if (sio_data->skip_pwm & (1 << 0))
  1368. continue;
  1369. sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
  1370. if (has_old_autopwm(data))
  1371. sysfs_remove_group(&dev->kobj,
  1372. &it87_group_autopwm[i]);
  1373. }
  1374. if (!sio_data->skip_vid)
  1375. sysfs_remove_group(&dev->kobj, &it87_group_vid);
  1376. }
  1377. static int __devinit it87_probe(struct platform_device *pdev)
  1378. {
  1379. struct it87_data *data;
  1380. struct resource *res;
  1381. struct device *dev = &pdev->dev;
  1382. struct it87_sio_data *sio_data = dev->platform_data;
  1383. const struct attribute_group *fan_group;
  1384. int err = 0, i;
  1385. int enable_pwm_interface;
  1386. int fan_beep_need_rw;
  1387. static const char *names[] = {
  1388. "it87",
  1389. "it8712",
  1390. "it8716",
  1391. "it8718",
  1392. "it8720",
  1393. };
  1394. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  1395. if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
  1396. dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
  1397. (unsigned long)res->start,
  1398. (unsigned long)(res->start + IT87_EC_EXTENT - 1));
  1399. err = -EBUSY;
  1400. goto ERROR0;
  1401. }
  1402. data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
  1403. if (!data) {
  1404. err = -ENOMEM;
  1405. goto ERROR1;
  1406. }
  1407. data->addr = res->start;
  1408. data->type = sio_data->type;
  1409. data->revision = sio_data->revision;
  1410. data->name = names[sio_data->type];
  1411. /* Now, we do the remaining detection. */
  1412. if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
  1413. || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
  1414. err = -ENODEV;
  1415. goto ERROR2;
  1416. }
  1417. platform_set_drvdata(pdev, data);
  1418. mutex_init(&data->update_lock);
  1419. /* Check PWM configuration */
  1420. enable_pwm_interface = it87_check_pwm(dev);
  1421. /* Initialize the IT87 chip */
  1422. it87_init_device(pdev);
  1423. /* Register sysfs hooks */
  1424. err = sysfs_create_group(&dev->kobj, &it87_group);
  1425. if (err)
  1426. goto ERROR2;
  1427. if (sio_data->beep_pin) {
  1428. err = sysfs_create_group(&dev->kobj, &it87_group_beep);
  1429. if (err)
  1430. goto ERROR4;
  1431. }
  1432. /* Do not create fan files for disabled fans */
  1433. fan_group = it87_get_fan_group(data);
  1434. fan_beep_need_rw = 1;
  1435. for (i = 0; i < 5; i++) {
  1436. if (!(data->has_fan & (1 << i)))
  1437. continue;
  1438. err = sysfs_create_group(&dev->kobj, &fan_group[i]);
  1439. if (err)
  1440. goto ERROR4;
  1441. if (sio_data->beep_pin) {
  1442. err = sysfs_create_file(&dev->kobj,
  1443. it87_attributes_fan_beep[i]);
  1444. if (err)
  1445. goto ERROR4;
  1446. if (!fan_beep_need_rw)
  1447. continue;
  1448. /* As we have a single beep enable bit for all fans,
  1449. * only the first enabled fan has a writable attribute
  1450. * for it. */
  1451. if (sysfs_chmod_file(&dev->kobj,
  1452. it87_attributes_fan_beep[i],
  1453. S_IRUGO | S_IWUSR))
  1454. dev_dbg(dev, "chmod +w fan%d_beep failed\n",
  1455. i + 1);
  1456. fan_beep_need_rw = 0;
  1457. }
  1458. }
  1459. if (enable_pwm_interface) {
  1460. for (i = 0; i < 3; i++) {
  1461. if (sio_data->skip_pwm & (1 << i))
  1462. continue;
  1463. err = sysfs_create_group(&dev->kobj,
  1464. &it87_group_pwm[i]);
  1465. if (err)
  1466. goto ERROR4;
  1467. if (!has_old_autopwm(data))
  1468. continue;
  1469. err = sysfs_create_group(&dev->kobj,
  1470. &it87_group_autopwm[i]);
  1471. if (err)
  1472. goto ERROR4;
  1473. }
  1474. }
  1475. if (!sio_data->skip_vid) {
  1476. data->vrm = vid_which_vrm();
  1477. /* VID reading from Super-I/O config space if available */
  1478. data->vid = sio_data->vid_value;
  1479. err = sysfs_create_group(&dev->kobj, &it87_group_vid);
  1480. if (err)
  1481. goto ERROR4;
  1482. }
  1483. data->hwmon_dev = hwmon_device_register(dev);
  1484. if (IS_ERR(data->hwmon_dev)) {
  1485. err = PTR_ERR(data->hwmon_dev);
  1486. goto ERROR4;
  1487. }
  1488. return 0;
  1489. ERROR4:
  1490. it87_remove_files(dev);
  1491. ERROR2:
  1492. platform_set_drvdata(pdev, NULL);
  1493. kfree(data);
  1494. ERROR1:
  1495. release_region(res->start, IT87_EC_EXTENT);
  1496. ERROR0:
  1497. return err;
  1498. }
  1499. static int __devexit it87_remove(struct platform_device *pdev)
  1500. {
  1501. struct it87_data *data = platform_get_drvdata(pdev);
  1502. hwmon_device_unregister(data->hwmon_dev);
  1503. it87_remove_files(&pdev->dev);
  1504. release_region(data->addr, IT87_EC_EXTENT);
  1505. platform_set_drvdata(pdev, NULL);
  1506. kfree(data);
  1507. return 0;
  1508. }
  1509. /* Must be called with data->update_lock held, except during initialization.
  1510. We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1511. would slow down the IT87 access and should not be necessary. */
  1512. static int it87_read_value(struct it87_data *data, u8 reg)
  1513. {
  1514. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1515. return inb_p(data->addr + IT87_DATA_REG_OFFSET);
  1516. }
  1517. /* Must be called with data->update_lock held, except during initialization.
  1518. We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1519. would slow down the IT87 access and should not be necessary. */
  1520. static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
  1521. {
  1522. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1523. outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
  1524. }
  1525. /* Return 1 if and only if the PWM interface is safe to use */
  1526. static int __devinit it87_check_pwm(struct device *dev)
  1527. {
  1528. struct it87_data *data = dev_get_drvdata(dev);
  1529. /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
  1530. * and polarity set to active low is sign that this is the case so we
  1531. * disable pwm control to protect the user. */
  1532. int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  1533. if ((tmp & 0x87) == 0) {
  1534. if (fix_pwm_polarity) {
  1535. /* The user asks us to attempt a chip reconfiguration.
  1536. * This means switching to active high polarity and
  1537. * inverting all fan speed values. */
  1538. int i;
  1539. u8 pwm[3];
  1540. for (i = 0; i < 3; i++)
  1541. pwm[i] = it87_read_value(data,
  1542. IT87_REG_PWM(i));
  1543. /* If any fan is in automatic pwm mode, the polarity
  1544. * might be correct, as suspicious as it seems, so we
  1545. * better don't change anything (but still disable the
  1546. * PWM interface). */
  1547. if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
  1548. dev_info(dev, "Reconfiguring PWM to "
  1549. "active high polarity\n");
  1550. it87_write_value(data, IT87_REG_FAN_CTL,
  1551. tmp | 0x87);
  1552. for (i = 0; i < 3; i++)
  1553. it87_write_value(data,
  1554. IT87_REG_PWM(i),
  1555. 0x7f & ~pwm[i]);
  1556. return 1;
  1557. }
  1558. dev_info(dev, "PWM configuration is "
  1559. "too broken to be fixed\n");
  1560. }
  1561. dev_info(dev, "Detected broken BIOS "
  1562. "defaults, disabling PWM interface\n");
  1563. return 0;
  1564. } else if (fix_pwm_polarity) {
  1565. dev_info(dev, "PWM configuration looks "
  1566. "sane, won't touch\n");
  1567. }
  1568. return 1;
  1569. }
  1570. /* Called when we have found a new IT87. */
  1571. static void __devinit it87_init_device(struct platform_device *pdev)
  1572. {
  1573. struct it87_sio_data *sio_data = pdev->dev.platform_data;
  1574. struct it87_data *data = platform_get_drvdata(pdev);
  1575. int tmp, i;
  1576. u8 mask;
  1577. /* For each PWM channel:
  1578. * - If it is in automatic mode, setting to manual mode should set
  1579. * the fan to full speed by default.
  1580. * - If it is in manual mode, we need a mapping to temperature
  1581. * channels to use when later setting to automatic mode later.
  1582. * Use a 1:1 mapping by default (we are clueless.)
  1583. * In both cases, the value can (and should) be changed by the user
  1584. * prior to switching to a different mode. */
  1585. for (i = 0; i < 3; i++) {
  1586. data->pwm_temp_map[i] = i;
  1587. data->pwm_duty[i] = 0x7f; /* Full speed */
  1588. data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
  1589. }
  1590. /* Some chips seem to have default value 0xff for all limit
  1591. * registers. For low voltage limits it makes no sense and triggers
  1592. * alarms, so change to 0 instead. For high temperature limits, it
  1593. * means -1 degree C, which surprisingly doesn't trigger an alarm,
  1594. * but is still confusing, so change to 127 degrees C. */
  1595. for (i = 0; i < 8; i++) {
  1596. tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
  1597. if (tmp == 0xff)
  1598. it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
  1599. }
  1600. for (i = 0; i < 3; i++) {
  1601. tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  1602. if (tmp == 0xff)
  1603. it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
  1604. }
  1605. /* Temperature channels are not forcibly enabled, as they can be
  1606. * set to two different sensor types and we can't guess which one
  1607. * is correct for a given system. These channels can be enabled at
  1608. * run-time through the temp{1-3}_type sysfs accessors if needed. */
  1609. /* Check if voltage monitors are reset manually or by some reason */
  1610. tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
  1611. if ((tmp & 0xff) == 0) {
  1612. /* Enable all voltage monitors */
  1613. it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
  1614. }
  1615. /* Check if tachometers are reset manually or by some reason */
  1616. mask = 0x70 & ~(sio_data->skip_fan << 4);
  1617. data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
  1618. if ((data->fan_main_ctrl & mask) == 0) {
  1619. /* Enable all fan tachometers */
  1620. data->fan_main_ctrl |= mask;
  1621. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  1622. data->fan_main_ctrl);
  1623. }
  1624. data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
  1625. /* Set tachometers to 16-bit mode if needed */
  1626. if (has_16bit_fans(data)) {
  1627. tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
  1628. if (~tmp & 0x07 & data->has_fan) {
  1629. dev_dbg(&pdev->dev,
  1630. "Setting fan1-3 to 16-bit mode\n");
  1631. it87_write_value(data, IT87_REG_FAN_16BIT,
  1632. tmp | 0x07);
  1633. }
  1634. /* IT8705F only supports three fans. */
  1635. if (data->type != it87) {
  1636. if (tmp & (1 << 4))
  1637. data->has_fan |= (1 << 3); /* fan4 enabled */
  1638. if (tmp & (1 << 5))
  1639. data->has_fan |= (1 << 4); /* fan5 enabled */
  1640. }
  1641. }
  1642. /* Fan input pins may be used for alternative functions */
  1643. data->has_fan &= ~sio_data->skip_fan;
  1644. /* Start monitoring */
  1645. it87_write_value(data, IT87_REG_CONFIG,
  1646. (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
  1647. | (update_vbat ? 0x41 : 0x01));
  1648. }
  1649. static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
  1650. {
  1651. data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
  1652. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  1653. data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
  1654. else /* Manual mode */
  1655. data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
  1656. if (has_old_autopwm(data)) {
  1657. int i;
  1658. for (i = 0; i < 5 ; i++)
  1659. data->auto_temp[nr][i] = it87_read_value(data,
  1660. IT87_REG_AUTO_TEMP(nr, i));
  1661. for (i = 0; i < 3 ; i++)
  1662. data->auto_pwm[nr][i] = it87_read_value(data,
  1663. IT87_REG_AUTO_PWM(nr, i));
  1664. }
  1665. }
  1666. static struct it87_data *it87_update_device(struct device *dev)
  1667. {
  1668. struct it87_data *data = dev_get_drvdata(dev);
  1669. int i;
  1670. mutex_lock(&data->update_lock);
  1671. if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
  1672. || !data->valid) {
  1673. if (update_vbat) {
  1674. /* Cleared after each update, so reenable. Value
  1675. returned by this read will be previous value */
  1676. it87_write_value(data, IT87_REG_CONFIG,
  1677. it87_read_value(data, IT87_REG_CONFIG) | 0x40);
  1678. }
  1679. for (i = 0; i <= 7; i++) {
  1680. data->in[i] =
  1681. it87_read_value(data, IT87_REG_VIN(i));
  1682. data->in_min[i] =
  1683. it87_read_value(data, IT87_REG_VIN_MIN(i));
  1684. data->in_max[i] =
  1685. it87_read_value(data, IT87_REG_VIN_MAX(i));
  1686. }
  1687. /* in8 (battery) has no limit registers */
  1688. data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
  1689. for (i = 0; i < 5; i++) {
  1690. /* Skip disabled fans */
  1691. if (!(data->has_fan & (1 << i)))
  1692. continue;
  1693. data->fan_min[i] =
  1694. it87_read_value(data, IT87_REG_FAN_MIN[i]);
  1695. data->fan[i] = it87_read_value(data,
  1696. IT87_REG_FAN[i]);
  1697. /* Add high byte if in 16-bit mode */
  1698. if (has_16bit_fans(data)) {
  1699. data->fan[i] |= it87_read_value(data,
  1700. IT87_REG_FANX[i]) << 8;
  1701. data->fan_min[i] |= it87_read_value(data,
  1702. IT87_REG_FANX_MIN[i]) << 8;
  1703. }
  1704. }
  1705. for (i = 0; i < 3; i++) {
  1706. data->temp[i] =
  1707. it87_read_value(data, IT87_REG_TEMP(i));
  1708. data->temp_high[i] =
  1709. it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  1710. data->temp_low[i] =
  1711. it87_read_value(data, IT87_REG_TEMP_LOW(i));
  1712. }
  1713. /* Newer chips don't have clock dividers */
  1714. if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
  1715. i = it87_read_value(data, IT87_REG_FAN_DIV);
  1716. data->fan_div[0] = i & 0x07;
  1717. data->fan_div[1] = (i >> 3) & 0x07;
  1718. data->fan_div[2] = (i & 0x40) ? 3 : 1;
  1719. }
  1720. data->alarms =
  1721. it87_read_value(data, IT87_REG_ALARM1) |
  1722. (it87_read_value(data, IT87_REG_ALARM2) << 8) |
  1723. (it87_read_value(data, IT87_REG_ALARM3) << 16);
  1724. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  1725. data->fan_main_ctrl = it87_read_value(data,
  1726. IT87_REG_FAN_MAIN_CTRL);
  1727. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
  1728. for (i = 0; i < 3; i++)
  1729. it87_update_pwm_ctrl(data, i);
  1730. data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  1731. /* The 8705 does not have VID capability.
  1732. The 8718 and the 8720 don't use IT87_REG_VID for the
  1733. same purpose. */
  1734. if (data->type == it8712 || data->type == it8716) {
  1735. data->vid = it87_read_value(data, IT87_REG_VID);
  1736. /* The older IT8712F revisions had only 5 VID pins,
  1737. but we assume it is always safe to read 6 bits. */
  1738. data->vid &= 0x3f;
  1739. }
  1740. data->last_updated = jiffies;
  1741. data->valid = 1;
  1742. }
  1743. mutex_unlock(&data->update_lock);
  1744. return data;
  1745. }
  1746. static int __init it87_device_add(unsigned short address,
  1747. const struct it87_sio_data *sio_data)
  1748. {
  1749. struct resource res = {
  1750. .start = address + IT87_EC_OFFSET,
  1751. .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
  1752. .name = DRVNAME,
  1753. .flags = IORESOURCE_IO,
  1754. };
  1755. int err;
  1756. err = acpi_check_resource_conflict(&res);
  1757. if (err)
  1758. goto exit;
  1759. pdev = platform_device_alloc(DRVNAME, address);
  1760. if (!pdev) {
  1761. err = -ENOMEM;
  1762. printk(KERN_ERR DRVNAME ": Device allocation failed\n");
  1763. goto exit;
  1764. }
  1765. err = platform_device_add_resources(pdev, &res, 1);
  1766. if (err) {
  1767. printk(KERN_ERR DRVNAME ": Device resource addition failed "
  1768. "(%d)\n", err);
  1769. goto exit_device_put;
  1770. }
  1771. err = platform_device_add_data(pdev, sio_data,
  1772. sizeof(struct it87_sio_data));
  1773. if (err) {
  1774. printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
  1775. goto exit_device_put;
  1776. }
  1777. err = platform_device_add(pdev);
  1778. if (err) {
  1779. printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
  1780. err);
  1781. goto exit_device_put;
  1782. }
  1783. return 0;
  1784. exit_device_put:
  1785. platform_device_put(pdev);
  1786. exit:
  1787. return err;
  1788. }
  1789. static int __init sm_it87_init(void)
  1790. {
  1791. int err;
  1792. unsigned short isa_address = 0;
  1793. struct it87_sio_data sio_data;
  1794. memset(&sio_data, 0, sizeof(struct it87_sio_data));
  1795. err = it87_find(&isa_address, &sio_data);
  1796. if (err)
  1797. return err;
  1798. err = platform_driver_register(&it87_driver);
  1799. if (err)
  1800. return err;
  1801. err = it87_device_add(isa_address, &sio_data);
  1802. if (err) {
  1803. platform_driver_unregister(&it87_driver);
  1804. return err;
  1805. }
  1806. return 0;
  1807. }
  1808. static void __exit sm_it87_exit(void)
  1809. {
  1810. platform_device_unregister(pdev);
  1811. platform_driver_unregister(&it87_driver);
  1812. }
  1813. MODULE_AUTHOR("Chris Gauthron, "
  1814. "Jean Delvare <khali@linux-fr.org>");
  1815. MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
  1816. module_param(update_vbat, bool, 0);
  1817. MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
  1818. module_param(fix_pwm_polarity, bool, 0);
  1819. MODULE_PARM_DESC(fix_pwm_polarity,
  1820. "Force PWM polarity to active high (DANGEROUS)");
  1821. MODULE_LICENSE("GPL");
  1822. module_init(sm_it87_init);
  1823. module_exit(sm_it87_exit);