it87.c 63 KB

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