f71882fg.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709
  1. /***************************************************************************
  2. * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
  3. * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/hwmon.h>
  27. #include <linux/hwmon-sysfs.h>
  28. #include <linux/err.h>
  29. #include <linux/mutex.h>
  30. #include <linux/io.h>
  31. #include <linux/acpi.h>
  32. #define DRVNAME "f71882fg"
  33. #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
  34. #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
  35. #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
  36. #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
  37. #define SIO_REG_LDSEL 0x07 /* Logical device select */
  38. #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
  39. #define SIO_REG_DEVREV 0x22 /* Device revision */
  40. #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
  41. #define SIO_REG_ENABLE 0x30 /* Logical device enable */
  42. #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
  43. #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
  44. #define SIO_F71808E_ID 0x0901 /* Chipset ID */
  45. #define SIO_F71808A_ID 0x1001 /* Chipset ID */
  46. #define SIO_F71858_ID 0x0507 /* Chipset ID */
  47. #define SIO_F71862_ID 0x0601 /* Chipset ID */
  48. #define SIO_F71869_ID 0x0814 /* Chipset ID */
  49. #define SIO_F71869A_ID 0x1007 /* Chipset ID */
  50. #define SIO_F71882_ID 0x0541 /* Chipset ID */
  51. #define SIO_F71889_ID 0x0723 /* Chipset ID */
  52. #define SIO_F71889E_ID 0x0909 /* Chipset ID */
  53. #define SIO_F71889A_ID 0x1005 /* Chipset ID */
  54. #define SIO_F8000_ID 0x0581 /* Chipset ID */
  55. #define SIO_F81865_ID 0x0704 /* Chipset ID */
  56. #define REGION_LENGTH 8
  57. #define ADDR_REG_OFFSET 5
  58. #define DATA_REG_OFFSET 6
  59. #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
  60. #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
  61. #define F71882FG_REG_IN(nr) (0x20 + (nr))
  62. #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
  63. #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
  64. #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
  65. #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
  66. #define F71882FG_REG_FAN_STATUS 0x92
  67. #define F71882FG_REG_FAN_BEEP 0x93
  68. #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
  69. #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
  70. #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
  71. #define F71882FG_REG_TEMP_STATUS 0x62
  72. #define F71882FG_REG_TEMP_BEEP 0x63
  73. #define F71882FG_REG_TEMP_CONFIG 0x69
  74. #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
  75. #define F71882FG_REG_TEMP_TYPE 0x6B
  76. #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
  77. #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
  78. #define F71882FG_REG_PWM_TYPE 0x94
  79. #define F71882FG_REG_PWM_ENABLE 0x96
  80. #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
  81. #define F71882FG_REG_FAN_FAULT_T 0x9F
  82. #define F71882FG_FAN_NEG_TEMP_EN 0x20
  83. #define F71882FG_FAN_PROG_SEL 0x80
  84. #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
  85. #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
  86. #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
  87. #define F71882FG_REG_START 0x01
  88. #define F71882FG_MAX_INS 9
  89. #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
  90. static unsigned short force_id;
  91. module_param(force_id, ushort, 0);
  92. MODULE_PARM_DESC(force_id, "Override the detected device ID");
  93. enum chips { f71808e, f71808a, f71858fg, f71862fg, f71869, f71869a, f71882fg,
  94. f71889fg, f71889ed, f71889a, f8000, f81865f };
  95. static const char *const f71882fg_names[] = {
  96. "f71808e",
  97. "f71808a",
  98. "f71858fg",
  99. "f71862fg",
  100. "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
  101. "f71869a",
  102. "f71882fg",
  103. "f71889fg", /* f81801u too, same id */
  104. "f71889ed",
  105. "f71889a",
  106. "f8000",
  107. "f81865f",
  108. };
  109. static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
  110. [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
  111. [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 },
  112. [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  113. [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  114. [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  115. [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  116. [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  117. [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  118. [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  119. [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  120. [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  121. [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  122. };
  123. static const char f71882fg_has_in1_alarm[] = {
  124. [f71808e] = 0,
  125. [f71808a] = 0,
  126. [f71858fg] = 0,
  127. [f71862fg] = 0,
  128. [f71869] = 0,
  129. [f71869a] = 0,
  130. [f71882fg] = 1,
  131. [f71889fg] = 1,
  132. [f71889ed] = 1,
  133. [f71889a] = 1,
  134. [f8000] = 0,
  135. [f81865f] = 1,
  136. };
  137. static const char f71882fg_fan_has_beep[] = {
  138. [f71808e] = 0,
  139. [f71808a] = 0,
  140. [f71858fg] = 0,
  141. [f71862fg] = 1,
  142. [f71869] = 1,
  143. [f71869a] = 1,
  144. [f71882fg] = 1,
  145. [f71889fg] = 1,
  146. [f71889ed] = 1,
  147. [f71889a] = 1,
  148. [f8000] = 0,
  149. [f81865f] = 1,
  150. };
  151. static const char f71882fg_nr_fans[] = {
  152. [f71808e] = 3,
  153. [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
  154. [f71858fg] = 3,
  155. [f71862fg] = 3,
  156. [f71869] = 3,
  157. [f71869a] = 3,
  158. [f71882fg] = 4,
  159. [f71889fg] = 3,
  160. [f71889ed] = 3,
  161. [f71889a] = 3,
  162. [f8000] = 3, /* +1 fan which is monitor only */
  163. [f81865f] = 2,
  164. };
  165. static const char f71882fg_temp_has_beep[] = {
  166. [f71808e] = 0,
  167. [f71808a] = 1,
  168. [f71858fg] = 0,
  169. [f71862fg] = 1,
  170. [f71869] = 1,
  171. [f71869a] = 1,
  172. [f71882fg] = 1,
  173. [f71889fg] = 1,
  174. [f71889ed] = 1,
  175. [f71889a] = 1,
  176. [f8000] = 0,
  177. [f81865f] = 1,
  178. };
  179. static const char f71882fg_nr_temps[] = {
  180. [f71808e] = 2,
  181. [f71808a] = 2,
  182. [f71858fg] = 3,
  183. [f71862fg] = 3,
  184. [f71869] = 3,
  185. [f71869a] = 3,
  186. [f71882fg] = 3,
  187. [f71889fg] = 3,
  188. [f71889ed] = 3,
  189. [f71889a] = 3,
  190. [f8000] = 3,
  191. [f81865f] = 2,
  192. };
  193. static struct platform_device *f71882fg_pdev;
  194. /* Super-I/O Function prototypes */
  195. static inline int superio_inb(int base, int reg);
  196. static inline int superio_inw(int base, int reg);
  197. static inline int superio_enter(int base);
  198. static inline void superio_select(int base, int ld);
  199. static inline void superio_exit(int base);
  200. struct f71882fg_sio_data {
  201. enum chips type;
  202. };
  203. struct f71882fg_data {
  204. unsigned short addr;
  205. enum chips type;
  206. struct device *hwmon_dev;
  207. struct mutex update_lock;
  208. int temp_start; /* temp numbering start (0 or 1) */
  209. char valid; /* !=0 if following fields are valid */
  210. char auto_point_temp_signed;
  211. unsigned long last_updated; /* In jiffies */
  212. unsigned long last_limits; /* In jiffies */
  213. /* Register Values */
  214. u8 in[F71882FG_MAX_INS];
  215. u8 in1_max;
  216. u8 in_status;
  217. u8 in_beep;
  218. u16 fan[4];
  219. u16 fan_target[4];
  220. u16 fan_full_speed[4];
  221. u8 fan_status;
  222. u8 fan_beep;
  223. /*
  224. * Note: all models have max 3 temperature channels, but on some
  225. * they are addressed as 0-2 and on others as 1-3, so for coding
  226. * convenience we reserve space for 4 channels
  227. */
  228. u16 temp[4];
  229. u8 temp_ovt[4];
  230. u8 temp_high[4];
  231. u8 temp_hyst[2]; /* 2 hysts stored per reg */
  232. u8 temp_type[4];
  233. u8 temp_status;
  234. u8 temp_beep;
  235. u8 temp_diode_open;
  236. u8 temp_config;
  237. u8 pwm[4];
  238. u8 pwm_enable;
  239. u8 pwm_auto_point_hyst[2];
  240. u8 pwm_auto_point_mapping[4];
  241. u8 pwm_auto_point_pwm[4][5];
  242. s8 pwm_auto_point_temp[4][4];
  243. };
  244. /* Sysfs in */
  245. static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
  246. char *buf);
  247. static ssize_t show_in_max(struct device *dev, struct device_attribute
  248. *devattr, char *buf);
  249. static ssize_t store_in_max(struct device *dev, struct device_attribute
  250. *devattr, const char *buf, size_t count);
  251. static ssize_t show_in_beep(struct device *dev, struct device_attribute
  252. *devattr, char *buf);
  253. static ssize_t store_in_beep(struct device *dev, struct device_attribute
  254. *devattr, const char *buf, size_t count);
  255. static ssize_t show_in_alarm(struct device *dev, struct device_attribute
  256. *devattr, char *buf);
  257. /* Sysfs Fan */
  258. static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
  259. char *buf);
  260. static ssize_t show_fan_full_speed(struct device *dev,
  261. struct device_attribute *devattr, char *buf);
  262. static ssize_t store_fan_full_speed(struct device *dev,
  263. struct device_attribute *devattr, const char *buf, size_t count);
  264. static ssize_t show_fan_beep(struct device *dev, struct device_attribute
  265. *devattr, char *buf);
  266. static ssize_t store_fan_beep(struct device *dev, struct device_attribute
  267. *devattr, const char *buf, size_t count);
  268. static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
  269. *devattr, char *buf);
  270. /* Sysfs Temp */
  271. static ssize_t show_temp(struct device *dev, struct device_attribute
  272. *devattr, char *buf);
  273. static ssize_t show_temp_max(struct device *dev, struct device_attribute
  274. *devattr, char *buf);
  275. static ssize_t store_temp_max(struct device *dev, struct device_attribute
  276. *devattr, const char *buf, size_t count);
  277. static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
  278. *devattr, char *buf);
  279. static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
  280. *devattr, const char *buf, size_t count);
  281. static ssize_t show_temp_crit(struct device *dev, struct device_attribute
  282. *devattr, char *buf);
  283. static ssize_t store_temp_crit(struct device *dev, struct device_attribute
  284. *devattr, const char *buf, size_t count);
  285. static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
  286. *devattr, char *buf);
  287. static ssize_t show_temp_type(struct device *dev, struct device_attribute
  288. *devattr, char *buf);
  289. static ssize_t show_temp_beep(struct device *dev, struct device_attribute
  290. *devattr, char *buf);
  291. static ssize_t store_temp_beep(struct device *dev, struct device_attribute
  292. *devattr, const char *buf, size_t count);
  293. static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
  294. *devattr, char *buf);
  295. static ssize_t show_temp_fault(struct device *dev, struct device_attribute
  296. *devattr, char *buf);
  297. /* PWM and Auto point control */
  298. static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
  299. char *buf);
  300. static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
  301. const char *buf, size_t count);
  302. static ssize_t show_simple_pwm(struct device *dev,
  303. struct device_attribute *devattr, char *buf);
  304. static ssize_t store_simple_pwm(struct device *dev,
  305. struct device_attribute *devattr, const char *buf, size_t count);
  306. static ssize_t show_pwm_enable(struct device *dev,
  307. struct device_attribute *devattr, char *buf);
  308. static ssize_t store_pwm_enable(struct device *dev,
  309. struct device_attribute *devattr, const char *buf, size_t count);
  310. static ssize_t show_pwm_interpolate(struct device *dev,
  311. struct device_attribute *devattr, char *buf);
  312. static ssize_t store_pwm_interpolate(struct device *dev,
  313. struct device_attribute *devattr, const char *buf, size_t count);
  314. static ssize_t show_pwm_auto_point_channel(struct device *dev,
  315. struct device_attribute *devattr, char *buf);
  316. static ssize_t store_pwm_auto_point_channel(struct device *dev,
  317. struct device_attribute *devattr, const char *buf, size_t count);
  318. static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
  319. struct device_attribute *devattr, char *buf);
  320. static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
  321. struct device_attribute *devattr, const char *buf, size_t count);
  322. static ssize_t show_pwm_auto_point_pwm(struct device *dev,
  323. struct device_attribute *devattr, char *buf);
  324. static ssize_t store_pwm_auto_point_pwm(struct device *dev,
  325. struct device_attribute *devattr, const char *buf, size_t count);
  326. static ssize_t show_pwm_auto_point_temp(struct device *dev,
  327. struct device_attribute *devattr, char *buf);
  328. static ssize_t store_pwm_auto_point_temp(struct device *dev,
  329. struct device_attribute *devattr, const char *buf, size_t count);
  330. /* Sysfs misc */
  331. static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
  332. char *buf);
  333. static int __devinit f71882fg_probe(struct platform_device *pdev);
  334. static int f71882fg_remove(struct platform_device *pdev);
  335. static struct platform_driver f71882fg_driver = {
  336. .driver = {
  337. .owner = THIS_MODULE,
  338. .name = DRVNAME,
  339. },
  340. .probe = f71882fg_probe,
  341. .remove = f71882fg_remove,
  342. };
  343. static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  344. /*
  345. * Temp attr for the f71858fg, the f71858fg is special as it has its
  346. * temperature indexes start at 0 (the others start at 1)
  347. */
  348. static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
  349. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
  350. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
  351. store_temp_max, 0, 0),
  352. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  353. store_temp_max_hyst, 0, 0),
  354. SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
  355. SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  356. store_temp_crit, 0, 0),
  357. SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  358. 0, 0),
  359. SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
  360. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
  361. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
  362. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
  363. store_temp_max, 0, 1),
  364. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  365. store_temp_max_hyst, 0, 1),
  366. SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
  367. SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  368. store_temp_crit, 0, 1),
  369. SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  370. 0, 1),
  371. SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  372. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  373. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
  374. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
  375. store_temp_max, 0, 2),
  376. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  377. store_temp_max_hyst, 0, 2),
  378. SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
  379. SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  380. store_temp_crit, 0, 2),
  381. SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  382. 0, 2),
  383. SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  384. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  385. };
  386. /* Temp attr for the standard models */
  387. static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
  388. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
  389. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
  390. store_temp_max, 0, 1),
  391. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  392. store_temp_max_hyst, 0, 1),
  393. /*
  394. * Should really be temp1_max_alarm, but older versions did not handle
  395. * the max and crit alarms separately and lm_sensors v2 depends on the
  396. * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
  397. */
  398. SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
  399. SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  400. store_temp_crit, 0, 1),
  401. SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  402. 0, 1),
  403. SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  404. SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
  405. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  406. }, {
  407. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
  408. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
  409. store_temp_max, 0, 2),
  410. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  411. store_temp_max_hyst, 0, 2),
  412. /* Should be temp2_max_alarm, see temp1_alarm note */
  413. SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
  414. SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  415. store_temp_crit, 0, 2),
  416. SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  417. 0, 2),
  418. SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  419. SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
  420. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  421. }, {
  422. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
  423. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
  424. store_temp_max, 0, 3),
  425. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
  426. store_temp_max_hyst, 0, 3),
  427. /* Should be temp3_max_alarm, see temp1_alarm note */
  428. SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
  429. SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
  430. store_temp_crit, 0, 3),
  431. SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
  432. 0, 3),
  433. SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
  434. SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
  435. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
  436. } };
  437. /* Temp attr for models which can beep on temp alarm */
  438. static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
  439. SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  440. store_temp_beep, 0, 1),
  441. SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  442. store_temp_beep, 0, 5),
  443. }, {
  444. SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  445. store_temp_beep, 0, 2),
  446. SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  447. store_temp_beep, 0, 6),
  448. }, {
  449. SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  450. store_temp_beep, 0, 3),
  451. SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
  452. store_temp_beep, 0, 7),
  453. } };
  454. /*
  455. * Temp attr for the f8000
  456. * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
  457. * is used as hysteresis value to clear alarms
  458. * Also like the f71858fg its temperature indexes start at 0
  459. */
  460. static struct sensor_device_attribute_2 f8000_temp_attr[] = {
  461. SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
  462. SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
  463. store_temp_crit, 0, 0),
  464. SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  465. store_temp_max, 0, 0),
  466. SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
  467. SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
  468. SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
  469. SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
  470. store_temp_crit, 0, 1),
  471. SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  472. store_temp_max, 0, 1),
  473. SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
  474. SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
  475. SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
  476. SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
  477. store_temp_crit, 0, 2),
  478. SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
  479. store_temp_max, 0, 2),
  480. SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
  481. SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
  482. };
  483. /* in attr for all models */
  484. static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
  485. SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
  486. SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
  487. SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
  488. SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
  489. SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
  490. SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
  491. SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
  492. SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
  493. SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
  494. };
  495. /* For models with in1 alarm capability */
  496. static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
  497. SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
  498. 0, 1),
  499. SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
  500. 0, 1),
  501. SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
  502. };
  503. /* Fan / PWM attr common to all models */
  504. static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
  505. SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
  506. SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
  507. show_fan_full_speed,
  508. store_fan_full_speed, 0, 0),
  509. SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
  510. SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
  511. SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  512. store_pwm_enable, 0, 0),
  513. SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
  514. show_pwm_interpolate, store_pwm_interpolate, 0, 0),
  515. }, {
  516. SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
  517. SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
  518. show_fan_full_speed,
  519. store_fan_full_speed, 0, 1),
  520. SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
  521. SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
  522. SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  523. store_pwm_enable, 0, 1),
  524. SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
  525. show_pwm_interpolate, store_pwm_interpolate, 0, 1),
  526. }, {
  527. SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
  528. SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
  529. show_fan_full_speed,
  530. store_fan_full_speed, 0, 2),
  531. SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
  532. SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
  533. SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  534. store_pwm_enable, 0, 2),
  535. SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
  536. show_pwm_interpolate, store_pwm_interpolate, 0, 2),
  537. }, {
  538. SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
  539. SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
  540. show_fan_full_speed,
  541. store_fan_full_speed, 0, 3),
  542. SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
  543. SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
  544. SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
  545. store_pwm_enable, 0, 3),
  546. SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
  547. show_pwm_interpolate, store_pwm_interpolate, 0, 3),
  548. } };
  549. /* Attr for the third fan of the f71808a, which only has manual pwm */
  550. static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
  551. SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
  552. SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
  553. SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
  554. show_simple_pwm, store_simple_pwm, 0, 2),
  555. };
  556. /* Attr for models which can beep on Fan alarm */
  557. static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
  558. SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  559. store_fan_beep, 0, 0),
  560. SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  561. store_fan_beep, 0, 1),
  562. SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  563. store_fan_beep, 0, 2),
  564. SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
  565. store_fan_beep, 0, 3),
  566. };
  567. /*
  568. * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
  569. * standard models
  570. */
  571. static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
  572. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  573. show_pwm_auto_point_channel,
  574. store_pwm_auto_point_channel, 0, 0),
  575. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  576. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  577. 1, 0),
  578. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  579. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  580. 4, 0),
  581. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  582. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  583. 0, 0),
  584. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  585. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  586. 3, 0),
  587. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  588. show_pwm_auto_point_temp_hyst,
  589. store_pwm_auto_point_temp_hyst,
  590. 0, 0),
  591. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  592. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  593. }, {
  594. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  595. show_pwm_auto_point_channel,
  596. store_pwm_auto_point_channel, 0, 1),
  597. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  598. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  599. 1, 1),
  600. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  601. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  602. 4, 1),
  603. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  604. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  605. 0, 1),
  606. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  607. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  608. 3, 1),
  609. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  610. show_pwm_auto_point_temp_hyst,
  611. store_pwm_auto_point_temp_hyst,
  612. 0, 1),
  613. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  614. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  615. }, {
  616. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  617. show_pwm_auto_point_channel,
  618. store_pwm_auto_point_channel, 0, 2),
  619. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  620. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  621. 1, 2),
  622. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  623. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  624. 4, 2),
  625. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  626. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  627. 0, 2),
  628. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  629. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  630. 3, 2),
  631. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  632. show_pwm_auto_point_temp_hyst,
  633. store_pwm_auto_point_temp_hyst,
  634. 0, 2),
  635. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  636. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  637. } };
  638. /*
  639. * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
  640. * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
  641. * programmed instead of being hardcoded to 0xff
  642. */
  643. static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
  644. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  645. show_pwm_auto_point_channel,
  646. store_pwm_auto_point_channel, 0, 0),
  647. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  648. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  649. 0, 0),
  650. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  651. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  652. 1, 0),
  653. SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  654. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  655. 4, 0),
  656. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  657. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  658. 0, 0),
  659. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  660. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  661. 3, 0),
  662. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  663. show_pwm_auto_point_temp_hyst,
  664. store_pwm_auto_point_temp_hyst,
  665. 0, 0),
  666. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  667. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  668. }, {
  669. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  670. show_pwm_auto_point_channel,
  671. store_pwm_auto_point_channel, 0, 1),
  672. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  673. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  674. 0, 1),
  675. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  676. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  677. 1, 1),
  678. SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  679. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  680. 4, 1),
  681. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  682. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  683. 0, 1),
  684. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  685. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  686. 3, 1),
  687. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  688. show_pwm_auto_point_temp_hyst,
  689. store_pwm_auto_point_temp_hyst,
  690. 0, 1),
  691. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  692. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  693. }, {
  694. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  695. show_pwm_auto_point_channel,
  696. store_pwm_auto_point_channel, 0, 2),
  697. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  698. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  699. 0, 2),
  700. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  701. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  702. 1, 2),
  703. SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  704. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  705. 4, 2),
  706. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  707. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  708. 0, 2),
  709. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  710. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  711. 3, 2),
  712. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  713. show_pwm_auto_point_temp_hyst,
  714. store_pwm_auto_point_temp_hyst,
  715. 0, 2),
  716. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  717. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  718. } };
  719. /* PWM attr for the standard models */
  720. static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
  721. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  722. show_pwm_auto_point_channel,
  723. store_pwm_auto_point_channel, 0, 0),
  724. SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  725. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  726. 0, 0),
  727. SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  728. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  729. 1, 0),
  730. SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  731. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  732. 2, 0),
  733. SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
  734. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  735. 3, 0),
  736. SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
  737. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  738. 4, 0),
  739. SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
  740. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  741. 0, 0),
  742. SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
  743. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  744. 1, 0),
  745. SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
  746. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  747. 2, 0),
  748. SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
  749. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  750. 3, 0),
  751. SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  752. show_pwm_auto_point_temp_hyst,
  753. store_pwm_auto_point_temp_hyst,
  754. 0, 0),
  755. SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
  756. show_pwm_auto_point_temp_hyst, NULL, 1, 0),
  757. SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
  758. show_pwm_auto_point_temp_hyst, NULL, 2, 0),
  759. SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
  760. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  761. }, {
  762. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  763. show_pwm_auto_point_channel,
  764. store_pwm_auto_point_channel, 0, 1),
  765. SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  766. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  767. 0, 1),
  768. SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  769. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  770. 1, 1),
  771. SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  772. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  773. 2, 1),
  774. SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
  775. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  776. 3, 1),
  777. SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
  778. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  779. 4, 1),
  780. SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
  781. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  782. 0, 1),
  783. SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
  784. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  785. 1, 1),
  786. SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
  787. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  788. 2, 1),
  789. SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
  790. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  791. 3, 1),
  792. SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  793. show_pwm_auto_point_temp_hyst,
  794. store_pwm_auto_point_temp_hyst,
  795. 0, 1),
  796. SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
  797. show_pwm_auto_point_temp_hyst, NULL, 1, 1),
  798. SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
  799. show_pwm_auto_point_temp_hyst, NULL, 2, 1),
  800. SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
  801. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  802. }, {
  803. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  804. show_pwm_auto_point_channel,
  805. store_pwm_auto_point_channel, 0, 2),
  806. SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  807. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  808. 0, 2),
  809. SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  810. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  811. 1, 2),
  812. SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  813. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  814. 2, 2),
  815. SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
  816. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  817. 3, 2),
  818. SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
  819. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  820. 4, 2),
  821. SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
  822. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  823. 0, 2),
  824. SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
  825. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  826. 1, 2),
  827. SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
  828. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  829. 2, 2),
  830. SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
  831. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  832. 3, 2),
  833. SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  834. show_pwm_auto_point_temp_hyst,
  835. store_pwm_auto_point_temp_hyst,
  836. 0, 2),
  837. SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
  838. show_pwm_auto_point_temp_hyst, NULL, 1, 2),
  839. SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
  840. show_pwm_auto_point_temp_hyst, NULL, 2, 2),
  841. SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
  842. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  843. }, {
  844. SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
  845. show_pwm_auto_point_channel,
  846. store_pwm_auto_point_channel, 0, 3),
  847. SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
  848. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  849. 0, 3),
  850. SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
  851. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  852. 1, 3),
  853. SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
  854. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  855. 2, 3),
  856. SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
  857. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  858. 3, 3),
  859. SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
  860. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  861. 4, 3),
  862. SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
  863. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  864. 0, 3),
  865. SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
  866. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  867. 1, 3),
  868. SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
  869. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  870. 2, 3),
  871. SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
  872. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  873. 3, 3),
  874. SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  875. show_pwm_auto_point_temp_hyst,
  876. store_pwm_auto_point_temp_hyst,
  877. 0, 3),
  878. SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
  879. show_pwm_auto_point_temp_hyst, NULL, 1, 3),
  880. SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
  881. show_pwm_auto_point_temp_hyst, NULL, 2, 3),
  882. SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
  883. show_pwm_auto_point_temp_hyst, NULL, 3, 3),
  884. } };
  885. /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
  886. static struct sensor_device_attribute_2 f8000_fan_attr[] = {
  887. SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
  888. };
  889. /*
  890. * PWM attr for the f8000, zones mapped to temp instead of to pwm!
  891. * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
  892. * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
  893. */
  894. static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
  895. SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
  896. show_pwm_auto_point_channel,
  897. store_pwm_auto_point_channel, 0, 0),
  898. SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
  899. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  900. 0, 2),
  901. SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
  902. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  903. 1, 2),
  904. SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
  905. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  906. 2, 2),
  907. SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
  908. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  909. 3, 2),
  910. SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
  911. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  912. 4, 2),
  913. SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
  914. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  915. 0, 2),
  916. SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
  917. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  918. 1, 2),
  919. SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
  920. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  921. 2, 2),
  922. SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
  923. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  924. 3, 2),
  925. SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  926. show_pwm_auto_point_temp_hyst,
  927. store_pwm_auto_point_temp_hyst,
  928. 0, 2),
  929. SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
  930. show_pwm_auto_point_temp_hyst, NULL, 1, 2),
  931. SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
  932. show_pwm_auto_point_temp_hyst, NULL, 2, 2),
  933. SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
  934. show_pwm_auto_point_temp_hyst, NULL, 3, 2),
  935. }, {
  936. SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
  937. show_pwm_auto_point_channel,
  938. store_pwm_auto_point_channel, 0, 1),
  939. SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
  940. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  941. 0, 0),
  942. SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
  943. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  944. 1, 0),
  945. SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
  946. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  947. 2, 0),
  948. SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
  949. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  950. 3, 0),
  951. SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
  952. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  953. 4, 0),
  954. SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
  955. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  956. 0, 0),
  957. SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
  958. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  959. 1, 0),
  960. SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
  961. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  962. 2, 0),
  963. SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
  964. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  965. 3, 0),
  966. SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  967. show_pwm_auto_point_temp_hyst,
  968. store_pwm_auto_point_temp_hyst,
  969. 0, 0),
  970. SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
  971. show_pwm_auto_point_temp_hyst, NULL, 1, 0),
  972. SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
  973. show_pwm_auto_point_temp_hyst, NULL, 2, 0),
  974. SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
  975. show_pwm_auto_point_temp_hyst, NULL, 3, 0),
  976. }, {
  977. SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
  978. show_pwm_auto_point_channel,
  979. store_pwm_auto_point_channel, 0, 2),
  980. SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
  981. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  982. 0, 1),
  983. SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
  984. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  985. 1, 1),
  986. SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
  987. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  988. 2, 1),
  989. SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
  990. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  991. 3, 1),
  992. SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
  993. show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
  994. 4, 1),
  995. SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
  996. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  997. 0, 1),
  998. SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
  999. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1000. 1, 1),
  1001. SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
  1002. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1003. 2, 1),
  1004. SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
  1005. show_pwm_auto_point_temp, store_pwm_auto_point_temp,
  1006. 3, 1),
  1007. SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
  1008. show_pwm_auto_point_temp_hyst,
  1009. store_pwm_auto_point_temp_hyst,
  1010. 0, 1),
  1011. SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
  1012. show_pwm_auto_point_temp_hyst, NULL, 1, 1),
  1013. SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
  1014. show_pwm_auto_point_temp_hyst, NULL, 2, 1),
  1015. SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
  1016. show_pwm_auto_point_temp_hyst, NULL, 3, 1),
  1017. } };
  1018. /* Super I/O functions */
  1019. static inline int superio_inb(int base, int reg)
  1020. {
  1021. outb(reg, base);
  1022. return inb(base + 1);
  1023. }
  1024. static int superio_inw(int base, int reg)
  1025. {
  1026. int val;
  1027. val = superio_inb(base, reg) << 8;
  1028. val |= superio_inb(base, reg + 1);
  1029. return val;
  1030. }
  1031. static inline int superio_enter(int base)
  1032. {
  1033. /* Don't step on other drivers' I/O space by accident */
  1034. if (!request_muxed_region(base, 2, DRVNAME)) {
  1035. pr_err("I/O address 0x%04x already in use\n", base);
  1036. return -EBUSY;
  1037. }
  1038. /* according to the datasheet the key must be send twice! */
  1039. outb(SIO_UNLOCK_KEY, base);
  1040. outb(SIO_UNLOCK_KEY, base);
  1041. return 0;
  1042. }
  1043. static inline void superio_select(int base, int ld)
  1044. {
  1045. outb(SIO_REG_LDSEL, base);
  1046. outb(ld, base + 1);
  1047. }
  1048. static inline void superio_exit(int base)
  1049. {
  1050. outb(SIO_LOCK_KEY, base);
  1051. release_region(base, 2);
  1052. }
  1053. static inline int fan_from_reg(u16 reg)
  1054. {
  1055. return reg ? (1500000 / reg) : 0;
  1056. }
  1057. static inline u16 fan_to_reg(int fan)
  1058. {
  1059. return fan ? (1500000 / fan) : 0;
  1060. }
  1061. static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
  1062. {
  1063. u8 val;
  1064. outb(reg, data->addr + ADDR_REG_OFFSET);
  1065. val = inb(data->addr + DATA_REG_OFFSET);
  1066. return val;
  1067. }
  1068. static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
  1069. {
  1070. u16 val;
  1071. val = f71882fg_read8(data, reg) << 8;
  1072. val |= f71882fg_read8(data, reg + 1);
  1073. return val;
  1074. }
  1075. static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
  1076. {
  1077. outb(reg, data->addr + ADDR_REG_OFFSET);
  1078. outb(val, data->addr + DATA_REG_OFFSET);
  1079. }
  1080. static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
  1081. {
  1082. f71882fg_write8(data, reg, val >> 8);
  1083. f71882fg_write8(data, reg + 1, val & 0xff);
  1084. }
  1085. static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
  1086. {
  1087. if (data->type == f71858fg)
  1088. return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
  1089. else
  1090. return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
  1091. }
  1092. static struct f71882fg_data *f71882fg_update_device(struct device *dev)
  1093. {
  1094. struct f71882fg_data *data = dev_get_drvdata(dev);
  1095. int nr_fans = f71882fg_nr_fans[data->type];
  1096. int nr_temps = f71882fg_nr_temps[data->type];
  1097. int nr, reg, point;
  1098. mutex_lock(&data->update_lock);
  1099. /* Update once every 60 seconds */
  1100. if (time_after(jiffies, data->last_limits + 60 * HZ) ||
  1101. !data->valid) {
  1102. if (f71882fg_has_in1_alarm[data->type]) {
  1103. data->in1_max =
  1104. f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
  1105. data->in_beep =
  1106. f71882fg_read8(data, F71882FG_REG_IN_BEEP);
  1107. }
  1108. /* Get High & boundary temps*/
  1109. for (nr = data->temp_start; nr < nr_temps + data->temp_start;
  1110. nr++) {
  1111. data->temp_ovt[nr] = f71882fg_read8(data,
  1112. F71882FG_REG_TEMP_OVT(nr));
  1113. data->temp_high[nr] = f71882fg_read8(data,
  1114. F71882FG_REG_TEMP_HIGH(nr));
  1115. }
  1116. if (data->type != f8000) {
  1117. data->temp_hyst[0] = f71882fg_read8(data,
  1118. F71882FG_REG_TEMP_HYST(0));
  1119. data->temp_hyst[1] = f71882fg_read8(data,
  1120. F71882FG_REG_TEMP_HYST(1));
  1121. }
  1122. /* All but the f71858fg / f8000 have this register */
  1123. if ((data->type != f71858fg) && (data->type != f8000)) {
  1124. reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
  1125. data->temp_type[1] = (reg & 0x02) ? 2 : 4;
  1126. data->temp_type[2] = (reg & 0x04) ? 2 : 4;
  1127. data->temp_type[3] = (reg & 0x08) ? 2 : 4;
  1128. }
  1129. if (f71882fg_fan_has_beep[data->type])
  1130. data->fan_beep = f71882fg_read8(data,
  1131. F71882FG_REG_FAN_BEEP);
  1132. if (f71882fg_temp_has_beep[data->type])
  1133. data->temp_beep = f71882fg_read8(data,
  1134. F71882FG_REG_TEMP_BEEP);
  1135. data->pwm_enable = f71882fg_read8(data,
  1136. F71882FG_REG_PWM_ENABLE);
  1137. data->pwm_auto_point_hyst[0] =
  1138. f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
  1139. data->pwm_auto_point_hyst[1] =
  1140. f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
  1141. for (nr = 0; nr < nr_fans; nr++) {
  1142. data->pwm_auto_point_mapping[nr] =
  1143. f71882fg_read8(data,
  1144. F71882FG_REG_POINT_MAPPING(nr));
  1145. switch (data->type) {
  1146. default:
  1147. for (point = 0; point < 5; point++) {
  1148. data->pwm_auto_point_pwm[nr][point] =
  1149. f71882fg_read8(data,
  1150. F71882FG_REG_POINT_PWM
  1151. (nr, point));
  1152. }
  1153. for (point = 0; point < 4; point++) {
  1154. data->pwm_auto_point_temp[nr][point] =
  1155. f71882fg_read8(data,
  1156. F71882FG_REG_POINT_TEMP
  1157. (nr, point));
  1158. }
  1159. break;
  1160. case f71808e:
  1161. case f71869:
  1162. data->pwm_auto_point_pwm[nr][0] =
  1163. f71882fg_read8(data,
  1164. F71882FG_REG_POINT_PWM(nr, 0));
  1165. /* Fall through */
  1166. case f71862fg:
  1167. data->pwm_auto_point_pwm[nr][1] =
  1168. f71882fg_read8(data,
  1169. F71882FG_REG_POINT_PWM
  1170. (nr, 1));
  1171. data->pwm_auto_point_pwm[nr][4] =
  1172. f71882fg_read8(data,
  1173. F71882FG_REG_POINT_PWM
  1174. (nr, 4));
  1175. data->pwm_auto_point_temp[nr][0] =
  1176. f71882fg_read8(data,
  1177. F71882FG_REG_POINT_TEMP
  1178. (nr, 0));
  1179. data->pwm_auto_point_temp[nr][3] =
  1180. f71882fg_read8(data,
  1181. F71882FG_REG_POINT_TEMP
  1182. (nr, 3));
  1183. break;
  1184. }
  1185. }
  1186. data->last_limits = jiffies;
  1187. }
  1188. /* Update every second */
  1189. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  1190. data->temp_status = f71882fg_read8(data,
  1191. F71882FG_REG_TEMP_STATUS);
  1192. data->temp_diode_open = f71882fg_read8(data,
  1193. F71882FG_REG_TEMP_DIODE_OPEN);
  1194. for (nr = data->temp_start; nr < nr_temps + data->temp_start;
  1195. nr++)
  1196. data->temp[nr] = f71882fg_read_temp(data, nr);
  1197. data->fan_status = f71882fg_read8(data,
  1198. F71882FG_REG_FAN_STATUS);
  1199. for (nr = 0; nr < nr_fans; nr++) {
  1200. data->fan[nr] = f71882fg_read16(data,
  1201. F71882FG_REG_FAN(nr));
  1202. data->fan_target[nr] =
  1203. f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
  1204. data->fan_full_speed[nr] =
  1205. f71882fg_read16(data,
  1206. F71882FG_REG_FAN_FULL_SPEED(nr));
  1207. data->pwm[nr] =
  1208. f71882fg_read8(data, F71882FG_REG_PWM(nr));
  1209. }
  1210. /* Some models have 1 more fan with limited capabilities */
  1211. if (data->type == f71808a) {
  1212. data->fan[2] = f71882fg_read16(data,
  1213. F71882FG_REG_FAN(2));
  1214. data->pwm[2] = f71882fg_read8(data,
  1215. F71882FG_REG_PWM(2));
  1216. }
  1217. if (data->type == f8000)
  1218. data->fan[3] = f71882fg_read16(data,
  1219. F71882FG_REG_FAN(3));
  1220. if (f71882fg_has_in1_alarm[data->type])
  1221. data->in_status = f71882fg_read8(data,
  1222. F71882FG_REG_IN_STATUS);
  1223. for (nr = 0; nr < F71882FG_MAX_INS; nr++)
  1224. if (f71882fg_has_in[data->type][nr])
  1225. data->in[nr] = f71882fg_read8(data,
  1226. F71882FG_REG_IN(nr));
  1227. data->last_updated = jiffies;
  1228. data->valid = 1;
  1229. }
  1230. mutex_unlock(&data->update_lock);
  1231. return data;
  1232. }
  1233. /* Sysfs Interface */
  1234. static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
  1235. char *buf)
  1236. {
  1237. struct f71882fg_data *data = f71882fg_update_device(dev);
  1238. int nr = to_sensor_dev_attr_2(devattr)->index;
  1239. int speed = fan_from_reg(data->fan[nr]);
  1240. if (speed == FAN_MIN_DETECT)
  1241. speed = 0;
  1242. return sprintf(buf, "%d\n", speed);
  1243. }
  1244. static ssize_t show_fan_full_speed(struct device *dev,
  1245. struct device_attribute *devattr, char *buf)
  1246. {
  1247. struct f71882fg_data *data = f71882fg_update_device(dev);
  1248. int nr = to_sensor_dev_attr_2(devattr)->index;
  1249. int speed = fan_from_reg(data->fan_full_speed[nr]);
  1250. return sprintf(buf, "%d\n", speed);
  1251. }
  1252. static ssize_t store_fan_full_speed(struct device *dev,
  1253. struct device_attribute *devattr,
  1254. const char *buf, size_t count)
  1255. {
  1256. struct f71882fg_data *data = dev_get_drvdata(dev);
  1257. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1258. long val;
  1259. err = kstrtol(buf, 10, &val);
  1260. if (err)
  1261. return err;
  1262. val = SENSORS_LIMIT(val, 23, 1500000);
  1263. val = fan_to_reg(val);
  1264. mutex_lock(&data->update_lock);
  1265. f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
  1266. data->fan_full_speed[nr] = val;
  1267. mutex_unlock(&data->update_lock);
  1268. return count;
  1269. }
  1270. static ssize_t show_fan_beep(struct device *dev, struct device_attribute
  1271. *devattr, char *buf)
  1272. {
  1273. struct f71882fg_data *data = f71882fg_update_device(dev);
  1274. int nr = to_sensor_dev_attr_2(devattr)->index;
  1275. if (data->fan_beep & (1 << nr))
  1276. return sprintf(buf, "1\n");
  1277. else
  1278. return sprintf(buf, "0\n");
  1279. }
  1280. static ssize_t store_fan_beep(struct device *dev, struct device_attribute
  1281. *devattr, const char *buf, size_t count)
  1282. {
  1283. struct f71882fg_data *data = dev_get_drvdata(dev);
  1284. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1285. unsigned long val;
  1286. err = kstrtoul(buf, 10, &val);
  1287. if (err)
  1288. return err;
  1289. mutex_lock(&data->update_lock);
  1290. data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
  1291. if (val)
  1292. data->fan_beep |= 1 << nr;
  1293. else
  1294. data->fan_beep &= ~(1 << nr);
  1295. f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
  1296. mutex_unlock(&data->update_lock);
  1297. return count;
  1298. }
  1299. static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
  1300. *devattr, char *buf)
  1301. {
  1302. struct f71882fg_data *data = f71882fg_update_device(dev);
  1303. int nr = to_sensor_dev_attr_2(devattr)->index;
  1304. if (data->fan_status & (1 << nr))
  1305. return sprintf(buf, "1\n");
  1306. else
  1307. return sprintf(buf, "0\n");
  1308. }
  1309. static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
  1310. char *buf)
  1311. {
  1312. struct f71882fg_data *data = f71882fg_update_device(dev);
  1313. int nr = to_sensor_dev_attr_2(devattr)->index;
  1314. return sprintf(buf, "%d\n", data->in[nr] * 8);
  1315. }
  1316. static ssize_t show_in_max(struct device *dev, struct device_attribute
  1317. *devattr, char *buf)
  1318. {
  1319. struct f71882fg_data *data = f71882fg_update_device(dev);
  1320. return sprintf(buf, "%d\n", data->in1_max * 8);
  1321. }
  1322. static ssize_t store_in_max(struct device *dev, struct device_attribute
  1323. *devattr, const char *buf, size_t count)
  1324. {
  1325. struct f71882fg_data *data = dev_get_drvdata(dev);
  1326. int err;
  1327. long val;
  1328. err = kstrtol(buf, 10, &val);
  1329. if (err)
  1330. return err;
  1331. val /= 8;
  1332. val = SENSORS_LIMIT(val, 0, 255);
  1333. mutex_lock(&data->update_lock);
  1334. f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
  1335. data->in1_max = val;
  1336. mutex_unlock(&data->update_lock);
  1337. return count;
  1338. }
  1339. static ssize_t show_in_beep(struct device *dev, struct device_attribute
  1340. *devattr, char *buf)
  1341. {
  1342. struct f71882fg_data *data = f71882fg_update_device(dev);
  1343. int nr = to_sensor_dev_attr_2(devattr)->index;
  1344. if (data->in_beep & (1 << nr))
  1345. return sprintf(buf, "1\n");
  1346. else
  1347. return sprintf(buf, "0\n");
  1348. }
  1349. static ssize_t store_in_beep(struct device *dev, struct device_attribute
  1350. *devattr, const char *buf, size_t count)
  1351. {
  1352. struct f71882fg_data *data = dev_get_drvdata(dev);
  1353. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1354. unsigned long val;
  1355. err = kstrtoul(buf, 10, &val);
  1356. if (err)
  1357. return err;
  1358. mutex_lock(&data->update_lock);
  1359. data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
  1360. if (val)
  1361. data->in_beep |= 1 << nr;
  1362. else
  1363. data->in_beep &= ~(1 << nr);
  1364. f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
  1365. mutex_unlock(&data->update_lock);
  1366. return count;
  1367. }
  1368. static ssize_t show_in_alarm(struct device *dev, struct device_attribute
  1369. *devattr, char *buf)
  1370. {
  1371. struct f71882fg_data *data = f71882fg_update_device(dev);
  1372. int nr = to_sensor_dev_attr_2(devattr)->index;
  1373. if (data->in_status & (1 << nr))
  1374. return sprintf(buf, "1\n");
  1375. else
  1376. return sprintf(buf, "0\n");
  1377. }
  1378. static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
  1379. char *buf)
  1380. {
  1381. struct f71882fg_data *data = f71882fg_update_device(dev);
  1382. int nr = to_sensor_dev_attr_2(devattr)->index;
  1383. int sign, temp;
  1384. if (data->type == f71858fg) {
  1385. /* TEMP_TABLE_SEL 1 or 3 ? */
  1386. if (data->temp_config & 1) {
  1387. sign = data->temp[nr] & 0x0001;
  1388. temp = (data->temp[nr] >> 5) & 0x7ff;
  1389. } else {
  1390. sign = data->temp[nr] & 0x8000;
  1391. temp = (data->temp[nr] >> 5) & 0x3ff;
  1392. }
  1393. temp *= 125;
  1394. if (sign)
  1395. temp -= 128000;
  1396. } else
  1397. temp = data->temp[nr] * 1000;
  1398. return sprintf(buf, "%d\n", temp);
  1399. }
  1400. static ssize_t show_temp_max(struct device *dev, struct device_attribute
  1401. *devattr, char *buf)
  1402. {
  1403. struct f71882fg_data *data = f71882fg_update_device(dev);
  1404. int nr = to_sensor_dev_attr_2(devattr)->index;
  1405. return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
  1406. }
  1407. static ssize_t store_temp_max(struct device *dev, struct device_attribute
  1408. *devattr, const char *buf, size_t count)
  1409. {
  1410. struct f71882fg_data *data = dev_get_drvdata(dev);
  1411. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1412. long val;
  1413. err = kstrtol(buf, 10, &val);
  1414. if (err)
  1415. return err;
  1416. val /= 1000;
  1417. val = SENSORS_LIMIT(val, 0, 255);
  1418. mutex_lock(&data->update_lock);
  1419. f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
  1420. data->temp_high[nr] = val;
  1421. mutex_unlock(&data->update_lock);
  1422. return count;
  1423. }
  1424. static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
  1425. *devattr, char *buf)
  1426. {
  1427. struct f71882fg_data *data = f71882fg_update_device(dev);
  1428. int nr = to_sensor_dev_attr_2(devattr)->index;
  1429. int temp_max_hyst;
  1430. mutex_lock(&data->update_lock);
  1431. if (nr & 1)
  1432. temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
  1433. else
  1434. temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
  1435. temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
  1436. mutex_unlock(&data->update_lock);
  1437. return sprintf(buf, "%d\n", temp_max_hyst);
  1438. }
  1439. static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
  1440. *devattr, const char *buf, size_t count)
  1441. {
  1442. struct f71882fg_data *data = dev_get_drvdata(dev);
  1443. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1444. ssize_t ret = count;
  1445. u8 reg;
  1446. long val;
  1447. err = kstrtol(buf, 10, &val);
  1448. if (err)
  1449. return err;
  1450. val /= 1000;
  1451. mutex_lock(&data->update_lock);
  1452. /* convert abs to relative and check */
  1453. data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
  1454. val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
  1455. data->temp_high[nr]);
  1456. val = data->temp_high[nr] - val;
  1457. /* convert value to register contents */
  1458. reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
  1459. if (nr & 1)
  1460. reg = (reg & 0x0f) | (val << 4);
  1461. else
  1462. reg = (reg & 0xf0) | val;
  1463. f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
  1464. data->temp_hyst[nr / 2] = reg;
  1465. mutex_unlock(&data->update_lock);
  1466. return ret;
  1467. }
  1468. static ssize_t show_temp_crit(struct device *dev, struct device_attribute
  1469. *devattr, char *buf)
  1470. {
  1471. struct f71882fg_data *data = f71882fg_update_device(dev);
  1472. int nr = to_sensor_dev_attr_2(devattr)->index;
  1473. return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
  1474. }
  1475. static ssize_t store_temp_crit(struct device *dev, struct device_attribute
  1476. *devattr, const char *buf, size_t count)
  1477. {
  1478. struct f71882fg_data *data = dev_get_drvdata(dev);
  1479. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1480. long val;
  1481. err = kstrtol(buf, 10, &val);
  1482. if (err)
  1483. return err;
  1484. val /= 1000;
  1485. val = SENSORS_LIMIT(val, 0, 255);
  1486. mutex_lock(&data->update_lock);
  1487. f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
  1488. data->temp_ovt[nr] = val;
  1489. mutex_unlock(&data->update_lock);
  1490. return count;
  1491. }
  1492. static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
  1493. *devattr, char *buf)
  1494. {
  1495. struct f71882fg_data *data = f71882fg_update_device(dev);
  1496. int nr = to_sensor_dev_attr_2(devattr)->index;
  1497. int temp_crit_hyst;
  1498. mutex_lock(&data->update_lock);
  1499. if (nr & 1)
  1500. temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
  1501. else
  1502. temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
  1503. temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
  1504. mutex_unlock(&data->update_lock);
  1505. return sprintf(buf, "%d\n", temp_crit_hyst);
  1506. }
  1507. static ssize_t show_temp_type(struct device *dev, struct device_attribute
  1508. *devattr, char *buf)
  1509. {
  1510. struct f71882fg_data *data = f71882fg_update_device(dev);
  1511. int nr = to_sensor_dev_attr_2(devattr)->index;
  1512. return sprintf(buf, "%d\n", data->temp_type[nr]);
  1513. }
  1514. static ssize_t show_temp_beep(struct device *dev, struct device_attribute
  1515. *devattr, char *buf)
  1516. {
  1517. struct f71882fg_data *data = f71882fg_update_device(dev);
  1518. int nr = to_sensor_dev_attr_2(devattr)->index;
  1519. if (data->temp_beep & (1 << nr))
  1520. return sprintf(buf, "1\n");
  1521. else
  1522. return sprintf(buf, "0\n");
  1523. }
  1524. static ssize_t store_temp_beep(struct device *dev, struct device_attribute
  1525. *devattr, const char *buf, size_t count)
  1526. {
  1527. struct f71882fg_data *data = dev_get_drvdata(dev);
  1528. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1529. unsigned long val;
  1530. err = kstrtoul(buf, 10, &val);
  1531. if (err)
  1532. return err;
  1533. mutex_lock(&data->update_lock);
  1534. data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
  1535. if (val)
  1536. data->temp_beep |= 1 << nr;
  1537. else
  1538. data->temp_beep &= ~(1 << nr);
  1539. f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
  1540. mutex_unlock(&data->update_lock);
  1541. return count;
  1542. }
  1543. static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
  1544. *devattr, char *buf)
  1545. {
  1546. struct f71882fg_data *data = f71882fg_update_device(dev);
  1547. int nr = to_sensor_dev_attr_2(devattr)->index;
  1548. if (data->temp_status & (1 << nr))
  1549. return sprintf(buf, "1\n");
  1550. else
  1551. return sprintf(buf, "0\n");
  1552. }
  1553. static ssize_t show_temp_fault(struct device *dev, struct device_attribute
  1554. *devattr, char *buf)
  1555. {
  1556. struct f71882fg_data *data = f71882fg_update_device(dev);
  1557. int nr = to_sensor_dev_attr_2(devattr)->index;
  1558. if (data->temp_diode_open & (1 << nr))
  1559. return sprintf(buf, "1\n");
  1560. else
  1561. return sprintf(buf, "0\n");
  1562. }
  1563. static ssize_t show_pwm(struct device *dev,
  1564. struct device_attribute *devattr, char *buf)
  1565. {
  1566. struct f71882fg_data *data = f71882fg_update_device(dev);
  1567. int val, nr = to_sensor_dev_attr_2(devattr)->index;
  1568. mutex_lock(&data->update_lock);
  1569. if (data->pwm_enable & (1 << (2 * nr)))
  1570. /* PWM mode */
  1571. val = data->pwm[nr];
  1572. else {
  1573. /* RPM mode */
  1574. val = 255 * fan_from_reg(data->fan_target[nr])
  1575. / fan_from_reg(data->fan_full_speed[nr]);
  1576. }
  1577. mutex_unlock(&data->update_lock);
  1578. return sprintf(buf, "%d\n", val);
  1579. }
  1580. static ssize_t store_pwm(struct device *dev,
  1581. struct device_attribute *devattr, const char *buf,
  1582. size_t count)
  1583. {
  1584. struct f71882fg_data *data = dev_get_drvdata(dev);
  1585. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1586. long val;
  1587. err = kstrtol(buf, 10, &val);
  1588. if (err)
  1589. return err;
  1590. val = SENSORS_LIMIT(val, 0, 255);
  1591. mutex_lock(&data->update_lock);
  1592. data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
  1593. if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
  1594. (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
  1595. count = -EROFS;
  1596. goto leave;
  1597. }
  1598. if (data->pwm_enable & (1 << (2 * nr))) {
  1599. /* PWM mode */
  1600. f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
  1601. data->pwm[nr] = val;
  1602. } else {
  1603. /* RPM mode */
  1604. int target, full_speed;
  1605. full_speed = f71882fg_read16(data,
  1606. F71882FG_REG_FAN_FULL_SPEED(nr));
  1607. target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
  1608. f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
  1609. data->fan_target[nr] = target;
  1610. data->fan_full_speed[nr] = full_speed;
  1611. }
  1612. leave:
  1613. mutex_unlock(&data->update_lock);
  1614. return count;
  1615. }
  1616. static ssize_t show_simple_pwm(struct device *dev,
  1617. struct device_attribute *devattr, char *buf)
  1618. {
  1619. struct f71882fg_data *data = f71882fg_update_device(dev);
  1620. int val, nr = to_sensor_dev_attr_2(devattr)->index;
  1621. val = data->pwm[nr];
  1622. return sprintf(buf, "%d\n", val);
  1623. }
  1624. static ssize_t store_simple_pwm(struct device *dev,
  1625. struct device_attribute *devattr,
  1626. const char *buf, size_t count)
  1627. {
  1628. struct f71882fg_data *data = dev_get_drvdata(dev);
  1629. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1630. long val;
  1631. err = kstrtol(buf, 10, &val);
  1632. if (err)
  1633. return err;
  1634. val = SENSORS_LIMIT(val, 0, 255);
  1635. mutex_lock(&data->update_lock);
  1636. f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
  1637. data->pwm[nr] = val;
  1638. mutex_unlock(&data->update_lock);
  1639. return count;
  1640. }
  1641. static ssize_t show_pwm_enable(struct device *dev,
  1642. struct device_attribute *devattr, char *buf)
  1643. {
  1644. int result = 0;
  1645. struct f71882fg_data *data = f71882fg_update_device(dev);
  1646. int nr = to_sensor_dev_attr_2(devattr)->index;
  1647. switch ((data->pwm_enable >> 2 * nr) & 3) {
  1648. case 0:
  1649. case 1:
  1650. result = 2; /* Normal auto mode */
  1651. break;
  1652. case 2:
  1653. result = 1; /* Manual mode */
  1654. break;
  1655. case 3:
  1656. if (data->type == f8000)
  1657. result = 3; /* Thermostat mode */
  1658. else
  1659. result = 1; /* Manual mode */
  1660. break;
  1661. }
  1662. return sprintf(buf, "%d\n", result);
  1663. }
  1664. static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
  1665. *devattr, const char *buf, size_t count)
  1666. {
  1667. struct f71882fg_data *data = dev_get_drvdata(dev);
  1668. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1669. long val;
  1670. err = kstrtol(buf, 10, &val);
  1671. if (err)
  1672. return err;
  1673. /* Special case for F8000 pwm channel 3 which only does auto mode */
  1674. if (data->type == f8000 && nr == 2 && val != 2)
  1675. return -EINVAL;
  1676. mutex_lock(&data->update_lock);
  1677. data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
  1678. /* Special case for F8000 auto PWM mode / Thermostat mode */
  1679. if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
  1680. switch (val) {
  1681. case 2:
  1682. data->pwm_enable &= ~(2 << (2 * nr));
  1683. break; /* Normal auto mode */
  1684. case 3:
  1685. data->pwm_enable |= 2 << (2 * nr);
  1686. break; /* Thermostat mode */
  1687. default:
  1688. count = -EINVAL;
  1689. goto leave;
  1690. }
  1691. } else {
  1692. switch (val) {
  1693. case 1:
  1694. /* The f71858fg does not support manual RPM mode */
  1695. if (data->type == f71858fg &&
  1696. ((data->pwm_enable >> (2 * nr)) & 1)) {
  1697. count = -EINVAL;
  1698. goto leave;
  1699. }
  1700. data->pwm_enable |= 2 << (2 * nr);
  1701. break; /* Manual */
  1702. case 2:
  1703. data->pwm_enable &= ~(2 << (2 * nr));
  1704. break; /* Normal auto mode */
  1705. default:
  1706. count = -EINVAL;
  1707. goto leave;
  1708. }
  1709. }
  1710. f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
  1711. leave:
  1712. mutex_unlock(&data->update_lock);
  1713. return count;
  1714. }
  1715. static ssize_t show_pwm_auto_point_pwm(struct device *dev,
  1716. struct device_attribute *devattr,
  1717. char *buf)
  1718. {
  1719. int result;
  1720. struct f71882fg_data *data = f71882fg_update_device(dev);
  1721. int pwm = to_sensor_dev_attr_2(devattr)->index;
  1722. int point = to_sensor_dev_attr_2(devattr)->nr;
  1723. mutex_lock(&data->update_lock);
  1724. if (data->pwm_enable & (1 << (2 * pwm))) {
  1725. /* PWM mode */
  1726. result = data->pwm_auto_point_pwm[pwm][point];
  1727. } else {
  1728. /* RPM mode */
  1729. result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
  1730. }
  1731. mutex_unlock(&data->update_lock);
  1732. return sprintf(buf, "%d\n", result);
  1733. }
  1734. static ssize_t store_pwm_auto_point_pwm(struct device *dev,
  1735. struct device_attribute *devattr,
  1736. const char *buf, size_t count)
  1737. {
  1738. struct f71882fg_data *data = dev_get_drvdata(dev);
  1739. int err, pwm = to_sensor_dev_attr_2(devattr)->index;
  1740. int point = to_sensor_dev_attr_2(devattr)->nr;
  1741. long val;
  1742. err = kstrtol(buf, 10, &val);
  1743. if (err)
  1744. return err;
  1745. val = SENSORS_LIMIT(val, 0, 255);
  1746. mutex_lock(&data->update_lock);
  1747. data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
  1748. if (data->pwm_enable & (1 << (2 * pwm))) {
  1749. /* PWM mode */
  1750. } else {
  1751. /* RPM mode */
  1752. if (val < 29) /* Prevent negative numbers */
  1753. val = 255;
  1754. else
  1755. val = (255 - val) * 32 / val;
  1756. }
  1757. f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
  1758. data->pwm_auto_point_pwm[pwm][point] = val;
  1759. mutex_unlock(&data->update_lock);
  1760. return count;
  1761. }
  1762. static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
  1763. struct device_attribute *devattr,
  1764. char *buf)
  1765. {
  1766. int result = 0;
  1767. struct f71882fg_data *data = f71882fg_update_device(dev);
  1768. int nr = to_sensor_dev_attr_2(devattr)->index;
  1769. int point = to_sensor_dev_attr_2(devattr)->nr;
  1770. mutex_lock(&data->update_lock);
  1771. if (nr & 1)
  1772. result = data->pwm_auto_point_hyst[nr / 2] >> 4;
  1773. else
  1774. result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
  1775. result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
  1776. mutex_unlock(&data->update_lock);
  1777. return sprintf(buf, "%d\n", result);
  1778. }
  1779. static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
  1780. struct device_attribute *devattr,
  1781. const char *buf, size_t count)
  1782. {
  1783. struct f71882fg_data *data = dev_get_drvdata(dev);
  1784. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1785. int point = to_sensor_dev_attr_2(devattr)->nr;
  1786. u8 reg;
  1787. long val;
  1788. err = kstrtol(buf, 10, &val);
  1789. if (err)
  1790. return err;
  1791. val /= 1000;
  1792. mutex_lock(&data->update_lock);
  1793. data->pwm_auto_point_temp[nr][point] =
  1794. f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
  1795. val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15,
  1796. data->pwm_auto_point_temp[nr][point]);
  1797. val = data->pwm_auto_point_temp[nr][point] - val;
  1798. reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
  1799. if (nr & 1)
  1800. reg = (reg & 0x0f) | (val << 4);
  1801. else
  1802. reg = (reg & 0xf0) | val;
  1803. f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
  1804. data->pwm_auto_point_hyst[nr / 2] = reg;
  1805. mutex_unlock(&data->update_lock);
  1806. return count;
  1807. }
  1808. static ssize_t show_pwm_interpolate(struct device *dev,
  1809. struct device_attribute *devattr, char *buf)
  1810. {
  1811. int result;
  1812. struct f71882fg_data *data = f71882fg_update_device(dev);
  1813. int nr = to_sensor_dev_attr_2(devattr)->index;
  1814. result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
  1815. return sprintf(buf, "%d\n", result);
  1816. }
  1817. static ssize_t store_pwm_interpolate(struct device *dev,
  1818. struct device_attribute *devattr,
  1819. const char *buf, size_t count)
  1820. {
  1821. struct f71882fg_data *data = dev_get_drvdata(dev);
  1822. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1823. unsigned long val;
  1824. err = kstrtoul(buf, 10, &val);
  1825. if (err)
  1826. return err;
  1827. mutex_lock(&data->update_lock);
  1828. data->pwm_auto_point_mapping[nr] =
  1829. f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
  1830. if (val)
  1831. val = data->pwm_auto_point_mapping[nr] | (1 << 4);
  1832. else
  1833. val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
  1834. f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
  1835. data->pwm_auto_point_mapping[nr] = val;
  1836. mutex_unlock(&data->update_lock);
  1837. return count;
  1838. }
  1839. static ssize_t show_pwm_auto_point_channel(struct device *dev,
  1840. struct device_attribute *devattr,
  1841. char *buf)
  1842. {
  1843. int result;
  1844. struct f71882fg_data *data = f71882fg_update_device(dev);
  1845. int nr = to_sensor_dev_attr_2(devattr)->index;
  1846. result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
  1847. data->temp_start);
  1848. return sprintf(buf, "%d\n", result);
  1849. }
  1850. static ssize_t store_pwm_auto_point_channel(struct device *dev,
  1851. struct device_attribute *devattr,
  1852. const char *buf, size_t count)
  1853. {
  1854. struct f71882fg_data *data = dev_get_drvdata(dev);
  1855. int err, nr = to_sensor_dev_attr_2(devattr)->index;
  1856. long val;
  1857. err = kstrtol(buf, 10, &val);
  1858. if (err)
  1859. return err;
  1860. switch (val) {
  1861. case 1:
  1862. val = 0;
  1863. break;
  1864. case 2:
  1865. val = 1;
  1866. break;
  1867. case 4:
  1868. val = 2;
  1869. break;
  1870. default:
  1871. return -EINVAL;
  1872. }
  1873. val += data->temp_start;
  1874. mutex_lock(&data->update_lock);
  1875. data->pwm_auto_point_mapping[nr] =
  1876. f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
  1877. val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
  1878. f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
  1879. data->pwm_auto_point_mapping[nr] = val;
  1880. mutex_unlock(&data->update_lock);
  1881. return count;
  1882. }
  1883. static ssize_t show_pwm_auto_point_temp(struct device *dev,
  1884. struct device_attribute *devattr,
  1885. char *buf)
  1886. {
  1887. int result;
  1888. struct f71882fg_data *data = f71882fg_update_device(dev);
  1889. int pwm = to_sensor_dev_attr_2(devattr)->index;
  1890. int point = to_sensor_dev_attr_2(devattr)->nr;
  1891. result = data->pwm_auto_point_temp[pwm][point];
  1892. return sprintf(buf, "%d\n", 1000 * result);
  1893. }
  1894. static ssize_t store_pwm_auto_point_temp(struct device *dev,
  1895. struct device_attribute *devattr,
  1896. const char *buf, size_t count)
  1897. {
  1898. struct f71882fg_data *data = dev_get_drvdata(dev);
  1899. int err, pwm = to_sensor_dev_attr_2(devattr)->index;
  1900. int point = to_sensor_dev_attr_2(devattr)->nr;
  1901. long val;
  1902. err = kstrtol(buf, 10, &val);
  1903. if (err)
  1904. return err;
  1905. val /= 1000;
  1906. if (data->auto_point_temp_signed)
  1907. val = SENSORS_LIMIT(val, -128, 127);
  1908. else
  1909. val = SENSORS_LIMIT(val, 0, 127);
  1910. mutex_lock(&data->update_lock);
  1911. f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
  1912. data->pwm_auto_point_temp[pwm][point] = val;
  1913. mutex_unlock(&data->update_lock);
  1914. return count;
  1915. }
  1916. static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
  1917. char *buf)
  1918. {
  1919. struct f71882fg_data *data = dev_get_drvdata(dev);
  1920. return sprintf(buf, "%s\n", f71882fg_names[data->type]);
  1921. }
  1922. static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
  1923. struct sensor_device_attribute_2 *attr, int count)
  1924. {
  1925. int err, i;
  1926. for (i = 0; i < count; i++) {
  1927. err = device_create_file(&pdev->dev, &attr[i].dev_attr);
  1928. if (err)
  1929. return err;
  1930. }
  1931. return 0;
  1932. }
  1933. static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
  1934. struct sensor_device_attribute_2 *attr, int count)
  1935. {
  1936. int i;
  1937. for (i = 0; i < count; i++)
  1938. device_remove_file(&pdev->dev, &attr[i].dev_attr);
  1939. }
  1940. static int __devinit f71882fg_create_fan_sysfs_files(
  1941. struct platform_device *pdev, int idx)
  1942. {
  1943. struct f71882fg_data *data = platform_get_drvdata(pdev);
  1944. int err;
  1945. /* Sanity check the pwm setting */
  1946. err = 0;
  1947. switch (data->type) {
  1948. case f71858fg:
  1949. if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
  1950. err = 1;
  1951. break;
  1952. case f71862fg:
  1953. if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
  1954. err = 1;
  1955. break;
  1956. case f8000:
  1957. if (idx == 2)
  1958. err = data->pwm_enable & 0x20;
  1959. break;
  1960. default:
  1961. break;
  1962. }
  1963. if (err) {
  1964. dev_err(&pdev->dev,
  1965. "Invalid (reserved) pwm settings: 0x%02x, "
  1966. "skipping fan %d\n",
  1967. (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
  1968. return 0; /* This is a non fatal condition */
  1969. }
  1970. err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
  1971. ARRAY_SIZE(fxxxx_fan_attr[0]));
  1972. if (err)
  1973. return err;
  1974. if (f71882fg_fan_has_beep[data->type]) {
  1975. err = f71882fg_create_sysfs_files(pdev,
  1976. &fxxxx_fan_beep_attr[idx],
  1977. 1);
  1978. if (err)
  1979. return err;
  1980. }
  1981. dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
  1982. (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
  1983. /* Check for unsupported auto pwm settings */
  1984. switch (data->type) {
  1985. case f71808e:
  1986. case f71808a:
  1987. case f71869:
  1988. case f71869a:
  1989. case f71889fg:
  1990. case f71889ed:
  1991. case f71889a:
  1992. data->pwm_auto_point_mapping[idx] =
  1993. f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
  1994. if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
  1995. (data->pwm_auto_point_mapping[idx] & 3) == 0) {
  1996. dev_warn(&pdev->dev,
  1997. "Auto pwm controlled by raw digital "
  1998. "data, disabling pwm auto_point "
  1999. "sysfs attributes for fan %d\n", idx + 1);
  2000. return 0; /* This is a non fatal condition */
  2001. }
  2002. break;
  2003. default:
  2004. break;
  2005. }
  2006. switch (data->type) {
  2007. case f71862fg:
  2008. err = f71882fg_create_sysfs_files(pdev,
  2009. &f71862fg_auto_pwm_attr[idx][0],
  2010. ARRAY_SIZE(f71862fg_auto_pwm_attr[0]));
  2011. break;
  2012. case f71808e:
  2013. case f71869:
  2014. err = f71882fg_create_sysfs_files(pdev,
  2015. &f71869_auto_pwm_attr[idx][0],
  2016. ARRAY_SIZE(f71869_auto_pwm_attr[0]));
  2017. break;
  2018. case f8000:
  2019. err = f71882fg_create_sysfs_files(pdev,
  2020. &f8000_auto_pwm_attr[idx][0],
  2021. ARRAY_SIZE(f8000_auto_pwm_attr[0]));
  2022. break;
  2023. default:
  2024. err = f71882fg_create_sysfs_files(pdev,
  2025. &fxxxx_auto_pwm_attr[idx][0],
  2026. ARRAY_SIZE(fxxxx_auto_pwm_attr[0]));
  2027. }
  2028. return err;
  2029. }
  2030. static int __devinit f71882fg_probe(struct platform_device *pdev)
  2031. {
  2032. struct f71882fg_data *data;
  2033. struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
  2034. int nr_fans = f71882fg_nr_fans[sio_data->type];
  2035. int nr_temps = f71882fg_nr_temps[sio_data->type];
  2036. int err, i;
  2037. u8 start_reg, reg;
  2038. data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
  2039. if (!data)
  2040. return -ENOMEM;
  2041. data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
  2042. data->type = sio_data->type;
  2043. data->temp_start =
  2044. (data->type == f71858fg || data->type == f8000) ? 0 : 1;
  2045. mutex_init(&data->update_lock);
  2046. platform_set_drvdata(pdev, data);
  2047. start_reg = f71882fg_read8(data, F71882FG_REG_START);
  2048. if (start_reg & 0x04) {
  2049. dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
  2050. err = -ENODEV;
  2051. goto exit_free;
  2052. }
  2053. if (!(start_reg & 0x03)) {
  2054. dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
  2055. err = -ENODEV;
  2056. goto exit_free;
  2057. }
  2058. /* Register sysfs interface files */
  2059. err = device_create_file(&pdev->dev, &dev_attr_name);
  2060. if (err)
  2061. goto exit_unregister_sysfs;
  2062. if (start_reg & 0x01) {
  2063. switch (data->type) {
  2064. case f71858fg:
  2065. data->temp_config =
  2066. f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
  2067. if (data->temp_config & 0x10)
  2068. /*
  2069. * The f71858fg temperature alarms behave as
  2070. * the f8000 alarms in this mode
  2071. */
  2072. err = f71882fg_create_sysfs_files(pdev,
  2073. f8000_temp_attr,
  2074. ARRAY_SIZE(f8000_temp_attr));
  2075. else
  2076. err = f71882fg_create_sysfs_files(pdev,
  2077. f71858fg_temp_attr,
  2078. ARRAY_SIZE(f71858fg_temp_attr));
  2079. break;
  2080. case f8000:
  2081. err = f71882fg_create_sysfs_files(pdev,
  2082. f8000_temp_attr,
  2083. ARRAY_SIZE(f8000_temp_attr));
  2084. break;
  2085. default:
  2086. err = f71882fg_create_sysfs_files(pdev,
  2087. &fxxxx_temp_attr[0][0],
  2088. ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
  2089. }
  2090. if (err)
  2091. goto exit_unregister_sysfs;
  2092. if (f71882fg_temp_has_beep[data->type]) {
  2093. err = f71882fg_create_sysfs_files(pdev,
  2094. &fxxxx_temp_beep_attr[0][0],
  2095. ARRAY_SIZE(fxxxx_temp_beep_attr[0])
  2096. * nr_temps);
  2097. if (err)
  2098. goto exit_unregister_sysfs;
  2099. }
  2100. for (i = 0; i < F71882FG_MAX_INS; i++) {
  2101. if (f71882fg_has_in[data->type][i]) {
  2102. err = device_create_file(&pdev->dev,
  2103. &fxxxx_in_attr[i].dev_attr);
  2104. if (err)
  2105. goto exit_unregister_sysfs;
  2106. }
  2107. }
  2108. if (f71882fg_has_in1_alarm[data->type]) {
  2109. err = f71882fg_create_sysfs_files(pdev,
  2110. fxxxx_in1_alarm_attr,
  2111. ARRAY_SIZE(fxxxx_in1_alarm_attr));
  2112. if (err)
  2113. goto exit_unregister_sysfs;
  2114. }
  2115. }
  2116. if (start_reg & 0x02) {
  2117. switch (data->type) {
  2118. case f71808e:
  2119. case f71808a:
  2120. case f71869:
  2121. case f71869a:
  2122. /* These always have signed auto point temps */
  2123. data->auto_point_temp_signed = 1;
  2124. /* Fall through to select correct fan/pwm reg bank! */
  2125. case f71889fg:
  2126. case f71889ed:
  2127. case f71889a:
  2128. reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
  2129. if (reg & F71882FG_FAN_NEG_TEMP_EN)
  2130. data->auto_point_temp_signed = 1;
  2131. /* Ensure banked pwm registers point to right bank */
  2132. reg &= ~F71882FG_FAN_PROG_SEL;
  2133. f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg);
  2134. break;
  2135. default:
  2136. break;
  2137. }
  2138. data->pwm_enable =
  2139. f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
  2140. for (i = 0; i < nr_fans; i++) {
  2141. err = f71882fg_create_fan_sysfs_files(pdev, i);
  2142. if (err)
  2143. goto exit_unregister_sysfs;
  2144. }
  2145. /* Some types have 1 extra fan with limited functionality */
  2146. switch (data->type) {
  2147. case f71808a:
  2148. err = f71882fg_create_sysfs_files(pdev,
  2149. f71808a_fan3_attr,
  2150. ARRAY_SIZE(f71808a_fan3_attr));
  2151. break;
  2152. case f8000:
  2153. err = f71882fg_create_sysfs_files(pdev,
  2154. f8000_fan_attr,
  2155. ARRAY_SIZE(f8000_fan_attr));
  2156. break;
  2157. default:
  2158. break;
  2159. }
  2160. if (err)
  2161. goto exit_unregister_sysfs;
  2162. }
  2163. data->hwmon_dev = hwmon_device_register(&pdev->dev);
  2164. if (IS_ERR(data->hwmon_dev)) {
  2165. err = PTR_ERR(data->hwmon_dev);
  2166. data->hwmon_dev = NULL;
  2167. goto exit_unregister_sysfs;
  2168. }
  2169. return 0;
  2170. exit_unregister_sysfs:
  2171. f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
  2172. return err; /* f71882fg_remove() also frees our data */
  2173. exit_free:
  2174. kfree(data);
  2175. return err;
  2176. }
  2177. static int f71882fg_remove(struct platform_device *pdev)
  2178. {
  2179. struct f71882fg_data *data = platform_get_drvdata(pdev);
  2180. int nr_fans = f71882fg_nr_fans[data->type];
  2181. int nr_temps = f71882fg_nr_temps[data->type];
  2182. int i;
  2183. u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
  2184. if (data->hwmon_dev)
  2185. hwmon_device_unregister(data->hwmon_dev);
  2186. device_remove_file(&pdev->dev, &dev_attr_name);
  2187. if (start_reg & 0x01) {
  2188. switch (data->type) {
  2189. case f71858fg:
  2190. if (data->temp_config & 0x10)
  2191. f71882fg_remove_sysfs_files(pdev,
  2192. f8000_temp_attr,
  2193. ARRAY_SIZE(f8000_temp_attr));
  2194. else
  2195. f71882fg_remove_sysfs_files(pdev,
  2196. f71858fg_temp_attr,
  2197. ARRAY_SIZE(f71858fg_temp_attr));
  2198. break;
  2199. case f8000:
  2200. f71882fg_remove_sysfs_files(pdev,
  2201. f8000_temp_attr,
  2202. ARRAY_SIZE(f8000_temp_attr));
  2203. break;
  2204. default:
  2205. f71882fg_remove_sysfs_files(pdev,
  2206. &fxxxx_temp_attr[0][0],
  2207. ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
  2208. }
  2209. if (f71882fg_temp_has_beep[data->type]) {
  2210. f71882fg_remove_sysfs_files(pdev,
  2211. &fxxxx_temp_beep_attr[0][0],
  2212. ARRAY_SIZE(fxxxx_temp_beep_attr[0]) * nr_temps);
  2213. }
  2214. for (i = 0; i < F71882FG_MAX_INS; i++) {
  2215. if (f71882fg_has_in[data->type][i]) {
  2216. device_remove_file(&pdev->dev,
  2217. &fxxxx_in_attr[i].dev_attr);
  2218. }
  2219. }
  2220. if (f71882fg_has_in1_alarm[data->type]) {
  2221. f71882fg_remove_sysfs_files(pdev,
  2222. fxxxx_in1_alarm_attr,
  2223. ARRAY_SIZE(fxxxx_in1_alarm_attr));
  2224. }
  2225. }
  2226. if (start_reg & 0x02) {
  2227. f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
  2228. ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
  2229. if (f71882fg_fan_has_beep[data->type]) {
  2230. f71882fg_remove_sysfs_files(pdev,
  2231. fxxxx_fan_beep_attr, nr_fans);
  2232. }
  2233. switch (data->type) {
  2234. case f71808a:
  2235. f71882fg_remove_sysfs_files(pdev,
  2236. &fxxxx_auto_pwm_attr[0][0],
  2237. ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
  2238. f71882fg_remove_sysfs_files(pdev,
  2239. f71808a_fan3_attr,
  2240. ARRAY_SIZE(f71808a_fan3_attr));
  2241. break;
  2242. case f71862fg:
  2243. f71882fg_remove_sysfs_files(pdev,
  2244. &f71862fg_auto_pwm_attr[0][0],
  2245. ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) *
  2246. nr_fans);
  2247. break;
  2248. case f71808e:
  2249. case f71869:
  2250. f71882fg_remove_sysfs_files(pdev,
  2251. &f71869_auto_pwm_attr[0][0],
  2252. ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans);
  2253. break;
  2254. case f8000:
  2255. f71882fg_remove_sysfs_files(pdev,
  2256. f8000_fan_attr,
  2257. ARRAY_SIZE(f8000_fan_attr));
  2258. f71882fg_remove_sysfs_files(pdev,
  2259. &f8000_auto_pwm_attr[0][0],
  2260. ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans);
  2261. break;
  2262. default:
  2263. f71882fg_remove_sysfs_files(pdev,
  2264. &fxxxx_auto_pwm_attr[0][0],
  2265. ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
  2266. }
  2267. }
  2268. platform_set_drvdata(pdev, NULL);
  2269. kfree(data);
  2270. return 0;
  2271. }
  2272. static int __init f71882fg_find(int sioaddr, unsigned short *address,
  2273. struct f71882fg_sio_data *sio_data)
  2274. {
  2275. u16 devid;
  2276. int err = superio_enter(sioaddr);
  2277. if (err)
  2278. return err;
  2279. devid = superio_inw(sioaddr, SIO_REG_MANID);
  2280. if (devid != SIO_FINTEK_ID) {
  2281. pr_debug("Not a Fintek device\n");
  2282. err = -ENODEV;
  2283. goto exit;
  2284. }
  2285. devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
  2286. switch (devid) {
  2287. case SIO_F71808E_ID:
  2288. sio_data->type = f71808e;
  2289. break;
  2290. case SIO_F71808A_ID:
  2291. sio_data->type = f71808a;
  2292. break;
  2293. case SIO_F71858_ID:
  2294. sio_data->type = f71858fg;
  2295. break;
  2296. case SIO_F71862_ID:
  2297. sio_data->type = f71862fg;
  2298. break;
  2299. case SIO_F71869_ID:
  2300. sio_data->type = f71869;
  2301. break;
  2302. case SIO_F71869A_ID:
  2303. sio_data->type = f71869a;
  2304. break;
  2305. case SIO_F71882_ID:
  2306. sio_data->type = f71882fg;
  2307. break;
  2308. case SIO_F71889_ID:
  2309. sio_data->type = f71889fg;
  2310. break;
  2311. case SIO_F71889E_ID:
  2312. sio_data->type = f71889ed;
  2313. break;
  2314. case SIO_F71889A_ID:
  2315. sio_data->type = f71889a;
  2316. break;
  2317. case SIO_F8000_ID:
  2318. sio_data->type = f8000;
  2319. break;
  2320. case SIO_F81865_ID:
  2321. sio_data->type = f81865f;
  2322. break;
  2323. default:
  2324. pr_info("Unsupported Fintek device: %04x\n",
  2325. (unsigned int)devid);
  2326. err = -ENODEV;
  2327. goto exit;
  2328. }
  2329. if (sio_data->type == f71858fg)
  2330. superio_select(sioaddr, SIO_F71858FG_LD_HWM);
  2331. else
  2332. superio_select(sioaddr, SIO_F71882FG_LD_HWM);
  2333. if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
  2334. pr_warn("Device not activated\n");
  2335. err = -ENODEV;
  2336. goto exit;
  2337. }
  2338. *address = superio_inw(sioaddr, SIO_REG_ADDR);
  2339. if (*address == 0) {
  2340. pr_warn("Base address not set\n");
  2341. err = -ENODEV;
  2342. goto exit;
  2343. }
  2344. *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
  2345. err = 0;
  2346. pr_info("Found %s chip at %#x, revision %d\n",
  2347. f71882fg_names[sio_data->type], (unsigned int)*address,
  2348. (int)superio_inb(sioaddr, SIO_REG_DEVREV));
  2349. exit:
  2350. superio_exit(sioaddr);
  2351. return err;
  2352. }
  2353. static int __init f71882fg_device_add(unsigned short address,
  2354. const struct f71882fg_sio_data *sio_data)
  2355. {
  2356. struct resource res = {
  2357. .start = address,
  2358. .end = address + REGION_LENGTH - 1,
  2359. .flags = IORESOURCE_IO,
  2360. };
  2361. int err;
  2362. f71882fg_pdev = platform_device_alloc(DRVNAME, address);
  2363. if (!f71882fg_pdev)
  2364. return -ENOMEM;
  2365. res.name = f71882fg_pdev->name;
  2366. err = acpi_check_resource_conflict(&res);
  2367. if (err)
  2368. goto exit_device_put;
  2369. err = platform_device_add_resources(f71882fg_pdev, &res, 1);
  2370. if (err) {
  2371. pr_err("Device resource addition failed\n");
  2372. goto exit_device_put;
  2373. }
  2374. err = platform_device_add_data(f71882fg_pdev, sio_data,
  2375. sizeof(struct f71882fg_sio_data));
  2376. if (err) {
  2377. pr_err("Platform data allocation failed\n");
  2378. goto exit_device_put;
  2379. }
  2380. err = platform_device_add(f71882fg_pdev);
  2381. if (err) {
  2382. pr_err("Device addition failed\n");
  2383. goto exit_device_put;
  2384. }
  2385. return 0;
  2386. exit_device_put:
  2387. platform_device_put(f71882fg_pdev);
  2388. return err;
  2389. }
  2390. static int __init f71882fg_init(void)
  2391. {
  2392. int err = -ENODEV;
  2393. unsigned short address;
  2394. struct f71882fg_sio_data sio_data;
  2395. memset(&sio_data, 0, sizeof(sio_data));
  2396. if (f71882fg_find(0x2e, &address, &sio_data) &&
  2397. f71882fg_find(0x4e, &address, &sio_data))
  2398. goto exit;
  2399. err = platform_driver_register(&f71882fg_driver);
  2400. if (err)
  2401. goto exit;
  2402. err = f71882fg_device_add(address, &sio_data);
  2403. if (err)
  2404. goto exit_driver;
  2405. return 0;
  2406. exit_driver:
  2407. platform_driver_unregister(&f71882fg_driver);
  2408. exit:
  2409. return err;
  2410. }
  2411. static void __exit f71882fg_exit(void)
  2412. {
  2413. platform_device_unregister(f71882fg_pdev);
  2414. platform_driver_unregister(&f71882fg_driver);
  2415. }
  2416. MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
  2417. MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
  2418. MODULE_LICENSE("GPL");
  2419. module_init(f71882fg_init);
  2420. module_exit(f71882fg_exit);