f71882fg.c 83 KB

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