diff --git a/CHANGES b/CHANGES index c94477b1..36540eaa 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,13 @@ ask CVS about it: ----------------------------------------------------------------------------- +2.6.3 (2001????) + Library: Add PCF8591 support + Module pcf8591: new + Program sensors: Add PCF8591 support + Program sensors-detect: Add several Nvidia chips, add PCF8591 + + 2.6.2 (20011118) Chip Modules (all): malloc.h -> slab.h Modules (all): Add MODULE_LICENSE("GPL") diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d2eee0b9..4710a3fd 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -64,3 +64,5 @@ problems. Author of the IT87 driver. * Hermann Jung Author of the fscpos driver. +* Aurelien Jarno + Author of the pcf8591 driver. \ No newline at end of file diff --git a/README b/README index f9ab2187..4cfbeba1 100644 --- a/README +++ b/README @@ -18,13 +18,14 @@ WARNING! If you downloaded this package through our CVS archive, you walk the cutting edge. Things may not even compile! On the other hand, you will be the first to profit from new drivers and other changes. Have fun! -WARNING! You also need the latest i2c package, +WARNING! You may also need the latest i2c package, EVEN IF your kernel does contain i2c support!!!!!!!!!, unless i2c came bundled with lm_sensors. Kernels 2.3.34 and later, and all 2.4.x kernels, contain the -I2C package; however, you will still need to download and install -the latest I2C version if you want lm_sensors to compile. +I2C package. Kernel 2.4.13 contains i2c-2.6.1, which is sufficient +for most users. However, if you have problems compiling, +you may still need to download and install the latest I2C version. See the lm_sensors download page for guidance: http://www.netroedge.com/~lm78/download.html @@ -52,7 +53,7 @@ At least the following hardware sensor chips are supported: Asus AS99127F Dallas Semiconductor DS75, DS1621, DS1625, DS1775, and DS1780 Hewlett Packard Maxilife (several revisions including '99 NBA) - Fujitsu Siemens Poseidon Chip + Fujitsu Siemens Poseidon, Scylla Genesys Logic GL518SM (rev 00, 80), GL520SM, GL523SM Intel Xeon processor embedded sensors ITE IT8705F, IT8712F embedded sensors @@ -73,12 +74,17 @@ We also support some miscellaneous chips: SDRAM Dimms with Serial Presence Detect EEPROMs Intel Xeon processor embedded EEPROMs DDC Monitor embedded EEPROMs + Philips Semiconductors PCF8591 + + +See our New Drivers page http://www.lm-sensors.nu/~lm78/newdrivers.html +for the latest information on supported devices. We always appreciate testers. If you own a specific monitoring chip listed on our 'new drivers' page, and are willing to help us out, please contact us. Even if you have no programming knowledge, you could -help us by running new modules and reporting on the results and output. +help us by running new modules and reporting on the results and output. If you want to offer more substantial help, this is very welcome too, of course. diff --git a/doc/chips/SUMMARY b/doc/chips/SUMMARY index 1c69a57a..1098f263 100644 --- a/doc/chips/SUMMARY +++ b/doc/chips/SUMMARY @@ -161,6 +161,9 @@ matorb pcf8574 Simple eight-bit parallel I/O +pcf8591 + Quad A/D + one D/A + ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/doc/chips/pcf8591 b/doc/chips/pcf8591 new file mode 100644 index 00000000..7a8a8dfb --- /dev/null +++ b/doc/chips/pcf8591 @@ -0,0 +1,128 @@ +Kernel driver `pcf8591.o' +======================== + +Status: Status: Complete; Beta. + +Supported chips: + * Philips PCF8591 + Prefix: `pcf8591' + Addresses scanned: I2C 0x48 - 0x4f (inclusive) + Datasheet: Publicly available at the Philips Semiconductor website + http://semiconductors.philips.com/ + +Author: Aurelien Jarno +valueable contributions by Jan M. Sendler + + +Module Parameters +----------------- + +* force: short array (min = 1, max = 48) + List of adapter,address pairs to boldly assume to be present +* force_pcf8591: short array (min = 1, max = 48) + List of adapter,address pairs which are unquestionably assumed to + contain a `pcf8591' chip +* ignore: short array (min = 1, max = 48) + List of adapter,address pairs not to scan +* ignore_range: short array (min = 1, max = 48) + List of adapter,start-addr,end-addr triples not to scan +* probe: short array (min = 1, max = 48) + List of adapter,address pairs to scan additionally +* probe_range: short array (min = 1, max = 48) + List of adapter,start-addr,end-addr triples to scan additionally + + +Description +----------- +The PCF8591 is an 8-bit A/D and D/A converter (4 analog input and one +analog ouput) for the I2C bus produced by Philips Semiconductors. It +is designed to provide a byte I2C interface to up to 4 separate devices. + +The PCF8591 has 4 analog inputs programmable as single-ended or +differential inputs : +- mode 0 : four single ended inputs + Pins AIN0 to AIN3 are single ended inputs for channels 0 to 3 + +- mode 1 : three differential inputs + Pins AIN3 is the common negative differential input + Pins AIN0 to AIN2 are positive differential inputs for channels 0 to 2 + +- mode 2 : single ended and differential mixed + Pins AIN0 and AIN1 are single ended inputs for channels 0 and 1 + Pins AIN2 is the positive differential input for channel 3 + Pins AIN3 is the negative differential input for channel 3 + +- mode 3 : four differential inputs + Pins AIN0 is the positive differential input for channel 0 + Pins AIN1 is the negative differential input for channel 0 + Pins AIN2 is the positive differential input for channel 1 + Pins AIN3 is the negative differential input for channel 1 + +For more informations see the datasheet. + + +Accessing PCF8591 via /proc interface +------------------------------------- + +! Be careful ! +The PCF8591 is plainly impossible to detect ! Stupid chip. +So every chip with adress in the interval [48..4f] are +detected as PCF8591. If you have other chips in this address +range, the workaround is to load this module after the one +for your others chips. + +On detection (i.e. insmod, modprobe et al.), directories are being +created for each detected PCF8591: + +/proc/sys/dev/sensors/pcf8591-<0>-<1>/ +where <0> is the bus the chip was detected on (e. g. i2c-0) +and <1> the chip address ([48..4f]): ./pcf8591-i2c-0-48/ + +Inside these directories, there are five files each: +ain_conf, ch0, ch1, ch2, ch3, aout_enable, aout. + +The ain_conf file is rw. Reading gives you the current analog inputs +configuration, and writing configure the analog inputs. It must be +a number between 0 and 3., other values are ignored. For the different +modes, see above in the description. + +The ch0, ch1, ch2 and ch3 files are ro. Reading gives the value +of the corresponding channel. Depending on the current analog inputs +configuration, channel ch2 and/or ch3 may are not used by the chip +and so read as 0. Values range are from 0 to 255 for single +ended inputs and -128 to +127 for differential inputs (8-bit ADC). + +The aout_enable is rw. Reading gives "0" for analog output enabled and +"1" for analog output disabled. Writing accepts "0" and "1" accordingly. + +The aout is rw. Writing a number between 0 and 255 (8-bit DAC), send +the value to the digital-to-analog converter. Note that a voltage will +only appears on AOUT pin if aout_enable equals 1. Reading return the last +value written. + +On module initialization the chip is configured as followed : +- four single ended differential inputs +- analog output set to 0 and enabled + + +Chip Features +------------- + +Chip `pcf8591' + LABEL LABEL CLASS COMPUTE CLASS ACCESS MAGNITUDE + ain_conf NONE NONE RW 0 + ch0 NONE NONE R 0 + ch1 NONE NONE R 0 + ch2 NONE NONE R 0 + ch3 NONE NONE R 0 + aout_enable NONE NONE RW 0 + aout NONE NONE RW 0 + + LABEL FEATURE SYMBOL SYSCTL FILE:OFFSET + ain_conf SENSORS_PCF8591_AIN_CONF ain_conf:1 + ch0 SENSORS_PCF8591_CH0 ain_ch0:1 + ch1 SENSORS_PCF8591_CH1 ain_ch1:1 + ch2 SENSORS_PCF8591_CH2 ain_ch2:1 + ch3 SENSORS_PCF8591_CH3 ain_ch3:1 + aout_enable SENSORS_PCF8591_AOUT_ENABLE aout_enable:1 + aout SENSORS_PCF8591_AOUT aout:1 diff --git a/etc/sensors.conf.eg b/etc/sensors.conf.eg index 5baadd83..473382c9 100644 --- a/etc/sensors.conf.eg +++ b/etc/sensors.conf.eg @@ -1174,3 +1174,24 @@ chip "fscscy-*" label volt5 "+5V" label voltbatt "+3.3V" + +chip "pcf8591-*" +# +# values for the Philips PCF8574 chip +# +# Analog inputs + + ignore ain_conf + set ain_conf 0 + label ch0 "Chan. 0" + label ch1 "Chan. 1" + label ch2 "Chan. 2" + label ch3 "Chan. 3" + +# Analog output + + ignore aout_enable + set aout_enable 1 + label aout "Output" + set aout 0 + diff --git a/kernel/chips/Module.mk b/kernel/chips/Module.mk index 08b32f3d..0f00fa51 100644 --- a/kernel/chips/Module.mk +++ b/kernel/chips/Module.mk @@ -24,7 +24,7 @@ KERNELCHIPSDIR := $(MODULE_DIR) # Regrettably, even 'simply expanded variables' will not put their currently # defined value verbatim into the command-list of rules... # These targets are NOT included in 'mkpatch' ... -KERNELCHIPSTARGETS := +KERNELCHIPSTARGETS := $(MODULE_DIR)/pcf8591.o # These targets ARE included in 'mkpatch', except for LTC1710, which we # leave here because it used to be in 'mkpatch' ... diff --git a/kernel/chips/pcf8591.c b/kernel/chips/pcf8591.c new file mode 100644 index 00000000..bbffc804 --- /dev/null +++ b/kernel/chips/pcf8591.c @@ -0,0 +1,550 @@ +/* + pcf8591.c - Part of lm_sensors, Linux kernel modules for hardware + monitoring + Copyright (c) 2001 Aurelien Jarno + + 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. +*/ + +#include +#include +#include +#include +#include "sensors.h" +#include "version.h" +#include + +#ifndef I2C_DRIVERID_PCF8591 +#define I2C_DRIVERID_PCF8591 1030 +#endif + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)) || \ + (LINUX_VERSION_CODE == KERNEL_VERSION(2,3,0)) +#define init_MUTEX(s) do { *(s) = MUTEX; } while(0) +#endif + +#ifndef THIS_MODULE +#define THIS_MODULE NULL +#endif + +/* Addresses to scan */ +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x48, 0x4f, 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(pcf8591); + +/* The PCF8591 control byte */ +/* 7 6 5 4 3 2 1 0 */ +/* | 0 |AOEF| AIP | 0 |AINC| AICH | */ + +#define PCF8591_CONTROL_BYTE_AOEF 0x40 /* Analog Output Enable Flag */ + /* (analog output active if 1) */ + +#define PCF8591_CONTROL_BYTE_AIP 0x30 /* Analog Input Programming */ + /* 0x00 = four single ended inputs */ + /* 0x10 = three differential inputs */ + /* 0x20 = single ended and differential mixed */ + /* 0x30 = two differential inputs */ + +#define PCF8591_CONTROL_BYTE_AINC 0x04 /* Autoincrement Flag */ + /* (switch on if 1) */ + +#define PCF8591_CONTROL_BYTE_AICH 0x03 /* Analog Output Enable Flag */ + /* 0x00 = channel 0 */ + /* 0x01 = channel 1 */ + /* 0x02 = channel 2 */ + /* 0x03 = channel 3 */ + + +/* Initial values */ +#define PCF8591_INIT_CONTROL_BYTE (PCF8591_CONTROL_BYTE_AOEF | PCF8591_CONTROL_BYTE_AINC) + /* DAC out enabled, four single ended inputs, autoincrement */ + +#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */ + + +/* Conversions. */ +#define REG_TO_SIGNED(reg) (reg & 0x80)?(reg - 256):(reg) + /* Convert signed 8 bit value to signed value */ + +#ifdef MODULE +extern int init_module(void); +extern int cleanup_module(void); +#endif + + + +struct pcf8591_data { + struct semaphore lock; + 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 control_byte; + u8 ch[4]; + u8 aout; +}; + +#ifdef MODULE +static +#else +extern +#endif +int __init sensors_pcf8591_init(void); +static int __init pcf8591_cleanup(void); +static int pcf8591_attach_adapter(struct i2c_adapter *adapter); +static int pcf8591_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); +static int pcf8591_detach_client(struct i2c_client *client); +static int pcf8591_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void pcf8591_inc_use(struct i2c_client *client); +static void pcf8591_dec_use(struct i2c_client *client); + +static void pcf8591_update_client(struct i2c_client *client); +static void pcf8591_init_client(struct i2c_client *client); + +static void pcf8591_ain_conf(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void pcf8591_ain(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void pcf8591_aout_enable(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void pcf8591_aout(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); + + +/* This is the driver that will be inserted */ +static struct i2c_driver pcf8591_driver = { + /* name */ "PCF8591 sensor chip driver", + /* id */ I2C_DRIVERID_PCF8591, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &pcf8591_attach_adapter, + /* detach_client */ &pcf8591_detach_client, + /* command */ &pcf8591_command, + /* inc_use */ &pcf8591_inc_use, + /* dec_use */ &pcf8591_dec_use +}; + +/* Used by lm78_init/cleanup */ +static int __initdata pcf8591_initialized = 0; + +static int pcf8591_id = 0; + + +/* The /proc/sys entries */ +/* These files are created for each detected PCF8591. 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 pcf8591_dir_table_template[] = { + {PCF8591_SYSCTL_AIN_CONF, "ain_conf", NULL, 0, 0644, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_ain_conf}, + {PCF8591_SYSCTL_CH0, "ch0", NULL, 0, 0444, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_ain}, + {PCF8591_SYSCTL_CH1, "ch1", NULL, 0, 0444, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_ain}, + {PCF8591_SYSCTL_CH2, "ch2", NULL, 0, 0444, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_ain}, + {PCF8591_SYSCTL_CH3, "ch3", NULL, 0, 0444, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_ain}, + {PCF8591_SYSCTL_AOUT_ENABLE, "aout_enable", NULL, 0, 0644, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_aout_enable}, + {PCF8591_SYSCTL_AOUT, "aout", NULL, 0, 0644, NULL, &i2c_proc_real, + &i2c_sysctl_real, NULL, &pcf8591_aout}, + {0} +}; + + +/* This function is called when: + * pcf8591_driver is inserted (when this module is loaded), for each + available adapter + * when a new adapter is inserted (and pcf8591_driver is still present) */ +int pcf8591_attach_adapter(struct i2c_adapter *adapter) +{ + return i2c_detect(adapter, &addr_data, pcf8591_detect); +} + +/* This function is called by i2c_detect */ +int pcf8591_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) +{ + int i; + struct i2c_client *new_client; + struct pcf8591_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; i2c_detect really won't call us. */ +#ifdef DEBUG + if (i2c_is_isa_adapter(adapter)) { + printk + (KERN_ERR "pcf8574.o: pcf8574_detect called for an ISA bus adapter?!?\n"); + return 0; + } +#endif + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) + 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. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct pcf8591_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } + + data = (struct pcf8591_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &pcf8591_driver; + new_client->flags = 0; + + /* Now, we would do the remaining detection. But the PCF8574 is plainly + impossible to detect! Stupid chip. */ + + /* Determine the chip type - only one kind supported! */ + if (kind <= 0) + kind = pcf8591; + + if (kind == pcf8591) { + type_name = "pcf8591"; + client_name = "PCF8591 chip"; + } else { +#ifdef DEBUG + printk(KERN_ERR "pcf8591.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); + + new_client->id = pcf8591_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 = i2c_register_entry(new_client, + type_name, + pcf8591_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + /* Initialize the PCF8591 chip */ + pcf8591_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 pcf8591_detach_client(struct i2c_client *client) +{ + int err; + +#ifdef MODULE + if (MOD_IN_USE) + return -EBUSY; +#endif + + i2c_deregister_entry(((struct pcf8591_data *) (client->data))-> + sysctl_id); + + if ((err = i2c_detach_client(client))) { + printk + (KERN_ERR "pcf8591.o: Client deregistration failed, client not detached.\n"); + return err; + } + + kfree(client); + + return 0; +} + +/* No commands defined yet */ +int pcf8591_command(struct i2c_client *client, unsigned int cmd, void *arg) +{ + return 0; +} + +/* Nothing here yet */ +void pcf8591_inc_use(struct i2c_client *client) +{ +#ifdef MODULE + MOD_INC_USE_COUNT; +#endif +} + +/* Nothing here yet */ +void pcf8591_dec_use(struct i2c_client *client) +{ +#ifdef MODULE + MOD_DEC_USE_COUNT; +#endif +} + +/* Called when we have found a new PCF8591. */ +void pcf8591_init_client(struct i2c_client *client) +{ + struct pcf8591_data *data = client->data; + data->control_byte = PCF8591_INIT_CONTROL_BYTE; + data->aout = PCF8591_INIT_AOUT; + + i2c_smbus_write_byte_data(client, data->control_byte, data->aout); +} + +void pcf8591_update_client(struct i2c_client *client) +{ + struct pcf8591_data *data = client->data; + + down(&data->update_lock); + + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { + +#ifdef DEBUG + printk(KERN_DEBUG "Starting pcf8591 update\n"); +#endif + + i2c_smbus_write_byte(client, data->control_byte); + i2c_smbus_read_byte(client); /* The first byte transmitted contains the */ + /* conversion code of the previous read cycled */ + /* FLUSH IT ! */ + + + /* Number of byte to read to signed depend on the analog input mode */ + data->ch[0] = i2c_smbus_read_byte(client); + data->ch[1] = i2c_smbus_read_byte(client); + /* In all case, read at least two values */ + + if ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) != 0x30) + data->ch[2] = i2c_smbus_read_byte(client); + /* Read the third value if not in "two differential inputs" mode */ + + if ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 0x00) + data->ch[3] = i2c_smbus_read_byte(client); + /* Read the fourth value only in "four single ended inputs" mode */ + + 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. */ +void pcf8591_ain_conf(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct pcf8591_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = (data->control_byte & PCF8591_CONTROL_BYTE_AIP) >> 4; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + if (results[0] >= 0 && results[0] <= 3) + { + data->control_byte &= ~PCF8591_CONTROL_BYTE_AIP; + data->control_byte |= (results[0] << 4); + i2c_smbus_write_byte(client, data->control_byte); + data->valid = 0; + } + } + } +} + +void pcf8591_ain(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct pcf8591_data *data = client->data; + int nr = ctl_name - PCF8591_SYSCTL_CH0; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + pcf8591_update_client(client); + + /* Number of data to show and conversion to signed depend on */ + /* the analog input mode */ + + switch(nr) { + case 0: + if (((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 0) + | ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 2)) + results[0] = data->ch[0]; /* single ended */ + else + results[0] = REG_TO_SIGNED(data->ch[0]);/* differential */ + break; + case 1: + if (((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 0) + | ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 2)) + results[0] = data->ch[1]; /* single ended */ + else + results[0] = REG_TO_SIGNED(data->ch[1]);/* differential */ + break; + case 2: + if ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 3) + results[0] = 0; /* channel not used */ + else if ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 0) + results[0] = data->ch[2]; /* single ended */ + else + results[0] = REG_TO_SIGNED(data->ch[2]);/* differential */ + break; + case 3: + if (((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 0) + | ((data->control_byte & PCF8591_CONTROL_BYTE_AIP) == 2)) + results[0] = data->ch[3]; /* single ended */ + else + results[0] = 0; /* channel not used */ + break; + } + *nrels_mag = 1; + } +} + +void pcf8591_aout_enable(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct pcf8591_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = !(!(data->control_byte & PCF8591_CONTROL_BYTE_AOEF)); + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + if (results[0]) + data->control_byte |= PCF8591_CONTROL_BYTE_AOEF; + else + data->control_byte &= ~PCF8591_CONTROL_BYTE_AOEF; + + i2c_smbus_write_byte(client, data->control_byte); + } + } +} + +void pcf8591_aout(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct pcf8591_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = data->aout; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + if (results[0] >= 0 && results[0] <= 255) /* ignore values outside DAC range */ + { + data->aout = results[0]; + i2c_smbus_write_byte_data(client, data->control_byte, data->aout); + } + } + } +} + +int __init sensors_pcf8591_init(void) +{ + int res; + + printk(KERN_INFO "pcf8591.o version %s (%s)\n", LM_VERSION, LM_DATE); + pcf8591_initialized = 0; + + if ((res = i2c_add_driver(&pcf8591_driver))) { + printk + (KERN_ERR "pcf8591.o: Driver registration failed, module not inserted.\n"); + pcf8591_cleanup(); + return res; + } + pcf8591_initialized++; + return 0; +} + +int __init pcf8591_cleanup(void) +{ + int res; + + if (pcf8591_initialized >= 1) { + if ((res = i2c_del_driver(&pcf8591_driver))) { + printk + (KERN_ERR "pcf8591.o: Driver deregistration failed, module not removed.\n"); + return res; + } + pcf8591_initialized--; + } + return 0; +} + +EXPORT_NO_SYMBOLS; + +#ifdef MODULE + +MODULE_AUTHOR("Aurelien Jarno "); +MODULE_DESCRIPTION("PCF8591 driver"); +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +int init_module(void) +{ + return sensors_pcf8591_init(); +} + +int cleanup_module(void) +{ + return pcf8591_cleanup(); +} + +#endif /* MODULE */ + + + + diff --git a/lib/chips.c b/lib/chips.c index 32274f91..366570d6 100644 --- a/lib/chips.c +++ b/lib/chips.c @@ -2453,6 +2453,26 @@ static sensors_chip_feature fscscy_features[] = { 0 } }; + static sensors_chip_feature pcf8591_features[] = + { + { SENSORS_PCF8591_AIN_CONF, "ain_conf", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_RW, PCF8591_SYSCTL_AIN_CONF, VALUE(1), 0 }, + { SENSORS_PCF8591_CH0, "ch0", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_R, PCF8591_SYSCTL_CH0, VALUE(1), 0 }, + { SENSORS_PCF8591_CH1, "ch1", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_R, PCF8591_SYSCTL_CH1, VALUE(1), 0 }, + { SENSORS_PCF8591_CH2, "ch2", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_R, PCF8591_SYSCTL_CH2, VALUE(1), 0 }, + { SENSORS_PCF8591_CH3, "ch3", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_R, PCF8591_SYSCTL_CH3, VALUE(1), 0 }, + { SENSORS_PCF8591_AOUT_ENABLE, "aout_enable", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_RW, PCF8591_SYSCTL_AOUT_ENABLE, VALUE(1), 0 }, + { SENSORS_PCF8591_AOUT, "aout", SENSORS_NO_MAPPING, SENSORS_NO_MAPPING, + SENSORS_MODE_RW, PCF8591_SYSCTL_AOUT, VALUE(1), 0 }, + { 0 } + }; + + sensors_chip_features sensors_chip_features_list[] = { { SENSORS_LM78_PREFIX, lm78_features }, @@ -2502,5 +2522,6 @@ sensors_chip_features sensors_chip_features_list[] = { SENSORS_IT87_PREFIX, it87_features }, { SENSORS_FSCPOS_PREFIX, fscpos_features }, { SENSORS_FSCSCY_PREFIX, fscscy_features }, + { SENSORS_PCF8591_PREFIX, pcf8591_features }, { 0 } }; diff --git a/lib/chips.h b/lib/chips.h index d2ff9ddd..4419016e 100644 --- a/lib/chips.h +++ b/lib/chips.h @@ -1113,6 +1113,17 @@ #define SENSORS_FSCSCY_WDOG_STATE 52 /* RW */ #define SENSORS_FSCSCY_WDOG_CONTROL 52 /* RW */ +/* PCF8591 chip. */ + +#define SENSORS_PCF8591_PREFIX "pcf8591" + +#define SENSORS_PCF8591_AIN_CONF 1 /* RW */ +#define SENSORS_PCF8591_CH0 2 /* R */ +#define SENSORS_PCF8591_CH1 3 /* R */ +#define SENSORS_PCF8591_CH2 4 /* R */ +#define SENSORS_PCF8591_CH3 5 /* R */ +#define SENSORS_PCF8591_AOUT_ENABLE 6 /* RW */ +#define SENSORS_PCF8591_AOUT 7 /* RW */ #endif /* def LIB_SENSORS_CHIPS_H */ diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index f4ab446b..6d88233e 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -518,7 +518,8 @@ use subs qw(mtp008_detect lm78_detect lm78_isa_detect lm78_alias_detect adm9240_detect adm1021_detect sis5595_isa_detect eeprom_detect via686a_isa_detect adm1022_detect ltc1710_detect gl525sm_detect lm87_detect ite_detect ite_isa_detect ite_alias_detect - ddcmonitor_detect ds1621_detect adm1024_detect fscpos_detect fscscy_detect); + ddcmonitor_detect ds1621_detect adm1024_detect fscpos_detect fscscy_detect + pcf8591_detect); # This is a list of all recognized chips. # Each entry must have the following fields: @@ -806,6 +807,12 @@ use subs qw(mtp008_detect lm78_detect lm78_isa_detect lm78_alias_detect i2c_addrs => [0x73], i2c_detect => sub { fscscy_detect @_ }, }, + { + name => "Philips Semiconductors PCF8591", + driver => "pcf8591", + i2c_addrs => [0x48..0x4f], + i2c_detect => sub { pcf8591_detect @_}, + }, ); @@ -2328,6 +2335,17 @@ sub fscscy_detect return (8); } +# $_[0]: A reference to the file descriptor to access this chip. +# We may assume an i2c_set_slave_addr was already done. +# $_[1]: Address +# Returns: undef if not detected, (1) if detected. +# Detection is impossible! +sub pcf8591_detect +{ + return (1); +} + + ################ # MAIN PROGRAM # ################ diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index 66ba9806..1379184c 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -2927,6 +2927,91 @@ void print_fscscy(const sensors_chip_name *name) free_the_label(&label); } +void print_pcf8591(const sensors_chip_name *name) +{ + char *label; + double ain_conf, ch0, ch1, ch2, ch3; + double aout_enable, aout; + int valid; + + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_AIN_CONF,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_AIN_CONF,&ain_conf)) { + if (valid) { + print_label(label,10); + switch ((int)ain_conf) + { + case 0: printf("four single ended inputs\n"); + break; + case 1: printf("three differential inputs\n"); + break; + case 2: printf("single ended and differential mixed\n"); + break; + case 3: printf("two differential inputs\n"); + break; + } + } + } + else printf("ERROR: Can't read analog inputs configuration!\n"); + free_the_label(&label); + + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_CH0,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_CH0,&ch0)) { + if (valid) { + print_label(label,10); + printf("%0.0f\n", ch0); + } + } + else printf("ERROR: Can't read ch0!\n"); + free_the_label(&label); + + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_CH1,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_CH1,&ch1)) { + if (valid) { + print_label(label,10); + printf("%0.0f\n", ch1); + } + } + else printf("ERROR: Can't read ch1!\n"); + free_the_label(&label); + + if (ain_conf != 3) { + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_CH2,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_CH2,&ch2)) { + if (valid) { + print_label(label,10); + printf("%0.0f\n", ch2); + } + } + else printf("ERROR: Can't read ch2!\n"); + free_the_label(&label); + } + + if (ain_conf == 0) { + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_CH3,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_CH3,&ch3)) { + if (valid) { + print_label(label,10); + printf("%0.0f\n", ch3); + } + } + else printf("ERROR: Can't read ch3!\n"); + free_the_label(&label); + } + + if (!sensors_get_label_and_valid(*name,SENSORS_PCF8591_AOUT,&label,&valid) && + !sensors_get_feature(*name,SENSORS_PCF8591_AOUT,&aout) && + !sensors_get_feature(*name,SENSORS_PCF8591_AOUT_ENABLE,&aout_enable)) { + if (valid) { + print_label(label,10); + printf("%0.0f (%s)\n", aout, aout_enable?"enabled":"disabled"); + } + } + else printf("ERROR: Can't read aout!\n"); + free_the_label(&label); + +} + + void print_unknown_chip(const sensors_chip_name *name) { int a,b,valid; diff --git a/prog/sensors/chips.h b/prog/sensors/chips.h index 46705d89..64031fd7 100644 --- a/prog/sensors/chips.h +++ b/prog/sensors/chips.h @@ -44,5 +44,6 @@ extern void print_lm87(const sensors_chip_name *name); extern void print_it87(const sensors_chip_name *name); extern void print_fscpos(const sensors_chip_name *name); extern void print_fscscy(const sensors_chip_name *name); +extern void print_pcf8591(const sensors_chip_name *name); #endif /* def PROG_SENSORS_CHIPS_H */ diff --git a/prog/sensors/main.c b/prog/sensors/main.c index 912690fc..983fc1fd 100644 --- a/prog/sensors/main.c +++ b/prog/sensors/main.c @@ -337,6 +337,8 @@ void do_a_print(sensors_chip_name name) print_fscpos(&name); else if (!strcmp(name.prefix,"fscscy")) print_fscscy(&name); + else if (!strcmp(name.prefix,"pcf8591")) + print_pcf8591(&name); else print_unknown_chip(&name); printf("\n");