abituguru3.c 41 KB

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