it87.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561
  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. * IT8721F Super I/O chip w/LPC interface
  19. * IT8726F Super I/O chip w/LPC interface
  20. * IT8728F Super I/O chip w/LPC interface
  21. * IT8758E Super I/O chip w/LPC interface
  22. * IT8782F Super I/O chip w/LPC interface
  23. * IT8783E/F Super I/O chip w/LPC interface
  24. * Sis950 A clone of the IT8705F
  25. *
  26. * Copyright (C) 2001 Chris Gauthron
  27. * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
  28. *
  29. * This program is free software; you can redistribute it and/or modify
  30. * it under the terms of the GNU General Public License as published by
  31. * the Free Software Foundation; either version 2 of the License, or
  32. * (at your option) any later version.
  33. *
  34. * This program is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. * GNU General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU General Public License
  40. * along with this program; if not, write to the Free Software
  41. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42. */
  43. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  44. #include <linux/module.h>
  45. #include <linux/init.h>
  46. #include <linux/slab.h>
  47. #include <linux/jiffies.h>
  48. #include <linux/platform_device.h>
  49. #include <linux/hwmon.h>
  50. #include <linux/hwmon-sysfs.h>
  51. #include <linux/hwmon-vid.h>
  52. #include <linux/err.h>
  53. #include <linux/mutex.h>
  54. #include <linux/sysfs.h>
  55. #include <linux/string.h>
  56. #include <linux/dmi.h>
  57. #include <linux/acpi.h>
  58. #include <linux/io.h>
  59. #define DRVNAME "it87"
  60. enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8782,
  61. it8783 };
  62. static unsigned short force_id;
  63. module_param(force_id, ushort, 0);
  64. MODULE_PARM_DESC(force_id, "Override the detected device ID");
  65. static struct platform_device *pdev;
  66. #define REG 0x2e /* The register to read/write */
  67. #define DEV 0x07 /* Register: Logical device select */
  68. #define VAL 0x2f /* The value to read/write */
  69. #define PME 0x04 /* The device with the fan registers in it */
  70. /* The device with the IT8718F/IT8720F VID value in it */
  71. #define GPIO 0x07
  72. #define DEVID 0x20 /* Register: Device ID */
  73. #define DEVREV 0x22 /* Register: Device Revision */
  74. static inline int superio_inb(int reg)
  75. {
  76. outb(reg, REG);
  77. return inb(VAL);
  78. }
  79. static inline void superio_outb(int reg, int val)
  80. {
  81. outb(reg, REG);
  82. outb(val, VAL);
  83. }
  84. static int superio_inw(int reg)
  85. {
  86. int val;
  87. outb(reg++, REG);
  88. val = inb(VAL) << 8;
  89. outb(reg, REG);
  90. val |= inb(VAL);
  91. return val;
  92. }
  93. static inline void superio_select(int ldn)
  94. {
  95. outb(DEV, REG);
  96. outb(ldn, VAL);
  97. }
  98. static inline int superio_enter(void)
  99. {
  100. /*
  101. * Try to reserve REG and REG + 1 for exclusive access.
  102. */
  103. if (!request_muxed_region(REG, 2, DRVNAME))
  104. return -EBUSY;
  105. outb(0x87, REG);
  106. outb(0x01, REG);
  107. outb(0x55, REG);
  108. outb(0x55, REG);
  109. return 0;
  110. }
  111. static inline void superio_exit(void)
  112. {
  113. outb(0x02, REG);
  114. outb(0x02, VAL);
  115. release_region(REG, 2);
  116. }
  117. /* Logical device 4 registers */
  118. #define IT8712F_DEVID 0x8712
  119. #define IT8705F_DEVID 0x8705
  120. #define IT8716F_DEVID 0x8716
  121. #define IT8718F_DEVID 0x8718
  122. #define IT8720F_DEVID 0x8720
  123. #define IT8721F_DEVID 0x8721
  124. #define IT8726F_DEVID 0x8726
  125. #define IT8728F_DEVID 0x8728
  126. #define IT8782F_DEVID 0x8782
  127. #define IT8783E_DEVID 0x8783
  128. #define IT87_ACT_REG 0x30
  129. #define IT87_BASE_REG 0x60
  130. /* Logical device 7 registers (IT8712F and later) */
  131. #define IT87_SIO_GPIO1_REG 0x25
  132. #define IT87_SIO_GPIO3_REG 0x27
  133. #define IT87_SIO_GPIO5_REG 0x29
  134. #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
  135. #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
  136. #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
  137. #define IT87_SIO_VID_REG 0xfc /* VID value */
  138. #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
  139. /* Update battery voltage after every reading if true */
  140. static bool update_vbat;
  141. /* Not all BIOSes properly configure the PWM registers */
  142. static bool fix_pwm_polarity;
  143. /* Many IT87 constants specified below */
  144. /* Length of ISA address segment */
  145. #define IT87_EXTENT 8
  146. /* Length of ISA address segment for Environmental Controller */
  147. #define IT87_EC_EXTENT 2
  148. /* Offset of EC registers from ISA base address */
  149. #define IT87_EC_OFFSET 5
  150. /* Where are the ISA address/data registers relative to the EC base address */
  151. #define IT87_ADDR_REG_OFFSET 0
  152. #define IT87_DATA_REG_OFFSET 1
  153. /*----- The IT87 registers -----*/
  154. #define IT87_REG_CONFIG 0x00
  155. #define IT87_REG_ALARM1 0x01
  156. #define IT87_REG_ALARM2 0x02
  157. #define IT87_REG_ALARM3 0x03
  158. /*
  159. * The IT8718F and IT8720F have the VID value in a different register, in
  160. * Super-I/O configuration space.
  161. */
  162. #define IT87_REG_VID 0x0a
  163. /*
  164. * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
  165. * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
  166. * mode.
  167. */
  168. #define IT87_REG_FAN_DIV 0x0b
  169. #define IT87_REG_FAN_16BIT 0x0c
  170. /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
  171. static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
  172. static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
  173. static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
  174. static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
  175. static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
  176. #define IT87_REG_FAN_MAIN_CTRL 0x13
  177. #define IT87_REG_FAN_CTL 0x14
  178. #define IT87_REG_PWM(nr) (0x15 + (nr))
  179. #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
  180. #define IT87_REG_VIN(nr) (0x20 + (nr))
  181. #define IT87_REG_TEMP(nr) (0x29 + (nr))
  182. #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
  183. #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
  184. #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
  185. #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
  186. #define IT87_REG_VIN_ENABLE 0x50
  187. #define IT87_REG_TEMP_ENABLE 0x51
  188. #define IT87_REG_TEMP_EXTRA 0x55
  189. #define IT87_REG_BEEP_ENABLE 0x5c
  190. #define IT87_REG_CHIPID 0x58
  191. #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
  192. #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
  193. struct it87_devices {
  194. const char *name;
  195. u16 features;
  196. };
  197. #define FEAT_12MV_ADC (1 << 0)
  198. #define FEAT_NEWER_AUTOPWM (1 << 1)
  199. #define FEAT_OLD_AUTOPWM (1 << 2)
  200. #define FEAT_16BIT_FANS (1 << 3)
  201. #define FEAT_TEMP_OFFSET (1 << 4)
  202. static const struct it87_devices it87_devices[] = {
  203. [it87] = {
  204. .name = "it87",
  205. .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
  206. },
  207. [it8712] = {
  208. .name = "it8712",
  209. .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
  210. },
  211. [it8716] = {
  212. .name = "it8716",
  213. .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
  214. },
  215. [it8718] = {
  216. .name = "it8718",
  217. .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
  218. },
  219. [it8720] = {
  220. .name = "it8720",
  221. .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
  222. },
  223. [it8721] = {
  224. .name = "it8721",
  225. .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
  226. | FEAT_TEMP_OFFSET,
  227. },
  228. [it8728] = {
  229. .name = "it8728",
  230. .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
  231. | FEAT_TEMP_OFFSET,
  232. },
  233. [it8782] = {
  234. .name = "it8782",
  235. .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
  236. },
  237. [it8783] = {
  238. .name = "it8783",
  239. .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
  240. },
  241. };
  242. #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
  243. #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
  244. #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
  245. #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
  246. #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
  247. struct it87_sio_data {
  248. enum chips type;
  249. /* Values read from Super-I/O config space */
  250. u8 revision;
  251. u8 vid_value;
  252. u8 beep_pin;
  253. u8 internal; /* Internal sensors can be labeled */
  254. /* Features skipped based on config or DMI */
  255. u16 skip_in;
  256. u8 skip_vid;
  257. u8 skip_fan;
  258. u8 skip_pwm;
  259. u8 skip_temp;
  260. };
  261. /*
  262. * For each registered chip, we need to keep some data in memory.
  263. * The structure is dynamically allocated.
  264. */
  265. struct it87_data {
  266. struct device *hwmon_dev;
  267. enum chips type;
  268. u16 features;
  269. unsigned short addr;
  270. const char *name;
  271. struct mutex update_lock;
  272. char valid; /* !=0 if following fields are valid */
  273. unsigned long last_updated; /* In jiffies */
  274. u16 in_scaled; /* Internal voltage sensors are scaled */
  275. u8 in[9][3]; /* [nr][0]=in, [1]=min, [2]=max */
  276. u8 has_fan; /* Bitfield, fans enabled */
  277. u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
  278. u8 has_temp; /* Bitfield, temp sensors enabled */
  279. s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
  280. u8 sensor; /* Register value */
  281. u8 fan_div[3]; /* Register encoding, shifted right */
  282. u8 vid; /* Register encoding, combined */
  283. u8 vrm;
  284. u32 alarms; /* Register encoding, combined */
  285. u8 beeps; /* Register encoding */
  286. u8 fan_main_ctrl; /* Register value */
  287. u8 fan_ctl; /* Register value */
  288. /*
  289. * The following 3 arrays correspond to the same registers up to
  290. * the IT8720F. The meaning of bits 6-0 depends on the value of bit
  291. * 7, and we want to preserve settings on mode changes, so we have
  292. * to track all values separately.
  293. * Starting with the IT8721F, the manual PWM duty cycles are stored
  294. * in separate registers (8-bit values), so the separate tracking
  295. * is no longer needed, but it is still done to keep the driver
  296. * simple.
  297. */
  298. u8 pwm_ctrl[3]; /* Register value */
  299. u8 pwm_duty[3]; /* Manual PWM value set by user */
  300. u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
  301. /* Automatic fan speed control registers */
  302. u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
  303. s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
  304. };
  305. static int adc_lsb(const struct it87_data *data, int nr)
  306. {
  307. int lsb = has_12mv_adc(data) ? 12 : 16;
  308. if (data->in_scaled & (1 << nr))
  309. lsb <<= 1;
  310. return lsb;
  311. }
  312. static u8 in_to_reg(const struct it87_data *data, int nr, long val)
  313. {
  314. val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
  315. return SENSORS_LIMIT(val, 0, 255);
  316. }
  317. static int in_from_reg(const struct it87_data *data, int nr, int val)
  318. {
  319. return val * adc_lsb(data, nr);
  320. }
  321. static inline u8 FAN_TO_REG(long rpm, int div)
  322. {
  323. if (rpm == 0)
  324. return 255;
  325. rpm = SENSORS_LIMIT(rpm, 1, 1000000);
  326. return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
  327. 254);
  328. }
  329. static inline u16 FAN16_TO_REG(long rpm)
  330. {
  331. if (rpm == 0)
  332. return 0xffff;
  333. return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
  334. }
  335. #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
  336. 1350000 / ((val) * (div)))
  337. /* The divider is fixed to 2 in 16-bit mode */
  338. #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
  339. 1350000 / ((val) * 2))
  340. #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
  341. ((val) + 500) / 1000), -128, 127))
  342. #define TEMP_FROM_REG(val) ((val) * 1000)
  343. static u8 pwm_to_reg(const struct it87_data *data, long val)
  344. {
  345. if (has_newer_autopwm(data))
  346. return val;
  347. else
  348. return val >> 1;
  349. }
  350. static int pwm_from_reg(const struct it87_data *data, u8 reg)
  351. {
  352. if (has_newer_autopwm(data))
  353. return reg;
  354. else
  355. return (reg & 0x7f) << 1;
  356. }
  357. static int DIV_TO_REG(int val)
  358. {
  359. int answer = 0;
  360. while (answer < 7 && (val >>= 1))
  361. answer++;
  362. return answer;
  363. }
  364. #define DIV_FROM_REG(val) (1 << (val))
  365. static const unsigned int pwm_freq[8] = {
  366. 48000000 / 128,
  367. 24000000 / 128,
  368. 12000000 / 128,
  369. 8000000 / 128,
  370. 6000000 / 128,
  371. 3000000 / 128,
  372. 1500000 / 128,
  373. 750000 / 128,
  374. };
  375. static int it87_probe(struct platform_device *pdev);
  376. static int it87_remove(struct platform_device *pdev);
  377. static int it87_read_value(struct it87_data *data, u8 reg);
  378. static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
  379. static struct it87_data *it87_update_device(struct device *dev);
  380. static int it87_check_pwm(struct device *dev);
  381. static void it87_init_device(struct platform_device *pdev);
  382. static struct platform_driver it87_driver = {
  383. .driver = {
  384. .owner = THIS_MODULE,
  385. .name = DRVNAME,
  386. },
  387. .probe = it87_probe,
  388. .remove = it87_remove,
  389. };
  390. static ssize_t show_in(struct device *dev, struct device_attribute *attr,
  391. char *buf)
  392. {
  393. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  394. int nr = sattr->nr;
  395. int index = sattr->index;
  396. struct it87_data *data = it87_update_device(dev);
  397. return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
  398. }
  399. static ssize_t set_in(struct device *dev, struct device_attribute *attr,
  400. const char *buf, size_t count)
  401. {
  402. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  403. int nr = sattr->nr;
  404. int index = sattr->index;
  405. struct it87_data *data = dev_get_drvdata(dev);
  406. unsigned long val;
  407. if (kstrtoul(buf, 10, &val) < 0)
  408. return -EINVAL;
  409. mutex_lock(&data->update_lock);
  410. data->in[nr][index] = in_to_reg(data, nr, val);
  411. it87_write_value(data,
  412. index == 1 ? IT87_REG_VIN_MIN(nr)
  413. : IT87_REG_VIN_MAX(nr),
  414. data->in[nr][index]);
  415. mutex_unlock(&data->update_lock);
  416. return count;
  417. }
  418. static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
  419. static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
  420. 0, 1);
  421. static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
  422. 0, 2);
  423. static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
  424. static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
  425. 1, 1);
  426. static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
  427. 1, 2);
  428. static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
  429. static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
  430. 2, 1);
  431. static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
  432. 2, 2);
  433. static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
  434. static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
  435. 3, 1);
  436. static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
  437. 3, 2);
  438. static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
  439. static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
  440. 4, 1);
  441. static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
  442. 4, 2);
  443. static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
  444. static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
  445. 5, 1);
  446. static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
  447. 5, 2);
  448. static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
  449. static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
  450. 6, 1);
  451. static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
  452. 6, 2);
  453. static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
  454. static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
  455. 7, 1);
  456. static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
  457. 7, 2);
  458. static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
  459. /* 3 temperatures */
  460. static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
  461. char *buf)
  462. {
  463. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  464. int nr = sattr->nr;
  465. int index = sattr->index;
  466. struct it87_data *data = it87_update_device(dev);
  467. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
  468. }
  469. static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
  470. const char *buf, size_t count)
  471. {
  472. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  473. int nr = sattr->nr;
  474. int index = sattr->index;
  475. struct it87_data *data = dev_get_drvdata(dev);
  476. long val;
  477. u8 reg, regval;
  478. if (kstrtol(buf, 10, &val) < 0)
  479. return -EINVAL;
  480. mutex_lock(&data->update_lock);
  481. switch (index) {
  482. default:
  483. case 1:
  484. reg = IT87_REG_TEMP_LOW(nr);
  485. break;
  486. case 2:
  487. reg = IT87_REG_TEMP_HIGH(nr);
  488. break;
  489. case 3:
  490. regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  491. if (!(regval & 0x80)) {
  492. regval |= 0x80;
  493. it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
  494. }
  495. data->valid = 0;
  496. reg = IT87_REG_TEMP_OFFSET[nr];
  497. break;
  498. }
  499. data->temp[nr][index] = TEMP_TO_REG(val);
  500. it87_write_value(data, reg, data->temp[nr][index]);
  501. mutex_unlock(&data->update_lock);
  502. return count;
  503. }
  504. static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
  505. static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  506. 0, 1);
  507. static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  508. 0, 2);
  509. static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
  510. set_temp, 0, 3);
  511. static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
  512. static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  513. 1, 1);
  514. static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  515. 1, 2);
  516. static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
  517. set_temp, 1, 3);
  518. static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
  519. static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  520. 2, 1);
  521. static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  522. 2, 2);
  523. static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
  524. set_temp, 2, 3);
  525. static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
  526. 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. u8 reg = data->sensor; /* In case value is updated while used */
  532. if (reg & (1 << nr))
  533. return sprintf(buf, "3\n"); /* thermal diode */
  534. if (reg & (8 << nr))
  535. return sprintf(buf, "4\n"); /* thermistor */
  536. return sprintf(buf, "0\n"); /* disabled */
  537. }
  538. static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
  539. const char *buf, size_t count)
  540. {
  541. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  542. int nr = sensor_attr->index;
  543. struct it87_data *data = dev_get_drvdata(dev);
  544. long val;
  545. u8 reg;
  546. if (kstrtol(buf, 10, &val) < 0)
  547. return -EINVAL;
  548. reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  549. reg &= ~(1 << nr);
  550. reg &= ~(8 << nr);
  551. if (val == 2) { /* backwards compatibility */
  552. dev_warn(dev,
  553. "Sensor type 2 is deprecated, please use 4 instead\n");
  554. val = 4;
  555. }
  556. /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
  557. if (val == 3)
  558. reg |= 1 << nr;
  559. else if (val == 4)
  560. reg |= 8 << nr;
  561. else if (val != 0)
  562. return -EINVAL;
  563. mutex_lock(&data->update_lock);
  564. data->sensor = reg;
  565. it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
  566. data->valid = 0; /* Force cache refresh */
  567. mutex_unlock(&data->update_lock);
  568. return count;
  569. }
  570. static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
  571. set_temp_type, 0);
  572. static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
  573. set_temp_type, 1);
  574. static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
  575. set_temp_type, 2);
  576. /* 3 Fans */
  577. static int pwm_mode(const struct it87_data *data, int nr)
  578. {
  579. int ctrl = data->fan_main_ctrl & (1 << nr);
  580. if (ctrl == 0) /* Full speed */
  581. return 0;
  582. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  583. return 2;
  584. else /* Manual mode */
  585. return 1;
  586. }
  587. static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
  588. char *buf)
  589. {
  590. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  591. int nr = sattr->nr;
  592. int index = sattr->index;
  593. int speed;
  594. struct it87_data *data = it87_update_device(dev);
  595. speed = has_16bit_fans(data) ?
  596. FAN16_FROM_REG(data->fan[nr][index]) :
  597. FAN_FROM_REG(data->fan[nr][index],
  598. DIV_FROM_REG(data->fan_div[nr]));
  599. return sprintf(buf, "%d\n", speed);
  600. }
  601. static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
  602. char *buf)
  603. {
  604. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  605. int nr = sensor_attr->index;
  606. struct it87_data *data = it87_update_device(dev);
  607. return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
  608. }
  609. static ssize_t show_pwm_enable(struct device *dev,
  610. struct device_attribute *attr, char *buf)
  611. {
  612. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  613. int nr = sensor_attr->index;
  614. struct it87_data *data = it87_update_device(dev);
  615. return sprintf(buf, "%d\n", pwm_mode(data, nr));
  616. }
  617. static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
  618. char *buf)
  619. {
  620. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  621. int nr = sensor_attr->index;
  622. struct it87_data *data = it87_update_device(dev);
  623. return sprintf(buf, "%d\n",
  624. pwm_from_reg(data, data->pwm_duty[nr]));
  625. }
  626. static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
  627. char *buf)
  628. {
  629. struct it87_data *data = it87_update_device(dev);
  630. int index = (data->fan_ctl >> 4) & 0x07;
  631. return sprintf(buf, "%u\n", pwm_freq[index]);
  632. }
  633. static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
  634. const char *buf, size_t count)
  635. {
  636. struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
  637. int nr = sattr->nr;
  638. int index = sattr->index;
  639. struct it87_data *data = dev_get_drvdata(dev);
  640. long val;
  641. u8 reg;
  642. if (kstrtol(buf, 10, &val) < 0)
  643. return -EINVAL;
  644. mutex_lock(&data->update_lock);
  645. if (has_16bit_fans(data)) {
  646. data->fan[nr][index] = FAN16_TO_REG(val);
  647. it87_write_value(data, IT87_REG_FAN_MIN[nr],
  648. data->fan[nr][index] & 0xff);
  649. it87_write_value(data, IT87_REG_FANX_MIN[nr],
  650. data->fan[nr][index] >> 8);
  651. } else {
  652. reg = it87_read_value(data, IT87_REG_FAN_DIV);
  653. switch (nr) {
  654. case 0:
  655. data->fan_div[nr] = reg & 0x07;
  656. break;
  657. case 1:
  658. data->fan_div[nr] = (reg >> 3) & 0x07;
  659. break;
  660. case 2:
  661. data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
  662. break;
  663. }
  664. data->fan[nr][index] =
  665. FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
  666. it87_write_value(data, IT87_REG_FAN_MIN[nr],
  667. data->fan[nr][index]);
  668. }
  669. mutex_unlock(&data->update_lock);
  670. return count;
  671. }
  672. static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
  673. const char *buf, size_t count)
  674. {
  675. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  676. int nr = sensor_attr->index;
  677. struct it87_data *data = dev_get_drvdata(dev);
  678. unsigned long val;
  679. int min;
  680. u8 old;
  681. if (kstrtoul(buf, 10, &val) < 0)
  682. return -EINVAL;
  683. mutex_lock(&data->update_lock);
  684. old = it87_read_value(data, IT87_REG_FAN_DIV);
  685. /* Save fan min limit */
  686. min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
  687. switch (nr) {
  688. case 0:
  689. case 1:
  690. data->fan_div[nr] = DIV_TO_REG(val);
  691. break;
  692. case 2:
  693. if (val < 8)
  694. data->fan_div[nr] = 1;
  695. else
  696. data->fan_div[nr] = 3;
  697. }
  698. val = old & 0x80;
  699. val |= (data->fan_div[0] & 0x07);
  700. val |= (data->fan_div[1] & 0x07) << 3;
  701. if (data->fan_div[2] == 3)
  702. val |= 0x1 << 6;
  703. it87_write_value(data, IT87_REG_FAN_DIV, val);
  704. /* Restore fan min limit */
  705. data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
  706. it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
  707. mutex_unlock(&data->update_lock);
  708. return count;
  709. }
  710. /* Returns 0 if OK, -EINVAL otherwise */
  711. static int check_trip_points(struct device *dev, int nr)
  712. {
  713. const struct it87_data *data = dev_get_drvdata(dev);
  714. int i, err = 0;
  715. if (has_old_autopwm(data)) {
  716. for (i = 0; i < 3; i++) {
  717. if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
  718. err = -EINVAL;
  719. }
  720. for (i = 0; i < 2; i++) {
  721. if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
  722. err = -EINVAL;
  723. }
  724. }
  725. if (err) {
  726. dev_err(dev,
  727. "Inconsistent trip points, not switching to automatic mode\n");
  728. dev_err(dev, "Adjust the trip points and try again\n");
  729. }
  730. return err;
  731. }
  732. static ssize_t set_pwm_enable(struct device *dev,
  733. struct device_attribute *attr, const char *buf, size_t count)
  734. {
  735. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  736. int nr = sensor_attr->index;
  737. struct it87_data *data = dev_get_drvdata(dev);
  738. long val;
  739. if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
  740. return -EINVAL;
  741. /* Check trip points before switching to automatic mode */
  742. if (val == 2) {
  743. if (check_trip_points(dev, nr) < 0)
  744. return -EINVAL;
  745. }
  746. mutex_lock(&data->update_lock);
  747. if (val == 0) {
  748. int tmp;
  749. /* make sure the fan is on when in on/off mode */
  750. tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  751. it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
  752. /* set on/off mode */
  753. data->fan_main_ctrl &= ~(1 << nr);
  754. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  755. data->fan_main_ctrl);
  756. } else {
  757. if (val == 1) /* Manual mode */
  758. data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
  759. data->pwm_temp_map[nr] :
  760. data->pwm_duty[nr];
  761. else /* Automatic mode */
  762. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  763. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  764. /* set SmartGuardian mode */
  765. data->fan_main_ctrl |= (1 << nr);
  766. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  767. data->fan_main_ctrl);
  768. }
  769. mutex_unlock(&data->update_lock);
  770. return count;
  771. }
  772. static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
  773. const char *buf, size_t count)
  774. {
  775. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  776. int nr = sensor_attr->index;
  777. struct it87_data *data = dev_get_drvdata(dev);
  778. long val;
  779. if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  780. return -EINVAL;
  781. mutex_lock(&data->update_lock);
  782. if (has_newer_autopwm(data)) {
  783. /*
  784. * If we are in automatic mode, the PWM duty cycle register
  785. * is read-only so we can't write the value.
  786. */
  787. if (data->pwm_ctrl[nr] & 0x80) {
  788. mutex_unlock(&data->update_lock);
  789. return -EBUSY;
  790. }
  791. data->pwm_duty[nr] = pwm_to_reg(data, val);
  792. it87_write_value(data, IT87_REG_PWM_DUTY(nr),
  793. data->pwm_duty[nr]);
  794. } else {
  795. data->pwm_duty[nr] = pwm_to_reg(data, val);
  796. /*
  797. * If we are in manual mode, write the duty cycle immediately;
  798. * otherwise, just store it for later use.
  799. */
  800. if (!(data->pwm_ctrl[nr] & 0x80)) {
  801. data->pwm_ctrl[nr] = data->pwm_duty[nr];
  802. it87_write_value(data, IT87_REG_PWM(nr),
  803. data->pwm_ctrl[nr]);
  804. }
  805. }
  806. mutex_unlock(&data->update_lock);
  807. return count;
  808. }
  809. static ssize_t set_pwm_freq(struct device *dev,
  810. struct device_attribute *attr, const char *buf, size_t count)
  811. {
  812. struct it87_data *data = dev_get_drvdata(dev);
  813. unsigned long val;
  814. int i;
  815. if (kstrtoul(buf, 10, &val) < 0)
  816. return -EINVAL;
  817. /* Search for the nearest available frequency */
  818. for (i = 0; i < 7; i++) {
  819. if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
  820. break;
  821. }
  822. mutex_lock(&data->update_lock);
  823. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
  824. data->fan_ctl |= i << 4;
  825. it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
  826. mutex_unlock(&data->update_lock);
  827. return count;
  828. }
  829. static ssize_t show_pwm_temp_map(struct device *dev,
  830. struct device_attribute *attr, char *buf)
  831. {
  832. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  833. int nr = sensor_attr->index;
  834. struct it87_data *data = it87_update_device(dev);
  835. int map;
  836. if (data->pwm_temp_map[nr] < 3)
  837. map = 1 << data->pwm_temp_map[nr];
  838. else
  839. map = 0; /* Should never happen */
  840. return sprintf(buf, "%d\n", map);
  841. }
  842. static ssize_t set_pwm_temp_map(struct device *dev,
  843. struct device_attribute *attr, const char *buf, size_t count)
  844. {
  845. struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
  846. int nr = sensor_attr->index;
  847. struct it87_data *data = dev_get_drvdata(dev);
  848. long val;
  849. u8 reg;
  850. /*
  851. * This check can go away if we ever support automatic fan speed
  852. * control on newer chips.
  853. */
  854. if (!has_old_autopwm(data)) {
  855. dev_notice(dev, "Mapping change disabled for safety reasons\n");
  856. return -EINVAL;
  857. }
  858. if (kstrtol(buf, 10, &val) < 0)
  859. return -EINVAL;
  860. switch (val) {
  861. case (1 << 0):
  862. reg = 0x00;
  863. break;
  864. case (1 << 1):
  865. reg = 0x01;
  866. break;
  867. case (1 << 2):
  868. reg = 0x02;
  869. break;
  870. default:
  871. return -EINVAL;
  872. }
  873. mutex_lock(&data->update_lock);
  874. data->pwm_temp_map[nr] = reg;
  875. /*
  876. * If we are in automatic mode, write the temp mapping immediately;
  877. * otherwise, just store it for later use.
  878. */
  879. if (data->pwm_ctrl[nr] & 0x80) {
  880. data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
  881. it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
  882. }
  883. mutex_unlock(&data->update_lock);
  884. return count;
  885. }
  886. static ssize_t show_auto_pwm(struct device *dev,
  887. struct device_attribute *attr, char *buf)
  888. {
  889. struct it87_data *data = it87_update_device(dev);
  890. struct sensor_device_attribute_2 *sensor_attr =
  891. to_sensor_dev_attr_2(attr);
  892. int nr = sensor_attr->nr;
  893. int point = sensor_attr->index;
  894. return sprintf(buf, "%d\n",
  895. pwm_from_reg(data, data->auto_pwm[nr][point]));
  896. }
  897. static ssize_t set_auto_pwm(struct device *dev,
  898. struct device_attribute *attr, const char *buf, size_t count)
  899. {
  900. struct it87_data *data = dev_get_drvdata(dev);
  901. struct sensor_device_attribute_2 *sensor_attr =
  902. to_sensor_dev_attr_2(attr);
  903. int nr = sensor_attr->nr;
  904. int point = sensor_attr->index;
  905. long val;
  906. if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
  907. return -EINVAL;
  908. mutex_lock(&data->update_lock);
  909. data->auto_pwm[nr][point] = pwm_to_reg(data, val);
  910. it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
  911. data->auto_pwm[nr][point]);
  912. mutex_unlock(&data->update_lock);
  913. return count;
  914. }
  915. static ssize_t show_auto_temp(struct device *dev,
  916. struct device_attribute *attr, char *buf)
  917. {
  918. struct it87_data *data = it87_update_device(dev);
  919. struct sensor_device_attribute_2 *sensor_attr =
  920. to_sensor_dev_attr_2(attr);
  921. int nr = sensor_attr->nr;
  922. int point = sensor_attr->index;
  923. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
  924. }
  925. static ssize_t set_auto_temp(struct device *dev,
  926. struct device_attribute *attr, const char *buf, size_t count)
  927. {
  928. struct it87_data *data = dev_get_drvdata(dev);
  929. struct sensor_device_attribute_2 *sensor_attr =
  930. to_sensor_dev_attr_2(attr);
  931. int nr = sensor_attr->nr;
  932. int point = sensor_attr->index;
  933. long val;
  934. if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
  935. return -EINVAL;
  936. mutex_lock(&data->update_lock);
  937. data->auto_temp[nr][point] = TEMP_TO_REG(val);
  938. it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
  939. data->auto_temp[nr][point]);
  940. mutex_unlock(&data->update_lock);
  941. return count;
  942. }
  943. static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
  944. static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  945. 0, 1);
  946. static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
  947. set_fan_div, 0);
  948. static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
  949. static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  950. 1, 1);
  951. static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
  952. set_fan_div, 1);
  953. static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
  954. static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  955. 2, 1);
  956. static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
  957. set_fan_div, 2);
  958. static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
  959. static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  960. 3, 1);
  961. static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
  962. static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  963. 4, 1);
  964. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
  965. show_pwm_enable, set_pwm_enable, 0);
  966. static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
  967. static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
  968. static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
  969. show_pwm_temp_map, set_pwm_temp_map, 0);
  970. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
  971. show_auto_pwm, set_auto_pwm, 0, 0);
  972. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
  973. show_auto_pwm, set_auto_pwm, 0, 1);
  974. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
  975. show_auto_pwm, set_auto_pwm, 0, 2);
  976. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
  977. show_auto_pwm, NULL, 0, 3);
  978. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
  979. show_auto_temp, set_auto_temp, 0, 1);
  980. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
  981. show_auto_temp, set_auto_temp, 0, 0);
  982. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
  983. show_auto_temp, set_auto_temp, 0, 2);
  984. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
  985. show_auto_temp, set_auto_temp, 0, 3);
  986. static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
  987. show_auto_temp, set_auto_temp, 0, 4);
  988. static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
  989. show_pwm_enable, set_pwm_enable, 1);
  990. static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
  991. static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
  992. static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
  993. show_pwm_temp_map, set_pwm_temp_map, 1);
  994. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
  995. show_auto_pwm, set_auto_pwm, 1, 0);
  996. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
  997. show_auto_pwm, set_auto_pwm, 1, 1);
  998. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
  999. show_auto_pwm, set_auto_pwm, 1, 2);
  1000. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
  1001. show_auto_pwm, NULL, 1, 3);
  1002. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
  1003. show_auto_temp, set_auto_temp, 1, 1);
  1004. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
  1005. show_auto_temp, set_auto_temp, 1, 0);
  1006. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
  1007. show_auto_temp, set_auto_temp, 1, 2);
  1008. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
  1009. show_auto_temp, set_auto_temp, 1, 3);
  1010. static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
  1011. show_auto_temp, set_auto_temp, 1, 4);
  1012. static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
  1013. show_pwm_enable, set_pwm_enable, 2);
  1014. static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
  1015. static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
  1016. static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
  1017. show_pwm_temp_map, set_pwm_temp_map, 2);
  1018. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
  1019. show_auto_pwm, set_auto_pwm, 2, 0);
  1020. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
  1021. show_auto_pwm, set_auto_pwm, 2, 1);
  1022. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
  1023. show_auto_pwm, set_auto_pwm, 2, 2);
  1024. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
  1025. show_auto_pwm, NULL, 2, 3);
  1026. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
  1027. show_auto_temp, set_auto_temp, 2, 1);
  1028. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
  1029. show_auto_temp, set_auto_temp, 2, 0);
  1030. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
  1031. show_auto_temp, set_auto_temp, 2, 2);
  1032. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
  1033. show_auto_temp, set_auto_temp, 2, 3);
  1034. static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
  1035. show_auto_temp, set_auto_temp, 2, 4);
  1036. /* Alarms */
  1037. static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
  1038. char *buf)
  1039. {
  1040. struct it87_data *data = it87_update_device(dev);
  1041. return sprintf(buf, "%u\n", data->alarms);
  1042. }
  1043. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  1044. static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  1045. char *buf)
  1046. {
  1047. int bitnr = to_sensor_dev_attr(attr)->index;
  1048. struct it87_data *data = it87_update_device(dev);
  1049. return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  1050. }
  1051. static ssize_t clear_intrusion(struct device *dev, struct device_attribute
  1052. *attr, const char *buf, size_t count)
  1053. {
  1054. struct it87_data *data = dev_get_drvdata(dev);
  1055. long val;
  1056. int config;
  1057. if (kstrtol(buf, 10, &val) < 0 || val != 0)
  1058. return -EINVAL;
  1059. mutex_lock(&data->update_lock);
  1060. config = it87_read_value(data, IT87_REG_CONFIG);
  1061. if (config < 0) {
  1062. count = config;
  1063. } else {
  1064. config |= 1 << 5;
  1065. it87_write_value(data, IT87_REG_CONFIG, config);
  1066. /* Invalidate cache to force re-read */
  1067. data->valid = 0;
  1068. }
  1069. mutex_unlock(&data->update_lock);
  1070. return count;
  1071. }
  1072. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
  1073. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
  1074. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
  1075. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
  1076. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
  1077. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
  1078. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
  1079. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
  1080. static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
  1081. static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
  1082. static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
  1083. static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
  1084. static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
  1085. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
  1086. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
  1087. static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
  1088. static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
  1089. show_alarm, clear_intrusion, 4);
  1090. static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
  1091. char *buf)
  1092. {
  1093. int bitnr = to_sensor_dev_attr(attr)->index;
  1094. struct it87_data *data = it87_update_device(dev);
  1095. return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
  1096. }
  1097. static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
  1098. const char *buf, size_t count)
  1099. {
  1100. int bitnr = to_sensor_dev_attr(attr)->index;
  1101. struct it87_data *data = dev_get_drvdata(dev);
  1102. long val;
  1103. if (kstrtol(buf, 10, &val) < 0
  1104. || (val != 0 && val != 1))
  1105. return -EINVAL;
  1106. mutex_lock(&data->update_lock);
  1107. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  1108. if (val)
  1109. data->beeps |= (1 << bitnr);
  1110. else
  1111. data->beeps &= ~(1 << bitnr);
  1112. it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
  1113. mutex_unlock(&data->update_lock);
  1114. return count;
  1115. }
  1116. static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
  1117. show_beep, set_beep, 1);
  1118. static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
  1119. static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
  1120. static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
  1121. static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
  1122. static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
  1123. static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
  1124. static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
  1125. /* fanX_beep writability is set later */
  1126. static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
  1127. static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
  1128. static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
  1129. static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
  1130. static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
  1131. static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
  1132. show_beep, set_beep, 2);
  1133. static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
  1134. static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
  1135. static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
  1136. char *buf)
  1137. {
  1138. struct it87_data *data = dev_get_drvdata(dev);
  1139. return sprintf(buf, "%u\n", data->vrm);
  1140. }
  1141. static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
  1142. const char *buf, size_t count)
  1143. {
  1144. struct it87_data *data = dev_get_drvdata(dev);
  1145. unsigned long val;
  1146. if (kstrtoul(buf, 10, &val) < 0)
  1147. return -EINVAL;
  1148. data->vrm = val;
  1149. return count;
  1150. }
  1151. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
  1152. static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
  1153. char *buf)
  1154. {
  1155. struct it87_data *data = it87_update_device(dev);
  1156. return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
  1157. }
  1158. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
  1159. static ssize_t show_label(struct device *dev, struct device_attribute *attr,
  1160. char *buf)
  1161. {
  1162. static const char * const labels[] = {
  1163. "+5V",
  1164. "5VSB",
  1165. "Vbat",
  1166. };
  1167. static const char * const labels_it8721[] = {
  1168. "+3.3V",
  1169. "3VSB",
  1170. "Vbat",
  1171. };
  1172. struct it87_data *data = dev_get_drvdata(dev);
  1173. int nr = to_sensor_dev_attr(attr)->index;
  1174. return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
  1175. : labels[nr]);
  1176. }
  1177. static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
  1178. static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
  1179. static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
  1180. static ssize_t show_name(struct device *dev, struct device_attribute
  1181. *devattr, char *buf)
  1182. {
  1183. struct it87_data *data = dev_get_drvdata(dev);
  1184. return sprintf(buf, "%s\n", data->name);
  1185. }
  1186. static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  1187. static struct attribute *it87_attributes_in[9][5] = {
  1188. {
  1189. &sensor_dev_attr_in0_input.dev_attr.attr,
  1190. &sensor_dev_attr_in0_min.dev_attr.attr,
  1191. &sensor_dev_attr_in0_max.dev_attr.attr,
  1192. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  1193. NULL
  1194. }, {
  1195. &sensor_dev_attr_in1_input.dev_attr.attr,
  1196. &sensor_dev_attr_in1_min.dev_attr.attr,
  1197. &sensor_dev_attr_in1_max.dev_attr.attr,
  1198. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  1199. NULL
  1200. }, {
  1201. &sensor_dev_attr_in2_input.dev_attr.attr,
  1202. &sensor_dev_attr_in2_min.dev_attr.attr,
  1203. &sensor_dev_attr_in2_max.dev_attr.attr,
  1204. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  1205. NULL
  1206. }, {
  1207. &sensor_dev_attr_in3_input.dev_attr.attr,
  1208. &sensor_dev_attr_in3_min.dev_attr.attr,
  1209. &sensor_dev_attr_in3_max.dev_attr.attr,
  1210. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  1211. NULL
  1212. }, {
  1213. &sensor_dev_attr_in4_input.dev_attr.attr,
  1214. &sensor_dev_attr_in4_min.dev_attr.attr,
  1215. &sensor_dev_attr_in4_max.dev_attr.attr,
  1216. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  1217. NULL
  1218. }, {
  1219. &sensor_dev_attr_in5_input.dev_attr.attr,
  1220. &sensor_dev_attr_in5_min.dev_attr.attr,
  1221. &sensor_dev_attr_in5_max.dev_attr.attr,
  1222. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  1223. NULL
  1224. }, {
  1225. &sensor_dev_attr_in6_input.dev_attr.attr,
  1226. &sensor_dev_attr_in6_min.dev_attr.attr,
  1227. &sensor_dev_attr_in6_max.dev_attr.attr,
  1228. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  1229. NULL
  1230. }, {
  1231. &sensor_dev_attr_in7_input.dev_attr.attr,
  1232. &sensor_dev_attr_in7_min.dev_attr.attr,
  1233. &sensor_dev_attr_in7_max.dev_attr.attr,
  1234. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  1235. NULL
  1236. }, {
  1237. &sensor_dev_attr_in8_input.dev_attr.attr,
  1238. NULL
  1239. } };
  1240. static const struct attribute_group it87_group_in[9] = {
  1241. { .attrs = it87_attributes_in[0] },
  1242. { .attrs = it87_attributes_in[1] },
  1243. { .attrs = it87_attributes_in[2] },
  1244. { .attrs = it87_attributes_in[3] },
  1245. { .attrs = it87_attributes_in[4] },
  1246. { .attrs = it87_attributes_in[5] },
  1247. { .attrs = it87_attributes_in[6] },
  1248. { .attrs = it87_attributes_in[7] },
  1249. { .attrs = it87_attributes_in[8] },
  1250. };
  1251. static struct attribute *it87_attributes_temp[3][6] = {
  1252. {
  1253. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1254. &sensor_dev_attr_temp1_max.dev_attr.attr,
  1255. &sensor_dev_attr_temp1_min.dev_attr.attr,
  1256. &sensor_dev_attr_temp1_type.dev_attr.attr,
  1257. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  1258. NULL
  1259. } , {
  1260. &sensor_dev_attr_temp2_input.dev_attr.attr,
  1261. &sensor_dev_attr_temp2_max.dev_attr.attr,
  1262. &sensor_dev_attr_temp2_min.dev_attr.attr,
  1263. &sensor_dev_attr_temp2_type.dev_attr.attr,
  1264. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  1265. NULL
  1266. } , {
  1267. &sensor_dev_attr_temp3_input.dev_attr.attr,
  1268. &sensor_dev_attr_temp3_max.dev_attr.attr,
  1269. &sensor_dev_attr_temp3_min.dev_attr.attr,
  1270. &sensor_dev_attr_temp3_type.dev_attr.attr,
  1271. &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  1272. NULL
  1273. } };
  1274. static const struct attribute_group it87_group_temp[3] = {
  1275. { .attrs = it87_attributes_temp[0] },
  1276. { .attrs = it87_attributes_temp[1] },
  1277. { .attrs = it87_attributes_temp[2] },
  1278. };
  1279. static struct attribute *it87_attributes_temp_offset[] = {
  1280. &sensor_dev_attr_temp1_offset.dev_attr.attr,
  1281. &sensor_dev_attr_temp2_offset.dev_attr.attr,
  1282. &sensor_dev_attr_temp3_offset.dev_attr.attr,
  1283. };
  1284. static struct attribute *it87_attributes[] = {
  1285. &dev_attr_alarms.attr,
  1286. &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
  1287. &dev_attr_name.attr,
  1288. NULL
  1289. };
  1290. static const struct attribute_group it87_group = {
  1291. .attrs = it87_attributes,
  1292. };
  1293. static struct attribute *it87_attributes_in_beep[] = {
  1294. &sensor_dev_attr_in0_beep.dev_attr.attr,
  1295. &sensor_dev_attr_in1_beep.dev_attr.attr,
  1296. &sensor_dev_attr_in2_beep.dev_attr.attr,
  1297. &sensor_dev_attr_in3_beep.dev_attr.attr,
  1298. &sensor_dev_attr_in4_beep.dev_attr.attr,
  1299. &sensor_dev_attr_in5_beep.dev_attr.attr,
  1300. &sensor_dev_attr_in6_beep.dev_attr.attr,
  1301. &sensor_dev_attr_in7_beep.dev_attr.attr,
  1302. NULL
  1303. };
  1304. static struct attribute *it87_attributes_temp_beep[] = {
  1305. &sensor_dev_attr_temp1_beep.dev_attr.attr,
  1306. &sensor_dev_attr_temp2_beep.dev_attr.attr,
  1307. &sensor_dev_attr_temp3_beep.dev_attr.attr,
  1308. };
  1309. static struct attribute *it87_attributes_fan[5][3+1] = { {
  1310. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1311. &sensor_dev_attr_fan1_min.dev_attr.attr,
  1312. &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  1313. NULL
  1314. }, {
  1315. &sensor_dev_attr_fan2_input.dev_attr.attr,
  1316. &sensor_dev_attr_fan2_min.dev_attr.attr,
  1317. &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  1318. NULL
  1319. }, {
  1320. &sensor_dev_attr_fan3_input.dev_attr.attr,
  1321. &sensor_dev_attr_fan3_min.dev_attr.attr,
  1322. &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  1323. NULL
  1324. }, {
  1325. &sensor_dev_attr_fan4_input.dev_attr.attr,
  1326. &sensor_dev_attr_fan4_min.dev_attr.attr,
  1327. &sensor_dev_attr_fan4_alarm.dev_attr.attr,
  1328. NULL
  1329. }, {
  1330. &sensor_dev_attr_fan5_input.dev_attr.attr,
  1331. &sensor_dev_attr_fan5_min.dev_attr.attr,
  1332. &sensor_dev_attr_fan5_alarm.dev_attr.attr,
  1333. NULL
  1334. } };
  1335. static const struct attribute_group it87_group_fan[5] = {
  1336. { .attrs = it87_attributes_fan[0] },
  1337. { .attrs = it87_attributes_fan[1] },
  1338. { .attrs = it87_attributes_fan[2] },
  1339. { .attrs = it87_attributes_fan[3] },
  1340. { .attrs = it87_attributes_fan[4] },
  1341. };
  1342. static const struct attribute *it87_attributes_fan_div[] = {
  1343. &sensor_dev_attr_fan1_div.dev_attr.attr,
  1344. &sensor_dev_attr_fan2_div.dev_attr.attr,
  1345. &sensor_dev_attr_fan3_div.dev_attr.attr,
  1346. };
  1347. static struct attribute *it87_attributes_pwm[3][4+1] = { {
  1348. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1349. &sensor_dev_attr_pwm1.dev_attr.attr,
  1350. &dev_attr_pwm1_freq.attr,
  1351. &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
  1352. NULL
  1353. }, {
  1354. &sensor_dev_attr_pwm2_enable.dev_attr.attr,
  1355. &sensor_dev_attr_pwm2.dev_attr.attr,
  1356. &dev_attr_pwm2_freq.attr,
  1357. &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
  1358. NULL
  1359. }, {
  1360. &sensor_dev_attr_pwm3_enable.dev_attr.attr,
  1361. &sensor_dev_attr_pwm3.dev_attr.attr,
  1362. &dev_attr_pwm3_freq.attr,
  1363. &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
  1364. NULL
  1365. } };
  1366. static const struct attribute_group it87_group_pwm[3] = {
  1367. { .attrs = it87_attributes_pwm[0] },
  1368. { .attrs = it87_attributes_pwm[1] },
  1369. { .attrs = it87_attributes_pwm[2] },
  1370. };
  1371. static struct attribute *it87_attributes_autopwm[3][9+1] = { {
  1372. &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
  1373. &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
  1374. &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
  1375. &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
  1376. &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
  1377. &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
  1378. &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
  1379. &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
  1380. &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
  1381. NULL
  1382. }, {
  1383. &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
  1384. &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
  1385. &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
  1386. &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
  1387. &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
  1388. &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
  1389. &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
  1390. &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
  1391. &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
  1392. NULL
  1393. }, {
  1394. &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
  1395. &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
  1396. &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
  1397. &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
  1398. &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
  1399. &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
  1400. &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
  1401. &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
  1402. &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
  1403. NULL
  1404. } };
  1405. static const struct attribute_group it87_group_autopwm[3] = {
  1406. { .attrs = it87_attributes_autopwm[0] },
  1407. { .attrs = it87_attributes_autopwm[1] },
  1408. { .attrs = it87_attributes_autopwm[2] },
  1409. };
  1410. static struct attribute *it87_attributes_fan_beep[] = {
  1411. &sensor_dev_attr_fan1_beep.dev_attr.attr,
  1412. &sensor_dev_attr_fan2_beep.dev_attr.attr,
  1413. &sensor_dev_attr_fan3_beep.dev_attr.attr,
  1414. &sensor_dev_attr_fan4_beep.dev_attr.attr,
  1415. &sensor_dev_attr_fan5_beep.dev_attr.attr,
  1416. };
  1417. static struct attribute *it87_attributes_vid[] = {
  1418. &dev_attr_vrm.attr,
  1419. &dev_attr_cpu0_vid.attr,
  1420. NULL
  1421. };
  1422. static const struct attribute_group it87_group_vid = {
  1423. .attrs = it87_attributes_vid,
  1424. };
  1425. static struct attribute *it87_attributes_label[] = {
  1426. &sensor_dev_attr_in3_label.dev_attr.attr,
  1427. &sensor_dev_attr_in7_label.dev_attr.attr,
  1428. &sensor_dev_attr_in8_label.dev_attr.attr,
  1429. NULL
  1430. };
  1431. static const struct attribute_group it87_group_label = {
  1432. .attrs = it87_attributes_label,
  1433. };
  1434. /* SuperIO detection - will change isa_address if a chip is found */
  1435. static int __init it87_find(unsigned short *address,
  1436. struct it87_sio_data *sio_data)
  1437. {
  1438. int err;
  1439. u16 chip_type;
  1440. const char *board_vendor, *board_name;
  1441. err = superio_enter();
  1442. if (err)
  1443. return err;
  1444. err = -ENODEV;
  1445. chip_type = force_id ? force_id : superio_inw(DEVID);
  1446. switch (chip_type) {
  1447. case IT8705F_DEVID:
  1448. sio_data->type = it87;
  1449. break;
  1450. case IT8712F_DEVID:
  1451. sio_data->type = it8712;
  1452. break;
  1453. case IT8716F_DEVID:
  1454. case IT8726F_DEVID:
  1455. sio_data->type = it8716;
  1456. break;
  1457. case IT8718F_DEVID:
  1458. sio_data->type = it8718;
  1459. break;
  1460. case IT8720F_DEVID:
  1461. sio_data->type = it8720;
  1462. break;
  1463. case IT8721F_DEVID:
  1464. sio_data->type = it8721;
  1465. break;
  1466. case IT8728F_DEVID:
  1467. sio_data->type = it8728;
  1468. break;
  1469. case IT8782F_DEVID:
  1470. sio_data->type = it8782;
  1471. break;
  1472. case IT8783E_DEVID:
  1473. sio_data->type = it8783;
  1474. break;
  1475. case 0xffff: /* No device at all */
  1476. goto exit;
  1477. default:
  1478. pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
  1479. goto exit;
  1480. }
  1481. superio_select(PME);
  1482. if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
  1483. pr_info("Device not activated, skipping\n");
  1484. goto exit;
  1485. }
  1486. *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
  1487. if (*address == 0) {
  1488. pr_info("Base address not set, skipping\n");
  1489. goto exit;
  1490. }
  1491. err = 0;
  1492. sio_data->revision = superio_inb(DEVREV) & 0x0f;
  1493. pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
  1494. chip_type, *address, sio_data->revision);
  1495. /* in8 (Vbat) is always internal */
  1496. sio_data->internal = (1 << 2);
  1497. /* Read GPIO config and VID value from LDN 7 (GPIO) */
  1498. if (sio_data->type == it87) {
  1499. /* The IT8705F doesn't have VID pins at all */
  1500. sio_data->skip_vid = 1;
  1501. /* The IT8705F has a different LD number for GPIO */
  1502. superio_select(5);
  1503. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1504. } else if (sio_data->type == it8783) {
  1505. int reg25, reg27, reg2A, reg2C, regEF;
  1506. sio_data->skip_vid = 1; /* No VID */
  1507. superio_select(GPIO);
  1508. reg25 = superio_inb(IT87_SIO_GPIO1_REG);
  1509. reg27 = superio_inb(IT87_SIO_GPIO3_REG);
  1510. reg2A = superio_inb(IT87_SIO_PINX1_REG);
  1511. reg2C = superio_inb(IT87_SIO_PINX2_REG);
  1512. regEF = superio_inb(IT87_SIO_SPI_REG);
  1513. /* Check if fan3 is there or not */
  1514. if ((reg27 & (1 << 0)) || !(reg2C & (1 << 2)))
  1515. sio_data->skip_fan |= (1 << 2);
  1516. if ((reg25 & (1 << 4))
  1517. || (!(reg2A & (1 << 1)) && (regEF & (1 << 0))))
  1518. sio_data->skip_pwm |= (1 << 2);
  1519. /* Check if fan2 is there or not */
  1520. if (reg27 & (1 << 7))
  1521. sio_data->skip_fan |= (1 << 1);
  1522. if (reg27 & (1 << 3))
  1523. sio_data->skip_pwm |= (1 << 1);
  1524. /* VIN5 */
  1525. if ((reg27 & (1 << 0)) || (reg2C & (1 << 2)))
  1526. sio_data->skip_in |= (1 << 5); /* No VIN5 */
  1527. /* VIN6 */
  1528. if (reg27 & (1 << 1))
  1529. sio_data->skip_in |= (1 << 6); /* No VIN6 */
  1530. /*
  1531. * VIN7
  1532. * Does not depend on bit 2 of Reg2C, contrary to datasheet.
  1533. */
  1534. if (reg27 & (1 << 2)) {
  1535. /*
  1536. * The data sheet is a bit unclear regarding the
  1537. * internal voltage divider for VCCH5V. It says
  1538. * "This bit enables and switches VIN7 (pin 91) to the
  1539. * internal voltage divider for VCCH5V".
  1540. * This is different to other chips, where the internal
  1541. * voltage divider would connect VIN7 to an internal
  1542. * voltage source. Maybe that is the case here as well.
  1543. *
  1544. * Since we don't know for sure, re-route it if that is
  1545. * not the case, and ask the user to report if the
  1546. * resulting voltage is sane.
  1547. */
  1548. if (!(reg2C & (1 << 1))) {
  1549. reg2C |= (1 << 1);
  1550. superio_outb(IT87_SIO_PINX2_REG, reg2C);
  1551. pr_notice("Routing internal VCCH5V to in7.\n");
  1552. }
  1553. pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
  1554. pr_notice("Please report if it displays a reasonable voltage.\n");
  1555. }
  1556. if (reg2C & (1 << 0))
  1557. sio_data->internal |= (1 << 0);
  1558. if (reg2C & (1 << 1))
  1559. sio_data->internal |= (1 << 1);
  1560. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1561. } else {
  1562. int reg;
  1563. bool uart6;
  1564. superio_select(GPIO);
  1565. reg = superio_inb(IT87_SIO_GPIO3_REG);
  1566. if (sio_data->type == it8721 || sio_data->type == it8728 ||
  1567. sio_data->type == it8782) {
  1568. /*
  1569. * IT8721F/IT8758E, and IT8782F don't have VID pins
  1570. * at all, not sure about the IT8728F.
  1571. */
  1572. sio_data->skip_vid = 1;
  1573. } else {
  1574. /* We need at least 4 VID pins */
  1575. if (reg & 0x0f) {
  1576. pr_info("VID is disabled (pins used for GPIO)\n");
  1577. sio_data->skip_vid = 1;
  1578. }
  1579. }
  1580. /* Check if fan3 is there or not */
  1581. if (reg & (1 << 6))
  1582. sio_data->skip_pwm |= (1 << 2);
  1583. if (reg & (1 << 7))
  1584. sio_data->skip_fan |= (1 << 2);
  1585. /* Check if fan2 is there or not */
  1586. reg = superio_inb(IT87_SIO_GPIO5_REG);
  1587. if (reg & (1 << 1))
  1588. sio_data->skip_pwm |= (1 << 1);
  1589. if (reg & (1 << 2))
  1590. sio_data->skip_fan |= (1 << 1);
  1591. if ((sio_data->type == it8718 || sio_data->type == it8720)
  1592. && !(sio_data->skip_vid))
  1593. sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
  1594. reg = superio_inb(IT87_SIO_PINX2_REG);
  1595. uart6 = sio_data->type == it8782 && (reg & (1 << 2));
  1596. /*
  1597. * The IT8720F has no VIN7 pin, so VCCH should always be
  1598. * routed internally to VIN7 with an internal divider.
  1599. * Curiously, there still is a configuration bit to control
  1600. * this, which means it can be set incorrectly. And even
  1601. * more curiously, many boards out there are improperly
  1602. * configured, even though the IT8720F datasheet claims
  1603. * that the internal routing of VCCH to VIN7 is the default
  1604. * setting. So we force the internal routing in this case.
  1605. *
  1606. * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
  1607. * If UART6 is enabled, re-route VIN7 to the internal divider
  1608. * if that is not already the case.
  1609. */
  1610. if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
  1611. reg |= (1 << 1);
  1612. superio_outb(IT87_SIO_PINX2_REG, reg);
  1613. pr_notice("Routing internal VCCH to in7\n");
  1614. }
  1615. if (reg & (1 << 0))
  1616. sio_data->internal |= (1 << 0);
  1617. if ((reg & (1 << 1)) || sio_data->type == it8721 ||
  1618. sio_data->type == it8728)
  1619. sio_data->internal |= (1 << 1);
  1620. /*
  1621. * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
  1622. * While VIN7 can be routed to the internal voltage divider,
  1623. * VIN5 and VIN6 are not available if UART6 is enabled.
  1624. *
  1625. * Also, temp3 is not available if UART6 is enabled and TEMPIN3
  1626. * is the temperature source. Since we can not read the
  1627. * temperature source here, skip_temp is preliminary.
  1628. */
  1629. if (uart6) {
  1630. sio_data->skip_in |= (1 << 5) | (1 << 6);
  1631. sio_data->skip_temp |= (1 << 2);
  1632. }
  1633. sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
  1634. }
  1635. if (sio_data->beep_pin)
  1636. pr_info("Beeping is supported\n");
  1637. /* Disable specific features based on DMI strings */
  1638. board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1639. board_name = dmi_get_system_info(DMI_BOARD_NAME);
  1640. if (board_vendor && board_name) {
  1641. if (strcmp(board_vendor, "nVIDIA") == 0
  1642. && strcmp(board_name, "FN68PT") == 0) {
  1643. /*
  1644. * On the Shuttle SN68PT, FAN_CTL2 is apparently not
  1645. * connected to a fan, but to something else. One user
  1646. * has reported instant system power-off when changing
  1647. * the PWM2 duty cycle, so we disable it.
  1648. * I use the board name string as the trigger in case
  1649. * the same board is ever used in other systems.
  1650. */
  1651. pr_info("Disabling pwm2 due to hardware constraints\n");
  1652. sio_data->skip_pwm = (1 << 1);
  1653. }
  1654. }
  1655. exit:
  1656. superio_exit();
  1657. return err;
  1658. }
  1659. static void it87_remove_files(struct device *dev)
  1660. {
  1661. struct it87_data *data = platform_get_drvdata(pdev);
  1662. struct it87_sio_data *sio_data = dev->platform_data;
  1663. int i;
  1664. sysfs_remove_group(&dev->kobj, &it87_group);
  1665. for (i = 0; i < 9; i++) {
  1666. if (sio_data->skip_in & (1 << i))
  1667. continue;
  1668. sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
  1669. if (it87_attributes_in_beep[i])
  1670. sysfs_remove_file(&dev->kobj,
  1671. it87_attributes_in_beep[i]);
  1672. }
  1673. for (i = 0; i < 3; i++) {
  1674. if (!(data->has_temp & (1 << i)))
  1675. continue;
  1676. sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
  1677. if (has_temp_offset(data))
  1678. sysfs_remove_file(&dev->kobj,
  1679. it87_attributes_temp_offset[i]);
  1680. if (sio_data->beep_pin)
  1681. sysfs_remove_file(&dev->kobj,
  1682. it87_attributes_temp_beep[i]);
  1683. }
  1684. for (i = 0; i < 5; i++) {
  1685. if (!(data->has_fan & (1 << i)))
  1686. continue;
  1687. sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
  1688. if (sio_data->beep_pin)
  1689. sysfs_remove_file(&dev->kobj,
  1690. it87_attributes_fan_beep[i]);
  1691. if (i < 3 && !has_16bit_fans(data))
  1692. sysfs_remove_file(&dev->kobj,
  1693. it87_attributes_fan_div[i]);
  1694. }
  1695. for (i = 0; i < 3; i++) {
  1696. if (sio_data->skip_pwm & (1 << 0))
  1697. continue;
  1698. sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
  1699. if (has_old_autopwm(data))
  1700. sysfs_remove_group(&dev->kobj,
  1701. &it87_group_autopwm[i]);
  1702. }
  1703. if (!sio_data->skip_vid)
  1704. sysfs_remove_group(&dev->kobj, &it87_group_vid);
  1705. sysfs_remove_group(&dev->kobj, &it87_group_label);
  1706. }
  1707. static int it87_probe(struct platform_device *pdev)
  1708. {
  1709. struct it87_data *data;
  1710. struct resource *res;
  1711. struct device *dev = &pdev->dev;
  1712. struct it87_sio_data *sio_data = dev->platform_data;
  1713. int err = 0, i;
  1714. int enable_pwm_interface;
  1715. int fan_beep_need_rw;
  1716. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  1717. if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
  1718. DRVNAME)) {
  1719. dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
  1720. (unsigned long)res->start,
  1721. (unsigned long)(res->start + IT87_EC_EXTENT - 1));
  1722. return -EBUSY;
  1723. }
  1724. data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
  1725. if (!data)
  1726. return -ENOMEM;
  1727. data->addr = res->start;
  1728. data->type = sio_data->type;
  1729. data->features = it87_devices[sio_data->type].features;
  1730. data->name = it87_devices[sio_data->type].name;
  1731. /*
  1732. * IT8705F Datasheet 0.4.1, 3h == Version G.
  1733. * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
  1734. * These are the first revisions with 16-bit tachometer support.
  1735. */
  1736. switch (data->type) {
  1737. case it87:
  1738. if (sio_data->revision >= 0x03) {
  1739. data->features &= ~FEAT_OLD_AUTOPWM;
  1740. data->features |= FEAT_16BIT_FANS;
  1741. }
  1742. break;
  1743. case it8712:
  1744. if (sio_data->revision >= 0x08) {
  1745. data->features &= ~FEAT_OLD_AUTOPWM;
  1746. data->features |= FEAT_16BIT_FANS;
  1747. }
  1748. break;
  1749. default:
  1750. break;
  1751. }
  1752. /* Now, we do the remaining detection. */
  1753. if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
  1754. || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
  1755. return -ENODEV;
  1756. platform_set_drvdata(pdev, data);
  1757. mutex_init(&data->update_lock);
  1758. /* Check PWM configuration */
  1759. enable_pwm_interface = it87_check_pwm(dev);
  1760. /* Starting with IT8721F, we handle scaling of internal voltages */
  1761. if (has_12mv_adc(data)) {
  1762. if (sio_data->internal & (1 << 0))
  1763. data->in_scaled |= (1 << 3); /* in3 is AVCC */
  1764. if (sio_data->internal & (1 << 1))
  1765. data->in_scaled |= (1 << 7); /* in7 is VSB */
  1766. if (sio_data->internal & (1 << 2))
  1767. data->in_scaled |= (1 << 8); /* in8 is Vbat */
  1768. } else if (sio_data->type == it8782 || sio_data->type == it8783) {
  1769. if (sio_data->internal & (1 << 0))
  1770. data->in_scaled |= (1 << 3); /* in3 is VCC5V */
  1771. if (sio_data->internal & (1 << 1))
  1772. data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
  1773. }
  1774. data->has_temp = 0x07;
  1775. if (sio_data->skip_temp & (1 << 2)) {
  1776. if (sio_data->type == it8782
  1777. && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
  1778. data->has_temp &= ~(1 << 2);
  1779. }
  1780. /* Initialize the IT87 chip */
  1781. it87_init_device(pdev);
  1782. /* Register sysfs hooks */
  1783. err = sysfs_create_group(&dev->kobj, &it87_group);
  1784. if (err)
  1785. return err;
  1786. for (i = 0; i < 9; i++) {
  1787. if (sio_data->skip_in & (1 << i))
  1788. continue;
  1789. err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
  1790. if (err)
  1791. goto error;
  1792. if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
  1793. err = sysfs_create_file(&dev->kobj,
  1794. it87_attributes_in_beep[i]);
  1795. if (err)
  1796. goto error;
  1797. }
  1798. }
  1799. for (i = 0; i < 3; i++) {
  1800. if (!(data->has_temp & (1 << i)))
  1801. continue;
  1802. err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
  1803. if (err)
  1804. goto error;
  1805. if (has_temp_offset(data)) {
  1806. err = sysfs_create_file(&dev->kobj,
  1807. it87_attributes_temp_offset[i]);
  1808. if (err)
  1809. goto error;
  1810. }
  1811. if (sio_data->beep_pin) {
  1812. err = sysfs_create_file(&dev->kobj,
  1813. it87_attributes_temp_beep[i]);
  1814. if (err)
  1815. goto error;
  1816. }
  1817. }
  1818. /* Do not create fan files for disabled fans */
  1819. fan_beep_need_rw = 1;
  1820. for (i = 0; i < 5; i++) {
  1821. if (!(data->has_fan & (1 << i)))
  1822. continue;
  1823. err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
  1824. if (err)
  1825. goto error;
  1826. if (i < 3 && !has_16bit_fans(data)) {
  1827. err = sysfs_create_file(&dev->kobj,
  1828. it87_attributes_fan_div[i]);
  1829. if (err)
  1830. goto error;
  1831. }
  1832. if (sio_data->beep_pin) {
  1833. err = sysfs_create_file(&dev->kobj,
  1834. it87_attributes_fan_beep[i]);
  1835. if (err)
  1836. goto error;
  1837. if (!fan_beep_need_rw)
  1838. continue;
  1839. /*
  1840. * As we have a single beep enable bit for all fans,
  1841. * only the first enabled fan has a writable attribute
  1842. * for it.
  1843. */
  1844. if (sysfs_chmod_file(&dev->kobj,
  1845. it87_attributes_fan_beep[i],
  1846. S_IRUGO | S_IWUSR))
  1847. dev_dbg(dev, "chmod +w fan%d_beep failed\n",
  1848. i + 1);
  1849. fan_beep_need_rw = 0;
  1850. }
  1851. }
  1852. if (enable_pwm_interface) {
  1853. for (i = 0; i < 3; i++) {
  1854. if (sio_data->skip_pwm & (1 << i))
  1855. continue;
  1856. err = sysfs_create_group(&dev->kobj,
  1857. &it87_group_pwm[i]);
  1858. if (err)
  1859. goto error;
  1860. if (!has_old_autopwm(data))
  1861. continue;
  1862. err = sysfs_create_group(&dev->kobj,
  1863. &it87_group_autopwm[i]);
  1864. if (err)
  1865. goto error;
  1866. }
  1867. }
  1868. if (!sio_data->skip_vid) {
  1869. data->vrm = vid_which_vrm();
  1870. /* VID reading from Super-I/O config space if available */
  1871. data->vid = sio_data->vid_value;
  1872. err = sysfs_create_group(&dev->kobj, &it87_group_vid);
  1873. if (err)
  1874. goto error;
  1875. }
  1876. /* Export labels for internal sensors */
  1877. for (i = 0; i < 3; i++) {
  1878. if (!(sio_data->internal & (1 << i)))
  1879. continue;
  1880. err = sysfs_create_file(&dev->kobj,
  1881. it87_attributes_label[i]);
  1882. if (err)
  1883. goto error;
  1884. }
  1885. data->hwmon_dev = hwmon_device_register(dev);
  1886. if (IS_ERR(data->hwmon_dev)) {
  1887. err = PTR_ERR(data->hwmon_dev);
  1888. goto error;
  1889. }
  1890. return 0;
  1891. error:
  1892. it87_remove_files(dev);
  1893. return err;
  1894. }
  1895. static int it87_remove(struct platform_device *pdev)
  1896. {
  1897. struct it87_data *data = platform_get_drvdata(pdev);
  1898. hwmon_device_unregister(data->hwmon_dev);
  1899. it87_remove_files(&pdev->dev);
  1900. return 0;
  1901. }
  1902. /*
  1903. * Must be called with data->update_lock held, except during initialization.
  1904. * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1905. * would slow down the IT87 access and should not be necessary.
  1906. */
  1907. static int it87_read_value(struct it87_data *data, u8 reg)
  1908. {
  1909. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1910. return inb_p(data->addr + IT87_DATA_REG_OFFSET);
  1911. }
  1912. /*
  1913. * Must be called with data->update_lock held, except during initialization.
  1914. * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
  1915. * would slow down the IT87 access and should not be necessary.
  1916. */
  1917. static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
  1918. {
  1919. outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
  1920. outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
  1921. }
  1922. /* Return 1 if and only if the PWM interface is safe to use */
  1923. static int it87_check_pwm(struct device *dev)
  1924. {
  1925. struct it87_data *data = dev_get_drvdata(dev);
  1926. /*
  1927. * Some BIOSes fail to correctly configure the IT87 fans. All fans off
  1928. * and polarity set to active low is sign that this is the case so we
  1929. * disable pwm control to protect the user.
  1930. */
  1931. int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
  1932. if ((tmp & 0x87) == 0) {
  1933. if (fix_pwm_polarity) {
  1934. /*
  1935. * The user asks us to attempt a chip reconfiguration.
  1936. * This means switching to active high polarity and
  1937. * inverting all fan speed values.
  1938. */
  1939. int i;
  1940. u8 pwm[3];
  1941. for (i = 0; i < 3; i++)
  1942. pwm[i] = it87_read_value(data,
  1943. IT87_REG_PWM(i));
  1944. /*
  1945. * If any fan is in automatic pwm mode, the polarity
  1946. * might be correct, as suspicious as it seems, so we
  1947. * better don't change anything (but still disable the
  1948. * PWM interface).
  1949. */
  1950. if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
  1951. dev_info(dev,
  1952. "Reconfiguring PWM to active high polarity\n");
  1953. it87_write_value(data, IT87_REG_FAN_CTL,
  1954. tmp | 0x87);
  1955. for (i = 0; i < 3; i++)
  1956. it87_write_value(data,
  1957. IT87_REG_PWM(i),
  1958. 0x7f & ~pwm[i]);
  1959. return 1;
  1960. }
  1961. dev_info(dev,
  1962. "PWM configuration is too broken to be fixed\n");
  1963. }
  1964. dev_info(dev,
  1965. "Detected broken BIOS defaults, disabling PWM interface\n");
  1966. return 0;
  1967. } else if (fix_pwm_polarity) {
  1968. dev_info(dev,
  1969. "PWM configuration looks sane, won't touch\n");
  1970. }
  1971. return 1;
  1972. }
  1973. /* Called when we have found a new IT87. */
  1974. static void it87_init_device(struct platform_device *pdev)
  1975. {
  1976. struct it87_sio_data *sio_data = pdev->dev.platform_data;
  1977. struct it87_data *data = platform_get_drvdata(pdev);
  1978. int tmp, i;
  1979. u8 mask;
  1980. /*
  1981. * For each PWM channel:
  1982. * - If it is in automatic mode, setting to manual mode should set
  1983. * the fan to full speed by default.
  1984. * - If it is in manual mode, we need a mapping to temperature
  1985. * channels to use when later setting to automatic mode later.
  1986. * Use a 1:1 mapping by default (we are clueless.)
  1987. * In both cases, the value can (and should) be changed by the user
  1988. * prior to switching to a different mode.
  1989. * Note that this is no longer needed for the IT8721F and later, as
  1990. * these have separate registers for the temperature mapping and the
  1991. * manual duty cycle.
  1992. */
  1993. for (i = 0; i < 3; i++) {
  1994. data->pwm_temp_map[i] = i;
  1995. data->pwm_duty[i] = 0x7f; /* Full speed */
  1996. data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
  1997. }
  1998. /*
  1999. * Some chips seem to have default value 0xff for all limit
  2000. * registers. For low voltage limits it makes no sense and triggers
  2001. * alarms, so change to 0 instead. For high temperature limits, it
  2002. * means -1 degree C, which surprisingly doesn't trigger an alarm,
  2003. * but is still confusing, so change to 127 degrees C.
  2004. */
  2005. for (i = 0; i < 8; i++) {
  2006. tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
  2007. if (tmp == 0xff)
  2008. it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
  2009. }
  2010. for (i = 0; i < 3; i++) {
  2011. tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  2012. if (tmp == 0xff)
  2013. it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
  2014. }
  2015. /*
  2016. * Temperature channels are not forcibly enabled, as they can be
  2017. * set to two different sensor types and we can't guess which one
  2018. * is correct for a given system. These channels can be enabled at
  2019. * run-time through the temp{1-3}_type sysfs accessors if needed.
  2020. */
  2021. /* Check if voltage monitors are reset manually or by some reason */
  2022. tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
  2023. if ((tmp & 0xff) == 0) {
  2024. /* Enable all voltage monitors */
  2025. it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
  2026. }
  2027. /* Check if tachometers are reset manually or by some reason */
  2028. mask = 0x70 & ~(sio_data->skip_fan << 4);
  2029. data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
  2030. if ((data->fan_main_ctrl & mask) == 0) {
  2031. /* Enable all fan tachometers */
  2032. data->fan_main_ctrl |= mask;
  2033. it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
  2034. data->fan_main_ctrl);
  2035. }
  2036. data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
  2037. /* Set tachometers to 16-bit mode if needed */
  2038. if (has_16bit_fans(data)) {
  2039. tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
  2040. if (~tmp & 0x07 & data->has_fan) {
  2041. dev_dbg(&pdev->dev,
  2042. "Setting fan1-3 to 16-bit mode\n");
  2043. it87_write_value(data, IT87_REG_FAN_16BIT,
  2044. tmp | 0x07);
  2045. }
  2046. /* IT8705F, IT8782F, and IT8783E/F only support three fans. */
  2047. if (data->type != it87 && data->type != it8782 &&
  2048. data->type != it8783) {
  2049. if (tmp & (1 << 4))
  2050. data->has_fan |= (1 << 3); /* fan4 enabled */
  2051. if (tmp & (1 << 5))
  2052. data->has_fan |= (1 << 4); /* fan5 enabled */
  2053. }
  2054. }
  2055. /* Fan input pins may be used for alternative functions */
  2056. data->has_fan &= ~sio_data->skip_fan;
  2057. /* Start monitoring */
  2058. it87_write_value(data, IT87_REG_CONFIG,
  2059. (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
  2060. | (update_vbat ? 0x41 : 0x01));
  2061. }
  2062. static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
  2063. {
  2064. data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
  2065. if (has_newer_autopwm(data)) {
  2066. data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
  2067. data->pwm_duty[nr] = it87_read_value(data,
  2068. IT87_REG_PWM_DUTY(nr));
  2069. } else {
  2070. if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
  2071. data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
  2072. else /* Manual mode */
  2073. data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
  2074. }
  2075. if (has_old_autopwm(data)) {
  2076. int i;
  2077. for (i = 0; i < 5 ; i++)
  2078. data->auto_temp[nr][i] = it87_read_value(data,
  2079. IT87_REG_AUTO_TEMP(nr, i));
  2080. for (i = 0; i < 3 ; i++)
  2081. data->auto_pwm[nr][i] = it87_read_value(data,
  2082. IT87_REG_AUTO_PWM(nr, i));
  2083. }
  2084. }
  2085. static struct it87_data *it87_update_device(struct device *dev)
  2086. {
  2087. struct it87_data *data = dev_get_drvdata(dev);
  2088. int i;
  2089. mutex_lock(&data->update_lock);
  2090. if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
  2091. || !data->valid) {
  2092. if (update_vbat) {
  2093. /*
  2094. * Cleared after each update, so reenable. Value
  2095. * returned by this read will be previous value
  2096. */
  2097. it87_write_value(data, IT87_REG_CONFIG,
  2098. it87_read_value(data, IT87_REG_CONFIG) | 0x40);
  2099. }
  2100. for (i = 0; i <= 7; i++) {
  2101. data->in[i][0] =
  2102. it87_read_value(data, IT87_REG_VIN(i));
  2103. data->in[i][1] =
  2104. it87_read_value(data, IT87_REG_VIN_MIN(i));
  2105. data->in[i][2] =
  2106. it87_read_value(data, IT87_REG_VIN_MAX(i));
  2107. }
  2108. /* in8 (battery) has no limit registers */
  2109. data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
  2110. for (i = 0; i < 5; i++) {
  2111. /* Skip disabled fans */
  2112. if (!(data->has_fan & (1 << i)))
  2113. continue;
  2114. data->fan[i][1] =
  2115. it87_read_value(data, IT87_REG_FAN_MIN[i]);
  2116. data->fan[i][0] = it87_read_value(data,
  2117. IT87_REG_FAN[i]);
  2118. /* Add high byte if in 16-bit mode */
  2119. if (has_16bit_fans(data)) {
  2120. data->fan[i][0] |= it87_read_value(data,
  2121. IT87_REG_FANX[i]) << 8;
  2122. data->fan[i][1] |= it87_read_value(data,
  2123. IT87_REG_FANX_MIN[i]) << 8;
  2124. }
  2125. }
  2126. for (i = 0; i < 3; i++) {
  2127. if (!(data->has_temp & (1 << i)))
  2128. continue;
  2129. data->temp[i][0] =
  2130. it87_read_value(data, IT87_REG_TEMP(i));
  2131. data->temp[i][1] =
  2132. it87_read_value(data, IT87_REG_TEMP_LOW(i));
  2133. data->temp[i][2] =
  2134. it87_read_value(data, IT87_REG_TEMP_HIGH(i));
  2135. if (has_temp_offset(data))
  2136. data->temp[i][3] =
  2137. it87_read_value(data,
  2138. IT87_REG_TEMP_OFFSET[i]);
  2139. }
  2140. /* Newer chips don't have clock dividers */
  2141. if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
  2142. i = it87_read_value(data, IT87_REG_FAN_DIV);
  2143. data->fan_div[0] = i & 0x07;
  2144. data->fan_div[1] = (i >> 3) & 0x07;
  2145. data->fan_div[2] = (i & 0x40) ? 3 : 1;
  2146. }
  2147. data->alarms =
  2148. it87_read_value(data, IT87_REG_ALARM1) |
  2149. (it87_read_value(data, IT87_REG_ALARM2) << 8) |
  2150. (it87_read_value(data, IT87_REG_ALARM3) << 16);
  2151. data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
  2152. data->fan_main_ctrl = it87_read_value(data,
  2153. IT87_REG_FAN_MAIN_CTRL);
  2154. data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
  2155. for (i = 0; i < 3; i++)
  2156. it87_update_pwm_ctrl(data, i);
  2157. data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
  2158. /*
  2159. * The IT8705F does not have VID capability.
  2160. * The IT8718F and later don't use IT87_REG_VID for the
  2161. * same purpose.
  2162. */
  2163. if (data->type == it8712 || data->type == it8716) {
  2164. data->vid = it87_read_value(data, IT87_REG_VID);
  2165. /*
  2166. * The older IT8712F revisions had only 5 VID pins,
  2167. * but we assume it is always safe to read 6 bits.
  2168. */
  2169. data->vid &= 0x3f;
  2170. }
  2171. data->last_updated = jiffies;
  2172. data->valid = 1;
  2173. }
  2174. mutex_unlock(&data->update_lock);
  2175. return data;
  2176. }
  2177. static int __init it87_device_add(unsigned short address,
  2178. const struct it87_sio_data *sio_data)
  2179. {
  2180. struct resource res = {
  2181. .start = address + IT87_EC_OFFSET,
  2182. .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
  2183. .name = DRVNAME,
  2184. .flags = IORESOURCE_IO,
  2185. };
  2186. int err;
  2187. err = acpi_check_resource_conflict(&res);
  2188. if (err)
  2189. goto exit;
  2190. pdev = platform_device_alloc(DRVNAME, address);
  2191. if (!pdev) {
  2192. err = -ENOMEM;
  2193. pr_err("Device allocation failed\n");
  2194. goto exit;
  2195. }
  2196. err = platform_device_add_resources(pdev, &res, 1);
  2197. if (err) {
  2198. pr_err("Device resource addition failed (%d)\n", err);
  2199. goto exit_device_put;
  2200. }
  2201. err = platform_device_add_data(pdev, sio_data,
  2202. sizeof(struct it87_sio_data));
  2203. if (err) {
  2204. pr_err("Platform data allocation failed\n");
  2205. goto exit_device_put;
  2206. }
  2207. err = platform_device_add(pdev);
  2208. if (err) {
  2209. pr_err("Device addition failed (%d)\n", err);
  2210. goto exit_device_put;
  2211. }
  2212. return 0;
  2213. exit_device_put:
  2214. platform_device_put(pdev);
  2215. exit:
  2216. return err;
  2217. }
  2218. static int __init sm_it87_init(void)
  2219. {
  2220. int err;
  2221. unsigned short isa_address = 0;
  2222. struct it87_sio_data sio_data;
  2223. memset(&sio_data, 0, sizeof(struct it87_sio_data));
  2224. err = it87_find(&isa_address, &sio_data);
  2225. if (err)
  2226. return err;
  2227. err = platform_driver_register(&it87_driver);
  2228. if (err)
  2229. return err;
  2230. err = it87_device_add(isa_address, &sio_data);
  2231. if (err) {
  2232. platform_driver_unregister(&it87_driver);
  2233. return err;
  2234. }
  2235. return 0;
  2236. }
  2237. static void __exit sm_it87_exit(void)
  2238. {
  2239. platform_device_unregister(pdev);
  2240. platform_driver_unregister(&it87_driver);
  2241. }
  2242. MODULE_AUTHOR("Chris Gauthron, Jean Delvare <khali@linux-fr.org>");
  2243. MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
  2244. module_param(update_vbat, bool, 0);
  2245. MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
  2246. module_param(fix_pwm_polarity, bool, 0);
  2247. MODULE_PARM_DESC(fix_pwm_polarity,
  2248. "Force PWM polarity to active high (DANGEROUS)");
  2249. MODULE_LICENSE("GPL");
  2250. module_init(sm_it87_init);
  2251. module_exit(sm_it87_exit);