it87.c 62 KB

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