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