From 2072a3c9d601bf86468e3cc94863b60d71641d0e Mon Sep 17 00:00:00 2001 From: "Mark D. Studebaker" Date: Thu, 11 May 2000 01:35:22 +0000 Subject: [PATCH] (mds) Add adm1025 driver from Chen-Yuan Wu. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@801 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + CONTRIBUTORS | 2 + README | 2 +- doc/chips/SUMMARY | 3 + doc/chips/adm1025 | 12 + kernel/chips/Module.mk | 3 +- kernel/chips/adm1025.c | 724 +++++++++++++++++++++++++++++++++++++++ kernel/include/sensors.h | 22 ++ 8 files changed, 767 insertions(+), 2 deletions(-) create mode 100644 doc/chips/adm1025 create mode 100644 kernel/chips/adm1025.c diff --git a/CHANGES b/CHANGES index fdf73e89..9dc8904b 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ ask CVS about it: cvs diff -r V2-0-0 -r V2-0-1 -u 2.5.1 (2000????) + Module adm1025: new Module ddcmon: Fixed bus scan which could hang SMBus Module maxilife: Add support for Maxilife '99 (NBA) Module via686a: Enable sensors if not enabled by BIOS diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 23e5dfd7..88c9725b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -52,3 +52,5 @@ problems. * Gerd Knorr (?) Designed the i2c structs, which made it possible to use the smbus-is- just-an-i2c-extension approach. +* Chen-Yuan Wu + Author of the adm1025 driver. diff --git a/README b/README index 5c65873f..38313d1a 100644 --- a/README +++ b/README @@ -48,7 +48,7 @@ At least the following I2C/SMBus adapters are supported: At least the following hardware sensor chips are supported: - Analog Devices ADM1021, ADM1022, and ADM9240 + Analog Devices ADM1021, ADM1022, ADM1025, and ADM9240 Asus AS99127F Dallas Semiconductor DS1780, DS75, and DS1775 Hewlett Packard Maxilife (several revisions including '99 NBA) diff --git a/doc/chips/SUMMARY b/doc/chips/SUMMARY index 338be36b..dec7bb23 100644 --- a/doc/chips/SUMMARY +++ b/doc/chips/SUMMARY @@ -46,6 +46,9 @@ adm1021 xeon 1 - - - yes no (xeon - no detection - requires force parameter) +adm1025 + adm1025 2 6 - - yes no + adm9240 adm9240 1 6 2 1 dac yes no ds1780 1 6 2 1 dac yes no diff --git a/doc/chips/adm1025 b/doc/chips/adm1025 new file mode 100644 index 00000000..9c81d218 --- /dev/null +++ b/doc/chips/adm1025 @@ -0,0 +1,12 @@ +Kernel driver `adm1021.o' +========================= + +Status: Complete; Alpha. + +Supported chips: + * Analog Devices ADM1025 + Prefix `adm1025' + Addresses scanned: I2C 0x2c - 0x2e (inclusive) + Datasheet: Publicly available at the Analog Devices website + +Author: Chen-Yuan Wu diff --git a/kernel/chips/Module.mk b/kernel/chips/Module.mk index 832abdfb..80c2be3a 100644 --- a/kernel/chips/Module.mk +++ b/kernel/chips/Module.mk @@ -27,7 +27,8 @@ KERNELCHIPSTARGETS := $(MODULE_DIR)/bt869.o $(MODULE_DIR)/gl520sm.o \ $(MODULE_DIR)/matorb.o $(MODULE_DIR)/maxilife.o \ $(MODULE_DIR)/thmc50.o \ $(MODULE_DIR)/via686a.o \ - $(MODULE_DIR)/ddcmon.o + $(MODULE_DIR)/ddcmon.o \ + $(MODULE_DIR)/adm1025.o ifneq ($(shell if grep -q '^CONFIG_SENSORS_ADM1021=y' $(LINUX)/.config; then echo 1; fi),1) KERNELCHIPSTARGETS += $(MODULE_DIR)/adm1021.o endif diff --git a/kernel/chips/adm1025.c b/kernel/chips/adm1025.c new file mode 100644 index 00000000..9a144910 --- /dev/null +++ b/kernel/chips/adm1025.c @@ -0,0 +1,724 @@ +/* + adm1025.c - Part of lm_sensors, Linux kernel modules for hardware + monitoring + Add by Gordon Wu according to the adm9240.c written by + + Frodo Looijaard + and Philip Edelbrock + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* Supports ADM10250. See doc/chips/adm9240 for details */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "version.h" +#include "i2c-isa.h" +#include "sensors.h" +#include + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)) +#define init_MUTEX(s) do { *(s) = MUTEX; } while(0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13) +#define THIS_MODULE NULL +#endif + +/* Addresses to scan */ +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x2c, 0x2f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; + +/* Insmod parameters */ +SENSORS_INSMOD_1(adm1025); + +/* Many ADM1025 constants specified below */ + +#define ADM1025_REG_IN_MAX(nr) (0x2b + (nr) * 2) +#define ADM1025_REG_IN_MIN(nr) (0x2c + (nr) * 2) +#define ADM1025_REG_IN(nr) (0x20 + (nr)) + +/* The ADM1025 registers */ +#define ADM1025_REG_TEST 0x15 +/* These are all read-only */ +#define ADM1025_REG_2_5V 0x20 +#define ADM1025_REG_VCCP1 0x21 +#define ADM1025_REG_3_3V 0x22 +#define ADM1025_REG_5V 0x23 +#define ADM1025_REG_12V 0x24 +#define ADM1025_REG_VCC 0x25 +#define ADM1025_REG_RTEMP 0x26 +#define ADM1025_REG_TEMP 0x27 +#define ADM1025_REG_COMPANY_ID 0x3E /* 0x41 for ADM1025 */ +#define ADM1025_REG_DIE_REV 0x3F +/* These are read/write */ +#define ADM1025_REG_2_5V_HIGH 0x2B +#define ADM1025_REG_2_5V_LOW 0x2C +#define ADM1025_REG_VCCP1_HIGH 0x2D +#define ADM1025_REG_VCCP1_LOW 0x2E +#define ADM1025_REG_3_3V_HIGH 0x2F +#define ADM1025_REG_3_3V_LOW 0x30 +#define ADM1025_REG_5V_HIGH 0x31 +#define ADM1025_REG_5V_LOW 0x32 +#define ADM1025_REG_12V_HIGH 0x33 +#define ADM1025_REG_12V_LOW 0x34 +#define ADM1025_REG_VCC_HIGH 0x35 +#define ADM1025_REG_VCC_LOW 0x36 +#define ADM1025_REG_RTEMP_HIGH 0x37 +#define ADM1025_REG_RTEMP_LOW 0x38 +#define ADM1025_REG_TEMP_HIGH 0x39 +#define ADM1025_REG_TEMP_LOW 0x3A + +#define ADM1025_REG_CONFIG 0x40 +#define ADM1025_REG_INT1_STAT 0x41 +#define ADM1025_REG_INT2_STAT 0x42 + +#define ADM1025_REG_VID 0x47 +#define ADM1025_REG_VID4 0x49 + +/* Conversions. Rounding and limit checking is only done on the TO_REG + variants. Note that you should be a bit careful with which arguments + these macros are called: arguments may be evaluated more than once. + Fixing this is just not worth it. */ +#define IN_TO_REG(val,nr) (SENSORS_LIMIT(((val) & 0xff),0,255)) +#define IN_FROM_REG(val,nr) (val) + +/* #define TEMP_FROM_REG(temp) \ + ((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \ + ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \ +*/ +#define TEMP_FROM_REG(temp) (((temp)>0x7f?(-temp):(temp))*10) + +#define TEMP_LIMIT_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) + +#define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT(((val)<0?(((val)-5)/10):\ + ((val)+5)/10), \ + 0,255) + +#define ALARMS_FROM_REG(val) (val) + + +#define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\ + 205-(val)*5) + +/* Initial limits */ +#define ADM1025_INIT_IN_0 190 +#define ADM1025_INIT_IN_1 190 +#define ADM1025_INIT_IN_2 190 +#define ADM1025_INIT_IN_3 190 +#define ADM1025_INIT_IN_4 190 +#define ADM1025_INIT_IN_5 190 + +#define ADM1025_INIT_IN_PERCENTAGE 10 + +#define ADM1025_INIT_IN_MIN_0 \ + (ADM1025_INIT_IN_0 - ADM1025_INIT_IN_0 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_0 \ + (ADM1025_INIT_IN_0 + ADM1025_INIT_IN_0 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MIN_1 \ + (ADM1025_INIT_IN_1 - ADM1025_INIT_IN_1 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_1 \ + (ADM1025_INIT_IN_1 + ADM1025_INIT_IN_1 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MIN_2 \ + (ADM1025_INIT_IN_2 - ADM1025_INIT_IN_2 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_2 \ + (ADM1025_INIT_IN_2 + ADM1025_INIT_IN_2 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MIN_3 \ + (ADM1025_INIT_IN_3 - ADM1025_INIT_IN_3 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_3 \ + (ADM1025_INIT_IN_3 + ADM1025_INIT_IN_3 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MIN_4 \ + (ADM1025_INIT_IN_4 - ADM1025_INIT_IN_4 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_4 \ + (ADM1025_INIT_IN_4 + ADM1025_INIT_IN_4 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MIN_5 \ + (ADM1025_INIT_IN_5 - ADM1025_INIT_IN_5 * ADM1025_INIT_IN_PERCENTAGE / 100) +#define ADM1025_INIT_IN_MAX_5 \ + (ADM1025_INIT_IN_5 + ADM1025_INIT_IN_5 * ADM1025_INIT_IN_PERCENTAGE / 100) + +#define ADM1025_INIT_RTEMP_MAX 600 +#define ADM1025_INIT_RTEMP_MIN 500 +#define ADM1025_INIT_TEMP_MAX 600 +#define ADM1025_INIT_TEMP_MIN 500 + +#ifdef MODULE +extern int init_module(void); +extern int cleanup_module(void); +#endif /* MODULE */ + +/* For each registered ADM1025, we need to keep some data in memory. That + data is pointed to by adm1025_list[NR]->data. The structure itself is + dynamically allocated, at the same time when a new adm1025 client is + allocated. */ +struct adm1025_data { + int sysctl_id; + enum chips type; + + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ + + u8 in[6]; /* Register value */ + u8 in_max[6]; /* Register value */ + u8 in_min[6]; /* Register value */ + int rtemp; /* Register value */ + u8 rtemp_max; /* Register value */ + u8 rtemp_min; /* Register encoding, shifted right */ + int temp; /* Temp, shifted right */ + u8 temp_max; /* Register value */ + u8 temp_min; /* Register value */ + u16 alarms; /* Register encoding, combined */ + u8 analog_out; /* Register value */ + u8 vid; /* Register value combined */ +}; + + +#ifdef MODULE +static +#else +extern +#endif +int __init sensors_adm1025_init(void); +static int __init adm1025_cleanup(void); + +static int adm1025_attach_adapter(struct i2c_adapter *adapter); +static int adm1025_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); +static int adm1025_detach_client(struct i2c_client *client); +static int adm1025_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void adm1025_inc_use(struct i2c_client *client); +static void adm1025_dec_use(struct i2c_client *client); + +static int adm1025_read_value(struct i2c_client *client, u8 register); +static int adm1025_write_value(struct i2c_client *client, u8 register, + u8 value); +static void adm1025_update_client(struct i2c_client *client); +static void adm1025_init_client(struct i2c_client *client); + + +static void adm1025_in(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm1025_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm1025_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +/*static void adm1025_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, + long *results);*/ +static void adm1025_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); + +/* I choose here for semi-static ADM1025 allocation. Complete dynamic + allocation could also be used; the code needed for this would probably + take more memory than the datastructure takes now. */ +static int adm1025_id = 0; + +static struct i2c_driver adm1025_driver = { + /* name */ "ADM1025 sensor driver", + /* id */ I2C_DRIVERID_ADM1025, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &adm1025_attach_adapter, + /* detach_client */ &adm1025_detach_client, + /* command */ &adm1025_command, + /* inc_use */ &adm1025_inc_use, + /* dec_use */ &adm1025_dec_use +}; + +/* Used by adm1025_init/cleanup */ +static int __initdata adm1025_initialized = 0; + +/* The /proc/sys entries */ +/* These files are created for each detected ADM1025. This is just a template; + though at first sight, you might think we could use a statically + allocated list, we need some way to get back to the parent - which + is done through one of the 'extra' fields which are initialized + when a new copy is allocated. */ +static ctl_table adm1025_dir_table_template[] = { + {ADM1025_SYSCTL_IN0, "2.5V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + {ADM1025_SYSCTL_IN1, "Vccp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + {ADM1025_SYSCTL_IN2, "3.3V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + {ADM1025_SYSCTL_IN3, "5V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + {ADM1025_SYSCTL_IN4, "12V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + {ADM1025_SYSCTL_IN5, "Vcc", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_in}, + /*{ADM1025_SYSCTL_RTEMP, "Remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_rm_temp},*/ + {ADM1025_SYSCTL_TEMP, "Local_temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_temp}, + {ADM1025_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_alarms}, +/* {ADM1025_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_analog_out},*/ + {ADM1025_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1025_vid}, + {0} +}; + +int adm1025_attach_adapter(struct i2c_adapter *adapter) +{ + return sensors_detect(adapter, &addr_data, adm1025_detect); +} + +static int adm1025_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) +{ + int i; + struct i2c_client *new_client; + struct adm1025_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; + + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ +#ifdef DEBUG + if (i2c_is_isa_adapter(adapter)) { + printk + ("adm1025.o: adm1025_detect called for an ISA bus adapter?!?\n"); + return 0; + } +#endif + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; + + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access adm1025_{read,write}_value. */ + + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct adm1025_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } + + data = (struct adm1025_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &adm1025_driver; + new_client->flags = 0; + + /* Now, we do the remaining detection. */ + + if (kind < 0) { + if((adm1025_read_value(new_client,ADM1025_REG_CONFIG) & 0x80) != 0x00) + goto ERROR1; + } + + /* Determine the chip type. */ + if (kind <= 0) { + i = adm1025_read_value(new_client, ADM1025_REG_COMPANY_ID); + if (i == 0x41) + kind = adm1025; + else { + if (kind == 0) + printk + ("adm1025.o: Ignoring 'force' parameter for unknown chip at " + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } + } + + if (kind == adm1025) { + type_name = "adm1025"; + client_name = "ADM1025 chip"; + } else { +#ifdef DEBUG + printk("adm1025.o: Internal error: unknown kind (%d)?!?", + kind); +#endif + goto ERROR1; + } + + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; + + new_client->id = adm1025_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); + + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; + + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + adm1025_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + /* Initialize the ADM1025 chip */ + adm1025_init_client(new_client); + return 0; + +/* OK, this is not exactly good programming practice, usually. But it is + very code-efficient in this case. */ + + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; +} + +int adm1025_detach_client(struct i2c_client *client) +{ + int err; + + sensors_deregister_entry(((struct adm1025_data *) (client->data))-> + sysctl_id); + + if ((err = i2c_detach_client(client))) { + printk + ("adm1025.o: Client deregistration failed, client not detached.\n"); + return err; + } + + kfree(client); + + return 0; + +} + +/* No commands defined yet */ +int adm1025_command(struct i2c_client *client, unsigned int cmd, void *arg) +{ + return 0; +} + +void adm1025_inc_use(struct i2c_client *client) +{ +#ifdef MODULE + MOD_INC_USE_COUNT; +#endif +} + +void adm1025_dec_use(struct i2c_client *client) +{ +#ifdef MODULE + MOD_DEC_USE_COUNT; +#endif +} + +int adm1025_read_value(struct i2c_client *client, u8 reg) +{ + return 0xFF & i2c_smbus_read_byte_data(client, reg); +} + +int adm1025_write_value(struct i2c_client *client, u8 reg, u8 value) +{ + return i2c_smbus_write_byte_data(client, reg, value); +} + +/* Called when we have found a new ADM1025. It should set limits, etc. */ +void adm1025_init_client(struct i2c_client *client) +{ + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others. This makes most other + initializations unnecessary */ + adm1025_write_value(client, ADM1025_REG_CONFIG, 0x80); + + adm1025_write_value(client, ADM1025_REG_IN_MIN(0), + IN_TO_REG(ADM1025_INIT_IN_MIN_0, 0)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(0), + IN_TO_REG(ADM1025_INIT_IN_MAX_0, 0)); + adm1025_write_value(client, ADM1025_REG_IN_MIN(1), + IN_TO_REG(ADM1025_INIT_IN_MIN_1, 1)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(1), + IN_TO_REG(ADM1025_INIT_IN_MAX_1, 1)); + adm1025_write_value(client, ADM1025_REG_IN_MIN(2), + IN_TO_REG(ADM1025_INIT_IN_MIN_2, 2)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(2), + IN_TO_REG(ADM1025_INIT_IN_MAX_2, 2)); + adm1025_write_value(client, ADM1025_REG_IN_MIN(3), + IN_TO_REG(ADM1025_INIT_IN_MIN_3, 3)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(3), + IN_TO_REG(ADM1025_INIT_IN_MAX_3, 3)); + adm1025_write_value(client, ADM1025_REG_IN_MIN(4), + IN_TO_REG(ADM1025_INIT_IN_MIN_4, 4)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(4), + IN_TO_REG(ADM1025_INIT_IN_MAX_4, 4)); + adm1025_write_value(client, ADM1025_REG_IN_MIN(5), + IN_TO_REG(ADM1025_INIT_IN_MIN_5, 5)); + adm1025_write_value(client, ADM1025_REG_IN_MAX(5), + IN_TO_REG(ADM1025_INIT_IN_MAX_5, 5)); + + adm1025_write_value(client, ADM1025_REG_RTEMP_HIGH, + TEMP_LIMIT_TO_REG(ADM1025_INIT_RTEMP_MAX)); + adm1025_write_value(client, ADM1025_REG_RTEMP_LOW, + TEMP_LIMIT_TO_REG(ADM1025_INIT_RTEMP_MIN)); + adm1025_write_value(client, ADM1025_REG_TEMP_HIGH, + TEMP_LIMIT_TO_REG(ADM1025_INIT_TEMP_MAX)); + adm1025_write_value(client, ADM1025_REG_TEMP_LOW, + TEMP_LIMIT_TO_REG(ADM1025_INIT_TEMP_MIN)); + + /* Start monitoring */ + adm1025_write_value(client, ADM1025_REG_CONFIG, 0x01); +} + +void adm1025_update_client(struct i2c_client *client) +{ + struct adm1025_data *data = client->data; + u8 i; + + down(&data->update_lock); + + if ( + (jiffies - data->last_updated > + (data->type == adm1025 ? HZ / 2 : HZ * 2)) + || (jiffies < data->last_updated) || !data->valid) { + +#ifdef DEBUG + printk("Starting adm1025 update\n"); +#endif + for (i = 0; i <= 5; i++) { + data->in[i] = + adm1025_read_value(client, ADM1025_REG_IN(i)); + data->in_min[i] = + adm1025_read_value(client, + ADM1025_REG_IN_MIN(i)); + data->in_max[i] = + adm1025_read_value(client, + ADM1025_REG_IN_MAX(i)); + } + data->temp = + adm1025_read_value(client, ADM1025_REG_TEMP); + printk("The temp is %2x\n",data->temp); + data->temp_max = + adm1025_read_value(client, ADM1025_REG_TEMP_HIGH); + data->temp_min = + adm1025_read_value(client, ADM1025_REG_TEMP_LOW); + + i = adm1025_read_value(client, ADM1025_REG_VID); + data->vid = i & 0x0f; + data->vid |= + (adm1025_read_value(client, ADM1025_REG_VID4) & 0x01) + << 4; + + data->alarms = + adm1025_read_value(client, + ADM1025_REG_INT1_STAT) + + (adm1025_read_value(client, ADM1025_REG_INT2_STAT) << + 8); + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); +} + + +/* The next few functions are the call-back functions of the /proc/sys and + sysctl files. Which function is used is defined in the ctl_table in + the extra1 field. + Each function must return the magnitude (power of 10 to divide the date + with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must + put a maximum of *nrels elements in results reflecting the data of this + file, and set *nrels to the number it actually put in it, if operation== + SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from + results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. + Note that on SENSORS_PROC_REAL_READ, I do not check whether results is + large enough (by checking the incoming value of *nrels). This is not very + good practice, but as long as you put less than about 5 values in results, + you can assume it is large enough. */ +void adm1025_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + + int scales[6] = { 250, 225, 330, 500, 1200, 330 }; + + struct adm1025_data *data = client->data; + int nr = ctl_name - ADM1025_SYSCTL_IN0; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1025_update_client(client); + results[0] = + IN_FROM_REG(data->in_min[nr], nr) * scales[nr] / 192; + results[1] = + IN_FROM_REG(data->in_max[nr], nr) * scales[nr] / 192; + results[2] = + IN_FROM_REG(data->in[nr], nr) * scales[nr] / 192; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = + IN_TO_REG((results[0] * 192) / scales[nr], nr); + adm1025_write_value(client, ADM1025_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = + IN_TO_REG((results[1] * 192) / scales[nr], nr); + adm1025_write_value(client, ADM1025_REG_IN_MAX(nr), + data->in_max[nr]); + } + } +} + + +void adm1025_temp(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct adm1025_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1025_update_client(client); + results[0] = TEMP_LIMIT_FROM_REG(data->temp_max); + results[1] = TEMP_LIMIT_FROM_REG(data->temp_min); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_max = TEMP_LIMIT_TO_REG(results[0]); + adm1025_write_value(client, ADM1025_REG_TEMP_HIGH, + data->temp_max); + } + if (*nrels_mag >= 2) { + data->temp_min = TEMP_LIMIT_TO_REG(results[1]); + adm1025_write_value(client, ADM1025_REG_TEMP_LOW, + data->temp_min); + } + } +} + +void adm1025_alarms(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct adm1025_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1025_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } +} +/* +void adm1025_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) +{ + struct adm1025_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1025_update_client(client); + results[0] = data->analog_out; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->analog_out = results[0]; + adm1025_write_value(client, ADM1025_REG_ANALOG_OUT, + data->analog_out); + } + } +} +*/ + +void adm1025_vid(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct adm1025_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1025_update_client(client); + results[0] = VID_FROM_REG(data->vid); + *nrels_mag = 1; + } +} + +int __init sensors_adm1025_init(void) +{ + int res; + + printk("adm1025.o version %s (%s)\n", LM_VERSION, LM_DATE); + adm1025_initialized = 0; + + if ((res = i2c_add_driver(&adm1025_driver))) { + printk + ("adm1025.o: Driver registration failed, module not inserted.\n"); + adm1025_cleanup(); + return res; + } + adm1025_initialized++; + return 0; +} + +int __init adm1025_cleanup(void) +{ + int res; + + if (adm1025_initialized >= 1) { + if ((res = i2c_del_driver(&adm1025_driver))) { + printk + ("adm1025.o: Driver deregistration failed, module not removed.\n"); + return res; + } + adm1025_initialized--; + } + return 0; +} + +EXPORT_NO_SYMBOLS; + +#ifdef MODULE + +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); +MODULE_DESCRIPTION("ADM1025 driver"); + +int init_module(void) +{ + return sensors_adm1025_init(); +} + +int cleanup_module(void) +{ + return adm1025_cleanup(); +} + +#endif /* MODULE */ diff --git a/kernel/include/sensors.h b/kernel/include/sensors.h index 96a528e9..f810ea09 100644 --- a/kernel/include/sensors.h +++ b/kernel/include/sensors.h @@ -375,6 +375,7 @@ extern inline int SENSORS_LIMIT(long value, long low, long high) #define I2C_DRIVERID_THMC50 1017 #define I2C_DRIVERID_DDCMON 1018 #define I2C_DRIVERID_VIA686A 1019 +#define I2C_DRIVERID_ADM1025 1020 /* Sysctl IDs */ #ifdef DEV_HWMON @@ -576,6 +577,27 @@ struct sensors_chips_data { #define ADM9240_ALARM_TEMP 0x0010 #define ADM9240_ALARM_CHAS 0x1000 +#define ADM1025_SYSCTL_IN0 1000 /* Volts * 100 */ +#define ADM1025_SYSCTL_IN1 1001 +#define ADM1025_SYSCTL_IN2 1002 +#define ADM1025_SYSCTL_IN3 1003 +#define ADM1025_SYSCTL_IN4 1004 +#define ADM1025_SYSCTL_IN5 1005 +#define ADM1025_SYSCTL_RTEMP 1251 +#define ADM1025_SYSCTL_TEMP 1250 /* Degrees Celcius * 100 */ +#define ADM1025_SYSCTL_ALARMS 2001 /* bitvector */ +#define ADM1025_SYSCTL_ANALOG_OUT 2002 +#define ADM1025_SYSCTL_VID 2003 + +#define ADM1025_ALARM_IN0 0x0001 +#define ADM1025_ALARM_IN1 0x0002 +#define ADM1025_ALARM_IN2 0x0004 +#define ADM1025_ALARM_IN3 0x0008 +#define ADM1025_ALARM_IN4 0x0100 +#define ADM1025_ALARM_IN5 0x0200 +#define ADM1025_ALARM_RTEMP 0x0020 +#define ADM1025_ALARM_TEMP 0x0010 + #define LTC1710_SYSCTL_SWITCH_1 1000 #define LTC1710_SYSCTL_SWITCH_2 1001