abituguru3.c 41 KB

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