aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/abituguru3.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/abituguru3.c')
-rw-r--r--drivers/hwmon/abituguru3.c211
1 files changed, 129 insertions, 82 deletions
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index 93ab1a5001c7..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,33 +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,
87 * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0
88 */
83#define ABIT_UGURU3_IN_NAMES_LENGTH \ 89#define ABIT_UGURU3_IN_NAMES_LENGTH \
84 (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11) 90 (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11)
85/* sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0, 91/*
86 temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0, 92 * sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0,
87 temp??_label\0 */ 93 * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0,
94 * temp??_label\0
95 */
88#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)
89/* sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0, 97/*
90 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 */
91#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)
92/* Worst case scenario 16 in sensors (longest names_length) and the rest 102/*
93 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 */
94#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 + \
95 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH) 107 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH)
96 108
97/* All the macros below are named identical to the openguru2 program 109/*
98 reverse engineered by Louis Kruger, hence the names might not be 100% 110 * All the macros below are named identical to the openguru2 program
99 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%
100 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 */
101/* Two i/o-ports are used by uGuru */ 115/* Two i/o-ports are used by uGuru */
102#define ABIT_UGURU3_BASE 0x00E0 116#define ABIT_UGURU3_BASE 0x00E0
103#define ABIT_UGURU3_CMD 0x00 117#define ABIT_UGURU3_CMD 0x00
104#define ABIT_UGURU3_DATA 0x04 118#define ABIT_UGURU3_DATA 0x04
105#define ABIT_UGURU3_REGION_LENGTH 5 119#define ABIT_UGURU3_REGION_LENGTH 5
106/* The wait_xxx functions return this on success and the last contents 120/*
107 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 */
108#define ABIT_UGURU3_SUCCESS -1 124#define ABIT_UGURU3_SUCCESS -1
109/* uGuru status flags */ 125/* uGuru status flags */
110#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01 126#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01
@@ -131,9 +147,11 @@ struct abituguru3_motherboard_info {
131 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1]; 147 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1];
132}; 148};
133 149
134/* For the Abit uGuru, we need to keep some data in memory. 150/*
135 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.
136 abituguru3 device is allocated. */ 152 * The structure is dynamically allocated, at the same time when a new
153 * abituguru3 device is allocated.
154 */
137struct abituguru3_data { 155struct abituguru3_data {
138 struct device *hwmon_dev; /* hwmon registered device */ 156 struct device *hwmon_dev; /* hwmon registered device */
139 struct mutex update_lock; /* protect access to data and uGuru */ 157 struct mutex update_lock; /* protect access to data and uGuru */
@@ -141,8 +159,10 @@ struct abituguru3_data {
141 char valid; /* !=0 if following fields are valid */ 159 char valid; /* !=0 if following fields are valid */
142 unsigned long last_updated; /* In jiffies */ 160 unsigned long last_updated; /* In jiffies */
143 161
144 /* For convenience the sysfs attr and their names are generated 162 /*
145 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 */
146 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
147 * 10]; 167 * 10];
148 168
@@ -152,9 +172,11 @@ struct abituguru3_data {
152 /* Pointer to the sensors info for the detected motherboard */ 172 /* Pointer to the sensors info for the detected motherboard */
153 const struct abituguru3_sensor_info *sensors; 173 const struct abituguru3_sensor_info *sensors;
154 174
155 /* The abituguru3 supports up to 48 sensors, and thus has registers 175 /*
156 sets for 48 sensors, for convienence reasons / simplicity of the 176 * The abituguru3 supports up to 48 sensors, and thus has registers
157 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 */
158 180
159 /* Alarms for all 48 sensors (1 bit per sensor) */ 181 /* Alarms for all 48 sensors (1 bit per sensor) */
160 u8 alarms[48/8]; 182 u8 alarms[48/8];
@@ -162,9 +184,11 @@ struct abituguru3_data {
162 /* Value of all 48 sensors */ 184 /* Value of all 48 sensors */
163 u8 value[48]; 185 u8 value[48];
164 186
165 /* Settings of all 48 sensors, note in and temp sensors (the first 32 187 /*
166 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
167 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 */
168 u8 settings[48][3]; 192 u8 settings[48][3];
169}; 193};
170 194
@@ -627,8 +651,10 @@ static int abituguru3_wait_while_busy(struct abituguru3_data *data)
627 timeout--; 651 timeout--;
628 if (timeout == 0) 652 if (timeout == 0)
629 return x; 653 return x;
630 /* sleep a bit before our last try, to give the uGuru3 one 654 /*
631 last chance to respond. */ 655 * sleep a bit before our last try, to give the uGuru3 one
656 * last chance to respond.
657 */
632 if (timeout == 1) 658 if (timeout == 1)
633 msleep(1); 659 msleep(1);
634 } 660 }
@@ -646,16 +672,20 @@ static int abituguru3_wait_for_read(struct abituguru3_data *data)
646 timeout--; 672 timeout--;
647 if (timeout == 0) 673 if (timeout == 0)
648 return x; 674 return x;
649 /* sleep a bit before our last try, to give the uGuru3 one 675 /*
650 last chance to respond. */ 676 * sleep a bit before our last try, to give the uGuru3 one
677 * last chance to respond.
678 */
651 if (timeout == 1) 679 if (timeout == 1)
652 msleep(1); 680 msleep(1);
653 } 681 }
654 return ABIT_UGURU3_SUCCESS; 682 return ABIT_UGURU3_SUCCESS;
655} 683}
656 684
657/* This synchronizes us with the uGuru3's protocol state machine, this 685/*
658 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 */
659static int abituguru3_synchronize(struct abituguru3_data *data) 689static int abituguru3_synchronize(struct abituguru3_data *data)
660{ 690{
661 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT; 691 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT;
@@ -711,8 +741,10 @@ static int abituguru3_synchronize(struct abituguru3_data *data)
711 return 0; 741 return 0;
712} 742}
713 743
714/* Read count bytes from sensor sensor_addr in bank bank_addr and store the 744/*
715 result in buf */ 745 * Read count bytes from sensor sensor_addr in bank bank_addr and store the
746 * result in buf
747 */
716static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset, 748static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
717 u8 count, u8 *buf) 749 u8 count, u8 *buf)
718{ 750{
@@ -771,8 +803,10 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
771 return i; 803 return i;
772} 804}
773 805
774/* Sensor settings are stored 1 byte per offset with the bytes 806/*
775 placed add consecutive offsets. */ 807 * Sensor settings are stored 1 byte per offset with the bytes
808 * placed add consecutive offsets.
809 */
776static int abituguru3_read_increment_offset(struct abituguru3_data *data, 810static int abituguru3_read_increment_offset(struct abituguru3_data *data,
777 u8 bank, u8 offset, u8 count, 811 u8 bank, u8 offset, u8 count,
778 u8 *buf, int offset_count) 812 u8 *buf, int offset_count)
@@ -792,9 +826,11 @@ static int abituguru3_read_increment_offset(struct abituguru3_data *data,
792 return i * count; 826 return i * count;
793} 827}
794 828
795/* Following are the sysfs callback functions. These functions expect: 829/*
796 sensor_device_attribute_2->index: index into the data->sensors array 830 * Following are the sysfs callback functions. These functions expect:
797 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 */
798static struct abituguru3_data *abituguru3_update_device(struct device *dev); 834static struct abituguru3_data *abituguru3_update_device(struct device *dev);
799 835
800static ssize_t show_value(struct device *dev, 836static ssize_t show_value(struct device *dev,
@@ -820,8 +856,10 @@ static ssize_t show_value(struct device *dev,
820 value = (value * sensor->multiplier) / sensor->divisor + 856 value = (value * sensor->multiplier) / sensor->divisor +
821 sensor->offset; 857 sensor->offset;
822 858
823 /* alternatively we could update the sensors settings struct for this, 859 /*
824 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 */
825 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR) 863 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR)
826 value *= 1000; 864 value *= 1000;
827 865
@@ -840,10 +878,12 @@ static ssize_t show_alarm(struct device *dev,
840 878
841 port = data->sensors[attr->index].port; 879 port = data->sensors[attr->index].port;
842 880
843 /* See if the alarm bit for this sensor is set and if a bitmask is 881 /*
844 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
845 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
846 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 */
847 if ((data->alarms[port / 8] & (0x01 << (port % 8))) && 887 if ((data->alarms[port / 8] & (0x01 << (port % 8))) &&
848 (!attr->nr || (data->settings[port][0] & attr->nr))) 888 (!attr->nr || (data->settings[port][0] & attr->nr)))
849 return sprintf(buf, "1\n"); 889 return sprintf(buf, "1\n");
@@ -1105,8 +1145,10 @@ LEAVE_UPDATE:
1105static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state) 1145static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state)
1106{ 1146{
1107 struct abituguru3_data *data = platform_get_drvdata(pdev); 1147 struct abituguru3_data *data = platform_get_drvdata(pdev);
1108 /* make sure all communications with the uguru3 are done and no new 1148 /*
1109 ones are started */ 1149 * make sure all communications with the uguru3 are done and no new
1150 * ones are started
1151 */
1110 mutex_lock(&data->update_lock); 1152 mutex_lock(&data->update_lock);
1111 return 0; 1153 return 0;
1112} 1154}
@@ -1148,7 +1190,8 @@ static int __init abituguru3_dmi_detect(void)
1148 if (!board_name) 1190 if (!board_name)
1149 return err; 1191 return err;
1150 1192
1151 /* 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
1152 * DMI string contained in brackets. Truncate the string at 1195 * DMI string contained in brackets. Truncate the string at
1153 * the first occurrence of a bracket. Trim any trailing space 1196 * the first occurrence of a bracket. Trim any trailing space
1154 * from the substring. 1197 * from the substring.
@@ -1171,15 +1214,18 @@ static int __init abituguru3_dmi_detect(void)
1171 return 1; 1214 return 1;
1172} 1215}
1173 1216
1174/* FIXME: Manual detection should die eventually; we need to collect stable 1217/*
1218 * FIXME: Manual detection should die eventually; we need to collect stable
1175 * 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.
1176 */ 1220 */
1177 1221
1178static int __init abituguru3_detect(void) 1222static int __init abituguru3_detect(void)
1179{ 1223{
1180 /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or 1224 /*
1181 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
1182 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 */
1183 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); 1229 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA);
1184 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); 1230 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD);
1185 if (((data_val == 0x00) || (data_val == 0x08)) && 1231 if (((data_val == 0x00) || (data_val == 0x08)) &&
@@ -1211,7 +1257,8 @@ static int __init abituguru3_init(void)
1211 if (err < 0) 1257 if (err < 0)
1212 return err; 1258 return err;
1213 1259
1214 /* Fall back to manual detection if there was no exact 1260 /*
1261 * Fall back to manual detection if there was no exact
1215 * board name match, or force was specified. 1262 * board name match, or force was specified.
1216 */ 1263 */
1217 if (err > 0) { 1264 if (err > 0) {