abituguru3.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /*
  2. * abituguru3.c
  3. *
  4. * Copyright (c) 2006-2008 Hans de Goede <hdegoede@redhat.com>
  5. * Copyright (c) 2008 Alistair John Strachan <alistair@devzero.co.uk>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /*
  22. * This driver supports the sensor part of revision 3 of the custom Abit uGuru
  23. * chip found on newer Abit uGuru motherboards. Note: because of lack of specs
  24. * only reading the sensors and their settings is supported.
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/jiffies.h>
  31. #include <linux/mutex.h>
  32. #include <linux/err.h>
  33. #include <linux/delay.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/hwmon.h>
  36. #include <linux/hwmon-sysfs.h>
  37. #include <linux/dmi.h>
  38. #include <linux/io.h>
  39. /* uGuru3 bank addresses */
  40. #define ABIT_UGURU3_SETTINGS_BANK 0x01
  41. #define ABIT_UGURU3_SENSORS_BANK 0x08
  42. #define ABIT_UGURU3_MISC_BANK 0x09
  43. #define ABIT_UGURU3_ALARMS_START 0x1E
  44. #define ABIT_UGURU3_SETTINGS_START 0x24
  45. #define ABIT_UGURU3_VALUES_START 0x80
  46. #define ABIT_UGURU3_BOARD_ID 0x0A
  47. /* uGuru3 sensor bank flags */ /* Alarm if: */
  48. #define ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE 0x01 /* temp over warn */
  49. #define ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE 0x02 /* volt over max */
  50. #define ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE 0x04 /* volt under min */
  51. #define ABIT_UGURU3_TEMP_HIGH_ALARM_FLAG 0x10 /* temp is over warn */
  52. #define ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG 0x20 /* volt is over max */
  53. #define ABIT_UGURU3_VOLT_LOW_ALARM_FLAG 0x40 /* volt is under min */
  54. #define ABIT_UGURU3_FAN_LOW_ALARM_ENABLE 0x01 /* fan under min */
  55. #define ABIT_UGURU3_BEEP_ENABLE 0x08 /* beep if alarm */
  56. #define ABIT_UGURU3_SHUTDOWN_ENABLE 0x80 /* shutdown if alarm */
  57. /* sensor types */
  58. #define ABIT_UGURU3_IN_SENSOR 0
  59. #define ABIT_UGURU3_TEMP_SENSOR 1
  60. #define ABIT_UGURU3_FAN_SENSOR 2
  61. /*
  62. * Timeouts / Retries, if these turn out to need a lot of fiddling we could
  63. * convert them to params. Determined by trial and error. I assume this is
  64. * cpu-speed independent, since the ISA-bus and not the CPU should be the
  65. * bottleneck.
  66. */
  67. #define ABIT_UGURU3_WAIT_TIMEOUT 250
  68. /*
  69. * Normally the 0xAC at the end of synchronize() is reported after the
  70. * first read, but sometimes not and we need to poll
  71. */
  72. #define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5
  73. /* utility macros */
  74. #define ABIT_UGURU3_NAME "abituguru3"
  75. #define ABIT_UGURU3_DEBUG(format, arg...) \
  76. if (verbose) \
  77. printk(KERN_DEBUG ABIT_UGURU3_NAME ": " format , ## arg)
  78. /* Macros to help calculate the sysfs_names array length */
  79. #define ABIT_UGURU3_MAX_NO_SENSORS 26
  80. /*
  81. * sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
  82. * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0
  83. */
  84. #define ABIT_UGURU3_IN_NAMES_LENGTH \
  85. (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11)
  86. /*
  87. * sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0,
  88. * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0,
  89. * temp??_label\0
  90. */
  91. #define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13)
  92. /*
  93. * sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0,
  94. * fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0
  95. */
  96. #define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12)
  97. /*
  98. * Worst case scenario 16 in sensors (longest names_length) and the rest
  99. * temp sensors (second longest names_length).
  100. */
  101. #define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \
  102. (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH)
  103. /*
  104. * All the macros below are named identical to the openguru2 program
  105. * reverse engineered by Louis Kruger, hence the names might not be 100%
  106. * logical. I could come up with better names, but I prefer keeping the names
  107. * identical so that this driver can be compared with his work more easily.
  108. */
  109. /* Two i/o-ports are used by uGuru */
  110. #define ABIT_UGURU3_BASE 0x00E0
  111. #define ABIT_UGURU3_CMD 0x00
  112. #define ABIT_UGURU3_DATA 0x04
  113. #define ABIT_UGURU3_REGION_LENGTH 5
  114. /*
  115. * The wait_xxx functions return this on success and the last contents
  116. * of the DATA register (0-255) on failure.
  117. */
  118. #define ABIT_UGURU3_SUCCESS -1
  119. /* uGuru status flags */
  120. #define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01
  121. #define ABIT_UGURU3_STATUS_BUSY 0x02
  122. /* Structures */
  123. struct abituguru3_sensor_info {
  124. const char *name;
  125. int port;
  126. int type;
  127. int multiplier;
  128. int divisor;
  129. int offset;
  130. };
  131. /* Avoid use of flexible array members */
  132. #define ABIT_UGURU3_MAX_DMI_NAMES 2
  133. struct abituguru3_motherboard_info {
  134. u16 id;
  135. const char *dmi_name[ABIT_UGURU3_MAX_DMI_NAMES + 1];
  136. /* + 1 -> end of sensors indicated by a sensor with name == NULL */
  137. struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1];
  138. };
  139. /*
  140. * For the Abit uGuru, we need to keep some data in memory.
  141. * The structure is dynamically allocated, at the same time when a new
  142. * abituguru3 device is allocated.
  143. */
  144. struct abituguru3_data {
  145. struct device *hwmon_dev; /* hwmon registered device */
  146. struct mutex update_lock; /* protect access to data and uGuru */
  147. unsigned short addr; /* uguru base address */
  148. char valid; /* !=0 if following fields are valid */
  149. unsigned long last_updated; /* In jiffies */
  150. /*
  151. * For convenience the sysfs attr and their names are generated
  152. * automatically. We have max 10 entries per sensor (for in sensors)
  153. */
  154. struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS
  155. * 10];
  156. /* Buffer to store the dynamically generated sysfs names */
  157. char sysfs_names[ABIT_UGURU3_SYSFS_NAMES_LENGTH];
  158. /* Pointer to the sensors info for the detected motherboard */
  159. const struct abituguru3_sensor_info *sensors;
  160. /*
  161. * The abituguru3 supports up to 48 sensors, and thus has registers
  162. * sets for 48 sensors, for convienence reasons / simplicity of the
  163. * code we always read and store all registers for all 48 sensors
  164. */
  165. /* Alarms for all 48 sensors (1 bit per sensor) */
  166. u8 alarms[48/8];
  167. /* Value of all 48 sensors */
  168. u8 value[48];
  169. /*
  170. * Settings of all 48 sensors, note in and temp sensors (the first 32
  171. * sensors) have 3 bytes of settings, while fans only have 2 bytes,
  172. * for convenience we use 3 bytes for all sensors
  173. */
  174. u8 settings[48][3];
  175. };
  176. /* Constants */
  177. static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
  178. { 0x000C, { NULL } /* Unknown, need DMI string */, {
  179. { "CPU Core", 0, 0, 10, 1, 0 },
  180. { "DDR", 1, 0, 10, 1, 0 },
  181. { "DDR VTT", 2, 0, 10, 1, 0 },
  182. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  183. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  184. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  185. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  186. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  187. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  188. { "ATX +5V", 9, 0, 30, 1, 0 },
  189. { "+3.3V", 10, 0, 20, 1, 0 },
  190. { "5VSB", 11, 0, 30, 1, 0 },
  191. { "CPU", 24, 1, 1, 1, 0 },
  192. { "System", 25, 1, 1, 1, 0 },
  193. { "PWM", 26, 1, 1, 1, 0 },
  194. { "CPU Fan", 32, 2, 60, 1, 0 },
  195. { "NB Fan", 33, 2, 60, 1, 0 },
  196. { "SYS FAN", 34, 2, 60, 1, 0 },
  197. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  198. { NULL, 0, 0, 0, 0, 0 } }
  199. },
  200. { 0x000D, { NULL } /* Abit AW8, need DMI string */, {
  201. { "CPU Core", 0, 0, 10, 1, 0 },
  202. { "DDR", 1, 0, 10, 1, 0 },
  203. { "DDR VTT", 2, 0, 10, 1, 0 },
  204. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  205. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  206. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  207. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  208. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  209. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  210. { "ATX +5V", 9, 0, 30, 1, 0 },
  211. { "+3.3V", 10, 0, 20, 1, 0 },
  212. { "5VSB", 11, 0, 30, 1, 0 },
  213. { "CPU", 24, 1, 1, 1, 0 },
  214. { "System", 25, 1, 1, 1, 0 },
  215. { "PWM1", 26, 1, 1, 1, 0 },
  216. { "PWM2", 27, 1, 1, 1, 0 },
  217. { "PWM3", 28, 1, 1, 1, 0 },
  218. { "PWM4", 29, 1, 1, 1, 0 },
  219. { "CPU Fan", 32, 2, 60, 1, 0 },
  220. { "NB Fan", 33, 2, 60, 1, 0 },
  221. { "SYS Fan", 34, 2, 60, 1, 0 },
  222. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  223. { "AUX2 Fan", 36, 2, 60, 1, 0 },
  224. { "AUX3 Fan", 37, 2, 60, 1, 0 },
  225. { "AUX4 Fan", 38, 2, 60, 1, 0 },
  226. { "AUX5 Fan", 39, 2, 60, 1, 0 },
  227. { NULL, 0, 0, 0, 0, 0 } }
  228. },
  229. { 0x000E, { NULL } /* AL-8, need DMI string */, {
  230. { "CPU Core", 0, 0, 10, 1, 0 },
  231. { "DDR", 1, 0, 10, 1, 0 },
  232. { "DDR VTT", 2, 0, 10, 1, 0 },
  233. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  234. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  235. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  236. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  237. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  238. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  239. { "ATX +5V", 9, 0, 30, 1, 0 },
  240. { "+3.3V", 10, 0, 20, 1, 0 },
  241. { "5VSB", 11, 0, 30, 1, 0 },
  242. { "CPU", 24, 1, 1, 1, 0 },
  243. { "System", 25, 1, 1, 1, 0 },
  244. { "PWM", 26, 1, 1, 1, 0 },
  245. { "CPU Fan", 32, 2, 60, 1, 0 },
  246. { "NB Fan", 33, 2, 60, 1, 0 },
  247. { "SYS Fan", 34, 2, 60, 1, 0 },
  248. { NULL, 0, 0, 0, 0, 0 } }
  249. },
  250. { 0x000F, { NULL } /* Unknown, need DMI string */, {
  251. { "CPU Core", 0, 0, 10, 1, 0 },
  252. { "DDR", 1, 0, 10, 1, 0 },
  253. { "DDR VTT", 2, 0, 10, 1, 0 },
  254. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  255. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  256. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  257. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  258. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  259. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  260. { "ATX +5V", 9, 0, 30, 1, 0 },
  261. { "+3.3V", 10, 0, 20, 1, 0 },
  262. { "5VSB", 11, 0, 30, 1, 0 },
  263. { "CPU", 24, 1, 1, 1, 0 },
  264. { "System", 25, 1, 1, 1, 0 },
  265. { "PWM", 26, 1, 1, 1, 0 },
  266. { "CPU Fan", 32, 2, 60, 1, 0 },
  267. { "NB Fan", 33, 2, 60, 1, 0 },
  268. { "SYS Fan", 34, 2, 60, 1, 0 },
  269. { NULL, 0, 0, 0, 0, 0 } }
  270. },
  271. { 0x0010, { NULL } /* Abit NI8 SLI GR, need DMI string */, {
  272. { "CPU Core", 0, 0, 10, 1, 0 },
  273. { "DDR", 1, 0, 10, 1, 0 },
  274. { "DDR VTT", 2, 0, 10, 1, 0 },
  275. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  276. { "NB 1.4V", 4, 0, 10, 1, 0 },
  277. { "SB 1.5V", 6, 0, 10, 1, 0 },
  278. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  279. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  280. { "ATX +5V", 9, 0, 30, 1, 0 },
  281. { "+3.3V", 10, 0, 20, 1, 0 },
  282. { "5VSB", 11, 0, 30, 1, 0 },
  283. { "CPU", 24, 1, 1, 1, 0 },
  284. { "SYS", 25, 1, 1, 1, 0 },
  285. { "PWM", 26, 1, 1, 1, 0 },
  286. { "CPU Fan", 32, 2, 60, 1, 0 },
  287. { "NB Fan", 33, 2, 60, 1, 0 },
  288. { "SYS Fan", 34, 2, 60, 1, 0 },
  289. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  290. { "OTES1 Fan", 36, 2, 60, 1, 0 },
  291. { NULL, 0, 0, 0, 0, 0 } }
  292. },
  293. { 0x0011, { "AT8 32X", NULL }, {
  294. { "CPU Core", 0, 0, 10, 1, 0 },
  295. { "DDR", 1, 0, 20, 1, 0 },
  296. { "DDR VTT", 2, 0, 10, 1, 0 },
  297. { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 },
  298. { "NB 1.8V", 4, 0, 10, 1, 0 },
  299. { "NB 1.8V Dual", 5, 0, 10, 1, 0 },
  300. { "HTV 1.2", 3, 0, 10, 1, 0 },
  301. { "PCIE 1.2V", 12, 0, 10, 1, 0 },
  302. { "NB 1.2V", 13, 0, 10, 1, 0 },
  303. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  304. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  305. { "ATX +5V", 9, 0, 30, 1, 0 },
  306. { "+3.3V", 10, 0, 20, 1, 0 },
  307. { "5VSB", 11, 0, 30, 1, 0 },
  308. { "CPU", 24, 1, 1, 1, 0 },
  309. { "NB", 25, 1, 1, 1, 0 },
  310. { "System", 26, 1, 1, 1, 0 },
  311. { "PWM", 27, 1, 1, 1, 0 },
  312. { "CPU Fan", 32, 2, 60, 1, 0 },
  313. { "NB Fan", 33, 2, 60, 1, 0 },
  314. { "SYS Fan", 34, 2, 60, 1, 0 },
  315. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  316. { "AUX2 Fan", 36, 2, 60, 1, 0 },
  317. { "AUX3 Fan", 37, 2, 60, 1, 0 },
  318. { NULL, 0, 0, 0, 0, 0 } }
  319. },
  320. { 0x0012, { NULL } /* Abit AN8 32X, need DMI string */, {
  321. { "CPU Core", 0, 0, 10, 1, 0 },
  322. { "DDR", 1, 0, 20, 1, 0 },
  323. { "DDR VTT", 2, 0, 10, 1, 0 },
  324. { "HyperTransport", 3, 0, 10, 1, 0 },
  325. { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 },
  326. { "NB", 4, 0, 10, 1, 0 },
  327. { "SB", 6, 0, 10, 1, 0 },
  328. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  329. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  330. { "ATX +5V", 9, 0, 30, 1, 0 },
  331. { "+3.3V", 10, 0, 20, 1, 0 },
  332. { "5VSB", 11, 0, 30, 1, 0 },
  333. { "CPU", 24, 1, 1, 1, 0 },
  334. { "SYS", 25, 1, 1, 1, 0 },
  335. { "PWM", 26, 1, 1, 1, 0 },
  336. { "CPU Fan", 32, 2, 60, 1, 0 },
  337. { "NB Fan", 33, 2, 60, 1, 0 },
  338. { "SYS Fan", 34, 2, 60, 1, 0 },
  339. { "AUX1 Fan", 36, 2, 60, 1, 0 },
  340. { NULL, 0, 0, 0, 0, 0 } }
  341. },
  342. { 0x0013, { NULL } /* Abit AW8D, need DMI string */, {
  343. { "CPU Core", 0, 0, 10, 1, 0 },
  344. { "DDR", 1, 0, 10, 1, 0 },
  345. { "DDR VTT", 2, 0, 10, 1, 0 },
  346. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  347. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  348. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  349. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  350. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  351. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  352. { "ATX +5V", 9, 0, 30, 1, 0 },
  353. { "+3.3V", 10, 0, 20, 1, 0 },
  354. { "5VSB", 11, 0, 30, 1, 0 },
  355. { "CPU", 24, 1, 1, 1, 0 },
  356. { "System", 25, 1, 1, 1, 0 },
  357. { "PWM1", 26, 1, 1, 1, 0 },
  358. { "PWM2", 27, 1, 1, 1, 0 },
  359. { "PWM3", 28, 1, 1, 1, 0 },
  360. { "PWM4", 29, 1, 1, 1, 0 },
  361. { "CPU Fan", 32, 2, 60, 1, 0 },
  362. { "NB Fan", 33, 2, 60, 1, 0 },
  363. { "SYS Fan", 34, 2, 60, 1, 0 },
  364. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  365. { "AUX2 Fan", 36, 2, 60, 1, 0 },
  366. { "AUX3 Fan", 37, 2, 60, 1, 0 },
  367. { "AUX4 Fan", 38, 2, 60, 1, 0 },
  368. { "AUX5 Fan", 39, 2, 60, 1, 0 },
  369. { NULL, 0, 0, 0, 0, 0 } }
  370. },
  371. { 0x0014, { "AB9", "AB9 Pro", NULL }, {
  372. { "CPU Core", 0, 0, 10, 1, 0 },
  373. { "DDR", 1, 0, 10, 1, 0 },
  374. { "DDR VTT", 2, 0, 10, 1, 0 },
  375. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  376. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  377. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  378. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  379. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  380. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  381. { "ATX +5V", 9, 0, 30, 1, 0 },
  382. { "+3.3V", 10, 0, 20, 1, 0 },
  383. { "5VSB", 11, 0, 30, 1, 0 },
  384. { "CPU", 24, 1, 1, 1, 0 },
  385. { "System", 25, 1, 1, 1, 0 },
  386. { "PWM", 26, 1, 1, 1, 0 },
  387. { "CPU Fan", 32, 2, 60, 1, 0 },
  388. { "NB Fan", 33, 2, 60, 1, 0 },
  389. { "SYS Fan", 34, 2, 60, 1, 0 },
  390. { NULL, 0, 0, 0, 0, 0 } }
  391. },
  392. { 0x0015, { NULL } /* Unknown, need DMI string */, {
  393. { "CPU Core", 0, 0, 10, 1, 0 },
  394. { "DDR", 1, 0, 20, 1, 0 },
  395. { "DDR VTT", 2, 0, 10, 1, 0 },
  396. { "HyperTransport", 3, 0, 10, 1, 0 },
  397. { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 },
  398. { "NB", 4, 0, 10, 1, 0 },
  399. { "SB", 6, 0, 10, 1, 0 },
  400. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  401. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  402. { "ATX +5V", 9, 0, 30, 1, 0 },
  403. { "+3.3V", 10, 0, 20, 1, 0 },
  404. { "5VSB", 11, 0, 30, 1, 0 },
  405. { "CPU", 24, 1, 1, 1, 0 },
  406. { "SYS", 25, 1, 1, 1, 0 },
  407. { "PWM", 26, 1, 1, 1, 0 },
  408. { "CPU Fan", 32, 2, 60, 1, 0 },
  409. { "NB Fan", 33, 2, 60, 1, 0 },
  410. { "SYS Fan", 34, 2, 60, 1, 0 },
  411. { "AUX1 Fan", 33, 2, 60, 1, 0 },
  412. { "AUX2 Fan", 35, 2, 60, 1, 0 },
  413. { "AUX3 Fan", 36, 2, 60, 1, 0 },
  414. { NULL, 0, 0, 0, 0, 0 } }
  415. },
  416. { 0x0016, { "AW9D-MAX", NULL }, {
  417. { "CPU Core", 0, 0, 10, 1, 0 },
  418. { "DDR2", 1, 0, 20, 1, 0 },
  419. { "DDR2 VTT", 2, 0, 10, 1, 0 },
  420. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  421. { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 },
  422. { "MCH 2.5V", 5, 0, 20, 1, 0 },
  423. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  424. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  425. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  426. { "ATX +5V", 9, 0, 30, 1, 0 },
  427. { "+3.3V", 10, 0, 20, 1, 0 },
  428. { "5VSB", 11, 0, 30, 1, 0 },
  429. { "CPU", 24, 1, 1, 1, 0 },
  430. { "System", 25, 1, 1, 1, 0 },
  431. { "PWM1", 26, 1, 1, 1, 0 },
  432. { "PWM2", 27, 1, 1, 1, 0 },
  433. { "PWM3", 28, 1, 1, 1, 0 },
  434. { "PWM4", 29, 1, 1, 1, 0 },
  435. { "CPU Fan", 32, 2, 60, 1, 0 },
  436. { "NB Fan", 33, 2, 60, 1, 0 },
  437. { "SYS Fan", 34, 2, 60, 1, 0 },
  438. { "AUX1 Fan", 35, 2, 60, 1, 0 },
  439. { "AUX2 Fan", 36, 2, 60, 1, 0 },
  440. { "AUX3 Fan", 37, 2, 60, 1, 0 },
  441. { "OTES1 Fan", 38, 2, 60, 1, 0 },
  442. { NULL, 0, 0, 0, 0, 0 } }
  443. },
  444. { 0x0017, { NULL } /* Unknown, need DMI string */, {
  445. { "CPU Core", 0, 0, 10, 1, 0 },
  446. { "DDR2", 1, 0, 20, 1, 0 },
  447. { "DDR2 VTT", 2, 0, 10, 1, 0 },
  448. { "HyperTransport", 3, 0, 10, 1, 0 },
  449. { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 },
  450. { "NB 1.8V", 4, 0, 10, 1, 0 },
  451. { "NB 1.2V ", 13, 0, 10, 1, 0 },
  452. { "SB 1.2V", 5, 0, 10, 1, 0 },
  453. { "PCIE 1.2V", 12, 0, 10, 1, 0 },
  454. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  455. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  456. { "ATX +5V", 9, 0, 30, 1, 0 },
  457. { "ATX +3.3V", 10, 0, 20, 1, 0 },
  458. { "ATX 5VSB", 11, 0, 30, 1, 0 },
  459. { "CPU", 24, 1, 1, 1, 0 },
  460. { "System", 26, 1, 1, 1, 0 },
  461. { "PWM", 27, 1, 1, 1, 0 },
  462. { "CPU FAN", 32, 2, 60, 1, 0 },
  463. { "SYS FAN", 34, 2, 60, 1, 0 },
  464. { "AUX1 FAN", 35, 2, 60, 1, 0 },
  465. { "AUX2 FAN", 36, 2, 60, 1, 0 },
  466. { "AUX3 FAN", 37, 2, 60, 1, 0 },
  467. { NULL, 0, 0, 0, 0, 0 } }
  468. },
  469. { 0x0018, { "AB9 QuadGT", NULL }, {
  470. { "CPU Core", 0, 0, 10, 1, 0 },
  471. { "DDR2", 1, 0, 20, 1, 0 },
  472. { "DDR2 VTT", 2, 0, 10, 1, 0 },
  473. { "CPU VTT", 3, 0, 10, 1, 0 },
  474. { "MCH 1.25V", 4, 0, 10, 1, 0 },
  475. { "ICHIO 1.5V", 5, 0, 10, 1, 0 },
  476. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  477. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  478. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  479. { "ATX +5V", 9, 0, 30, 1, 0 },
  480. { "+3.3V", 10, 0, 20, 1, 0 },
  481. { "5VSB", 11, 0, 30, 1, 0 },
  482. { "CPU", 24, 1, 1, 1, 0 },
  483. { "System", 25, 1, 1, 1, 0 },
  484. { "PWM Phase1", 26, 1, 1, 1, 0 },
  485. { "PWM Phase2", 27, 1, 1, 1, 0 },
  486. { "PWM Phase3", 28, 1, 1, 1, 0 },
  487. { "PWM Phase4", 29, 1, 1, 1, 0 },
  488. { "PWM Phase5", 30, 1, 1, 1, 0 },
  489. { "CPU Fan", 32, 2, 60, 1, 0 },
  490. { "SYS Fan", 34, 2, 60, 1, 0 },
  491. { "AUX1 Fan", 33, 2, 60, 1, 0 },
  492. { "AUX2 Fan", 35, 2, 60, 1, 0 },
  493. { "AUX3 Fan", 36, 2, 60, 1, 0 },
  494. { NULL, 0, 0, 0, 0, 0 } }
  495. },
  496. { 0x0019, { "IN9 32X MAX", NULL }, {
  497. { "CPU Core", 7, 0, 10, 1, 0 },
  498. { "DDR2", 13, 0, 20, 1, 0 },
  499. { "DDR2 VTT", 14, 0, 10, 1, 0 },
  500. { "CPU VTT", 3, 0, 20, 1, 0 },
  501. { "NB 1.2V", 4, 0, 10, 1, 0 },
  502. { "SB 1.5V", 6, 0, 10, 1, 0 },
  503. { "HyperTransport", 5, 0, 10, 1, 0 },
  504. { "ATX +12V (24-Pin)", 12, 0, 60, 1, 0 },
  505. { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 },
  506. { "ATX +5V", 9, 0, 30, 1, 0 },
  507. { "ATX +3.3V", 10, 0, 20, 1, 0 },
  508. { "ATX 5VSB", 11, 0, 30, 1, 0 },
  509. { "CPU", 24, 1, 1, 1, 0 },
  510. { "System", 25, 1, 1, 1, 0 },
  511. { "PWM Phase1", 26, 1, 1, 1, 0 },
  512. { "PWM Phase2", 27, 1, 1, 1, 0 },
  513. { "PWM Phase3", 28, 1, 1, 1, 0 },
  514. { "PWM Phase4", 29, 1, 1, 1, 0 },
  515. { "PWM Phase5", 30, 1, 1, 1, 0 },
  516. { "CPU FAN", 32, 2, 60, 1, 0 },
  517. { "SYS FAN", 34, 2, 60, 1, 0 },
  518. { "AUX1 FAN", 33, 2, 60, 1, 0 },
  519. { "AUX2 FAN", 35, 2, 60, 1, 0 },
  520. { "AUX3 FAN", 36, 2, 60, 1, 0 },
  521. { NULL, 0, 0, 0, 0, 0 } }
  522. },
  523. { 0x001A, { "IP35 Pro", "IP35 Pro XE", NULL }, {
  524. { "CPU Core", 0, 0, 10, 1, 0 },
  525. { "DDR2", 1, 0, 20, 1, 0 },
  526. { "DDR2 VTT", 2, 0, 10, 1, 0 },
  527. { "CPU VTT 1.2V", 3, 0, 10, 1, 0 },
  528. { "MCH 1.25V", 4, 0, 10, 1, 0 },
  529. { "ICHIO 1.5V", 5, 0, 10, 1, 0 },
  530. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  531. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  532. { "ATX +12V (8-pin)", 8, 0, 60, 1, 0 },
  533. { "ATX +5V", 9, 0, 30, 1, 0 },
  534. { "+3.3V", 10, 0, 20, 1, 0 },
  535. { "5VSB", 11, 0, 30, 1, 0 },
  536. { "CPU", 24, 1, 1, 1, 0 },
  537. { "System", 25, 1, 1, 1, 0 },
  538. { "PWM", 26, 1, 1, 1, 0 },
  539. { "PWM Phase2", 27, 1, 1, 1, 0 },
  540. { "PWM Phase3", 28, 1, 1, 1, 0 },
  541. { "PWM Phase4", 29, 1, 1, 1, 0 },
  542. { "PWM Phase5", 30, 1, 1, 1, 0 },
  543. { "CPU Fan", 32, 2, 60, 1, 0 },
  544. { "SYS Fan", 34, 2, 60, 1, 0 },
  545. { "AUX1 Fan", 33, 2, 60, 1, 0 },
  546. { "AUX2 Fan", 35, 2, 60, 1, 0 },
  547. { "AUX3 Fan", 36, 2, 60, 1, 0 },
  548. { "AUX4 Fan", 37, 2, 60, 1, 0 },
  549. { NULL, 0, 0, 0, 0, 0 } }
  550. },
  551. { 0x001B, { NULL } /* Unknown, need DMI string */, {
  552. { "CPU Core", 0, 0, 10, 1, 0 },
  553. { "DDR3", 1, 0, 20, 1, 0 },
  554. { "DDR3 VTT", 2, 0, 10, 1, 0 },
  555. { "CPU VTT", 3, 0, 10, 1, 0 },
  556. { "MCH 1.25V", 4, 0, 10, 1, 0 },
  557. { "ICHIO 1.5V", 5, 0, 10, 1, 0 },
  558. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  559. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  560. { "ATX +12V (8-pin)", 8, 0, 60, 1, 0 },
  561. { "ATX +5V", 9, 0, 30, 1, 0 },
  562. { "+3.3V", 10, 0, 20, 1, 0 },
  563. { "5VSB", 11, 0, 30, 1, 0 },
  564. { "CPU", 24, 1, 1, 1, 0 },
  565. { "System", 25, 1, 1, 1, 0 },
  566. { "PWM Phase1", 26, 1, 1, 1, 0 },
  567. { "PWM Phase2", 27, 1, 1, 1, 0 },
  568. { "PWM Phase3", 28, 1, 1, 1, 0 },
  569. { "PWM Phase4", 29, 1, 1, 1, 0 },
  570. { "PWM Phase5", 30, 1, 1, 1, 0 },
  571. { "CPU Fan", 32, 2, 60, 1, 0 },
  572. { "SYS Fan", 34, 2, 60, 1, 0 },
  573. { "AUX1 Fan", 33, 2, 60, 1, 0 },
  574. { "AUX2 Fan", 35, 2, 60, 1, 0 },
  575. { "AUX3 Fan", 36, 2, 60, 1, 0 },
  576. { NULL, 0, 0, 0, 0, 0 } }
  577. },
  578. { 0x001C, { "IX38 QuadGT", NULL }, {
  579. { "CPU Core", 0, 0, 10, 1, 0 },
  580. { "DDR2", 1, 0, 20, 1, 0 },
  581. { "DDR2 VTT", 2, 0, 10, 1, 0 },
  582. { "CPU VTT", 3, 0, 10, 1, 0 },
  583. { "MCH 1.25V", 4, 0, 10, 1, 0 },
  584. { "ICHIO 1.5V", 5, 0, 10, 1, 0 },
  585. { "ICH 1.05V", 6, 0, 10, 1, 0 },
  586. { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 },
  587. { "ATX +12V (8-pin)", 8, 0, 60, 1, 0 },
  588. { "ATX +5V", 9, 0, 30, 1, 0 },
  589. { "+3.3V", 10, 0, 20, 1, 0 },
  590. { "5VSB", 11, 0, 30, 1, 0 },
  591. { "CPU", 24, 1, 1, 1, 0 },
  592. { "System", 25, 1, 1, 1, 0 },
  593. { "PWM Phase1", 26, 1, 1, 1, 0 },
  594. { "PWM Phase2", 27, 1, 1, 1, 0 },
  595. { "PWM Phase3", 28, 1, 1, 1, 0 },
  596. { "PWM Phase4", 29, 1, 1, 1, 0 },
  597. { "PWM Phase5", 30, 1, 1, 1, 0 },
  598. { "CPU Fan", 32, 2, 60, 1, 0 },
  599. { "SYS Fan", 34, 2, 60, 1, 0 },
  600. { "AUX1 Fan", 33, 2, 60, 1, 0 },
  601. { "AUX2 Fan", 35, 2, 60, 1, 0 },
  602. { "AUX3 Fan", 36, 2, 60, 1, 0 },
  603. { NULL, 0, 0, 0, 0, 0 } }
  604. },
  605. { 0x0000, { NULL }, { { NULL, 0, 0, 0, 0, 0 } } }
  606. };
  607. /* Insmod parameters */
  608. static bool force;
  609. module_param(force, bool, 0);
  610. MODULE_PARM_DESC(force, "Set to one to force detection.");
  611. /* Default verbose is 1, since this driver is still in the testing phase */
  612. static bool verbose = 1;
  613. module_param(verbose, bool, 0644);
  614. MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting");
  615. static const char *never_happen = "This should never happen.";
  616. static const char *report_this =
  617. "Please report this to the abituguru3 maintainer (see MAINTAINERS)";
  618. /* wait while the uguru is busy (usually after a write) */
  619. static int abituguru3_wait_while_busy(struct abituguru3_data *data)
  620. {
  621. u8 x;
  622. int timeout = ABIT_UGURU3_WAIT_TIMEOUT;
  623. while ((x = inb_p(data->addr + ABIT_UGURU3_DATA)) &
  624. ABIT_UGURU3_STATUS_BUSY) {
  625. timeout--;
  626. if (timeout == 0)
  627. return x;
  628. /*
  629. * sleep a bit before our last try, to give the uGuru3 one
  630. * last chance to respond.
  631. */
  632. if (timeout == 1)
  633. msleep(1);
  634. }
  635. return ABIT_UGURU3_SUCCESS;
  636. }
  637. /* wait till uguru is ready to be read */
  638. static int abituguru3_wait_for_read(struct abituguru3_data *data)
  639. {
  640. u8 x;
  641. int timeout = ABIT_UGURU3_WAIT_TIMEOUT;
  642. while (!((x = inb_p(data->addr + ABIT_UGURU3_DATA)) &
  643. ABIT_UGURU3_STATUS_READY_FOR_READ)) {
  644. timeout--;
  645. if (timeout == 0)
  646. return x;
  647. /*
  648. * sleep a bit before our last try, to give the uGuru3 one
  649. * last chance to respond.
  650. */
  651. if (timeout == 1)
  652. msleep(1);
  653. }
  654. return ABIT_UGURU3_SUCCESS;
  655. }
  656. /*
  657. * This synchronizes us with the uGuru3's protocol state machine, this
  658. * must be done before each command.
  659. */
  660. static int abituguru3_synchronize(struct abituguru3_data *data)
  661. {
  662. int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT;
  663. x = abituguru3_wait_while_busy(data);
  664. if (x != ABIT_UGURU3_SUCCESS) {
  665. ABIT_UGURU3_DEBUG("synchronize timeout during initial busy "
  666. "wait, status: 0x%02x\n", x);
  667. return -EIO;
  668. }
  669. outb(0x20, data->addr + ABIT_UGURU3_DATA);
  670. x = abituguru3_wait_while_busy(data);
  671. if (x != ABIT_UGURU3_SUCCESS) {
  672. ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, "
  673. "status: 0x%02x\n", x);
  674. return -EIO;
  675. }
  676. outb(0x10, data->addr + ABIT_UGURU3_CMD);
  677. x = abituguru3_wait_while_busy(data);
  678. if (x != ABIT_UGURU3_SUCCESS) {
  679. ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, "
  680. "status: 0x%02x\n", x);
  681. return -EIO;
  682. }
  683. outb(0x00, data->addr + ABIT_UGURU3_CMD);
  684. x = abituguru3_wait_while_busy(data);
  685. if (x != ABIT_UGURU3_SUCCESS) {
  686. ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, "
  687. "status: 0x%02x\n", x);
  688. return -EIO;
  689. }
  690. x = abituguru3_wait_for_read(data);
  691. if (x != ABIT_UGURU3_SUCCESS) {
  692. ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, "
  693. "status: 0x%02x\n", x);
  694. return -EIO;
  695. }
  696. while ((x = inb(data->addr + ABIT_UGURU3_CMD)) != 0xAC) {
  697. timeout--;
  698. if (timeout == 0) {
  699. ABIT_UGURU3_DEBUG("synchronize timeout cmd does not "
  700. "hold 0xAC after synchronize, cmd: 0x%02x\n",
  701. x);
  702. return -EIO;
  703. }
  704. msleep(1);
  705. }
  706. return 0;
  707. }
  708. /*
  709. * Read count bytes from sensor sensor_addr in bank bank_addr and store the
  710. * result in buf
  711. */
  712. static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
  713. u8 count, u8 *buf)
  714. {
  715. int i, x;
  716. x = abituguru3_synchronize(data);
  717. if (x)
  718. return x;
  719. outb(0x1A, data->addr + ABIT_UGURU3_DATA);
  720. x = abituguru3_wait_while_busy(data);
  721. if (x != ABIT_UGURU3_SUCCESS) {
  722. ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
  723. "sending 0x1A, status: 0x%02x\n", (unsigned int)bank,
  724. (unsigned int)offset, x);
  725. return -EIO;
  726. }
  727. outb(bank, data->addr + ABIT_UGURU3_CMD);
  728. x = abituguru3_wait_while_busy(data);
  729. if (x != ABIT_UGURU3_SUCCESS) {
  730. ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
  731. "sending the bank, status: 0x%02x\n",
  732. (unsigned int)bank, (unsigned int)offset, x);
  733. return -EIO;
  734. }
  735. outb(offset, data->addr + ABIT_UGURU3_CMD);
  736. x = abituguru3_wait_while_busy(data);
  737. if (x != ABIT_UGURU3_SUCCESS) {
  738. ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
  739. "sending the offset, status: 0x%02x\n",
  740. (unsigned int)bank, (unsigned int)offset, x);
  741. return -EIO;
  742. }
  743. outb(count, data->addr + ABIT_UGURU3_CMD);
  744. x = abituguru3_wait_while_busy(data);
  745. if (x != ABIT_UGURU3_SUCCESS) {
  746. ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
  747. "sending the count, status: 0x%02x\n",
  748. (unsigned int)bank, (unsigned int)offset, x);
  749. return -EIO;
  750. }
  751. for (i = 0; i < count; i++) {
  752. x = abituguru3_wait_for_read(data);
  753. if (x != ABIT_UGURU3_SUCCESS) {
  754. ABIT_UGURU3_DEBUG("timeout reading byte %d from "
  755. "0x%02x:0x%02x, status: 0x%02x\n", i,
  756. (unsigned int)bank, (unsigned int)offset, x);
  757. break;
  758. }
  759. buf[i] = inb(data->addr + ABIT_UGURU3_CMD);
  760. }
  761. return i;
  762. }
  763. /*
  764. * Sensor settings are stored 1 byte per offset with the bytes
  765. * placed add consecutive offsets.
  766. */
  767. static int abituguru3_read_increment_offset(struct abituguru3_data *data,
  768. u8 bank, u8 offset, u8 count,
  769. u8 *buf, int offset_count)
  770. {
  771. int i, x;
  772. for (i = 0; i < offset_count; i++) {
  773. x = abituguru3_read(data, bank, offset + i, count,
  774. buf + i * count);
  775. if (x != count) {
  776. if (x < 0)
  777. return x;
  778. return i * count + x;
  779. }
  780. }
  781. return i * count;
  782. }
  783. /*
  784. * Following are the sysfs callback functions. These functions expect:
  785. * sensor_device_attribute_2->index: index into the data->sensors array
  786. * sensor_device_attribute_2->nr: register offset, bitmask or NA.
  787. */
  788. static struct abituguru3_data *abituguru3_update_device(struct device *dev);
  789. static ssize_t show_value(struct device *dev,
  790. struct device_attribute *devattr, char *buf)
  791. {
  792. int value;
  793. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  794. struct abituguru3_data *data = abituguru3_update_device(dev);
  795. const struct abituguru3_sensor_info *sensor;
  796. if (!data)
  797. return -EIO;
  798. sensor = &data->sensors[attr->index];
  799. /* are we reading a setting, or is this a normal read? */
  800. if (attr->nr)
  801. value = data->settings[sensor->port][attr->nr];
  802. else
  803. value = data->value[sensor->port];
  804. /* convert the value */
  805. value = (value * sensor->multiplier) / sensor->divisor +
  806. sensor->offset;
  807. /*
  808. * alternatively we could update the sensors settings struct for this,
  809. * but then its contents would differ from the windows sw ini files
  810. */
  811. if (sensor->type == ABIT_UGURU3_TEMP_SENSOR)
  812. value *= 1000;
  813. return sprintf(buf, "%d\n", value);
  814. }
  815. static ssize_t show_alarm(struct device *dev,
  816. struct device_attribute *devattr, char *buf)
  817. {
  818. int port;
  819. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  820. struct abituguru3_data *data = abituguru3_update_device(dev);
  821. if (!data)
  822. return -EIO;
  823. port = data->sensors[attr->index].port;
  824. /*
  825. * See if the alarm bit for this sensor is set and if a bitmask is
  826. * given in attr->nr also check if the alarm matches the type of alarm
  827. * we're looking for (for volt it can be either low or high). The type
  828. * is stored in a few readonly bits in the settings of the sensor.
  829. */
  830. if ((data->alarms[port / 8] & (0x01 << (port % 8))) &&
  831. (!attr->nr || (data->settings[port][0] & attr->nr)))
  832. return sprintf(buf, "1\n");
  833. else
  834. return sprintf(buf, "0\n");
  835. }
  836. static ssize_t show_mask(struct device *dev,
  837. struct device_attribute *devattr, char *buf)
  838. {
  839. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  840. struct abituguru3_data *data = dev_get_drvdata(dev);
  841. if (data->settings[data->sensors[attr->index].port][0] & attr->nr)
  842. return sprintf(buf, "1\n");
  843. else
  844. return sprintf(buf, "0\n");
  845. }
  846. static ssize_t show_label(struct device *dev,
  847. struct device_attribute *devattr, char *buf)
  848. {
  849. struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
  850. struct abituguru3_data *data = dev_get_drvdata(dev);
  851. return sprintf(buf, "%s\n", data->sensors[attr->index].name);
  852. }
  853. static ssize_t show_name(struct device *dev,
  854. struct device_attribute *devattr, char *buf)
  855. {
  856. return sprintf(buf, "%s\n", ABIT_UGURU3_NAME);
  857. }
  858. /* Sysfs attr templates, the real entries are generated automatically. */
  859. static const
  860. struct sensor_device_attribute_2 abituguru3_sysfs_templ[3][10] = { {
  861. SENSOR_ATTR_2(in%d_input, 0444, show_value, NULL, 0, 0),
  862. SENSOR_ATTR_2(in%d_min, 0444, show_value, NULL, 1, 0),
  863. SENSOR_ATTR_2(in%d_max, 0444, show_value, NULL, 2, 0),
  864. SENSOR_ATTR_2(in%d_min_alarm, 0444, show_alarm, NULL,
  865. ABIT_UGURU3_VOLT_LOW_ALARM_FLAG, 0),
  866. SENSOR_ATTR_2(in%d_max_alarm, 0444, show_alarm, NULL,
  867. ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG, 0),
  868. SENSOR_ATTR_2(in%d_beep, 0444, show_mask, NULL,
  869. ABIT_UGURU3_BEEP_ENABLE, 0),
  870. SENSOR_ATTR_2(in%d_shutdown, 0444, show_mask, NULL,
  871. ABIT_UGURU3_SHUTDOWN_ENABLE, 0),
  872. SENSOR_ATTR_2(in%d_min_alarm_enable, 0444, show_mask, NULL,
  873. ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE, 0),
  874. SENSOR_ATTR_2(in%d_max_alarm_enable, 0444, show_mask, NULL,
  875. ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE, 0),
  876. SENSOR_ATTR_2(in%d_label, 0444, show_label, NULL, 0, 0)
  877. }, {
  878. SENSOR_ATTR_2(temp%d_input, 0444, show_value, NULL, 0, 0),
  879. SENSOR_ATTR_2(temp%d_max, 0444, show_value, NULL, 1, 0),
  880. SENSOR_ATTR_2(temp%d_crit, 0444, show_value, NULL, 2, 0),
  881. SENSOR_ATTR_2(temp%d_alarm, 0444, show_alarm, NULL, 0, 0),
  882. SENSOR_ATTR_2(temp%d_beep, 0444, show_mask, NULL,
  883. ABIT_UGURU3_BEEP_ENABLE, 0),
  884. SENSOR_ATTR_2(temp%d_shutdown, 0444, show_mask, NULL,
  885. ABIT_UGURU3_SHUTDOWN_ENABLE, 0),
  886. SENSOR_ATTR_2(temp%d_alarm_enable, 0444, show_mask, NULL,
  887. ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE, 0),
  888. SENSOR_ATTR_2(temp%d_label, 0444, show_label, NULL, 0, 0)
  889. }, {
  890. SENSOR_ATTR_2(fan%d_input, 0444, show_value, NULL, 0, 0),
  891. SENSOR_ATTR_2(fan%d_min, 0444, show_value, NULL, 1, 0),
  892. SENSOR_ATTR_2(fan%d_alarm, 0444, show_alarm, NULL, 0, 0),
  893. SENSOR_ATTR_2(fan%d_beep, 0444, show_mask, NULL,
  894. ABIT_UGURU3_BEEP_ENABLE, 0),
  895. SENSOR_ATTR_2(fan%d_shutdown, 0444, show_mask, NULL,
  896. ABIT_UGURU3_SHUTDOWN_ENABLE, 0),
  897. SENSOR_ATTR_2(fan%d_alarm_enable, 0444, show_mask, NULL,
  898. ABIT_UGURU3_FAN_LOW_ALARM_ENABLE, 0),
  899. SENSOR_ATTR_2(fan%d_label, 0444, show_label, NULL, 0, 0)
  900. } };
  901. static struct sensor_device_attribute_2 abituguru3_sysfs_attr[] = {
  902. SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0),
  903. };
  904. static int abituguru3_probe(struct platform_device *pdev)
  905. {
  906. const int no_sysfs_attr[3] = { 10, 8, 7 };
  907. int sensor_index[3] = { 0, 1, 1 };
  908. struct abituguru3_data *data;
  909. int i, j, type, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV;
  910. char *sysfs_filename;
  911. u8 buf[2];
  912. u16 id;
  913. data = devm_kzalloc(&pdev->dev, sizeof(struct abituguru3_data),
  914. GFP_KERNEL);
  915. if (!data)
  916. return -ENOMEM;
  917. data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
  918. mutex_init(&data->update_lock);
  919. platform_set_drvdata(pdev, data);
  920. /* Read the motherboard ID */
  921. i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, ABIT_UGURU3_BOARD_ID,
  922. 2, buf);
  923. if (i != 2)
  924. goto abituguru3_probe_error;
  925. /* Completely read the uGuru to see if one really is there */
  926. if (!abituguru3_update_device(&pdev->dev))
  927. goto abituguru3_probe_error;
  928. /* lookup the ID in our motherboard table */
  929. id = ((u16)buf[0] << 8) | (u16)buf[1];
  930. for (i = 0; abituguru3_motherboards[i].id; i++)
  931. if (abituguru3_motherboards[i].id == id)
  932. break;
  933. if (!abituguru3_motherboards[i].id) {
  934. pr_err("error unknown motherboard ID: %04X. %s\n",
  935. (unsigned int)id, report_this);
  936. goto abituguru3_probe_error;
  937. }
  938. data->sensors = abituguru3_motherboards[i].sensors;
  939. pr_info("found Abit uGuru3, motherboard ID: %04X\n", (unsigned int)id);
  940. /* Fill the sysfs attr array */
  941. sysfs_attr_i = 0;
  942. sysfs_filename = data->sysfs_names;
  943. sysfs_names_free = ABIT_UGURU3_SYSFS_NAMES_LENGTH;
  944. for (i = 0; data->sensors[i].name; i++) {
  945. /* Fail safe check, this should never happen! */
  946. if (i >= ABIT_UGURU3_MAX_NO_SENSORS) {
  947. pr_err("Fatal error motherboard has more sensors then ABIT_UGURU3_MAX_NO_SENSORS. %s %s\n",
  948. never_happen, report_this);
  949. res = -ENAMETOOLONG;
  950. goto abituguru3_probe_error;
  951. }
  952. type = data->sensors[i].type;
  953. for (j = 0; j < no_sysfs_attr[type]; j++) {
  954. used = snprintf(sysfs_filename, sysfs_names_free,
  955. abituguru3_sysfs_templ[type][j].dev_attr.attr.
  956. name, sensor_index[type]) + 1;
  957. data->sysfs_attr[sysfs_attr_i] =
  958. abituguru3_sysfs_templ[type][j];
  959. data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name =
  960. sysfs_filename;
  961. data->sysfs_attr[sysfs_attr_i].index = i;
  962. sysfs_filename += used;
  963. sysfs_names_free -= used;
  964. sysfs_attr_i++;
  965. }
  966. sensor_index[type]++;
  967. }
  968. /* Fail safe check, this should never happen! */
  969. if (sysfs_names_free < 0) {
  970. pr_err("Fatal error ran out of space for sysfs attr names. %s %s\n",
  971. never_happen, report_this);
  972. res = -ENAMETOOLONG;
  973. goto abituguru3_probe_error;
  974. }
  975. /* Register sysfs hooks */
  976. for (i = 0; i < sysfs_attr_i; i++)
  977. if (device_create_file(&pdev->dev,
  978. &data->sysfs_attr[i].dev_attr))
  979. goto abituguru3_probe_error;
  980. for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++)
  981. if (device_create_file(&pdev->dev,
  982. &abituguru3_sysfs_attr[i].dev_attr))
  983. goto abituguru3_probe_error;
  984. data->hwmon_dev = hwmon_device_register(&pdev->dev);
  985. if (IS_ERR(data->hwmon_dev)) {
  986. res = PTR_ERR(data->hwmon_dev);
  987. goto abituguru3_probe_error;
  988. }
  989. return 0; /* success */
  990. abituguru3_probe_error:
  991. for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
  992. device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
  993. for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++)
  994. device_remove_file(&pdev->dev,
  995. &abituguru3_sysfs_attr[i].dev_attr);
  996. return res;
  997. }
  998. static int abituguru3_remove(struct platform_device *pdev)
  999. {
  1000. int i;
  1001. struct abituguru3_data *data = platform_get_drvdata(pdev);
  1002. platform_set_drvdata(pdev, NULL);
  1003. hwmon_device_unregister(data->hwmon_dev);
  1004. for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
  1005. device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
  1006. for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++)
  1007. device_remove_file(&pdev->dev,
  1008. &abituguru3_sysfs_attr[i].dev_attr);
  1009. return 0;
  1010. }
  1011. static struct abituguru3_data *abituguru3_update_device(struct device *dev)
  1012. {
  1013. int i;
  1014. struct abituguru3_data *data = dev_get_drvdata(dev);
  1015. mutex_lock(&data->update_lock);
  1016. if (!data->valid || time_after(jiffies, data->last_updated + HZ)) {
  1017. /* Clear data->valid while updating */
  1018. data->valid = 0;
  1019. /* Read alarms */
  1020. if (abituguru3_read_increment_offset(data,
  1021. ABIT_UGURU3_SETTINGS_BANK,
  1022. ABIT_UGURU3_ALARMS_START,
  1023. 1, data->alarms, 48/8) != (48/8))
  1024. goto LEAVE_UPDATE;
  1025. /* Read in and temp sensors (3 byte settings / sensor) */
  1026. for (i = 0; i < 32; i++) {
  1027. if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK,
  1028. ABIT_UGURU3_VALUES_START + i,
  1029. 1, &data->value[i]) != 1)
  1030. goto LEAVE_UPDATE;
  1031. if (abituguru3_read_increment_offset(data,
  1032. ABIT_UGURU3_SETTINGS_BANK,
  1033. ABIT_UGURU3_SETTINGS_START + i * 3,
  1034. 1,
  1035. data->settings[i], 3) != 3)
  1036. goto LEAVE_UPDATE;
  1037. }
  1038. /* Read temp sensors (2 byte settings / sensor) */
  1039. for (i = 0; i < 16; i++) {
  1040. if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK,
  1041. ABIT_UGURU3_VALUES_START + 32 + i,
  1042. 1, &data->value[32 + i]) != 1)
  1043. goto LEAVE_UPDATE;
  1044. if (abituguru3_read_increment_offset(data,
  1045. ABIT_UGURU3_SETTINGS_BANK,
  1046. ABIT_UGURU3_SETTINGS_START + 32 * 3 +
  1047. i * 2, 1,
  1048. data->settings[32 + i], 2) != 2)
  1049. goto LEAVE_UPDATE;
  1050. }
  1051. data->last_updated = jiffies;
  1052. data->valid = 1;
  1053. }
  1054. LEAVE_UPDATE:
  1055. mutex_unlock(&data->update_lock);
  1056. if (data->valid)
  1057. return data;
  1058. else
  1059. return NULL;
  1060. }
  1061. #ifdef CONFIG_PM_SLEEP
  1062. static int abituguru3_suspend(struct device *dev)
  1063. {
  1064. struct abituguru3_data *data = dev_get_drvdata(dev);
  1065. /*
  1066. * make sure all communications with the uguru3 are done and no new
  1067. * ones are started
  1068. */
  1069. mutex_lock(&data->update_lock);
  1070. return 0;
  1071. }
  1072. static int abituguru3_resume(struct device *dev)
  1073. {
  1074. struct abituguru3_data *data = dev_get_drvdata(dev);
  1075. mutex_unlock(&data->update_lock);
  1076. return 0;
  1077. }
  1078. static SIMPLE_DEV_PM_OPS(abituguru3_pm, abituguru3_suspend, abituguru3_resume);
  1079. #define ABIT_UGURU3_PM &abituguru3_pm
  1080. #else
  1081. #define ABIT_UGURU3_PM NULL
  1082. #endif /* CONFIG_PM */
  1083. static struct platform_driver abituguru3_driver = {
  1084. .driver = {
  1085. .owner = THIS_MODULE,
  1086. .name = ABIT_UGURU3_NAME,
  1087. .pm = ABIT_UGURU3_PM
  1088. },
  1089. .probe = abituguru3_probe,
  1090. .remove = abituguru3_remove,
  1091. };
  1092. static int __init abituguru3_dmi_detect(void)
  1093. {
  1094. const char *board_vendor, *board_name;
  1095. int i, err = (force) ? 1 : -ENODEV;
  1096. const char *const *dmi_name;
  1097. size_t sublen;
  1098. board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1099. if (!board_vendor || strcmp(board_vendor, "http://www.abit.com.tw/"))
  1100. return err;
  1101. board_name = dmi_get_system_info(DMI_BOARD_NAME);
  1102. if (!board_name)
  1103. return err;
  1104. /*
  1105. * At the moment, we don't care about the part of the vendor
  1106. * DMI string contained in brackets. Truncate the string at
  1107. * the first occurrence of a bracket. Trim any trailing space
  1108. * from the substring.
  1109. */
  1110. sublen = strcspn(board_name, "(");
  1111. while (sublen > 0 && board_name[sublen - 1] == ' ')
  1112. sublen--;
  1113. for (i = 0; abituguru3_motherboards[i].id; i++) {
  1114. dmi_name = abituguru3_motherboards[i].dmi_name;
  1115. for ( ; *dmi_name; dmi_name++) {
  1116. if (strlen(*dmi_name) != sublen)
  1117. continue;
  1118. if (!strncasecmp(board_name, *dmi_name, sublen))
  1119. return 0;
  1120. }
  1121. }
  1122. /* No match found */
  1123. return 1;
  1124. }
  1125. /*
  1126. * FIXME: Manual detection should die eventually; we need to collect stable
  1127. * DMI model names first before we can rely entirely on CONFIG_DMI.
  1128. */
  1129. static int __init abituguru3_detect(void)
  1130. {
  1131. /*
  1132. * See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or
  1133. * 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05
  1134. * or 0x55 at CMD instead, why is unknown.
  1135. */
  1136. u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA);
  1137. u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD);
  1138. if (((data_val == 0x00) || (data_val == 0x08)) &&
  1139. ((cmd_val == 0xAC) || (cmd_val == 0x05) ||
  1140. (cmd_val == 0x55)))
  1141. return 0;
  1142. ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = "
  1143. "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val);
  1144. if (force) {
  1145. pr_info("Assuming Abit uGuru3 is present because of \"force\" parameter\n");
  1146. return 0;
  1147. }
  1148. /* No uGuru3 found */
  1149. return -ENODEV;
  1150. }
  1151. static struct platform_device *abituguru3_pdev;
  1152. static int __init abituguru3_init(void)
  1153. {
  1154. struct resource res = { .flags = IORESOURCE_IO };
  1155. int err;
  1156. /* Attempt DMI detection first */
  1157. err = abituguru3_dmi_detect();
  1158. if (err < 0)
  1159. return err;
  1160. /*
  1161. * Fall back to manual detection if there was no exact
  1162. * board name match, or force was specified.
  1163. */
  1164. if (err > 0) {
  1165. err = abituguru3_detect();
  1166. if (err)
  1167. return err;
  1168. pr_warn("this motherboard was not detected using DMI. "
  1169. "Please send the output of \"dmidecode\" to the abituguru3 maintainer (see MAINTAINERS)\n");
  1170. }
  1171. err = platform_driver_register(&abituguru3_driver);
  1172. if (err)
  1173. goto exit;
  1174. abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME,
  1175. ABIT_UGURU3_BASE);
  1176. if (!abituguru3_pdev) {
  1177. pr_err("Device allocation failed\n");
  1178. err = -ENOMEM;
  1179. goto exit_driver_unregister;
  1180. }
  1181. res.start = ABIT_UGURU3_BASE;
  1182. res.end = ABIT_UGURU3_BASE + ABIT_UGURU3_REGION_LENGTH - 1;
  1183. res.name = ABIT_UGURU3_NAME;
  1184. err = platform_device_add_resources(abituguru3_pdev, &res, 1);
  1185. if (err) {
  1186. pr_err("Device resource addition failed (%d)\n", err);
  1187. goto exit_device_put;
  1188. }
  1189. err = platform_device_add(abituguru3_pdev);
  1190. if (err) {
  1191. pr_err("Device addition failed (%d)\n", err);
  1192. goto exit_device_put;
  1193. }
  1194. return 0;
  1195. exit_device_put:
  1196. platform_device_put(abituguru3_pdev);
  1197. exit_driver_unregister:
  1198. platform_driver_unregister(&abituguru3_driver);
  1199. exit:
  1200. return err;
  1201. }
  1202. static void __exit abituguru3_exit(void)
  1203. {
  1204. platform_device_unregister(abituguru3_pdev);
  1205. platform_driver_unregister(&abituguru3_driver);
  1206. }
  1207. MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
  1208. MODULE_DESCRIPTION("Abit uGuru3 Sensor device");
  1209. MODULE_LICENSE("GPL");
  1210. module_init(abituguru3_init);
  1211. module_exit(abituguru3_exit);