abituguru3.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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);