summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/abituguru3.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/abituguru3.c')
-rw-r--r--drivers/hwmon/abituguru3.c267
1 files changed, 164 insertions, 103 deletions
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index 34a14a77e008..a5bc4287daa6 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -1,28 +1,28 @@
1/* 1/*
2 abituguru3.c 2 * abituguru3.c
3 3 *
4 Copyright (c) 2006-2008 Hans de Goede <hdegoede@redhat.com> 4 * Copyright (c) 2006-2008 Hans de Goede <hdegoede@redhat.com>
5 Copyright (c) 2008 Alistair John Strachan <alistair@devzero.co.uk> 5 * Copyright (c) 2008 Alistair John Strachan <alistair@devzero.co.uk>
6 6 *
7 This program is free software; you can redistribute it and/or modify 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 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 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21/* 21/*
22 This driver supports the sensor part of revision 3 of the custom Abit uGuru 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 23 * chip found on newer Abit uGuru motherboards. Note: because of lack of specs
24 only reading the sensors and their settings is supported. 24 * only reading the sensors and their settings is supported.
25*/ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 28
@@ -62,13 +62,17 @@
62#define ABIT_UGURU3_TEMP_SENSOR 1 62#define ABIT_UGURU3_TEMP_SENSOR 1
63#define ABIT_UGURU3_FAN_SENSOR 2 63#define ABIT_UGURU3_FAN_SENSOR 2
64 64
65/* Timeouts / Retries, if these turn out to need a lot of fiddling we could 65/*
66 convert them to params. Determined by trial and error. I assume this is 66 * Timeouts / Retries, if these turn out to need a lot of fiddling we could
67 cpu-speed independent, since the ISA-bus and not the CPU should be the 67 * convert them to params. Determined by trial and error. I assume this is
68 bottleneck. */ 68 * cpu-speed independent, since the ISA-bus and not the CPU should be the
69 * bottleneck.
70 */
69#define ABIT_UGURU3_WAIT_TIMEOUT 250 71#define ABIT_UGURU3_WAIT_TIMEOUT 250
70/* Normally the 0xAC at the end of synchronize() is reported after the 72/*
71 first read, but sometimes not and we need to poll */ 73 * Normally the 0xAC at the end of synchronize() is reported after the
74 * first read, but sometimes not and we need to poll
75 */
72#define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5 76#define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5
73/* utility macros */ 77/* utility macros */
74#define ABIT_UGURU3_NAME "abituguru3" 78#define ABIT_UGURU3_NAME "abituguru3"
@@ -78,32 +82,45 @@
78 82
79/* Macros to help calculate the sysfs_names array length */ 83/* Macros to help calculate the sysfs_names array length */
80#define ABIT_UGURU3_MAX_NO_SENSORS 26 84#define ABIT_UGURU3_MAX_NO_SENSORS 26
81/* sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, 85/*
82 in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0 */ 86 * sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
83#define ABIT_UGURU3_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11) 87 * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0
84/* sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0, 88 */
85 temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0, 89#define ABIT_UGURU3_IN_NAMES_LENGTH \
86 temp??_label\0 */ 90 (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11)
91/*
92 * sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0,
93 * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0,
94 * temp??_label\0
95 */
87#define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13) 96#define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13)
88/* sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0, 97/*
89 fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0 */ 98 * sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0,
99 * fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0
100 */
90#define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12) 101#define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12)
91/* Worst case scenario 16 in sensors (longest names_length) and the rest 102/*
92 temp sensors (second longest names_length). */ 103 * Worst case scenario 16 in sensors (longest names_length) and the rest
104 * temp sensors (second longest names_length).
105 */
93#define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \ 106#define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \
94 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH) 107 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH)
95 108
96/* All the macros below are named identical to the openguru2 program 109/*
97 reverse engineered by Louis Kruger, hence the names might not be 100% 110 * All the macros below are named identical to the openguru2 program
98 logical. I could come up with better names, but I prefer keeping the names 111 * reverse engineered by Louis Kruger, hence the names might not be 100%
99 identical so that this driver can be compared with his work more easily. */ 112 * logical. I could come up with better names, but I prefer keeping the names
113 * identical so that this driver can be compared with his work more easily.
114 */
100/* Two i/o-ports are used by uGuru */ 115/* Two i/o-ports are used by uGuru */
101#define ABIT_UGURU3_BASE 0x00E0 116#define ABIT_UGURU3_BASE 0x00E0
102#define ABIT_UGURU3_CMD 0x00 117#define ABIT_UGURU3_CMD 0x00
103#define ABIT_UGURU3_DATA 0x04 118#define ABIT_UGURU3_DATA 0x04
104#define ABIT_UGURU3_REGION_LENGTH 5 119#define ABIT_UGURU3_REGION_LENGTH 5
105/* The wait_xxx functions return this on success and the last contents 120/*
106 of the DATA register (0-255) on failure. */ 121 * The wait_xxx functions return this on success and the last contents
122 * of the DATA register (0-255) on failure.
123 */
107#define ABIT_UGURU3_SUCCESS -1 124#define ABIT_UGURU3_SUCCESS -1
108/* uGuru status flags */ 125/* uGuru status flags */
109#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01 126#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01
@@ -112,7 +129,7 @@
112 129
113/* Structures */ 130/* Structures */
114struct abituguru3_sensor_info { 131struct abituguru3_sensor_info {
115 const char* name; 132 const char *name;
116 int port; 133 int port;
117 int type; 134 int type;
118 int multiplier; 135 int multiplier;
@@ -130,9 +147,11 @@ struct abituguru3_motherboard_info {
130 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1]; 147 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1];
131}; 148};
132 149
133/* For the Abit uGuru, we need to keep some data in memory. 150/*
134 The structure is dynamically allocated, at the same time when a new 151 * For the Abit uGuru, we need to keep some data in memory.
135 abituguru3 device is allocated. */ 152 * The structure is dynamically allocated, at the same time when a new
153 * abituguru3 device is allocated.
154 */
136struct abituguru3_data { 155struct abituguru3_data {
137 struct device *hwmon_dev; /* hwmon registered device */ 156 struct device *hwmon_dev; /* hwmon registered device */
138 struct mutex update_lock; /* protect access to data and uGuru */ 157 struct mutex update_lock; /* protect access to data and uGuru */
@@ -140,8 +159,10 @@ struct abituguru3_data {
140 char valid; /* !=0 if following fields are valid */ 159 char valid; /* !=0 if following fields are valid */
141 unsigned long last_updated; /* In jiffies */ 160 unsigned long last_updated; /* In jiffies */
142 161
143 /* For convenience the sysfs attr and their names are generated 162 /*
144 automatically. We have max 10 entries per sensor (for in sensors) */ 163 * For convenience the sysfs attr and their names are generated
164 * automatically. We have max 10 entries per sensor (for in sensors)
165 */
145 struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS 166 struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS
146 * 10]; 167 * 10];
147 168
@@ -151,9 +172,11 @@ struct abituguru3_data {
151 /* Pointer to the sensors info for the detected motherboard */ 172 /* Pointer to the sensors info for the detected motherboard */
152 const struct abituguru3_sensor_info *sensors; 173 const struct abituguru3_sensor_info *sensors;
153 174
154 /* The abituguru3 supports up to 48 sensors, and thus has registers 175 /*
155 sets for 48 sensors, for convienence reasons / simplicity of the 176 * The abituguru3 supports up to 48 sensors, and thus has registers
156 code we always read and store all registers for all 48 sensors */ 177 * sets for 48 sensors, for convienence reasons / simplicity of the
178 * code we always read and store all registers for all 48 sensors
179 */
157 180
158 /* Alarms for all 48 sensors (1 bit per sensor) */ 181 /* Alarms for all 48 sensors (1 bit per sensor) */
159 u8 alarms[48/8]; 182 u8 alarms[48/8];
@@ -161,9 +184,11 @@ struct abituguru3_data {
161 /* Value of all 48 sensors */ 184 /* Value of all 48 sensors */
162 u8 value[48]; 185 u8 value[48];
163 186
164 /* Settings of all 48 sensors, note in and temp sensors (the first 32 187 /*
165 sensors) have 3 bytes of settings, while fans only have 2 bytes, 188 * Settings of all 48 sensors, note in and temp sensors (the first 32
166 for convenience we use 3 bytes for all sensors */ 189 * sensors) have 3 bytes of settings, while fans only have 2 bytes,
190 * for convenience we use 3 bytes for all sensors
191 */
167 u8 settings[48][3]; 192 u8 settings[48][3];
168}; 193};
169 194
@@ -626,8 +651,10 @@ static int abituguru3_wait_while_busy(struct abituguru3_data *data)
626 timeout--; 651 timeout--;
627 if (timeout == 0) 652 if (timeout == 0)
628 return x; 653 return x;
629 /* sleep a bit before our last try, to give the uGuru3 one 654 /*
630 last chance to respond. */ 655 * sleep a bit before our last try, to give the uGuru3 one
656 * last chance to respond.
657 */
631 if (timeout == 1) 658 if (timeout == 1)
632 msleep(1); 659 msleep(1);
633 } 660 }
@@ -645,48 +672,57 @@ static int abituguru3_wait_for_read(struct abituguru3_data *data)
645 timeout--; 672 timeout--;
646 if (timeout == 0) 673 if (timeout == 0)
647 return x; 674 return x;
648 /* sleep a bit before our last try, to give the uGuru3 one 675 /*
649 last chance to respond. */ 676 * sleep a bit before our last try, to give the uGuru3 one
677 * last chance to respond.
678 */
650 if (timeout == 1) 679 if (timeout == 1)
651 msleep(1); 680 msleep(1);
652 } 681 }
653 return ABIT_UGURU3_SUCCESS; 682 return ABIT_UGURU3_SUCCESS;
654} 683}
655 684
656/* This synchronizes us with the uGuru3's protocol state machine, this 685/*
657 must be done before each command. */ 686 * This synchronizes us with the uGuru3's protocol state machine, this
687 * must be done before each command.
688 */
658static int abituguru3_synchronize(struct abituguru3_data *data) 689static int abituguru3_synchronize(struct abituguru3_data *data)
659{ 690{
660 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT; 691 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT;
661 692
662 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 693 x = abituguru3_wait_while_busy(data);
694 if (x != ABIT_UGURU3_SUCCESS) {
663 ABIT_UGURU3_DEBUG("synchronize timeout during initial busy " 695 ABIT_UGURU3_DEBUG("synchronize timeout during initial busy "
664 "wait, status: 0x%02x\n", x); 696 "wait, status: 0x%02x\n", x);
665 return -EIO; 697 return -EIO;
666 } 698 }
667 699
668 outb(0x20, data->addr + ABIT_UGURU3_DATA); 700 outb(0x20, data->addr + ABIT_UGURU3_DATA);
669 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 701 x = abituguru3_wait_while_busy(data);
702 if (x != ABIT_UGURU3_SUCCESS) {
670 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, " 703 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, "
671 "status: 0x%02x\n", x); 704 "status: 0x%02x\n", x);
672 return -EIO; 705 return -EIO;
673 } 706 }
674 707
675 outb(0x10, data->addr + ABIT_UGURU3_CMD); 708 outb(0x10, data->addr + ABIT_UGURU3_CMD);
676 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 709 x = abituguru3_wait_while_busy(data);
710 if (x != ABIT_UGURU3_SUCCESS) {
677 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, " 711 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, "
678 "status: 0x%02x\n", x); 712 "status: 0x%02x\n", x);
679 return -EIO; 713 return -EIO;
680 } 714 }
681 715
682 outb(0x00, data->addr + ABIT_UGURU3_CMD); 716 outb(0x00, data->addr + ABIT_UGURU3_CMD);
683 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 717 x = abituguru3_wait_while_busy(data);
718 if (x != ABIT_UGURU3_SUCCESS) {
684 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, " 719 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, "
685 "status: 0x%02x\n", x); 720 "status: 0x%02x\n", x);
686 return -EIO; 721 return -EIO;
687 } 722 }
688 723
689 if ((x = abituguru3_wait_for_read(data)) != ABIT_UGURU3_SUCCESS) { 724 x = abituguru3_wait_for_read(data);
725 if (x != ABIT_UGURU3_SUCCESS) {
690 ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, " 726 ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, "
691 "status: 0x%02x\n", x); 727 "status: 0x%02x\n", x);
692 return -EIO; 728 return -EIO;
@@ -705,18 +741,22 @@ static int abituguru3_synchronize(struct abituguru3_data *data)
705 return 0; 741 return 0;
706} 742}
707 743
708/* Read count bytes from sensor sensor_addr in bank bank_addr and store the 744/*
709 result in buf */ 745 * Read count bytes from sensor sensor_addr in bank bank_addr and store the
746 * result in buf
747 */
710static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset, 748static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
711 u8 count, u8 *buf) 749 u8 count, u8 *buf)
712{ 750{
713 int i, x; 751 int i, x;
714 752
715 if ((x = abituguru3_synchronize(data))) 753 x = abituguru3_synchronize(data);
754 if (x)
716 return x; 755 return x;
717 756
718 outb(0x1A, data->addr + ABIT_UGURU3_DATA); 757 outb(0x1A, data->addr + ABIT_UGURU3_DATA);
719 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 758 x = abituguru3_wait_while_busy(data);
759 if (x != ABIT_UGURU3_SUCCESS) {
720 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 760 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
721 "sending 0x1A, status: 0x%02x\n", (unsigned int)bank, 761 "sending 0x1A, status: 0x%02x\n", (unsigned int)bank,
722 (unsigned int)offset, x); 762 (unsigned int)offset, x);
@@ -724,7 +764,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
724 } 764 }
725 765
726 outb(bank, data->addr + ABIT_UGURU3_CMD); 766 outb(bank, data->addr + ABIT_UGURU3_CMD);
727 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 767 x = abituguru3_wait_while_busy(data);
768 if (x != ABIT_UGURU3_SUCCESS) {
728 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 769 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
729 "sending the bank, status: 0x%02x\n", 770 "sending the bank, status: 0x%02x\n",
730 (unsigned int)bank, (unsigned int)offset, x); 771 (unsigned int)bank, (unsigned int)offset, x);
@@ -732,7 +773,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
732 } 773 }
733 774
734 outb(offset, data->addr + ABIT_UGURU3_CMD); 775 outb(offset, data->addr + ABIT_UGURU3_CMD);
735 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 776 x = abituguru3_wait_while_busy(data);
777 if (x != ABIT_UGURU3_SUCCESS) {
736 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 778 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
737 "sending the offset, status: 0x%02x\n", 779 "sending the offset, status: 0x%02x\n",
738 (unsigned int)bank, (unsigned int)offset, x); 780 (unsigned int)bank, (unsigned int)offset, x);
@@ -740,7 +782,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
740 } 782 }
741 783
742 outb(count, data->addr + ABIT_UGURU3_CMD); 784 outb(count, data->addr + ABIT_UGURU3_CMD);
743 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 785 x = abituguru3_wait_while_busy(data);
786 if (x != ABIT_UGURU3_SUCCESS) {
744 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 787 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
745 "sending the count, status: 0x%02x\n", 788 "sending the count, status: 0x%02x\n",
746 (unsigned int)bank, (unsigned int)offset, x); 789 (unsigned int)bank, (unsigned int)offset, x);
@@ -748,8 +791,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
748 } 791 }
749 792
750 for (i = 0; i < count; i++) { 793 for (i = 0; i < count; i++) {
751 if ((x = abituguru3_wait_for_read(data)) != 794 x = abituguru3_wait_for_read(data);
752 ABIT_UGURU3_SUCCESS) { 795 if (x != ABIT_UGURU3_SUCCESS) {
753 ABIT_UGURU3_DEBUG("timeout reading byte %d from " 796 ABIT_UGURU3_DEBUG("timeout reading byte %d from "
754 "0x%02x:0x%02x, status: 0x%02x\n", i, 797 "0x%02x:0x%02x, status: 0x%02x\n", i,
755 (unsigned int)bank, (unsigned int)offset, x); 798 (unsigned int)bank, (unsigned int)offset, x);
@@ -760,28 +803,34 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
760 return i; 803 return i;
761} 804}
762 805
763/* Sensor settings are stored 1 byte per offset with the bytes 806/*
764 placed add consecutive offsets. */ 807 * Sensor settings are stored 1 byte per offset with the bytes
808 * placed add consecutive offsets.
809 */
765static int abituguru3_read_increment_offset(struct abituguru3_data *data, 810static int abituguru3_read_increment_offset(struct abituguru3_data *data,
766 u8 bank, u8 offset, u8 count, 811 u8 bank, u8 offset, u8 count,
767 u8 *buf, int offset_count) 812 u8 *buf, int offset_count)
768{ 813{
769 int i, x; 814 int i, x;
770 815
771 for (i = 0; i < offset_count; i++) 816 for (i = 0; i < offset_count; i++) {
772 if ((x = abituguru3_read(data, bank, offset + i, count, 817 x = abituguru3_read(data, bank, offset + i, count,
773 buf + i * count)) != count) { 818 buf + i * count);
819 if (x != count) {
774 if (x < 0) 820 if (x < 0)
775 return x; 821 return x;
776 return i * count + x; 822 return i * count + x;
777 } 823 }
824 }
778 825
779 return i * count; 826 return i * count;
780} 827}
781 828
782/* Following are the sysfs callback functions. These functions expect: 829/*
783 sensor_device_attribute_2->index: index into the data->sensors array 830 * Following are the sysfs callback functions. These functions expect:
784 sensor_device_attribute_2->nr: register offset, bitmask or NA. */ 831 * sensor_device_attribute_2->index: index into the data->sensors array
832 * sensor_device_attribute_2->nr: register offset, bitmask or NA.
833 */
785static struct abituguru3_data *abituguru3_update_device(struct device *dev); 834static struct abituguru3_data *abituguru3_update_device(struct device *dev);
786 835
787static ssize_t show_value(struct device *dev, 836static ssize_t show_value(struct device *dev,
@@ -807,8 +856,10 @@ static ssize_t show_value(struct device *dev,
807 value = (value * sensor->multiplier) / sensor->divisor + 856 value = (value * sensor->multiplier) / sensor->divisor +
808 sensor->offset; 857 sensor->offset;
809 858
810 /* alternatively we could update the sensors settings struct for this, 859 /*
811 but then its contents would differ from the windows sw ini files */ 860 * alternatively we could update the sensors settings struct for this,
861 * but then its contents would differ from the windows sw ini files
862 */
812 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR) 863 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR)
813 value *= 1000; 864 value *= 1000;
814 865
@@ -827,10 +878,12 @@ static ssize_t show_alarm(struct device *dev,
827 878
828 port = data->sensors[attr->index].port; 879 port = data->sensors[attr->index].port;
829 880
830 /* See if the alarm bit for this sensor is set and if a bitmask is 881 /*
831 given in attr->nr also check if the alarm matches the type of alarm 882 * See if the alarm bit for this sensor is set and if a bitmask is
832 we're looking for (for volt it can be either low or high). The type 883 * given in attr->nr also check if the alarm matches the type of alarm
833 is stored in a few readonly bits in the settings of the sensor. */ 884 * we're looking for (for volt it can be either low or high). The type
885 * is stored in a few readonly bits in the settings of the sensor.
886 */
834 if ((data->alarms[port / 8] & (0x01 << (port % 8))) && 887 if ((data->alarms[port / 8] & (0x01 << (port % 8))) &&
835 (!attr->nr || (data->settings[port][0] & attr->nr))) 888 (!attr->nr || (data->settings[port][0] & attr->nr)))
836 return sprintf(buf, "1\n"); 889 return sprintf(buf, "1\n");
@@ -923,7 +976,8 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
923 u8 buf[2]; 976 u8 buf[2];
924 u16 id; 977 u16 id;
925 978
926 if (!(data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL))) 979 data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL);
980 if (!data)
927 return -ENOMEM; 981 return -ENOMEM;
928 982
929 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; 983 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
@@ -931,10 +985,10 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
931 platform_set_drvdata(pdev, data); 985 platform_set_drvdata(pdev, data);
932 986
933 /* Read the motherboard ID */ 987 /* Read the motherboard ID */
934 if ((i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, 988 i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, ABIT_UGURU3_BOARD_ID,
935 ABIT_UGURU3_BOARD_ID, 2, buf)) != 2) { 989 2, buf);
990 if (i != 2)
936 goto abituguru3_probe_error; 991 goto abituguru3_probe_error;
937 }
938 992
939 /* Completely read the uGuru to see if one really is there */ 993 /* Completely read the uGuru to see if one really is there */
940 if (!abituguru3_update_device(&pdev->dev)) 994 if (!abituguru3_update_device(&pdev->dev))
@@ -1091,8 +1145,10 @@ LEAVE_UPDATE:
1091static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state) 1145static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state)
1092{ 1146{
1093 struct abituguru3_data *data = platform_get_drvdata(pdev); 1147 struct abituguru3_data *data = platform_get_drvdata(pdev);
1094 /* make sure all communications with the uguru3 are done and no new 1148 /*
1095 ones are started */ 1149 * make sure all communications with the uguru3 are done and no new
1150 * ones are started
1151 */
1096 mutex_lock(&data->update_lock); 1152 mutex_lock(&data->update_lock);
1097 return 0; 1153 return 0;
1098} 1154}
@@ -1134,7 +1190,8 @@ static int __init abituguru3_dmi_detect(void)
1134 if (!board_name) 1190 if (!board_name)
1135 return err; 1191 return err;
1136 1192
1137 /* At the moment, we don't care about the part of the vendor 1193 /*
1194 * At the moment, we don't care about the part of the vendor
1138 * DMI string contained in brackets. Truncate the string at 1195 * DMI string contained in brackets. Truncate the string at
1139 * the first occurrence of a bracket. Trim any trailing space 1196 * the first occurrence of a bracket. Trim any trailing space
1140 * from the substring. 1197 * from the substring.
@@ -1157,15 +1214,18 @@ static int __init abituguru3_dmi_detect(void)
1157 return 1; 1214 return 1;
1158} 1215}
1159 1216
1160/* FIXME: Manual detection should die eventually; we need to collect stable 1217/*
1218 * FIXME: Manual detection should die eventually; we need to collect stable
1161 * DMI model names first before we can rely entirely on CONFIG_DMI. 1219 * DMI model names first before we can rely entirely on CONFIG_DMI.
1162 */ 1220 */
1163 1221
1164static int __init abituguru3_detect(void) 1222static int __init abituguru3_detect(void)
1165{ 1223{
1166 /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or 1224 /*
1167 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 1225 * See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or
1168 or 0x55 at CMD instead, why is unknown. */ 1226 * 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05
1227 * or 0x55 at CMD instead, why is unknown.
1228 */
1169 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); 1229 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA);
1170 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); 1230 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD);
1171 if (((data_val == 0x00) || (data_val == 0x08)) && 1231 if (((data_val == 0x00) || (data_val == 0x08)) &&
@@ -1197,7 +1257,8 @@ static int __init abituguru3_init(void)
1197 if (err < 0) 1257 if (err < 0)
1198 return err; 1258 return err;
1199 1259
1200 /* Fall back to manual detection if there was no exact 1260 /*
1261 * Fall back to manual detection if there was no exact
1201 * board name match, or force was specified. 1262 * board name match, or force was specified.
1202 */ 1263 */
1203 if (err > 0) { 1264 if (err > 0) {